Skip to main content

otspot_model/
variable.rs

1//! Variable type for the modeling API
2
3/// Integrality requirement for a decision variable.
4///
5/// `Continuous` is the default (matches pre-MIP behaviour). `Integer` / `Binary`
6/// route the model through the MILP/MIQP branch-and-bound solver. `Binary` is an
7/// `Integer` variable additionally fixed to the `[0, 1]` box.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum VarKind {
10    /// Real-valued variable (no integrality requirement).
11    Continuous,
12    /// Variable constrained to integer values within its bounds.
13    Integer,
14    /// Integer variable additionally restricted to `{0, 1}`.
15    Binary,
16}
17
18/// A lightweight handle to a decision variable.
19///
20/// `Variable` is `Copy`, so it can be used in expressions multiple times
21/// without being consumed: `x + y` does not move `x`.
22///
23/// Internally, a `Variable` carries its index and the ID of the model that
24/// created it. The model ID is used by [`ModelResult::try_value`] to detect
25/// cross-model variable misuse at runtime.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27pub struct Variable {
28    pub(crate) index: usize,
29    pub(crate) model_id: u64,
30}
31
32/// Metadata about a variable stored in the `Model`.
33pub(crate) struct VariableDefinition {
34    pub name: String,
35    pub lower_bound: f64,
36    pub upper_bound: f64,
37    /// Integrality requirement. `Continuous` for `add_var`.
38    pub kind: VarKind,
39}