blob: ec424457553e3b6cee1085901bb87e529a697de3 [file] [log] [blame]
Austin Schuh405fa6c2015-09-06 18:13:55 -07001(************** Content-type: application/mathematica **************
2
3 Mathematica-Compatible Notebook
4
5This notebook can be used with any Mathematica-compatible
6application, such as Mathematica, MathReader or Publicon. The data
7for the notebook starts with the line containing stars above.
8
9To get the notebook into a Mathematica-compatible application, do
10one of the following:
11
12* Save the data starting with the line of stars above into a file
13 with a name ending in .nb, then open the file inside the
14 application;
15
16* Copy the data starting with the line of stars above to the
17 clipboard, then use the Paste menu command inside the application.
18
19Data for notebooks contains only printable 7-bit ASCII and can be
20sent directly in email or through ftp in text mode. Newlines can be
21CR, LF or CRLF (Unix, Macintosh or MS-DOS style).
22
23NOTE: If you modify the data for this notebook not in a Mathematica-
24compatible application, you must delete the line below containing
25the word CacheID, otherwise Mathematica-compatible applications may
26try to use invalid cache data.
27
28For more information on notebooks and Mathematica-compatible
29applications, contact Wolfram Research:
30 web: http://www.wolfram.com
31 email: info@wolfram.com
32 phone: +1-217-398-0700 (U.S.)
33
34Notebook reader applications are available free of charge from
35Wolfram Research.
36*******************************************************************)
37
38(*CacheID: 232*)
39
40
41(*NotebookFileLineBreakTest
42NotebookFileLineBreakTest*)
43(*NotebookOptionsPosition[ 13920, 436]*)
44(*NotebookOutlinePosition[ 14959, 472]*)
45(* CellTagsIndexPosition[ 14871, 466]*)
46(*WindowFrame->Normal*)
47
48
49
50Notebook[{
51Cell[TextData[{
52 StyleBox["Diet Problem",
53 FontColor->RGBColor[0.0557107, 0.137819, 0.517113]],
54 "\nAn Application of Vertex Enumeration\nwith ",
55 StyleBox["MathLink",
56 FontSize->24,
57 FontSlant->"Italic",
58 FontColor->RGBColor[0.0146487, 0.461387, 0.0967727]],
59 " to ",
60 StyleBox["cddlib",
61 FontColor->RGBColor[0.517113, 0.0273594, 0.0273594]]
62}], "Title",
63 ImageRegion->{{0, 1}, {0, 1}},
64 FontSize->27],
65
66Cell[TextData[StyleBox["Komei Fukuda, fukuda@ifor.math.ethz.ch\nSwiss Federal \
67Institute of Technology, Lausanne and Zurich\nMarch 14, 1999",
68 FontSize->17,
69 FontSlant->"Italic"]], "Subtitle",
70 ImageRegion->{{0, 1}, {0, 1}}],
71
72Cell[CellGroupData[{
73
74Cell["Connecting cddmathlink", "Section",
75 InitializationCell->True,
76 ImageRegion->{{0, 1}, {0, 1}}],
77
78Cell[CellGroupData[{
79
80Cell[TextData[{
81 "You just put the compiled cddmathlink for your computer in some directory. \
82 In this example, the name of the directory is ",
83 StyleBox["\"~/Math\".",
84 FontFamily->"Courier",
85 FontWeight->"Bold"]
86}], "Text",
87 InitializationCell->True,
88 ImageRegion->{{0, 1}, {0, 1}}],
89
90Cell["Off[General::spell1]; Off[General::spell];", "Input",
91 InitializationCell->True,
92 ImageRegion->{{0, 1}, {0, 1}}],
93
94Cell[CellGroupData[{
95
96Cell["cddml=Install[\"~/Math/cddmathlink\"]", "Input",
97 InitializationCell->True,
98 ImageRegion->{{0, 1}, {0, 1}}],
99
100Cell[BoxData[
101 \(LinkObject["/Users/fukuda/Math/cddmathlink", 7, 7]\)], "Output"]
102}, Open ]]
103}, Open ]]
104}, Closed]],
105
106Cell[CellGroupData[{
107
108Cell["What is Diet Problem?", "Section",
109 ImageRegion->{{0, 1}, {0, 1}},
110 FontSize->20],
111
112Cell["\<\
113The following diet problem is taken from V. Chvatal's great book \
114on Linear Programming (\"Linear Programming\", W.H.Freeman and Company,1983). \
115 It is to design a cheapest meal with six possible items below to satisfy \
116prescribed nutritional needs. Please see Page 3 of the book.\
117\>", "Text",
118 ImageRegion->{{0, 1}, {0, 1}}],
119
120Cell[CellGroupData[{
121
122Cell["\<\
123var={\"\",\"Oatmeal\",\"Chicken\",\"Eggs\",\"Milk\",\"Cherry Pie\", \
124
125\t\"Pork Beans\"};
126
127price={\"Price/Ser\", \"3c\", \"24c\", \"13c\", \"9c\", \"20c\", \
128\"19c\"}\
129\>", "Input",
130 ImageRegion->{{0, 1}, {0, 1}},
131 FontSize->14],
132
133Cell[BoxData[
134 \({"Price/Ser", "3c", "24c", "13c", "9c", "20c", "19c"}\)], "Output"]
135}, Open ]],
136
137Cell["\<\
138MatrixForm[dietproblem1=
139{{0, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0},
140 {0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0},
141 {0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 1},
142 {4, -1, 0, 0, 0, 0, 0}, {3, 0, -1, 0, 0, 0, 0},
143 {2, 0, 0, -1, 0, 0, 0}, {8, 0, 0, 0, -1, 0, 0},
144 {2, 0, 0, 0, 0, -1, 0}, {2, 0, 0, 0, 0, 0, -1},
145 {-2000, 110, 205, 160, 160, 420, 260},
146 {-55, 4, 32, 13, 8, 4, 14},
147 {-800, 2, 12, 54, 285, 22, 80}}];\
148\>", "Input",
149 ImageRegion->{{0, 1}, {0, 1}},
150 FontSize->14],
151
152Cell[CellGroupData[{
153
154Cell["\<\
155TableForm[table1=Prepend[Prepend[dietproblem1,var],price]]
156\
157\>", "Input",
158 ImageRegion->{{0, 1}, {0, 1}}],
159
160Cell[BoxData[
161 TagBox[GridBox[{
162 {"\<\"Price/Ser\"\>", "\<\"3c\"\>", "\<\"24c\"\>", "\<\"13c\"\>", "\
163\<\"9c\"\>", "\<\"20c\"\>", "\<\"19c\"\>"},
164 {"\<\"\"\>", "\<\"Oatmeal\"\>", "\<\"Chicken\"\>", "\<\"Eggs\"\>", \
165"\<\"Milk\"\>", "\<\"Cherry Pie\"\>", "\<\"Pork Beans\"\>"},
166 {"0", "1", "0", "0", "0", "0", "0"},
167 {"0", "0", "1", "0", "0", "0", "0"},
168 {"0", "0", "0", "1", "0", "0", "0"},
169 {"0", "0", "0", "0", "1", "0", "0"},
170 {"0", "0", "0", "0", "0", "1", "0"},
171 {"0", "0", "0", "0", "0", "0", "1"},
172 {"4", \(-1\), "0", "0", "0", "0", "0"},
173 {"3", "0", \(-1\), "0", "0", "0", "0"},
174 {"2", "0", "0", \(-1\), "0", "0", "0"},
175 {"8", "0", "0", "0", \(-1\), "0", "0"},
176 {"2", "0", "0", "0", "0", \(-1\), "0"},
177 {"2", "0", "0", "0", "0", "0", \(-1\)},
178 {\(-2000\), "110", "205", "160", "160", "420", "260"},
179 {\(-55\), "4", "32", "13", "8", "4", "14"},
180 {\(-800\), "2", "12", "54", "285", "22", "80"}
181 },
182 RowSpacings->1,
183 ColumnSpacings->3,
184 RowAlignments->Baseline,
185 ColumnAlignments->{Left}],
186 Function[ BoxForm`e$,
187 TableForm[ BoxForm`e$]]]], "Output"]
188}, Open ]],
189
190Cell["\<\
191m=Transpose[Drop[Transpose[dietproblem1],1]];
192b=-First[Transpose[dietproblem1]];
193c={3, 24, 13, 9, 20, 19};\
194\>", "Input",
195 ImageRegion->{{0, 1}, {0, 1}},
196 FontSize->14],
197
198Cell[TextData[{
199 "By using the build-in LP optimizer of ",
200 StyleBox["Mathematica",
201 FontSlant->"Italic"],
202 ", one can easily compute the optimal solution."
203}], "Text",
204 ImageRegion->{{0, 1}, {0, 1}}],
205
206Cell[CellGroupData[{
207
208Cell["lps=LinearProgramming[c, m,b]", "Input",
209 ImageRegion->{{0, 1}, {0, 1}},
210 FontSize->14],
211
212Cell[BoxData[
213 \({4, 0, 0, 9\/2, 2, 0}\)], "Output"]
214}, Open ]],
215
216Cell[CellGroupData[{
217
218Cell["optvalue= N[c.lps]", "Input",
219 ImageRegion->{{0, 1}, {0, 1}},
220 FontSize->14],
221
222Cell[BoxData[
223 \(92.5`\)], "Output"]
224}, Open ]],
225
226Cell["\<\
227We can see the optimal solution better in the following table. It \
228is certainly not an exciting menu. In fact, an optimal solution to any \
229optimization problem tends to be extreme, and thus it must be modified for \
230practical purposes.\
231\>", "Text",
232 ImageRegion->{{0, 1}, {0, 1}}],
233
234Cell[CellGroupData[{
235
236Cell["\<\
237TableForm[Join[{var},{Prepend[N[lps],optvalue]}]]
238\
239\>", "Input",
240 ImageRegion->{{0, 1}, {0, 1}},
241 FontSize->14],
242
243Cell[BoxData[
244 TagBox[GridBox[{
245 {"\<\"\"\>", "\<\"Oatmeal\"\>", "\<\"Chicken\"\>", "\<\"Eggs\"\>", \
246"\<\"Milk\"\>", "\<\"Cherry Pie\"\>", "\<\"Pork Beans\"\>"},
247 {"92.5`", "4.`", "0.`", "0.`", "4.5`", "2.`", "0.`"}
248 },
249 RowSpacings->1,
250 ColumnSpacings->3,
251 RowAlignments->Baseline,
252 ColumnAlignments->{Left}],
253 Function[ BoxForm`e$,
254 TableForm[ BoxForm`e$]]]], "Output"]
255}, Open ]]
256}, Closed]],
257
258Cell[CellGroupData[{
259
260Cell["Why is the Vertex Enumeration Useful?", "Section",
261 ImageRegion->{{0, 1}, {0, 1}}],
262
263Cell["\<\
264Now we try to do something more reasonable. We use cddmathlink \
265fuction AllVertices:\
266\>", "Subsection",
267 ImageRegion->{{0, 1}, {0, 1}}],
268
269Cell[CellGroupData[{
270
271Cell["?AllVertices", "Input",
272 ImageRegion->{{0, 1}, {0, 1}}],
273
274Cell[BoxData[
275 \("AllVertices[m,d+1,A] generates all extreme points (vertices) and \
276extreme rays of the convex polyhedron in R^(d+1) given as the solution set to \
277an inequality system A x >= 0 where A is an m*(d+1) matrix and \
278x=(1,x1,...,xd). The output is {{extlist, linearity}, ecdlist} where extlist \
279is the extreme point list and ecdlist is the incidence list. Each vertex \
280(ray) has the first component 1 (0). If the convex polyhedron is nonempty \
281and has no vertices, extlist is a (nonunique) set of generators of the \
282polyhedron where those generators in the linearity list are considered as \
283linearity space (of points satisfying A (0, x1, x2, ...., xd) = 0) \
284generators."\)], "Print",
285 CellTags->"Info3249106745-1451094"]
286}, Open ]],
287
288Cell[CellGroupData[{
289
290Cell["\<\
291We can then compute ALL possibilities for cost at most, say One \
292Dollar.\
293\>", "Subsection",
294 ImageRegion->{{0, 1}, {0, 1}}],
295
296Cell["BudgetLimit=100;", "Input",
297 ImageRegion->{{0, 1}, {0, 1}}],
298
299Cell[CellGroupData[{
300
301Cell["\<\
302MatrixForm[dietproblem2=Append[dietproblem1,
303 {BudgetLimit, -3, -24, -13, -9, -20, -19}]]\
304\>", "Input",
305 ImageRegion->{{0, 1}, {0, 1}}],
306
307Cell[BoxData[
308 TagBox[
309 RowBox[{"(", "\[NoBreak]", GridBox[{
310 {"0", "1", "0", "0", "0", "0", "0"},
311 {"0", "0", "1", "0", "0", "0", "0"},
312 {"0", "0", "0", "1", "0", "0", "0"},
313 {"0", "0", "0", "0", "1", "0", "0"},
314 {"0", "0", "0", "0", "0", "1", "0"},
315 {"0", "0", "0", "0", "0", "0", "1"},
316 {"4", \(-1\), "0", "0", "0", "0", "0"},
317 {"3", "0", \(-1\), "0", "0", "0", "0"},
318 {"2", "0", "0", \(-1\), "0", "0", "0"},
319 {"8", "0", "0", "0", \(-1\), "0", "0"},
320 {"2", "0", "0", "0", "0", \(-1\), "0"},
321 {"2", "0", "0", "0", "0", "0", \(-1\)},
322 {\(-2000\), "110", "205", "160", "160", "420", "260"},
323 {\(-55\), "4", "32", "13", "8", "4", "14"},
324 {\(-800\), "2", "12", "54", "285", "22", "80"},
325 {"100", \(-3\), \(-24\), \(-13\), \(-9\), \(-20\), \(-19\)}
326 }], "\[NoBreak]", ")"}],
327 Function[ BoxForm`e$,
328 MatrixForm[ BoxForm`e$]]]], "Output"],
329
330Cell[CellGroupData[{
331
332Cell["{m2,d2}=Dimensions[dietproblem2]", "Input",
333 ImageRegion->{{0, 1}, {0, 1}}],
334
335Cell[BoxData[
336 \({16, 7}\)], "Output"]
337}, Open ]],
338
339Cell["\<\
340{{extlist,linearity},inclist}=AllVertices[m2,d2,Flatten[\
341dietproblem2]];\
342\>", "Input",
343 ImageRegion->{{0, 1}, {0, 1}}]
344}, Open ]],
345
346Cell[CellGroupData[{
347
348Cell["Length[extlist]", "Input",
349 ImageRegion->{{0, 1}, {0, 1}}],
350
351Cell[BoxData[
352 \(17\)], "Output"]
353}, Open ]],
354
355Cell["vlist=Map[Drop[#,1]&, extlist];", "Input",
356 ImageRegion->{{0, 1}, {0, 1}}],
357
358Cell["allsolutions=Union[Map[Prepend[#, N[c.#,3]]&, N[vlist,5]]];", "Input",
359 ImageRegion->{{0, 1}, {0, 1}}],
360
361Cell[CellGroupData[{
362
363Cell["TableForm[table2=Prepend[allsolutions,var]]", "Input",
364 ImageRegion->{{0, 1}, {0, 1}}],
365
366Cell[BoxData[
367 TagBox[GridBox[{
368 {"\<\"\"\>", "\<\"Oatmeal\"\>", "\<\"Chicken\"\>", "\<\"Eggs\"\>", \
369"\<\"Milk\"\>", "\<\"Cherry Pie\"\>", "\<\"Pork Beans\"\>"},
370 {"92.5`", "4.`", "0.`", "0.`", "4.5`", "2.`", "0.`"},
371 {"97.33333333333336`", "4.`", "0.`", "0.`", "8.`",
372 "0.6666666666666675`", "0.`"},
373 {"98.6035889070147`", "4.`", "0.`", "0.`", "2.232952691680261`",
374 "2.`", "1.3951060358890708`"},
375 {"100.`", "1.6470588235294117`", "0.`", "0.`", "6.117647058823529`",
376 "2.`", "0.`"},
377 {"100.`", "2.8085106382978777`", "0.`", "0.`", "8.`",
378 "0.9787234042553182`", "0.`"},
379 {"100.`", "3.7415068699984926`", "0.`", "0.`",
380 "2.1980371432885404`", "2.`", "1.5259550052846136`"},
381 {"100.`", "4.`", "0.`", "0.`", "2.2091586794462197`", "2.`",
382 "1.4798722044728432`"},
383 {"100.`", "4.`", "0.`", "0.`", "5.333333333333333`", "2.`", "0.`"},
384 {"100.`", "4.`", "0.`", "0.`", "8.`", "0.8000000000000002`",
385 "0.`"},
386 {"100.`", "4.`", "0.`", "0.49557522123893516`", "8.`",
387 "0.4778761061946923`", "0.`"},
388 {"100.`", "4.`", "0.`", "1.8750000000000029`", "2.624999999999996`",
389 "2.`", "0.`"},
390 {"100.`", "4.`", "0.1655305777133171`", "0.`", "2.268813149625332`",
391 "2.`", "1.2425235678027577`"},
392 {"100.`", "4.`", "0.1872909698996644`", "0.`", "8.`",
393 "0.5752508361204028`", "0.`"},
394 {"100.`", "4.`", "0.601503759398496`", "0.`", "3.729323308270678`",
395 "2.`", "0.`"},
396 {"100.00000000000001`", "4.`", "0.`", "0.`", "2.179657768651609`",
397 "1.8828199863107473`", "1.6171937029431882`"},
398 {"100.00000000000001`", "4.`", "0.`", "0.`", "8.`",
399 "0.4172661870503621`", "0.4028776978417242`"},
400 {"100.00000000000001`", "4.`", "0.`", "1.025149700598805`",
401 "2.2122155688622755`", "2.`", "0.7770059880239508`"}
402 },
403 RowSpacings->1,
404 ColumnSpacings->3,
405 RowAlignments->Baseline,
406 ColumnAlignments->{Left}],
407 Function[ BoxForm`e$,
408 TableForm[ BoxForm`e$]]]], "Output"]
409}, Open ]]
410}, Open ]],
411
412Cell["\<\
413The list is complete in the sense that any feasible menu of cost at \
414most One Dollar is a combination of these seventeen (extreme) solutions. One \
415can find menus with Chicken, Eggs or Pork that might be much more desireble \
416than the optimal menu. Also it shows you cannot avoid Oatmeal nor Cherry \
417pie within this budget to satisfy the nutritional needs.\
418\>", "Text",
419 ImageRegion->{{0, 1}, {0, 1}}]
420}, Closed]],
421
422Cell[CellGroupData[{
423
424Cell["Disconnecting cddmathlink", "Section",
425 ImageRegion->{{0, 1}, {0, 1}}],
426
427Cell[CellGroupData[{
428
429Cell["Uninstall[cddml]", "Input",
430 ImageRegion->{{0, 1}, {0, 1}}],
431
432Cell[BoxData[
433 \("/Users/fukuda/Math/cddmathlink"\)], "Output"]
434}, Open ]]
435}, Closed]]
436},
437FrontEndVersion->"4.1 for Macintosh",
438ScreenRectangle->{{0, 1152}, {0, 746}},
439AutoGeneratedPackage->None,
440WindowToolbars->{},
441CellGrouping->Manual,
442WindowSize->{639, 621},
443WindowMargins->{{1, Automatic}, {Automatic, 1}},
444PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}},
445ShowCellLabel->True,
446ShowCellTags->False,
447RenderingOptions->{"ObjectDithering"->True,
448"RasterDithering"->False}
449]
450
451(*******************************************************************
452Cached data follows. If you edit this Notebook file directly, not
453using Mathematica, you must remove the line containing CacheID at
454the top of the file. The cache data will then be recreated when
455you save this file from within Mathematica.
456*******************************************************************)
457
458(*CellTagsOutline
459CellTagsIndex->{
460 "Info3249106745-1451094"->{
461 Cell[7959, 273, 753, 11, 167, "Print",
462 CellTags->"Info3249106745-1451094"]}
463 }
464*)
465
466(*CellTagsIndex
467CellTagsIndex->{
468 {"Info3249106745-1451094", 14759, 459}
469 }
470*)
471
472(*NotebookFileOutline
473Notebook[{
474Cell[1705, 50, 424, 13, 179, "Title"],
475Cell[2132, 65, 228, 4, 92, "Subtitle"],
476
477Cell[CellGroupData[{
478Cell[2385, 73, 103, 2, 56, "Section",
479 InitializationCell->True],
480
481Cell[CellGroupData[{
482Cell[2513, 79, 295, 8, 49, "Text",
483 InitializationCell->True],
484Cell[2811, 89, 120, 2, 27, "Input",
485 InitializationCell->True],
486
487Cell[CellGroupData[{
488Cell[2956, 95, 115, 2, 27, "Input",
489 InitializationCell->True],
490Cell[3074, 99, 84, 1, 27, "Output"]
491}, Open ]]
492}, Open ]]
493}, Closed]],
494
495Cell[CellGroupData[{
496Cell[3219, 107, 89, 2, 40, "Section"],
497Cell[3311, 111, 343, 6, 68, "Text"],
498
499Cell[CellGroupData[{
500Cell[3679, 121, 240, 9, 76, "Input"],
501Cell[3922, 132, 87, 1, 27, "Output"]
502}, Open ]],
503Cell[4024, 136, 495, 13, 172, "Input"],
504
505Cell[CellGroupData[{
506Cell[4544, 153, 117, 4, 42, "Input"],
507Cell[4664, 159, 1261, 27, 293, "Output"]
508}, Open ]],
509Cell[5940, 189, 180, 6, 60, "Input"],
510Cell[6123, 197, 207, 6, 32, "Text"],
511
512Cell[CellGroupData[{
513Cell[6355, 207, 95, 2, 28, "Input"],
514Cell[6453, 211, 55, 1, 42, "Output"]
515}, Open ]],
516
517Cell[CellGroupData[{
518Cell[6545, 217, 84, 2, 28, "Input"],
519Cell[6632, 221, 39, 1, 27, "Output"]
520}, Open ]],
521Cell[6686, 225, 298, 6, 50, "Text"],
522
523Cell[CellGroupData[{
524Cell[7009, 235, 124, 5, 44, "Input"],
525Cell[7136, 242, 443, 11, 53, "Output"]
526}, Open ]]
527}, Closed]],
528
529Cell[CellGroupData[{
530Cell[7628, 259, 89, 1, 36, "Section"],
531Cell[7720, 262, 149, 4, 46, "Subsection"],
532
533Cell[CellGroupData[{
534Cell[7894, 270, 62, 1, 27, "Input"],
535Cell[7959, 273, 753, 11, 167, "Print",
536 CellTags->"Info3249106745-1451094"]
537}, Open ]],
538
539Cell[CellGroupData[{
540Cell[8749, 289, 136, 4, 46, "Subsection"],
541Cell[8888, 295, 66, 1, 27, "Input"],
542
543Cell[CellGroupData[{
544Cell[8979, 300, 149, 4, 42, "Input"],
545Cell[9131, 306, 1041, 21, 277, "Output"],
546
547Cell[CellGroupData[{
548Cell[10197, 331, 82, 1, 27, "Input"],
549Cell[10282, 334, 41, 1, 27, "Output"]
550}, Open ]],
551Cell[10338, 338, 131, 4, 42, "Input"]
552}, Open ]],
553
554Cell[CellGroupData[{
555Cell[10506, 347, 65, 1, 27, "Input"],
556Cell[10574, 350, 36, 1, 27, "Output"]
557}, Open ]],
558Cell[10625, 354, 81, 1, 27, "Input"],
559Cell[10709, 357, 109, 1, 27, "Input"],
560
561Cell[CellGroupData[{
562Cell[10843, 362, 93, 1, 27, "Input"],
563Cell[10939, 365, 2233, 42, 309, "Output"]
564}, Open ]]
565}, Open ]],
566Cell[13199, 411, 418, 7, 68, "Text"]
567}, Closed]],
568
569Cell[CellGroupData[{
570Cell[13654, 423, 78, 1, 36, "Section"],
571
572Cell[CellGroupData[{
573Cell[13757, 428, 66, 1, 27, "Input"],
574Cell[13826, 431, 66, 1, 27, "Output"]
575}, Open ]]
576}, Closed]]
577}
578]
579*)
580
581
582
583(*******************************************************************
584End of Mathematica Notebook file.
585*******************************************************************)
586