pub struct Solver { /* private fields */ }Expand description
Structure-exploiting convex QP solver.
Implementations§
Source§impl Solver
impl Solver
Sourcepub const fn new(settings: SolverSettings) -> Solver
pub const fn new(settings: SolverSettings) -> Solver
Creates a solver with explicit settings.
Examples found in repository?
9fn main() -> Result<(), Box<dyn Error>> {
10 let mut config = SyntheticConfig::default();
11 let mut settings = SolverSettings::default();
12 let arguments: Vec<String> = env::args().skip(1).collect();
13 let mut index = 0;
14 while index < arguments.len() {
15 let flag = &arguments[index];
16 let value = arguments
17 .get(index + 1)
18 .ok_or_else(|| format!("missing value after {flag}"))?;
19 match flag.as_str() {
20 "--n" => config.assets = value.parse()?,
21 "--k" => config.factors = value.parse()?,
22 "--seed" => config.seed = value.parse()?,
23 "--inequalities" => config.inequalities = value.parse()?,
24 "--alpha" => settings.over_relaxation = value.parse()?,
25 "--polish" => settings.polish = value.parse()?,
26 _ => return Err(format!("unknown argument: {flag}").into()),
27 }
28 index += 2;
29 }
30 config.max_weight = (10.0 / config.assets as f64).min(1.0);
31
32 let instance = generate_synthetic(config)?;
33 let warm_start = WarmStart::from_primal(instance.feasible_reference.clone());
34 let mut runner = BenchmarkRunner::new();
35 runner.add_solver(Box::new(Solver::new(settings)));
36
37 println!("{}", BenchmarkRunner::markdown_header());
38 for record in runner.run(&instance.name, &instance.problem, Some(&warm_start)) {
39 match record {
40 Ok(record) => println!("{}", record.markdown_row()),
41 Err(error) => eprintln!("{error}"),
42 }
43 }
44 Ok(())
45}Sourcepub const fn settings(&self) -> &SolverSettings
pub const fn settings(&self) -> &SolverSettings
Returns the active settings.
Sourcepub fn solve(
&self,
problem: &QpProblem,
warm_start: Option<&WarmStart>,
) -> Result<Solution, SolverError>
pub fn solve( &self, problem: &QpProblem, warm_start: Option<&WarmStart>, ) -> Result<Solution, SolverError>
Solves a convex factor-model QP.
When SolverSettings::scaling_iterations is positive, ADMM iterates
on a Ruiz-equilibrated copy of the data; termination checks and every
value on the returned Solution are evaluated on the original data.
Each call pays equilibration and factorization setup again. For
rolling sequences over a fixed structure, build a Workspace with
Solver::workspace instead.
§Errors
Returns SolverError when the input, settings, warm start, factor
covariance, or reduced linear system is invalid.
Sourcepub fn workspace(&self, problem: &QpProblem) -> Result<Workspace, SolverError>
pub fn workspace(&self, problem: &QpProblem) -> Result<Workspace, SolverError>
Builds a reusable Workspace that caches the equilibration and the
SMW-reduced factorization across solves (roadmap 2.4).
Use it when the problem structure — covariance, constraint matrices, bounds — is fixed and only the linear cost or right-hand sides change between solves, as in rolling rebalances.
§Errors
Returns SolverError when the input, settings, factor covariance,
or reduced linear system is invalid.