Skip to content

Commit 9643762

Browse files
committed
comparison
1 parent 734fdc7 commit 9643762

26 files changed

+211
-54
lines changed

ext/JuMPModels/glider.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function OptimalControlProblems.glider(::JuMPBackend; nh::Int64=100)
3030
@variables(
3131
model,
3232
begin
33-
0 <= t_f, (start = 1.0)
33+
0 <= tf, (start = 1.0)
3434
0.0 <= x[k=0:nh], (start = x_0 + vx_0 * (k / nh))
3535
y[k=0:nh], (start = y_0 + (k / nh) * (y_f - y_0))
3636
0.0 <= vx[k=0:nh], (start = vx_0)
@@ -44,7 +44,7 @@ function OptimalControlProblems.glider(::JuMPBackend; nh::Int64=100)
4444
@expressions(
4545
model,
4646
begin
47-
step, t_f / nh
47+
step, tf / nh
4848
r[i=0:nh], (x[i] / r_0 - 2.5)^2
4949
u[i=0:nh], u_c * (1 - r[i]) * exp(-r[i])
5050
w[i=0:nh], vy[i] - u[i]

ext/JuMPModels/steering.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ function OptimalControlProblems.steering(::JuMPBackend; nh::Int64=100)
2323
model = JuMP.Model()
2424

2525
@variable(model, u_min <= u[i=1:(nh + 1)] <= u_max, start = 0.0) # control
26-
@variable(model, x[i=1:(nh + 1), j=1:4], start = gen_x0(i, j)) # state
27-
@variable(model, tf, start = 1.0) # final time
26+
@variable(model, x1[i=1:(nh + 1)], start = gen_x0(i, 1)) # state x1
27+
@variable(model, x2[i=1:(nh + 1)], start = gen_x0(i, 2)) # state x2
28+
@variable(model, x3[i=1:(nh + 1)], start = gen_x0(i, 3)) # state x3
29+
@variable(model, x4[i=1:(nh + 1)], start = gen_x0(i, 4)) # state x4
30+
@variable(model, tf, start = 1.0) # final time
2831

2932
@expression(model, h, tf / nh) # step size
3033
@objective(model, Min, tf)
@@ -35,18 +38,21 @@ function OptimalControlProblems.steering(::JuMPBackend; nh::Int64=100)
3538
@constraints(
3639
model,
3740
begin
38-
con_x1[i=1:nh], x[i + 1, 1] == x[i, 1] + 0.5 * h * (x[i, 3] + x[i + 1, 3])
39-
con_x2[i=1:nh], x[i + 1, 2] == x[i, 2] + 0.5 * h * (x[i, 4] + x[i + 1, 4])
40-
con_x3[i=1:nh],
41-
x[i + 1, 3] == x[i, 3] + 0.5 * h * (a * cos(u[i]) + a * cos(u[i + 1]))
42-
con_x4[i=1:nh],
43-
x[i + 1, 4] == x[i, 4] + 0.5 * h * (a * sin(u[i]) + a * sin(u[i + 1]))
41+
con_x1[i=1:nh], x1[i + 1] == x1[i] + 0.5 * h * (x3[i] + x3[i + 1])
42+
con_x2[i=1:nh], x2[i + 1] == x2[i] + 0.5 * h * (x4[i] + x4[i + 1])
43+
con_x3[i=1:nh], x3[i + 1] == x3[i] + 0.5 * h * (a * cos(u[i]) + a * cos(u[i + 1]))
44+
con_x4[i=1:nh], x4[i + 1] == x4[i] + 0.5 * h * (a * sin(u[i]) + a * sin(u[i + 1]))
4445
end
4546
)
4647

4748
# Boundary conditions
48-
@constraint(model, [j = 1:4], x[1, j] == xs[j])
49-
@constraint(model, [j = 2:4], x[nh + 1, j] == xf[j])
49+
@constraint(model, x1[1] == xs[1])
50+
@constraint(model, x2[1] == xs[2])
51+
@constraint(model, x3[1] == xs[3])
52+
@constraint(model, x4[1] == xs[4])
53+
@constraint(model, x2[nh + 1] == xf[2])
54+
@constraint(model, x3[nh + 1] == xf[3])
55+
@constraint(model, x4[nh + 1] == xf[4])
5056

5157
return model
52-
end
58+
end

ext/MetaData/beam.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
beam_meta = Dict(:name => "beam", :nh => 100, :nvar => 404, :ncon => 305, :minimize => true)
1+
beam_meta = Dict(
2+
:name => "beam",
3+
:nh => 100,
4+
:nvar => 404,
5+
:ncon => 305,
6+
:minimize => true,
7+
:state_name => ["x1", "x2"],
8+
:costate_name => ["con_x1", "con_x2"],
9+
:control_name => ["u"],
10+
:time => ("final_time", "tf", 1.0)
11+
)

ext/MetaData/bioreactor.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
bioreactor_meta = Dict(
2-
:name => "bioreactor", :nh => 100, :nvar => 505, :ncon => 404, :minimize => false
3-
)
2+
:name => "bioreactor",
3+
:nh => 100,
4+
:nvar => 505,
5+
:ncon => 404,
6+
:minimize => false,
7+
:state_name => ["y", "s", "b"],
8+
:costate_name => ["con_y", "con_s", "con_b"],
9+
:control_name => ["u"],
10+
:time => ("final_time", "T", 300.0) # T = 10 * N where N = 30 by default
11+
)

ext/MetaData/cart_pendulum.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
cart_pendulum_meta = Dict(
2-
:name => "cart_pendulum", :nh => 100, :nvar => 507, :ncon => 405, :minimize => true
3-
)
2+
:name => "cart_pendulum",
3+
:nh => 100,
4+
:nvar => 507,
5+
:ncon => 405,
6+
:minimize => true,
7+
:state_name => ["x", "dx", "theta", "omega"],
8+
:costate_name => ["d_x", "d_dx", "d_theta", "d_omega"],
9+
:control_name => "Fex",
10+
:time => ("final_time", "tf", nothing)
11+
)

ext/MetaData/chain.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
chain_meta = Dict(
2-
:name => "chain", :nh => 100, :nvar => 404, :ncon => 305, :minimize => true
3-
)
2+
:name => "chain",
3+
:nh => 100,
4+
:nvar => 404,
5+
:ncon => 305,
6+
:minimize => true,
7+
:state_name => ["x1", "x2", "x3"],
8+
:costate_name => ["con_x1", "con_x2", "con_x3"],
9+
:control_name => ["u"],
10+
:time => ("final_time", "tf", 1.0)
11+
)

ext/MetaData/dielectrophoretic_particle.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ dielectrophoretic_particle_meta = Dict(
44
:nvar => 304,
55
:ncon => 203,
66
:minimize => true,
7-
)
7+
:state_name => ["x", "y"],
8+
:costate_name => ["con_x", "con_y"],
9+
:control_name => "u",
10+
:time => ("final_time", "tf", nothing)
11+
)

ext/MetaData/double_oscillator.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
double_oscillator_meta = Dict(
22
:name => "double_oscillator",
3-
:nh => nothing,
3+
:nh => 100, #:nh => nothing,
44
:nvar => nothing,
55
:ncon => nothing,
66
:minimize => true,
7-
)
7+
:state_name => ["x1", "x2", "x3", "x4"],
8+
:costate_name => ["con_x1", "con_x2", "con_x3", "con_x4"],
9+
:control_name => "u",
10+
:time => ("final_time", "tf", 2π)
11+
)

ext/MetaData/ducted_fan.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
ducted_fan_meta = Dict(
22
:name => "ducted_fan",
3-
:nh => nothing,
3+
:nh => 100, # :nh => nothing,
44
:nvar => nothing,
55
:ncon => nothing,
66
:minimize => true,
7-
)
7+
:state_name => ["x1", "v1", "x2", "v2", "α", ""],
8+
:costate_name => ["con_x1", "con_v1", "con_x2", "con_v2", "con_α", "con_vα"],
9+
:control_name => ["u1", "u2"],
10+
:time => ("final_time", "tf", nothing)
11+
)

ext/MetaData/electrical_vehicle.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
electrical_vehicle_meta = Dict(
22
:name => "electrical_vehicle",
3-
:nh => nothing,
3+
:nh => 100, #:nh => nothing,
44
:nvar => nothing,
55
:ncon => nothing,
66
:minimize => true,
7-
)
7+
:state_name => ["x", "v"],
8+
:costate_name => ["cond_x", "cond_v"],
9+
:control_name => "u",
10+
:time => ("final_time", "tf", 1.0)
11+
)

0 commit comments

Comments
 (0)