Skip to content

Commit

Permalink
Clean up Demo.demo() a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lassepe committed Mar 7, 2024
1 parent 303aa6f commit 715ad1e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/Demo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function demo()
initial_state = mortar([[-1.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0]])
# both players want to reach a goal position at (0, 1))
context = [0.0, 1.0, 0.0, 1.0]
joint_strategy = solve_trajectory_game!(solver, game, initial_state; context)
initial_joint_strategy = solve_trajectory_game!(solver, game, initial_state; context)

# to demonstrate the differentiability, let us use gradient descent to find
# goal positions that minimize each players' control effort
Expand All @@ -72,10 +72,6 @@ function demo()
end
end

# we can quickly visualize the solution
GLMakie.plot(game.env; color=:lightgray) |> display
GLMakie.plot!(joint_strategy)

context_estimate = context
number_of_gradient_steps = 100
learning_rate = 1e-2
Expand All @@ -84,6 +80,18 @@ function demo()
context_estimate -= learning_rate * ∇context
end

final_joint_strategy = solve_trajectory_game!(solver, game, initial_state; context=context_estimate)

# visualize the solution...
# ...for the initial context estimate
figure = GLMakie.Figure()
GLMakie.plot(figure[1, 1], game.env; axis=(; aspect=GLMakie.DataAspect(), title="Game solution for initial context estimate"))
GLMakie.plot!(figure[1, 1], initial_joint_strategy)
# ...and the optimized context estimate
GLMakie.plot(figure[1, 2], game.env; axis=(; aspect=GLMakie.DataAspect(), title="Game solution for optimized context estimate"))
GLMakie.plot!(figure[1, 2], final_joint_strategy)
display(figure)

# trivially, we find that we can minimize each player's control input by setting
# their goal positions to the initial positions
@show (context_estimate - initial_state[[1, 2, 5, 6]])
Expand Down

0 comments on commit 715ad1e

Please sign in to comment.