64 """A subset of a Model's constraints (including variable bounds/integrality).
66 When returned from `solve.compute_infeasible_subsystem`, the contained
67 `ModelSubsetBounds` will all be nonempty.
70 variable_bounds: The upper and/or lower bound constraints on these variables
71 are included in the subset.
72 variable_integrality: The constraint that a variable is integer is included
74 linear_constraints: The upper and/or lower bounds from these linear
75 constraints are included in the subset.
78 variable_bounds: Mapping[variables_mod.Variable, ModelSubsetBounds] = (
79 immutabledict.immutabledict()
81 variable_integrality: FrozenSet[variables_mod.Variable] = frozenset()
82 linear_constraints: Mapping[
83 linear_constraints_mod.LinearConstraint, ModelSubsetBounds
84 ] = immutabledict.immutabledict()
87 """Returns true if all the nested constraint collections are empty.
89 Warning: When `self.variable_bounds` or `self.linear_constraints` contain
90 only ModelSubsetBounds which are themselves empty, this function will return
94 True if this is empty.
100 def to_proto(self) -> infeasible_subsystem_pb2.ModelSubsetProto:
101 """Returns an equivalent proto message for this `ModelSubset`."""
102 return infeasible_subsystem_pb2.ModelSubsetProto(
104 var.id: bounds.to_proto()
109 con.id: bounds.to_proto()
116 model_subset: infeasible_subsystem_pb2.ModelSubsetProto, mod:
model.Model
118 """Returns an equivalent `ModelSubset` to the input proto."""
119 if model_subset.quadratic_constraints:
120 raise NotImplementedError(
121 "quadratic_constraints not yet implemented for ModelSubset in Python"
123 if model_subset.second_order_cone_constraints:
124 raise NotImplementedError(
125 "second_order_cone_constraints not yet implemented for ModelSubset in"
128 if model_subset.sos1_constraints:
129 raise NotImplementedError(
130 "sos1_constraints not yet implemented for ModelSubset in Python"
132 if model_subset.sos2_constraints:
133 raise NotImplementedError(
134 "sos2_constraints not yet implemented for ModelSubset in Python"
136 if model_subset.indicator_constraints:
137 raise NotImplementedError(
138 "indicator_constraints not yet implemented for ModelSubset in Python"
143 for var_id, bounds
in model_subset.variable_bounds.items()
145 variable_integrality=frozenset(
146 mod.get_variable(var_id)
for var_id
in model_subset.variable_integrality
150 for con_id, bounds
in model_subset.linear_constraints.items()
155@dataclasses.dataclass(frozen=True)
190 infeasible_system_result: infeasible_subsystem_pb2.ComputeInfeasibleSubsystemResultProto,
192) -> ComputeInfeasibleSubsystemResult:
193 """Returns an equivalent `ComputeInfeasibleSubsystemResult` to the input proto."""
197 infeasible_system_result.infeasible_subsystem, mod
199 is_minimal=infeasible_system_result.is_minimal,