Struct gurobi::Model [−][src]
pub struct Model { /* fields omitted */ }
Gurobi model object associated with certain environment.
Methods
impl Model
[src]
impl Model
pub fn new(modelname: &str, env: &Env) -> Result<Model>
[src]
pub fn new(modelname: &str, env: &Env) -> Result<Model>
Create an empty Gurobi model from the environment.
Note that all of the parameters in given environment will copy by Gurobi API
and a new environment associated with the model will create.
If you want to query/modify the value of parameters, use get_env()
.
Arguments
- modelname : Name of the model
- env : An environment object.
Example
use gurobi::*; let mut env = gurobi::Env::new("").unwrap(); env.set(param::OutputFlag, 0).unwrap(); env.set(param::Heuristics, 0.5).unwrap(); // ... let model = Model::new("model1", &env).unwrap();
pub fn read_from(filename: &str, env: &Env) -> Result<Model>
[src]
pub fn read_from(filename: &str, env: &Env) -> Result<Model>
Read a model from a file
pub fn copy(&self) -> Result<Model>
[src]
pub fn copy(&self) -> Result<Model>
create a copy of the model
pub fn fixed(&self) -> Result<Model>
[src]
pub fn fixed(&self) -> Result<Model>
Create an fixed model associated with the model.
In fixed model, each integer variable is fixed to the value that it takes in the original MIP solution. Note that the model must be MIP and have a solution loaded.
pub fn relax(&self) -> Result<Model>
[src]
pub fn relax(&self) -> Result<Model>
Create an relaxation of the model (undocumented).
pub fn presolve(&self) -> Result<Model>
[src]
pub fn presolve(&self) -> Result<Model>
Perform presolve on the model.
pub fn feasibility(&self) -> Result<Model>
[src]
pub fn feasibility(&self) -> Result<Model>
Create a feasibility model (undocumented).
pub fn get_env(&self) -> &Env
[src]
pub fn get_env(&self) -> &Env
Get immutable reference of an environment object associated with the model.
pub fn get_env_mut(&mut self) -> &mut Env
[src]
pub fn get_env_mut(&mut self) -> &mut Env
Get mutable reference of an environment object associated with the model.
pub fn update(&mut self) -> Result<()>
[src]
pub fn update(&mut self) -> Result<()>
Apply all modification of the model to process
pub fn optimize(&mut self) -> Result<()>
[src]
pub fn optimize(&mut self) -> Result<()>
Optimize the model synchronously
pub fn optimize_async(&mut self) -> Result<()>
[src]
pub fn optimize_async(&mut self) -> Result<()>
Optimize the model asynchronously
pub fn optimize_with_callback<F>(&mut self, callback: F) -> Result<()> where
F: FnMut(Callback) -> Result<()> + 'static,
[src]
pub fn optimize_with_callback<F>(&mut self, callback: F) -> Result<()> where
F: FnMut(Callback) -> Result<()> + 'static,
Optimize the model with a callback function
pub fn sync(&self) -> Result<()>
[src]
pub fn sync(&self) -> Result<()>
Wait for a optimization called asynchronously.
pub fn compute_iis(&mut self) -> Result<()>
[src]
pub fn compute_iis(&mut self) -> Result<()>
Compute an Irreducible Inconsistent Subsystem (IIS) of the model.
pub fn terminate(&self)
[src]
pub fn terminate(&self)
Send a request to the model to terminate the current optimization process.
pub fn reset(&self) -> Result<()>
[src]
pub fn reset(&self) -> Result<()>
Reset the model to an unsolved state.
All solution information previously computed are discarded.
pub fn tune(&self) -> Result<()>
[src]
pub fn tune(&self) -> Result<()>
Perform an automated search for parameter settings that improve performance on the model. See also references on official manual.
pub fn get_tune_result(&self, n: i32) -> Result<()>
[src]
pub fn get_tune_result(&self, n: i32) -> Result<()>
Prepare to retrieve the results of tune()
.
See also references on official
manual.
pub fn get_concurrent_env(&self, num: i32) -> Result<Env>
[src]
pub fn get_concurrent_env(&self, num: i32) -> Result<Env>
Create/retrieve a concurrent environment for the model
Note that the number of concurrent environments (num
) must be contiguously numbered.
Example
let env1 = model.get_concurrent_env(0).unwrap(); let env2 = model.get_concurrent_env(1).unwrap(); let env3 = model.get_concurrent_env(2).unwrap(); ...
pub fn discard_concurrent_envs(&self)
[src]
pub fn discard_concurrent_envs(&self)
Discard all concurrent environments for the model.
pub fn message(&self, message: &str)
[src]
pub fn message(&self, message: &str)
Insert a message into log file.
When message cannot convert to raw C string, a panic is occurred.
pub fn read(&mut self, filename: &str) -> Result<()>
[src]
pub fn read(&mut self, filename: &str) -> Result<()>
Import optimization data of the model from a file.
pub fn write(&self, filename: &str) -> Result<()>
[src]
pub fn write(&self, filename: &str) -> Result<()>
Export optimization data of the model to a file.
pub fn add_var(
&mut self,
name: &str,
vtype: VarType,
obj: f64,
lb: f64,
ub: f64,
colconstrs: &[Constr],
colvals: &[f64]
) -> Result<Var>
[src]
pub fn add_var(
&mut self,
name: &str,
vtype: VarType,
obj: f64,
lb: f64,
ub: f64,
colconstrs: &[Constr],
colvals: &[f64]
) -> Result<Var>
add a decision variable to the model.
pub fn add_vars(
&mut self,
names: &[&str],
vtypes: &[VarType],
objs: &[f64],
lbs: &[f64],
ubs: &[f64],
colconstrs: &[&[Constr]],
colvals: &[&[f64]]
) -> Result<Vec<Var>>
[src]
pub fn add_vars(
&mut self,
names: &[&str],
vtypes: &[VarType],
objs: &[f64],
lbs: &[f64],
ubs: &[f64],
colconstrs: &[&[Constr]],
colvals: &[&[f64]]
) -> Result<Vec<Var>>
add decision variables to the model.
pub fn add_constr(
&mut self,
name: &str,
expr: LinExpr,
sense: ConstrSense,
rhs: f64
) -> Result<Constr>
[src]
pub fn add_constr(
&mut self,
name: &str,
expr: LinExpr,
sense: ConstrSense,
rhs: f64
) -> Result<Constr>
add a linear constraint to the model.
pub fn add_constrs(
&mut self,
name: &[&str],
expr: &[LinExpr],
sense: &[ConstrSense],
rhs: &[f64]
) -> Result<Vec<Constr>>
[src]
pub fn add_constrs(
&mut self,
name: &[&str],
expr: &[LinExpr],
sense: &[ConstrSense],
rhs: &[f64]
) -> Result<Vec<Constr>>
add linear constraints to the model.
pub fn add_range(
&mut self,
name: &str,
expr: LinExpr,
lb: f64,
ub: f64
) -> Result<(Var, Constr)>
[src]
pub fn add_range(
&mut self,
name: &str,
expr: LinExpr,
lb: f64,
ub: f64
) -> Result<(Var, Constr)>
Add a range constraint to the model.
This operation adds a decision variable with lower/upper bound, and a linear
equality constraint which states that the value of variable must equal to expr
.
Returns
- An decision variable associated with the model. It has lower/upper bound constraints.
- An linear equality constraint associated with the model.
pub fn add_ranges(
&mut self,
names: &[&str],
expr: &[LinExpr],
lb: &[f64],
ub: &[f64]
) -> Result<(Vec<Var>, Vec<Constr>)>
[src]
pub fn add_ranges(
&mut self,
names: &[&str],
expr: &[LinExpr],
lb: &[f64],
ub: &[f64]
) -> Result<(Vec<Var>, Vec<Constr>)>
Add range constraints to the model.
pub fn add_qconstr(
&mut self,
constrname: &str,
expr: QuadExpr,
sense: ConstrSense,
rhs: f64
) -> Result<QConstr>
[src]
pub fn add_qconstr(
&mut self,
constrname: &str,
expr: QuadExpr,
sense: ConstrSense,
rhs: f64
) -> Result<QConstr>
add a quadratic constraint to the model.
pub fn add_sos(
&mut self,
vars: &[Var],
weights: &[f64],
sostype: SOSType
) -> Result<SOS>
[src]
pub fn add_sos(
&mut self,
vars: &[Var],
weights: &[f64],
sostype: SOSType
) -> Result<SOS>
add Special Order Set (SOS) constraint to the model.
pub fn set_objective<Expr: Into<QuadExpr>>(
&mut self,
expr: Expr,
sense: ModelSense
) -> Result<()>
[src]
pub fn set_objective<Expr: Into<QuadExpr>>(
&mut self,
expr: Expr,
sense: ModelSense
) -> Result<()>
Set the objective function of the model.
pub fn get<A: Attr>(&self, attr: A) -> Result<A::Out>
[src]
pub fn get<A: Attr>(&self, attr: A) -> Result<A::Out>
Query the value of attributes which associated with variable/constraints.
pub fn set<A: Attr>(&mut self, attr: A, value: A::Out) -> Result<()>
[src]
pub fn set<A: Attr>(&mut self, attr: A, value: A::Out) -> Result<()>
Set the value of attributes which associated with variable/constraints.
pub fn get_values<A: AttrArray, P>(
&self,
attr: A,
item: &[P]
) -> Result<Vec<A::Out>> where
P: Deref<Target = Proxy>,
[src]
pub fn get_values<A: AttrArray, P>(
&self,
attr: A,
item: &[P]
) -> Result<Vec<A::Out>> where
P: Deref<Target = Proxy>,
Query the value of attributes which associated with variable/constraints.
pub fn set_values<A: AttrArray, P>(
&mut self,
attr: A,
item: &[P],
val: &[A::Out]
) -> Result<()> where
P: Deref<Target = Proxy>,
[src]
pub fn set_values<A: AttrArray, P>(
&mut self,
attr: A,
item: &[P],
val: &[A::Out]
) -> Result<()> where
P: Deref<Target = Proxy>,
Set the value of attributes which associated with variable/constraints.
pub fn feas_relax(
&mut self,
relaxtype: RelaxType,
minrelax: bool,
vars: &[Var],
lbpen: &[f64],
ubpen: &[f64],
constrs: &[Constr],
rhspen: &[f64]
) -> Result<(f64, Iter<Var>, Iter<Constr>, Iter<QConstr>)>
[src]
pub fn feas_relax(
&mut self,
relaxtype: RelaxType,
minrelax: bool,
vars: &[Var],
lbpen: &[f64],
ubpen: &[f64],
constrs: &[Constr],
rhspen: &[f64]
) -> Result<(f64, Iter<Var>, Iter<Constr>, Iter<QConstr>)>
Modify the model to create a feasibility relaxation.
$$ \text{minimize}\quad f(x) + \sum_{i \in IIS} penalty_i(s_i) $$ where $s_i > 0$ is the slack variable of $i$ -th constraint.
This method will modify the model.
If you don't want to modify the model, copy the model before invoking
this method (see also copy()
).
Arguments
relaxtype
: The type of cost function used when finding the minimum cost relaxation. See alsoRelaxType
.minrelax
: The type of feasibility relaxation to perform.vars
: Variables whose bounds are allowed to be violated.lbpen
/ubpen
: Penalty for violating a variable lower/upper bound.INFINITY
means that the bounds doesn't allow to be violated.constrs
: Linear constraints that are allowed to be violated.rhspen
: Penalty for violating a linear constraint.INFINITY
means that the bounds doesn't allow to be violated.
Returns
- The objective value for the relaxation performed (if
minrelax
istrue
). - Slack variables for relaxation and linear/quadratic constraints related to theirs.
pub fn set_pwl_obj(&mut self, var: &Var, x: &[f64], y: &[f64]) -> Result<()>
[src]
pub fn set_pwl_obj(&mut self, var: &Var, x: &[f64], y: &[f64]) -> Result<()>
Set a piecewise-linear objective function for the variable.
The piecewise-linear objective function $f(x)$ is defined as follows: \begin{align} f(x) = \begin{cases} y_1 + \dfrac{y_2 - y_1}{x_2 - x_1} \, (x - x_1) & \text{if $x \leq x_1$}, \\ \\ y_i + \dfrac{y_{i+1} - y_i}{x_{i+1}-x_i} \, (x - x_i) & \text{if $x_i \leq x \leq x_{i+1}$}, \\ \\ y_n + \dfrac{y_n - y_{n-1}}{x_n-x_{n-1}} \, (x - x_n) & \text{if $x \geq x_n$}, \end{cases} \end{align} where $\bm{x} = \{ x_1, ..., x_n \}$, $\bm{y} = \{ y_1, ..., y_n \}$ is the points.
The attribute Obj
will be set to 0.
To delete the piecewise-linear function on the variable, set the value of Obj
attribute to non-zero.
Arguments
var
:x
: $n$-points from domain of the variable. The order of entries should be non-decreasing.y
: $n$-points of objective values at each point $x_i$
pub fn status(&self) -> Result<Status>
[src]
pub fn status(&self) -> Result<Status>
Retrieve the status of the model.
ⓘImportant traits for Iter<'a, T>pub fn get_vars(&self) -> Iter<Var>
[src]
pub fn get_vars(&self) -> Iter<Var>
Retrieve an iterator of the variables in the model.
ⓘImportant traits for Iter<'a, T>pub fn get_constrs(&self) -> Iter<Constr>
[src]
pub fn get_constrs(&self) -> Iter<Constr>
Retrieve an iterator of the linear constraints in the model.
ⓘImportant traits for Iter<'a, T>pub fn get_qconstrs(&self) -> Iter<QConstr>
[src]
pub fn get_qconstrs(&self) -> Iter<QConstr>
Retrieve an iterator of the quadratic constraints in the model.
ⓘImportant traits for Iter<'a, T>pub fn get_sos(&self) -> Iter<SOS>
[src]
pub fn get_sos(&self) -> Iter<SOS>
Retrieve an iterator of the special order set (SOS) constraints in the model.
pub fn remove<P: DerefMut<Target = Proxy>>(&mut self, item: P)
[src]
pub fn remove<P: DerefMut<Target = Proxy>>(&mut self, item: P)
Remove a variable from the model.
pub fn get_coeff(&self, var: &Var, constr: &Constr) -> Result<f64>
[src]
pub fn get_coeff(&self, var: &Var, constr: &Constr) -> Result<f64>
Retrieve a single constant matrix coefficient of the model.
pub fn set_coeff(
&mut self,
var: &Var,
constr: &Constr,
value: f64
) -> Result<()>
[src]
pub fn set_coeff(
&mut self,
var: &Var,
constr: &Constr,
value: f64
) -> Result<()>
Change a single constant matrix coefficient of the model.
pub fn set_coeffs(
&mut self,
vars: &[&Var],
constrs: &[&Constr],
values: &[f64]
) -> Result<()>
[src]
pub fn set_coeffs(
&mut self,
vars: &[&Var],
constrs: &[&Constr],
values: &[f64]
) -> Result<()>
Change a set of constant matrix coefficients of the model.