use crate::instance::Instance;
use crate::logical_memory::{LogicalMemoryProfile, LogicalMemoryVisitor, Path};
use crate::v1;
crate::impl_logical_memory_profile! {
v1::Parameters as "Parameters" {
entries,
}
}
crate::impl_logical_memory_profile! {
v1::instance::Description as "Description" {
name,
description,
authors,
created_by,
}
}
macro_rules! impl_special_constraint_profile {
($constraint_type:ty, $name:literal { $($field:ident),+ $(,)? }) => {
impl LogicalMemoryProfile for $constraint_type {
fn visit_logical_memory<V: LogicalMemoryVisitor>(
&self,
path: &mut Path,
visitor: &mut V,
) {
$(
self.$field.visit_logical_memory(
path.with(concat!($name, ".", stringify!($field))).as_mut(),
visitor,
);
)+
}
}
};
}
impl_special_constraint_profile!(
crate::IndicatorConstraint,
"IndicatorConstraint" {
indicator_variable,
equality,
stage,
}
);
impl_special_constraint_profile!(
crate::OneHotConstraint,
"OneHotConstraint" {
variables,
stage,
}
);
impl_special_constraint_profile!(
crate::Sos1Constraint,
"Sos1Constraint" {
variables,
stage,
}
);
macro_rules! impl_constraint_collection_profile {
($constraint_type:ty, $active_name:expr, $removed_name:expr) => {
impl LogicalMemoryProfile
for crate::constraint_type::ConstraintCollection<$constraint_type>
{
fn visit_logical_memory<V: LogicalMemoryVisitor>(
&self,
path: &mut Path,
visitor: &mut V,
) {
self.active()
.visit_logical_memory(path.with($active_name).as_mut(), visitor);
self.removed()
.visit_logical_memory(path.with($removed_name).as_mut(), visitor);
self.context()
.visit_logical_memory(path.with("context").as_mut(), visitor);
}
}
};
}
impl_constraint_collection_profile!(crate::Constraint, "constraints", "removed_constraints");
impl_constraint_collection_profile!(
crate::IndicatorConstraint,
"indicator_constraints",
"removed_indicator_constraints"
);
impl_constraint_collection_profile!(
crate::OneHotConstraint,
"one_hot_constraints",
"removed_one_hot_constraints"
);
impl_constraint_collection_profile!(
crate::Sos1Constraint,
"sos1_constraints",
"removed_sos1_constraints"
);
impl Instance {
pub fn logical_memory_profile(&self) -> crate::MemoryProfile {
crate::logical_memory::build_profile(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::constraint::CreatedData;
use crate::logical_memory::logical_memory_to_folded;
use crate::{
coeff, linear, Constraint, ConstraintID, DecisionVariable, Equality, Function, VariableID,
};
use std::collections::{BTreeMap, BTreeSet};
#[test]
fn test_instance_empty_snapshot() {
let instance = Instance::default();
let folded = logical_memory_to_folded(&instance);
insta::assert_snapshot!(folded, @r###"
Instance.annotations;HashMap[stack] 48
Instance.constraint_collection;constraints;BTreeMap[stack] 24
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.constraint_collection;removed_constraints;BTreeMap[stack] 24
Instance.decision_variable_dependency;AcyclicAssignments.assignments;FnvHashMap[stack] 32
Instance.decision_variable_dependency;AcyclicAssignments.dependency 144
Instance.decision_variable_dependency;AcyclicAssignments.topological_order;Vec[stack] 24
Instance.decision_variables;DecisionVariableTable.columns;CreatedDecisionVariableColumns.fixed_values;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.description;Option[stack] 168
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[stack] 24
Instance.indicator_constraint_collection;removed_indicator_constraints;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.entries;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.objective;Zero 40
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[stack] 24
Instance.one_hot_constraint_collection;removed_one_hot_constraints;BTreeMap[stack] 24
Instance.parameters;Option[stack] 48
Instance.sense 1
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;removed_sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[stack] 24
"###);
}
#[test]
fn test_instance_with_objective_and_variables_snapshot() {
let dv1 = DecisionVariable::continuous();
let dv2 = DecisionVariable::continuous();
let mut decision_variables = BTreeMap::new();
decision_variables.insert(VariableID::from(1), dv1);
decision_variables.insert(VariableID::from(2), dv2);
let objective = Function::Linear(
((coeff!(2.0) * linear!(1)).unwrap() + (coeff!(3.0) * linear!(2)).unwrap()).unwrap(),
);
let instance = Instance::new(
crate::instance::Sense::Minimize,
objective,
decision_variables,
BTreeMap::new(),
)
.unwrap();
let folded = logical_memory_to_folded(&instance);
insta::assert_snapshot!(folded, @r###"
Instance.annotations;HashMap[stack] 48
Instance.constraint_collection;constraints;BTreeMap[stack] 24
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.constraint_collection;removed_constraints;BTreeMap[stack] 24
Instance.decision_variable_dependency;AcyclicAssignments.assignments;FnvHashMap[stack] 32
Instance.decision_variable_dependency;AcyclicAssignments.dependency 144
Instance.decision_variable_dependency;AcyclicAssignments.topological_order;Vec[stack] 24
Instance.decision_variables;DecisionVariableTable.columns;CreatedDecisionVariableColumns.fixed_values;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[key];VariableID.0 16
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.lower 16
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.upper 16
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.kind 2
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.description;Option[stack] 168
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[stack] 24
Instance.indicator_constraint_collection;removed_indicator_constraints;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.entries;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.objective;Linear;PolynomialBase.terms 80
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[stack] 24
Instance.one_hot_constraint_collection;removed_one_hot_constraints;BTreeMap[stack] 24
Instance.parameters;Option[stack] 48
Instance.sense 1
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;removed_sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[stack] 24
"###);
}
#[test]
fn test_instance_with_constraints_snapshot() {
let dv1 = DecisionVariable::continuous();
let dv2 = DecisionVariable::continuous();
let mut decision_variables = BTreeMap::new();
decision_variables.insert(VariableID::from(1), dv1);
decision_variables.insert(VariableID::from(2), dv2);
let objective = Function::Linear(
((coeff!(2.0) * linear!(1)).unwrap() + (coeff!(3.0) * linear!(2)).unwrap()).unwrap(),
);
let constraint = Constraint {
equality: Equality::LessThanOrEqualToZero,
stage: CreatedData {
function: Function::Linear((linear!(1) + linear!(2)).unwrap()),
},
};
let mut constraints = BTreeMap::new();
constraints.insert(ConstraintID::from(1), constraint);
let instance = Instance::new(
crate::instance::Sense::Minimize,
objective,
decision_variables,
constraints,
)
.unwrap();
let folded = logical_memory_to_folded(&instance);
insta::assert_snapshot!(folded, @r###"
Instance.annotations;HashMap[stack] 48
Instance.constraint_collection;constraints;BTreeMap[key];ConstraintID.0 8
Instance.constraint_collection;constraints;BTreeMap[stack] 24
Instance.constraint_collection;constraints;Constraint.equality 1
Instance.constraint_collection;constraints;Constraint.stage;CreatedData.function;Linear;PolynomialBase.terms 80
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.constraint_collection;removed_constraints;BTreeMap[stack] 24
Instance.decision_variable_dependency;AcyclicAssignments.assignments;FnvHashMap[stack] 32
Instance.decision_variable_dependency;AcyclicAssignments.dependency 144
Instance.decision_variable_dependency;AcyclicAssignments.topological_order;Vec[stack] 24
Instance.decision_variables;DecisionVariableTable.columns;CreatedDecisionVariableColumns.fixed_values;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[key];VariableID.0 16
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.lower 16
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.upper 16
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.kind 2
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.description;Option[stack] 168
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[stack] 24
Instance.indicator_constraint_collection;removed_indicator_constraints;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.entries;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.objective;Linear;PolynomialBase.terms 80
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[stack] 24
Instance.one_hot_constraint_collection;removed_one_hot_constraints;BTreeMap[stack] 24
Instance.parameters;Option[stack] 48
Instance.sense 1
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;removed_sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[stack] 24
"###);
}
#[test]
fn test_instance_with_special_constraints_snapshot() {
let mut decision_variables = BTreeMap::new();
decision_variables.insert(VariableID::from(1), DecisionVariable::binary());
decision_variables.insert(VariableID::from(2), DecisionVariable::binary());
decision_variables.insert(VariableID::from(3), DecisionVariable::continuous());
let mut instance = Instance::new(
crate::instance::Sense::Minimize,
Function::Zero,
decision_variables,
BTreeMap::new(),
)
.unwrap();
instance
.add_indicator_constraint(
crate::IndicatorConstraint::new(
VariableID::from(1),
Equality::LessThanOrEqualToZero,
Function::Linear((linear!(2) + coeff!(-1.0)).unwrap()),
),
crate::ConstraintContext::default(),
)
.unwrap();
instance
.add_one_hot_constraint(
crate::OneHotConstraint::new(
[1, 2]
.into_iter()
.map(VariableID::from)
.collect::<BTreeSet<_>>(),
)
.unwrap(),
crate::ConstraintContext::default(),
)
.unwrap();
instance
.add_sos1_constraint(
crate::Sos1Constraint::new(
[2, 3]
.into_iter()
.map(VariableID::from)
.collect::<BTreeSet<_>>(),
)
.unwrap(),
crate::ConstraintContext::default(),
)
.unwrap();
let folded = logical_memory_to_folded(&instance);
insta::assert_snapshot!(folded, @r###"
Instance.annotations;HashMap[stack] 48
Instance.constraint_collection;constraints;BTreeMap[stack] 24
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.constraint_collection;removed_constraints;BTreeMap[stack] 24
Instance.decision_variable_dependency;AcyclicAssignments.assignments;FnvHashMap[stack] 32
Instance.decision_variable_dependency;AcyclicAssignments.dependency 144
Instance.decision_variable_dependency;AcyclicAssignments.topological_order;Vec[stack] 24
Instance.decision_variables;DecisionVariableTable.columns;CreatedDecisionVariableColumns.fixed_values;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[key];VariableID.0 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.lower 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.upper 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.kind 3
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.description;Option[stack] 168
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[key];IndicatorConstraintID.0 8
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[stack] 24
Instance.indicator_constraint_collection;indicator_constraints;IndicatorConstraint.equality 1
Instance.indicator_constraint_collection;indicator_constraints;IndicatorConstraint.indicator_variable;VariableID.0 8
Instance.indicator_constraint_collection;indicator_constraints;IndicatorConstraint.stage;CreatedData.function;Linear;PolynomialBase.terms 80
Instance.indicator_constraint_collection;removed_indicator_constraints;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.entries;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.objective;Zero 40
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[key];OneHotConstraintID.0 8
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[stack] 24
Instance.one_hot_constraint_collection;one_hot_constraints;OneHotConstraint.variables;BTreeSet[stack] 24
Instance.one_hot_constraint_collection;one_hot_constraints;OneHotConstraint.variables;VariableID.0 16
Instance.one_hot_constraint_collection;removed_one_hot_constraints;BTreeMap[stack] 24
Instance.parameters;Option[stack] 48
Instance.sense 1
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;removed_sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[key];Sos1ConstraintID.0 8
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;Sos1Constraint.variables;BTreeSet[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;Sos1Constraint.variables;VariableID.0 16
"###);
}
#[test]
fn test_instance_with_multiple_variables_with_labels_snapshot() {
let dv1 = DecisionVariable::continuous();
let dv2 = DecisionVariable::continuous();
let dv3 = DecisionVariable::continuous();
let mut decision_variables = BTreeMap::new();
decision_variables.insert(VariableID::from(1), dv1);
decision_variables.insert(VariableID::from(2), dv2);
decision_variables.insert(VariableID::from(3), dv3);
let mut instance = Instance::new(
crate::instance::Sense::Minimize,
Function::Zero,
decision_variables,
BTreeMap::new(),
)
.unwrap();
instance
.set_variable_label(
1.into(),
crate::ModelingLabel {
name: Some("x1".to_string()),
..Default::default()
},
)
.unwrap();
instance
.set_variable_label(
2.into(),
crate::ModelingLabel {
name: Some("x2".to_string()),
..Default::default()
},
)
.unwrap();
instance
.set_variable_label(
3.into(),
crate::ModelingLabel {
name: Some("x3_with_longer_name".to_string()),
..Default::default()
},
)
.unwrap();
let folded = logical_memory_to_folded(&instance);
insta::assert_snapshot!(folded, @r###"
Instance.annotations;HashMap[stack] 48
Instance.constraint_collection;constraints;BTreeMap[stack] 24
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.constraint_collection;removed_constraints;BTreeMap[stack] 24
Instance.decision_variable_dependency;AcyclicAssignments.assignments;FnvHashMap[stack] 32
Instance.decision_variable_dependency;AcyclicAssignments.dependency 144
Instance.decision_variable_dependency;AcyclicAssignments.topological_order;Vec[stack] 24
Instance.decision_variables;DecisionVariableTable.columns;CreatedDecisionVariableColumns.fixed_values;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[key];VariableID.0 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.lower 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.upper 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.kind 3
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name 95
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[key];VariableID.0 24
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.description;Option[stack] 168
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[stack] 24
Instance.indicator_constraint_collection;removed_indicator_constraints;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.entries;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.objective;Zero 40
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[stack] 24
Instance.one_hot_constraint_collection;removed_one_hot_constraints;BTreeMap[stack] 24
Instance.parameters;Option[stack] 48
Instance.sense 1
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;removed_sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[stack] 24
"###);
}
#[test]
fn test_instance_with_parameters_and_description_snapshot() {
let dv1 = DecisionVariable::continuous();
let mut decision_variables = BTreeMap::new();
decision_variables.insert(VariableID::from(1), dv1);
let mut instance = Instance::new(
crate::instance::Sense::Minimize,
Function::Zero,
decision_variables,
BTreeMap::new(),
)
.unwrap();
let mut parameters = v1::Parameters {
entries: std::collections::HashMap::new(),
};
parameters.entries.insert(1, 10.0);
parameters.entries.insert(2, 20.0);
instance.parameters = Some(parameters);
let description = v1::instance::Description {
name: Some("Test Instance".to_string()),
description: Some("A test optimization problem".to_string()),
authors: vec!["Alice".to_string(), "Bob".to_string()],
created_by: Some("OMMX Test Suite".to_string()),
created: None,
license: None,
dataset: None,
};
instance.description = Some(description);
let folded = logical_memory_to_folded(&instance);
insta::assert_snapshot!(folded, @r###"
Instance.annotations;HashMap[stack] 48
Instance.constraint_collection;constraints;BTreeMap[stack] 24
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.constraint_collection;removed_constraints;BTreeMap[stack] 24
Instance.decision_variable_dependency;AcyclicAssignments.assignments;FnvHashMap[stack] 32
Instance.decision_variable_dependency;AcyclicAssignments.dependency 144
Instance.decision_variable_dependency;AcyclicAssignments.topological_order;Vec[stack] 24
Instance.decision_variables;DecisionVariableTable.columns;CreatedDecisionVariableColumns.fixed_values;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[key];VariableID.0 8
Instance.decision_variables;DecisionVariableTable.entries;BTreeMap[stack] 24
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.lower 8
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.bound;Bound.upper 8
Instance.decision_variables;DecisionVariableTable.entries;DecisionVariable.kind 1
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.decision_variables;DecisionVariableTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.description;Description.authors 56
Instance.description;Description.authors;Vec[stack] 24
Instance.description;Description.created_by 39
Instance.description;Description.description 51
Instance.description;Description.name 37
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.indicator_constraint_collection;indicator_constraints;BTreeMap[stack] 24
Instance.indicator_constraint_collection;removed_indicator_constraints;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.entries;BTreeMap[stack] 24
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.named_functions;NamedFunctionTable.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.objective;Zero 40
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.one_hot_constraint_collection;one_hot_constraints;BTreeMap[stack] 24
Instance.one_hot_constraint_collection;removed_one_hot_constraints;BTreeMap[stack] 24
Instance.parameters;Parameters.entries 16
Instance.parameters;Parameters.entries;HashMap[key] 16
Instance.parameters;Parameters.entries;HashMap[stack] 48
Instance.sense 1
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.description;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.name;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.parameters;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.labels;ModelingLabelStore.subscripts;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;context;ConstraintContextStore.provenance;FnvHashMap[stack] 32
Instance.sos1_constraint_collection;removed_sos1_constraints;BTreeMap[stack] 24
Instance.sos1_constraint_collection;sos1_constraints;BTreeMap[stack] 24
"###);
}
}