[Scip] Adding variables and Constraints to MIP

Gerald Gamrath gamrath at zib.de
Wed Mar 7 23:08:38 MET 2012


Dear Sheetal,

if you want to create a variable without upper bound, you should set the 
upper bound to infinity, by giving SCIPinfinity(scip) instead of NULL to 
the SCIPcreateVar() method. NULL is just a null pointer and is 
interpreted as an upper bound of 0, such that all variables that you 
create are fixed to 0.

I hope that helps and solves your problem. If not, please tell us and we 
will have a closer look.

Best,
Gerald

Am 07.03.2012 22:51, schrieb sheetal murkute:
> Hi,
> I have written a code for solving MIP. I did not get any compilation 
> error, however,
> the solution comes out to be infeasible, which is incorrect. There 
> might be some error in creating constraints and variables for SCIP.
>
> I want to create continuous variables >= 0. For this I have set lower 
> bound as 0, upper bound NULL and type SCIP_VARTYPE_CONTINUOUS.
> Is this correct? All the codes in examples folder in SCIP are having 
> bounded variables, hence I am not sure about this.
>
>         std::vector<SCIP_VAR*> _vars;
> ostringstream namebuf;
>
> // create xijk variables and add to problem, store to the std vector 
> for later use
> for(i=1;i<=A*K;i++)
> {
> SCIP_VAR* var;
> namebuf.str("");
> namebuf << "x#" << i;
> SCIP_CALL_EXC(SCIPcreateVar(scip, & var, namebuf.str().c_str(), 
> 0.0,NULL, ObjCoeff[i], SCIP_VARTYPE_CONTINUOUS, TRUE, FALSE, NULL, 
> NULL, NULL, NULL, NULL));
> SCIP_CALL_EXC(SCIPaddVar(scip, var));
> _vars.push_back(var);
> }
>
>
> Also for adding constraints, I initially set number of nonzero 
> variables to 0, and index and values of coefficients as NULL. After that,
> I add coefficients using SCIPaddCoefLinear. Is this correct?
>
> /* first constraint (flow balancing) in MCF */
>
>
> j=1;s=1;
> for ( commodity=1, shift = 0 ;  commodity<= K && shift < K; 
>  commodity++, shift++)
> {
> for (n=1; n<=N; n++)
> {
> SCIP_CONS * cons;
> namebuf.str("");
> namebuf<<"constraint_"<<s;
> // this is an equality constraint, hence lower and upper bounds are b[s]
> SCIP_CALL_EXC( SCIPcreateConsLinear(scip, & cons, 
> namebuf.str().c_str(), 0, NULL, NULL, b[s], b[s],
> TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
> for(i=1;i<=A;i++)
> {
> if(n == Arcs[i][j])
> { SCIP_CALL_EXC( SCIPaddCoefLinear(scip, cons, _vars[i*K - shift], 
> 1.0) ); }
>
> else if(n == Arcs[i][j+1])
> { SCIP_CALL_EXC( SCIPaddCoefLinear(scip, cons, _vars[i*K - shift], 
> -1.0) );}
> }
>
> SCIP_CALL_EXC( SCIPaddCons(scip, cons) );
> _cons.push_back(cons);
> s++;
> }
> }
>
>
> Please suggest if anything is wrong.
>
> -- 
> Thanks with Best Regards,
> Sheetal
>
>
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> http://listserv.zib.de/mailman/listinfo/scip

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.zib.de/mailman/private/scip/attachments/20120307/5026b834/attachment.html


More information about the Scip mailing list