Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d7d970a
Duration Constraint
BBhattacharyya1729 Apr 21, 2025
f4513fd
Merge remote-tracking branch 'upstream/main'
BBhattacharyya1729 May 1, 2025
b9981a7
free phases
andgoldschmidt May 3, 2025
acf0de1
intro global constraints / objectives, constraints to use global dim …
andgoldschmidt May 5, 2025
55e0a8b
Added Pairwise
BBhattacharyya1729 May 6, 2025
66f6941
clean
andgoldschmidt May 7, 2025
3d9e65a
Merge branch 'main' of github.com:harmoniqs/DirectTrajOpt.jl into fea…
andgoldschmidt May 7, 2025
aec79a7
Merge branch 'main' of github.com:harmoniqs/DirectTrajOpt.jl into fea…
andgoldschmidt May 7, 2025
8d936fe
refactor to separate pure knot point from global mixed
andgoldschmidt May 9, 2025
5c009eb
check overlapping constraint for zero reset
andgoldschmidt May 10, 2025
da8a5be
add reset for global nonlinear constraint
andgoldschmidt May 10, 2025
b2deb0f
min time obj free time only
andgoldschmidt May 19, 2025
6f9db34
added duration and symmetry consraints
BBhattacharyya1729 May 28, 2025
dcc5643
Update regularizers.jl
BBhattacharyya1729 May 28, 2025
ef4657a
Merge branch 'harmoniqs:main' into Feature/DurationSymmetry
BBhattacharyya1729 May 28, 2025
dd18f16
Merge branch 'main' into feature/free-phases
andgoldschmidt Jun 4, 2025
d7781ab
update global data
andgoldschmidt Jun 5, 2025
5911dc1
refactor NT concrete
Jun 7, 2025
1ffee19
update for new NT
Jun 13, 2025
c0213ea
added tests for symmetry and duration constraints
BBhattacharyya1729 Jun 16, 2025
9b6f1e7
Fixed duration/symmetry constraint tests
BBhattacharyya1729 Jun 16, 2025
1b07173
update for parametric NT, test global obj and constraints
andgoldschmidt Jun 17, 2025
e9623fb
Merge remote-tracking branch 'bikrant/Feature/DurationSymmetry' into …
andgoldschmidt Jun 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added duration and symmetry consraints
  • Loading branch information
BBhattacharyya1729 committed May 28, 2025
commit 6f9db3403b294430c89edd37dcf150b11cd16685
39 changes: 39 additions & 0 deletions src/constraints/linear_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export TimeStepsAllEqualConstraint
export L1SlackConstraint
export TotalConstraint
export DurationConstraint
export SymmetryConstraint
export SymmetricControlConstraint
###
### EqualityConstraint
###
Expand Down Expand Up @@ -262,4 +264,41 @@ function DurationConstraint(
@assert traj.timestep isa Symbol
indices = [index(k, traj.components[traj.timestep][1], traj.dim) for k ∈ 1:traj.T]
return TotalConstraint(indices, value ,label)
end


struct SymmetryConstraint <: AbstractLinearConstraint
even_index_pairs::Vector{Tuple{Int64,Int64}}
odd_index_pairs::Vector{Tuple{Int64,Int64}}
label::String
end

function SymmetricControlConstraint(
traj::NamedTrajectory,
name::Symbol,
idx::Vector{Int64};
even = true,
label = "Symmetry Constraint on $name"
)
even_pairs = Vector{Tuple{Int64,Int64}}()
odd_pairs = Vector{Tuple{Int64,Int64}}()

component_indicies = [slice(t, traj.components[name], traj.dim)[idx] for t ∈ 1:traj.T]
if(even)
even_pairs = vcat(even_pairs,reduce(vcat,[collect(zip(component_indicies[[idx,traj.T - idx+1]]...)) for idx in 1:traj.T ÷ 2]))
else
odd_pairs = vcat(odd_pairs,reduce(vcat,[collect(zip(component_indicies[[idx,traj.T - idx+1]]...)) for idx in 1:traj.T ÷ 2]))
end

if traj.timestep isa Symbol
time_indices = [index(k, traj.components[traj.timestep][1], traj.dim) for k ∈ 1:traj.T]
even_pairs = vcat(even_pairs,[(time_indices[idx],time_indices[traj.T + 1 - idx]) for idx ∈ 1:traj.T÷2])
end

return SymmetryConstraint(
even_pairs,
odd_pairs,
label
)

end
21 changes: 21 additions & 0 deletions src/solvers/ipopt_solver/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,25 @@ MOI.add_constraints(
MOI.EqualTo(con.value)
)

end

function (con::SymmetryConstraint)(
opt::Ipopt.Optimizer,
vars::Vector{MOI.VariableIndex}
)

for (i1,i2) in con.even_index_pairs
MOI.add_constraints(
opt,
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, vars[i1]) , MOI.ScalarAffineTerm(-1.0, vars[i2])], 0.0),
MOI.EqualTo(0.0)
)
end
for (i1,i2) in con.odd_index_pairs
MOI.add_constraints(
opt,
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, vars[i1]) , MOI.ScalarAffineTerm(1.0, vars[i2])], 0.0),
MOI.EqualTo(0.0)
)
end
end