Skip to content
25 changes: 14 additions & 11 deletions src/lemke/bimatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,14 @@ def createLCP(self):
def runLH(self, droppedlabel):
lcp = self.createLCP()
lcp.d[droppedlabel - 1] = 0 # subsidize this label
tabl = lemke.tableau(lcp)
# tabl.runlemke(verbose=True, lexstats=True, z0=gz0)
tabl.runlemke()
return tuple(getequil(tabl))

result = lemke.runlemke(lcp=lcp)
if result is None:
raise RuntimeError("runlemke() failed to find a solution unexpectedly.")

equilibrium = result[1: lcp.n - 1]
return tuple(equilibrium)
Comment on lines 157 to +167

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nataliemes This is not a problem because LH should never fail with ray termination, do you agree?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, runlemke() should never fail here, but I added an explicit check anyway, so that if it ever does (due to a bug in our implementation), the error is clearer.


def LH(self, LHstring):
m = self.A.numrows
Expand All @@ -184,9 +188,13 @@ def runtrace(self, xprior, yprior):
Ay = self.A.negmatrix @ yprior
xB = xprior @ self.B.negmatrix
lcp.d = np.hstack((Ay, xB, [1, 1]))
tabl = lemke.tableau(lcp)
tabl.runlemke()
return tuple(getequil(tabl))

result = lemke.runlemke(lcp=lcp)
if result is None:
raise RuntimeError("runlemke() failed to find a solution unexpectedly.")

equilibrium = result[1: lcp.n - 1]
return tuple(equilibrium)

def trace_uniform_prior(self):
m = self.A.numrows
Expand Down Expand Up @@ -255,11 +263,6 @@ def uniform(n):
return np.array([fractions.Fraction(1, n) for _ in range(n)])


def getequil(tabl):
tabl.createsol()
return tabl.solution[1: tabl.n - 1]


def str_eq(eq, m, n):
x = "(" + ",".join([str(x) for x in eq[0:m]]) + ")"
y = "(" + ",".join([str(x) for x in eq[m: m + n]]) + ")"
Expand Down
Loading
Loading