You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MIPLearn/miplearn/features.py

31 lines
996 B

# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
from typing import TYPE_CHECKING, Dict
from miplearn.types import ModelFeatures, ConstraintFeatures
if TYPE_CHECKING:
from miplearn import InternalSolver
class ModelFeaturesExtractor:
def __init__(
self,
internal_solver: "InternalSolver",
) -> None:
self.solver = internal_solver
def extract(self) -> ModelFeatures:
constraints: Dict[str, ConstraintFeatures] = {}
for cid in self.solver.get_constraint_ids():
constraints[cid] = {
"rhs": self.solver.get_constraint_rhs(cid),
"lhs": self.solver.get_constraint_lhs(cid),
"sense": self.solver.get_constraint_sense(cid),
}
return {
"constraints": constraints,
}