Skip to content
Snippets Groups Projects
Commit c49768e2 authored by Olivier Cots's avatar Olivier Cots
Browse files

update archi

parent 88ce3efd
No related branches found
No related tags found
No related merge requests found
Showing
with 4521 additions and 0 deletions
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
%% Cell type:markdown id: tags:
# Turnpike
We consider the following optimal control problem:
$$ \int_0^{2} x^2(t)\,\mathrm{d}t \to \min, $$
where
$$ \dot{x}(t) = u(t),\quad |u(t)| \leq 1, $$
$$ x(0)=1,\quad x(2)=1/2. $$
%% Cell type:markdown id: tags:
<div class="alert alert-info">
**_Question._**
Solve the optimal control problem with `Jump` and `Ipopt`.
</div>
%% Cell type:code id: tags:
``` julia
using JuMP, Ipopt
# Create JuMP model, using Ipopt as the solver
turnpike = Model(optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 5))
# Parameters
t0 = 0. # initial time
tf = 2. # final time
c0 = 0. # Initial cost
x0 = 1. # Initial position
xf = 0.5 # Final position
N = 800 # Grid size
Δt = (tf-t0)/N # Time step
#### TO COMPLETE
#
# Define the variables (@variables), the objective (@objective), the limit constraints (@constraints)
# and the dynamic constraints (@NLconstraint)
#
# We consider the cost has an additional variable: c(0) = 0 and c(2) is free.
# The dynamics for the cost is dc = x^2 and the objective function is simple c(2)
#
@variables(turnpike, begin
# to complete
end)
# Objective
@objective(turnpike,
Min,
# to complete
)
# Initial conditions
@constraints(turnpike, begin
# to complete
end)
# Dynamics
for j in 2:N
# cost dynamics
@NLconstraint(turnpike,
# to complete
)
# state dynamics
@NLconstraint(turnpike,
# to complete
)
end
#### END TO COMPLETE
# Solve for the control and state
println("Solving...")
status = optimize!(turnpike)
# Display results
println("Solver status: ", status)
println("Minimum cost: ", objective_value(turnpike))
```
%% Cell type:code id: tags:
``` julia
# Can visualize the state and control variables
using Gadfly
```
%% Cell type:code id: tags:
``` julia
c_plot = plot(x = (1:N) * Δt, y = value.(c)[:], Geom.line,
Guide.xlabel("Time (s)"), Guide.ylabel("Cost"))
x_plot = plot(x = (1:N) * Δt, y = value.(x)[:], Geom.line,
Guide.xlabel("Time (s)"), Guide.ylabel("Position"))
u_plot = plot(x = (1:N) * Δt, y = value.(u)[:], Geom.line,
Guide.xlabel("Time (s)"), Guide.ylabel("Control"))
draw(SVG(6inch, 6inch), vstack(c_plot, x_plot, u_plot))
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment