glpk - Reading CSV data into subscripted set -
i ask assistance problem i'm dealing week. have been looking everywhere solution. official doc not accurate enough , says nothing on matter.
the problem following: part of csv file "food.csv". here copied 6 columns make small previe of data.
name index e k c rice 1 0 0 0 0 lentils 2 0.39 5 0.05 44 carrot 3 167.05 7 132 59 potato 4 0.03 0 21 74 apple 5 0.38 1 6 0.04
i'm importing gnu mathprog linear program using table
statement. problem is, each column i'm forced use separated parameter. prefer index columns single 2 dimensional parameter iterate on them easily.
set fields; param kc{i in 1..card(fields)}, symbolic; # symbolic example, it's numeric table data in "csv" "food.csv": fields <- [index], kc~kcal;
the problem way have use separate parameter each column, if have 40 collumns , 2 constraints each of columns, gives 80 constraints in separated lines, if want change something, need change 80 lines of code, because cannot iterate on columns , simplify it.
here put parsed csv file.
display statement @ line 213 kc[1] = '1.12' kc[2] = '3.53' kc[3] = '0.41' kc[4] = '0.86' kc[5] = '0.48' kc[6] = '3.89' kc[7] = '0.36' kc[8] = '1.89' kc[9] = '8.84' kc[10] = '0.72' kc[11] = '1.2' kc[12] = '2.95' kc[13] = '6.54' kc[14] = '5.41' kc[15] = '0.81' kc[16] = '1.49' kc[17] = '0.4'
and more interresting having like:
kc[1][1] # first entry, first column kc[1][2] # first entry, second column kc[2][5] # second entry entry, fifth column
does has idea how achieve this?
your input data (i.e. food.csv) not matched parsed output data.
please post correct data (i.e. input data , desire output data), can you.
it easy solve problem. see example csv data in glpk/mathprog distribution files in ../examples/csv folder, transportation model. uses csv input , output.
this example of syntax (below).
set i; /* canning plants */
set j; /* markets */
set k dimen 2; /* transportation lane */
param d{i in i, j in j}; /* distance in thousands of miles */
table tab_distance in "csv" "distances.csv" : k <- [plant, market], d ~ distance;
Comments
Post a Comment