Macro grb::c [−][src]
c!() { /* proc-macro */ }
Expand description
A proc-macro for creating constraint objects.
Syntax
Inequality constraints
To create an IneqExpr
object for a linear or quadratic constraint, the syntax is
c!( LHS CMP RHS )
LHS
and RHS
should be valid algebraic expressions involving Var
objects and numeric constants.
For example, if x
, y
and z
are Var
objects and vars
is an Vec<Var>
objects, these are valid:
c!(vars.iter().grb_sum() == x );
c!( x + 1/2 == 1.4*y - 2*z );
c!( 2*x >= z*y );
c!( 2*x >= 7*(z*y) ); // note the brackets on the non-linear term when a coefficient is present
but the following are not:
c!(vars.iter().sum() == x ); // cannot infer type on sum() call
c!( 2*x >= z >= y ); // chained comparison
c!( 2*x >= 7*z*y ); // no brackets around var*var when a coefficient is present
The macro expands c!( LHS == RHS )
to:
grb::constr::IneqExpr {
lhs: grb::Expr::from(LHS),
sense: grb::ConstrSense::Equal,
rhs: grb::Expr::from(RHS),
};
Range constraints
To create a RangeExpr
object for a range constraint, use the syntax
c!( EXPR in LB..UB )
c!( EXPR in LB.. )
c!( EXPR in ..UB )
c!( EXPR in .. )
where EXPR
is a valid expression, like LHS
and RHS
above. Additionally, EXPR
must be linear,
although this is not checked at compile-time.
LB
and UB
can be any expression that evaluates to type that can be cast to a f64
using
the as
operator. For example, the following are valid (variables have the meaning as above):
c!( x - y + 2*z in 0..200 );
c!( x - y + 2*z in 1.. );
c!( x - y in (1.0/3.0)..(1<<4));