[pymprog] Constraints and Iteration
An easy and flexible mathematical programming environment for Python.
Brought to you by:
lanyjie
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 |