Macro grb::add_var [−][src]
add_var!() { /* proc-macro */ }
Convienence wrapper around Model::add_var
; adds a new variable to a Model
object. The macro keyword arguments are
optional.
Syntax
The syntax of macro is two positional arguments followed by any number of named arguments:
add_var!(MODEL, VAR_TYPE, NAMED_ARG1: VAL1, NAMED_ARG2: VAL2, ...)
MODEL
should be an instance of a Model
.
VAR_TYPE
should be the variable type - a variant of VarType
.
The named arguments are described below.
Name | Type | Model::add_var argument |
---|---|---|
name | Anything that implements AsRef<str> (&str, String, etc) | name |
obj | Anything that can be cast to a f64 | obj |
bounds | A range expression, see below | ub & lb |
The bounds
argument takes a value of the form LB..UB
where LB
and UB
are the upper and lower bounds of the variable.
LB
and UB
can be left off as well, so ..UB
(short for -INFINITY..UB
), LB..
(short for LB..INFINITY
) and ..
are also valid values.
use grb::prelude::*; let mut model = Model::new("Model").unwrap(); add_var!(model, Continuous, name: "name", obj: 0.0, bounds: -10..10)?; add_var!(model, Integer, bounds: 0..)?; add_var!(model, Continuous, name: &format!("X[{}]", 42))?;