Macro grb::add_var[][src]

add_var!() { /* proc-macro */ }
Expand description

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.

NameTypeModel::add_var argument
nameAnything that implements AsRef<str> (&str, String, etc)name
objAnything that can be cast to a f64obj
boundsA range expression, see belowub & 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))?;