All published worksheets from http://sagenb.org
Image: ubuntu2004
This worksheet uses a special module not available in the standard distribution of Sage. You can access it via the third menu list above ("Data..."), if you wish to look at the code or download it separately. The following command makes functionality of this module available for later use in the worksheet and should be executed first. It is also recommended to check "Typeset" box located after the fourth menu list.
Corn and Barley via Simplex Method
We are working (still) on the following problem:
A farmer has 1000 acres available to grow corn and barley. Corn has a net profit of \$10/acre while barley has a net profit of \$5/acre. The farmer has 1500 kilogramms of fertilizer available with 3kg/acre needed for corn and 1kg/acre needed for barley. According to local laws, at least 40% of available land must be used. The farmer wants to maximize the profit.
We have seen, that in the standard form you can formulate this problem as
$$ \begin{array}{l}
\max\ 10 x_1 + 5 x_2 \\
x_1 + x_2 \leq 1000 \\
3x_1 + x_2 \leq 1500 \\
- x_1 - x_2 \leq -400 \\
x_1, x_2 \geq 0,
\end{array} $$
where is the land (in acres) used to plant corn and is the land used to plant barley. Alternatively, this problem (and any other in the standard form) can be written as
$$ \begin{array}{l}
\max\ c x \\
A x \leq b \\
x \geq 0,
\end{array} $$
where is a matrix of coefficients in the inequalities, is the vector of constant terms in the inequalities, is the vector of coefficients of the objective function, and is the vector of decision variables. We can define these objects and set up an LP problem in Sage as follows.
If the output above does not look "pretty", e.g. you see "x1" instead of "", check the "Typeset" box on the top.
To solve this problem using Simplex Method, we start with the Initial Dictionary:
Unfortunately, this dictionary is infeasible, so we need to go through the Phase I and solve the Auxiliary Problem first.
It is no surprise to us that this dictionary is not optimal and not even feasible. But for the auxiliary problem we know how to get a feasible dictionary: let enter and the variable with the most negative constant coefficient leave. The following commands set as the entering variable, as the leaving variable, then update the dictionary (which is usually the longest step if you do it by hand - now you can avoid its computational details, but remember that no computers can be used on the tests), and show it.
The dictionary is still not optimal, but now it is feasible and we can use the "usual" Simplex Method. On each step we want to do the same operations as above, for convenience you can call the "elusive" method:
- Enter
- Leave
- Update
- Show
- Is feasible/optimal VErification
It is actually possible to call this method without specifying entering and leaving variables: it will not guess them for you, but will just show the dictionary and its status.
With an optimal dictionary for the auxiliary problem (and with the optimal value ZERO), we can construct a Feasible Dictionary for the original problem and use it for Phase II.
From this optimal dictionary we can read-off the Optimal Value 6250 and an Optimal Solution .
Now let's turn our attention to the Dual Problem.
In order to be able to solve it using the Simplex Method, we need to convert it to standard form. Fortunately, it is easy for dual problems:
The optimal value of the dual problem is the same as for the primal one, 6250 (remember "the minus in front"). An optimal solution is given by .
You can use the same framework for any other problem (in standard form). When doing this beware that most of the "typos" will be caught for you, e.g.
but you are still free to shoot yourself in a foot:
If you have any issues that you cannot resolve, please let me know and I will try to help. If you "share" your worksheet with me (using "Share" blue button on the top right of the page) and send me an email with your username and short description of the problem, I should be able to correct it (and leave some comments) directly in your worksheet.