Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest changes #99

Merged
merged 7 commits into from
Jul 27, 2023
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

## unreleased
### Added
- Primal heuristic plugin
- Primal heuristic plugin.
- Solving Model state, to represent methods accessible when during solving.
- Moved solution query methods to its own trait.
### Fixed
### Changed
- Moved ScipPtr struct and methods to its own module.
### Removed

## 0.2.4
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ use russcip::status::Status;
use russcip::variable::VarType;
use russcip::retcode::Retcode;
use crate::russcip::model::ModelWithProblem;
use crate::russcip::model::ProblemOrSolving;
use crate::russcip::WithSolutions;

fn main() {
// Create model
Expand Down
5 changes: 3 additions & 2 deletions src/branchrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct BranchingCandidate {
mod tests {
use super::*;
use crate::model::{ModelWithProblem, ProblemCreated};
use crate::Solving;
use crate::{model::Model, status::Status};

struct PanickingBranchingRule;
Expand Down Expand Up @@ -135,7 +136,7 @@ mod tests {
}

struct FirstBranchingRule {
model: Model<ProblemCreated>,
model: Model<Solving>,
}

impl BranchRule for FirstBranchingRule {
Expand Down Expand Up @@ -166,7 +167,7 @@ mod tests {
}

struct CustomBranchingRule {
model: Model<ProblemCreated>,
model: Model<Solving>,
}

impl BranchRule for CustomBranchingRule {
Expand Down
148 changes: 76 additions & 72 deletions src/heuristic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ops::{BitOr, BitOrAssign};

use crate::ffi;
use crate::Solution;

/// A trait for defining custom primal heuristics.
pub trait Heuristic {
Expand Down Expand Up @@ -99,10 +98,9 @@ impl From<HeurResult> for u32 {
}
}


#[cfg(test)]
mod tests {
use crate::{Model, ModelWithProblem, ProblemCreated, SolError};
use crate::{Model, ModelWithProblem, ProblemOrSolving, Solving};

use super::*;

Expand All @@ -125,19 +123,20 @@ mod tests {
let heur = NoSolutionFoundHeur;
let mut timing = HeurTiming::BEFORE_PRESOL;
timing |= HeurTiming::AFTER_PROP_LOOP;
model.include_heur(
"no_sol_found_heur",
"",
9999999,
'n',
1,
0,
-1,
timing,
false,
Box::new(heur),
).solve();

model
.include_heur(
"no_sol_found_heur",
"",
9999999,
'n',
1,
0,
-1,
timing,
false,
Box::new(heur),
)
.solve();
}

struct ImpostorHeur;
Expand All @@ -151,28 +150,29 @@ mod tests {
#[test]
#[should_panic]
fn impostor_heur() {
let model = Model::new()
let model = Model::new()
.hide_output()
.include_default_plugins()
.read_prob("data/test/simple.lp")
.unwrap();

let heur = ImpostorHeur;
model.include_heur(
"impostor_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE | HeurTiming::AFTER_LP_NODE,
false,
Box::new(heur),
).solve();
model
.include_heur(
"impostor_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE | HeurTiming::AFTER_LP_NODE,
false,
Box::new(heur),
)
.solve();
}


struct DelayedHeur;

impl Heuristic for DelayedHeur {
Expand All @@ -181,7 +181,6 @@ mod tests {
}
}


#[test]
fn delayed_heur() {
let model = Model::new()
Expand All @@ -191,21 +190,22 @@ mod tests {
.unwrap();

let heur = DelayedHeur;
model.include_heur(
"delayed_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE,
false,
Box::new(heur),
).solve();
model
.include_heur(
"delayed_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE,
false,
Box::new(heur),
)
.solve();
}


struct DidNotRunHeur;

impl Heuristic for DidNotRunHeur {
Expand All @@ -223,23 +223,24 @@ mod tests {
.unwrap();

let heur = DidNotRunHeur;
model.include_heur(
"did_not_run_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE,
false,
Box::new(heur),
).solve();
model
.include_heur(
"did_not_run_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE,
false,
Box::new(heur),
)
.solve();
}


struct FoundSolHeur {
model: Model<ProblemCreated>,
model: Model<Solving>,
}

impl Heuristic for FoundSolHeur {
Expand All @@ -254,7 +255,6 @@ mod tests {
}
}


#[test]
fn found_sol_heur() {
let model = Model::new()
Expand All @@ -263,18 +263,22 @@ mod tests {
.read_prob("data/test/simple.lp")
.unwrap();

let heur = FoundSolHeur { model: model.clone_for_plugins() };
model.include_heur(
"found_sol_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE,
false,
Box::new(heur),
).solve();
let heur = FoundSolHeur {
model: model.clone_for_plugins(),
};
model
.include_heur(
"found_sol_heur",
"",
9999999,
'n',
1,
0,
-1,
HeurTiming::BEFORE_NODE,
false,
Box::new(heur),
)
.solve();
}
}
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
//! use russcip::model::ObjSense;
//! use russcip::status::Status;
//! use russcip::variable::VarType;
//! use crate::russcip::model::ProblemOrSolving;
//! use crate::russcip::model::ModelWithProblem;
//!
//! use crate::russcip::WithSolutions;
//!
//! // Create model
//! let mut model = Model::new()
Expand Down Expand Up @@ -94,6 +95,8 @@ pub use eventhdlr::*;
pub mod heuristic;
pub use heuristic::*;

mod scip;

/// A macro for calling a `SCIP` function and returning an error if the return code is not `SCIP_OKAY`.
#[macro_export]
macro_rules! scip_call {
Expand Down
Loading
Loading