Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions sa_tool/sa_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SATool:

def __init__(self, graph):
if (False == nx.is_bipartite(graph)):
print "[ERROR]Not a bipartite graph provided."
print ("[ERROR]Not a bipartite graph provided.")
sys.exit()

#Copying the graph provided by the user
Expand All @@ -29,7 +29,7 @@ def __init__(self, graph):

#Ensuring that the bipartite == 1 is assigned to varaibles
Y = list(self.variables)
if (self.G.node[Y[0]]['bipartite'] == 1):
if (self.G.nodes[Y[0]]['bipartite'] == 1):
X = self.constraints
self.constraints = self.variables
self.variables = X
Expand All @@ -39,18 +39,18 @@ def __init__(self, graph):
known = []
unknown = []
for n in self.variables:
if (self.G.node[n]['type'] == 'known'):
if (self.G.nodes[n]['type'] == 'known'):
known.append(n)
elif (self.G.node[n]['type'] == 'unknown'):
elif (self.G.nodes[n]['type'] == 'unknown'):
unknown.append(n)
else:
print "[ERROR] Please specify for each node type as 'known' or 'unknown'"
print ("[ERROR] Please specify for each node type as 'known' or 'unknown'")
sys.exit()

self.known = set(known)
self.unknown = set(unknown)
except KeyError:
print "[ERROR] Please specify for each node type as 'known' or 'unknown'"
print ("[ERROR] Please specify for each node type as 'known' or 'unknown'")
sys.exit()

#Creating reduced graph by removing known variables
Expand Down Expand Up @@ -120,16 +120,16 @@ def calculate_matching_ranking_constraints(self):

self.max_match_dict = dict(max_matching)
self.max_match_list = max_matching
print "Max Matching : ",max_matching
print ("Max Matching : ",max_matching)

def calculate_maximum_matching(self):
try:
self.max_match_dict = nx.algorithms.bipartite.maximum_matching(self.R)
self.max_match_list = list(self.max_match_dict.items())
print self.max_match_list
print (self.max_match_list)
except:
print "Networkx Development version required for calculationg maximum matching"
print "Please read Installation instructions "
print ("Networkx Development version required for calculationg maximum matching")
print ("Please read Installation instructions ")
exit()


Expand Down Expand Up @@ -214,7 +214,7 @@ def visualize_bipartite(self, with_matching=False,with_orientation=False):
ax1.set_title("With Orientation")
#self.calculate_maximum_matching()
self.calculate_matching_ranking_constraints()
print pos
print (pos)
nx.draw_networkx_edges(self.G,pos,ax=ax1,
edgelist=self.max_match_list,
width=5,alpha=0.3,edge_color='b')
Expand Down