rasheedja / simplex-method Goto Github PK
View Code? Open in Web Editor NEWImplementation of the two-phase simplex method in exact rational arithmetic.
License: Other
Implementation of the two-phase simplex method in exact rational arithmetic.
License: Other
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?
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:
twoPhaseSimplex (Min [(1,1)]) [GEQ [(1,1)] 0)
: correct 0twoPhaseSimplex (Max [(1,1)]) [GEQ [(1,1)] 0)
: correct NothingtwoPhaseSimplex (Max [(1,-1)]) [GEQ [(1,1)] 0)
: correct 0twoPhaseSimplex (Min [(1,-1)]) [GEQ [(1,1)] 0)
: correct NothingBut if I flip the constraint, either by using LEQ or negating it, the unbounded cases seem to fail:
twoPhaseSimplex (Max [(1,1)]) [LEQ [(1,1)] 0)
: correct 0twoPhaseSimplex (Min [(1,1)]) [LEQ [(1,1)] 0)
: incorrect 0twoPhaseSimplex (Max [(1,-1)]) [LEQ [(1,1)] 0)
: incorrect 0twoPhaseSimplex (Min [(1,1)]) [GEQ [(1,-1)] 0)
: incorrect 0Am 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).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.