russcip/lib.rs
1//! # russcip
2//! Safe Rust interface for [SCIP](https://scipopt.org/) optimization suite.
3//!
4//! For usage, please refer to the [README](https://github.com/scipopt/russcip).
5//!
6//! # Example
7//! ```rust
8//! use russcip::prelude::*;
9//!
10//! let mut model = Model::default().minimize();
11//! let x = model.add(var().bin().obj(1.0));
12//! let y = model.add(var().bin().obj(2.0));
13//! model.add(cons().coef(&x, 1.0).coef(&y, 1.0).eq(1.0));
14//!
15//! let solved = model.solve();
16//! assert_eq!(solved.status(), Status::Optimal);
17//! assert_eq!(solved.obj_val(), 1.0);
18//! ```
19
20#![deny(missing_docs)]
21#![allow(clippy::macro_metavars_in_unsafe)]
22extern crate core;
23
24/// Re-exports the `scip_sys` crate, which provides low-level bindings to the SCIP library.
25pub use scip_sys as ffi;
26
27/// Contains the `BranchRule` trait used to define custom branching rules.
28pub mod branchrule;
29pub use branchrule::*;
30
31/// Contains the `Constraint` struct, which represents a constraint in an optimization problem.
32pub mod constraint;
33pub use constraint::*;
34
35/// The main module, it contains the `Model` struct, which represents an optimization problem.
36pub mod model;
37pub use model::*;
38
39/// Contains the `Pricer` trait used to define custom variable pricing strategies.
40pub mod pricer;
41pub use pricer::*;
42
43/// Contains the `Retcode` enum, which represents the return codes of SCIP functions.
44pub mod retcode;
45pub use retcode::*;
46
47/// Contains the `Solution` struct, which represents a solution to an optimization problem.
48pub mod solution;
49pub use solution::*;
50
51/// Contains the `Status` enum, which represents the status of an optimization problem.
52pub mod status;
53pub use status::*;
54
55/// Contains the `Variable` struct, which represents a variable in an optimization problem.
56pub mod variable;
57pub use variable::*;
58
59/// Contains the `Node` struct, which represents a node in the branch-and-bound tree.
60pub mod node;
61pub use node::*;
62
63/// Contains the `EventHdlr` trait used to define custom event handlers.
64pub mod eventhdlr;
65pub use eventhdlr::*;
66
67/// Contains the `Heur` trait used to define custom primal heuristics.
68pub mod heuristic;
69pub use heuristic::*;
70
71/// Contains the `Separator` trait used to define custom separation routines.
72pub mod separator;
73pub use separator::*;
74
75/// Contains all the traits and structs that are re-exported by default.
76pub mod prelude;
77
78mod scip;
79
80/// Contains the `Col` struct, which represents a column in an LP relaxation.
81pub mod col;
82pub use col::*;
83
84mod param;
85/// Contains the `Row` struct, which represents a row in an LP relaxation.
86pub mod row;
87
88/// Contains methods for creating scip objects in an ergonomic way.
89pub mod builder;
90
91/// Contains the `Conshdlr` trait used to define custom constraint handlers.
92pub mod conshdlr;
93mod diving;
94mod probing;
95
96pub use conshdlr::*;
97pub use diving::*;
98
99pub use row::*;
100
101/// A macro for calling a `SCIP` function and returning an error if the return code is not `SCIP_OKAY`.
102#[macro_export]
103macro_rules! scip_call {
104 ($res:expr) => {
105 let res = unsafe { $res };
106 let retcode = $crate::retcode::Retcode::from(res);
107 if retcode != $crate::retcode::Retcode::Okay {
108 return Err(retcode);
109 }
110 };
111}
112
113/// A macro for calling a `SCIP` function and panicking if the return code is not `SCIP_OKAY`.
114#[macro_export]
115macro_rules! scip_call_panic {
116 ($res:expr) => {
117 let res = unsafe { $res };
118 let retcode = $crate::retcode::Retcode::from(res);
119 if retcode != $crate::retcode::Retcode::Okay {
120 panic!("SCIP call failed with retcode {:?}", retcode);
121 }
122 };
123}
124
125/// A macro for calling a `SCIP` function and panicking with a custom message if the return code is not `SCIP_OKAY`.
126#[macro_export]
127macro_rules! scip_call_expect {
128 ($res:expr, $msg:expr) => {
129 let res = unsafe { $res };
130 let retcode = $crate::retcode::Retcode::from(res);
131 if retcode != $crate::retcode::Retcode::Okay {
132 panic!("{} - SCIP call failed with retcode {:?}", $msg, retcode);
133 }
134 };
135}