def casso1(): err = 0; x = c.Variable("x"); y = c.Variable("y"); solver = c.SimplexSolver (); solver .AddConstraint( c.LinearInequality(x,c.cnLEQ,y)) solver .AddConstraint( c.LinearEquation(y, x+3.0)) solver .AddConstraint( c.LinearEquation(x,10.0,c.sWeak())) solver .AddConstraint( c.LinearEquation(y,10.0,c.sWeak())) err |= not (x==10 and y==13 or x==7 and y==10) print ">> x=",x.Value(), "y=", y.Value() print "err:",err or "OK"
def addDelete2(): err = 0 x = c.Variable(); y = c.Variable(); solver = c.SimplexSolver(); solver .AddConstraint( c.LinearEquation(x, 100.0, c.sWeak())) solver .AddConstraint( c.LinearEquation(y, 120.0, c.sStrong())); c10 = c.LinearInequality (x,c.cnLEQ,10.0); c20 = c.LinearInequality (x,c.cnLEQ,20.0); solver .AddConstraint(c10) .AddConstraint(c20); err |= not (x==10 and y==120) print ">> x=",x.Value(), "y=", y.Value() solver.RemoveConstraint(c10); err |= x!=20 or y!=120 print ">> x=",x.Value(), "y=", y.Value() cxy = c.LinearEquation ( 2*x, y); solver.AddConstraint(cxy); err |= x!=20 or y!=40 print ">> x=",x.Value(), "y=", y.Value() solver.RemoveConstraint(c20); err |= x!=60 or y!=120 print ">> x=",x.Value(), "y=", y.Value() solver.RemoveConstraint(cxy); err |= x!=100 or y!=120 print ">> x=",x.Value(), "y=", y.Value() print "err:",err or "OK"
def addDelete1(): err = 0 x = c.Variable("x"); solver = c.SimplexSolver(); solver.AddConstraint( c.LinearEquation( x, 100, c.sWeak() )); c10 = c.LinearInequality(x,c.cnLEQ,10.0); c20 = c.LinearInequality(x,c.cnLEQ,20.0); solver .AddConstraint(c10) .AddConstraint(c20); err |= x.Value()!=10 print ">> x=",x.Value() print "-" print solver ; print "-" solver.RemoveConstraint(c10); print solver ; print "-" err |= x.Value()!=20 print ">> x=",x.Value() solver.RemoveConstraint(c20); err |= x.Value()!=100 print ">> x=",x.Value() c10again = c.LinearInequality(x, c.cnLEQ,10.0); solver .AddConstraint(c10) .AddConstraint(c10again); err |= x.Value()!=10 print ">> x=",x.Value() solver.RemoveConstraint(c10); err |= x.Value()!=10 print ">> x=",x.Value() solver.RemoveConstraint(c10again); err |= x.Value()!=100 print ">> x=",x.Value() print "err:",err or "OK"
def test_expression(): print "..var" x = c.Variable("x",7) y = c.Variable("y",8) print "x:", x.Value(), x print "y:", y.Value(), y print "..expr" l0 = c.LinearExpression(0) l1 = c.LinearExpression(x) print l0 +1 print l1 /2 print l1+y print (l1+2)/3 print l0+y+1.5 print y+3 l2 = l1+(y+1)/2 print l2 #def z(): # print l2.getTerms() print "..strength" s= c.sWeak() print s s= c.sStrong() print s s = c.Strength('boza', 1,1,1) print s if 10: print "..equation" leq = c.LinearEquation( x,23 ) print '1',leq.this # print '1',leq.this.Expression() print '1',leq.Expression() print '1',leq, "\n-----" if 10: leq = c.LinearEquation( l2,100 ) print '2',leq.this print '2',leq leq = c.LinearEquation( l2, 100, c.sWeak() ) print '3',leq.this print '3',leq leq = c.LinearEquation( x, 100, c.sWeak() ) print '4',leq.this print '4',leq leq = c.LinearEquation( x, y, c.sWeak() ) print leq if 10: print "..inequation" leq = c.LinearInequality( l2 ) print leq leq = c.LinearInequality( l2,c.cnLEQ,100 ) print leq leq = c.LinearInequality( l2,c.cnLEQ,x ) print leq leq = c.LinearInequality( x, c.cnGEQ, y, c.sStrong() ) print leq leq = c.LinearInequality( x, c.cnGEQ, y+1) print leq leq = c.LinearInequality( x, c.cnNEQ, y+5) #this does not work as expected; DO NOT USE print leq print '=====' c.StayConstraint( x, c.sMedium() ) return print "..bounds" solver = c.SimplexSolver() solver.AddBounds( x, 1, 5) solver.AddBounds( x, 1, y) solver.AddBounds( x, y, 7)