Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

After a long time looking at my code I have found that the constraints are defined before

def sol_zero_sum_game(M=matrix([[1,-1], [-1,1]]),code=1) :
    dim = M.nrows()
    U=ones_matrix(dim,dim)
    zsg=MixedIntegerLinearProgram(maximization=False, solver="GLPK")
    x=zsg.new_variable(real=True,nonnegative=True, indices=[0..dim-1])
    minM=min(min(M))
    Id= identity_matrix(dim)
    M1=(abs(minM)+1)*U+M
    Bzsgl=M1*x
    zsg.set_objective(sum(x[i] for i in range(dim)))
    #show(xx)
    for i in range(0,dim) :
           zsg.add_constraint(Bzsgl[i]>=1)
    zsg.solve()
    xx=zsg.get_values(x)
    if code==1 :
        return zsg.show()
    if code==2 :
        return xx

After a long time looking at my code I have found that the constraints are were defined before after calling solve

def sol_zero_sum_game(M=matrix([[1,-1], [-1,1]]),code=1) :
    dim = M.nrows()
    U=ones_matrix(dim,dim)
    zsg=MixedIntegerLinearProgram(maximization=False, solver="GLPK")
    x=zsg.new_variable(real=True,nonnegative=True, indices=[0..dim-1])
    minM=min(min(M))
    Id= identity_matrix(dim)
    M1=(abs(minM)+1)*U+M
    Bzsgl=M1*x
    zsg.set_objective(sum(x[i] for i in range(dim)))
    #show(xx)
    for i in range(0,dim) :
           zsg.add_constraint(Bzsgl[i]>=1)
    zsg.solve()
    xx=zsg.get_values(x)
    if code==1 :
        return zsg.show()
    if code==2 :
        return xx