I am a novice in GLPK and linear programming. I'm trying to output some data to a .csv file and it is outputting it to the file but it isn't separating the data with comma.
set I; /*equipments */
set J; /* maintenance plans */
param cost{I}; /* failure cost for equip i in I */
param maint{J};
param prob{I, J}; /* failure probab i in I under j in J */
param filename, symbolic := "out.csv";
var x{I, J} binary; /* 1 if include maintenance plan, 0 otherwise */
minimize MainCost: sum{i in I} sum{j in J} prob[i,j]*cost[i]*x[i,j];
s.t. MaintCost{j in I}: sum{(i,j) in {I, J}}(maint[j]*x[i,j]) <= 10;
s.t. Unit {i in I}: sum{j in J} x[i,j] = 1;
solve;
printf {(i,j) in {I, J}: x[i,j] = 1}
j,"," >> filename;
Here is the first problem: I'd like to save in .csv sth like 1,3,2,1,...,1
data;
param: I: cost:=
1 5
2 10
3 9
4 3
5 6
6 5
7 7
8 6
9 10
10 6;
param: J: maint:=
1 0
2 1
3 2 ;
param prob
: 1 2 3 :=
1 0.71349520313981 0.608394373323201 0.46473857148101
2 0.604843473690396 0.494158592651351 0.35715264359696
3 0.640260888759684 0.532400290182621 0.394600541097475
4 0.71349520313981 0.608394373323201 0.46473857148101
5 0.500170157438303 0.383902444963231 0.256863101331242
6 0.696759243580332 0.582579242310187 0.433239819885668
7 0.604843473690396 0.494158592651351 0.35715264359696
8 0.660549568442532 0.553447396825782 0.414065533311644
9 0.612144282180733 0.502294490808246 0.365501585646775
10 0.71349520313981 0.608394373323201 0.46473857148101 ;
end;
Second: instead of "<=10" in the 1st constraint, I'd like to have different values, e.g 0,10,20,30,40,50 and run this code subject for these values and save the values in the "out.csv" file. In this specific case, I'd have in the out.csv 6 rows and the values separated with comma. I can't put the function objective and constraints inside a "for", for eg. So, ideas?
Thanks a lot in advance.