Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53496

Re: Simplex Algorithm

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'algorithm': 0.04; 'interfaces': 0.04; 'column': 0.07; 'conventions': 0.07; 'element': 0.07; 'variables': 0.07; 'conventions.': 0.09; 'linear': 0.09; 'positioned': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variables.': 0.09; 'python': 0.11; "wouldn't": 0.14; '-1.': 0.16; '-2.': 0.16; 'ass': 0.16; 'columns': 0.16; 'kern': 0.16; 'programmatic': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reproduce': 0.16; 'solver': 0.16; 'solver,': 0.16; 'third,': 0.16; 'tommy': 0.16; 'underlying': 0.16; "variable's": 0.16; 'language': 0.16; 'wrote:': 0.18; 'options.': 0.19; 'properly': 0.19; 'solution.': 0.20; 'work,': 0.20; '>>>': 0.22; 'programming': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'interpret': 0.24; 'looks': 0.24; "i've": 0.25; 'compiled': 0.26; 'this:': 0.26; 'second': 0.26; 'excel': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'robert': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'getting': 0.31; 'bunch': 0.31; 'second,': 0.31; 'anyone': 0.31; 'class': 0.32; 'this.': 0.32; 'figure': 0.32; 'run': 0.32; 'url:python': 0.33; 'sources': 0.33; 'third': 0.33; 'problem': 0.35; 'basic': 0.35; "can't": 0.35; 'except': 0.35; 'something': 0.35; 'case,': 0.35; 'convert': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'representing': 0.36; 'url:org': 0.36; 'so,': 0.37; 'too': 0.37; 'represent': 0.38; 'thank': 0.38; 'displays': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'easy': 0.60; 'is.': 0.60; 'simple,': 0.60; 'show': 0.63; 'choose': 0.64; 'our': 0.64; 'different': 0.65; 'spot': 0.65; 'world': 0.66; 'between': 0.67; 'believe': 0.68; 'sound': 0.68; 'results': 0.69; '11.': 0.74; 'column.': 0.84; 'eco': 0.84; 'forced': 0.84; 'fourth': 0.84; 'maximized': 0.84; 'pain': 0.84; 'terrible': 0.84; 'vba': 0.84; 'luck': 0.93; 'modelling': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: Simplex Algorithm
Date Mon, 02 Sep 2013 16:43:48 +0100
References <1PRUt.242963$ZD2.40442@fx19.iad> <mailman.477.1378115748.19984.python-list@python.org> <5224A963.4040304@xxxxxx.xxx>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 213.1.240.226
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8
In-Reply-To <5224A963.4040304@xxxxxx.xxx>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.496.1378136639.19984.python-list@python.org> (permalink)
Lines 88
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1378136639 news.xs4all.nl 15869 [2001:888:2000:d::a6]:55210
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53496

Show key headers only | View raw


On 2013-09-02 16:06, Tommy Vee wrote:
> On 9/2/2013 5:55 AM, Robert Kern wrote:
>> On 2013-09-02 02:26, Tommy Vee wrote:
>>> Anyone know where I can get an easy to use Python class or algorithm
>>> for the
>>> Simplex optimization algorithm?  I've tried the one in the link below,
>>> but I
>>> can't figure out if a) I'm using it properly, or b) where to get the
>>> solution.
>>> BTW, I tried some test scenarios using MS Excel's "Solver" and just
>>> can't get
>>> this algorithm to match Excel's results (which is spot on).
>>>
>>> http://taw9.hubpages.com/hub/Simplex-Algorithm-in-Python
>>>
>>> BTW, if I can't something to work, I'm going to be forced to use the VBA
>>> programmatic Excel interface. That wouldn't be too bad, but the data
>>> comes from
>>> a DB and getting it properly positioned to use Excel's "Solver" is very
>>> painful.  A Python approach would be much cleaner.
>>
>> Can you show some of the test scenarios that you tried? There are
>> different conventions in how to represent a linear programming problem,
>> and different solvers may choose different conventions. You may have to
>> convert between representations.
>>
>> You may have better luck with the PuLP interface:
>>
>>    https://pypi.python.org/pypi/PuLP
>>
>> PuLP itself is just a modelling language rather than a solver, but the
>> sources do contain compiled binaries for the CoinMP solver so it will
>> work out-of-box on popular platforms, like Windows.
>>
>>    https://projects.coin-or.org/CoinMP
>>
>
> Thank you, I will definitely look at these and other options.  BTW, try the test
> scenario in the link I sent.  Very simple, only 3 variables.
>
> Maximize:  2x+3y+2z
>
> Constraints: 2x+y+z <=4, x+2y+z <=7, z <= 5
>
> The algorithm displays the Tableau after each pivot, but where is the answer for
> x, y and z?

You will have to read up on the Dantzig Simplex Algorithm to learn how to read 
off the results from the final tableau. My understanding is that you look at the 
columns representing the basic variables (in this case, the second, third, and 
fourth columns represent x, y, and z, respectively). If the column is all 0s 
except for a single 1, then the row with the 1 has the variable's value in the 
rightmost column. If the column has other values in it, then the variable's 
value is 0.

> When I run this in Excel's Solver, I get x=0, y=3, z=1. which is indeed the
> maximized solution (11).

The final tableau for this problem looks like this:

[[  1.   1.   0.   0.   1.   1.   0.  11.]
  [  0.   3.   0.   1.   2.  -1.   0.   1.]
  [  0.  -1.   1.   0.  -1.   1.   0.   3.]
  [  0.  -3.   0.   0.  -2.   1.   1.   4.]]

So, for x, we look in the second column and notice that it has a bunch of 
different values in it, so x=0.

For y, we look in the third column and see that it has its single 1 in the third 
row. Looking all the way on the right for that row, we get a 3.

For z, we look in the fourth column and see that it has its single 1 in the 
second row. Looking all the way on the right for that row, we get a 1.

So this solver does reproduce the result x=0, y=3, z=1. The maximized solution 
is in the upper-rightmost element of the tableau, 11.

Sound like a pain in the ass to code up that logic? It is. PuLP and other 
industrial grade solver interfaces won't make you go through this.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Simplex Algorithm Tommy Vee <xxxxx@xxxxxx.xxx> - 2013-09-01 21:26 -0400
  Re: Simplex Algorithm Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-02 09:06 +0100
    Re: Simplex Algorithm Tommy Vee <xxxxx@xxxxxx.xxx> - 2013-09-02 10:42 -0400
    Re: Simplex Algorithm Tommy Vee <vitaletom1@gmail.com> - 2013-09-02 10:42 -0400
  Re: Simplex Algorithm Robert Kern <robert.kern@gmail.com> - 2013-09-02 10:45 +0100
  Re: Simplex Algorithm Robert Kern <robert.kern@gmail.com> - 2013-09-02 10:55 +0100
    Re: Simplex Algorithm Tommy Vee <xxxxx@xxxxxx.xxx> - 2013-09-02 11:06 -0400
      Re: Simplex Algorithm Robert Kern <robert.kern@gmail.com> - 2013-09-02 16:43 +0100
        Re: Simplex Algorithm Tommy Vee <xxxxx@xxxxxx.xxx> - 2013-09-02 14:59 -0400
        Re: Simplex Algorithm Tommy Vee <vitaletom1@gmail.com> - 2013-09-02 14:59 -0400
    Re: Simplex Algorithm Tommy Vee <vitaletom1@gmail.com> - 2013-09-02 11:06 -0400
  Re: Simplex Algorithm Tony the Tiger <tony@tiger.invalid> - 2013-09-16 13:47 -0500

csiph-web