[−][src]Crate cplex_sys
Low-level binding for Cplex
This crate provides automatically generated low-level bindings to Cplex. The build script scans the C-header files and creates appropriate functions and constants.
In order to compile this crate, the environment variable CPLEX_HOME
must be set to a path containing cplex, e.g.
export CPLEX_HOME=/opt/CPLEX_Studio1271/cplex
cargo build
(That path should contain the header files in include/ilcplex
and the library
in lib/x86-64_linux
).
Note that this is really low-level. The functions are just plain bindings to the C-API without any additional safe guards.
Example
#[macro_use] extern crate cplex_sys as cpx; use std::os::raw::{c_char, c_int}; use std::ffi::CString; use std::ptr::null; fn main() { let mut status = 0; let mut env = unsafe { cpx::openCPLEX(&mut status) }; assert_eq!(status, 0); let mut lp = unsafe { cpx::createprob(env, &mut status, CString::new("Test LP").unwrap().as_ptr()) }; assert_eq!(status, 0); let obj = [1.0, 2.0, 3.0]; let ub = [40.0, cpx::INFBOUND, cpx::INFBOUND]; let rmatbeg = [0, 3]; let rmatind = [0, 1, 2, 0, 1, 2]; let rmatval = [-1.0, 1.0, 1.0, 1.0, -3.0, 1.0]; let sense = ['L' as c_char, 'L' as c_char]; let rhs = [20.0, 30.0]; unwrapcpx!(cpx::newcols(env, lp, 3, obj.as_ptr(), null(), ub.as_ptr(), null(), null())); unwrapcpx!(cpx::addrows(env, lp, 0, 2, rmatval.len() as c_int, rhs.as_ptr(), sense.as_ptr(), rmatbeg.as_ptr(), rmatind.as_ptr(), rmatval.as_ptr(), null(), null())); unwrapcpx!(cpx::chgobjsen(env, lp, cpx::MAX)); unwrapcpx!(cpx::lpopt(env, lp)); let mut x = [0.0; 3]; let mut objval = 0.0; unwrapcpx!(cpx::getobjval(env, lp, &mut objval)); unwrapcpx!(cpx::getx(env, lp, x.as_mut_ptr(), 0, 2)); assert!((objval - 202.5).abs() < 1e-9); assert!((x[0] - 40.0).abs() < 1e-9); assert!((x[1] - 17.5).abs() < 1e-9); assert!((x[2] - 42.5).abs() < 1e-9); unwrapcpx!(cpx::freeprob(env, &mut lp)); unwrapcpx!(cpx::closeCPLEX(&mut env)); }
Macros
trycpx | Wrapper around CPLEX low-level functions returning a status code. |
unwrapcpx | Wrapper around CPLEX low-level functions returning a status code. |
Structs
CplexError | Error describing a CPLEX status code. |
Enums
Alg | |
CallbackContext | |
CallbackInfo | |
CallbackSolutionStrategy | |
Channel | |
Deserializer | |
Env | |
File | |
InfoType | |
Lp | |
Net | |
ObjectiveSense | Objective sense of the problem. |
Param | |
Serializer | |
Stat |