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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
mod analysis;
mod approx;
mod arbitrary;
mod clip_bounds;
mod constraint_hints;
mod convert;
mod decision_variable;
mod error;
mod evaluate;
mod log_encode;
mod new;
mod parse;
mod pass;
mod penalty;
mod reduce_binary_power;
mod serialize;
mod setter;
mod stats;
mod substitute;
pub use analysis::*;
pub use error::*;
pub use log_encode::*;
pub use stats::*;
use crate::{
constraint_hints::ConstraintHints, parse::Parse, v1, AcyclicAssignments, Constraint,
ConstraintID, DecisionVariable, Evaluate, Function, RemovedConstraint, VariableID,
VariableIDSet,
};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub enum Sense {
#[default]
Minimize,
Maximize,
}
/// Instance, represents a mathematical optimization problem.
///
/// Invariants
/// -----------
/// - [`Self::decision_variables`] contains all decision variables used in the problem.
/// - The keys of [`Self::constraints`] and [`Self::removed_constraints`] are disjoint sets.
/// - The keys of [`Self::decision_variable_dependency`] are not used. See also the document of [`DecisionVariableAnalysis`].
///
#[derive(Debug, Clone, PartialEq, getset::Getters, getset::CopyGetters, Default)]
pub struct Instance {
#[getset(get_copy = "pub")]
sense: Sense,
#[getset(get = "pub")]
objective: Function,
#[getset(get = "pub")]
decision_variables: BTreeMap<VariableID, DecisionVariable>,
#[getset(get = "pub")]
constraints: BTreeMap<ConstraintID, Constraint>,
#[getset(get = "pub")]
removed_constraints: BTreeMap<ConstraintID, RemovedConstraint>,
#[getset(get = "pub")]
decision_variable_dependency: AcyclicAssignments,
/// The constraint hints, i.e. some constraints are in form of one-hot, SOS1,2, or other special types.
///
/// Note
/// -----
/// This struct does not validate the hints in mathematical sense.
/// Only checks the decision variable and constraint IDs are valid.
#[getset(get = "pub")]
constraint_hints: ConstraintHints,
// Optional fields for additional metadata.
// These fields are public since arbitrary values can be set without validation.
pub parameters: Option<v1::Parameters>,
pub description: Option<v1::instance::Description>,
}
/// Optimization problem instance with parameters
///
/// Invariants
/// -----------
/// - [`Self::decision_variables`] and [`Self::parameters`] contains all decision variables and parameters used in the problem.
/// - This means every IDs appearing in the constraints and the objective function must be included in either of them.
/// - The IDs of [`Self::decision_variables`] and [`Self::parameters`] are disjoint sets.
/// - The keys of [`Self::constraints`] and [`Self::removed_constraints`] are disjoint sets.
/// - The keys of [`Self::decision_variable_dependency`] are not used. See also the document of [`DecisionVariableAnalysis`].
///
#[derive(Debug, Clone, PartialEq, getset::Getters, Default)]
pub struct ParametricInstance {
#[getset(get = "pub")]
sense: Sense,
#[getset(get = "pub")]
objective: Function,
#[getset(get = "pub")]
decision_variables: BTreeMap<VariableID, DecisionVariable>,
#[getset(get = "pub")]
parameters: BTreeMap<VariableID, v1::Parameter>,
#[getset(get = "pub")]
constraints: BTreeMap<ConstraintID, Constraint>,
#[getset(get = "pub")]
removed_constraints: BTreeMap<ConstraintID, RemovedConstraint>,
#[getset(get = "pub")]
decision_variable_dependency: AcyclicAssignments,
/// The constraint hints, i.e. some constraints are in form of one-hot, SOS1,2, or other special types.
///
/// Note
/// -----
/// This struct does not validate the hints in mathematical sense.
/// Only checks the decision variable and constraint IDs are valid.
#[getset(get = "pub")]
constraint_hints: ConstraintHints,
// Optional fields for additional metadata.
// These fields are public since arbitrary values can be set without validation.
pub description: Option<v1::instance::Description>,
}