Originally posted by: SystemAdmin
Hi all,
I'm working on a project in which I need to model that the outcome of a certain constraint must be 0 or 1. The constraint is of the form 'sum(a_i * b_i)'. I have no problem building the constraint and in order to enforce outcome being 0 or 1, I add
cplex.addLe( constraint, 1 );
Since my constraint is a IloLinearIntExpr, I'm sure that my outcome will be an int lower than 1, and constraints on a and b ensure the outcome will never be lower than 0. So I know the outcome is 0 or 1.
But now I want to do the exact same thing, but enforce the outcome to be 0 or 2. I found the semiContVar constructor, which I use to in
IloNumVar range = cplex.semiContVar( 2, 2, IloNumVarType.Int );
cplex.addEq( constraint, range );
My assumption was that 'range' now could be made either 0 or 2 (in my understanding semiContVar can be either 0, or a value between the given lower bound and upper bound, which I both set to 2) and because 'constraint' has to equal 'range', the outcome could also be either 0 or 2.
But my program only returns 0 as a result, while I am sure that I use examples where, for some i, outcome 2 would be a better choise. Can someone help me out with what I'm doing wrong here? Or provide me with an easier solution to model my problem?
Thanks in advance.
#CPLEXOptimizers#DecisionOptimization