Source code for foxes_opt.core.farm_objective

from iwopy import Objective

from foxes.utils import new_instance, all_subclasses


[docs] class FarmObjective(Objective): """ Abstract base class for foxes wind farm objective functions. :group: opt.core """
[docs] def __init__(self, problem, name, sel_turbines=None, **kwargs): """ Constraints. Parameters ---------- problem: foxes_opt.FarmOptProblem The underlying optimization problem name: str The name of the objective function sel_turbines: list of int, optional The selected turbines kwargs: dict, optional Additional parameters for `iwopy.Objective` """ super().__init__(problem, name, **kwargs) self._sel_turbines = sel_turbines
@property def farm(self): """ The wind farm Returns ------- foxes.core.WindFarm : The wind farm """ return self.problem.farm @property def sel_turbines(self): """ The list of selected turbines Returns ------- list of int : The list of selected turbines """ return ( self.problem.sel_turbines if self._sel_turbines is None else self._sel_turbines ) @property def n_sel_turbines(self): """ The numer of selected turbines Returns ------- int : The numer of selected turbines """ return len(self.sel_turbines)
[docs] def add_to_layout_figure(self, ax, **kwargs): """ Add to a layout figure Parameters ---------- ax: matplotlib.pyplot.Axis The figure axis """ return ax
[docs] @classmethod def print_models(cls): """ Prints all model names. """ names = sorted([scls.__name__ for scls in all_subclasses(cls)]) for n in names: print(n)
[docs] @classmethod def new(cls, objective_type, *args, **kwargs): """ Run-time farm objective factory. Parameters ---------- objective_type: string The selected derived class name args: tuple, optional Additional parameters for the constructor kwargs: dict, optional Additional parameters for the constructor """ return new_instance(cls, objective_type, *args, **kwargs)