Skip to content

Commit

Permalink
Merge pull request #27 from scipopt/fix-macos-bundled
Browse files Browse the repository at this point in the history
Fix macos bundled link & improve tested example
  • Loading branch information
mmghannam authored Feb 8, 2025
2 parents c0bcc0d + aa8869f commit a795106
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
os: [
ubuntu-latest,
macos-latest,
macos-13,
macos-14, # macOS arm runner
windows-latest,
]
Expand All @@ -32,7 +32,7 @@ jobs:
matrix:
os: [
ubuntu-latest,
macos-latest,
macos-13,
macos-14, # macOS arm runner
windows-latest,
]
Expand All @@ -49,7 +49,7 @@ jobs:
strategy:
matrix:
os: [
macos-latest,
macos-13,
macos-14,
ubuntu-latest,
windows-latest,
Expand All @@ -58,7 +58,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install bison
if: ${{ matrix.os == 'macos-latest' || matrix.os == 'macos-14' }}
if: ${{ matrix.os == 'macos-13' || matrix.os == 'macos-14' }}
run: |
brew install bison gcc
- name: Test from-source
Expand Down
2 changes: 1 addition & 1 deletion bundled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn download_scip() {
let os_string = if os == "linux" && arch == "x86_64" {
"linux"
} else if os == "macos" && arch == "x86_64" {
"macos"
"macos-intel"
} else if os == "macos" && arch == "aarch64" {
"macos-arm"
} else if os == "windows" && arch == "x86_64" {
Expand Down
50 changes: 48 additions & 2 deletions examples/create.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
use scip_sys::{SCIPcreate, SCIPfree, SCIPprintVersion};
use scip_sys::*;
use std::mem::MaybeUninit;

fn main() {
let mut scip_ptr = MaybeUninit::uninit();
unsafe { SCIPcreate(scip_ptr.as_mut_ptr()) };
let mut scip_ptr = unsafe { scip_ptr.assume_init() };
unsafe { SCIPprintVersion(scip_ptr, std::ptr::null_mut()) };

// include default plugins
unsafe { SCIPincludeDefaultPlugins(scip_ptr) };

unsafe { SCIPcreateProbBasic(scip_ptr, "test".as_ptr() as *const i8) };

// add a variable
let mut var_ptr = MaybeUninit::uninit();
unsafe {
SCIPcreateVarBasic(
scip_ptr,
var_ptr.as_mut_ptr(),
"x".as_ptr() as *const i8,
0.0,
1.0,
1.0,
SCIP_Vartype_SCIP_VARTYPE_BINARY,
)
};
let mut var_ptr = unsafe { var_ptr.assume_init() };
unsafe { SCIPaddVar(scip_ptr, var_ptr) };

// add a constraint
let mut cons_ptr = MaybeUninit::uninit();
unsafe {
SCIPcreateConsBasicLinear(
scip_ptr,
cons_ptr.as_mut_ptr(),
"c".as_ptr() as *const i8,
1,
&mut var_ptr,
&mut 1.0,
1.0,
1.0,
)
};
let mut cons_ptr = unsafe { cons_ptr.assume_init() };
unsafe { SCIPaddCons(scip_ptr, cons_ptr) };

unsafe { SCIPsolve(scip_ptr) };

let obj_val = unsafe { SCIPgetPrimalbound(scip_ptr) };
let eps = unsafe { SCIPfeastol(scip_ptr) };
assert!((obj_val - 1.0).abs() < eps);

unsafe { SCIPreleaseVar(scip_ptr, &mut var_ptr) };
unsafe { SCIPreleaseCons(scip_ptr, &mut cons_ptr) };
unsafe { SCIPfree(&mut scip_ptr) };
}
2 changes: 1 addition & 1 deletion from_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ pub fn compile_scip(source_path: PathBuf) -> PathBuf {
}

#[cfg(not(feature = "from-source"))]
pub fn compile_scip(source_path: PathBuf) -> PathBuf {
pub fn compile_scip(_source_path: PathBuf) -> PathBuf {
unimplemented!("Cannot compile SCIP without the `from-source` feature")
}
47 changes: 47 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@ mod tests {
let mut scip_ptr = MaybeUninit::uninit();
unsafe { SCIPcreate(scip_ptr.as_mut_ptr()) };
let mut scip_ptr = unsafe { scip_ptr.assume_init() };

// include default plugins
unsafe { SCIPincludeDefaultPlugins(scip_ptr) };

unsafe { SCIPcreateProbBasic(scip_ptr, "test".as_ptr() as *const i8) };

// add a variable
let mut var_ptr = MaybeUninit::uninit();
unsafe {
SCIPcreateVarBasic(
scip_ptr,
var_ptr.as_mut_ptr(),
"x".as_ptr() as *const i8,
0.0,
1.0,
1.0,
SCIP_Vartype_SCIP_VARTYPE_BINARY,
)
};
let mut var_ptr = unsafe { var_ptr.assume_init() };
unsafe { SCIPaddVar(scip_ptr, var_ptr) };

// add a constraint
let mut cons_ptr = MaybeUninit::uninit();
unsafe {
SCIPcreateConsBasicLinear(
scip_ptr,
cons_ptr.as_mut_ptr(),
"c".as_ptr() as *const i8,
1,
&mut var_ptr,
&mut 1.0,
1.0,
1.0,
)
};
let mut cons_ptr = unsafe { cons_ptr.assume_init() };
unsafe { SCIPaddCons(scip_ptr, cons_ptr) };

unsafe { SCIPsolve(scip_ptr) };

let obj_val = unsafe { SCIPgetPrimalbound(scip_ptr) };
let eps = unsafe { SCIPfeastol(scip_ptr) };
assert!((obj_val - 1.0).abs() < eps);

unsafe { SCIPreleaseVar(scip_ptr, &mut var_ptr) };
unsafe { SCIPreleaseCons(scip_ptr, &mut cons_ptr) };
unsafe { SCIPfree(&mut scip_ptr) };
}
}

0 comments on commit a795106

Please sign in to comment.