Skip to content

Commit

Permalink
Bundled feature (#127)
Browse files Browse the repository at this point in the history
* Bundled feature

* Add bundled scip tests

* Add example as file instead of including in README

* Set scip-sys version back

* Move bundled ci tests to scip-sys

* Cargo fmt

* Update scip-sys to 0.1.8
  • Loading branch information
mmghannam authored Mar 10, 2024
1 parent a7615c8 commit c2942fb
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 128 deletions.
46 changes: 2 additions & 44 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
toolchain: stable
override: true

- name: Run cargo-tarpaulin
uses: actions-rs/[email protected]
with:
Expand Down Expand Up @@ -129,46 +129,4 @@ jobs:
components: clippy
- uses: Swatinem/rust-cache@v2
- name: Check Clippy Linter
run: cargo clippy --all-features --all-targets -- -D warnings

# TODO: move to scip-sys repo
# MacOS-test:
# runs-on: macos-latest
# steps:
# - uses: actions/checkout@v2
#
# - name: Cache dependencies (SCIPOptSuite)
# id: cache-scip
# uses: actions/cache@v2
# with:
# path: |
# ${{ runner.workspace }}/scipoptsuite
# ~/Library/Caches/Homebrew/tbb--*
# /usr/local/opt/tbb*
# ~/Library/Caches/Homebrew/downloads/*--tbb-*
# ~/Library/Caches/Homebrew/boost--*
# /usr/local/opt/boost*
# ~/Library/Caches/Homebrew/downloads/*--boost-*
# key: ${{ runner.os }}-scipopt-${{ env.version }}-${{ hashFiles('**/lockfiles') }}
# restore-keys: |
# ${{ runner.os }}-scipopt-${{ env.version }}-
#
# - name: Install dependencies (SCIPOptSuite)
# if: steps.cache-scip.outputs.cache-hit != 'true'
# run: |
# brew install tbb boost bison
# wget --quiet --no-check-certificate https://scipopt.org/download/release/scipoptsuite-${{ env.version }}.tgz
# tar xfz scipoptsuite-${{ env.version }}.tgz
# cd scipoptsuite-${{ env.version }}
# mkdir build
# cd build
# cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${{ runner.workspace }}/scipoptsuite -DIPOPT=off -DSYM=none -DTPI=tny -DREADLINE=off
# make install -j
#
# - name: Build and test
# run: |
# brew install tbb boost bison
# export SCIPOPTDIR=${{ runner.workspace }}/scipoptsuite/
# export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:${{ runner.workspace }}/scipoptsuite/lib
# cargo build
# cargo test
run: cargo clippy --all-features --all-targets -- -D warnings
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Added
- Add support for indicator constraints
- Added method `set_memory_limit` to allow specifying a memory limit.
- Added `bundled` feature to download a precompiled binary for the user's OS and architecture.
### Fixed
- Fixed Windows MSVC build.
### Changed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ exclude = ["data/test/*"]

[features]
raw = []
bundled = ["scip-sys/bundled"]

[dependencies]
scip-sys = "0.1.5"
doc-comment = "0.3.3"
scip-sys = "0.1.8"

[dev-dependencies]
rayon = "1.5.1"
Expand Down
62 changes: 19 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,42 @@
[img_coverage]: https://img.shields.io/codecov/c/github/scipopt/russcip

A safe Rust interface for [SCIP](https://www.scipopt.org/index.php#download). This crate also exposes access to the SCIP's C-API through the `ffi` module.
The project is currently actively developed, issues/pull-requests are very welcome.
## Dependencies
Make sure SCIP is installed, the easiest way to install it is to install a precompiled package from [here](https://scipopt.org/index.php#download) or through conda by running
```bash
conda install --channel conda-forge scip
```
After which `russcip` would be able to find the installation in the current Conda environment. Alternatively, you can specify the installation directory through the `SCIPOPTDIR` environment variable.

*russcip* is tested against SCIP 8.0.3 but it might work for other versions depending on which functionality you use.
The project is currently actively developed, issues/pull-requests are very welcome.

## Installation
By running
```bash
cargo add russcip
cargo add russcip --features bundled
```
or to get the most recent version, add the following to your `Cargo.toml`
```toml
[dependencies]
russcip = { git = "https://github.com/scipopt/russcip" }
russcip = { git = "https://github.com/scipopt/russcip", features = ["bundled"] }
```

## Example
Model and solve an integer program.
```rust
use russcip::prelude::*;

fn main() {
// Create model
let mut model = Model::new()
.hide_output()
.include_default_plugins()
.create_prob("test")
.set_obj_sense(ObjSense::Maximize);

// Add variables
let x1 = model.add_var(0., f64::INFINITY, 3., "x1", VarType::Integer);
let x2 = model.add_var(0., f64::INFINITY, 4., "x2", VarType::Integer);

// Add constraints
model.add_cons(vec![x1.clone(), x2.clone()], &[2., 1.], -f64::INFINITY, 100., "c1");
model.add_cons(vec![x1.clone(), x2.clone()], &[1., 2.], -f64::INFINITY, 80., "c2");
The `bundled` feature will download a precompiled SCIP as part of the build process.
This is the easiest to get started with russcip, if you want to use a custom SCIP installation check the [section](#custom-scip-installation) below.

let solved_model = model.solve();

let status = solved_model.status();
println!("Solved with status {:?}", status);

let obj_val = solved_model.obj_val();
println!("Objective value: {}", obj_val);
## Custom SCIP installation
If the `bundled` feature is not enabled, `russcip` will look for a scip installation in the current conda environment,
to install SCIP using conda run the following command
```bash
conda install --channel conda-forge scip
```
Alternatively, you can specify the installation directory through the `SCIPOPTDIR` environment variable.

let sol = solved_model.best_sol().unwrap();
let vars = solved_model.vars();
*russcip* is tested against SCIP 9.0.0 but it might work for other versions depending on which functionality you use.

for var in vars {
println!("{} = {}", &var.name(), sol.val(var));
}
}

### Examples
An [example](examples/create_and_solve.rs) on how to model and solve an integer program can be found in the [examples](examples) directory.
To run the example, you can use the following command
```bash
cargo run --example create_and_solve
```


## The `raw` feature
You can enable this feature by specifying the feature in your `Cargo.toml`
```toml
Expand Down
45 changes: 45 additions & 0 deletions examples/create_and_solve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use russcip::prelude::*;

fn main() {
// Create model
let mut model = Model::new()
.hide_output()
.include_default_plugins()
.create_prob("test")
.set_obj_sense(ObjSense::Maximize);

// Add variables
let x1 = model.add_var(0., f64::INFINITY, 3., "x1", VarType::Integer);
let x2 = model.add_var(0., f64::INFINITY, 4., "x2", VarType::Integer);

// Add constraints
model.add_cons(
vec![x1.clone(), x2.clone()],
&[2., 1.],
-f64::INFINITY,
100.,
"c1",
);
model.add_cons(
vec![x1.clone(), x2.clone()],
&[1., 2.],
-f64::INFINITY,
80.,
"c2",
);

let solved_model = model.solve();

let status = solved_model.status();
println!("Solved with status {:?}", status);

let obj_val = solved_model.obj_val();
println!("Objective value: {}", obj_val);

let sol = solved_model.best_sol().unwrap();
let vars = solved_model.vars();

for var in vars {
println!("{} = {}", &var.name(), sol.val(var));
}
}
41 changes: 2 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,10 @@
//! # russcip
//! Safe Rust interface for SCIP.
//! Safe Rust interface for [SCIP](https://scipopt.org/) optimization suite.
//!
//! # Example
//! Model and solve an integer program.
//! ```rust
//! use russcip::prelude::*;
//!
//! // Create model
//! let mut model = Model::new()
//! .hide_output()
//! .include_default_plugins()
//! .create_prob("test")
//! .set_obj_sense(ObjSense::Maximize);
//!
//! // Add variables
//! let x1 = model.add_var(0., f64::INFINITY, 3., "x1", VarType::Integer);
//! let x2 = model.add_var(0., f64::INFINITY, 4., "x2", VarType::Integer);
//!
//! // Add constraints
//! model.add_cons(vec![x1.clone(), x2.clone()], &[2., 1.], -f64::INFINITY, 100., "c1");
//! model.add_cons(vec![x1.clone(), x2.clone()], &[1., 2.], -f64::INFINITY, 80., "c2");
//!
//! let solved_model = model.solve();
//!
//! let status = solved_model.status();
//! println!("Solved with status {:?}", status);
//!
//! let obj_val = solved_model.obj_val();
//! println!("Objective value: {}", obj_val);
//!
//! let sol = solved_model.best_sol().expect("No solution found");
//! let vars = solved_model.vars();
//!
//! for var in vars {
//! println!("{} = {}", &var.name(), sol.val(var));
//! }
//! For examples and usage, please refer to the [repository](https://github.com/scipopt/russcip).

#![deny(missing_docs)]

extern crate core;
extern crate doc_comment;
doc_comment::doctest!("../README.md");

/// Re-exports the `scip_sys` crate, which provides low-level bindings to the SCIP library.
pub use scip_sys as ffi;

Expand Down

0 comments on commit c2942fb

Please sign in to comment.