cplex for if-else statments

陌路散爱 提交于 2019-12-10 23:35:23

问题


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

回答1:


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));


来源:https://stackoverflow.com/questions/13339623/cplex-for-if-else-statments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!