pymprog-help Mailing List for PyMathProg
An easy and flexible mathematical programming environment for Python.
Brought to you by:
lanyjie
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(2) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2014 |
Jan
|
Feb
(1) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Junior B. <jrb...@gm...> - 2019-10-01 18:52:52
|
Hi. How to set time limit in pymprog? Thank you. -- *Júnior César Bonafim* *Docente Faculdade de Tecnologia de Ribeirão Preto - FATEC* |
From: abbas o. <abb...@gm...> - 2019-06-26 20:10:58
|
Hi, Is there any way to read an lp/mps file using the pymprog? regards |
From: Joshua F. <cro...@gm...> - 2018-11-26 22:10:28
|
I have a few questions. 1. GLPK can convert SAT problems from Mathprog modeling language and solve using MinSAT. Is it possible to do this with pymprog, i.e. formulate at a problem as a 0-1 integer problem using your python library and have it solve it in minsat instead of GLPK. 2. Part of my research involves solving big 0-1 integer programs, and GLPK is the slowest solver in the world (at least compared to CBC, SCIP, CPLEX, and GUROBI). Is it possible to program in pymprog and solve with a faster solver, at the very least CBC. I know PULP does this already, but I really like the simple syntax which is is much better than PULPs. -- Joshua Friedman PhD Cro...@gm... http://www.math.sunysb.edu/~joshua |
From: Sarah V. <sva...@gm...> - 2018-03-14 18:16:15
|
Hi, I am experiencing an issue setting parameters in v1.1.2. From the webpage documenting v1.0, I expect that executing: >>> r = {(3,4):3, (1,2):4} >>> R = par('R', r) would result in >>> R{(1, 2): (R[1,2]:4), (3, 4): (R[3,4]:3)} However, what actually occurs is >>> R{(1, 2): [(R[1:4), (2]:0)], (3, 4): [(R[3:3), (4]:0)]} Based on the documentation this seems like a bug. Is there a workaround for this? Thanks, Sarah |
From: Whitmore, L. <lw...@sa...> - 2017-04-18 23:18:58
|
Hi all, I am curious to know if there is some way using pymprog to import a model from a glp or mps file. Any help on this matter would be greatly appreciated. -------------------------------- Leanne Whitmore, PhD Postdoctoral Appointee Sandia National Labs Phone: 925-294-2469 |
From: usa u. <usa...@gm...> - 2015-03-31 19:27:13
|
Hi, I am trying to install pymprog by following the instructions at: http://pymprog.sourceforge.net/setup.html The easy way: 1. Setup Python 2.5.4. 2. Install GLPK: a setup program can be downloaded here <http://gnuwin32.sourceforge.net/packages/glpk.htm> and make sure your PATH enviroment variable contains the path to the glpk.dll file (by default in english language, it is in folder “C:\Program Files\GnuWin32\bin”). 3. Download *dist#.#.zip (*where #.# is the version) and unzip it, you will find two windows installer, and a zip file containing the source files. Run both installers. Unzip the source files and you can now play with the examples there. *I have installed * *Python 2.5 and GLPK.Where to find dist#.#.zip ? * Thanks David |
From: guillaume <gcm...@fr...> - 2015-01-16 19:05:15
|
Bonjour - good morning I am a mathematics teacher in France ; I have written a programm in python 2.7 using glpk via pymprog to solve a supply chain network design problem. May it be interesting for anyone ? Thank you Guillaume Cantin |
From: Yingjie L. <la...@ya...> - 2014-03-19 09:25:17
|
Hi Rogdrigo, This looks like you have not properly installed the package. You should follow the directions on how to build and setup the package in the manual, which comes with the source and also available online: http://pymprog.sourceforge.net/ Best, Yingjie On Friday, February 28, 2014 5:21 AM, Rodrigo Cesar Silva <rod...@gm...> wrote: I tried to run the dive-in first example but an error appeared. Following are the commands I entered and the error: > > >IDLE 1.2.4 >>>> from pymprog import * # Import the module ># index and data >xid, rid = range(3), range(3) >c = (10.0, 6.0, 4.0) >mat = [ (1.0, 1.0, 1.0), > (10.0, 4.0, 5.0), > (2.0, 2.0, 6.0)] >b = (100.0, 600.0, 300.0) >#problem definition >beginModel('basic') >verbose(True) >x = var(xid, 'X') #create variables >maximize( #set objective > sum(c[i]*x[i] for i in xid), 'myobj' >) >r=st( #set constraints > sum(x[j]*mat[i][j] for j in xid) <= b[i] for i in rid >) >solve() #solve and report >print "Solver status:", status() > > > > > > >Traceback (most recent call last): > File "<pyshell#0>", line 1, in <module> > from pymprog import * # Import the module > File "C:\Python25\lib\site-packages\pymprog.py", line 31, in <module> > from glpk import LPX >ImportError: DLL load failed with error code 193 > > >What could be the problem? > > >Thanks, > > >Rodrigo. >------------------------------------------------------------------------------ >Flow-based real-time traffic analytics software. Cisco certified tool. >Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer >Customize your own dashboards, set traffic alerts and generate reports. >Network behavioral analysis & security monitoring. All-in-one tool. >http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk >_______________________________________________ >pymprog-help mailing list >pym...@li... >https://lists.sourceforge.net/lists/listinfo/pymprog-help > > > |
From: Yingjie L. <la...@ya...> - 2014-03-19 09:22:27
|
Hi Matias, Sorry for getting back to you so late. Please look at the manual on how to build and setup. The manual advise against VC. You should use mingw. The manual comes with your download, or you can also view online at: http://pymprog.sourceforge.net/ Hope this helps. Let me know if you still have problems. Best, Yingjie On Monday, November 18, 2013 12:40 PM, Matias Palma <mpa...@gm...> wrote: I am installing the GLPK to be used by Coopr to solve Pyomo models. When I run build_GLPK_with-VC10 to generate files gplsol.exe and glpk.lib and then copy to python the command prompt gives the error" the system cannot find the path specified. The path is Visual Studio 10.0\VC”\bin\nmake.exe” . I download the visual basic10 I have the folder VC but I do not have folder called “bin” and I do not have nmake.exe . Somebody knows how to solve that >------------------------------------------------------------------------------ >DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps >OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access >Free app hosting. Or install the open source package on any LAMP server. >Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! >http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk >_______________________________________________ >pymprog-help mailing list >pym...@li... >https://lists.sourceforge.net/lists/listinfo/pymprog-help > > > |
From: Rodrigo C. S. <rod...@gm...> - 2014-02-27 21:21:21
|
I tried to run the dive-in first example but an error appeared. Following are the commands I entered and the error: IDLE 1.2.4 >>> from pymprog import * # Import the module # index and data xid, rid = range(3), range(3) c = (10.0, 6.0, 4.0) mat = [ (1.0, 1.0, 1.0), (10.0, 4.0, 5.0), (2.0, 2.0, 6.0)] b = (100.0, 600.0, 300.0) #problem definition beginModel('basic') verbose(True) x = var(xid, 'X') #create variables maximize( #set objective sum(c[i]*x[i] for i in xid), 'myobj' ) r=st( #set constraints sum(x[j]*mat[i][j] for j in xid) <= b[i] for i in rid ) solve() #solve and report print "Solver status:", status() *Traceback (most recent call last):* * File "<pyshell#0>", line 1, in <module>* * from pymprog import * # Import the module* * File "C:\Python25\lib\site-packages\pymprog.py", line 31, in <module>* * from glpk import LPX* *ImportError: DLL load failed with error code 193* What could be the problem? Thanks, Rodrigo. |
From: Matias P. <mpa...@gm...> - 2013-11-18 04:39:57
|
I am installing the GLPK to be used by Coopr to solve Pyomo models. When I run build_GLPK_with-VC10 to generate files gplsol.exe and glpk.lib and then copy to python the command prompt gives the error" the system cannot find the path specified. The path is Visual Studio 10.0\VC”\bin\nmake.exe” . I download the visual basic10 I have the folder VC but I do not have folder called “bin” and I do not have nmake.exe . Somebody knows how to solve that |
From: yuanqian <yua...@tj...> - 2012-07-27 03:42:20
|
Dear Sir/Madam Hello, I am using Python 2.7 in Windows with some packages and I would like to setup PyMathProg. After installing GLPK, i downloaded dist0.4.2. But I am not able to install the windows installer glpk-0.3.3.win32-py2.5.exe because it says that I must have Python 2.5 installed. After I install Python 2.5, I can not install it successfully.It said "Could not create key glpk-py2.5" "Could not set key value Python2.5 glpk-0.3.3" How could I install it successfully and How could I use PyMathProg with Python 2.7 ? Thank you very much! |
From: Edd B. <ve...@gm...> - 2012-06-23 17:16:38
|
Hi, I was wondering if pymprog can support arbitrary precision solving of MILP programs? I notice that we lose precision when working with large numbers, for example: ---8<--- import pymprog import sys bits = 64 # large values offset = 5 l_val = 2**bits - offset u_val = 2**bits - 1 print("offset = %d" % offset) print("l = %d" % (l_val)) print("u = %d" % (u_val)) pymprog.beginModel() pymprog.solvopt(msg_lev=pymprog.LPX.MSG_ERR) # make vars l = pymprog.var(name="l", bounds=(0, 2**bits-1), kind=float) u = pymprog.var(name="u", bounds=(0, 2**bits-1), kind=float) # objective o = l + u pymprog.minimize(o, "objective") # l = l_val pymprog.st(l <= l_val) pymprog.st(l >= l_val) # u = u_val pymprog.st(u <= u_val) pymprog.st(u >= u_val) pymprog.solve() print("solve was " + pymprog.status()) print("%s: %d" % ("l", l.primal)) print("%s: %d" % ("u", u.primal)) print("We expected l = %d" % (l_val)) print("We expected u = %d" % (u_val)) if l.primal != l_val or u.primal != u_val: raise Exception("Oh no!") else: print("OK") ---8<--- Gives: ---8<--- % python pmp.py offset = 5 l = 18446744073709551611 u = 18446744073709551615 solve was opt l: 18446744073709551616 u: 18446744073709551616 We expected l = 18446744073709551611 We expected u = 18446744073709551615 Traceback (most recent call last): File "pmp.py", line 44, in <module> raise Exception("Oh no!") Exception: Oh no! ---8<--- Cheers -- Best Regards Edd Barrett http://www.theunixzoo.co.uk |
From: Jens H. <jen...@tu...> - 2012-04-27 12:48:41
|
Hello, as a new user of the PyMathProg library I'm trying to come up with an integer linear program formulation for an assignment problem similar to your example at http://pymprog.sourceforge.net/advanced.html but with additional constraints. My problem is that, even though I declared my variables boolean and using the integer solver, I end up with a solution that does not seem to be an integer, but a relaxed solution to my problem. I would very much appreciate if you could give me some advice on whether I'm using the solver correctly. A minimal example of the code I'm running is as follows, while a more reader friendly formulation can be found in the attachment. def example(c, l, m, n): ''' m = number of agents n = number of tasks nxn cost matrix filled with positive real values c = costmatrix nxn linking constraint matrix filled with boolean values diagonal values are all zero l = linking matrix ''' from numpy import reshape, array ## transpose linking matrix l = array(l).T l = l.tolist() n = len(c[0]) m = len(c) N = range(n) M = range(m) print 'Minimize:' print ' sum_{i=1}^{n}sum_{i=1}^{n} c_{ij}x_{ij}' print 'Subject to:' print '(1) sum_{j=1}^{n} x_{ij} = 1, for all i in {1,2,...,n}' print ' \"Every SeqPos can have max. one assigned Residue.\"' print '(2) sum_{i=1}^{n} x_{ij} = 1, for all j in {1,2,...,n}' print ' \"Every Residue can be assigned to max one SeqPos.\"' print '(3) x_{ij+1} <= (L^TX)_{ij},' print ' for all i in {1,2,...,n} and for all j in {1,2,...,n-1}' print ' \"Assignment has to be consistent with linking, s.t.' print ' IF residue k is assigned to sequence position j,' print ' THEN position j+1 can only be assigned to a residue k\'' print ' that is a valid successor of residue k, that is' print ' when L[k][k\'] = 1\"' print beginModel("assign") verbose(True) #Turn on this for model output A = iprod(M, N) #combine index #declare variables x = var(A, 'x', kind=bool) #assignment decision vars #declare parameters: tc = par(c, 'C') ## cost matrix lt = par(l, 'L') ## linking matrix (transposed) minimize(sum(tc[i][j] * x[i, j] for i, j in A), 'totalcost') ## objective st([sum(x[k, j] for j in N) == 1 for k in M], 'residue') st([sum(x[i, k] for i in M) == 1 for k in N], 'sequence pos') st([x[i, j + 1] <= sum(lt[i][k] * x[k, j] for k in N) for i, j in A if j < (n - 1)], 'linking') solve('int') ## integer solver assign = [(i, j) for i in M for j in N if x[i, j].primal > .5] endModel() X = reshape([x[i, j].primal for i in range(n) for j in range(n)], (n, n)) return assign, X if __name__ == "__main__": m = 4 # residues n = 4 # sequence positions c = [[.0, .1, .1, .1], [.1, .0, .1, .1], [.1, .1, .0, .1], [.1, .1, .1, .0]] l = [[0, 1, 0, 1], [0, 0, 1, 1], [0, 0, 0, 1], [1, 1, 1, 0]] assign, X = example(c, l, m, n) print 'X= ' print X --------------------------- Jens Hooge AG Bernhard Schölkopf Department: Machine Learning Max Planck Institute for Intelligent Systems Spemannstr. 38 72076 Tübingen Phone: +49-7071-601557 http://www.kyb.tuebingen.mpg.de/nc/employee/details/jhooge.html |
From: Shawn H. <hel...@gm...> - 2011-04-09 17:56:46
|
Hi Yingjie, Thanks for making a modeling language for python that is close to MathProg. I really like the syntax you came up. There are some other math modeling choices for python such as PuLP and Coopr, but I find yours easier to read -- way to go! Question -- Have you thought of connecting to other solvers besides GLPK? PuLP and Coopr are nice because the connect with CBC, CPLEX and Gurobi which all have a branch and cut, which appear to run faster than GLPK. Just an idea, but it would be really cool if you could borrow from those projects to incorporate how they work with these other solvers. Great project you have, Shawn |
From: Yingjie L. <la...@ya...> - 2010-11-24 13:05:09
|
--- On Tue, 11/23/10, Gerardo Berbeglia <gbe...@gm...> wrote: > From: Gerardo Berbeglia <gbe...@gm...> > Subject: [pymprog] question MPS file > To: pym...@li... > Date: Tuesday, November 23, 2010, 8:57 PM > Does PyMathProg have a procedure to > save an LP or ILP model into a > file under the MPS format? > Thanks. > > Yes, it is already there. Write problem to fixed MPS format file: lp.write(mps=filename) For other formats, see >>> import pymprog >>> help(pymprog.model.write) Hope this helps. Yingjie |
From: Gerardo B. <gbe...@gm...> - 2010-11-23 16:57:24
|
Does PyMathProg have a procedure to save an LP or ILP model into a file under the MPS format? Thanks. |
From: Gerardo B. <gbe...@gm...> - 2010-10-12 19:43:56
|
Hello, I am using Python 2.6 in Windows with some packages such as Numpy and I would like to setup PyMathProg. After installing GLPK, i downloaded dist0.4.2. But I am not able to install the windows installer glpk-0.3.3.win32-py2.5.exe because it says that I must have Python 2.5 installed. How could I use PyMathProg with Python 2.6 ? Thanks, Gerardo. |
From: Seung Mo Gu <su...@gm...> - 2010-04-10 19:29:35
|
Hello! I tried installing pymathprog but ran into some errors. I'll try to be explicit in my installation procedure in case there was something I missed out or messed up on. Originally I had Python v2.6 but since the installation guide for pymathprog insisted 2.5.4 I uninstalled 2.6 for it. currently it is installed to the c: directory itself. I installed glpk from off the site and installed it to the Program Files directory. (I'm currently on a windows 7 machine and it by default suggests the Program Files (x86) directory but I installed it to the original one. After installing python and glpk, I downloaded the zip file and unzipped it. When running either of the installation files 2 error windows appeared. 1) "Could not set key value" with message "Python 2.5 glpk-0.3.3" or "Python 2.5 pymprog-0.4.2" depending on which install files you run 2) "Could not set key value" with message "C:\Python25\Removeglpk.exe" -u "C:\Python25\glpk-wininst.log" or " "C:\Python25\Removepymprog.exe" -u "C:\Python25\pymprog-wininst.log" again depending on which install files you run I don't get the error messages when i run both files as administrator. However when i "from pymprog import *" the idle shell displays the following error message: >>> from pymprog import * Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> from pymprog import * File "C:\Python25\lib\site-packages\pymprog.py", line 31, in <module> from glpk import LPX ImportError: DLL load failed: The specified module could not be found. >>> I'm not sure what I'm doing wrong. I did have glpk installed before along with gusek (an IDE for glpk). But even after uninstalling and reinstalling everything, I get the same message. Any help? |
From: Nico G. <nic...@gm...> - 2010-04-08 13:46:32
|
Hi everyone, I also posted this question in the pymprog Forum. Generally, a Forum seems to be the more comfortable place for discussing and archiving solutions. But I messed up my post a little and can't seem to find an "edit"-button. So, here my question again on the mailing list: Is there a way to get all possible solutions from a zero sum game problem? To illustrate what I mean, I altered the example from the <http://pymprog.sourceforge.net/tutorial.html#zero-sum-two-player-game> tutorial: #####Solve this 2-player 0-sum game: ## ## Gain for player 1 ## (Loss for player 2) ## ## || Player 2 ## Player 1 || B1 B2 B3 ## A1 || -1 1 0 ## A2 || 1 -1 0 ## A3 || 0 0 0 ## ############################## beginModel('game') # the gain of player 1 v = var(name='game_value', bounds=(None,None)) #free # mixed strategy of player 2 p = var([1,2,3], 'prob') # player 2 wants to minimize v minimize(v) # probability sums to 1 st(p[1]+p[2]+p[3] == 1) # player 1 plays the best strat. r1=st(v >= -1*p[1] + 1*p[2] + 0*p[3]) r2=st(v >= 1*p[1] + -1*p[2] + 0*p[3]) r3=st(v >= 0*p[1] + -0*p[2] + 0*p[3]) solve() print v print "Player 1's mixed Strategy:" print "A1:", r1.dual, "A2:", r2.dual, "A3:", r3.dual print "Player 2's mixed strategy:" print p endModel() [/code] The result is: game_value=0.000000 Player 1's mixed Strategy: A1: 0.5 A2: 0.5 A3: 0.0 Player 2's mixed strategy: {1: prob[1]=0.500000, 2: prob[2]=0.500000, 3: prob[3]=0.000000} But obviously, this is not the only solution. The strategy {A1: 0.0 A2: 0.0 A3: 1.0} has the same expectation value, as well as for example {A1: 0.25 A2: 0.25 A3: 0.5} or any other strategy where A1 and A2 are chosen in the same proportion and in the rest of the cases A3 is played. Now, since there are infinite many solutions, the simple answer to my question must obviously be: "No, you can't list all possible solutions to such a problem." But it is most unsatisfying that there seems to be no feedback that additional solutions exist. If maybe at least the extrema could be suggested as solutions? (in this case, {A1: 0.0 A2: 0.0 A3: 1.0} and {A1: 0.5 A2: 0.5 A3: 0.0} are the extrema of the solution space.) Would be glad to get feedback. Thanks, Bye Sano |
From: Nico G. <nic...@gm...> - 2010-04-08 13:38:28
|
Hi Yingjie, not, it's not too late at all - this project is a persistent one. ^_- Thank you very much - I see now that I must get more accustomed to the generator syntax. Generally, is there a way to initialize an "empty" pymprog variable? I stumbled upon this problem when I tried to change the constraint from the zero-sum-game example for arbitrarily large games. In: st(p[1]+p[2]+p[3] == 1) the number of ps is already fixed to three. So, my idea was: ------------------------------ p = var([1,2,3]) sum = var() for i in range (len(p)): sum = sum + p[i+1] st(sum == 1) -------------------------------- The problem is that sum = var() leads sum being to X1=0.000000. And with that, my final condition ends up being: X0[1]+ X0[2]+ X0[3]+ X1 To get around this, I used a rather clumsy trick: ------------------------------- p = var([1,2,3]) sum = p[1] for i in range (len(p)-1): sum = sum + p[i+2] st(sum == 1) -------------------------------- I can't remember why I didn't just initialize sum as an int with value zero, but there must have been a reason for this. -_-° Anyway: Is there a way to initialize an empty pymprog variable? If not, is there a smart way to do this with generators? Many Thanks Bye Nico -----Ursprüngliche Nachricht----- Von: Yingjie Lan [mailto:la...@ya...] Gesendet: Montag, 8. März 2010 06:50 An: pym...@li...; Nico Grupp Betreff: Re: [pymprog] Constraints and Iteration > > m = 3 # 3 > strategies > > M = > range(m) # payoffs of player A > > n = 3 # 3 > strategies > > N = range(n) # payoffs > of player B > > > > (…) > > > > > > class Test: > > > def > __init__(self): > > > beginModel('game') > > > self.x = > var(A, 'x') > > > > > > So far, so good. > But when I try to > implement point 3, it doesn’t work. The idea was to > ensure that: > > > > payoff of > self.x[i,j] = - payoff of self.x[j,i] > > > > and it’d best > be done with > iterations. But when trying something like this: > > > > > > for i in > M: > > > for j in N: > > > st((self.x[i,j]) == > -(self.x[i,j])) > > > > > > it leads > to: > Hi, Nico: It is probably too late, but I tested with the code below: #--------------------Cut----------------------- from pymprog import * m = 3 # 3 strategies M = range(m) # payoffs of player A n = 3 # 3 strategies N = range(n) # payoffs of player B A = iprod(M,N) class Test: def __init__(me): beginModel('game') me.x = var(A,'x') #st((me.x[i,j]) == -(me.x[j,i]) for i,j in A) for i in M: for j in N: print st((me.x[i,j]) == - (me.x[j,i])) t=Test() #--------------------Cut----------------------- And this is the output (note: you might want to check if you are using the latest version of pymprog): #--------------------Cut----------------------- yaellan:pymprog xiaoliz$ python testreg.py s.t. R0: 2 x[(0, 0)] == 0 s.t. R1: x[(0, 1)]+ x[(1, 0)] == 0 s.t. R2: x[(2, 0)]+ x[(0, 2)] == 0 s.t. R3: x[(0, 1)]+ x[(1, 0)] == 0 s.t. R4: 2 x[(1, 1)] == 0 s.t. R5: x[(1, 2)]+ x[(2, 1)] == 0 s.t. R6: x[(2, 0)]+ x[(0, 2)] == 0 s.t. R7: x[(1, 2)]+ x[(2, 1)] == 0 s.t. R8: 2 x[(2, 2)] == 0 #--------------------Cut----------------------- Cheers, Yingjie |
From: Yingjie L. <la...@ya...> - 2010-03-08 06:16:28
|
> > m = 3 # 3 > strategies > > M = > range(m) # payoffs of player A > > n = 3 # 3 > strategies > > N = range(n) # payoffs > of player B > > > > (…) > > > > > > class Test: > > > def > __init__(self): > > > beginModel('game') > > > self.x = > var(A, 'x') > > > > > > So far, so good. > But when I try to > implement point 3, it doesn’t work. The idea was to > ensure that: > > > > payoff of > self.x[i,j] = - payoff of self.x[j,i] > > > > and it’d best > be done with > iterations. But when trying something like this: > > > > > > for i in > M: > > > for j in N: > > > st((self.x[i,j]) == > -(self.x[i,j])) > > > > > > it leads > to: > Hi, Nico: It is probably too late, but I tested with the code below: #--------------------Cut----------------------- from pymprog import * m = 3 # 3 strategies M = range(m) # payoffs of player A n = 3 # 3 strategies N = range(n) # payoffs of player B A = iprod(M,N) class Test: def __init__(me): beginModel('game') me.x = var(A,'x') #st((me.x[i,j]) == -(me.x[j,i]) for i,j in A) for i in M: for j in N: print st((me.x[i,j]) == - (me.x[j,i])) t=Test() #--------------------Cut----------------------- And this is the output (note: you might want to check if you are using the latest version of pymprog): #--------------------Cut----------------------- yaellan:pymprog xiaoliz$ python testreg.py s.t. R0: 2 x[(0, 0)] == 0 s.t. R1: x[(0, 1)]+ x[(1, 0)] == 0 s.t. R2: x[(2, 0)]+ x[(0, 2)] == 0 s.t. R3: x[(0, 1)]+ x[(1, 0)] == 0 s.t. R4: 2 x[(1, 1)] == 0 s.t. R5: x[(1, 2)]+ x[(2, 1)] == 0 s.t. R6: x[(2, 0)]+ x[(0, 2)] == 0 s.t. R7: x[(1, 2)]+ x[(2, 1)] == 0 s.t. R8: 2 x[(2, 2)] == 0 #--------------------Cut----------------------- Cheers, Yingjie |
From: Nico G. <nic...@gm...> - 2010-01-22 10:11:46
|
Hi everybody, I'm working on a way to do inverse linear optimization for 2 player zero sum games, but I'm encountering some problems concerning the constraints. When doing the inverse optimization, I know the probabilities with which each strategy is played in the nash equilibrium and want to calculate one of the many combinations of payoffs, so that my desired probabilities are a solution to this game. So, regarding this example: http://pymprog.sourceforge.net/tutorial.html#zero-sum-two-player-game, I want to do it basically the other way around. To make things easier, I'm only regarding symmetric two player zero sum games like Rock-Paper-Scissors (RPS), which enables me to make further assumptions: 1) Both players have the same set of strategies available 2) If both players utilize the same strategy, the payoff for both is zero 3) If strategy A versus strategy B leads to an outcome of X, then strategy B versus strategy A will lead to an outcome of -X (If I win with paper vs. rock and score one point, I will also lose one point if my opponent pulls the same trick and uses his paper vs. my rock). Now, there are several issues I have with the constraints. I have created the matrix like in example http://pymprog.sourceforge.net/advanced.html#re-optimize-the-assignment: m = 3 # 3 strategies M = range(m) # payoffs of player A n = 3 # 3 strategies N = range(n) # payoffs of player B (.) class Test: def __init__(self): beginModel('game') self.x = var(A, 'x') So far, so good. But when I try to implement point 3, it doesn't work. The idea was to ensure that: payoff of self.x[i,j] = - payoff of self.x[j,i] and it'd best be done with iterations. But when trying something like this: for i in M: for j in N: st((self.x[i,j]) == -(self.x[i,j])) it leads to: File "C:\Users\sano98\workspace\Balancer\src\Test.py", line 77, in calculate st((self.x[i,j]) == -(self.x[i,j])) File "C:\Python25\Lib\site-packages\pymprog.py", line 77, in st return prob.st(cons, name, inds) File "C:\Python25\Lib\site-packages\pymprog.py", line 267, in st cons = [t for t in cons] #copy TypeError: 'bool' object is not iterable Strangely, the constraint itself seems to work when called without iteration: self.constraint_01= st(self.x[0,1] == -(self.x[1,0])) self.constraint_02= st(self.x[0,2] == -(self.x[2,0])) self.constraint_03= st(self.x[2,1] == -(self.x[1,2])) But when it comes to place assumption 2) in the form of a constraint, it doesn't even work this way, since: self.constraint_04= st(self.x[0,0] == 0) also leads to File "C:\Users\sano98\workspace\Balancer\src\Test.py", line 98, in calculate self.constraint_04= st(self.x[0,0] == 0) File "C:\Python25\Lib\site-packages\pymprog.py", line 77, in st return prob.st(cons, name, inds) File "C:\Python25\Lib\site-packages\pymprog.py", line 267, in st cons = [t for t in cons] #copy TypeError: 'bool' object is not iterable Now, does anyone have an idea what the problem is? I can't seem to find any pattern why some of those things work and some don't. Thanks for the time and effort and hopefully for a solution or hint. ^_- Bye Nico |
From: Alex W. <sa...@uk...> - 2009-12-09 05:52:10
|
Hello, I'm taking a linear programming course, and I'm attempting to write an efficient frontier problem based on the code in http://www.orfe.princeton.edu/~rvdb/307/lectures/lec3.pdf With verbose on, I get an error: Traceback (most recent call last): File "project2.py", line 68, in <module> sum(dev[t] for t in T) / float(n) <= risk File "C:\Python25\Lib\site-packages\pymprog.py", line 76, in st return prob.st(cons, name, inds) File "C:\Python25\Lib\site-packages\pymprog.py", line 246, in st if me.verb: cons.exprint() AttributeError: 'constraint' object has no attribute 'exprint' The line that causes it is c1 = st( sum(dev[t] for t in T) / float(n) <= risk ) Where the relevant code is dates = [] # Time entries for data in portfolio: if (data[2] not in dates): dates.append(data[2]) A[data[0]].append(data[1]) n = len(dates) T = range(1, n) dev = var(T, 'T') # Dictionary with keys in T risk = 0.08 I can run the basic.py example, though. Any help? -Alex |
From: Alan R. <dal...@ms...> - 2009-07-30 02:18:40
|
Hello Yingjie I am new to both GLPK and of course PyMathProg. On my side I am spending time in the book "The Science of Decision Making" http://www.amazon.com/Science-Decision-Making-Problem-Based-Approach/dp/0471318272/ref=sr_1_1?ie=UTF8&qid=1248919635&sr=8-1 The book dives into Linear Programming with Excel as the main tool. My goal is to build my skills in linear programming models with Excel and then transition those skills to Python. I was using Python with OpenOpt at first and once I got an idea of how it worked I found it also did not have a built in way to define a "Sensitivity Analysis". Reading various Newsgroup posts I thought GLPK could perform a "Sensitivity Analysis", hence it seemed to make sense that PyMathProg could do so. So here are my questions 1) Did I make a big assumption that GLPK could perform a "Sensitivity Analysis"? 2) If I did not make a wrong assumption, then what would it take to have PyMathProg perform a "Sensitivity Analysis"? I am very big on the idea of "Sensitivity Analysis" due to what I have read in both this book and the paper by Ed Leamer "Let's Take the Con Out of Econometrics" http://ideas.repec.org/p/cla/uclawp/239.html (I can't say I know all the math in this paper, but I grasped his point about using "Sensitivity Analysis" to determine how valid are the results of the model). Thank you Alan Ridgeway Subject: Re: PyMathProg From: Yin...@rh... To: dal...@ms... Date: Wed, 17 Jun 2009 13:40:43 -0400 Hi Alan, It is good to know that things works for you. PyMathProg 0.2.1 is also released, where there are relatively complete documentation. For example, how to get the dual/primal values of variables/constraints. You can use that to construct a range report. I hope this helps. All the documentation is also online at http://pymprog.sf.net/. In most cases, sensitivity analysis can be done via changing the values of parameters (you need to create them first, see the advanced exmples) and then call the solve() again. Could you also joint the email list https://lists.sourceforge.net/lists/listinfo/pymprog-help so that the questions answered can be archived for the benefit of all users. Thanks! Yingjie Yingjie Lan DIT(MSS) Ph.D. Program The Robert H. Smith School of Business University of Maryland 3300 Van Munching Hall College Park, Maryland 20742-1815 USA Email: yl...@rh... Web: http://wam.umd.edu/~ylan/ Phone: (301) 314-1968 Fax: (301) 314-9611 -----Alan Ridgeway <dal...@ms...> wrote: ----- To: <yl...@um...> From: Alan Ridgeway <dal...@ms...> Date: 06/16/2009 11:31PM Subject: PyMathProg Hello Yingjie I have PyMathProg 2.0 installed. I can run the examples in both Windows and Linux. I have a request for the documentation. Can you provide an example of how I could pull a sensitivity report for the results? This way when I get a Max or Min I can determine the range for how valid the result is. Thank you Alan Ridgeway |