Skip to content

Commit

Permalink
v__0.0.9.11
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-jacquet committed Dec 16, 2023
1 parent ec0886c commit 1f02c36
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
60 changes: 30 additions & 30 deletions mec/gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,36 @@ def mangasarian_stone_solve(self):
'p_i': thesol[:self.nbi], 'q_j': thesol[self.nbi:(self.nbi+self.nbj)]}
return(sol_dict)

def lemke_howson_solve(self,verbose = 0):
A_i_j = self.A_i_j - np.min(self.A_i_j) + 1 # ensures that matrices are positive
B_i_j = self.B_i_j - np.min(self.B_i_j) + 1
zks = ['x_' + str(i+1) for i in range(self.nbi)] + ['y_' + str(j+1) for j in range(self.nbj)]
wks = ['r_' + str(i+1) for i in range(self.nbi)] + ['s_' + str(j+1) for j in range(self.nbj)]
complements = list(len(zks)+np.arange(len(zks))) + list(np.arange(len(zks)))
C_k_l = np.block([[np.zeros((self.nbi, self.nbi)), A_i_j],
[B_i_j.T, np.zeros((self.nbj, self.nbj))]])
tab = Tableau(C_k_l, np.ones(self.nbi + self.nbj), np.zeros(self.nbi + self.nbj), wks, zks)
kent = len(wks) # z_1 enters
while True:
kdep = tab.determine_departing(kent)
if verbose > 1:
print('Basis: ', [(wks+zks)[i] for i in tab.k_b])
print((wks+zks)[kent], 'enters,', (wks+zks)[kdep], 'departs')
tab.update(kent, kdep)
if (complements[kent] not in tab.k_b) and (complements[kdep] in tab.k_b):
break
else:
kent = complements[kdep]
z_k, _, _ = tab.solution() # solution returns: x_j, y_i, x_j@self.c_j
x_i, y_j = z_k[:self.nbi], z_k[self.nbi:]
α = 1 / y_j.sum()
β = 1 / x_i.sum()
p_i = x_i * α
q_j = y_j * β
sol_dict = {'val1': α + np.min(self.A_i_j) - 1,
'val2': β + np.min(self.B_i_j) - 1,
'p_i': p_i, 'q_j': q_j}
return(sol_dict)
def lemke_howson_solve(self,verbose = 0):
A_i_j = self.A_i_j - np.min(self.A_i_j) + 1 # ensures that matrices are positive
B_i_j = self.B_i_j - np.min(self.B_i_j) + 1
zks = ['x_' + str(i+1) for i in range(self.nbi)] + ['y_' + str(j+1) for j in range(self.nbj)]
wks = ['r_' + str(i+1) for i in range(self.nbi)] + ['s_' + str(j+1) for j in range(self.nbj)]
complements = list(len(zks)+np.arange(len(zks))) + list(np.arange(len(zks)))
C_k_l = np.block([[np.zeros((self.nbi, self.nbi)), A_i_j],
[B_i_j.T, np.zeros((self.nbj, self.nbj))]])
tab = Tableau(C_k_l, np.ones(self.nbi + self.nbj), np.zeros(self.nbi + self.nbj), wks, zks)
kent = len(wks) # z_1 enters
while True:
kdep = tab.determine_departing(kent)
if verbose > 1:
print('Basis: ', [(wks+zks)[i] for i in tab.k_b])
print((wks+zks)[kent], 'enters,', (wks+zks)[kdep], 'departs')
tab.update(kent, kdep)
if (complements[kent] not in tab.k_b) and (complements[kdep] in tab.k_b):
break
else:
kent = complements[kdep]
z_k, _, _ = tab.solution() # solution returns: x_j, y_i, x_j@self.c_j
x_i, y_j = z_k[:self.nbi], z_k[self.nbi:]
α = 1 / y_j.sum()
β = 1 / x_i.sum()
p_i = x_i * α
q_j = y_j * β
sol_dict = {'val1': α + np.min(self.A_i_j) - 1,
'val2': β + np.min(self.B_i_j) - 1,
'p_i': p_i, 'q_j': q_j}
return(sol_dict)


class TwoBases:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="mec",
version="0.0.9.10",
version="0.0.9.11",
authors=["Alfred Galichon"],
author_email="ag133@nyu.edu",
licence="",
Expand Down

0 comments on commit 1f02c36

Please sign in to comment.