Ask Your Question
0

How to get slack values when using GLPK backend?

asked 2013-07-15 09:17:24 +0100

Shimi gravatar image

Hello, When using sagemath to compute a linear programming problem(using GLPK backend), is there a way to get the slack values other than the full p.print_ranges()? that is just send the slacks(surplus) to a variable or vector? Thanks.

edit retag flag offensive close merge delete

Comments

It would help if you post a small working example of how you are using GLPK.

niles gravatar imageniles ( 2013-07-15 12:50:34 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2013-07-15 14:31:14 +0100

tmonteil gravatar image

There seems not to be a method for that in Sage. Those values are not returned but printed by the method .print_ranges(), but you can still get the lines by doing:

sage: s = open(SAGE_TMP+"/ranges.tmp").readlines()

and then try to parse the list of strings s.

For example, if you want to extract the values of the "Slack Marginal" field, you can do:

sage: L = []
sage: interesting = False
sage: for line in s:
sage:     try:
sage:         if line[45:50] == 'Slack':
sage:             interesting = True
sage:     except IndexError:
sage:         pass
sage:     if line.startswith('GLPK'):
sage:         interesting = False
sage:     if interesting:
sage:         try:
sage:             L.append(RR(line[37:50]))
sage:         except TypeError:
sage:             pass

Note that i do not know the meaning of the isolated dots in this column (perhaps they mean 0 or something else), so you may have to adapt this.

edit flag offensive delete link more

Comments

1

surely there are some clues for a better solution in the source code of `.print_ranges()`, aren't there?

niles gravatar imageniles ( 2013-07-15 15:39:50 +0100 )edit
1

Not really, the `.print_ranges()` method only prints the file `SAGE_TMP+"/ranges.tmp"`, and this file seems to be created by GLPK since it does not appear anywhere else in the Sage source code.

tmonteil gravatar imagetmonteil ( 2013-07-15 16:53:35 +0100 )edit

Thanks for the reply. The problem wound up being much simpler to formulate and get the necessary values using lp_solve.

Shimi gravatar imageShimi ( 2013-07-16 05:36:46 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-07-15 09:17:24 +0100

Seen: 431 times

Last updated: Jul 15 '13