Walkthrough: Creating and Solving a Nonlinear Model

# Walkthrough: Creating and Solving a Nonlinear Model

Solver Foundation 3.0

You can use Optimization Modeling Language (OML) to create and solve nonlinear models. This topic provides an example of a nonlinear model that minimizes fuel consumption on a shipping route. The objective is to minimize the fuel consumption and emissions on the shipping route by optimizing speed on each segment of the shipping route. This example is based on a problem described by K Fagerholt, G Laporte, and I Norstad in Journal of the Operational Research Society 61 (March, 2010), pages 523-529.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

### To add the route segment data

• In an Excel worksheet, enter the following data. The following table shows port identifiers, segment identifiers, the distance of each segment, and boundaries for departure from port that specify the earliest and latest time that a ship may depart from port. The time values are in elapsed days. The table also includes two columns for output data: a time column representing the sailing time, and a speed column for the ship speed, in knots. These two columns do not contain any data initially.

Port

Segment

Distance

Early

Late

Time

Speed

0

0

0

0

0

1

1

510

1

4

2

2

2699

50

65

3

3

838

70

75

4

4

3625

74

80

The segments represent the following starting ports, in order:

• Vancouver

• Seattle

• Busan

• Kaohsiung

• Hong Kong

### To add the model

1. On the Solver Foundation tab in Excel, click Model to open the Modeling Pane.

2. On the Model tab of the Modeling Pane, click Manual in the Editing Mode list.

3. Copy the following OML model into the lower pane.

The OML model includes the following elements:

• A set named Segments that represents route segments.

• A parameter named Distance that represents the distances of the route segments, and two parameters named Early and Late that represent the earliest and latest possible departure times.

• A decision named Speed that represents the speed in knots, a decision named Time that represents the departure time, and a decision named Wait that represents idle time spent waiting in port. Upper and lower bounds are specified for each decision.

Tip

When you solve a nonlinear model by using the hybrid local search solver, include domain restrictions on the decisions when possible. For more information, see Solving Nonlinear Models using the Default Solver.

• A constraint named bounds that restricts the departure time based on the early and late values, a constraint named times that calculates the departure time for the current segment, and a third constraint named wait_0 sets the initial wait time value.

• A goal named fuel that specifies that the solver should minimize fuel consumption. The goal includes a cubic function to calculate fuel consumption, which also accounts for time spent waiting in port.

The following OML code shows the model.

```Model[
Parameters[
Sets[Integers[-Infinity, Infinity]],
Segments
],
Parameters[
Reals[0, Infinity],
Distance[Segments]
],
Parameters[
Reals[-Infinity, Infinity],
Early[Segments],
Late[Segments]
],
Decisions[
Reals[14, 20],
Speed[Segments]
],
Decisions[
Reals[0, 2400],
Time[Segments]
],
Decisions[
Reals[0, 2400],
Wait[Segments]
],
Constraints[
bounds -> Foreach[{i, Segments}, Early[i] <= Time[i] <= Late[i]],
times -> FilteredForeach[{i, Segments}, i > 0, Time[i - 1] +
Distance[i - 1] / (24 * Speed[i - 1]) + Wait[i] == Time[i]],
wait_0 -> Wait[0] == 0
],
Goals[
Minimize[
fuel -> Annotation[Sum[{i, Segments}, Distance[i] * (0.0036 *
Speed[i]^2 - 0.1015 * Speed[i] + 0.8848) + 0.01 * Wait[i]],
"order", 0]
]
]
]

```
4. Select Automatic in the Editing Mode list to save the model.

### To bind route segment data to the model

1. Select all the data in the route segment table, including the column headings.

2. On the Parameters tab of the Modeling Pane, click the Distance parameter.

3. Click the ellipsis button (…) to the right of the Binding field.

4. In the Binding Editor for the parameter, select the Range Includes Column Data checkbox.

5. Select the following values:

• Set: Segments

• Column Header: Segment

• Value Field: Distance

6. Repeat the previous steps to bind route segment data to the Early parameter, but in the Binding Editor set the Value Field to Early.

7. Repeat the previous step to bind route segment data to the Late parameter, but in the Binding Editor set the Value Field to Late.

### To bind output values to the table

1. Select all the data in the route segment table, including the column headings.

2. On the Decisions tab of the Modeling Pane, click the Speed parameter.

3. Click the ellipsis button (…) to the right of the Binding field.

4. Select the following values:

• Set: Segments

• Column Header: Port

• Value Field: Speed

5. Repeat the previous steps to bind output values to the Time decision, but in the Binding Editor set the Value Field to Time.

### To solve the model

1. On the Solver Foundation tab, click Check.

2. On the Solver Foundation tab, click Solve.

3. On the Solver Foundation tab, click Summary.

## Output

```Solution Type   LocalOptimal
fuel                 1299.996132

Speed[0]  17.45048488
Speed[1]  14.0948877
Speed[2]  14.09720337
Speed[3]  14.09621516
Speed[4]  14.09722222

Time[0]   0
Time[1]   1.187654873
Time[2]   63.1493147
Time[3]   71.29733314
Time[4]   74

Wait[0]   0
Wait[1]   1.187654865
Wait[2]   60.45402099
Wait[3]   0.170667853
Wait[4]   0.225642613
```