Struct grb::AsyncModel [−][src]
pub struct AsyncModel(_);
A wrapper around Model
that supports async optimisation in the background.
From the Gurobi manual, regarding solving models asynchronously:
“[modifying or performing non-permitted] calls on the running model, or on any other models that were built within the same Gurobi environment,
will fail with error code OPTIMIZATION_IN_PROGRESS
.”
For this reason, creating an AsyncModel
requires a Model
whose Env
wasn’t previously been used to construct other models.
Model
implements From<AsyncModel>
, so you can recover the Model
using .into()
(see examples).
Implementations
impl AsyncModel
[src]
pub fn new(model: Model) -> AsyncModel
[src]
Panics
This function will panic if the model
does not have sole ownership over its Env
. This means
the Model
cannot be created with Model::new
, instead you must use Model::with_env
.
Examples
This example panics because env
has two references - inside m
and the bound variable in the current scope
use grb::prelude::*; use grb::AsyncModel; let env = Env::new("")?; let mut m = Model::with_env("model", &env)?; let mut m = AsyncModel::new(m); // panic - env is still in scope
This is easily resolved by ensuring env
is no longer in scope when the AsyncModel
is created.
let mut m = Model::with_env("model", &env)?; drop(env); let mut m = AsyncModel::new(m); // ok
You can also pass an owned Env
to Model::with_env
:
let mut m = Model::with_env("model", env)?; let mut m = AsyncModel::new(m); // also ok
This example panics because m
uses the default Env
, which is also stored globally.
Model
s created with Model::new
can never be made into AsyncModel
s for this reason.
let m = Model::new("model1")?; let m = AsyncModel::new(m); // panic
pub fn optimize(self) -> Result<AsyncHandle, (Self, Error)>
[src]
Optimize the model on another thread. This method will always trigger a Model::update
on the underlying Model
.
On success, returns an AsyncHandle
that provides a limited API for model queries.
The AsyncModel
can be retrieved by calling AsyncHandle::join
.
Errors
An grb::Error::FromAPI
may occur. In this case, the Err
variant contains this error
and gives back ownership of this AsyncModel
.
Examples
use grb::prelude::*; use grb::AsyncModel; let mut m = Model::with_env("model", &Env::new("")?)?; let x = add_ctsvar!(m, obj: 2)?; let y = add_intvar!(m, bounds: 0..100)?; m.add_constr("c0", c!(x <= y - 0.5 ))?; let m = AsyncModel::new(m); let handle = match m.optimize() { Err((_, e)) => panic!("{}", e), Ok(h) => h }; println!("The model has explored {} MIP nodes so far", handle.node_cnt()?); let (m, errors) = handle.join(); // the AsyncModel is always returned errors?; // optimisation errors - as if Model::optimize were called. let m: Model = m.into(); // get original Model back
Trait Implementations
impl From<AsyncModel> for Model
[src]
fn from(model: AsyncModel) -> Model
[src]
Auto Trait Implementations
impl !RefUnwindSafe for AsyncModel
impl !Send for AsyncModel
impl !Sync for AsyncModel
impl Unpin for AsyncModel
impl UnwindSafe for AsyncModel
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,