foxes_opt.problems.layout.geom_layouts.geom_reggrid

Classes

GeomRegGrid

A regular grid within a boundary geometry.

Module Contents

class foxes_opt.problems.layout.geom_layouts.geom_reggrid.GeomRegGrid(boundary: foxes.utils.geom2d.AreaGeometry, n_turbines: int, min_dist: float, max_dist: float | None = None, D: float | None = None)[source]

Bases: iwopy.Problem

A regular grid within a boundary geometry.

This optimization problem does not involve wind farms.

Parameters:
boundary

The boundary geometry

n_turbines

The number of turbines in the layout

min_dist

The minimal distance between points

max_dist

The maximal distance between points

D

The diameter of circle fully within boundary

add_constraint(constraint: iwopy.core.constraint.Constraint, varmap_int: collections.abc.Mapping[str | int, str | int | numpy.integer] | None = None, varmap_float: collections.abc.Mapping[str | int, str | int | numpy.integer] | None = None, verbosity: int = 0) → None

Add a constraint to the problem.

Parameters:
constraint

The constraint

varmap_int

Mapping from objective variables to problem variables. Key: str or int, value: str or int

varmap_float

Mapping from objective variables to problem variables. Key: str or int, value: str or int

verbosity

The verbosity level, 0 = silent

add_objective(objective: iwopy.core.objective.Objective, varmap_int: collections.abc.Mapping[str | int, str | int | numpy.integer] | None = None, varmap_float: collections.abc.Mapping[str | int, str | int | numpy.integer] | None = None, verbosity: int = 0) → None

Add an objective to the problem.

Parameters:
objective

The objective

varmap_int

Mapping from objective variables to problem variables. Key: str or int, value: str or int

varmap_float

Mapping from objective variables to problem variables. Key: str or int, value: str or int

verbosity

The verbosity level, 0 = silent

apply_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray) → tuple[numpy.ndarray, numpy.ndarray][source]

Apply new variables to the problem.

Parameters:
vars_int

The integer variable values, shape: (n_vars_int,)

vars_float

The float variable values, shape: (n_vars_float,)

Returns:
problem_results

The results of the variable application to the problem

apply_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray) → tuple[numpy.ndarray, numpy.ndarray][source]

Apply new variables to the problem, for a whole 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)

Returns:
problem_results

The results of the variable application to the problem

calc_jacobian(vars_int: numpy.ndarray, vars_float: numpy.ndarray, func: iwopy.core.function.OptFunction, components: collections.abc.Sequence[int] | numpy.ndarray | None, ivars: list[int], fvars: list[int], vrs: list[int], pop: bool = False, verbosity: int = 0, func_values: numpy.ndarray | None = None, max_deltas: numpy.ndarray | None = None) → scipy.sparse.csr_matrix

Assemble a CSR Jacobian from analytical partial derivatives.

Call get_jacobian instead of calling this method directly. Derived classes can supply numerical derivatives for unresolved entries.

Parameters:
vars_int

The integer variable values, shape: (n_vars_int,)

vars_float

The float variable values, shape: (n_vars_float,)

func

The initialized function to differentiate.

components

Component indices in the requested row order, or None for all.

ivars

The indices of the function int variables in the problem

fvars

The indices of the function float variables in the problem

vrs

The function float variable indices wrt which the derivatives are to be calculated

func_values

Previously calculated values for the selected components, with shape (n_components,). The analytical implementation ignores them.

max_deltas

Positive finite call-local displacement caps in complete problem float-variable order, shape (n_vars_float,). Ignored analytically.

pop

Flag for vectorizing calculations via population

verbosity

The verbosity level, 0 = silent

Returns:
jacobian

CSR Jacobian with shape (n_components, n_vrs). Independent entries and exact zeros are not stored. Unavailable analytical derivatives remain explicitly stored as NaN.

check_constraints_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_constraints_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)

evaluate_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray, ret_prob_res: False = False) → tuple[numpy.ndarray, numpy.ndarray]
evaluate_individual(vars_int: numpy.ndarray, vars_float: numpy.ndarray, ret_prob_res: True) → tuple[numpy.ndarray, numpy.ndarray, object | None]

Evaluate a single individual of the problem.

Parameters:
vars_int

The integer variable values, shape: (n_vars_int,)

vars_float

The float variable values, shape: (n_vars_float,)

ret_prob_res

Flag for additionally returning of problem results

Returns:
objs

The objective function values, shape: (n_objectives,)

con

The constraints values, shape: (n_constraints,)

prob_res

The problem results

evaluate_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, ret_prob_res: False = False) → tuple[numpy.ndarray, numpy.ndarray]
evaluate_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, ret_prob_res: True) → tuple[numpy.ndarray, numpy.ndarray, object | None]

Evaluate 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)

ret_prob_res

Flag for additionally returning of problem results

Returns:
objs

The objective function values, shape: (n_pop, n_objectives)

cons

The constraints values, shape: (n_pop, n_constraints)

prob_res

The problem results

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, verbosity: int = 1) → tuple[object | None, numpy.ndarray, 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,)

verbosity

The verbosity level, 0 = silent

Returns:
problem_results

The results of the variable application to the problem

objs

The objective function values, shape: (n_objectives,)

cons

The constraints values, shape: (n_constraints,)

finalize_population(vars_int: numpy.ndarray, vars_float: numpy.ndarray, verbosity: int = 0) → tuple[object | None, numpy.ndarray, 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)

verbosity

The verbosity level, 0 = silent

Returns:
problem_results

The results of the variable application to the problem

objs

The final objective function values, shape: (n_pop, n_components)

cons

The final constraint values, shape: (n_pop, n_constraints)

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

Obtain bound-certified constraint components in problem order.

Parameters:
vars_float

Initial float variables, shape: (n_vars_float,).

lower, upper

Enforced bounds in problem float-variable order, with the same shape. Lower bounds must not exceed upper bounds.

Returns:
components

Sorted global constraint indices. Every omitted component must be certified feasible throughout the box by its owner.

Raises:
ValueError

If bounds have invalid shapes or a selector returns invalid or duplicate component indices.

get_fig(xy: numpy.ndarray | None = None, valid: numpy.ndarray | None = None, ax: Axes | None = None, title: str | None = None, true_circle: bool = True, **bargs: Any) → matplotlib.axes.Axes[source]

Return plotly figure axis.

Parameters:
xy

The xy coordinate array, shape: (n_points, 2)

valid

Boolean array of validity, shape: (n_points,)

ax

The figure axis

title

The figure title

true_circle

Draw points as circles with diameter self.D

bars

The boundary plot arguments

Returns:
ax

The figure axis

get_jacobian(vars_int: numpy.ndarray, vars_float: numpy.ndarray, func: iwopy.core.function.OptFunction | None = None, components: collections.abc.Sequence[int] | numpy.ndarray | None = None, vars: collections.abc.Sequence[str | int] | None = None, pop: bool = False, verbosity: int = 0, func_values: numpy.ndarray | None = None, max_deltas: numpy.ndarray | None = None) → scipy.sparse.csr_matrix

Obtain a CSR Jacobian for a function linked to this problem.

The func object typically is a iwopy.core.OptFunctionList object that contains a selection of objectives and/or constraints that were previously added to this problem. By default all objectives and constraints (and all their components) are being considered, cf. class ProblemDefaultFunc.

Parameters:
vars_int

The integer variable values, shape: (n_vars_int,)

vars_float

The float variable values, shape: (n_vars_float,)

func

The functions to be differentiated, or None for a list of all objectives and all constraints (in that order)

components

Component indices in the requested row order, or None for all.

vars

Floating variable names, integer problem-variable indices, or name patterns, or None for all problem floating variables. Selection order and repeated matches are preserved. Every selected variable must belong to the function.

func_values

Previously calculated values in the selected component order, with shape (n_components,). Numerical wrappers can reuse them.

max_deltas

Positive finite call-local displacement caps in complete problem float-variable order, shape (n_vars_float,). LocalFD uses the smaller of its configured delta and this cap. Analytical and fixed-grid derivatives are unchanged.

verbosity

The verbosity level, 0 = silent

pop

Flag for vectorizing calculations via population

Returns:
jacobian

CSR Jacobian with shape (n_components, n_vars). Rows follow the selected component order and columns the selected floating variable order. Independent entries and exact zeros are implicit. Use jacobian.toarray() when a dense array is required.

Raises:
ValueError

If the function belongs to another problem, a selected variable is unavailable, an analytical derivative remains unresolved, or displacement caps have invalid shapes or non-positive/non-finite values.

TypeError

If a variable selector is neither a name nor an integer index.

initial_values_float() → numpy.ndarray[source]

The initial values of the float variables.

Returns:
values

Initial float values, shape: (n_vars_float,)

initial_values_int() → numpy.typing.ArrayLike

The initial values of the integer variables.

Returns:
values

Initial int values, shape: (n_vars_int,)

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

Initialize the object.

Parameters:
verbosity

The verbosity level, 0 = silent

layout_derivative(vars_int: numpy.ndarray, vars_float: numpy.ndarray, var: int) → numpy.ndarray[source]

Calculate the layout derivative for one float variable.

Parameters:
vars_int

The integer variable values

vars_float

The float variable values

var

The float variable index

Returns:
derivative

Point-coordinate derivatives, shape: (n_turbines, 2)

max_values_float() → numpy.ndarray[source]

The maximal values of the float variables.

Use numpy.inf for unbounded.

Returns:
values

Maximal float values, shape: (n_vars_float,)

max_values_int() → numpy.typing.ArrayLike

The maximal values of the integer variables.

Use self.INT_INF for unbounded.

Returns:
values

Maximal int values, shape: (n_vars_int,)

min_values_float() → numpy.ndarray[source]

The minimal values of the float variables.

Use -numpy.inf for unbounded.

Returns:
values

Minimal float values, shape: (n_vars_float,)

min_values_int() → numpy.typing.ArrayLike

The minimal values of the integer variables.

Use -self.INT_INF for unbounded.

Returns:
values

Minimal int values, shape: (n_vars_int,)

classmethod new(problem_type: str, *args: object, **kwargs: object) → Problem

Run-time problem factory.

Parameters:
problem_type

The selected derived class name

args

Additional parameters for constructor

kwargs

Additional parameters for constructor

prob_res_einsum_individual(prob_res_list: collections.abc.Sequence[object | None], coeffs: numpy.ndarray) → object | None

Calculate the einsum of problem results

Parameters:
prob_res_list

The problem results

coeffs

The coefficients

Returns:
prob_res

The weighted sum of problem results

prob_res_einsum_population(prob_res_list: collections.abc.Sequence[object | None], coeffs: numpy.ndarray) → object | None

Calculate the einsum of problem results

Parameters:
prob_res_list

The problem results

coeffs

The coefficients

Returns:
prob_res

The weighted sum of problem results

var_names_float() → list[str][source]

The names of float variables.

Returns:
names

The names of the float variables

var_names_int() → list[str]

The names of integer variables.

Returns:
names

The names of the integer variables

D = None
INT_INF = -999999
boundary
cons : iwopy.core.function_list.OptFunctionList[iwopy.core.constraint.Constraint]
property initialized : bool

Flag for finished initialization

Returns:
initialized

True if initialization has been done

max_dist : float | None
property max_values_constraints : numpy.ndarray | None

Gets the maximal values of constraints

Returns:
cma

The maximal constraint values, shape: (n_constraints,)

property maximize_objs : numpy.ndarray

Flags for objective maximization

Returns:
maximize

Boolean flag for maximization of objective, shape: (n_objectives,)

memory : iwopy.core.memory.Memory | None = None
min_dist
property min_values_constraints : numpy.ndarray | None

Gets the minimal values of constraints

Returns:
cmi

The minimal constraint values, shape: (n_constraints,)

property n_constraints : int

The total number of constraints, i.e., the sum of all components

Returns:
n_con

The total number of constraint functions

property n_objectives : int

The total number of objectives, i.e., the sum of all components

Returns:
n_obj

The total number of objective functions

n_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'
objs : iwopy.core.function_list.OptFunctionList[iwopy.core.objective.Objective]