c - Programmatic access to MathProg solutions in GLPK -
i have problem expressed in mathprog doesn't seem describable using c api. specifically, have constraints between variables. i've generated mathprog file , passed glpk. finds correct solution, don't see how access solution programmatically. returned glp_prob
struct has no rows or columns. parse solution printed solver, i'm hoping there's better way.
alternatively, if it's possible express constraints between variables using c api, suspect solve problem. mathprog code below.
param t := 200; set b, dimen 3; set c, dimen 2; set s, dimen 2; set q := setof{(i,j,c) in b : j == 1} i; set := setof{(i,s) in s} i; set e := setof{(i,j) in q cross i} (i, j); var x{(i,j) in e}, >=0, <=1, binary; var y{i}, >=0, <=1, binary; maximize obj : sum{(i,j,c) in b} x[i,j] * c; s.t. q1c: sum{(i,s) in s} x[1,i] <= 1; s.t. q2c: sum{(i,s) in s} x[2,i] <= 1; s.t. size : sum{(i,c) in c} c * y[i] <= t; s.t. c111avail : x[1,1] <= y[1]; s.t. c122avail : x[1,2] <= y[2]; s.t. c131avail : x[1,3] <= y[1]; s.t. c132avail : x[1,3] <= y[2]; s.t. c243avail : x[2,4] <= y[3]; solve; printf "set:"; printf {(i,s) in s: y[i] == 1} " %i", i; printf "\nnot set:"; printf {(i,s) in s: y[i] == 0} " %i", i; printf "\n"; data; set c := 1 100 2 100 3 100 4 100 ; set s := 1 100 2 100 3 200 4 100 ; set b := 1 1 30 1 2 30 1 3 75 1 4 0 2 1 0 2 2 0 2 3 0 2 4 35 ; end;
there additional glpk api routines can use after solving problem. like
glp_get_row_prim(lp, i) glp_get_col_prim(lp, i)
which return primal value of row/column floating point number.
to generate matrix representation of inequalities between 2 variables (for example c api routines), have reformulate equations, variables on left hand side of equation. example
x[1, 1] <= y[1];
will turn into
y[1] - x[1, 1] >= 0;
Comments
Post a Comment