mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Add StaticLazyComponent.xy
This commit is contained in:
@@ -5,12 +5,14 @@
|
||||
import logging
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
import numpy as np
|
||||
from tqdm.auto import tqdm
|
||||
|
||||
from miplearn.classifiers.counting import CountingClassifier
|
||||
from miplearn.components.component import Component
|
||||
from miplearn.types import TrainingSample
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -202,3 +204,26 @@ class StaticLazyConstraintsComponent(Component):
|
||||
else:
|
||||
result[category].append([1, 0])
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def xy_sample(
|
||||
instance: Any,
|
||||
sample: TrainingSample,
|
||||
) -> Tuple[Dict, Dict]:
|
||||
x: Dict = {}
|
||||
y: Dict = {}
|
||||
if "LazyStatic: All" not in sample:
|
||||
return x, y
|
||||
for cid in sorted(sample["LazyStatic: All"]):
|
||||
category = instance.get_constraint_category(cid)
|
||||
if category is None:
|
||||
continue
|
||||
if category not in x:
|
||||
x[category] = []
|
||||
y[category] = []
|
||||
x[category] += [instance.get_constraint_features(cid)]
|
||||
if cid in sample["LazyStatic: Enforced"]:
|
||||
y[category] += [[False, True]]
|
||||
else:
|
||||
y[category] += [[True, False]]
|
||||
return x, y
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
from typing import Optional, Dict, Callable, Any, Union, Tuple, List
|
||||
from typing import Optional, Dict, Callable, Any, Union, Tuple, List, Set
|
||||
|
||||
from mypy_extensions import TypedDict
|
||||
|
||||
@@ -16,6 +16,8 @@ TrainingSample = TypedDict(
|
||||
"LP log": str,
|
||||
"LP solution": Optional[Solution],
|
||||
"LP value": Optional[float],
|
||||
"LazyStatic: All": Set[str],
|
||||
"LazyStatic: Enforced": Set[str],
|
||||
"Lower bound": Optional[float],
|
||||
"MIP log": str,
|
||||
"Solution": Optional[Solution],
|
||||
|
||||
Reference in New Issue
Block a user