Skip to content

Commit

Permalink
v__0.0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredgalichon committed Nov 24, 2023
1 parent d03dc15 commit 57cefc7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions mec/lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def plot2d (self, the_path=[], legend=True):
class Dictionary(LP):
def __init__(self, A_i_j, d_i, c_j = None , slack_var_names_i=None,decision_var_names_j=None):
# s_i = d_i - A_i_j @ x_j
if d_i.min()<0:
from warnings import warn
warn('The array d_i has negative entries; zero is not a feasible solution.')
LP.__init__(self,A_i_j, d_i, c_j,decision_var_names_j,slack_var_names_i)
self.nonbasic = [Symbol(x) for x in self.decision_var_names_j]
self.base = { Symbol('obj') : c_j @ self.nonbasic }
Expand Down Expand Up @@ -187,6 +190,9 @@ def simplex_loop(self,verbose = 0):
class Tableau(LP):
def __init__(self, A_i_j, d_i, c_j = None,slack_var_names_i=None, decision_var_names_j = None):
# s_i = d_i - (A_i_j @ x_j
if d_i.min()<0:
from warnings import warn
warn('The array d_i has negative entries; zero is not a feasible solution.')
LP.__init__(self, A_i_j, d_i, c_j, decision_var_names_j, slack_var_names_i)
self.names_all_variables = self.slack_var_names_i + self.decision_var_names_j
self.tableau = np.block([[np.zeros((1,self.nbi)), self.c_j.reshape((1,-1)), 0],
Expand Down Expand Up @@ -301,3 +307,18 @@ def IP_loop(self, tol=1e-6, verbose=0):
return True # finished


def two_phase(A_i_j,d_i, verbose = False):
nbi,nbj = A_i_j.shape
signs_i = np.minimum(2*np.sign(d_i)+1,1) # 1 if >=0, -1 else
d_i = signs_i*d_i
A_i_j = signs_i[:,None] * A_i_j
the_tableau = Tableau(A_i_j, d_i, c_j = A_i_j.sum(axis= 0) )
the_tableau.simplex_solve()
if min(the_tableau.k_b >= nbi ):
if verbose:
print('Feasible.')
return [k-nbi for k in the_tableau.k_b ]
else:
if verbose:
print('Infeasible.')
return None
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.8.1",
version="0.0.8.2",
url="",
authors=["Alfred Galichon"],
author_email="ag133@nyu.edu",
Expand Down

0 comments on commit 57cefc7

Please sign in to comment.