maptor.solver#
Functions for solving optimal control problems.
- maptor.solver.solve_fixed_mesh(problem, nlp_options=None, show_summary=True)[source]#
Solve optimal control problem using fixed pseudospectral meshes.
Solves the problem using the exact mesh configuration specified in each phase without adaptive refinement. Provides direct control over mesh discretization for computational efficiency or specific accuracy requirements.
- Return type:
- Parameters:
- Args:
problem: Configured Problem instance with mesh, dynamics, and objective nlp_options: IPOPT solver options with full customization:
Any IPOPT option as “ipopt.option_name”: value
show_summary: Whether to display solution summary (default: True)
- Returns:
Solution: Optimization results with trajectories and solver diagnostics
- Examples:
Basic usage:
>>> solution = mtor.solve_fixed_mesh(problem)
Custom solver options:
>>> solution = mtor.solve_fixed_mesh( ... problem, ... nlp_options={ ... "ipopt.print_level": 5, # Verbose output ... "ipopt.max_iter": 1000, # Iteration limit ... "ipopt.tol": 1e-6 # Tolerance ... } ... )
High-accuracy solver settings:
>>> solution = mtor.solve_fixed_mesh( ... problem, ... nlp_options={ ... "ipopt.tol": 1e-10, ... "ipopt.constr_viol_tol": 1e-9, ... "ipopt.hessian_approximation": "exact" ... } ... )
Linear solver options:
>>> solution = mtor.solve_fixed_mesh( ... problem, ... nlp_options={ ... "ipopt.linear_solver": "mumps", ... "ipopt.mumps_mem_percent": 50000 ... } ... )
Silent solving:
>>> solution = mtor.solve_fixed_mesh( ... problem, ... nlp_options={"ipopt.print_level": 0}, ... show_summary=False ... )
- maptor.solver.solve_adaptive(problem, error_tolerance=1e-06, max_iterations=30, min_polynomial_degree=3, max_polynomial_degree=8, ode_solver_tolerance=1e-06, ode_method='RK45', ode_max_step=None, ode_atol_factor=1e-08, num_error_sim_points=50, ode_solver=None, nlp_options=None, show_summary=True)[source]#
Solve optimal control problem using adaptive mesh refinement.
Automatically refines mesh until target error tolerance is achieved across all phases. Provides high-accuracy solutions with computational efficiency through adaptive polynomial degree and interval refinement.
- Return type:
- Parameters:
problem (Problem)
error_tolerance (float)
max_iterations (int)
min_polynomial_degree (int)
max_polynomial_degree (int)
ode_solver_tolerance (float)
ode_method (str)
ode_max_step (float | None)
ode_atol_factor (float)
num_error_sim_points (int)
ode_solver (Callable[[...], ODESolverResult] | None)
show_summary (bool)
- Args:
problem: Configured Problem instance with initial mesh configurations
- error_tolerance: Target relative error tolerance with ranges:
1e-3: Coarse accuracy, fast solving
1e-6: Standard accuracy (default)
1e-9: High accuracy, slower convergence
- max_iterations: Maximum refinement iterations:
5-10: Standard problems
15-25: Complex problems
30+: Very challenging problems (default: 30)
- min_polynomial_degree: Minimum polynomial degree per interval:
3: Fast, lower accuracy (default)
4-5: Balanced accuracy/speed
6+: High accuracy start
- max_polynomial_degree: Maximum polynomial degree per interval:
8-10: Standard limit (default: 10)
12-15: High accuracy problems
20+: Very smooth solutions only
- ode_solver_tolerance: ODE integration tolerance for error estimation:
1e-6: Standard (default)
1e-9: High accuracy error estimation
1e-5: Faster, less accurate
- ode_method: ODE integration method options:
“RK45”: Runge-Kutta 4(5) (default)
“RK23”: Runge-Kutta 2(3)
“DOP853”: Dormand-Prince 8(5,3)
“LSODA”: Automatic stiff/non-stiff
“Radau”: Implicit Runge-Kutta
- ode_max_step: Maximum ODE step size:
None: Automatic (default)
float: Fixed maximum step
- ode_atol_factor: Absolute tolerance factor (atol = rtol * factor):
1e-8 (default)
- num_error_sim_points: Points for error simulation:
30-50: Standard (default: 50)
100+: High-resolution error estimation
- ode_solver: Custom ODE solver function:
None: Use scipy.solve_ivp (default)
Callable: Custom solver implementation
nlp_options: IPOPT options for each NLP solve (same as solve_fixed_mesh)
show_summary: Display solution summary (default: True)
- Returns:
Solution: High-accuracy adaptive solution with refinement diagnostics
- Examples:
Basic adaptive solving:
>>> solution = mtor.solve_adaptive(problem)
High-accuracy solving:
>>> solution = mtor.solve_adaptive( ... problem, ... error_tolerance=1e-8, ... max_iterations=20, ... max_polynomial_degree=15 ... )
Fast approximate solving:
>>> solution = mtor.solve_adaptive( ... problem, ... error_tolerance=1e-3, ... max_iterations=5, ... min_polynomial_degree=3, ... max_polynomial_degree=6 ... )
Custom ODE solver settings:
>>> solution = mtor.solve_adaptive( ... problem, ... ode_method="LSODA", ... ode_solver_tolerance=1e-9, ... num_error_sim_points=100 ... )
Complex problem settings:
>>> solution = mtor.solve_adaptive( ... problem, ... error_tolerance=1e-6, ... max_iterations=30, ... min_polynomial_degree=4, ... max_polynomial_degree=12, ... nlp_options={ ... "ipopt.max_iter": 3000, ... "ipopt.tol": 1e-8, ... "ipopt.linear_solver": "mumps" ... } ... )
Override initial guess:
>>> custom_guess = MultiPhaseInitialGuess(...) >>> solution = mtor.solve_adaptive( ... problem, ... initial_guess=custom_guess ... )
Silent adaptive solving:
>>> solution = mtor.solve_adaptive( ... problem, ... nlp_options={"ipopt.print_level": 0}, ... show_summary=False ... )
Polynomial degree ranges:
>>> # Conservative polynomial progression >>> solution = mtor.solve_adaptive( ... problem, ... min_polynomial_degree=3, ... max_polynomial_degree=8 ... ) >>> >>> # Aggressive high-accuracy >>> solution = mtor.solve_adaptive( ... problem, ... min_polynomial_degree=6, ... max_polynomial_degree=20 ... )
Error tolerance ranges:
>>> # Quick verification >>> solution = mtor.solve_adaptive(problem, error_tolerance=1e-3) >>> # Production accuracy >>> solution = mtor.solve_adaptive(problem, error_tolerance=1e-6) >>> # Research accuracy >>> solution = mtor.solve_adaptive(problem, error_tolerance=1e-9)