Is it possible to include a conditional expression ("condition ? exp1 : exp2") in CPLEX Java API? In OPL I can write this (x,y,c are decision variables)
(c==1 ? x+y : x ) == 0
but I didn't find the equivalent function in it's Java API
you could write
solver.addEq((c==1)?solver.sum(x,y):x,0);
Let me give you a tiny example
IloCplex solver = new IloCplex();
IloNumVar x = solver.numVar(0,10);
IloNumVar y = solver.numVar(0,10);
int c=1;
solver.addEq((c==1)?solver.sum(x,y):x,0);
solver.addMaximize(solver.sum(x,y));
solver.solve();
System.out.println("x = " + solver.getValue(x));
System.out.println("y = " + solver.getValue(y));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.