cplex for if-else statments

2019-07-13 02:53发布

I am new to cplex. In my ilp I have couple of if-else statement. I want to use cplex for solving my problem using java API. I don't know how to formulate if-else in cplex. example:

if x>0 then a=1
else if x=0 then a=0

标签: java cplex
1条回答
三岁会撩人
2楼-- · 2019-07-13 03:45

I don't think that the Java API supports the if/then/else structure, however it is possible to do if/then

IloCplex cplex = new IloCplex();
IloNumVar x = cplex.numVar(-100, 100);
IloNumVar a = cplex.intVar(0, 1);

cplex.ifThen(cplex.ge(x, 100), cplex.eq(a, 1));
cplex.ifThen(cplex.eq(x, 0), cplex.eq(a, 0));
查看更多
登录 后发表回答