Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A question of presentation

Here is a code which works as expected

nl=3
nc=2
ring=QQ
A=matrix(ring,nl,nc,[3,2,1,4,1,1])
b=vector(ring,[3,5,6])
c=vector(ring,[4,7])
sign=list([">=",">=","<="])
vsign=list([">=",">="])
show(LatexExpr(r"\boldsymbol{A}="),A)
show(LatexExpr(r"\boldsymbol{b}="),b)
show(LatexExpr(r"\boldsymbol{c}="),c)
show(LatexExpr(r"\boldsymbol{Signs}="),sign)
show(LatexExpr(r"\boldsymbol{Vsigns}="),vsign)

def primal_lp(opt,A,b,c,signAb,signx):
    nc=A.ncols()
    x = var("x_", n=nc)
    X=[xj for xj in x]
    Zer1 =[0 for v in x]
    Zer2 =[0 for v in range(len(signAb))]
    con=A*vector(X)
    z=c*vector(X)
    from _operator import le, ge, eq
    op1=[ge  if v==">=" else (le if v=='<=' else eq)  for v in signx]
    tt1=list(map(lambda u,v:u(*v), op1 ,zip(X,Zer1)))
    op2=[ge  if v==">=" else (le if v=='<=' else eq)  for v in signAb]
    tt2=list(map(lambda u,v:u(*v), op1 ,zip(con,Zer2)))
    z1=flatten([opt,z,tt2,tt1])
    return show(z1)
    primal_lp('max',A,b,c,sign,vsign)

I would like to present the results like

$\max 4 x_0 + 7 x_1$

$3 x_0 + 2 x_1\geq 0 $

$x_0+4 x_1 \leq 0$

$x_0+x_1=0$

$x_0≥0$

$x_1≤0 $

I have tried to use table but I haven't found any way to obtain the desired representation. Any idea ?