本文介绍了if-else陈述的复数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的。在我的ilp中,我有一些if-else语句。我想使用cplex通过Java API解决我的问题。我不知道如何在cplex中制定if-else。
示例:

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 API支持if / then / else结构,但是可以执行if / then

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

这篇关于if-else陈述的复数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:07