[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] new version of python-glpk

From: Joao Pedro Pedroso
Subject: [Help-glpk] new version of python-glpk
Date: Mon, 26 Apr 2010 20:35:22 +0400

Dear GLPK users,

There is a new version of the python-glpk interface available:

The integration between Python and GnuMathProg is now much deeper,
allowing to define/modify data in Python, as in the example below
(available in the python-glpk's distribution as "").

Best regards,

from glpk import *

# create an LP as an instance of class "glpk",
# based on the model "diet.mod" (coming in glpk's "examples")
problem = glpk("models/diet.mod")

# solve
print "\n\nsolution:", problem.solution()

# define/modify problem data:
# "F" and "a" are, respectively, a "set" and a "param" in "diet.mod";
# now, they can be accessed in Python as members of the "glpk" instance
problem.F += ['Bacalhau']       # add a new food
problem.a['Bacalhau','Calorie']    = 87.3       # nutrients
problem.a['Bacalhau','Protein']    = 98.7
problem.a['Bacalhau','Calcium']    = 17.3
problem.a['Bacalhau','Iron']       = 12.3
problem.a['Bacalhau','Vitamin-A']  = 12.3       

# update and solve
print "\n\nsolution:", problem.solution()

# one more update
problem.F.remove('Bacalhau')    # remove food
for key in problem.a.keys():
    if 'Bacalhau' in key:
        del problem.a[key]

# update and solve
print "\n\nsolution:", problem.solution()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]