foxes_opt.constraints.min_dist

Classes

MinDistConstraint

Turbines must keep at least a minimal

MinDistLocalConstraint

Turbines must keep at least a minimal spatial distance,

Module Contents

class foxes_opt.constraints.min_dist.MinDistConstraint(problem: foxes_opt.core.farm_opt_problem.FarmOptProblem, min_dist: float, min_dist_unit: str = 'm', name: str = 'dist', sel_turbines: list[int] | None = None, infer_vars: bool = True, check_only_selected: bool = False, **kwargs: Any)[source]

Bases: foxes_opt.core.farm_constraint.FarmConstraint

Turbines must keep at least a minimal spatial distance.

Parameters:
problem

The underlying optimization problem

min_dist

The minimal distance

min_dist_unit

The minimal distance unit, either m or D

name

The name of the constraint

sel_turbines

The selected turbines

infer_vars

Whether to infer the float variables automatically

check_only_selected

Whether to check distances only among selected turbines

kwargs

Additional parameters for iwopy.Constraint

active_components(vars_float: numpy.ndarray, lower: numpy.ndarray, upper: numpy.ndarray) → numpy.ndarray[source]

Select pairs that can approach the spacing limit within bounds.

Parameters:
vars_float

Initial values in this constraint’s float-variable order.

lower, upper

Enforced coordinate bounds in the same order, in metres. Unselected turbine positions remain fixed.

Returns:
components

Stable pair-component indices whose coordinate boxes can approach the nominal minimum distance. Omitted pairs are separated throughout the box. Component metadata, full values and feasibility checks remain unchanged. Unbounded coordinates are handled conservatively. Unsupported variable parameterizations, variable diameters and state-dependent coordinates retain all pairs.

Raises:
ValueError

If the minimum-distance unit is neither m nor D.

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

Add to a layout figure

Parameters:
ax

The figure axis

ana_deriv(vars_int: numpy.ndarray, vars_float: numpy.ndarray, var: int, components: collections.abc.Sequence[int] | numpy.ndarray | None = None) → numpy.ndarray[source]

Calculate the analytical derivative for one float variable.

Parameters:
vars_int

The integer variable values

vars_float

The float variable values

var

The float variable index

components

The selected components, or None for all

Returns:
deriv

The derivative values, shape: (n_sel_components,)

calc_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: Any, components: list[int] | None = None) → numpy.ndarray[source]

Calculate values for a single individual of the underlying problem.

Parameters:
vars_int

The integer variable values, shape: (n_vars_int,)

vars_float

The float variable values, shape: (n_vars_float,)

problem_results

The results of the variable application to the problem

components

The selected components or None for all

Returns:
values

The component values, shape: (n_sel_components,)

calc_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: Any, components: list[int] | None = None) → numpy.ndarray[source]

Calculate values for all individuals of a population.

Parameters:
vars_int

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

vars_float

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

problem_results

The results of the variable application to the problem

components

The selected components or None for all

Returns:
values

The component values, shape: (n_pop, n_sel_components)

check_individual(constraint_values: numpy.ndarray, verbosity: int = 0) → numpy.ndarray

Check if the constraints are fullfilled for the given individual.

Parameters:
constraint_values

The constraint values, shape: (n_components,)

verbosity

The verbosity level, 0 = silent

Returns:
values

The boolean result, shape: (n_components,)

check_population(constraint_values: numpy.ndarray, verbosity: int = 0) → numpy.ndarray

Check if the constraints are fullfilled for the given population.

Parameters:
constraint_values

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

verbosity

The verbosity level, 0 = silent

Returns:
values

The boolean result, shape: (n_pop, n_components)

component_turbines(components: collections.abc.Sequence[int] | numpy.ndarray | None = None) → set[int]

Return turbines associated with constraint components.

Parameters:
components

The selected component indices, or None for all components.

Returns:
turbines

The associated turbine indices.

finalize(verbosity: int = 0, /) → None
finalize(*, verbosity: int = 0) → None

Finalize the object.

Parameters:
verbosity

The verbosity level, 0 = silent

finalize_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: object, verbosity: int = 1) → numpy.ndarray

Finalization, given the champion data.

Parameters:
vars_int

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

vars_float

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

problem_results

The results of the variable application to the problem

verbosity

The verbosity level, 0 = silent

Returns:
values

The component values, shape: (n_components,)

finalize_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: object, verbosity: int = 1) → numpy.ndarray

Finalization, given the final population data.

Parameters:
vars_int

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

vars_float

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

problem_results

The results of the variable application to the problem

verbosity

The verbosity level, 0 = silent

Returns:
values

The component values, shape: (n_pop, n_components)

get_bounds() → tuple[numpy.ndarray, numpy.ndarray]

Returns the bounds for all components.

Non-existing bounds are expressed by np.inf.

Returns:
min

The lower bounds, shape: (n_components,)

max

The upper bounds, shape: (n_components,)

initialize(verbosity: int = 0) → None[source]

Initialize the constaint.

Parameters:
verbosity

The verbosity level, 0 = silent

n_components() → int[source]

Returns the number of components of the function.

Returns:
value

The number of components.

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

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

Prints all model names.

rename_vars_float(varmap: collections.abc.Mapping[str | int, str]) → None

Rename float variables.

Parameters:
varmap

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

rename_vars_int(varmap: collections.abc.Mapping[str | int, str]) → None

Rename integer variables.

Parameters:
varmap

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

vardeps_float() → numpy.ndarray[tuple[int, int], numpy.dtype[Any]][source]

Gets the dependencies of all components on the function float variables

Returns:
deps

The dependencies of components on function variables, shape

vardeps_int() → numpy.ndarray

Gets the dependencies of all components on the function int variables

Returns:
deps

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

check_only_selected = False
property component_names : list[str]

The names of the components

Returns:
names

The component names

property farm : foxes.core.WindFarm

The wind farm

Returns:
value

The wind farm

property initialized : bool

Flag for finished initialization

Returns:
initialized

True if initialization has been done

min_dist : float
min_dist_unit : str = 'm'
property n_sel_turbines : int

The numer of selected turbines

Returns:
value

The numer of selected turbines

property n_vars_float : int

The number of float variables

Returns:
n

The number of float variables

property n_vars_int : int

The number of int variables

Returns:
n

The number of int variables

name = 'Base'
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 : list[str]

The names of the float variables

Returns:
names

The float variable names

property var_names_int : list[str]

The names of the integer variables

Returns:
names

The integer variable names

class foxes_opt.constraints.min_dist.MinDistLocalConstraint(problem: foxes_opt.core.farm_opt_problem.FarmOptProblem, min_dist: float, min_dist_unit: str = 'm', name: str = 'dist', sel_turbines: list[int] | None = None, infer_vars: bool = True, check_only_selected: bool = False, max_move: float | None = None, **kwargs: Any)[source]

Bases: MinDistConstraint

Turbines must keep at least a minimal spatial distance, checking only pairs that can violate the distance in a local move problem.

Parameters:
problem

The underlying local move optimization problem

min_dist

The minimal distance

min_dist_unit

The minimal distance unit, either m or D

name

The name of the constraint

sel_turbines

The selected turbines

infer_vars

Whether to infer the float variables automatically

check_only_selected

Whether to check distances only among selected turbines

max_move

The maximal local displacement per selected turbine. If None, infer from problem.radius or problem.square_length.

kwargs

Additional parameters for iwopy.Constraint

active_components(vars_float: numpy.ndarray, lower: numpy.ndarray, upper: numpy.ndarray) → numpy.ndarray

Select pairs that can approach the spacing limit within bounds.

Parameters:
vars_float

Initial values in this constraint’s float-variable order.

lower, upper

Enforced coordinate bounds in the same order, in metres. Unselected turbine positions remain fixed.

Returns:
components

Stable pair-component indices whose coordinate boxes can approach the nominal minimum distance. Omitted pairs are separated throughout the box. Component metadata, full values and feasibility checks remain unchanged. Unbounded coordinates are handled conservatively. Unsupported variable parameterizations, variable diameters and state-dependent coordinates retain all pairs.

Raises:
ValueError

If the minimum-distance unit is neither m nor D.

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

Add to a layout figure

Parameters:
ax

The figure axis

ana_deriv(vars_int: numpy.ndarray, vars_float: numpy.ndarray, var: int, components: collections.abc.Sequence[int] | numpy.ndarray | None = None) → numpy.ndarray

Calculate the analytical derivative for one float variable.

Parameters:
vars_int

The integer variable values

vars_float

The float variable values

var

The float variable index

components

The selected components, or None for all

Returns:
deriv

The derivative values, shape: (n_sel_components,)

calc_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: Any, components: list[int] | None = None) → numpy.ndarray

Calculate values for a single individual of the underlying problem.

Parameters:
vars_int

The integer variable values, shape: (n_vars_int,)

vars_float

The float variable values, shape: (n_vars_float,)

problem_results

The results of the variable application to the problem

components

The selected components or None for all

Returns:
values

The component values, shape: (n_sel_components,)

calc_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: Any, components: list[int] | None = None) → numpy.ndarray

Calculate values for all individuals of a population.

Parameters:
vars_int

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

vars_float

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

problem_results

The results of the variable application to the problem

components

The selected components or None for all

Returns:
values

The component values, shape: (n_pop, n_sel_components)

check_individual(constraint_values: numpy.ndarray, verbosity: int = 0) → numpy.ndarray

Check if the constraints are fullfilled for the given individual.

Parameters:
constraint_values

The constraint values, shape: (n_components,)

verbosity

The verbosity level, 0 = silent

Returns:
values

The boolean result, shape: (n_components,)

check_population(constraint_values: numpy.ndarray, verbosity: int = 0) → numpy.ndarray

Check if the constraints are fullfilled for the given population.

Parameters:
constraint_values

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

verbosity

The verbosity level, 0 = silent

Returns:
values

The boolean result, shape: (n_pop, n_components)

component_turbines(components: collections.abc.Sequence[int] | numpy.ndarray | None = None) → set[int]

Return turbines associated with constraint components.

Parameters:
components

The selected component indices, or None for all components.

Returns:
turbines

The associated turbine indices.

finalize(verbosity: int = 0, /) → None
finalize(*, verbosity: int = 0) → None

Finalize the object.

Parameters:
verbosity

The verbosity level, 0 = silent

finalize_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: object, verbosity: int = 1) → numpy.ndarray

Finalization, given the champion data.

Parameters:
vars_int

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

vars_float

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

problem_results

The results of the variable application to the problem

verbosity

The verbosity level, 0 = silent

Returns:
values

The component values, shape: (n_components,)

finalize_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, problem_results: object, verbosity: int = 1) → numpy.ndarray

Finalization, given the final population data.

Parameters:
vars_int

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

vars_float

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

problem_results

The results of the variable application to the problem

verbosity

The verbosity level, 0 = silent

Returns:
values

The component values, shape: (n_pop, n_components)

get_bounds() → tuple[numpy.ndarray, numpy.ndarray]

Returns the bounds for all components.

Non-existing bounds are expressed by np.inf.

Returns:
min

The lower bounds, shape: (n_components,)

max

The upper bounds, shape: (n_components,)

initialize(verbosity: int = 0) → None[source]

Initialize the constaint.

Parameters:
verbosity

The verbosity level, 0 = silent

n_components() → int

Returns the number of components of the function.

Returns:
value

The number of components.

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

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

Prints all model names.

rename_vars_float(varmap: collections.abc.Mapping[str | int, str]) → None

Rename float variables.

Parameters:
varmap

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

rename_vars_int(varmap: collections.abc.Mapping[str | int, str]) → None

Rename integer variables.

Parameters:
varmap

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

vardeps_float() → numpy.ndarray[tuple[int, int], numpy.dtype[Any]]

Gets the dependencies of all components on the function float variables

Returns:
deps

The dependencies of components on function variables, shape

vardeps_int() → numpy.ndarray

Gets the dependencies of all components on the function int variables

Returns:
deps

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

check_only_selected = False
property component_names : list[str]

The names of the components

Returns:
names

The component names

property farm : foxes.core.WindFarm

The wind farm

Returns:
value

The wind farm

property initialized : bool

Flag for finished initialization

Returns:
initialized

True if initialization has been done

max_move = None
min_dist : float
min_dist_unit : str = 'm'
property n_sel_turbines : int

The numer of selected turbines

Returns:
value

The numer of selected turbines

property n_vars_float : int

The number of float variables

Returns:
n

The number of float variables

property n_vars_int : int

The number of int variables

Returns:
n

The number of int variables

name = 'Base'
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 : list[str]

The names of the float variables

Returns:
names

The float variable names

property var_names_int : list[str]

The names of the integer variables

Returns:
names

The integer variable names