Skip to content

Commit

Permalink
fixes aon assignment (#222)
Browse files Browse the repository at this point in the history
* fixes aon assignment
* removes unused import
  • Loading branch information
janzill authored Feb 11, 2021
1 parent e978e36 commit 5005222
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 5 additions & 1 deletion aequilibrae/paths/linear_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ def execute(self):
if c.results.num_skims > 0:
copy_three_dimensions(c.results.skims.matrix_view, c._aon_results.skims.matrix_view, self.cores)
flows.append(c.results.total_link_loads * c.pce)

if self.algorithm == "all-or-nothing":
break

else:
self.__calculate_step_direction()
self.calculate_stepsize()
Expand Down Expand Up @@ -395,7 +399,7 @@ def execute(self):
idx = c.graph.skim_fields.index(self.time_field)
c.graph.skims[:, idx] = self.congested_time[:]
c._aon_results.reset()
if self.rgap > self.rgap_target:
if (self.rgap > self.rgap_target) and (self.algorithm != "all-or-nothing"):
logger.error(f"Desired RGap of {self.rgap_target} was NOT reached")
logger.info(f"{self.algorithm} Assignment finished. {self.iter} iterations and {self.rgap} final gap")
if pyqt:
Expand Down
17 changes: 8 additions & 9 deletions aequilibrae/paths/traffic_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from aequilibrae.matrix import AequilibraeMatrix
from aequilibrae.project.data import Matrices


spec = iutil.find_spec("openmatrix")
has_omx = spec is not None

Expand Down Expand Up @@ -230,9 +231,7 @@ def set_algorithm(self, algorithm: str):
if algo is None:
raise AttributeError(f"Assignment algorithm not available. Choose from: {','.join(self.all_algorithms)}")

if algo == "all-or-nothing":
self.assignment = allOrNothing(self)
elif algo in ["msa", "frank-wolfe", "cfw", "bfw"]:
if algo in ["all-or-nothing", "msa", "frank-wolfe", "cfw", "bfw"]:
self.assignment = LinearApproximation(self, algo)
else:
raise Exception("Algorithm not listed in the case selection")
Expand Down Expand Up @@ -303,17 +302,17 @@ def set_time_field(self, time_field: str) -> None:
"""

if not self.classes:
raise ValueError('Your need add at least one traffic classes first')
raise ValueError("Your need add at least one traffic classes first")

c = self.classes[0]
if time_field not in c.graph.graph.columns:
raise ValueError('Field not in graph')
raise ValueError("Field not in graph")

if np.any(np.isnan(c.graph.graph[time_field].values)):
raise ValueError("At least one link free-flow time is NaN")

if c.graph.graph[time_field].values.min() <= 0:
raise ValueError('There is at least one link with zero or negative free-flow time')
raise ValueError("There is at least one link with zero or negative free-flow time")

self.__dict__["free_flow_tt"] = np.array(c.graph.graph[time_field].values, copy=True).astype(np.float64)
self.__dict__["congested_time"] = np.array(self.free_flow_tt, copy=True)
Expand All @@ -329,17 +328,17 @@ def set_capacity_field(self, capacity_field: str) -> None:
"""

if not self.classes:
raise ValueError('Your need add at least one traffic classes first')
raise ValueError("Your need add at least one traffic classes first")

c = self.classes[0]
if capacity_field not in c.graph.graph.columns:
raise ValueError('Field not in graph')
raise ValueError("Field not in graph")

if np.any(np.isnan(c.graph.graph[capacity_field].values)):
raise ValueError("At least one link capacity is NaN")

if c.graph.graph[capacity_field].values.min() <= 0:
raise ValueError('There is at least one link with zero or negative capacity')
raise ValueError("There is at least one link with zero or negative capacity")

self.__dict__["cores"] = c.results.cores
self.__dict__["capacity"] = np.array(c.graph.graph[capacity_field], copy=True).astype(np.float64)
Expand Down

0 comments on commit 5005222

Please sign in to comment.