Giter Site home page Giter Site logo

rasheedja / simplex-method Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 192 KB

Implementation of the two-phase simplex method in exact rational arithmetic.

License: Other

Haskell 100.00%
bsd-3-clause haskell linear-programming math mathematics maths optimisation optimization simplex-method

simplex-method's People

Contributors

rasheedja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simplex-method's Issues

Adding positivity constraints change the result

Hello,

I have these constraints:

[LEQ {lhs = fromList [(1,1 % 1),(2,1 % 1),(3,0 % 1)], rhs = 1 % 1},LEQ {lhs = fromList [(1,1 % 1),(2,0 % 1),(3,1 % 1)], rhs = 1 % 1}]

and the objective is to maximize the first variable.

I get this result:

Just (Result {objectiveVar = 6, varValMap = fromList [(1,1 % 1),(6,1 % 1)]})

Variables 2 and 3 do not appear in this resut.

Now I add the constraints "variable 2 positive" and "variable 3 positive":

[LEQ {lhs = fromList [(1,1 % 1),(2,1 % 1),(3,0 % 1)], rhs = 1 % 1},LEQ {lhs = fromList [(1,1 % 1),(2,(-1) % 1),(3,0 % 1)], rhs = 0 % 1},LEQ {lhs = fromList [(1,1 % 1),(2,0 % 1),(3,(-1) % 1)], rhs = 0 % 1},LEQ {lhs = fromList [(1,1 % 1),(2,0 % 1),(3,1 % 1)], rhs = 1 % 1}]

Then I get the expected results, with variables 2 and 3 present this time:

Just (Result {objectiveVar = 8, varValMap = fromList [(1,1 % 2),(2,1 % 2),(3,1 % 2),(8,1 % 2)]})

Is it normal? That sounds strange to me, because the positivity constraints should be implicit, no?

Unexpected results for simple (degenerate) cases

Thanks for this, it's quite useful and seems to work in most cases, but there are some weird results I don't quite understand. Here's some things that work as expected:

  • minimize x st x>=0, twoPhaseSimplex (Min [(1,1)]) [GEQ [(1,1)] 0): correct 0
  • maximize x st x>=0, twoPhaseSimplex (Max [(1,1)]) [GEQ [(1,1)] 0): correct Nothing
  • maximize -x st x>=0, twoPhaseSimplex (Max [(1,-1)]) [GEQ [(1,1)] 0): correct 0
  • minimize -x st x>=0, twoPhaseSimplex (Min [(1,-1)]) [GEQ [(1,1)] 0): correct Nothing

But if I flip the constraint, either by using LEQ or negating it, the unbounded cases seem to fail:

  • maximize x st x<=0, twoPhaseSimplex (Max [(1,1)]) [LEQ [(1,1)] 0): correct 0
  • minimize x st x<=0, twoPhaseSimplex (Min [(1,1)]) [LEQ [(1,1)] 0): incorrect 0
  • maximize -x st x<=0, twoPhaseSimplex (Max [(1,-1)]) [LEQ [(1,1)] 0): incorrect 0
  • minimize x st -x>=0, twoPhaseSimplex (Min [(1,1)]) [GEQ [(1,-1)] 0): incorrect 0

Am I doing something wrong or misinterpreting something? I can reproduce this with various multiple varibles as well, but it only seems to happen when I'm essentially saying to minimize variables that are bounded above (rather than below).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.