Beispiel #1
0
def test_LP_solve_Karmarkar_example ():
    p = Polyhedron('x1+x2==MAX')
    for i in range (11):
        p1 = mpq((i,10))*1
        p.add('2*%s*x1+x2<=%s+1' % (p1,p1**2))
    names, D = p.get_LP()
    Dwork = D[:]
    xopt, vopt = Dwork.LP_solve(overwrite=True)
    assert (D[0,1:] * xopt)[0,0]==vopt==mpq ((5,4)),`D[0,1:] * xopt,vopt`
Beispiel #2
0
def test_LP_solve_Karmarkar_example():
    p = Polyhedron('x1+x2==MAX')
    for i in range(11):
        p1 = mpq((i, 10)) * 1
        p.add('2*%s*x1+x2<=%s+1' % (p1, p1**2))
    names, D = p.get_LP()
    Dwork = D[:]
    xopt, vopt = Dwork.LP_solve(overwrite=True)
    assert (D[0, 1:] * xopt)[0, 0] == vopt == mpq(
        (5, 4)), ` D[0, 1:] * xopt, vopt `
Beispiel #3
0
def str2num(s):
    f = eval(s)
    i = int(f)
    if i == f:
        return i
    import sympycore, gmpy
    r = gmpy.f2q(f)
    n, d = int(r.numer()), int(r.denom())
    return sympycore.mpq((n, d))
Beispiel #4
0
def str2num(s):
    f = eval(s)
    i = int (f)
    if i==f:
        return i
    import sympycore, gmpy
    r = gmpy.f2q(f)
    n,d = int(r.numer ()), int (r.denom ())
    return sympycore.mpq((n,d))
Beispiel #5
0
def time2(n=500):
    import sympycore as sympy
    w = sympy.mpq((3,4))
    x = sympy.polynomials.PolynomialRing[1]([0, 1, 1])
    b = (x-1)*(x-2)*(x-w)
    a = (x-1)*(x-2)*(x-3)*(x-4)*(x-5)# + (x-1)*(x-2)*x**10
    t1 = clock()
    while n:
        divmod(a, b)
        n -= 1
    t2 = clock()
    return 100 / (t2-t1)