Skip to content

Commit

Permalink
Fixed broken incidence matrix function
Browse files Browse the repository at this point in the history
  • Loading branch information
squoilin committed Feb 3, 2020
1 parent 2115236 commit 935c9b7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dispaset/preprocessing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ def incidence_matrix(sets, set_used, parameters, param_used):
This function generates the incidence matrix of the lines within the nodes
A particular case is considered for the node "Rest Of the World", which is no explicitely defined in DispaSET
"""

for i in range(len(sets[set_used])):
[from_node, to_node] = sets[set_used][i].split('->')
for i,l in enumerate(sets[set_used]):
[from_node, to_node] = l.split('->')
if (from_node.strip() in sets['n']) and (to_node.strip() in sets['n']):
parameters[param_used]['val'][i, sets['n'].index(to_node.strip())] = 1
parameters[param_used]['val'][i, sets['n'].index(from_node.strip())] = -1
elif (from_node.strip() in sets['n']) and (to_node.strip() == 'RoW'):
parameters[param_used]['val'][i, sets['n'].index(from_node.strip())] = -1
elif (from_node.strip() == 'RoW') and (to_node.strip() in sets['n']):
parameters[param_used]['val'][i, sets['n'].index(to_node.strip())] = 1
else:
logging.warning("The line " + str(sets[set_used][i]) + " contains unrecognized nodes")
logging.error("The line " + str(l) + " contains unrecognized nodes (" + from_node.strip() + ' or ' + to_node.strip() + ")")

return parameters[param_used]


Expand Down

0 comments on commit 935c9b7

Please sign in to comment.