Try our new documentation site (beta).


Specifying Multiple Scenarios

Your first step in building a multi-scenario model is to modify the NumScenarios attribute to indicate how many scenarios you would like to consider. Once you have changed this attribute, you can describe the different scenarios by changing various scenario-related attributes (listed below). When you later call optimize on a multi-scenario model (a model where NumScenarios is greater than 0), the solver will try to find optimal solutions for all specified scenarios. Note that it will not try to find a solution for the base model.

Variations in the different scenarios are expressed through a set of four attributes:

The first three are variable attributes, and the last is a linear constraint attribute. You can give each scenario a name through the ScenNName attribute (a model attribute).

You use the ScenarioNumber parameter to modify scenario attributes for a specific scenario. Scenarios are numbered 0 through NumScenarios-1. To give an example, to create a model where binary variable <span>$</span>x<span>$</span> is fixed to 0 and 1 in two scenarios, you would:

  • Set the NumScenarios attribute to 2, to indicate that your model has two scenarios.
  • Set the ScenarioNumber parameter to 0, to indicate that you would first like to modify scenario attributes for scenario 0.
  • Set the ScenNUB attribute for variable <span>$</span>x<span>$</span> to 0 (to fix the binary variable to zero in this scenario).
  • Set the ScenarioNumber parameter to 1, to move on to scenario 1.
  • Set the ScenNLB attribute for variable <span>$</span>x<span>$</span> to 1 (to fix the binary variable to one in this scenario).

You query scenario attributes in a similar manner: set the ScenarioNumber parameter to choose the scenario you would like to query, and then use the appropriate attribute query routine to obtain the desired attribute values (consult our Attribute Examples for examples).

Note that unmodified scenario attributes take a special value of GRB.UNDEFINED. If you modified a scenario attribute and would like to revert that modification, you can set the attribute back to GRB.UNDEFINED.

You can change the number of scenarios in your model as many times as you like (by modifying the NumScenarios attribute). When you increase the count, new empty scenarios are created (an empty scenario is a scenario with no changes from the base model). When you decrease the count, existing scenarios are discarded. When you set the count to zero, the model is no longer treated as a multi-scenario model.

We have extended the LP and MPS file formats, so writing a model with multiple scenarios to a file will capture those scenarios. Similarly, if you read a model file that contains multiple scenarios, then NumScenarios and the various scenario attributes will capture the scenarios stored in the file. See the file format section for details.

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization