Skip to content

Commit 406b566

Browse files
authored
Merge pull request #23 from control-toolbox/profiling
foo
2 parents a1961cf + 38f85a4 commit 406b566

File tree

2 files changed

+35
-43
lines changed

2 files changed

+35
-43
lines changed

profiling/boundary.jl

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,21 @@ begin
2121
r[2] = xf[1]
2222
return nothing
2323
end
24-
#bc!(r, x0, xf, v) = r .= [x0[1], xf[1]]
25-
CTModels.constraint!(
26-
pre_ocp, :boundary; f=bc!, lb=[-1, 0], ub=[-1, 0], label=:boundary1
27-
)
28-
CTModels.constraint!(
29-
pre_ocp, :boundary; f=bc!, lb=[-1, 0], ub=[-1, 0], label=:boundary2
30-
)
31-
CTModels.constraint!(
32-
pre_ocp, :boundary; f=bc!, lb=[-1, 0], ub=[-1, 0], label=:boundary3
33-
)
34-
CTModels.constraint!(
35-
pre_ocp, :control; rg=1:2, lb=[0, 0], ub=[Inf, Inf], label=:control_rg
36-
)
24+
CTModels.constraint!(pre_ocp, :boundary, f=bc!, lb=[-1, 0], ub=[-1, 0], label=:boundary1); N = 2
25+
#CTModels.constraint!(pre_ocp, :boundary, f=bc!, lb=[-1, 0], ub=[-1, 0], label=:boundary2); N += 2
26+
#CTModels.constraint!(pre_ocp, :boundary, f=bc!, lb=[-1, 0], ub=[-1, 0], label=:boundary3); N += 2
27+
CTModels.constraint!(pre_ocp, :control, rg=1:2, lb=[0, 0], ub=[Inf, Inf], label=:control_rg)
3728
CTModels.definition!(pre_ocp, Expr(:simple_integrator_min_energy))
3829
ocp = CTModels.build_model(pre_ocp)
39-
return ocp
30+
return ocp, N
4031
end
4132

42-
ocp = simple_integrator_model()
33+
ocp, N = simple_integrator_model()
4334

4435
x0 = [1.0]
4536
xf = [0.0]
46-
v = Float64[]
47-
r = zeros(Float64, 6)
37+
v = Float64[]
38+
r = zeros(Float64, N)
4839
bc_constraint = CTModels.boundary_constraints_nl(ocp)
4940
boundary! = bc_constraint[2]
5041
boundary!(r, x0, xf, v)
@@ -61,24 +52,27 @@ let
6152
println("--------------------------------")
6253
println("Boundary constraint")
6354
@code_warntype bc!(r, x0, xf, v)
64-
55+
println("\n")
6556
println("--------------------------------")
6657
println("Boundary constraint from model")
6758
@code_warntype boundary!(r, x0, xf, v)
6859
end
6960

7061
let
62+
println("--------------------------------")
7163
println("Boundary constraint")
72-
@btime bc!(r, x0, xf, v)
64+
display(@benchmark bc!(r, x0, xf, v))
65+
println("\n")
66+
println("--------------------------------")
7367
println("Boundary constraint from model")
74-
@btime boundary!(r, x0, xf, v)
68+
display(@benchmark boundary!(r, x0, xf, v))
7569
end
7670

7771
let
7872
println("--------------------------------")
7973
println("Boundary constraint")
80-
@code_native debuginfo = :none dump_module = false bc!(r, x0, xf, v)
81-
74+
@code_native debuginfo=:none dump_module=false bc!(r, x0, xf, v)
75+
println("\n")
8276
println("--------------------------------")
8377
println("Boundary constraint from model")
8478
@code_native debuginfo = :none dump_module = false boundary!(r, x0, xf, v)

src/model.jl

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,17 @@ function build_constraints(constraints::ConstraintsDictType)::ConstraintsModel
7474
length_boundary_cons_nl::Int = length(boundary_cons_nl_f)
7575

7676
function make_path_cons_nl(
77-
constraints_number::Int,
78-
constraints_dimensions::Vector{Int},
77+
constraints_number::Int,
78+
constraints_dimensions::Vector{Int},
79+
constraints_function::Function # only one function
80+
)
81+
@assert constraints_number == 1
82+
return constraints_function
83+
end
84+
85+
function make_path_cons_nl(
86+
constraints_number::Int,
87+
constraints_dimensions::Vector{Int},
7988
constraints_functions::Function...,
8089
)
8190
function path_cons_nl!(val, t, x, u, v)
@@ -90,15 +99,14 @@ function build_constraints(constraints::ConstraintsDictType)::ConstraintsModel
9099
return path_cons_nl!
91100
end
92101

93-
# function path_cons_nl!(val, t, x, u, v) # nonlinear path constraints (in place)
94-
# j = 1
95-
# for i in 1:length_path_cons_nl
96-
# li = path_cons_nl_dim[i]
97-
# path_cons_nl_f[i](@view(val[j:(j + li - 1)]), t, x, u, v)
98-
# j += li
99-
# end
100-
# return nothing
101-
# end
102+
function make_boundary_cons_nl(
103+
constraints_number::Int,
104+
constraints_dimensions::Vector{Int},
105+
constraints_function::Function # only one function
106+
)
107+
@assert constraints_number == 1
108+
return constraints_function
109+
end
102110

103111
function make_boundary_cons_nl(
104112
constraints_number::Int,
@@ -117,16 +125,6 @@ function build_constraints(constraints::ConstraintsDictType)::ConstraintsModel
117125
return boundary_cons_nl!
118126
end
119127

120-
# function boundary_cons_nl!(val, x0, xf, v) # nonlinear boundary constraints
121-
# j = 1
122-
# for i in 1:length_boundary_cons_nl
123-
# li = boundary_cons_nl_dim[i]
124-
# boundary_cons_nl_f[i](@view(val[j:(j + li - 1)]), x0, xf, v)
125-
# j += li
126-
# end
127-
# return nothing
128-
# end
129-
130128
path_cons_nl! = make_path_cons_nl(
131129
length_path_cons_nl, path_cons_nl_dim, path_cons_nl_f...
132130
)

0 commit comments

Comments
 (0)