pub(crate) const LP_SOLVER_DEBUG: bool = false;
#[macro_export]
macro_rules! lp_debug {
($($arg:tt)*) => {
if $crate::lpsolver::LP_SOLVER_DEBUG {
eprintln!($($arg)*);
}
};
}
pub mod types;
pub mod matrix;
pub mod lu;
pub mod basis;
pub mod simplex_primal;
pub mod simplex_dual;
pub mod csp_integration;
pub use types::{LpProblem, LpSolution, LpStatus, LpError, LpConfig};
pub use matrix::Matrix;
pub use csp_integration::{
LinearConstraintSystem, LinearConstraint, ConstraintRelation, LinearObjective,
apply_lp_solution,
};
pub fn solve(problem: &LpProblem) -> Result<LpSolution, LpError> {
solve_with_config(problem, &LpConfig::default())
}
pub fn solve_with_config(problem: &LpProblem, config: &LpConfig) -> Result<LpSolution, LpError> {
problem.validate()?;
let mut solver = simplex_primal::PrimalSimplex::new(config.clone());
solver.solve(problem)
}
pub fn solve_warmstart(
problem: &LpProblem,
previous: &LpSolution,
config: &LpConfig,
) -> Result<LpSolution, LpError> {
problem.validate()?;
let mut problem_warmstart = problem.clone();
problem_warmstart.basic_indices = Some(previous.basic_indices.clone());
let mut solver = simplex_dual::DualSimplex::new(config.clone());
solver.solve(&problem_warmstart)
}