Skip to content

Commit 70ae5d1

Browse files
authored
Merge pull request #283 from JuliaControl/new_default_backends
changed: better `jacobian` and `hessian` defaults for the sparse case in `NonLinMPC` and `MovingHorizonEstimator`
2 parents d24318f + c0f1d02 commit 70ae5d1

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ Our goal is controlling the first output $y_1$, but the second one $y_2$ should
5151
35:
5252

5353
```julia
54-
mhe = MovingHorizonEstimator(model)
55-
mpc = LinMPC(mhe, Mwt=[1, 0], Nwt=[0.1])
54+
mpc = LinMPC(model, Mwt=[1, 0], Nwt=[0.1])
5655
mpc = setconstraint!(mpc, ymax=[Inf, 35])
5756
```
5857

src/ModelPredictiveControl.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ using DifferentiationInterface: hessian!, value_gradient_and_hessian!, prepare_h
1414
using DifferentiationInterface: Constant, Cache
1515
using SparseConnectivityTracer: TracerSparsityDetector
1616
using SparseMatrixColorings: GreedyColoringAlgorithm, sparsity_pattern
17+
using SparseMatrixColorings: NaturalOrder, LargestFirst, SmallestLast
18+
using SparseMatrixColorings: IncidenceDegree, DynamicLargestFirst
1719

1820
import ProgressLogging
1921

src/controller/nonlinmpc.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const DEFAULT_NONLINMPC_JACDENSE = AutoForwardDiff()
55
const DEFAULT_NONLINMPC_JACSPARSE = AutoSparse(
66
AutoForwardDiff();
77
sparsity_detector=TracerSparsityDetector(),
8-
coloring_algorithm=GreedyColoringAlgorithm(),
8+
coloring_algorithm=GreedyColoringAlgorithm(ALL_COLORING_ORDERS),
99
)
1010
const DEFAULT_NONLINMPC_HESSIAN = DEFAULT_NONLINMPC_JACSPARSE
1111

@@ -291,10 +291,17 @@ NonLinMPC controller with a sample time Ts = 10.0 s:
291291
AutoSparse(
292292
AutoForwardDiff();
293293
sparsity_detector = TracerSparsityDetector(),
294-
coloring_algorithm = GreedyColoringAlgorithm()
294+
coloring_algorithm = GreedyColoringAlgorithm((
295+
NaturalOrder(),
296+
LargestFirst(),
297+
SmallestLast(),
298+
IncidenceDegree(),
299+
DynamicLargestFirst()
300+
))
295301
)
296302
```
297-
This is also the sparse backend selected for the Hessian of the Lagrangian function if
303+
that is, it will test many coloring orders at preparation and keep the best. This is
304+
also the sparse backend selected for the Hessian of the Lagrangian function if
298305
`oracle=true` and `hessian=true`, which is the second exception. Second order
299306
derivatives are only supported with `oracle=true` option.
300307

src/estimator/mhe/construct.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const DEFAULT_NONLINMHE_JACOBIAN = AutoForwardDiff()
55
const DEFAULT_NONLINMHE_HESSIAN = AutoSparse(
66
AutoForwardDiff();
77
sparsity_detector=TracerSparsityDetector(),
8-
coloring_algorithm=GreedyColoringAlgorithm(),
8+
coloring_algorithm=GreedyColoringAlgorithm(ALL_COLORING_ORDERS),
99
)
1010

1111
@doc raw"""
@@ -382,9 +382,17 @@ MovingHorizonEstimator estimator with a sample time Ts = 10.0 s:
382382
AutoSparse(
383383
AutoForwardDiff();
384384
sparsity_detector = TracerSparsityDetector(),
385-
coloring_algorithm = GreedyColoringAlgorithm()
385+
coloring_algorithm = GreedyColoringAlgorithm((
386+
NaturalOrder(),
387+
LargestFirst(),
388+
SmallestLast(),
389+
IncidenceDegree(),
390+
DynamicLargestFirst()
391+
))
386392
)
387393
```
394+
that is, it will test many coloring orders at preparation and keep the best.
395+
388396
The slack variable ``ε`` relaxes the constraints if enabled, see [`setconstraint!`](@ref).
389397
It is disabled by default for the MHE (from `Cwt=Inf`) but it should be activated for
390398
problems with two or more types of bounds, to ensure feasibility (e.g. on the estimated

src/general.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ const DEFAULT_LWT = 0.0
66
const DEFAULT_CWT = 1e5
77
const DEFAULT_EWT = 0.0
88

9+
"All deterministic algorithms for matrix coloring order in `SparseMatrixColoring.jl`."
10+
const ALL_COLORING_ORDERS = (
11+
NaturalOrder(),
12+
LargestFirst(),
13+
SmallestLast(),
14+
IncidenceDegree(),
15+
DynamicLargestFirst(),
16+
)
17+
918
"Termination status that means 'no solution available'."
1019
const ERROR_STATUSES = (
1120
JuMP.INFEASIBLE, JuMP.DUAL_INFEASIBLE, JuMP.LOCALLY_INFEASIBLE,

0 commit comments

Comments
 (0)