help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] How I include a table of 1000 records


From: Noli Sicad
Subject: Re: [Help-glpk] How I include a table of 1000 records
Date: Wed, 21 Oct 2015 13:36:05 +1100

Hi Luis,

If you want to use GLPK/MathProg, please have a look at the csv
example (i.e. transp_csv.mod) included in the glpk source code.

~~~~~~~
e.g.

table tab_plant IN "CSV" "plants.csv" :
  I <- [plant], a ~ capacity;

table tab_market IN "CSV" "markets.csv" :
  J <- [market], b ~ demand;

table tab_distance IN "CSV" "distances.csv" :
  K <- [plant, market], d ~ distance;

~~~~~~~~

AMPL table is very different from GLPK/MathProg table. AMPL table
scripts does work in GLPK/MathProg


Noli







On 10/21/15, luisjaime <address@hidden> wrote:
> Thanks Noli.
>
> It's your suggestion better.  Google"ing" I find a book: AMPL writed for
> Robert Fourer, David M. Gay and Brian W. Kernighan, and I'm reading it.
> Find that for read a table, It will see like:
>
> set KF;  #for the key field on the table
> param field1{LI}; #for the field one
> param field2{LI}; #for the field two
> param field3{LI}; #for the field three
>
> table data IN "CSV" "tablename.csv":
>      KF <- [key], field1 ~ f1, field2 ~ f2, field3 ~ f3;
>
> The table file named "tablename.csv" in disk, would have the next:
>
> key,f1,f2,f3
> 1,0.3,0.2,-7
> 2,-0.5,7,3.2
> 3,0.2,0.1,0.0
>
> If any body find utilitarian this information...
>
> If some body don't have the book, I've complete in a only file.
>
> Thanks.
>
> luis jaime
>
>
> El 14/10/15 a las 22:03, Noli Sicad escribió:
>> Hi Luis,
>>
>> Just do this:
>>
>> set I:= {1..6};
>> /* Las i muestras */
>>
>> For 10,000 records,
>>
>> set I:= {1..1000};
>>
>> For CSV file, read and write, you can see the example in
>> glpk-4.56/examples/csv folder.
>>
>> transp_csv.mod
>>
>>
>> Regards, Noli
>>
>> On 10/15/15, luisjaime <address@hidden> wrote:
>>> Good day for all people in this list:
>>>
>>> I've the next model:
>>>
>>>
>>> set I;
>>> /* Las i muestras */
>>> set J;
>>> /* los j instrumentos */
>>>
>>> param r{i in I, j in J};
>>> /* cada una de las muestras de los retornos */
>>>
>>> var x {j in J};
>>> /* el portafolio */
>>>
>>> minimize obj: sum{i in I, j in J} r[i,j]*x[j];
>>> /* La función objetivo */
>>>
>>> s.t. porc_total: sum {j in J} x[j] = 1;
>>>
>>> data;
>>>
>>> set I := 1 2 3 4 5 6;
>>>
>>> set J := 1 2 3;
>>>
>>> param r: 1 2 3:=
>>>           1 0.04300620 0.06094491 0.8793238
>>>           2 0.08306441 0.05640739 0.6835024
>>>           3 0.05271815 0.08390957 1.2346929
>>>           4 0.09064139 0.08094768 1.1428601
>>>           5 0.09523738 0.05262512 0.6908464
>>>           6 0.02364452 0.06848395 1.3471945 ;
>>>
>>> end;
>>>
>>> this run ok, but, how I do for include 1000 records?  It's imposible
>>> write set I:= 1 2 3 .... 999 1000; there are a short form?  I tried with
>>> "set I:=1..1000;" form, but glpsol don't understand.   And, if I will
>>> like read from a csv file, How I can do it?  Of course I've ready a file
>>> with the records.
>>>
>>> I have readed the gmpl.pdf but if there are examples, all are related
>>> for the specific item in the guide but haven't examples complete showing
>>> situations like mine, exception the tsp problem.
>>>
>>> Thanks a lot!
>>>
>>>
>>> luis jaime
>>>
>>> _______________________________________________
>>> Help-glpk mailing list
>>> address@hidden
>>> https://lists.gnu.org/mailman/listinfo/help-glpk
>>>
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]