Skip to content

Commit ed757cb

Browse files
committed
fix constraint_violation run_ci
1 parent da224e9 commit ed757cb

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

examples/test.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using ForwardDiff
2+
using Symbolics
3+
4+
5+
# function
6+
my_func(x) = cos(x[1])
7+
8+
# variables
9+
@variables x[1:1]
10+
11+
# symbolic functions
12+
f = my_func(x)
13+
df = Symbolics.gradient(f, x)
14+
15+
# julia functions
16+
f_func = eval(Symbolics.build_function(f, x))
17+
df_func = eval(Symbolics.build_function(df, x)[1])
18+
19+
# eval functions
20+
f_func([0.5 * π])
21+
df_func([0.5 * π])
22+
23+
# diff gradient function (autodiff)
24+
ForwardDiff.jacobian(df_func, [0.5 * π])
25+
26+
# diff gradient function (symbolics)
27+
dfs = df_func(x)
28+
ddfs = Symbolics.gradient(dfs[1], x)
29+
30+
31+
##
32+
using Symbolics
33+
using LinearAlgebra
34+
35+
function midpoint(f,x,u,dt)
36+
return x + dt*f(x + 0.5*dt*f(x,u),u)
37+
end
38+
39+
function car(x, u)
40+
[u[1] * cos(x[3]); u[1] * sin(x[3]); u[2]]
41+
end
42+
43+
@variables x[1:3] u[1:2]
44+
dt = .1
45+
val = midpoint(car,x,u,dt)
46+
@show val
47+
jac = Symbolics.jacobian(val,[x;u])
48+
@show jac

src/constraints.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ function constraint_violation(c_data::ConstraintsData; norm_type=Inf)
9898
c_max = 0.0
9999
for t = 1:T
100100
nc = cons[t].nc
101+
ineq = cons[t].idx_ineq
101102
for i = 1:nc
102-
cti = c_data.c[t][i]
103-
(i in cons[t].idx_ineq) && (cti = max(0.0, cti))
103+
cti = (i in ineq) ? max(0.0, c_data.c[t][i]) : abs(c_data.c[t][i])
104104
c_max = max(c_max, cti)
105105
end
106106
end

src/dynamics.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ function step!(d::Dynamics, x, u, w)
3434
return d.val_cache
3535
end
3636

37-
# function eval_con!(c, cons::Model, x, u, w)
38-
# for (t, con) in enumerate(cons)
39-
# step!(con, x[t], u[t], w[t])
40-
# @views c[t] .= con.val_cache
41-
# end
42-
# end
43-
4437
function eval_con_jac!(jx, ju, cons::Model, x, u, w)
4538
for (t, con) in enumerate(cons)
4639
con.jacx(con.jacx_cache, x[t], u[t], w[t])

0 commit comments

Comments
 (0)