コード例 #1
0
ファイル: test.py プロジェクト: svilendobrev/cassowarypy
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"
コード例 #2
0
ファイル: test.py プロジェクト: svilendobrev/cassowarypy
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)