[SciPy-Dev] Proposed enhancement: pure Python implementationof LP simplex method (two-phase)
Fri Jul 30 05:54:40 CDT 2010
Thanks for uploading lp2.py: I hadn't noticed it and I uploaded a revised
lp.py with the changes you required except for the object stuff, on which I
had a question (namely: should the NamedTuple be based on
Anyway, feel free to remove lp.py .
Regarding the warning, you may safely take it away altogether: the "print"
was a diagnostic leftover that I had overlooked (the "unsolvable" status is
anyway returned to the caller).
From: "Pauli Virtanen" <email@example.com>
Sent: Friday, July 30, 2010 4:49 PM
> Fri, 30 Jul 2010 09:48:49 +0800, Enzo Michelangeli wrote:
>>> I think your "test case" could easily be turned into a unit test, which
>>> would make the submission more complete.
> Seems to work.
> Some API nitpicks,
> Return a solution object rather than a tuple:
> class NamedTuple(tuple):
> def __new__(cls, values, names):
> self = tuple.__new__(cls, values)
> for value, name in zip(values, names):
> setattr(self, name, value)
> return self
> class Solution(NamedTuple):
> _fields = 
> def __new__(cls, *a, **kw):
> values = list(a)
> for name in cls._fields[len(values):]:
> if len(values) != len(cls._fields) or kw:
> raise ValueError("Invalid arguments")
> return NamedTuple.__new__(cls, values, cls._fields)
> def __repr__(self):
> return "%s%s" % (self.__class__.__name__,
> class LPSolution(Solution):
> Solution to a linear programming problem
> The optimal solution
> The optimal value
> True if the solution is bounded; False if unbounded
> True if the problem is solvable; False if unsolvable
> Indices of the basis of the solution.
> _fields = ['x', 'min', 'is_bounded', 'solvable', 'basis']
> def lp(...):
> return LPSolution(optx, zmin, is_bounded, sol, basis)
> We could (and probably should) replace *all* cases in Scipy where a tuple
> is currently returned by this sort of pattern. It's backwards compatible,
> since the returned object is still some sort of a tuple.
> Don't print to stdout.
> Use warnings.warn if you need to warn about something.
> c = np.asarray(c)
> A = np.asarray(A)
> b = np.asarray(b)
> in the beginning -- good for convenience.
More information about the SciPy-Dev