Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to best practice for pandas>=0.20.0 #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions pandas_min_cost_flow/min_cost_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ def createModel(self):

# Create objective
def obj_rule(m):
return sum(m.Y[e] * self.arc_data.ix[e,'Cost'] for e in self.arc_set)
return sum(m.Y[e] * self.arc_data.loc[e,'Cost'] for e in self.arc_set)
self.m.OBJ = pe.Objective(rule=obj_rule, sense=pe.minimize)

# Flow Ballance rule
# Flow Balance rule
def flow_bal_rule(m, n):
arcs = self.arc_data.reset_index()
preds = arcs[ arcs.End == n ]['Start']
succs = arcs[ arcs.Start == n ]['End']
return sum(m.Y[(p,n)] for p in preds) - sum(m.Y[(n,s)] for s in succs) == self.node_data.ix[n,'Imbalance']
return sum(m.Y[(p,n)] for p in preds) - sum(m.Y[(n,s)] for s in succs) == self.node_data.loc[n,'Imbalance']
self.m.FlowBal = pe.Constraint(self.m.node_set, rule=flow_bal_rule)

# Upper bounds rule
def upper_bounds_rule(m, n1, n2):
e = (n1,n2)
if self.arc_data.ix[e, 'UpperBound'] < 0:
if self.arc_data.loc[e, 'UpperBound'] < 0:
return pe.Constraint.Skip
return m.Y[e] <= self.arc_data.ix[e, 'UpperBound']
return m.Y[e] <= self.arc_data.loc[e, 'UpperBound']
self.m.UpperBound = pe.Constraint(self.m.arc_set, rule=upper_bounds_rule)

# Lower bounds rule
def lower_bounds_rule(m, n1, n2):
e = (n1,n2)
if self.arc_data.ix[e, 'LowerBound'] < 0:
if self.arc_data.loc[e, 'LowerBound'] < 0:
return pe.Constraint.Skip
return m.Y[e] >= self.arc_data.ix[e, 'LowerBound']
return m.Y[e] >= self.arc_data.loc[e, 'LowerBound']
self.m.LowerBound = pe.Constraint(self.m.arc_set, rule=lower_bounds_rule)

def solve(self):
Expand Down