Skip to content

Commit

Permalink
fix: Remove unnecessary associated type Error from SolverModel
Browse files Browse the repository at this point in the history
Was set to ResolutionError everywhere
  • Loading branch information
jacobsvante committed Oct 22, 2024
1 parent d4a4942 commit f1adce7
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/solvers/clarabel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ impl ClarabelProblem {

impl SolverModel for ClarabelProblem {
type Solution = ClarabelSolution;
type Error = ResolutionError;

fn solve(self) -> Result<Self::Solution, Self::Error> {
fn solve(self) -> Result<Self::Solution, ResolutionError> {
let mut solver = self.into_solver();
solver.solve();
match solver.solution.status {
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/coin_cbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ impl CoinCbcProblem {

impl SolverModel for CoinCbcProblem {
type Solution = CoinCbcSolution;
type Error = ResolutionError;

fn solve(mut self) -> Result<Self::Solution, Self::Error> {
fn solve(mut self) -> Result<Self::Solution, ResolutionError> {
// Due to a bug in cbc, SOS constraints are only taken into account
// if the model has at least one integer variable.
// See: https://github.com/coin-or/Cbc/issues/376
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/cplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ impl CPLEXProblem {

impl SolverModel for CPLEXProblem {
type Solution = CplexSolved;
type Error = ResolutionError;

fn solve(self) -> Result<Self::Solution, Self::Error> {
fn solve(self) -> Result<Self::Solution, ResolutionError> {
let solution = match self.model.solve_as(if self.has_integer {
ProblemType::MixedInteger
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/highs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ impl HighsProblem {

impl SolverModel for HighsProblem {
type Solution = HighsSolution;
type Error = ResolutionError;

fn solve(mut self) -> Result<Self::Solution, Self::Error> {
fn solve(mut self) -> Result<Self::Solution, ResolutionError> {
let verbose = self.verbose;
let options = std::mem::take(&mut self.options);
let mut model = self.into_inner();
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/lp_solvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ pub struct Model<T> {

impl<T: SolverTrait> SolverModel for Model<T> {
type Solution = LpSolution;
type Error = ResolutionError;

fn solve(self) -> Result<Self::Solution, Self::Error> {
fn solve(self) -> Result<Self::Solution, ResolutionError> {
let map = self.solver.run(&self.problem)?;
match map.status {
Status::Infeasible => return Err(ResolutionError::Infeasible),
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/lpsolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ pub struct LpSolveProblem(Problem);

impl SolverModel for LpSolveProblem {
type Solution = LpSolveSolution;
type Error = ResolutionError;

fn solve(mut self) -> Result<Self::Solution, Self::Error> {
fn solve(mut self) -> Result<Self::Solution, ResolutionError> {
use ResolutionError::*;
match Problem::solve(&mut self.0) {
SolveStatus::Unbounded => Err(Unbounded),
Expand Down
4 changes: 1 addition & 3 deletions src/solvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ impl Error for MipGapError {}
pub trait SolverModel {
/// The type of the solution to the problem
type Solution: Solution;
/// The error that can occur while solving the problem
type Error: std::error::Error;

/// Takes a model and adds a constraint to it
fn with(mut self, constraint: Constraint) -> Self
Expand All @@ -190,7 +188,7 @@ pub trait SolverModel {
}

/// Find the solution for the problem being modeled
fn solve(self) -> Result<Self::Solution, Self::Error>;
fn solve(self) -> Result<Self::Solution, ResolutionError>;

/// Adds a constraint to the Model and returns a reference to the index
fn add_constraint(&mut self, c: Constraint) -> ConstraintReference;
Expand Down
3 changes: 1 addition & 2 deletions src/solvers/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ impl CardinalityConstraintSolver for SCIPProblem {

impl SolverModel for SCIPProblem {
type Solution = SCIPSolved;
type Error = ResolutionError;

fn solve(self) -> Result<Self::Solution, Self::Error> {
fn solve(self) -> Result<Self::Solution, ResolutionError> {
let solved_model = self.model.solve();
let status = solved_model.status();
match status {
Expand Down

0 comments on commit f1adce7

Please sign in to comment.