home *** CD-ROM | disk | FTP | other *** search
/ Freelog 65 / Freelog065.iso / BAS / Bureautique / Gnumeric / gnumeric-1.3.92-rc1.exe / analysis-solver.xml < prev    next >
Text File  |  2004-11-01  |  15KB  |  372 lines

  1. <sect1 id="sect-advanced-analysis-solver">
  2.   <title>Solver</title>
  3.  
  4.   <para>With Gnumeric Solver you can solve linear programs.</para>
  5.  
  6.   <!-- Add a comment so we keep this picture in figures/. and its
  7.        Makefile.am. -->
  8.   <!-- solver-05.png -->
  9.  
  10.  
  11.   <sect2>
  12.     <title>Introduction to Linear Programming</title>
  13.  
  14.     <para>A linear program (LP) is a problem that can be expressed as
  15.     linear functions.  As you probably already know, a linear function
  16.     is the one whose graph is always a straight line.  Thus each
  17.     variable of it appears in a separate term with its coefficient.
  18.     There must be no products or quotients of these variables.  In
  19.     addition, the exponent of each term must be one.  No logarithmic,
  20.     exponential, trigonometric terms are allowed.  Especially note that
  21.     functions like ABS, IF, MAX, and MIN are not linear.  Here are a
  22.     few examples of linear functions:</para>
  23.  
  24.     <programlisting>
  25.     3x + y - 5z
  26.     -3.23x + 0.33y
  27.     -0.3x + 4y - 2z + 1.2m
  28.     </programlisting>
  29.  
  30.     <para>The linear problem has a so called objective function which
  31.     is to be minimized or maximized and constraints.  The objective
  32.     function is the one whose value we would like to optimize.
  33.     Typically, this function could determine the profit generated by
  34.     the expected sales of the given model (maximization problem), or,
  35.     the cost of the production in the given environment (minimization
  36.     problem).  Anyway, on purely mathematical point of view, we could
  37.     examine the following objective function:</para>
  38.  
  39.     <programlisting>
  40.     Maximize 2x + 3y - z
  41.     </programlisting>
  42.  
  43.     <para>In linear programming the variables of this functions are
  44.     not allowed to take any values (otherwise the maximum of any
  45.     objective function would be infinity).  The problem also has
  46.     constraints.  The constraints are a set of linear functions and a
  47.     set of their right hand side values (RHS).  For example, for the
  48.     previously defined objective function we have the following
  49.     constraints:</para>
  50.  
  51.     <programlisting>
  52.     x + y <= 5           (#1)
  53.     3x - y + z <= 9      (#2)
  54.     x + y >= 1           (#3)
  55.     x + y + z = 4        (#4)
  56.     x, y, z >= 0         (non-negativity assumption)
  57.     </programlisting>
  58.  
  59.     <para>This constraint set consists of three inequality constraints
  60.     (#1-#3) and one equality constraint (#4).  Their RHS values are 5,
  61.     9, 1, and 4.  In addition, we also have the non-negativity
  62.     assumption.  That is, all the variables (x, y, and z) have to take
  63.     only positive numbers.  The idea is to find the optimal values for
  64.     the variables (x, y, and z) but also to satisfy all the given
  65.     constraints.</para>
  66.   </sect2>
  67.  
  68.   <sect2>
  69.     <title>Spreadsheet Modeling</title>
  70.  
  71.     <para>To solve optimization problems with Gnumeric you have to
  72.     type in the problem into a sheet.  A recommended way to start with
  73.     is to allocate a separate column in the spreadsheet for each
  74.     decision variable (in the previous example the x, y, and z) and a
  75.     separate row for each constraint (the constraints #1-#4).  The
  76.     coefficients of these variables should be placed into the cells
  77.     corresponding to the allocated row and the column.  It is also
  78.     recommended that you label the rows and the columns to make the
  79.     sheet much more readable.  The sheet for our maximization problem
  80.     would look like this:</para>
  81.  
  82.     <figure id="fig-linear-program-example">
  83.       <title>Linear programming example</title>
  84.       <screenshot>
  85.         <mediaobject>
  86.             <imageobject>
  87.               <imagedata fileref="figures/solver-01.png" format="PNG" />
  88.             </imageobject>
  89.             <textobject>
  90.               <phrase>An image of a worksheet with a linear programing problem.</phrase>
  91.             </textobject>
  92.            </mediaobject>
  93.       </screenshot>
  94.     </figure>
  95.  
  96.     <para>As you can see, we have put the model variables into cells
  97.     B3:D3.  They are currently all zeros.  The cell E4 contains the
  98.     objective function definition.  The easiest way to define it is to
  99.     use SUMPRODUCT build-in function.  Thus in our model, we have the
  100.     formula `=SUMPRODUCT(B3:D3,B4:D4)' in E3.</para>
  101.  
  102.     <para>The constraints are defined in rows seven to ten.  Since
  103.     the coefficients of these functions are in columns B, C and D we
  104.     will get the total sum of each of the constraint using the
  105.     formula `SUMPRODUCT(B$3:D$3,Bn:Dn)' where n is the row number of
  106.     the constraint.  For example, in E7 we have
  107.     `=SUMPRODUCT(B$3:D$3,B7:D7)', in E8 `=SUMPRODUCT(B$3:D$3,B8:D8)'
  108.     and so on.  The right hand side (RHS) values of the constraints
  109.     are typed into cells G7:G10.</para>
  110.  
  111.   </sect2>
  112.  
  113.   <sect2>
  114.     <title>Using Solver</title>
  115.  
  116.     <sect3>
  117.       <title>Solver Parameters</title>
  118.  
  119.       <para>Now it is time to select `Solver...' from the `Tools' menu.
  120.       After you have done it, the following dialog will appear:</para>
  121.  
  122.       <figure id="fig-solver-dialog-1">
  123.         <title>The empty Solver dialog.</title>
  124.         <screenshot>
  125.           <mediaobject>
  126.             <imageobject>
  127.               <imagedata fileref="figures/solver-02.png" format="PNG" />
  128.             </imageobject>
  129.             <textobject>
  130.               <phrase>An image of the solver dialog open to the "Parameters" tab.</phrase>
  131.             </textobject>
  132.            </mediaobject>
  133.         </screenshot>
  134.       </figure>
  135.  
  136.       <para>Since we have the objective function in E3 type this into
  137.       the `Set Target Cell:' entry.  We are about to maximize this
  138.       function, thus the radio button `Max' should be pressed on.  By
  139.       default, the problem is assumed to be maximization problem.  The
  140.       input variables (x, y, and z) were in cells B3:D3 so type the
  141.       cell range into the `By Changing Cells:' entry.</para>
  142.  
  143.       <para>The model to be optimized is a linear model.  Thus, we
  144.       should check that the check button `Linear (LP/MILP)' is pressed
  145.       on under the `Model Assumptions'.  Also make sure that the
  146.       assume non-negative button is on, otherwise, the input variables
  147.       can also take negative values.  There is also a check button
  148.       `Assume Integer (Discrete)' which adds an integer constraint for
  149.       all the input variables.  The integer optimization is
  150.       described, however, later.</para>
  151.  
  152.       <para>A few additional options can be set too.  If you want to
  153.       limit the number of iterations the optimization algorithm is
  154.       allowed to take you can set the maximum number in the `Max
  155.       iterations' entry box.  Similarly, you can limit the maximum
  156.       time the optimization is allowed to take in the `Max time' entry
  157.       box.  If either one of these settings is exceeded during the
  158.       optimization, the optimization is interrupted and an error
  159.       dialog is displayed.</para>
  160.  
  161.       <para>Some models can be better solved if the model is scaled
  162.       into another form before the actual optimization.  Gnumeric
  163.       solver supports automatic scaling which can be checked on by
  164.       using the check button on the bottom of the dialog.  Note that
  165.       the automatic scaling does not change the model since before
  166.       checking out the results the model is scaled back to its
  167.       original form.</para>
  168.  
  169.     </sect3>
  170.  
  171.     <sect3>
  172.       <title>Solver Constraints</title>
  173.  
  174.       <para>Now we can add the constraints.  Select the `Constraints'
  175.       page from the top of the dialog and the following page should
  176.       appear.</para>
  177.  
  178.       <figure id="fig-solver-add-constraint-dialog">
  179.         <title>Add constraint dialog.</title>
  180.         <screenshot>
  181.           <mediaobject>
  182.             <imageobject>
  183.               <imagedata fileref="figures/solver-03.png" format="PNG" />
  184.             </imageobject>
  185.             <textobject>
  186.               <phrase>An image of the solver dialog open to the "Constraints" tab.</phrase>
  187.             </textobject>
  188.            </mediaobject>
  189.         </screenshot>
  190.       </figure>
  191.  
  192.       <para>In this page, you can see all constraints that have been
  193.       defined in the `Subject to the Constraints:' window.  Since none
  194.       has been defined, this window should be empty.  Now type in the
  195.       constraints (#1-#4) one by one.</para>
  196.  
  197.       <para>When adding constraints, the three entry boxes in the
  198.       bottom of the dialog are used.  Put a cell name of the total
  199.       left hand side (LHS) cell into the `Left Hand Side:' entry box.
  200.       In our example, this would be E7 for the constraint #1, E8 for
  201.       constraint #2, and so on.  The combo entry in the middle defines
  202.       the type of the constraint.  It can be<![CDATA[ `<=', `=', `>='
  203.       ]]> , or `Int'.  We will explain the `Int' constraints later.
  204.       In this example, you should select <![CDATA[ `<=' for
  205.       constraints #1-#2, `>=' ]]>for #3, and `=' for constraint #4.
  206.       The last entry on the right takes the right hand side values of
  207.       the constraints.  For constraints #1-#4 they should be G7 (5),
  208.       G8 (9), G9 (1), and G10 (4) in this order.</para>
  209.  
  210.       <para>After typing a constraint press
  211.       <mousebutton>Add</mousebutton> button, and you will be able to
  212.       define the next one.  When you have typed in all the
  213.       constraints, the Solver dialog should look like this:</para>
  214.  
  215.       <figure id="fig-solver-dialog-2">
  216.         <title>The solver dialog</title>
  217.         <screenshot>
  218.           <mediaobject>
  219.             <imageobject>
  220.               <imagedata fileref="figures/solver-04.png" format="PNG" />
  221.             </imageobject>
  222.             <textobject>
  223.               <phrase>An image of the solver dialog open to the
  224.               "Constraints" tab with constraints entered.</phrase>
  225.             </textobject>
  226.            </mediaobject>
  227.         </screenshot>
  228.       </figure>
  229.  
  230.       <para>The order of the constraints does not matter.  If you want
  231.       to change or delete a constraint click it and then press
  232.       `Change' or `Delete' button.</para>
  233.  
  234.       <para>Note that you can also type ranges into the LHS and RHS
  235.       entries.  For example, you could have typed D7:D8 and G7:G8
  236.       instead of the two separate constraints.</para>
  237.  
  238.       <para>If the constraints have now been typed in correctly, we
  239.       should check what reports we want to produce.</para>
  240.  
  241.     </sect3>
  242.  
  243.     <sect3>
  244.       <title>Solver Reporting</title>
  245.  
  246.       <para>Select the `Reports' page from the top of the dialog and
  247.       the a page containing five check buttons should appear.  By
  248.       pressing these check buttons on, you can produce various kinds of
  249.       reports.  You can read more about solver reporting in the
  250.       following section.</para>
  251.  
  252.     </sect3>
  253.  
  254.     <sect3>
  255.       <title>Optimization</title>
  256.  
  257.       <para>After you have specified the parameters, the constraints
  258.       and the reporting options it is time to press the `OK' button.
  259.       If everything went ok, you will see a dialog saying: `Solver
  260.       found an optimal solution. All constraints and optimality
  261.       conditions are satisfied.'.  This means that the solver found an
  262.       optimal solution and the optimal values are now stored into the
  263.       input variables.  For all models, this, however, does not
  264.       happen.</para>
  265.  
  266.       <para>If a feasible solution cannot be found, the solver reports
  267.       that `A feasible solution could not be found. All specified
  268.       constraints cannot be met simultaneously.'.</para>
  269.  
  270.       <para>If the model is unbounded, the solver reports that `The
  271.       Target Cell value specified does not converge!  The program is
  272.       unbounded.'.</para>
  273.  
  274.       <para>If the maximum number of iterations specified in the
  275.       options was exceeded, the solver reports that `The maximum
  276.       number of iterations exceeded. The optimal value could not be
  277.       found.'.</para>
  278.  
  279.       <para>If the maximum time specified in the options was exceeded,
  280.       the solver reports that `The maximum time exceeded. The optimal
  281.       value could not be found in given time.'.</para>
  282.  
  283.     </sect3>
  284.  
  285.   </sect2>
  286.  
  287.   <sect2>
  288.     <title>Solver Reports</title>
  289.  
  290.     <sect3>
  291.       <title>Answer Report</title>
  292.  
  293.       <para>Answer report gives the original and final values for the
  294.       problem and for all the input variables and the constraints.  In
  295.       addition, for the constraints their formulas, binding status and
  296.       the slacks are printed out nicely.  The answer report is given
  297.       as a new sheet.</para>
  298.  
  299.     </sect3>
  300.  
  301.     <sect3>
  302.       <title>Sensitivity Report</title>
  303.  
  304.       <para>Sensitivity report gives the shadow prices for the
  305.       constraints.</para>
  306.  
  307.       <para>Note that if the model contains integer or boolean
  308.       constraints, sensitivity report cannot be produced.</para>
  309.  
  310.     </sect3>
  311.  
  312.     <sect3>
  313.       <title>Limits Report</title>
  314.  
  315.       <para>Limits report reports the achieved optimal value all the
  316.       input variables of the model with the optimal values and with
  317.       upper and lower bound for the optimal value in with the
  318.       particular variable could vary without changing the optimal
  319.       solution.</para>
  320.  
  321.       <para>If an optimal value for a variable x is 4, for example,
  322.       and the lower bound is 2.4 and upper bound 5.9, then x could
  323.       take any value between 2.4 and 5.9, and still all the same
  324.       constraints were binding as with the optimal value 4.  In limits
  325.       report, you can also find the value of the target cell for both
  326.       upper and lower bound values for the variable.  For example, if
  327.       the optimal value where x is 4 leads to a profit of $5,000,
  328.       limits report specifies that if x is set to 2.4 the profit drops
  329.       to $3,640.</para>
  330.  
  331.       <para>Note that if the model contains integer or boolean
  332.       constraints, limits report cannot be produced.</para>
  333.  
  334.     </sect3>
  335.  
  336.     <sect3>
  337.       <title>Performance Report</title>
  338.  
  339.       <para>Performance reports gives various statistical
  340.       characteristics about the given model like how many variables
  341.       and rows it contains, and how many non-zero matrix elements it
  342.       has.  It also gives out the performance numbers like how much
  343.       computing time was required to compute the results.</para>
  344.  
  345.     </sect3>
  346.  
  347.     <sect3>
  348.       <title>Program Report</title>
  349.  
  350.       <para>Program report gives the model in its mathematical form.
  351.       Program report is useful for checking out the correctness of the
  352.       model.  It can also be useful for educational purposes.</para>
  353.  
  354.     </sect3>
  355.  
  356.   </sect2>
  357.  
  358.   <sect2>
  359.     <title>Integer Programming</title>
  360.  
  361.     <para>You can use the Solver tool also for integer programming
  362.     (IP) and more generally mixed integer programming.  In integer
  363.     programming some of the decision variables are required to take on
  364.     integer values.  To do so, just add a constraint whose type is
  365.     `Int'.</para>
  366.  
  367.   </sect2>
  368.  
  369. </sect1>
  370.  
  371.  
  372.