mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Remove sample.after_mip
This commit is contained in:
@@ -95,13 +95,12 @@ class ObjectiveValueComponent(Component):
|
||||
|
||||
# Labels
|
||||
y: Dict[Hashable, List[List[float]]] = {}
|
||||
if sample.after_mip is not None:
|
||||
mip_stats = sample.after_mip.mip_solve
|
||||
assert mip_stats is not None
|
||||
if mip_stats.mip_lower_bound is not None:
|
||||
y["Lower bound"] = [[mip_stats.mip_lower_bound]]
|
||||
if mip_stats.mip_upper_bound is not None:
|
||||
y["Upper bound"] = [[mip_stats.mip_upper_bound]]
|
||||
mip_lower_bound = sample.get("mip_lower_bound")
|
||||
mip_upper_bound = sample.get("mip_upper_bound")
|
||||
if mip_lower_bound is not None:
|
||||
y["Lower bound"] = [[mip_lower_bound]]
|
||||
if mip_upper_bound is not None:
|
||||
y["Upper bound"] = [[mip_upper_bound]]
|
||||
|
||||
return x, y
|
||||
|
||||
@@ -111,9 +110,6 @@ class ObjectiveValueComponent(Component):
|
||||
instance: Instance,
|
||||
sample: Sample,
|
||||
) -> Dict[Hashable, Dict[str, float]]:
|
||||
assert sample.after_mip is not None
|
||||
assert sample.after_mip.mip_solve is not None
|
||||
|
||||
def compare(y_pred: float, y_actual: float) -> Dict[str, float]:
|
||||
err = np.round(abs(y_pred - y_actual), 8)
|
||||
return {
|
||||
@@ -125,8 +121,8 @@ class ObjectiveValueComponent(Component):
|
||||
|
||||
result: Dict[Hashable, Dict[str, float]] = {}
|
||||
pred = self.sample_predict(sample)
|
||||
actual_ub = sample.after_mip.mip_solve.mip_upper_bound
|
||||
actual_lb = sample.after_mip.mip_solve.mip_lower_bound
|
||||
actual_ub = sample.get("mip_upper_bound")
|
||||
actual_lb = sample.get("mip_lower_bound")
|
||||
if actual_ub is not None:
|
||||
result["Upper bound"] = compare(pred["Upper bound"], actual_ub)
|
||||
if actual_lb is not None:
|
||||
|
||||
@@ -155,6 +155,7 @@ class PrimalSolutionComponent(Component):
|
||||
assert sample.after_load.variables is not None
|
||||
assert sample.after_load.variables.names is not None
|
||||
assert sample.after_load.variables.categories is not None
|
||||
mip_var_values = sample.get("mip_var_values")
|
||||
|
||||
for (i, var_name) in enumerate(sample.after_load.variables.names):
|
||||
# Initialize categories
|
||||
@@ -174,10 +175,8 @@ class PrimalSolutionComponent(Component):
|
||||
x[category].append(features)
|
||||
|
||||
# Labels
|
||||
if sample.after_mip is not None:
|
||||
assert sample.after_mip.variables is not None
|
||||
assert sample.after_mip.variables.values is not None
|
||||
opt_value = sample.after_mip.variables.values[i]
|
||||
if mip_var_values is not None:
|
||||
opt_value = mip_var_values[i]
|
||||
assert opt_value is not None
|
||||
assert 0.0 - 1e-5 <= opt_value <= 1.0 + 1e-5, (
|
||||
f"Variable {var_name} has non-binary value {opt_value} in the "
|
||||
@@ -194,14 +193,13 @@ class PrimalSolutionComponent(Component):
|
||||
_: Optional[Instance],
|
||||
sample: Sample,
|
||||
) -> Dict[Hashable, Dict[str, float]]:
|
||||
assert sample.after_mip is not None
|
||||
assert sample.after_mip.variables is not None
|
||||
assert sample.after_mip.variables.values is not None
|
||||
assert sample.after_mip.variables.names is not None
|
||||
mip_var_values = sample.get("mip_var_values")
|
||||
var_names = sample.get("var_names")
|
||||
assert mip_var_values is not None
|
||||
assert var_names is not None
|
||||
|
||||
solution_actual = {
|
||||
var_name: sample.after_mip.variables.values[i]
|
||||
for (i, var_name) in enumerate(sample.after_mip.variables.names)
|
||||
var_name: mip_var_values[i] for (i, var_name) in enumerate(var_names)
|
||||
}
|
||||
solution_pred = self.sample_predict(sample)
|
||||
vars_all, vars_one, vars_zero = set(), set(), set()
|
||||
|
||||
Reference in New Issue
Block a user