Skip to content

Commit

Permalink
further simplify weightsToEdges algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Yrjö Kari-Koskinen committed Apr 2, 2018
1 parent edf12e3 commit d6ddf98
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,24 @@ def __str__(self):
def weightsToEdges(sortedWeights, weights):
i = 0
edges = []
target = ""
while i+1 < len(sortedWeights):
currentNode = sortedWeights[i][1]
currentWeight = weights[currentNode]
if currentWeight == 0:
i += 1
continue;

transact = abs(currentWeight)
if currentWeight < 0:
try:
node = findGreaterWeight(transact, weights)
edges.append(Edge(currentNode, node, transact))
weights[node] += currentWeight
i += 1
continue
target = findGreaterWeight(transact, weights)
except NodeError:
pass
if currentWeight != 0:
target = sortedWeights[i+1][1]
else:
target = sortedWeights[i+1][1]
edges.append(Edge(currentNode, target, transact))
weights[target] += currentWeight
edges.append(Edge(currentNode, target, transact))
weights[target] += currentWeight
i += 1
return edges

Expand Down

0 comments on commit d6ddf98

Please sign in to comment.