You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/OnlineDocs/explanation/analysis/alternative_solutions.rst
+132-11
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,15 @@ Optimization solvers are generally designed to return a feasible solution
6
6
to the user. However, there are many applications where a user needs
7
7
more context than this result. For example,
8
8
9
-
* alternative solutions can support an assessment of trade-offs between competing objectives;
9
+
* alternative solutions can support an assessment of trade-offs between
10
+
competing objectives;
10
11
11
-
* if the optimization formulation may be inaccurate or untrustworthy, then comparisons amongst alternative solutions provide additional insights into the reliability of these model predictions; or
12
+
* if the optimization formulation may be inaccurate or untrustworthy,
13
+
then comparisons amongst alternative solutions provide additional
14
+
insights into the reliability of these model predictions; or
12
15
13
-
* the user may have unexpressed objectives or constraints, which only are realized in later stages of model analysis.
16
+
* the user may have unexpressed objectives or constraints, which only
17
+
are realized in later stages of model analysis.
14
18
15
19
The *alternative-solutions library* provides a variety of functions that
16
20
can be used to generate optimal or near-optimal solutions for a pyomo
@@ -31,21 +35,29 @@ The following functions are defined in the alternative-solutions library:
31
35
32
36
* ``enumerate_linear_solutions_soln_pool``
33
37
34
-
* Finds alternative optimal solutions for a (mixed-binary) linear program using Gurobi's solution pool feature.
38
+
* Finds alternative optimal solutions for a (mixed-binary) linear
39
+
program using Gurobi's solution pool feature.
35
40
36
41
* ``gurobi_generate_solutions``
37
42
38
-
* Finds alternative optimal solutions for discrete variables using Gurobi's built-in solution pool capability.
43
+
* Finds alternative optimal solutions for discrete variables using
44
+
Gurobi's built-in solution pool capability.
39
45
40
46
* ``obbt_analysis_bounds_and_solutions``
41
47
42
-
* Calculates the bounds on each variable by solving a series of min and max optimization problems where each variable is used as the objective function. This can be applied to any class of problem supported by the selected solver.
48
+
* Calculates the bounds on each variable by solving a series of min
49
+
and max optimization problems where each variable is used as the
50
+
objective function. This can be applied to any class of problem
51
+
supported by the selected solver.
43
52
44
53
45
-
Usage Example
46
-
-------------
54
+
Basic Usage Example
55
+
-------------------
47
56
48
-
Many of functions in the alternative-solutions library have similar options, so we simply illustrate the ``enumerate_binary_solutions`` function. We define a simple knapsack example whose alternative solutions have integer objective values ranging from 0 to 90.
57
+
Many of the functions in the alternative-solutions library have similar
58
+
options, so we simply illustrate the ``enumerate_binary_solutions``
59
+
function. We define a simple knapsack example whose alternative
60
+
solutions have integer objective values ranging from 0 to 90.
49
61
50
62
.. doctest::
51
63
@@ -60,7 +72,9 @@ Many of functions in the alternative-solutions library have similar options, so
60
72
>>> m.o = pyo.Objective(expr=sum(values[i] * m.x[i] for i inrange(4)), sense=pyo.maximize)
61
73
>>> m.c = pyo.Constraint(expr=sum(weights[i] * m.x[i] for i inrange(4)) <= capacity)
62
74
63
-
We can execute the ``enumerate_binary_solutions`` function to generate a list of ``Solution`` objects that represent alternative optimal solutions:
75
+
We can execute the ``enumerate_binary_solutions`` function to generate a
76
+
list of ``Solution`` objects that represent alternative optimal
77
+
solutions:
64
78
65
79
.. doctest::
66
80
:skipif: not glpk_available
@@ -69,7 +83,9 @@ We can execute the ``enumerate_binary_solutions`` function to generate a list of
Each ``Solution`` object contains information about the objective and variables, and it includes various methods to access this information. For example:
86
+
Each ``Solution`` object contains information about the objective and
87
+
variables, and it includes various methods to access this information.
88
+
For example:
73
89
74
90
.. doctest::
75
91
:skipif: not glpk_available
@@ -88,6 +104,111 @@ Each ``Solution`` object contains information about the objective and variables,
88
104
}
89
105
90
106
107
+
Gap Usage Example
108
+
-----------------
109
+
110
+
When we only want some of the solutions based off a tolerance away from
111
+
optimal, this can be done using the ``abs_opt_gap`` parameter. This is
112
+
shown in the following simple knapsack examples where the weights and
113
+
values are the same.
114
+
115
+
.. doctest::
116
+
:skipif: not glpk_available
117
+
118
+
>>> import pyomo.environ as pyo
119
+
>>> import pyomo.contrib.alternative_solutions as aos
120
+
121
+
>>> values = [10,9,2,1,1]
122
+
>>> weights = [10,9,2,1,1]
123
+
124
+
>>> K =len(values)
125
+
>>> capacity =12
126
+
127
+
>>> m = pyo.ConcreteModel()
128
+
>>> m.x = pyo.Var(range(K), within=pyo.Binary)
129
+
>>> m.o = pyo.Objective(expr=sum(values[i] * m.x[i] for i inrange(K)), sense=pyo.maximize)
130
+
>>> m.c = pyo.Constraint(expr=sum(weights[i] * m.x[i] for i inrange(K)) <= capacity)
0 commit comments