foxes_opt.core.farm_constraint

Classes

FarmConstraint

Abstract base class for foxes wind farm

Module Contents

class foxes_opt.core.farm_constraint.FarmConstraint(problem: foxes_opt.core.farm_opt_problem.FarmOptProblem, name: str, sel_turbines: list[int] | None = None, **kwargs: Any)[source]

Bases: iwopy.Constraint

Abstract base class for foxes wind farm optimization constraints.

Parameters:
problem

The underlying optimization problem

name

The name of the constraint

sel_turbines

The selected turbines

kwargs

Additional parameters for iwopy.Constraint

add_to_layout_figure(ax: matplotlib.axes.Axes, **kwargs: Any) → matplotlib.axes.Axes[source]

Add to a layout figure

Parameters:
ax

The figure axis

ana_deriv(vars_int, vars_float, var, components=None)

Calculates the analytic derivative, if possible.

Use numpy.nan if analytic derivatives cannot be calculated.

Parameters:
vars_int: np.array

The integer variable values, shape: (n_vars_int,)

vars_float: np.array

The float variable values, shape: (n_vars_float,)

var: int

The index of the differentiation float variable

components: list of int

The selected components, or None for all

Returns:
deriv: numpy.ndarray

The derivative values, shape: (n_sel_components,)

abstract calc_individual(vars_int, vars_float, problem_results, components=None)

Calculate values for a single individual of the underlying problem.

Parameters:
vars_int: np.array

The integer variable values, shape: (n_vars_int,)

vars_float: np.array

The float variable values, shape: (n_vars_float,)

problem_results: Any

The results of the variable application to the problem

components: list of int, optional

The selected components or None for all

Returns:
values: np.array

The component values, shape: (n_sel_components,)

calc_population(vars_int, vars_float, problem_results, components=None)

Calculate values for all individuals of a population.

Parameters:
vars_int: np.array

The integer variable values, shape: (n_pop, n_vars_int)

vars_float: np.array

The float variable values, shape: (n_pop, n_vars_float)

problem_results: Any

The results of the variable application to the problem

components: list of int, optional

The selected components or None for all

Returns:
values: np.array

The component values, shape: (n_pop, n_sel_components)

check_individual(constraint_values, verbosity=0)

Check if the constraints are fullfilled for the given individual.

Parameters:
constraint_values: np.array

The constraint values, shape: (n_components,)

verbosity: int

The verbosity level, 0 = silent

Returns
values: np.array
——-

The boolean result, shape: (n_components,)

check_population(constraint_values, verbosity=0)

Check if the constraints are fullfilled for the given population.

Parameters:
constraint_values: np.array

The constraint values, shape: (n_pop, n_components,)

verbosity: int

The verbosity level, 0 = silent

Returns:
values: np.array

The boolean result, shape: (n_pop, n_components)

finalize(verbosity=0)

Finalize the object.

Parameters:
verbosity: int

The verbosity level, 0 = silent

finalize_individual(vars_int, vars_float, problem_results, verbosity=1)

Finalization, given the champion data.

Parameters:
vars_int: np.array

The optimal integer variable values, shape: (n_vars_int,)

vars_float: np.array

The optimal float variable values, shape: (n_vars_float,)

problem_results: Any

The results of the variable application to the problem

verbosity: int

The verbosity level, 0 = silent

Returns:
values: np.array

The component values, shape: (n_components,)

finalize_population(vars_int, vars_float, problem_results, verbosity=1)

Finalization, given the final population data.

Parameters:
vars_int: np.array

The integer variable values of the final generation, shape: (n_pop, n_vars_int)

vars_float: np.array

The float variable values of the final generation, shape: (n_pop, n_vars_float)

problem_results: Any

The results of the variable application to the problem

verbosity: int

The verbosity level, 0 = silent

Returns:
values: np.array

The component values, shape: (n_pop, n_components)

get_bounds()

Returns the bounds for all components.

Non-existing bounds are expressed by np.inf.

Returns:
min: np.array

The lower bounds, shape: (n_components,)

max: np.array

The upper bounds, shape: (n_components,)

initialize(verbosity=0)

Initialize the object.

Parameters:
verbosity: int

The verbosity level, 0 = silent

abstract n_components()

Returns the number of components of the function.

Returns:
int:

The number of components.

classmethod new(constraint_type: str, *args: Any, **kwargs: Any) → Any[source]

Run-time farm constraint factory.

Parameters:
constraint_type

The selected derived class name

args

Additional parameters for the constructor

kwargs

Additional parameters for the constructor

classmethod print_models() → None[source]

Prints all model names.

rename_vars_float(varmap)

Rename float variables.

Parameters:
varmap: dict

The name mapping. Key: old name str, Value: new name str

rename_vars_int(varmap)

Rename integer variables.

Parameters:
varmap: dict

The name mapping. Key: old name str, Value: new name str

vardeps_float()

Gets the dependencies of all components on the function float variables

Returns:
deps: numpy.ndarray of bool

The dependencies of components on function variables, shape: (n_components, n_vars_float)

vardeps_int()

Gets the dependencies of all components on the function int variables

Returns:
deps: numpy.ndarray of bool

The dependencies of components on function variables, shape: (n_components, n_vars_int)

property component_names

The names of the components

Returns:
names: list of str

The component names

property farm : foxes.core.WindFarm

The wind farm

Returns:
value

The wind farm

property initialized

Flag for finished initialization

Returns:
bool

True if initialization has been done

property n_sel_turbines : int

The numer of selected turbines

Returns:
value

The numer of selected turbines

property n_vars_float

The number of float variables

Returns:
n: int

The number of float variables

property n_vars_int

The number of int variables

Returns:
n: int

The number of int variables

name
problem
property sel_turbines : list[int]

The list of selected turbines

Returns:
value

The list of selected turbines

tol = 1e-05
property var_names_float

The names of the float variables

Returns:
names: list of str

The float variable names

property var_names_int

The names of the integer variables

Returns:
names: list of str

The integer variable names