Skip to content

Commit 6b8a540

Browse files
committed
Merge branch 'new_spaces' of https://github.com/quaquel/mesa-examples into new_spaces
2 parents 86df2c4 + d4f2bb5 commit 6b8a540

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

examples/aco_tsp/aco_tsp/model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from mesa.spaces import CellAgent, Network
99

10+
1011
@dataclass
1112
class NodeCoordinates:
1213
city: int
@@ -108,10 +109,11 @@ def calculate_pheromone_delta(self, q: float = 100):
108109
def move_to(self, cell) -> None:
109110
self._cities_visited.append(cell)
110111
if self.cell:
111-
self._traveled_distance += self.graph[self.cell.coordinate][cell.coordinate]["distance"]
112+
self._traveled_distance += self.graph[self.cell.coordinate][
113+
cell.coordinate
114+
]["distance"]
112115
super().move_to(cell)
113116

114-
115117
def decide_next_city(self):
116118
# Random
117119
# new_city = self.random.choice(list(self.model.all_cities - set(self.cities_visited)))
@@ -125,8 +127,10 @@ def decide_next_city(self):
125127
results = []
126128
for city in candidates:
127129
val = (
128-
(self.graph[self.cell.coordinate][city.coordinate]["pheromone"]) ** self.alpha
129-
* (self.graph[self.cell.coordinate][city.coordinate]["visibility"]) ** self.beta
130+
(self.graph[self.cell.coordinate][city.coordinate]["pheromone"])
131+
** self.alpha
132+
* (self.graph[self.cell.coordinate][city.coordinate]["visibility"])
133+
** self.beta
130134
)
131135
results.append(val)
132136

0 commit comments

Comments
 (0)