# 6.11 Problem Modification and Reoptimization¶

Often one might want to solve not just a single optimization problem, but a sequence of problems, each differing only slightly from the previous one. This section demonstrates how to modify and re-optimize an existing problem.

The example we study is a simple production planning model.

Problem modifications regarding variables, cones, objective function and constraints can be grouped in categories:

add/remove,

coefficient modifications,

bounds modifications.

Especially removing variables and constraints can be costly. Special care must be taken with respect to constraints and variable indexes that may be invalidated.

Depending on the type of modification, **MOSEK** may be able to optimize the modified problem more efficiently exploiting the information and internal state from the previous execution. After optimization, the solution is always stored internally, and is available before next optimization. The former optimal solution may be still feasible, but no longer optimal; or it may remain optimal if the modification of the objective function was small. This special case is discussed in Sec. 14.3 (Sensitivity Analysis).

In general, **MOSEK** exploits dual information and availability of an optimal basis from the previous execution. The simplex optimizer is well suited for exploiting an existing primal or dual feasible solution. Restarting capabilities for interior-point methods are still not as reliable and effective as those for the simplex algorithm. More information can be found in Chapter 10 of the book [Chvatal83].

Parameter settings (see Sec. 7.5 (Setting solver parameters)) can also be changed between optimizations.

## 6.11.1 Example: Production Planning¶

A company manufactures three types of products. Suppose the stages of manufacturing can be split into three parts: Assembly, Polishing and Packing. In the table below we show the time required for each stage as well as the profit associated with each product.

Product no. |
Assembly (minutes) |
Polishing (minutes) |
Packing (minutes) |
Profit ($) |
---|---|---|---|---|

0 |
2 |
3 |
2 |
1.50 |

1 |
4 |
2 |
3 |
2.50 |

2 |
3 |
3 |
2 |
3.00 |

With the current resources available, the company has \(100,000\) minutes of assembly time, \(50,000\) minutes of polishing time and \(60,000\) minutes of packing time available per year. We want to know how many items of each product the company should produce each year in order to maximize profit?

Denoting the number of items of each type by \(x_0,x_1\) and \(x_2\), this problem can be formulated as a linear optimization problem:

and

Code in Listing 6.20 loads and solves this problem.

```
let numcon = 3;
let numvar = 3;
let c = &[1.5, 2.5, 3.0 ];
let bkc = &[ Boundkey::UP,
Boundkey::UP,
Boundkey::UP ];
let blc = &[ -INF,
-INF,
-INF ];
let buc = &[ 100000.0,
50000.0,
60000.0 ];
let bkx = &[ Boundkey::LO,
Boundkey::LO,
Boundkey::LO
];
let blx = &[ 0.0, 0.0, 0.0 ];
let bux = &[ INF,
INF,
INF ];
let asub = &[
&[ 0i32, 1, 2 ],
&[ 0i32, 1, 2 ],
&[ 0i32, 1, 2 ] ];
let aval = &[
&[ 2.0, 3.0, 2.0 ],
&[ 4.0, 2.0, 3.0 ],
&[ 3.0, 3.0, 2.0 ] ];
let mut task = Task::new().unwrap();
/* Append the constraints. */
task.append_cons(numcon)?;
/* Append the variables. */
task.append_vars(numvar)?;
/* Put C. */
for (j,&cj) in (0..numvar).zip(c.iter()) {
task.put_c_j(j,cj)?;
}
/* Put constraint bounds. */
for (i,&bki,&bli,&bui) in izip!(0..numcon,bkc,blc,buc) {
task.put_con_bound(i, bki, bli, bui)?;
}
/* Put variable bounds. */
for (j,&bki,&bli,&bui) in izip!(0..numvar,bkx,blx,bux) {
task.put_var_bound(j, bki, bli, bui)?;
}
/* Put A. */
if numcon > 0 {
for (j,&asubj,&avalj) in izip!(0..numvar,asub,aval) {
task.put_a_col(j,
asubj,
avalj)?;
}
}
/* A maximization problem */
task.put_obj_sense(Objsense::MAXIMIZE)?;
/* Solve the problem */
let _trm = task.optimize()?;
let mut xx = vec![0.0; task.get_num_var()? as usize];
task.get_xx(Soltype::BAS, // Request the basic solution.
xx.as_mut_slice())?;
```

## 6.11.2 Changing the Linear Constraint Matrix¶

Suppose we want to change the time required for assembly of product \(0\) to \(3\) minutes. This corresponds to setting \(a_{0,0} = 3\), which is done by calling the function `Task.put_aij`

as shown below.

```
task.put_aij(0, 0, 3.0)?;
```

The problem now has the form:

and

After this operation we can reoptimize the problem.

## 6.11.3 Appending Variables¶

We now want to add a new product with the following data:

Product no. |
Assembly (minutes) |
Polishing (minutes) |
Packing (minutes) |
Profit ($) |
---|---|---|---|---|

3 |
4 |
0 |
1 |
1.00 |

This corresponds to creating a new variable \(x_3\), appending a new column to the \(A\) matrix and setting a new term in the objective. We do this in Listing 6.21

```
/***************** Add a new variable ******************************/
/* Get index of new variable. */
let varidx = task.get_num_var()?;
/* Append a new variable x_3 to the problem */
task.append_vars(1)?;
let numvar = numvar + 1;
/* Set bounds on new varaible */
task.put_var_bound(varidx, Boundkey::LO, 0.0, INF)?;
/* Change objective */
task.put_c_j(varidx, 1.0)?;
/* Put new values in the A matrix */
let acolsub = &[0i32, 2];
let acolval = &[4.0, 1.0];
task.put_a_col(varidx, /* column index */
acolsub,
acolval)?;
```

After this operation the new problem is:

and

## 6.11.4 Appending Constraints¶

Now suppose we want to add a new stage to the production process called *Quality control* for which \(30000\) minutes are available. The time requirement for this stage is shown below:

Product no. |
Quality control (minutes) |
---|---|

0 |
1 |

1 |
2 |

2 |
1 |

3 |
1 |

This corresponds to adding the constraint

to the problem. This is done as follows.

```
/********************** Add a new constraint ***************************/
/* Get index of new constraint. */
let conidx = task.get_num_con()?;
/* Append a new constraint */
task.append_cons(1)?;
let numcon = numcon + 1;
/* Set bounds on new constraint */
task.put_con_bound(conidx,
Boundkey::UP,
-INF,
30000.0)?;
/* Put new values in the A matrix */
let arowsub = &[0i32, 1, 2, 3 ];
let arowval = &[1.0, 2.0, 1.0, 1.0 ];
task.put_a_row(conidx, /* row index */
arowsub,
arowval)?;
```

Again, we can continue with re-optimizing the modified problem.

## 6.11.5 Changing bounds¶

One typical reoptimization scenario is to change bounds. Suppose for instance that we must operate with limited time resources, and we must change the upper bounds in the problem as follows:

Operation |
Time available (before) |
Time available (new) |
---|---|---|

Assembly |
100000 |
80000 |

Polishing |
50000 |
40000 |

Packing |
60000 |
50000 |

Quality control |
30000 |
22000 |

That means we would like to solve the problem:

In this case all we need to do is redefine the upper bound vector for the constraints, as shown in the next listing.

```
/********************** Change constraint bounds ********************/
let newbkc = &[Boundkey::UP,
Boundkey::UP,
Boundkey::UP,
Boundkey::UP];
let newblc = &[-INF,
-INF,
-INF,
-INF];
let newbuc = &[ 80000.0, 40000.0, 50000.0, 22000.0 ];
task.put_con_bound_slice(0, numcon, newbkc, newblc, newbuc)?;
```

Again, we can continue with re-optimizing the modified problem.

## 6.11.6 Advanced hot-start¶

If the optimizer used the data from the previous run to hot-start the optimizer for reoptimization, this will be indicated in the log:

```
Optimizer - hotstart : yes
```

When performing re-optimizations, instead of removing a basic variable it may be more efficient to fix the variable at zero and then remove it when the problem is re-optimized and it has left the basis. This makes it easier for **MOSEK** to restart the simplex optimizer.