63 """A subset of a Model's constraints (including variable bounds/integrality).
65 When returned from `solve.compute_infeasible_subsystem`, the contained
66 `ModelSubsetBounds` will all be nonempty.
69 variable_bounds: The upper and/or lower bound constraints on these variables
70 are included in the subset.
71 variable_integrality: The constraint that a variable is integer is included
73 linear_constraints: The upper and/or lower bounds from these linear
74 constraints are included in the subset.
77 variable_bounds: Mapping[variables_mod.Variable, ModelSubsetBounds] = (
78 immutabledict.immutabledict()
80 variable_integrality: FrozenSet[variables_mod.Variable] = frozenset()
81 linear_constraints: Mapping[
82 linear_constraints_mod.LinearConstraint, ModelSubsetBounds
83 ] = immutabledict.immutabledict()
86 """Returns true if all the nested constraint collections are empty.
88 Warning: When `self.variable_bounds` or `self.linear_constraints` contain
89 only ModelSubsetBounds which are themselves empty, this function will return
93 True if this is empty.
99 def to_proto(self) -> infeasible_subsystem_pb2.ModelSubsetProto:
100 """Returns an equivalent proto message for this `ModelSubset`."""
101 return infeasible_subsystem_pb2.ModelSubsetProto(
103 var.id: bounds.to_proto()
108 con.id: bounds.to_proto()
115 model_subset: infeasible_subsystem_pb2.ModelSubsetProto, mod:
model.Model
117 """Returns an equivalent `ModelSubset` to the input proto."""
118 if model_subset.quadratic_constraints:
119 raise NotImplementedError(
120 "quadratic_constraints not yet implemented for ModelSubset in Python"
122 if model_subset.second_order_cone_constraints:
123 raise NotImplementedError(
124 "second_order_cone_constraints not yet implemented for ModelSubset in"
127 if model_subset.sos1_constraints:
128 raise NotImplementedError(
129 "sos1_constraints not yet implemented for ModelSubset in Python"
131 if model_subset.sos2_constraints:
132 raise NotImplementedError(
133 "sos2_constraints not yet implemented for ModelSubset in Python"
135 if model_subset.indicator_constraints:
136 raise NotImplementedError(
137 "indicator_constraints not yet implemented for ModelSubset in Python"
142 for var_id, bounds
in model_subset.variable_bounds.items()
144 variable_integrality=frozenset(
145 mod.get_variable(var_id)
for var_id
in model_subset.variable_integrality
149 for con_id, bounds
in model_subset.linear_constraints.items()
154@dataclasses.dataclass(frozen=True)
189 infeasible_system_result: infeasible_subsystem_pb2.ComputeInfeasibleSubsystemResultProto,
191) -> ComputeInfeasibleSubsystemResult:
192 """Returns an equivalent `ComputeInfeasibleSubsystemResult` to the input proto."""
196 infeasible_system_result.infeasible_subsystem, mod
198 is_minimal=infeasible_system_result.is_minimal,