Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions examples/aco_tsp/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Configure visualization elements and instantiate a server"""

import os

import networkx as nx
import solara
from aco_tsp.model import AcoTspModel, TSPGraph
Expand All @@ -11,7 +13,10 @@ def circle_portrayal_example(agent):
return {"node_size": 20, "width": 0.1}


tsp_graph = TSPGraph.from_tsp_file("aco_tsp/data/kroA100.tsp")
tsp_graph = TSPGraph.from_tsp_file(
os.path.join(os.path.dirname(__file__), "aco_tsp/data/kroA100.tsp")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since app.py is already inside the aco_tsp directory, the joined path may not need the extra aco_tsp/ prefix. Using:

os.path.join(os.path.dirname(__file__), "data/kroA100.tsp")

would resolve directly to the data folder next to the script.

)

model_params = {
"num_agents": tsp_graph.num_cities,
"tsp_graph": tsp_graph,
Expand Down Expand Up @@ -43,9 +48,7 @@ def make_graph(model):
graph = model.grid.G
pos = model.tsp_graph.pos
weights = [graph[u][v]["pheromone"] for u, v in graph.edges()]
# normalize the weights
weights = [w / max(weights) for w in weights]

nx.draw(
graph,
ax=ax,
Expand All @@ -54,15 +57,10 @@ def make_graph(model):
width=weights,
edge_color="gray",
)

return solara.FigureMatplotlib(fig)


def ant_level_distances(model):
# ant_distances = model.datacollector.get_agent_vars_dataframe()
# Plot so that the step index is the x-axis, there's a line for each agent,
# and the y-axis is the distance traveled
# ant_distances['tsp_distance'].unstack(level=1).plot(ax=ax)
pass


Expand Down
Loading