-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (20 loc) · 925 Bytes
/
main.py
File metadata and controls
29 lines (20 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from gridworld import Gridworld
from value_iteration import value_iteration, extract_policy
from visualizations import visualize_policy_grid, plot_value_function_evolution
def main():
"""
Main function to initialize the gridworld, run value iteration, extract the optimal policy,
and generate visualizations.
"""
# Initialize the Gridworld environment
env = Gridworld(5, 5)
# Perform value iteration to find optimal values
V = value_iteration(env)
# Extract the optimal policy based on the optimal value function
policy = extract_policy(V, env)
# Visualize the optimal policy grid
visualize_policy_grid(policy, env.width, env.height, "optimal_policy_grid.png")
# Visualize the evolution of the value function during the value iteration process
plot_value_function_evolution(env, "value_function_evolution.png")
if __name__ == "__main__":
main()