Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ArjanCodes/examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Egges committed May 21, 2024
2 parents 3e5601a + 98daabd commit a01cd75
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 20 deletions.
8 changes: 6 additions & 2 deletions 2024/streamlit/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ def configure_page() -> None:

def configure_overview() -> None:
st.markdown("## Overview")
st.markdown("This app generates a maze and visualizes the pathfinding algorithms solving it.")
st.markdown("The aim is to compare the performance of different algorithms and heuristics.")
st.markdown(
"This app generates a maze and visualizes the pathfinding algorithms solving it."
)
st.markdown(
"The aim is to compare the performance of different algorithms and heuristics."
)


def configure_available_algo_heuristics() -> None:
Expand Down
20 changes: 16 additions & 4 deletions 2024/streamlit/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def configure_page() -> None:

def configure_overview() -> None:
st.markdown("## Overview")
st.markdown("This app generates a maze and visualizes the pathfinding algorithms solving it.")
st.markdown("The aim is to compare the performance of different algorithms and heuristics.")
st.markdown(
"This app generates a maze and visualizes the pathfinding algorithms solving it."
)
st.markdown(
"The aim is to compare the performance of different algorithms and heuristics."
)


def configure_available_algo_heuristics() -> None:
Expand All @@ -36,12 +40,20 @@ def configure_sidebar() -> MazeConfig:
width = st.sidebar.slider("Width", 5, 25, 11)
height = st.sidebar.slider("Height", 5, 25, 11)
num_rooms = st.sidebar.slider("Number of rooms", 0, 5, 0)
room_size_range = st.sidebar.slider("Room size range", 1, min(width, height) // 4, (3, 6))
room_size_range = st.sidebar.slider(
"Room size range", 1, min(width, height) // 4, (3, 6)
)
return MazeConfig(seed, width, height, num_rooms, room_size_range)


def create_plot(maze_config: MazeConfig) -> Figure:
maze = generate_maze(maze_config.seed, maze_config.width, maze_config.height, maze_config.num_rooms, maze_config.room_size_range)
maze = generate_maze(
maze_config.seed,
maze_config.width,
maze_config.height,
maze_config.num_rooms,
maze_config.room_size_range,
)
paths = solve_maze(maze, ((ALGORITHMS[0], HEURISTICS[0]),))
fig = plot_maze_with_paths(maze, paths)
return fig
Expand Down
49 changes: 39 additions & 10 deletions 2024/streamlit/sidebar_expanded.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from py_wanderer import ALGORITHMS, HEURISTICS
from py_wanderer.plotter import plot_maze_with_paths

from utils import generate_maze, solve_maze, MazeConfig, SolvingStrategy, SolvingStrategies
from utils import (
generate_maze,
solve_maze,
MazeConfig,
SolvingStrategy,
SolvingStrategies,
)


def configure_page() -> None:
Expand All @@ -12,8 +18,12 @@ def configure_page() -> None:

def configure_overview() -> None:
st.markdown("## Overview")
st.markdown("This app generates a maze and visualizes the pathfinding algorithms solving it.")
st.markdown("The aim is to compare the performance of different algorithms and heuristics.")
st.markdown(
"This app generates a maze and visualizes the pathfinding algorithms solving it."
)
st.markdown(
"The aim is to compare the performance of different algorithms and heuristics."
)


def configure_available_algo_heuristics() -> None:
Expand All @@ -36,22 +46,41 @@ def configure_sidebar() -> MazeConfig:
width = st.sidebar.slider("Width", 5, 101, 11)
height = st.sidebar.slider("Height", 5, 101, 11)
num_rooms = st.sidebar.slider("Number of rooms", 0, 5, 0)
room_size_range = st.sidebar.slider("Room size range", 1, min(width, height) // 4, (3, 6))
room_size_range = st.sidebar.slider(
"Room size range", 1, min(width, height) // 4, (3, 6)
)

algorithms_multiselect = st.sidebar.multiselect(
"Select algorithms", ALGORITHMS, [ALGORITHMS[0]], format_func=lambda x: x.__name__)
"Select algorithms",
ALGORITHMS,
[ALGORITHMS[0]],
format_func=lambda x: x.__name__,
)
heuristics_multiselect = st.sidebar.multiselect(
"Select heuristics", HEURISTICS, [HEURISTICS[0]], format_func=lambda x: x.__name__.title())
"Select heuristics",
HEURISTICS,
[HEURISTICS[0]],
format_func=lambda x: x.__name__.title(),
)
solving_strategies: SolvingStrategies = tuple(
(algorithm, heuristic) for algorithm in algorithms_multiselect for heuristic in heuristics_multiselect
(algorithm, heuristic)
for algorithm in algorithms_multiselect
for heuristic in heuristics_multiselect
)

return MazeConfig(seed, width, height, num_rooms, room_size_range, solving_strategies)
return MazeConfig(
seed, width, height, num_rooms, room_size_range, solving_strategies
)


def create_plot(maze_config: MazeConfig) -> Figure:
maze = generate_maze(maze_config.seed, maze_config.width, maze_config.height, maze_config.num_rooms,
maze_config.room_size_range)
maze = generate_maze(
maze_config.seed,
maze_config.width,
maze_config.height,
maze_config.num_rooms,
maze_config.room_size_range,
)
paths = solve_maze(maze, maze_config.solving_strategies)
fig = plot_maze_with_paths(maze, paths)
return fig
Expand Down
20 changes: 16 additions & 4 deletions 2024/streamlit/simple_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def configure_page() -> None:

def configure_overview() -> None:
st.markdown("## Overview")
st.markdown("This app generates a maze and visualizes the pathfinding algorithms solving it.")
st.markdown("The aim is to compare the performance of different algorithms and heuristics.")
st.markdown(
"This app generates a maze and visualizes the pathfinding algorithms solving it."
)
st.markdown(
"The aim is to compare the performance of different algorithms and heuristics."
)


def configure_available_algo_heuristics() -> None:
Expand All @@ -32,14 +36,22 @@ def configure_available_algo_heuristics() -> None:


def create_plot(maze_config: MazeConfig) -> Figure:
maze = generate_maze(maze_config.seed, maze_config.width, maze_config.height, maze_config.num_rooms, maze_config.room_size_range)
maze = generate_maze(
maze_config.seed,
maze_config.width,
maze_config.height,
maze_config.num_rooms,
maze_config.room_size_range,
)
paths = solve_maze(maze, ((ALGORITHMS[0], HEURISTICS[0]),))
fig = plot_maze_with_paths(maze, paths)
return fig


def main() -> None:
maze_config = MazeConfig(seed=0, width=11, height=11, num_rooms=0, room_size_range=(3, 6))
maze_config = MazeConfig(
seed=0, width=11, height=11, num_rooms=0, room_size_range=(3, 6)
)
configure_page()
configure_overview()
configure_available_algo_heuristics()
Expand Down

0 comments on commit a01cd75

Please sign in to comment.