Originally posted by: Martin-B
Hello,
I am having troubles using a decision variable as an index for a stepwise function. Taking the short model description below, it works correctly as long as I index the stepwise function with a range index:
range Periods = 0..3;
dvar int+ cost[Periods];
stepFunction stepF = stepwise{ 10 -> 2; 20 -> 3; 0 };
minimize sum(t in Periods) cost[t];
forall(t in Periods)
{
cost[t] == stepF(t);
}
The results are cost = [10 10 20 0], which is correct. The indices used are t = 0 1 2 3.
I am trying to use a decision variable as the index for the stepwise function. While it is syntactically possible to do so, the results are odd. The model is extended by a decision variable, which always takes the value of the range index t. This variable is used to index the stepwise function:
range Periods = 0..3;
dvar int+ cost[Periods];
stepFunction stepF = stepwise{ 10 -> 2; 20 -> 3; 0 };
minimize sum(t in Periods) cost[t];
forall(t in Periods)
{
period[t] == t;
}
forall(t in Periods)
{
cost[t] == stepF(period[t]);
}
If I minimize this model, the results will be cost = [10 10 10 0] and period = [0 1 2 3]. If I maximize the objective function, the results will be cost = [10 10 20 20] and period = [0 1 2 3]. While the decision variable takes the same values as the range index in the model before, the results are very different.
So my questions are:
Why is the outcome of a stepwise function different if I index it with an decision variable? Is it based on my formulation, and what can I do to get the desired result (which is an parameter from an array of parameters, chosen based on a value of a decision variable)?
Best regards,
Martin
#DecisionOptimization#OPLusingCPLEXOptimizer