Originally posted by: SystemAdmin
[jfk said:]
Hello,
in your example in the if's there seems to be some confusing logic:
1. the first condition says if "b>1" is true then you require "over == b-1". OK
2. after the first "else" the condition is "NOT(b>1) AND b<10" which means "b<=1 AND b<10" which will be true if b<=1. For this condition you would like to have "over == 10-b"; still OK though...<br />3. then after the last "else" the condition is (NOT(NOT(b>1)AND(b<10)) -> b>1 OR b>=10. For this condition you would like to have over == 0;
so according to no.3 if b>1... then over==0 but according to no.1 if b>1 then over==b-1, which can never happen at the same time.
anyway...
in OPL with the logical operators "=> - implication", "&& - AND", "|| - OR" you can do the following:
float a_max=1;
float a_min=10;
float eps=0.001;
dvar float+ b;
dvar float+ over;
//minimize
// b;
subject to {
b>=a_max+eps => over == b-a_max;
b<=a_max && b<=a_min-eps => over == a_min-b;
b>=a_max+eps || b>=a_min => over ==0;
};
note: the strict greater (smaller) had to be changed with greater(smaller) or equal so I introduced eps=0.001
otherwise you have to introduce some indicator variable(s) with bigM and post some constraints. Say t={0,1} integer, and t=1 means the case where
if b>=a_max+eps then over == b-a_max;
with "t" you can express this by:
b>=t*(a_max+eps) -(1-t)*BigMr;
over>=b-a_max - (1-t)*BigM;
over<=b-a_max + (1-t)*BigM;<br />
I hope it helps
cheers
#DecisionOptimization#MathematicalProgramming-General