[Scip] Nonlinear Constraint

Stefan Vigerske stefan at math.hu-berlin.de
Fri Jan 27 16:39:10 MET 2012


Hi,

> I am currently trying so run / solve my first nonlinear problems with scip. Sadly, I am not totally understanding how I can add nonlinear constraints.

Sorry, there are no nice examples yet.

> For example, I want to create a "simple" constraint as x*y<= 1.

For this constraint, you could also create a quadratic constraint directly.

SCIP_VAR* x = ...;
SCIP_VAR* y = ...;
SCIP_Real one = 1.0;
SCIP_CALL( SCIPcreateConsQuadratic(scip, &cons, "myconstraint", 0, NULL, 
NULL, 1, &x, &y, &one, -SCIPinfinity(scip), 1.0,
TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );

> Am I right, that in general, these constraints are build up from an amount of (linear) variables / coefficients and an additional expression tree for the nonlinear part of the constraint?

Yes.

> I did the following but it did not work :/
>
> (scip pointer already decleared)
>
> // get memory
> BMS_BLKMEM* blkmem = SCIPblkmem(_scip);
>
> SCIP_EXPRTREE* tree;
> SCIP_EXPR* root;
> SCIP_Real* params = NULL;
>
> // create root expression
> SCIPexprCreate(blkmem,&root, SCIP_EXPR_MUL);

That did not trigger an assert?

> //set childs for multiply / rood node
> SCIP_EXPR ** child = new SCIP_EXPR*[SCIPexprGetNChildren(root)];
> child = SCIPexprGetChildren(root);
> SCIPexprCreate(blkmem,&child[0], SCIP_EXPR_VARIDX, 0);
> SCIPexprCreate(blkmem,&child[1], SCIP_EXPR_VARIDX, 1);

Almost good.

You need to setup the tree from the leaves to the root:

SCIP_EXPR* child[2];
SCIP_CALL( SCIPexprCreate(blkmem, &child[0], SCIP_EXPR_VARIDX, 0) );
SCIP_CALL( SCIPexprCreate(blkmem, &child[1], SCIP_EXPR_VARIDX, 1) );
SCIP_CALL( SCIPexprCreate(blkmem, &root, SCIP_EXPR_MUL, child[0], 
child[1]) );

> //create a tree of this expression
> SCIPexprtreeCreate(blkmem,&tree, root, 0, 0, params);
>
> // give the variables to the tree - vars_ have already been decleared as usual
> SCIPexprtreeAddVars(tree, 2,vars_ );
>
> SCIP_EXPRTREE** tree_cont = new SCIP_EXPRTREE*[1];
> tree_cont[0] =  tree;
> SCIP_CONS* nl_cons;
> std::string name = "nl_test";
> SCIPcreateConsNonlinear(_scip,&nl_cons, name.c_str(), 0, NULL, NULL, 1,tree_cont,
>        NULL, -SCIPinfinity(_scip), 1, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE);
ok, but easier:
SCIP_CALL( SCIPcreateConsNonlinear(_scip, &nl_cons, "nl_test",
0, NULL, NULL, 1, &tree, NULL, -SCIPinfinity(_scip), 1,
TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );


> SCIPaddCons(_scip, nl_cons);
>
> At start I included the ConshdlrNonlinear and the NodeselBfs. When I try to solve the model, I get the message:
> (solver started, presolving is done)
> [src/scip/cons_nonlinear.c:2022] Warning: indefinite expression tree in constraint<nltester>

Probably this has to do with the wrong tree.

> [src/scip/cons_nonlinear.c:3508] ERROR: Error<-11>  in function call
> [src/scip/cons_nonlinear.c:7193] ERROR: Error<-11>  in function call
> [src/scip/cons.c:3019] ERROR: Error<-11>  in function call
> [src/scip/sol.c:1207] ERROR: Error<-11>  in function call
> [src/scip/primal.c:1147] ERROR: Error<-11>  in function call
> [src/scip/solve.c:2439] ERROR: Error<-11>  in function call
> [src/scip/solve.c:3062] ERROR: Error<-11>  in function call
> [src/scip/solve.c:3297] ERROR: Error<-11>  in function call
> [src/scip/solve.c:3879] ERROR: Error<-11>  in function call
> [src/scip/scip.c:7543] ERROR: Error<-11>  in function call
>
> What did I do wrong?

Try OPT=dbg :-).

Stefan

>
> Best regards
> Martin
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> http://listserv.zib.de/mailman/listinfo/scip
>


-- 
Stefan Vigerske
Humboldt University Berlin, Numerical Mathematics
http://www.math.hu-berlin.de/~stefan


More information about the Scip mailing list