Skip to content

Commit 0cb7c71

Browse files
committed
Fix typo in diet problem case study
1 parent a0423fb commit 0cb7c71

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

Diff for: examples/doc/samples/case_studies/diet/DietProblem.tex

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ \subsection*{Build the model}
5454

5555
The comma indicates that this parameter is over two different sets, and thus is in two dimensions. When we create the data file, we will be able to fill in how much of each nutrient each food contains.
5656

57-
At this point we have defined our sets and parameters. However, we have yet to cosnider the amount of food to be bought and eaten. This is the variable weâre trying to solve for, and thus we create an object of the variable class. Since this is just recording how much food to purchase, we create a one dimensional variable over food:
57+
At this point we have defined our sets and parameters. However, we have yet to consider the amount of food to be bought and eaten. This is the variable weâre trying to solve for, and thus we create an object of the variable class. Since this is just recording how much food to purchase, we create a one dimensional variable over food:
5858

5959
\begin{verbatim}model.amount=Var(model.foods, within = NonNegativeReals) \end{verbatim}
6060

6161
We restrict our domain to the non-negative reals. If we accepted negative numbers than the model could tell us to buy negative amounts of food, which is an unrealistic---and thus useless---model. We could further restrict the domain to the integers to make it more realistic, but that would make the problem much harder for little gain: if this model is used on a large scale than the difference between the integer solution and the non-integer solution is often irrelevant.
6262

6363
At this point we must start defining the rules associated with our parameters and variables. We begin with the most important rule, the cost rule, which will tell the model to try and minimize the overall cost. Logically, the total cost is going to be the sum of how much is spent on each food, and that value in turn is going to be determined by the cost of the food and how much of it is purchased. For example, if three \$5 hamburgers and two \$1 apples are purchased, than the total cost would be $3 \cdot 5 + 2 \cdot 1 = 17$. Note that this process is the same as taking the dot product of the amounts vector and the costs vector.
6464

65-
To input this, we must define the cost rule, which we creatively call costRule as
65+
To input this, we must define the cost rule, which we creatively call costRule as
6666

6767
\begin{verbatim}def costRule(model):
6868
return sum(model.costs[n]*model.amount[n] for n in model.foods)
@@ -75,10 +75,10 @@ \subsection*{Build the model}
7575

7676
This line defines the objective of the model as the costRule, which Pyomo interprets as the value it needs to minimize; in this case it will minimize our costs. Also, as a note, we defined the objective as ``model.cost'' which is not to be confused with the parameter we defined earlier as ``model.costs,'' despite their similar names. These are two different values and accidentally giving them the same name will cause problems when trying to solve the problem.
7777

78-
We must also create a rule for the volume consumed. The construction of this rule is similar to the cost rule as once again we take the dot product, this time between the volume and amount vectors.
78+
We must also create a rule for the volume consumed. The construction of this rule is similar to the cost rule as once again we take the dot product, this time between the volume and amount vectors.
7979

8080
\begin{verbatim}def volumeRule(model):
81-
return sum(model.volumes[n]*model.amount[n] for n in
81+
return sum(model.volumes[n]*model.amount[n] for n in
8282
model.foods) <= model.max_volume
8383
8484
model.volume = Constraint(rule=volumeRule)
@@ -90,7 +90,7 @@ \subsection*{Build the model}
9090

9191
\begin{verbatim}
9292
def nutrientRule(n, model):
93-
value = sum(model.nutrient_value[n,f]*model.amount[f]
93+
value = sum(model.nutrient_value[n,f]*model.amount[f]
9494
for f in model.foods)
9595
return (model.min_nutrient[n], value, model.max_nutrient[n])
9696
@@ -160,7 +160,7 @@ \subsection*{Data entry}
160160

161161
The amount of spaces between each element is irrelevant (as long as there is at least one) so the matrix should be formatted for ease of reading.
162162

163-
Now that we have finished both the model and the data file save them both. It's convention to give the model file a .py extension and the data file a .dat extension.
163+
Now that we have finished both the model and the data file save them both. It's convention to give the model file a .py extension and the data file a .dat extension.
164164

165165
\subsection*{Solution}
166166

Diff for: examples/doc/samples/case_studies/diet/README.txt

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ to import the Pyomo package for use in the code. The next step is to create an
1414

1515
{{{
1616
#!python
17-
model = AbstractModel()
17+
model = AbstractModel()
1818
}}}
1919
The rest of our work will be contained within this object.
2020

@@ -68,7 +68,7 @@ model.nutrient_value=Param(model.nutrients, model.foods)
6868

6969
The comma indicates that this parameter is over two different sets, and thus is in two dimensions. When we create the data file, we will be able to fill in how much of each nutrient each food contains.
7070

71-
At this point we have defined our sets and parameters. However, we have yet to cosnider the amount of food to be bought and eaten. This is the variable we're trying to solve for, and thus we create an object of the variable class. Since this is just recording how much food to purchase, we create a one dimensional variable over food:
71+
At this point we have defined our sets and parameters. However, we have yet to consider the amount of food to be bought and eaten. This is the variable we're trying to solve for, and thus we create an object of the variable class. Since this is just recording how much food to purchase, we create a one dimensional variable over food:
7272

7373
{{{
7474
#!python
@@ -79,7 +79,7 @@ We restrict our domain to the non-negative reals. If we accepted negative numbe
7979

8080
At this point we must start defining the rules associated with our parameters and variables. We begin with the most important rule, the cost rule, which will tell the model to try and minimize the overall cost. Logically, the total cost is going to be the sum of how much is spent on each food, and that value in turn is going to be determined by the cost of the food and how much of it is purchased. For example, if three !$5 hamburgers and two !$1 apples are purchased, than the total cost would be 3*5 + 2*1 = 17. Note that this process is the same as taking the dot product of the amounts vector and the costs vector.
8181

82-
To input this, we must define the cost rule, which we creatively call costRule as
82+
To input this, we must define the cost rule, which we creatively call costRule as
8383

8484
{{{
8585
#!python
@@ -95,7 +95,7 @@ model.cost=Objective(rule=costRule
9595

9696
This line defines the objective of the model as the costRule, which Pyomo interprets as the value it needs to minimize; in this case it will minimize our costs. Also, as a note, we defined the objective as "model.cost" which is not to be confused with the parameter we defined earlier as `"model.costs" despite their similar names. These are two different values and accidentally giving them the same name will cause problems when trying to solve the problem.
9797

98-
We must also create a rule for the volume consumed. The construction of this rule is similar to the cost rule as once again we take the dot product, this time between the volume and amount vectors.
98+
We must also create a rule for the volume consumed. The construction of this rule is similar to the cost rule as once again we take the dot product, this time between the volume and amount vectors.
9999

100100
{{{
101101
#!python
@@ -112,7 +112,7 @@ Finally, we need to add the constraint that ensures we obtain proper amounts of
112112
{{{
113113
#!python
114114
def nutrientRule(n, model):
115-
value = sum(model.nutrient_value[n,f]*model.amount[f]
115+
value = sum(model.nutrient_value[n,f]*model.amount[f]
116116
for f in model.foods)
117117
return (model.min_nutrient[n], value, model.max_nutrient[n])
118118

@@ -179,7 +179,7 @@ vc 0 30 0;
179179

180180
The amount of spaces between each element is irrelevant (as long as there is at least one) so the matrix should be formatted for ease of reading.
181181

182-
Now that we have finished both the model and the data file save them both. It's convention to give the model file a .py extension and the data file a .dat extension.
182+
Now that we have finished both the model and the data file save them both. It's convention to give the model file a .py extension and the data file a .dat extension.
183183

184184
== Solution ==
185185

@@ -193,7 +193,7 @@ Using Pyomo we quickly find the solution to our diet problem. Simply run Pyomo
193193
# ----------------------------------------------------------
194194
# Problem Information
195195
# ----------------------------------------------------------
196-
Problem:
196+
Problem:
197197
- Lower bound: 29.44055944
198198
Upper bound: inf
199199
Number of objectives: 1
@@ -205,28 +205,28 @@ Problem:
205205
# ----------------------------------------------------------
206206
# Solver Information
207207
# ----------------------------------------------------------
208-
Solver:
208+
Solver:
209209
- Status: ok
210210
Termination condition: unknown
211211
Error rc: 0
212212

213213
# ----------------------------------------------------------
214214
# Solution Information
215215
# ----------------------------------------------------------
216-
Solution:
216+
Solution:
217217
- number of solutions: 1
218218
number of solutions displayed: 1
219219
- Gap: 0.0
220220
Status: optimal
221-
Objective:
222-
f:
221+
Objective:
222+
f:
223223
Id: 0
224224
Value: 29.44055944
225-
Variable:
226-
amount[rice]:
225+
Variable:
226+
amount[rice]:
227227
Id: 0
228228
Value: 9.44056
229-
amount[apple]:
229+
amount[apple]:
230230
Id: 2
231231
Value: 10
232232

0 commit comments

Comments
 (0)