1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Constraint types and the `constraint!` macro
use Expression;
/// Sense (direction) of a linear constraint.
/// A linear constraint: `lhs sense rhs`.
///
/// Stored in normalized form: `lhs` contains only variable terms (no constant),
/// and `rhs` is a scalar.
/// Build a `Constraint` using natural inequality syntax.
///
/// # Examples
/// ```
/// use otspot_model::{Model, constraint};
/// let mut model = Model::new("demo");
/// let x = model.add_var("x", 0.0, f64::INFINITY);
/// let y = model.add_var("y", 0.0, 10.0);
/// model.add_constraint(constraint!((2.0 * x + 3.0 * y) <= 12.0));
/// model.add_constraint(constraint!((x + y) >= 3.0));
/// ```
/// Build a `Constraint` using natural inequality syntax.
///
/// Supported forms:
/// - `constraint!(x <= 5.0)` — single variable on the left
/// - `constraint!((expr) <= rhs)` — parenthesised expression on the left
///
/// For complex LHS expressions, wrap them in parentheses:
/// ```rust,no_run
/// # use otspot_model::{Model, constraint};
/// # let mut model = Model::new("demo");
/// # let x = model.add_var("x", 0.0, f64::INFINITY);
/// # let y = model.add_var("y", 0.0, f64::INFINITY);
/// model.add_constraint(constraint!((2.0 * x + 3.0 * y) <= 12.0));
/// ```
/// or use the method API directly:
/// ```rust,no_run
/// # use otspot_model::Model;
/// # let mut model = Model::new("demo");
/// # let x = model.add_var("x", 0.0, f64::INFINITY);
/// # let y = model.add_var("y", 0.0, f64::INFINITY);
/// model.add_constraint((2.0 * x + 3.0 * y).leq(12.0));
/// ```
;
=> ;
=> ;
// Single variable (ident can be followed by <= in macro rules)
=> ;
=> ;
=> ;
}