I need to find whether an integer variable is an odd or even number. The problem is as follows.
For a set i /1:5/;
Integer variable x(i);
Variable a(i), OF;
if x(i) is odd, then a(i) => 10;
if x(i) is even, then a(i) <= 10;
x.lo(i) = 0;
x.up(i) = 10;
I need to minimize OF = sum(i,a(i));
I tried this but I am unable to figure it out. Since we can't use variables in conditional (logical) statements using $. I don't know how to do it. COuld anyone please help me with this?
Code: Select all
Set i 'buses' /1:5/;
Parameters
b value /10/;
display b;
Integer Variables x;
Variable a, OF;
Equation cons1, cons2;
cons1(i).. a(i)$(mod(x(i),2)=0) =g= b;
cons2(i).. a(i)$(mod(x(i),2)=1) =l= b;
Equation obj;
obj.. OF =g= sum((i), a(i));
x.up(i) = 10;
x.lo(i) = 0;
Model OddEven / all /;
OPTION MINLP = BARON;
solve OddEven using MINLP minimizing OF;
display OF.l, x.l, a.l;