Exemplo n.º 1
0
def solve_lcp_file(lcp_file):
    unarch = Unarchiver(lcp_file)
    lcp = LCPObj(unarch.M,unarch.q)
    
    # Augment
    (n,) = lcp.q.shape
    alcp,x0,y0 = augment_lcp(lcp,5*n)
    (N,) = alcp.q.shape
    assert(N == n + 1) # Augmented
    
    (p,d,data) = kojima_solve(alcp,
                              x0=x0,
                              y0=y0)

    print '#'*20
    print 'FINISHED'
    print 'Slack variables', p[-1],d[-1]
        
    # Strip augmented variable and expand omitted nodes
    p = p[:-1]
    d = d[:-1]

    filename, file_extension = os.path.splitext(lcp_file)
    print "Writing solution to ",  filename + '.sol'
    arch = Archiver(p=p,d=d)
    arch.write(filename + '.sol')
Exemplo n.º 2
0
def solve_plcp_file(plcp_file):
    unarch = Unarchiver(plcp_file)
    (P,U,q) = (unarch.P,unarch.U,unarch.q)
    (n,) = q.shape
    plcp = ProjectiveLCPObj(P,U,q)
    
    # Augment
    alcp,x0,y0,w0 = augment_plcp(plcp,5 * n)
    (N,) = alcp.q.shape
    assert(N == n + 1) # Augmented
    
    (p,d,data) = projective_solve(alcp,
                                  x0=x0,
                                  y0=y0,
                                  w0=w0)

    print '#'*20
    print 'FINISHED'
    print 'Slack variables', p[-1],d[-1]
        
    # Strip augmented variable and expand omitted nodes
    p = p[:-1]
    d = d[:-1]

    filename, file_extension = os.path.splitext(plcp_file)
    sol_file =  filename + '.psol'
    print "Writing solution to ", sol_file
    arch = Archiver(p=p,d=d)
    arch.write(sol_file)