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