From f6bd5c5a6d6f7c2562261485cdf21621b014fa0d Mon Sep 17 00:00:00 2001 From: pabloguarda Date: Thu, 22 Feb 2024 12:45:50 -0500 Subject: [PATCH] fix edge weight calculation --- src/isuelogit/networks.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/isuelogit/networks.py b/src/isuelogit/networks.py index 82dff8b0..fc16244b 100644 --- a/src/isuelogit/networks.py +++ b/src/isuelogit/networks.py @@ -783,21 +783,22 @@ def generate_C(M): def generate_edges_weights(self, V: Matrix) -> Dict: ''' + + Edge weights are all non-negative and have the opposite sign that the utilities. + To avoid problems with link with positive utilities, namely, a negative weight, + the weights are shifted by a constant corresponding to the absolute value of the + most negative value. This will not affect the shortest path calculation. arguments: V (Matrix): Utility Matrix returns: - edge weights in utility units + edge weights that are all non-negative and have the opposite sign of the edge utilities ''' - # edges_weights_dict = dict(zip(dict(G.links).keys(), np.random.randint(0, 20, len(list(G.links))))) - - # To avoid problems with link with negative utilities, we deviates them by the link with the most negative values such that all have utilities greater or equal than 0. - + V = -V V = V+abs(np.min(V)) - edges_weights_dict = {} for index, vx in np.ndenumerate(V):