mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Remove sample.{get,set}
This commit is contained in:
@@ -52,7 +52,7 @@ class DynamicConstraintsComponent(Component):
|
||||
cids: Dict[str, List[str]] = {}
|
||||
constr_categories_dict = instance.get_constraint_categories()
|
||||
constr_features_dict = instance.get_constraint_features()
|
||||
instance_features = sample.get("instance_features_user")
|
||||
instance_features = sample.get_vector("instance_features_user")
|
||||
assert instance_features is not None
|
||||
for cid in self.known_cids:
|
||||
# Initialize categories
|
||||
@@ -81,7 +81,7 @@ class DynamicConstraintsComponent(Component):
|
||||
cids[category].append(cid)
|
||||
|
||||
# Labels
|
||||
enforced_cids = sample.get(self.attr)
|
||||
enforced_cids = sample.get_set(self.attr)
|
||||
if enforced_cids is not None:
|
||||
if cid in enforced_cids:
|
||||
y[category] += [[False, True]]
|
||||
@@ -132,7 +132,7 @@ class DynamicConstraintsComponent(Component):
|
||||
|
||||
@overrides
|
||||
def pre_sample_xy(self, instance: Instance, sample: Sample) -> Any:
|
||||
return sample.get(self.attr)
|
||||
return sample.get_set(self.attr)
|
||||
|
||||
@overrides
|
||||
def fit_xy(
|
||||
@@ -154,7 +154,7 @@ class DynamicConstraintsComponent(Component):
|
||||
instance: Instance,
|
||||
sample: Sample,
|
||||
) -> Dict[str, Dict[str, float]]:
|
||||
actual = sample.get(self.attr)
|
||||
actual = sample.get_set(self.attr)
|
||||
assert actual is not None
|
||||
pred = set(self.sample_predict(instance, sample))
|
||||
tp: Dict[str, int] = {}
|
||||
|
||||
@@ -78,7 +78,7 @@ class DynamicLazyConstraintsComponent(Component):
|
||||
stats: LearningSolveStats,
|
||||
sample: Sample,
|
||||
) -> None:
|
||||
sample.put("lazy_enforced", set(self.lazy_enforced))
|
||||
sample.put_set("lazy_enforced", set(self.lazy_enforced))
|
||||
|
||||
@overrides
|
||||
def iteration_cb(
|
||||
|
||||
@@ -87,7 +87,7 @@ class UserCutsComponent(Component):
|
||||
stats: LearningSolveStats,
|
||||
sample: Sample,
|
||||
) -> None:
|
||||
sample.put("user_cuts_enforced", set(self.enforced))
|
||||
sample.put_set("user_cuts_enforced", set(self.enforced))
|
||||
stats["UserCuts: Added in callback"] = self.n_added_in_callback
|
||||
if self.n_added_in_callback > 0:
|
||||
logger.info(f"{self.n_added_in_callback} user cuts added in callback")
|
||||
|
||||
@@ -77,9 +77,9 @@ class ObjectiveValueComponent(Component):
|
||||
_: Optional[Instance],
|
||||
sample: Sample,
|
||||
) -> Tuple[Dict[str, List[List[float]]], Dict[str, List[List[float]]]]:
|
||||
lp_instance_features = sample.get("lp_instance_features")
|
||||
lp_instance_features = sample.get_vector("lp_instance_features")
|
||||
if lp_instance_features is None:
|
||||
lp_instance_features = sample.get("instance_features_user")
|
||||
lp_instance_features = sample.get_vector("instance_features_user")
|
||||
assert lp_instance_features is not None
|
||||
|
||||
# Features
|
||||
@@ -90,8 +90,8 @@ class ObjectiveValueComponent(Component):
|
||||
|
||||
# Labels
|
||||
y: Dict[str, List[List[float]]] = {}
|
||||
mip_lower_bound = sample.get("mip_lower_bound")
|
||||
mip_upper_bound = sample.get("mip_upper_bound")
|
||||
mip_lower_bound = sample.get_scalar("mip_lower_bound")
|
||||
mip_upper_bound = sample.get_scalar("mip_upper_bound")
|
||||
if mip_lower_bound is not None:
|
||||
y["Lower bound"] = [[mip_lower_bound]]
|
||||
if mip_upper_bound is not None:
|
||||
@@ -116,8 +116,8 @@ class ObjectiveValueComponent(Component):
|
||||
|
||||
result: Dict[str, Dict[str, float]] = {}
|
||||
pred = self.sample_predict(sample)
|
||||
actual_ub = sample.get("mip_upper_bound")
|
||||
actual_lb = sample.get("mip_lower_bound")
|
||||
actual_ub = sample.get_scalar("mip_upper_bound")
|
||||
actual_lb = sample.get_scalar("mip_lower_bound")
|
||||
if actual_ub is not None:
|
||||
result["Upper bound"] = compare(pred["Upper bound"], actual_ub)
|
||||
if actual_lb is not None:
|
||||
|
||||
@@ -95,8 +95,8 @@ class PrimalSolutionComponent(Component):
|
||||
)
|
||||
|
||||
def sample_predict(self, sample: Sample) -> Solution:
|
||||
var_names = sample.get("var_names")
|
||||
var_categories = sample.get("var_categories")
|
||||
var_names = sample.get_vector("var_names")
|
||||
var_categories = sample.get_vector("var_categories")
|
||||
assert var_names is not None
|
||||
assert var_categories is not None
|
||||
|
||||
@@ -142,13 +142,13 @@ class PrimalSolutionComponent(Component):
|
||||
) -> Tuple[Dict[Category, List[List[float]]], Dict[Category, List[List[float]]]]:
|
||||
x: Dict = {}
|
||||
y: Dict = {}
|
||||
instance_features = sample.get("instance_features_user")
|
||||
mip_var_values = sample.get("mip_var_values")
|
||||
var_features = sample.get("lp_var_features")
|
||||
var_names = sample.get("var_names")
|
||||
var_categories = sample.get("var_categories")
|
||||
instance_features = sample.get_vector("instance_features_user")
|
||||
mip_var_values = sample.get_vector("mip_var_values")
|
||||
var_features = sample.get_vector_list("lp_var_features")
|
||||
var_names = sample.get_vector("var_names")
|
||||
var_categories = sample.get_vector("var_categories")
|
||||
if var_features is None:
|
||||
var_features = sample.get("var_features")
|
||||
var_features = sample.get_vector_list("var_features")
|
||||
assert instance_features is not None
|
||||
assert var_features is not None
|
||||
assert var_names is not None
|
||||
@@ -187,8 +187,8 @@ class PrimalSolutionComponent(Component):
|
||||
_: Optional[Instance],
|
||||
sample: Sample,
|
||||
) -> Dict[str, Dict[str, float]]:
|
||||
mip_var_values = sample.get("mip_var_values")
|
||||
var_names = sample.get("var_names")
|
||||
mip_var_values = sample.get_vector("mip_var_values")
|
||||
var_names = sample.get_vector("var_names")
|
||||
assert mip_var_values is not None
|
||||
assert var_names is not None
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class StaticLazyConstraintsComponent(Component):
|
||||
stats: LearningSolveStats,
|
||||
sample: Sample,
|
||||
) -> None:
|
||||
sample.put("lazy_enforced", self.enforced_cids)
|
||||
sample.put_set("lazy_enforced", self.enforced_cids)
|
||||
stats["LazyStatic: Restored"] = self.n_restored
|
||||
stats["LazyStatic: Iterations"] = self.n_iterations
|
||||
|
||||
@@ -75,7 +75,7 @@ class StaticLazyConstraintsComponent(Component):
|
||||
sample: Sample,
|
||||
) -> None:
|
||||
assert solver.internal_solver is not None
|
||||
static_lazy_count = sample.get("static_lazy_count")
|
||||
static_lazy_count = sample.get_scalar("static_lazy_count")
|
||||
assert static_lazy_count is not None
|
||||
|
||||
logger.info("Predicting violated (static) lazy constraints...")
|
||||
@@ -204,14 +204,14 @@ class StaticLazyConstraintsComponent(Component):
|
||||
x: Dict[str, List[List[float]]] = {}
|
||||
y: Dict[str, List[List[float]]] = {}
|
||||
cids: Dict[str, List[str]] = {}
|
||||
instance_features = sample.get("instance_features_user")
|
||||
constr_features = sample.get("lp_constr_features")
|
||||
constr_names = sample.get("constr_names")
|
||||
constr_categories = sample.get("constr_categories")
|
||||
constr_lazy = sample.get("constr_lazy")
|
||||
lazy_enforced = sample.get("lazy_enforced")
|
||||
instance_features = sample.get_vector("instance_features_user")
|
||||
constr_features = sample.get_vector_list("lp_constr_features")
|
||||
constr_names = sample.get_vector("constr_names")
|
||||
constr_categories = sample.get_vector("constr_categories")
|
||||
constr_lazy = sample.get_vector("constr_lazy")
|
||||
lazy_enforced = sample.get_set("lazy_enforced")
|
||||
if constr_features is None:
|
||||
constr_features = sample.get("constr_features_user")
|
||||
constr_features = sample.get_vector_list("constr_features_user")
|
||||
|
||||
assert instance_features is not None
|
||||
assert constr_features is not None
|
||||
|
||||
Reference in New Issue
Block a user