Hi,
let me explain with your example.
Take
int nRP=10;
range RPs=1..1;
range DPs=1..1;
int M = nRP; // Big M for Constraint 3
dvar int+ X[DPs][RPs] in 0..1; // Indicate if Resource[i] is assigned to Task[j]
dvar int+ Y[DPs] in 0..1; // Indicate if Resource[i] selected for pairing
dvar int+ Z[DPs]; // Indicates how many times Resource[i] has been used
float TotalCostC[i in DPs]=i*i*10;
dexpr float TotalCost=
sum (i in DPs)
stepwise { 0 -> 1;
(TotalCostC[i] + 848) -> 71 ;
(TotalCostC[i] + 1696) -> 141 ;
(TotalCostC[i] + 2544) -> 211 ;
(TotalCostC[i] + 3392) -> 281 ;
(TotalCostC[i] + 4240) -> 351 ; 10000} Z[i];
minimize (TotalCost); // Minimize Total Donor Cost
subject to
{
ct1: // (C1) Assign 1 Resource to each Task
forall (j in RPs)
sum (i in DPs)
X[i][j] == 1;
ct2: // (C2) Indicate if Resource[i] has been selected for pairing using Big M
forall (i in DPs)
sum(j in RPs)
X[i][j] <= M * Y[i];
// (C6) Count the # of Times Each Resource has been assigned
ct6:
forall (i in DPs)
sum (j in RPs)
X[i][j] == Z[i];
}
execute
{
writeln("TotalCost=",TotalCost)
writeln("obj=",cplex.getObjValue())
}
which gives
TotalCost=858
obj=0
Why do we have this discrepancy ?
Because during the solve,
stepwise { 0 -> 1;
(TotalCostC[i] + 848) -> 71 ;
means that if Z==1 then the value of the stepwise is either 0 or 848
Since we have a minimization model, 0 will be chosen
When evaluated, the stepwise will take the right value as said in
IDE and OPL > Optimization Programming Language (OPL) > Language Quick Reference > OPL keywords > stepwise
stepFunction f=stepwise {0->3; 2};
assert f(-1)==0;
assert f(3)==2;
assert f(3.1)==2;
This is the reason why you got surprised.
Now, in your case a workaround, not to have this discrepancy would be to write
float epsilon=0.001;
and then
stepwise { 0 -> 1+epsilon;
and then the model gives
TotalCost=0
obj=0
regards
#DecisionOptimization#OPLusingCPLEXOptimizer