java - Gurobi can't add constraints -
i'm writing program in java solve mip problem gurobi. problem requires lot of constraints , variables first ones cannot added model. deeper in problem, when try add constraint model show it(read through debugging),but row_no
equal -1. first things first:
create multi-dimensional matrix of variables:
grbvar[][] x = new grbvar[imax][jmax]; (int = 0; < imax; i++) { (int j = 0; j < jmax; j++) { x[i][j] = model.addvar(0.0, grb.infinity, 0.0, grb.semiint, "xi" + + "j" + j); } }
add constraints (looks xij < 10):
(int = 0; < imax; i++) { (int j = 0; j < jmax; j++) { grblinexpr lhs = new grblinexpr(); grblinexpr rhs = new grblinexpr(); lhs.addterm(1.0, x[i][j]]); rhs.addconstant(10); model.addconstr(lhs, grb.less_equal, rhs, "vi" + + "j" + j); } }
debug project: there
imax * jmax
columns,imax * jmax
variables,imax * jmax
contraints (withrow_no
= -1) , 0 rows.
any idea?
edit
i'm not use of row_no
, suppose gurobi (from abstract point of view) organizes data pseudo-matrix variables stored columns , constraints rows. why that? because every times add variable counter of columns grow 1 , col_no
associated particular column, instead when add constraint counter of rows doesn't change.
columns: http://www.gurobi.com/documentation/6.0/refman/java_grbmodel_getcol.html rows:http://www.gurobi.com/documentation/6.0/refman/java_grbmodel_getrow.html
edit 2
i don't have problems columns, rows or else, when try solve relaxed model, gurobi shows output:
optimize model 0 rows, 1475400 columns , 0 nonzeros coefficient statistics: matrix range [0e+00, 0e+00] objective range [0e+00, 0e+00] bounds range [1e+00, 1e+03] rhs range [0e+00, 0e+00] presolve removed 0 rows , 1475400 columns presolve time: 0.36s presolve: rows , columns removed iteration objective primal inf. dual inf. time 0 0.0000000e+00 0.000000e+00 0.000000e+00 1s solved in 0 iterations , 0.72 seconds optimal objective 0.000000000e+00
the solution feasible, can't show useful information. tought should update model after adding variables, not constraints. additionaly, read gurobi documentation if model needs update throws exception (not case):
"the common symptom of missing update not_in_model exception, indicates object trying reference isn't in model yet"
edit 3
i've followed suggest of update model (after adding constraints) , everythings works correctly. supposed wasn't mandatory but, in contrast of documentation (and code examples), is.
i guess model shows strange behaviour because variables have 0.0 coefficient in objective function. furthermore, setting variables 0 feasible solution.
while cannot explain internal mechanism of gurobi setting rows zero, gives correct answer (strange kind of) model.
Comments
Post a Comment