diff --git a/.gitignore b/.gitignore index f8ab10216febb7f4f8b0408aa260e1f423c3c9e8..1e25f17126a5900b78b27d3822d62ca6a634a872 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ exam_tabular_examples #solutions/ex01 #solutions/ex02 -solutions/ex03 +#solutions/ex03 solutions/ex04 solutions/ex05 solutions/ex06 @@ -29,8 +29,8 @@ solutions/ex13 # irlc/tests/tests_week01.py #irlc/tests/tests_week02.py -irlc/tests/tests_week03.py -irlc/tests/tests_week04.py +#irlc/tests/tests_week03.py +#irlc/tests/tests_week04.py irlc/tests/tests_week05.py irlc/tests/tests_week06.py irlc/tests/tests_week07.py @@ -66,8 +66,8 @@ irlc/exam/exam20*/solution # irlc/lectures/lec01 # irlc/lectures/lec02 -irlc/lectures/lec03 -irlc/lectures/lec04 +#irlc/lectures/lec03 +#irlc/lectures/lec04 irlc/lectures/lec05 irlc/lectures/lec06 irlc/lectures/lec07 diff --git a/irlc/ex02/dp.py b/irlc/ex02/dp.py index 24e061436debc4f0b07fe0cfea29fd88a49dfef0..66bb1e3342c05322693e16ee1da021387ee5a896 100644 --- a/irlc/ex02/dp.py +++ b/irlc/ex02/dp.py @@ -26,7 +26,7 @@ def DP_stochastic(model: DPModel) -> tuple[list[dict], list[dict]]: - ``pi`` - A list of dictionaries so that ``pi[k][x]`` represents :math:`\mu_k(x)` """ - """ + r""" In case you run into problems, I recommend following the hints in (Her25, Subsection 6.2.1) and focus on the case without a noise term; once it works, you can add the w-terms. When you don't loop over noise terms, just specify them as w = None in env.f and env.g. @@ -37,7 +37,7 @@ def DP_stochastic(model: DPModel) -> tuple[list[dict], list[dict]]: J[N] = {x: model.gN(x) for x in model.S(model.N)} for k in range(N-1, -1, -1): for x in model.S(k): - """ + r""" Update pi[k][x] and Jstar[k][x] using the general DP algorithm given in (Her25, Algorithm 1). If you implement it using the pseudo-code, I recommend you define Q (from the algorithm) as a dictionary like the J-function such that @@ -61,9 +61,9 @@ def DP_stochastic(model: DPModel) -> tuple[list[dict], list[dict]]: return J, pi -if __name__ == "__main__": # Test dp on small graph given in (Her25, Subsection 6.2.1) +if __name__ == "__main__": # Test dp on the deterministic version of the inventory control environment. print("Testing the deterministic DP algorithm on the small graph environment") - model = DeterministicInventoryDPModel() # Instantiate the small graph with target node 5 + model = DeterministicInventoryDPModel() # Instantiate the inventory control environment J, pi = DP_stochastic(model) # Print all optimal cost functions J_k(x_k) for k in range(len(J)): diff --git a/irlc/exam/readme.md b/irlc/exam/readme.md index c189b31a4b85f0ec947ad1761de0e72448513e77..f7b5903c05ced7fe878c56f3bf0e91dfcdf835ca 100644 --- a/irlc/exam/readme.md +++ b/irlc/exam/readme.md @@ -9,7 +9,10 @@ During the exam: - For the midterm, you can find the file on DTU Learn - The `zip` file will contain the toolbox code including solutions. It will also contain a directory: ```bash - irlc/exam/exam2024spring + irlc/exam/exam2025spring ``` - This directory contains the code you need to work on for the exam. Replace the directory on your local computer with this directory and you should be all set up - The `.zip` file will also contain solutions to nearly all exercises. Use these if benefits you. + +## Midterms +The two 'midterms' were used for practice during the first year with written exams. There are no midterms in the current version of the course. diff --git a/irlc/lectures/lec02/lecture_02_keyboard_pacman_g1.py b/irlc/lectures/lec02/lecture_02_keyboard_pacman_g1.py index 717f4300157d125eb3059d488f1519d61badef09..da4b7acba9f8c2d59f5d3423db61fbaf9c7f107d 100644 --- a/irlc/lectures/lec02/lecture_02_keyboard_pacman_g1.py +++ b/irlc/lectures/lec02/lecture_02_keyboard_pacman_g1.py @@ -10,8 +10,7 @@ def ppac(layout_str, name="pac"): env = PacmanEnvironment(layout=None, layout_str=layout_str, animate_movement=True) agent = Agent(env) env, agent = interactive(env, agent) - # agent = PlayWrapper(agent, env) - # env = VideoMonitor(env) + stats, _ = train(env, agent, num_episodes=5, max_steps=8) print("Accumulated reward for all episodes:", [s['Accumulated Reward'] for s in stats]) env.close() diff --git a/irlc/lectures/lec02/lecture_02_optimal_dp_g0.py b/irlc/lectures/lec02/lecture_02_optimal_dp_g0.py index 8c914974699e423122d2d1bf7429fd91048afe20..67532530f82b3e76cc09a87d81a1712a70c6f1b2 100644 --- a/irlc/lectures/lec02/lecture_02_optimal_dp_g0.py +++ b/irlc/lectures/lec02/lecture_02_optimal_dp_g0.py @@ -4,20 +4,14 @@ from irlc.ex02.dp_agent import DynamicalProgrammingAgent from gymnasium.wrappers import TimeLimit from irlc.pacman.pacman_environment import PacmanWinWrapper from irlc.ex01.agent import train -# from irlc import VideoMonitor -# from irlc.ex02.old.dp_pacman import DPPacmanModel from irlc.lectures.chapter3dp.dp_pacman import DPPacmanModel -# from irlc import PlayWrapper from irlc import interactive def simulate_1_game(layout_str): N = 30 env = PacmanEnvironment(layout=None, layout_str=layout_str, render_mode='human') - - # env = VideoMonitor(env, fps=3) model = DPPacmanModel(env, N=N, verbose=True) agent = DynamicalProgrammingAgent(env, model=model) - # agent = PlayWrapper(agent, env) env, agent = interactive(env, agent) env = TimeLimit(env, max_episode_steps=N) env = PacmanWinWrapper(env) diff --git a/irlc/lectures/lec02/lecture_02_optimal_inventory.py b/irlc/lectures/lec02/lecture_02_optimal_inventory.py index 48eb5e1320a987ac14f60aab9cf427c080709cbd..71b7bc69e21cef117af37f50294f88c15a47fe74 100644 --- a/irlc/lectures/lec02/lecture_02_optimal_inventory.py +++ b/irlc/lectures/lec02/lecture_02_optimal_inventory.py @@ -1,13 +1,11 @@ # This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc import Agent, interactive +from irlc import train, interactive from irlc.lectures.lec01.viz_inventory_environment import VizInventoryEnvironment if __name__ == "__main__": env = VizInventoryEnvironment(render_mode='human') from irlc.ex02.inventory import InventoryDPModel from irlc.ex02.dp_agent import DynamicalProgrammingAgent - - from irlc import train, interactive agent = DynamicalProgrammingAgent(env, model=InventoryDPModel()) env, agent = interactive(env, agent) diff --git a/irlc/lectures/lec03/ex_03_search.py b/irlc/lectures/lec03/ex_03_search.py deleted file mode 100644 index 7d5ce2ca57e2fb179f264be0f519d6d334287b12..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/ex_03_search.py +++ /dev/null @@ -1,18 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc import Agent, train, savepdf -from irlc.pacman.pacman_environment import PacmanEnvironment -from irlc.ex03.dp_forward import dp_forward -from irlc.ex03.search_problem import SearchProblem -from irlc.ex03.search_problem import EnsureTerminalSelfTransitionsWrapper -from irlc.ex03.pacman_search import layout2, layout1 - -if __name__ == "__main__": - env = PacmanEnvironment(layout_str=layout1, render_mode='human') - env.reset() - savepdf("ex03_layout1", env=env) - env.close() - - env = PacmanEnvironment(layout_str=layout1, render_mode='human') - env.reset() - savepdf("ex03_layout2", env=env) - env.close() diff --git a/irlc/lectures/lec03/lecture_03_alphab.py b/irlc/lectures/lec03/lecture_03_alphab.py deleted file mode 100644 index fa81c07f7264c87577af4431c2be9339a152c139..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_alphab.py +++ /dev/null @@ -1,7 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.ex03multisearch.multisearch_alphabeta import GymAlphaBetaAgent -from irlc.lectures.lec03.lecture_03_minimax import gminmax - -if __name__ == "__main__": - d = 3 - gminmax(Agent=GymAlphaBetaAgent,depth=d) diff --git a/irlc/lectures/lec03/lecture_03_dotsearch_astar_manhattan.py b/irlc/lectures/lec03/lecture_03_dotsearch_astar_manhattan.py deleted file mode 100644 index ebea74a0e4980b47a004271f184f81f38154fa9e..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_dotsearch_astar_manhattan.py +++ /dev/null @@ -1,8 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.lectures.lec03.lecture_03_dotsearch_dp import singledot -from irlc.lectures.chapter4search.yield_version.pacman_yield import AStarAgentYield -from irlc.ex03multisearch.pacman_problem_positionsearch_astar import manhattanHeuristic - -if __name__ == "__main__": - agent_args = dict(heuristic=manhattanHeuristic) - singledot(SAgent=AStarAgentYield, agent_args=agent_args) diff --git a/irlc/lectures/lec03/lecture_03_dotsearch_bfs.py b/irlc/lectures/lec03/lecture_03_dotsearch_bfs.py deleted file mode 100644 index 2fafd77ced41a6c50ad917927cc70801ea29061a..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_dotsearch_bfs.py +++ /dev/null @@ -1,9 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.lectures.lec03.lecture_03_dotsearch_dp import singledot -from irlc.lectures.chapter4search.yield_version.pacman_yield import BFSAgentYield - -if __name__ == "__main__": - # agent_args = dict(heuristic=manhattanHeuristic,N=30) - singledot(SAgent=BFSAgentYield) - - # singledot(SAgent=BFSAgentYield) diff --git a/irlc/lectures/lec03/lecture_03_dotsearch_dfs.py b/irlc/lectures/lec03/lecture_03_dotsearch_dfs.py deleted file mode 100644 index 276aa6bee3f60db8a9172d3dab1ba3ee463918f4..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_dotsearch_dfs.py +++ /dev/null @@ -1,9 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.lectures.lec03.lecture_03_dotsearch_dp import singledot -from irlc.lectures.chapter4search.yield_version.pacman_yield import DFSAgentYield - -if __name__ == "__main__": - # agent_args = dict(heuristic=manhattanHeuristic,N=30) - singledot(SAgent=DFSAgentYield) - - # singledot(SAgent=BFSAgentYield) diff --git a/irlc/lectures/lec03/lecture_03_dotsearch_dp.py b/irlc/lectures/lec03/lecture_03_dotsearch_dp.py deleted file mode 100644 index baff1ee775c117f2d1cfb55948667899eba0db5e..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_dotsearch_dp.py +++ /dev/null @@ -1,12 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.lectures.chapter4search.yield_version.pacman_yield import stest, ForwardDPSearchAgent, dargs -# from irlc.ex03.pacsearch_agents import GymPositionSearchProblem, manhattanHeuristic, GymCornersProblem, cornersHeuristic, foodHeuristic, GymFoodSearchProblem, GymAnyFoodSearchProblem -from irlc.ex03multisearch.pacman_problem_positionsearch import GymPositionSearchProblem#, manhattanHeuristic - - -def singledot(layout='smallMaze', SAgent=None, agent_args=None, layout_str=None): - stest(layout=layout, layout_str=layout_str, SAgent=SAgent, prob=GymPositionSearchProblem(), agent_args=agent_args, zoom=2, **dargs, fps=30) # part 3 - -if __name__ == "__main__": - agent_args = dict(N=30) - singledot(SAgent=ForwardDPSearchAgent, agent_args=agent_args) diff --git a/irlc/lectures/lec02/lecture_02_dp_gridworld_short.py b/irlc/lectures/lec03/lecture_03_dp_gridworld_short.py similarity index 100% rename from irlc/lectures/lec02/lecture_02_dp_gridworld_short.py rename to irlc/lectures/lec03/lecture_03_dp_gridworld_short.py diff --git a/irlc/lectures/lec03/lecture_03_expectimax.py b/irlc/lectures/lec03/lecture_03_expectimax.py deleted file mode 100644 index 826975f29ec88a7aeaedf08eff8bf356980791f7..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_expectimax.py +++ /dev/null @@ -1,7 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.ex03multisearch.multisearch_agents import GymExpectimaxAgent -from irlc.lectures.lec03.lecture_03_minimax import gminmax - -if __name__ == "__main__": - d = 3 - gminmax(Agent=GymExpectimaxAgent,depth=d) diff --git a/irlc/lectures/lec02/lecture_02_frozen_lake.py b/irlc/lectures/lec03/lecture_03_frozen_lake.py similarity index 100% rename from irlc/lectures/lec02/lecture_02_frozen_lake.py rename to irlc/lectures/lec03/lecture_03_frozen_lake.py diff --git a/irlc/lectures/lec02/lecture_02_frozen_long_slippery.py b/irlc/lectures/lec03/lecture_03_frozen_long_slippery.py similarity index 100% rename from irlc/lectures/lec02/lecture_02_frozen_long_slippery.py rename to irlc/lectures/lec03/lecture_03_frozen_long_slippery.py diff --git a/irlc/lectures/lec04/lecture_04_harmonic.py b/irlc/lectures/lec03/lecture_03_harmonic.py similarity index 100% rename from irlc/lectures/lec04/lecture_04_harmonic.py rename to irlc/lectures/lec03/lecture_03_harmonic.py diff --git a/irlc/lectures/lec03/lecture_03_minimax.py b/irlc/lectures/lec03/lecture_03_minimax.py deleted file mode 100644 index eb8ee7362072498ac35df5df4367f822898fd4bb..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_minimax.py +++ /dev/null @@ -1,35 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.ex01.agent import train -from irlc.pacman.pacman_environment import GymPacmanEnvironment -from irlc.utils.video_monitor import VideoMonitor -from irlc.ex03multisearch.multisearch_agents import GymMinimaxAgent - - -layout_str = """ -%%%%%%%%% -% % -% %%%% % -% % -% P % -%%%% % -%%%% .G % -%%%% % -%%%%%%%%% -""".strip() - -def gminmax(layout='smallClassic', layout_str=layout_str, Agent=None, depth=3, **kwargs): - zoom = 2 - env = GymPacmanEnvironment(layout=layout, layout_str=layout_str, zoom=zoom, **kwargs) - agent = Agent(env, depth=depth) - from irlc import PlayWrapper - agent = PlayWrapper(agent, env) - - env = VideoMonitor(env, agent=agent, agent_monitor_keys=tuple(), fps=10) - train(env, agent, num_episodes=30) - env.close() - -if __name__ == "__main__": - d = 3 - gminmax(layout='minimaxClassic', layout_str=layout_str, Agent=GymMinimaxAgent,depth=d) - # gminmax(layout='minimaxClassic', layout_str=layout_str, Agent=GymAlphaBetaAgent, depth=d) - # gminmax(layout='minimaxClassic', layout_str=layout_str, Agent=GymExpectimaxAgent,depth=d) diff --git a/irlc/lectures/lec03/lecture_03_squaresearch_bfs.py b/irlc/lectures/lec03/lecture_03_squaresearch_bfs.py deleted file mode 100644 index ac1e0953cd661d8ae9d0c859b6470ff7b28af798..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_squaresearch_bfs.py +++ /dev/null @@ -1,12 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.lectures.chapter4search.yield_version.pacman_yield import BFSAgentYield -from irlc.lectures.chapter4search.search_tables import s_large - -# def tricksearchdot(layout='trickySearch', SAgent=None, agent_args=None, layout_str=None): -# stest(layout_str=layout_str, SAgent=SAgent, prob=GymFoodSearchProblem(), agent_args=agent_args, zoom=2, **dargs, fps=1000) # part 3 - -from irlc.lectures.lec03.lecture_03_tricksearch_bfs import tricksearchdot - -if __name__ == "__main__": - # agent_args = dict(heuristic=manhattanHeuristic,N=30) - tricksearchdot(SAgent=BFSAgentYield, agent_args=None, layout_str=s_large) diff --git a/irlc/lectures/lec03/lecture_03_tricksearch_astar.py b/irlc/lectures/lec03/lecture_03_tricksearch_astar.py deleted file mode 100644 index 6c658491e286be118f4d82e429add412cd680b40..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_tricksearch_astar.py +++ /dev/null @@ -1,10 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -# from irlc.ex03.pacsearch_agents import GymPositionSearchProblem, manhattanHeuristic, GymCornersProblem, cornersHeuristic, foodHeuristic, GymFoodSearchProblem, GymAnyFoodSearchProblem -from irlc.lectures.chapter4search.yield_version.pacman_yield import AStarAgentYield - -from irlc.lectures.lec03.lecture_03_tricksearch_bfs import tricksearchdot -from irlc.ex03multisearch.pacman_problem_foodsearch_astar import foodHeuristic - -if __name__ == "__main__": - agent_args = dict(heuristic=foodHeuristic) - tricksearchdot(SAgent=AStarAgentYield, agent_args=agent_args) diff --git a/irlc/lectures/lec03/lecture_03_tricksearch_bfs.py b/irlc/lectures/lec03/lecture_03_tricksearch_bfs.py deleted file mode 100644 index 89b776456aa03640d6e75721ff7804ca3dbf8b6a..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_tricksearch_bfs.py +++ /dev/null @@ -1,21 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -from irlc.lectures.chapter4search.yield_version.pacman_yield import stest, dargs -from irlc.ex03multisearch.pacman_problem_foodsearch import GymFoodSearchProblem -from irlc.lectures.chapter4search.yield_version.pacman_yield import BFSAgentYield - -layout_str = """ -%%%%%%%%%%%% -% % % -%.%.%.%% % % -% P % % -%%%%%%%%%% % -%. % -%%%%%%%%%%%% -""".strip() - -def tricksearchdot(layout_str=layout_str, SAgent=None, agent_args=None): - stest(layout_str=layout_str, SAgent=SAgent, prob=GymFoodSearchProblem(), agent_args=agent_args, zoom=2, **dargs, fps=1000) # part 3 - -if __name__ == "__main__": - # agent_args = dict(heuristic=manhattanHeuristic,N=30) - tricksearchdot(SAgent=BFSAgentYield, agent_args=None) diff --git a/irlc/lectures/lec03/lecture_03_tricksearch_dfs.py b/irlc/lectures/lec03/lecture_03_tricksearch_dfs.py deleted file mode 100644 index f3b2ac4ad2eeed59217fe591c95385576e69c7ec..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/lecture_03_tricksearch_dfs.py +++ /dev/null @@ -1,10 +0,0 @@ -# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text. -# from irlc.ex03.pacsearch_agents import GymPositionSearchProblem, manhattanHeuristic, GymCornersProblem, cornersHeuristic, foodHeuristic, GymFoodSearchProblem, GymAnyFoodSearchProblem - -from irlc.lectures.chapter4search.yield_version.pacman_yield import DFSAgentYield -from irlc.lectures.lec03.lecture_03_tricksearch_bfs import tricksearchdot - - -if __name__ == "__main__": - # agent_args = dict(heuristic=manhattanHeuristic,N=30) - tricksearchdot(SAgent=DFSAgentYield, agent_args=None) diff --git a/irlc/lectures/lec03/snapshot_base/openaigym.video.0.8068.video000000.meta.json b/irlc/lectures/lec03/snapshot_base/openaigym.video.0.8068.video000000.meta.json deleted file mode 100644 index 5dc734d01281b1a52d401032ec7e9c6da2d4ea39..0000000000000000000000000000000000000000 --- a/irlc/lectures/lec03/snapshot_base/openaigym.video.0.8068.video000000.meta.json +++ /dev/null @@ -1 +0,0 @@ -{"episode_id": 0, "content_type": "video/mp4"} \ No newline at end of file diff --git a/irlc/lectures/lec03/snapshot_base/openaigym.video.0.8068.video000000.mp4 b/irlc/lectures/lec03/snapshot_base/openaigym.video.0.8068.video000000.mp4 deleted file mode 100644 index 17e5e5fbd204f4f1c8bf240b166ab0a318db4744..0000000000000000000000000000000000000000 Binary files a/irlc/lectures/lec03/snapshot_base/openaigym.video.0.8068.video000000.mp4 and /dev/null differ diff --git a/solutions/ex03/inventory_evaluation_TODO_1.py b/solutions/ex03/inventory_evaluation_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..ec037ab6c0e4495d508b769cb3f844361bc27766 --- /dev/null +++ b/solutions/ex03/inventory_evaluation_TODO_1.py @@ -0,0 +1,2 @@ + k = 0 + expected_number_of_items = sum([p * model.f(x, u, w, k=0) for w, p in model.Pw(x, u, k).items()]) \ No newline at end of file diff --git a/solutions/ex03/inventory_evaluation_TODO_2.py b/solutions/ex03/inventory_evaluation_TODO_2.py new file mode 100644 index 0000000000000000000000000000000000000000..e2897b1bbe779fd70b1d103bc72fada72f0e465a --- /dev/null +++ b/solutions/ex03/inventory_evaluation_TODO_2.py @@ -0,0 +1,12 @@ + model = InventoryDPModel() + N = model.N + J = [{} for _ in range(N + 1)] + J[N] = {x: model.gN(x) for x in model.S(model.N)} + for k in range(N - 1, -1, -1): + for x in model.S(k): + Qu = {u: sum(pw * (model.g(x, u, w, k) + J[k + 1][model.f(x, u, w, k)]) for w, pw in model.Pw(x, u, k).items()) for u + in model.A(x, k)} + + umin = pi[k][x] # min(Qu, key=Qu.get) + J[k][x] = Qu[umin] # Compute the expected cost function + J_pi_x0 = J[0][x0] \ No newline at end of file diff --git a/solutions/ex03/kuramoto_TODO_1.py b/solutions/ex03/kuramoto_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..27e0fcd91a1912fcd9510bd5c42085b40f5f035d --- /dev/null +++ b/solutions/ex03/kuramoto_TODO_1.py @@ -0,0 +1 @@ + symbolic_f_list = [u[0] + sym.cos(x[0])] \ No newline at end of file diff --git a/solutions/ex03/kuramoto_TODO_2.py b/solutions/ex03/kuramoto_TODO_2.py new file mode 100644 index 0000000000000000000000000000000000000000..0f1d61147d8b54964f5a35d9493bd13ead61df13 --- /dev/null +++ b/solutions/ex03/kuramoto_TODO_2.py @@ -0,0 +1 @@ + f_value = cmodel.f(x, u, t=0) \ No newline at end of file diff --git a/solutions/ex03/kuramoto_TODO_3.py b/solutions/ex03/kuramoto_TODO_3.py new file mode 100644 index 0000000000000000000000000000000000000000..f28ac99d8a97bd8ed4423c5dbaff106350e41d07 --- /dev/null +++ b/solutions/ex03/kuramoto_TODO_3.py @@ -0,0 +1,7 @@ + Delta = tt[k + 1] - tt[k] + xn = xs[k] + k1 = np.asarray(f(xn, u)) + k2 = np.asarray(f(xn + Delta * k1/2, u)) + k3 = np.asarray(f(xn + Delta * k2/2, u)) + k4 = np.asarray(f(xn + Delta * k3, u)) + x_next = xn + 1/6 * Delta * (k1 + 2*k2 + 2*k3 + k4) \ No newline at end of file diff --git a/solutions/ex03/toy_2d_control_TODO_1.py b/solutions/ex03/toy_2d_control_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..137a63b9c00938de0a696f65e96e233a0fec8e0f --- /dev/null +++ b/solutions/ex03/toy_2d_control_TODO_1.py @@ -0,0 +1,2 @@ + def sym_f(self, x, u, t=None): + return [x[1], sym.cos(x[0] + u[0])] \ No newline at end of file diff --git a/solutions/ex03/toy_2d_control_TODO_2.py b/solutions/ex03/toy_2d_control_TODO_2.py new file mode 100644 index 0000000000000000000000000000000000000000..91c054a3e7690e1932d077a6748793cd123c5b2f --- /dev/null +++ b/solutions/ex03/toy_2d_control_TODO_2.py @@ -0,0 +1,4 @@ + toy = Toy2DControl() + x0 = np.asarray([np.pi/2, 0]) + xs, us, ts, cost = toy.simulate( x0=x0, u_fun = u0, t0=0, tF=T) + wT = xs[-1][0] \ No newline at end of file