usagepatterns

Joris Gillis edited this page Jun 24, 2011 · 6 revisions

This page bundles treats some common patterns to handle typical situations that can appear when using CasADi as a tool.

The MX bundling pattern

When to use:

  • you have an optimization problem with multiple decision variables and/or parameters.

Suppose we have an optimization problem with multiple decision variables (A,B) and different parameters (P1,P2). We optimize for a range of P2 values, whilst printing out solutions of B:

X, (A,B)   = createParent([sp_dense(4,4),sp_tril(10)])
P, (P1,P2) = createParent([sp_tril(5),sp_dense(3,3)])

obj = MXFunction([X,P],[use A, B, P1, P2 here])

solver = NLPSolver(obj)

my loop:
solver.input(NLP_P)[P2.mapping()] = mynewP2 # Set with a 3x3
solver.evaluate()
print solver.output()[B.mapping()]  # Gives you 10x10 lower triangular

The output aggregation pattern

When to use: