pympcc.solve¶
- pympcc.solve(problem, strategy='scholtes', backend='ipopt', ipopt_options=None, solver_options=None, callback=None, inner_callback=None, time_limit=None, verbose=False, presolve=False, diagnostics=False, autoscale=False, b_stat_max_biactive=10, tnlp_refine=False, tnlp_max_iter=500, n_starts=1, perturb_scale=0.1, multistart_seed=0, n_jobs=1, **strategy_options)[source]¶
Solve an MPCC problem — convenience wrapper around
MPCCSolver.- Parameters:
problem (MPCCProblem) – The MPCC problem instance.
strategy ({'direct', 'scholtes', 'smoothing', 'lin_fukushima', 'augmented_lagrangian', 'slack'}) – Reformulation strategy (default
'scholtes'). SeeMPCCSolverfor a description of each option.backend ({'ipopt', 'filterSQP', 'scipy'}, optional) – NLP backend solver (default
'ipopt').'filterSQP'requires thepyfiltersqppackage and is incompatible withstrategy='slack'.'scipy'usesscipy.optimize.minimizewithmethod='trust-constr'and requires no IPOPT installation.ipopt_options (dict, optional) – IPOPT solver options (merged with package defaults). When
backend='filterSQP'the common keys"tol"and"max_iter"are translated; IPOPT-specific keys are silently ignored.solver_options (dict, optional) – Options forwarded directly to
SQPSolver. Ignored whenbackend='ipopt'.callback (callable, optional) –
f(k: int, info: IterationInfo) -> Nonecalled after each outer iteration. Not called by the'direct'strategy.inner_callback (callable, optional) –
f(iter_count: int, info: dict) -> boolinvoked once per IPOPT inner iteration (every NLP solve, including each outer-loop NLP).infocarries IPOPT’sintermediatearguments (alg_mod,obj_value,inf_pr,inf_du,mu,d_norm,regularization_size,alpha_du,alpha_pr,ls_trials). ReturnFalseto stop the current inner solve early;True(orNone) to continue.verbose (bool, optional) – If
Trueand no callback is provided, prints a formatted progress table to stdout after each outer iteration (defaultFalse).**strategy_options – Additional options for the strategy (e.g.
epsilon_0,reduction,max_iter).time_limit (float | None)
presolve (bool)
diagnostics (bool)
autoscale (bool)
b_stat_max_biactive (int)
tnlp_refine (bool)
tnlp_max_iter (int)
n_starts (int)
perturb_scale (float)
multistart_seed (int)
n_jobs (int)
- Return type:
Examples
Minimal call:
result = pympcc.solve(problem)
Use the filterSQP backend:
result = pympcc.solve(problem, backend='filterSQP')
Print progress after each outer iteration:
result = pympcc.solve(problem, strategy='scholtes', verbose=True)
Custom callback:
def my_cb(k, info): print(f"[{k}] obj={info.obj:.6f} comp={info.comp_residual:.2e}") result = pympcc.solve(problem, strategy='smoothing', callback=my_cb)
Enable verbose IPOPT output:
result = pympcc.solve(problem, ipopt_options={'print_level': 5})