I want to solve the model iteratively and in every iteration, the time is increasing by one period. In every iteration, I solve the model again. So, I wonder if I can assign the first-period result of the decision variable in the first iteration to the first period in the second iteration. For example, in the first iteration, the time period is T=7
and in the next iteration, it becomes T=8
. If decision variable is x_t,n
in which t
is time and n
is iteration counter, can I assign x_1,1
result to x_1,2
in docplex? My aim is to use the rolling-horizon technique.
Asked
Active
Viewed 469 times
0

Nari90
- 23
- 2
-
Could you precise whether you are solving the _same_ model instance at each iteration or re creating new instances? Also, do you want to assign values to variables as hard constraints, or as starting values for finding an optimal solution? There are different answers depending in which case you are.. – Philippe Couronne Jan 01 '21 at 15:28
-
Hi. I create random numbers in each iteration with a predetermined range. With each iteration there is an increase in time so, when the model implements the first iteration we save the value of the first period and assign it to the first period of the second iteration. Then, when we optimize the second iteration we save the value of the second period and assign it to the second period of the third iteration and so on. It is like 1st iteration value `x_1_1` to `x_1_2`, 2nd iteration value `x_2_2` to `x_2_3`, 3rd iteration `x_3_3` to `x_3_4` and etc. – Nari90 Jan 02 '21 at 08:18
1 Answers
1
In this answer, I am assuming you are using one instance of DOcplex model. Models are incremental and editable, that is , once solved, you can still add new variables and constraints to a model and solve again. The previous solution will be used as a starting point (if feasible) or used as heuristic (if not feasible).
There are several ways to set a variable value:
- first by setting its lower and upper bound to the same value v: this is a hard constraint, as in
x.lb = 3 x.ub = 3
- or by adding an explicit constraint This is also a hard constraint, adds one constraint to the problem. CPLEX pre-solve should naturally simplify this, but this adds complexity. This approach can be preferred when the model might become infeasible; using priorities, you might explore ways to make it back feasible by relaxing some constraints.
Example code
c3 = (x==3)
mdl.add(c3)
A different approach is to build a "warm start" solution with variable values, to be used as a starting point, assuming you are solving a Mixed Integer program.
In this approach, values are used as heuristic starting points, not as hard constraints;
in other terms, values can be changed by the solve.
See Model.add_mip_start()
for more details.

Philippe Couronne
- 826
- 1
- 5
- 6
-
As you mentioned I have used a hard constraint method. I've created the dictionary where I save the result of the previous iteration. For ex. I saved the first period, first iteration solution `(x_1st period^1st iter.)` and in the second iteration I have used it to assign to first period, second iteration `(x_1st period^2nd iter.)`. In my model however, I have a lot of variables. So, saving them in the dictionary and then assigning them in the new iteration took a lot of time because of every time the algorithm searches for the variables' value to assign in the new iteration. – Nari90 Jan 23 '21 at 13:05