[Doc] Examples for the sign convention of duals and costate (min/max, writing of constraints, direct vs indirect)
メンテナーはふだん 1 日以内に返信
@ocots がすでに取り組んでいます。
2026年10月23日 から。
評価
この issue はまだ評価されていません。
説明
Follow-up of #1014 (the convention) and companion of #1015 (the page that states it). This issue lists the examples to add to the documentation, so that a user can see that the signs do not depend on the solver, on the sense of the criterion, or on the way a constraint is written. Each example should also become a test: run in a docs page, it fails loudly if a convention moves.
The implementation is in three draft PRs:
- control-toolbox/CTSolvers.jl#289: one multiplier convention for every NLP solver.
min fandmax -fhave the same multipliers; a constraint with a single bound has a nonnegative multiplier; equalities keep their sign. - control-toolbox/CTFlows.jl#494: the solution of
Flow(ocp, law; constraint=:label, multiplier=μ)carriesdual(sol, ocp, :label), in the same convention. - control-toolbox/CTModels.jl#483:
dualon a solution that holds the duals of some constraints only, and the jumps of the duals in the plots of a multi-phase solution.
The convention, as the user should read it (for #1015)
- The dual of an inequality constraint is nonnegative, whatever the constraint and the sense of the criterion.
g(x) ≤ 0and-g(x) ≥ 0, orx(t) ≥ 0.1and0.1 - x(t) ≤ 0, are the same constraint and have the same dual. - An equality keeps its sign:
c = 0and-c = 0have opposite duals. min Jandmax -Jare the same problem: they have the same duals and the same costatep. Only the objective changes sign.- Indirect method: the pseudo-Hamiltonian
H = p·f + p⁰ℓ + μ·g(g ≥ 0,μ ≥ 0) is always maximised, withp⁰ = -1for a minimisation and+1for a maximisation.dual(sol, ocp, :label)of a flow solution is theμgiven to the flow (0off the boundary arc). - A constraint with two finite bounds,
lb ≤ c ≤ ub, has a signed dual:+μwhen the upper side is active,-μwhen the lower side is.
Examples to add
-
The signs do not change with
min/max. Solveẋ = u,x(0) = -1,x(t) + u(t) ≤ 0,0 ≤ u(t):- once as
∫ -u(t) dt → min, once as∫ u(t) dt → max; - with Ipopt and with MadNLP.
Show that
costate(sol)anddual(sol, ocp, :mixed)are the same in the four cases. The closed form isp(t) = e^{t-1} - 1anddual = e^{t-1}. - once as
-
The signs do not change with the way a constraint is written. The same problem with
x(t) + u(t) ≤ 0written as-x(t) - u(t) ≥ 0: the same dual. -
Direct and indirect give the same duals. Rebuild the solution of example 1 with
Flow(ocp, (x, p) -> -x; constraint=:mixed, multiplier=(x, p) -> p + 1), then comparedual(sol_direct, ocp, :mixed)anddual(sol_flow, ocp, :mixed)on one plot. They agree up to the discretisation error. -
A boundary arc in a multi-phase indirect solution. The problem of control-toolbox/CTFlows.jl#440 (
x ≥ 0.1, three arcs).plot(sol)shows the dual,0then2x = 0.2on the boundary arc then0, with its jumps at the junctions and the phase labels. Compare with a direct solve of the same problem. -
Why the label matters. In a flow, a constraint given as a function has no label: its dual cannot be placed in the solution, the flow warns, and
dualthrows. Show the labelled form,constraint=:labelor:label => :upper.
Possible tests (OptimalControl test suite, the cross-package level): examples 1 to 3, with Ipopt and MadNLP (and Uno), as @test on the closed form.
Still open (not for the user page)
- Box constraints. The dual of a box (
0 ≤ u(t) ≤ 1declared as a box) has the opposite sign to the same constraint written as a path constraint, and it is not divided by the step (control-toolbox/CTDirect.jl#639). The page should say so until it is fixed, or wait for it. - Boundary and box duals of a flow solution are not rebuilt (
dualthrows aPreconditionError). - Two-sided constraints: the signed value is kept. Is that what the page should present, or a pair (lower, upper)?
🤖 Generated with Claude Code
- 主要言語
- Julia
- スター
- 135
- フォーク
- 11
- 平均マージ
- 7時間 51分
- マージ済み PR(30日)
- 22
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
control-toolbox/OptimalControl.jl のほかの issue
-
[Doc] User guide to the duals: every kind, constraint ↔ dual, direct ↔ indirect対応中かも @ocots が 6 日前に担当しました。 オープン
control-toolbox/OptimalControl.jl#1035 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Tests of the duals: every kind of constraint, direct vs indirect, pinned algorithms対応中かも @ocots が 6 日前に担当しました。 オープン
control-toolbox/OptimalControl.jl#1034 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Documentation: sign conventions (min/max, p⁰, constraints, duals) and how they appear in a solution対応中かも @ocots が 17 日前に担当しました。 オープンdocumentation
control-toolbox/OptimalControl.jl#1015 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Tests fail on Julia 1.13: keyword-only anonymous function in test/problems/goddard.jl対応中かも @ocots が 19 日前に担当しました。 オープン
control-toolbox/OptimalControl.jl#996 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Docs: use Makie.Figure() instead of Makie.plot() for an empty canvas対応中かも @ocots が 19 日前に担当しました。 オープン
control-toolbox/OptimalControl.jl#994 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
control-toolbox/OptimalControl.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
Add project: Typst_jll.jl対応中かも @github-actions が今日担当しました。 オープンadd-project
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
YDX-2147483647/best-of-typst#590 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100