# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization # Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved. # Released under the modified BSD license. See COPYING.md for more details. from abc import ABC, abstractmethod from typing import Dict, Optional, Any class Sample(ABC): """Abstract dictionary-like class that stores training data.""" @abstractmethod def get(self, key: str) -> Optional[Any]: pass @abstractmethod def put(self, key: str, value: Any) -> None: pass class MemorySample(Sample): """Dictionary-like class that stores training data in-memory.""" def __init__( self, data: Optional[Dict[str, Any]] = None, ) -> None: if data is None: data = {} self._data: Dict[str, Any] = data def get(self, key: str) -> Optional[Any]: if key in self._data: return self._data[key] else: return None def put(self, key: str, value: Any) -> None: self._data[key] = value