[Scip] Adding variables and Constraints to MIP

sheetal murkute shvm11 at gmail.com
Wed Mar 7 22:51:52 MET 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.zib.de/mailman/private/scip/attachments/20120307/e7dc33ad/attachment.html


More information about the Scip mailing list