Tuesday, June 28, 2011

Differences in Linear Programming models

With my mind back on to the Science of Decision Making book, I have two different ways to build the same linear programming model. The book describes how to do so using Excel. So below is a screen shot of the model in Excel before it is resolved. E3:E8 uses the function of SUMPRODUCT of the related values in columns B, C, and D.





Seeking to maximize E8, it is subject to 
$B$9:$D$9 >= 0
$E$3:$E$7 <= $G$3:$G$7
with the changing cells $B$9:$D$9. 
This results in the answer below.
Produce 
20 of S
30 of F
0 of L
















Now to do the same problem using the GNU Linear Programming Kit (GLPK), the model is built as follows.
--------
# This finds the optimal solution for maximizing the RV plants's profit
#

/* Decision variables */
var x1 >=0;  /* Standard */
var x2 >=0;  /* Fancy */
var x3 >=0;  /* Luxury */

/* Objective function */
maximize z: 840*x1 + 1120*x2 + 1200*x3;

/* Constraints */
s.t. Engine_Shop : 3*x1 + 2*x2 + 1*x3 <= 120;
s.t. Body_Shop   : 1*x1 + 2*x2 + 3*x3 <= 80;
s.t. Standard_Fin : 2*x1 + 0*x2 + 0*x3 <= 96;
s.t. Fancy_Fin : 0*x1 + 3*x2 + 0*x3 <= 102;
s.t. Luxury_Fin : 0*x1 + 0*x2 + 2*x3 <= 40;

end;
--------
While spreadsheet fans may find this slightly harder to follow, the format in this tool is closer to how a student defines a linear programming problem in class, only slightly more complex given scripting variables. GLPK produces the following report after running "glpsol -m glpk_Science_of_decision_Ch001.mod -o test.sol"

--------
Problem:    glpk_Science_of_decision_Ch001
Rows:       6
Columns:    3
Non-zeros:  12
Status:     OPTIMAL
Objective:  z = 50400 (MAXimum)

   No.   Row name   St   Activity     Lower bound   Upper bound    Marginal
------ ------------ -- ------------- ------------- ------------- -------------
     1 z            B          50400                             
     2 Engine_Shop  NU           120                         120           140
     3 Body_Shop    NU            80                          80           420
     4 Standard_Fin B             40                          96 
     5 Fancy_Fin    B             90                         102 
     6 Luxury_Fin   B              0                          40 

   No. Column name  St   Activity     Lower bound   Upper bound    Marginal
------ ------------ -- ------------- ------------- ------------- -------------
     1 x1           B             20             0               
     2 x2           B             30             0               
     3 x3           NL             0             0                        -200

Karush-Kuhn-Tucker optimality conditions:

KKT.PE: max.abs.err. = 0.00e+000 on row 0
        max.rel.err. = 0.00e+000 on row 0
        High quality

KKT.PB: max.abs.err. = 0.00e+000 on row 0
        max.rel.err. = 0.00e+000 on row 0
        High quality

KKT.DE: max.abs.err. = 1.14e-013 on column 1
        max.rel.err. = 1.35e-016 on column 1
        High quality

KKT.DB: max.abs.err. = 0.00e+000 on row 0
        max.rel.err. = 0.00e+000 on row 0
        High quality

End of output
--------


While the report introduces a greater amount of information, we can still see the same results. 
The company should produce
20 of the standard
30 of the fancy
0 of the luxury

The Google Docs spreadsheet looks almost the same as Excel for the purposes of this post so a screenshot of it is excluded. The only difference between the two for this example is how the constraints are setup. See the previous post for the details. 

Resolved Google Docs solver issue

Well it seems the Solver in Google Docs spreadsheet can produce the same answer as Excel.
The issue comes down to how you enter the constraints. Excel can enter constraints as a range: $E$3:$E$7 <= $G$3:$G$7 but in Google Docs Spreadsheet, a range can not be used. Each constraining pair must be entered as a separate constraint.
Hence
E3 <= G3
E4 <= G4
E5 <= G5
E6 <= G6
E7 <= G7

So as I make my way through the book and try the examples in both Excel and Google Docs, I am sure I will find other issues.

Saturday, June 11, 2011

Using Solver tool in Excel and Google Docs

While I was working on the first problem in The Science of Decision Making book, it dawned on me that not only does Excel have a solver tool for Linear Programming problems, but Google docs spreadsheet also has a solver. So I tried the problem in both tools. Unfortunately I got different results. I tried the same steps over and over again to confirm if I make a mistake. So far they do not reconcile.

Results in Excel (which match the results in the book)


So I will email Google to find out if there is something I am missing.   

Science of Decision Making book and the many tools to optimize a decision

One of the great benefits of blogging is stating a goal and using your public announcement to motivate you to finish the goal. If the writer (me) does not accomplish the goal, it's embarrassing and becomes rather boring blogging. Hence my first post is about my goal to complete the work within the book The Science of Decision Making: A Problem-Based Approach Using Excel. Only in my case, I am looking to process the examples in both Excel and the program GNU Linear Programming Kit.

So why do I want to do this ? In my past experience with computer security I found a lot of peers, journals, and experts talked about risk, but few could talk about risk in a similar manner to an insurance actuary. Many expert technology companies and government institutions have a difficult time determining risk and making optimal decisions. I do not make any claims that I am any better at making decisions than the management of these organizations at this time. My interest is building skills that could give me the ability to determine security risks in a similar pattern to an insurance company. I am hoping that these skills will give me an advantage in any complex decision I need to make. At very least, I can use the book's content to build decision making skills in a way that is rational and provable. Of course if data collection and life was perfect, I could use these skills to solve every problem thrown at me like Charlie Eppes in the TV show Numb3rs, but the realistic goal would be to match the accuracy of insurance companies for IT security or other complex decisions.