Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ minilp = [

[dependencies]
coin_cbc = { version = "0.1", optional = true, default-features = false }
microlp = { version = "0.3.1", optional = true }
microlp = { version = "0.4.0", optional = true }
lpsolve = { version = "1.0.1", optional = true }
highs = { version = "2.0.0", optional = true }
russcip = { version = "0.9.1", optional = true }
Expand Down
23 changes: 19 additions & 4 deletions src/solvers/microlp.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//! A solver that uses [microlp](https://docs.rs/microlp), a pure rust solver.

use microlp::Error;
use std::time::Duration;

use microlp::{Error, StopReason};

use crate::variable::{UnsolvedProblem, VariableDefinition};
use crate::{
constraint::ConstraintReference,
solvers::{ObjectiveDirection, ResolutionError, Solution, SolutionStatus, SolverModel},
solvers::{
ObjectiveDirection, ResolutionError, Solution, SolutionStatus, SolverModel, WithTimeLimit,
},
};
use crate::{Constraint, Variable};

Expand Down Expand Up @@ -63,6 +67,14 @@ impl MicroLpProblem {
}
}

impl WithTimeLimit for MicroLpProblem {
fn with_time_limit<T: Into<f64>>(mut self, seconds: T) -> Self {
self.problem
.set_time_limit(Duration::from_secs_f64(seconds.into()));
self
}
}

impl SolverModel for MicroLpProblem {
type Solution = MicroLpSolution;
type Error = ResolutionError;
Expand Down Expand Up @@ -102,7 +114,6 @@ impl From<microlp::Error> for ResolutionError {
microlp::Error::Unbounded => Self::Unbounded,
microlp::Error::Infeasible => Self::Infeasible,
microlp::Error::InternalError(s) => Self::Str(s),
microlp::Error::Limit => Self::Other("Execution Limit reached"),
}
}
}
Expand All @@ -122,7 +133,11 @@ impl MicroLpSolution {

impl Solution for MicroLpSolution {
fn status(&self) -> SolutionStatus {
SolutionStatus::Optimal
let solution_kind = self.solution.stop_reason();
match solution_kind {
StopReason::Finished => SolutionStatus::Optimal,
StopReason::Limit => SolutionStatus::TimeLimit,
}
}
fn value(&self, variable: Variable) -> f64 {
self.solution.var_value(self.variables[variable.index()])
Expand Down