Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Double indexed variables in linear programming

The following linear programming code works perfectly.

nlg=4 #nombre de contraintes
mlg=6 #nombre de variables
Alg= matrix(nlg,mlg,[0,0,0,1,1,1,
                 1,0,0,1,0,0,
                 0,1,0,0,1,0,
                 1,1,3,0,0,0
                ]) # les coefficients
blgmin = [1,0,0,1] # les bornes inférieures pour les contraintes
blgmax = [1,0,0,3] # les bornes supérieures pour les contraintes (oo = infini)
show(LatexExpr('A = '),Alg)
show(LatexExpr('bmin = '),blgmin)

    show(LatexExpr('bmax = '),blgmax)
    lg = MixedIntegerLinearProgram(maximization=False, solver = "GLPK") # on crèe le programme

  x = lg.new_variable(integer=True, indices=[0..mlg-1]) # les nouvelles variables sont x[0] ... x[5]
    Blg = Alg * x # la fonction linéaire pour les contraintes
    lg.set_objective(x[0])# fixe l’objectif
    # On construit les contraintes avec leurs bornes
    for i in range(nlg) :
        lg.add_constraint(Blg[i], min=blgmin[i], max=blgmax[i])
    for i in range(mlg-1) :
        lg.set_binary(x[i])    
    lg.show()
    lg.solve()
    xx=lg.get_values(x)
    show(xx)

But now, for an other problem, I would like to define

1) variables with other names

2) double indexed variables

Is this possible ?