src.environment.optimizer.basic_optimizer¶
This is the basic optimizer class. All traditional optimizers should inherit from this class. Your own traditional should have the following functions: 1. init(self, config) : to initialize the optimizer 2. run_episode(self, problem) : to run the optimizer for an episode
Module Contents¶
Classes¶
Basic_Optimizer serves as an abstract base class for optimization algorithms. It provides common functionality such as random seed management for reproducibility across NumPy and PyTorch (CPU and GPU). Subclasses should implement the |
API¶
- class src.environment.optimizer.basic_optimizer.Basic_Optimizer(config)[source]¶
Basic_Optimizer serves as an abstract base class for optimization algorithms. It provides common functionality such as random seed management for reproducibility across NumPy and PyTorch (CPU and GPU). Subclasses should implement the
run_episodemethod to define the specific optimization process for a given problem.config (object): Configuration object containing optimizer settings, including the target device (e.g., ‘cpu’ or ‘cuda’).
Attributes:¶
rng_seed (int or None): The random seed used for reproducibility.
rng (np.random.RandomState): NumPy random number generator initialized with the seed.
rng_cpu (torch.Generator): PyTorch CPU random number generator initialized with the seed.
rng_gpu (torch.Generator or None): PyTorch GPU random number generator initialized with the seed if device is not ‘cpu’.
Methods:¶
seed(seed=None): Sets the random seed for NumPy and PyTorch (CPU/GPU) generators.
run_episode(problem): Abstract method to execute a single optimization episode; must be implemented by subclasses.
NotImplementedError: If
run_episodeis called directly on the base class.
Initialization
- abstractmethod run_episode(problem: src.environment.problem.basic_problem.Basic_Problem)[source]¶
Introduction¶
Executes a single episode of the optimization process for the given problem instance.
Args:¶
problem (Basic_Problem): An instance of the optimization problem to be solved.
Returns:¶
None
Raises:¶
NotImplementedError: This method must be implemented by subclasses.