foxes 0.7.4.25__py3-none-any.whl → 0.8.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of foxes might be problematic. Click here for more details.
- foxes/VERSION +1 -1
- {foxes-0.7.4.25.dist-info → foxes-0.8.1.dist-info}/METADATA +20 -116
- {foxes-0.7.4.25.dist-info → foxes-0.8.1.dist-info}/RECORD +7 -33
- foxes/opt/__init__.py +0 -9
- foxes/opt/constraints/__init__.py +0 -6
- foxes/opt/constraints/area_geometry.py +0 -214
- foxes/opt/constraints/min_dist.py +0 -239
- foxes/opt/core/__init__.py +0 -9
- foxes/opt/core/farm_constraint.py +0 -96
- foxes/opt/core/farm_objective.py +0 -97
- foxes/opt/core/farm_opt_problem.py +0 -346
- foxes/opt/core/farm_vars_problem.py +0 -219
- foxes/opt/core/pop_states.py +0 -206
- foxes/opt/objectives/__init__.py +0 -6
- foxes/opt/objectives/farm_vars.py +0 -323
- foxes/opt/objectives/max_n_turbines.py +0 -142
- foxes/opt/problems/__init__.py +0 -7
- foxes/opt/problems/layout/__init__.py +0 -9
- foxes/opt/problems/layout/farm_layout.py +0 -137
- foxes/opt/problems/layout/geom_layouts/__init__.py +0 -10
- foxes/opt/problems/layout/geom_layouts/constraints.py +0 -802
- foxes/opt/problems/layout/geom_layouts/geom_layout.py +0 -290
- foxes/opt/problems/layout/geom_layouts/geom_layout_gridded.py +0 -276
- foxes/opt/problems/layout/geom_layouts/geom_reggrid.py +0 -351
- foxes/opt/problems/layout/geom_layouts/geom_reggrids.py +0 -482
- foxes/opt/problems/layout/geom_layouts/objectives.py +0 -666
- foxes/opt/problems/layout/reggrids_layout.py +0 -417
- foxes/opt/problems/layout/regular_layout.py +0 -350
- foxes/opt/problems/opt_farm_vars.py +0 -586
- {foxes-0.7.4.25.dist-info → foxes-0.8.1.dist-info}/LICENSE +0 -0
- {foxes-0.7.4.25.dist-info → foxes-0.8.1.dist-info}/WHEEL +0 -0
- {foxes-0.7.4.25.dist-info → foxes-0.8.1.dist-info}/top_level.txt +0 -0
- {foxes-0.7.4.25.dist-info → foxes-0.8.1.dist-info}/zip-safe +0 -0
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
|
|
3
|
-
from foxes.opt.core.farm_constraint import FarmConstraint
|
|
4
|
-
import foxes.variables as FV
|
|
5
|
-
import foxes.constants as FC
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class MinDistConstraint(FarmConstraint):
|
|
9
|
-
"""
|
|
10
|
-
Turbines must keep at least a minimal
|
|
11
|
-
spatial distance.
|
|
12
|
-
|
|
13
|
-
Attributes
|
|
14
|
-
----------
|
|
15
|
-
farm: foxes.WindFarm
|
|
16
|
-
The wind farm
|
|
17
|
-
sel_turbines: list
|
|
18
|
-
The selected turbines
|
|
19
|
-
min_dist: float
|
|
20
|
-
The minimal distance
|
|
21
|
-
min_dist_unit: str
|
|
22
|
-
The minimal distance unit, either m or D
|
|
23
|
-
|
|
24
|
-
:group: opt.constraints
|
|
25
|
-
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
def __init__(
|
|
29
|
-
self,
|
|
30
|
-
problem,
|
|
31
|
-
min_dist,
|
|
32
|
-
min_dist_unit="m",
|
|
33
|
-
name="dist",
|
|
34
|
-
sel_turbines=None,
|
|
35
|
-
**kwargs,
|
|
36
|
-
):
|
|
37
|
-
"""
|
|
38
|
-
Constructor.
|
|
39
|
-
|
|
40
|
-
Parameters
|
|
41
|
-
----------
|
|
42
|
-
problem: foxes.opt.FarmOptProblem
|
|
43
|
-
The underlying optimization problem
|
|
44
|
-
min_dist: float
|
|
45
|
-
The minimal distance
|
|
46
|
-
min_dist_unit: str
|
|
47
|
-
The minimal distance unit, either m or D
|
|
48
|
-
name: str
|
|
49
|
-
The name of the constraint
|
|
50
|
-
sel_turbines: list of int, optional
|
|
51
|
-
The selected turbines
|
|
52
|
-
kwargs: dict, optional
|
|
53
|
-
Additional parameters for `iwopy.Constraint`
|
|
54
|
-
|
|
55
|
-
"""
|
|
56
|
-
self.min_dist = min_dist
|
|
57
|
-
self.min_dist_unit = min_dist_unit
|
|
58
|
-
|
|
59
|
-
selt = problem.sel_turbines if sel_turbines is None else sel_turbines
|
|
60
|
-
vrs = []
|
|
61
|
-
for ti in selt:
|
|
62
|
-
vrs += [problem.tvar(FV.X, ti), problem.tvar(FV.Y, ti)]
|
|
63
|
-
|
|
64
|
-
super().__init__(problem, name, sel_turbines, vnames_float=vrs, **kwargs)
|
|
65
|
-
|
|
66
|
-
def initialize(self, verbosity=0):
|
|
67
|
-
"""
|
|
68
|
-
Initialize the constaint.
|
|
69
|
-
|
|
70
|
-
Parameters
|
|
71
|
-
----------
|
|
72
|
-
verbosity: int
|
|
73
|
-
The verbosity level, 0 = silent
|
|
74
|
-
|
|
75
|
-
"""
|
|
76
|
-
N = self.farm.n_turbines
|
|
77
|
-
self._i2t = [] # i --> (ti, tj)
|
|
78
|
-
self._t2i = np.full([N, N], -1) # (ti, tj) --> i
|
|
79
|
-
i = 0
|
|
80
|
-
for ti in self.sel_turbines:
|
|
81
|
-
for tj in range(N):
|
|
82
|
-
if ti != tj and self._t2i[ti, tj] < 0:
|
|
83
|
-
self._i2t.append([ti, tj])
|
|
84
|
-
self._t2i[ti, tj] = i
|
|
85
|
-
self._t2i[tj, ti] = i
|
|
86
|
-
i += 1
|
|
87
|
-
self._i2t = np.array(self._i2t)
|
|
88
|
-
self._cnames = [f"{self.name}_{ti}_{tj}" for ti, tj in self._i2t]
|
|
89
|
-
super().initialize(verbosity)
|
|
90
|
-
|
|
91
|
-
def n_components(self):
|
|
92
|
-
"""
|
|
93
|
-
Returns the number of components of the
|
|
94
|
-
function.
|
|
95
|
-
|
|
96
|
-
Returns
|
|
97
|
-
-------
|
|
98
|
-
int:
|
|
99
|
-
The number of components.
|
|
100
|
-
|
|
101
|
-
"""
|
|
102
|
-
return len(self._i2t)
|
|
103
|
-
|
|
104
|
-
def vardeps_float(self):
|
|
105
|
-
"""
|
|
106
|
-
Gets the dependencies of all components
|
|
107
|
-
on the function float variables
|
|
108
|
-
|
|
109
|
-
Returns
|
|
110
|
-
-------
|
|
111
|
-
deps: numpy.ndarray of bool
|
|
112
|
-
The dependencies of components on function
|
|
113
|
-
variables, shape: (n_components, n_vars_float)
|
|
114
|
-
|
|
115
|
-
"""
|
|
116
|
-
turbs = list(self.problem.sel_turbines)
|
|
117
|
-
deps = np.zeros((self.n_components(), len(turbs), 2), dtype=bool)
|
|
118
|
-
for i, titj in enumerate(self._i2t):
|
|
119
|
-
for t in titj:
|
|
120
|
-
if t in turbs:
|
|
121
|
-
j = turbs.index(t)
|
|
122
|
-
deps[i, j] = True
|
|
123
|
-
return deps.reshape(self.n_components(), 2 * len(turbs))
|
|
124
|
-
|
|
125
|
-
def calc_individual(self, vars_int, vars_float, problem_results, components=None):
|
|
126
|
-
"""
|
|
127
|
-
Calculate values for a single individual of the
|
|
128
|
-
underlying problem.
|
|
129
|
-
|
|
130
|
-
Parameters
|
|
131
|
-
----------
|
|
132
|
-
vars_int: np.array
|
|
133
|
-
The integer variable values, shape: (n_vars_int,)
|
|
134
|
-
vars_float: np.array
|
|
135
|
-
The float variable values, shape: (n_vars_float,)
|
|
136
|
-
problem_results: Any
|
|
137
|
-
The results of the variable application
|
|
138
|
-
to the problem
|
|
139
|
-
components: list of int, optional
|
|
140
|
-
The selected components or None for all
|
|
141
|
-
|
|
142
|
-
Returns
|
|
143
|
-
-------
|
|
144
|
-
values: np.array
|
|
145
|
-
The component values, shape: (n_sel_components,)
|
|
146
|
-
|
|
147
|
-
"""
|
|
148
|
-
xy = np.stack(
|
|
149
|
-
[problem_results[FV.X].to_numpy(), problem_results[FV.Y].to_numpy()],
|
|
150
|
-
axis=-1,
|
|
151
|
-
)
|
|
152
|
-
if not np.all(np.abs(np.min(xy, axis=0) - np.max(xy, axis=0)) < 1e-13):
|
|
153
|
-
raise ValueError(f"Constraint '{self.name}': Require state independet XY")
|
|
154
|
-
xy = xy[0]
|
|
155
|
-
|
|
156
|
-
s = np.s_[:]
|
|
157
|
-
if components is not None and len(components) < self.n_components():
|
|
158
|
-
s = components
|
|
159
|
-
|
|
160
|
-
a = np.take_along_axis(xy, self._i2t[s][:, 0, None], axis=0)
|
|
161
|
-
b = np.take_along_axis(xy, self._i2t[s][:, 1, None], axis=0)
|
|
162
|
-
d = np.linalg.norm(a - b, axis=-1)
|
|
163
|
-
|
|
164
|
-
if self.min_dist_unit == "m":
|
|
165
|
-
mind = self.min_dist
|
|
166
|
-
|
|
167
|
-
elif self.min_dist_unit == "D":
|
|
168
|
-
D = problem_results[FV.D].to_numpy()
|
|
169
|
-
if not np.all(np.abs(np.min(D, axis=0) - np.max(D, axis=0)) < 1e-13):
|
|
170
|
-
raise ValueError(
|
|
171
|
-
f"Constraint '{self.name}': Require state independet D"
|
|
172
|
-
)
|
|
173
|
-
D = D[0]
|
|
174
|
-
|
|
175
|
-
Da = np.take_along_axis(D, self._i2t[s][:, 0], axis=0)
|
|
176
|
-
Db = np.take_along_axis(D, self._i2t[s][:, 1], axis=0)
|
|
177
|
-
mind = self.min_dist * np.maximum(Da, Db)
|
|
178
|
-
|
|
179
|
-
return mind - d
|
|
180
|
-
|
|
181
|
-
def calc_population(self, vars_int, vars_float, problem_results, components=None):
|
|
182
|
-
"""
|
|
183
|
-
Calculate values for all individuals of a population.
|
|
184
|
-
|
|
185
|
-
Parameters
|
|
186
|
-
----------
|
|
187
|
-
vars_int: np.array
|
|
188
|
-
The integer variable values, shape: (n_pop, n_vars_int)
|
|
189
|
-
vars_float: np.array
|
|
190
|
-
The float variable values, shape: (n_pop, n_vars_float)
|
|
191
|
-
problem_results: Any
|
|
192
|
-
The results of the variable application
|
|
193
|
-
to the problem
|
|
194
|
-
components: list of int, optional
|
|
195
|
-
The selected components or None for all
|
|
196
|
-
|
|
197
|
-
Returns
|
|
198
|
-
-------
|
|
199
|
-
values: np.array
|
|
200
|
-
The component values, shape: (n_pop, n_sel_components)
|
|
201
|
-
|
|
202
|
-
"""
|
|
203
|
-
n_pop = problem_results["n_pop"].values
|
|
204
|
-
n_states = problem_results["n_org_states"].values
|
|
205
|
-
n_turbines = problem_results.sizes[FC.TURBINE]
|
|
206
|
-
|
|
207
|
-
xy = np.stack(
|
|
208
|
-
[problem_results[FV.X].to_numpy(), problem_results[FV.Y].to_numpy()],
|
|
209
|
-
axis=-1,
|
|
210
|
-
)
|
|
211
|
-
xy = xy.reshape(n_pop, n_states, n_turbines, 2)
|
|
212
|
-
if not np.all(np.abs(np.min(xy, axis=1) - np.max(xy, axis=1)) < 1e-13):
|
|
213
|
-
raise ValueError(f"Constraint '{self.name}': Require state independet XY")
|
|
214
|
-
xy = xy[:, 0]
|
|
215
|
-
|
|
216
|
-
s = np.s_[:]
|
|
217
|
-
if components is not None and len(components) < self.n_components():
|
|
218
|
-
s = components
|
|
219
|
-
|
|
220
|
-
a = np.take_along_axis(xy, self._i2t[s][None, :, 0, None], axis=1)
|
|
221
|
-
b = np.take_along_axis(xy, self._i2t[s][None, :, 1, None], axis=1)
|
|
222
|
-
d = np.linalg.norm(a - b, axis=-1)
|
|
223
|
-
|
|
224
|
-
if self.min_dist_unit == "m":
|
|
225
|
-
mind = self.min_dist
|
|
226
|
-
|
|
227
|
-
elif self.min_dist_unit == "D":
|
|
228
|
-
D = problem_results[FV.D].to_numpy().reshape(n_pop, n_states, n_turbines)
|
|
229
|
-
if not np.all(np.abs(np.min(D, axis=1) - np.max(D, axis=1)) < 1e-13):
|
|
230
|
-
raise ValueError(
|
|
231
|
-
f"Constraint '{self.name}': Require state independet D"
|
|
232
|
-
)
|
|
233
|
-
D = D[:, 0]
|
|
234
|
-
|
|
235
|
-
Da = np.take_along_axis(D, self._i2t[s][None, :, 0], axis=1)
|
|
236
|
-
Db = np.take_along_axis(D, self._i2t[s][None, :, 1], axis=1)
|
|
237
|
-
mind = self.min_dist * np.maximum(Da, Db)
|
|
238
|
-
|
|
239
|
-
return mind - d
|
foxes/opt/core/__init__.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Abstract classes and core functionality for wind farm optimization.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .farm_opt_problem import FarmOptProblem
|
|
6
|
-
from .farm_vars_problem import FarmVarsProblem
|
|
7
|
-
from .farm_objective import FarmObjective
|
|
8
|
-
from .farm_constraint import FarmConstraint
|
|
9
|
-
from .pop_states import PopStates
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
from iwopy import Constraint
|
|
2
|
-
|
|
3
|
-
from foxes.utils import all_subclasses
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class FarmConstraint(Constraint):
|
|
7
|
-
"""
|
|
8
|
-
Abstract base class for foxes wind farm
|
|
9
|
-
optimization constraints.
|
|
10
|
-
|
|
11
|
-
:group: opt.core
|
|
12
|
-
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
def __init__(self, problem, name, sel_turbines=None, **kwargs):
|
|
16
|
-
"""
|
|
17
|
-
Constructor.
|
|
18
|
-
|
|
19
|
-
Parameters
|
|
20
|
-
----------
|
|
21
|
-
problem: foxes.opt.FarmOptProblem
|
|
22
|
-
The underlying optimization problem
|
|
23
|
-
name: str
|
|
24
|
-
The name of the constraint
|
|
25
|
-
sel_turbines: list of int, optional
|
|
26
|
-
The selected turbines
|
|
27
|
-
kwargs: dict, optional
|
|
28
|
-
Additional parameters for `iwopy.Constraint`
|
|
29
|
-
|
|
30
|
-
"""
|
|
31
|
-
super().__init__(problem, name, **kwargs)
|
|
32
|
-
self._sel_turbines = sel_turbines
|
|
33
|
-
|
|
34
|
-
@property
|
|
35
|
-
def farm(self):
|
|
36
|
-
"""
|
|
37
|
-
The wind farm
|
|
38
|
-
|
|
39
|
-
Returns
|
|
40
|
-
-------
|
|
41
|
-
foxes.core.WindFarm :
|
|
42
|
-
The wind farm
|
|
43
|
-
|
|
44
|
-
"""
|
|
45
|
-
return self.problem.farm
|
|
46
|
-
|
|
47
|
-
@property
|
|
48
|
-
def sel_turbines(self):
|
|
49
|
-
"""
|
|
50
|
-
The list of selected turbines
|
|
51
|
-
|
|
52
|
-
Returns
|
|
53
|
-
-------
|
|
54
|
-
list of int :
|
|
55
|
-
The list of selected turbines
|
|
56
|
-
|
|
57
|
-
"""
|
|
58
|
-
return (
|
|
59
|
-
self.problem.sel_turbines
|
|
60
|
-
if self._sel_turbines is None
|
|
61
|
-
else self._sel_turbines
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
def n_sel_turbines(self):
|
|
66
|
-
"""
|
|
67
|
-
The numer of selected turbines
|
|
68
|
-
|
|
69
|
-
Returns
|
|
70
|
-
-------
|
|
71
|
-
int :
|
|
72
|
-
The numer of selected turbines
|
|
73
|
-
|
|
74
|
-
"""
|
|
75
|
-
return len(self.sel_turbines)
|
|
76
|
-
|
|
77
|
-
def add_to_layout_figure(self, ax, **kwargs):
|
|
78
|
-
"""
|
|
79
|
-
Add to a layout figure
|
|
80
|
-
|
|
81
|
-
Parameters
|
|
82
|
-
----------
|
|
83
|
-
ax: matplotlib.pyplot.Axis
|
|
84
|
-
The figure axis
|
|
85
|
-
|
|
86
|
-
"""
|
|
87
|
-
return ax
|
|
88
|
-
|
|
89
|
-
@classmethod
|
|
90
|
-
def print_models(cls):
|
|
91
|
-
"""
|
|
92
|
-
Prints all model names.
|
|
93
|
-
"""
|
|
94
|
-
names = sorted([scls.__name__ for scls in all_subclasses(cls)])
|
|
95
|
-
for n in names:
|
|
96
|
-
print(n)
|
foxes/opt/core/farm_objective.py
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
from iwopy import Objective
|
|
3
|
-
|
|
4
|
-
from foxes.utils import all_subclasses
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class FarmObjective(Objective):
|
|
8
|
-
"""
|
|
9
|
-
Abstract base class for foxes wind farm
|
|
10
|
-
objective functions.
|
|
11
|
-
|
|
12
|
-
:group: opt.core
|
|
13
|
-
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
def __init__(self, problem, name, sel_turbines=None, **kwargs):
|
|
17
|
-
"""
|
|
18
|
-
Constraints.
|
|
19
|
-
|
|
20
|
-
Parameters
|
|
21
|
-
----------
|
|
22
|
-
problem: foxes.opt.FarmOptProblem
|
|
23
|
-
The underlying optimization problem
|
|
24
|
-
name: str
|
|
25
|
-
The name of the objective function
|
|
26
|
-
sel_turbines: list of int, optional
|
|
27
|
-
The selected turbines
|
|
28
|
-
kwargs: dict, optional
|
|
29
|
-
Additional parameters for `iwopy.Objective`
|
|
30
|
-
|
|
31
|
-
"""
|
|
32
|
-
super().__init__(problem, name, **kwargs)
|
|
33
|
-
self._sel_turbines = sel_turbines
|
|
34
|
-
|
|
35
|
-
@property
|
|
36
|
-
def farm(self):
|
|
37
|
-
"""
|
|
38
|
-
The wind farm
|
|
39
|
-
|
|
40
|
-
Returns
|
|
41
|
-
-------
|
|
42
|
-
foxes.core.WindFarm :
|
|
43
|
-
The wind farm
|
|
44
|
-
|
|
45
|
-
"""
|
|
46
|
-
return self.problem.farm
|
|
47
|
-
|
|
48
|
-
@property
|
|
49
|
-
def sel_turbines(self):
|
|
50
|
-
"""
|
|
51
|
-
The list of selected turbines
|
|
52
|
-
|
|
53
|
-
Returns
|
|
54
|
-
-------
|
|
55
|
-
list of int :
|
|
56
|
-
The list of selected turbines
|
|
57
|
-
|
|
58
|
-
"""
|
|
59
|
-
return (
|
|
60
|
-
self.problem.sel_turbines
|
|
61
|
-
if self._sel_turbines is None
|
|
62
|
-
else self._sel_turbines
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
@property
|
|
66
|
-
def n_sel_turbines(self):
|
|
67
|
-
"""
|
|
68
|
-
The numer of selected turbines
|
|
69
|
-
|
|
70
|
-
Returns
|
|
71
|
-
-------
|
|
72
|
-
int :
|
|
73
|
-
The numer of selected turbines
|
|
74
|
-
|
|
75
|
-
"""
|
|
76
|
-
return len(self.sel_turbines)
|
|
77
|
-
|
|
78
|
-
def add_to_layout_figure(self, ax, **kwargs):
|
|
79
|
-
"""
|
|
80
|
-
Add to a layout figure
|
|
81
|
-
|
|
82
|
-
Parameters
|
|
83
|
-
----------
|
|
84
|
-
ax: matplotlib.pyplot.Axis
|
|
85
|
-
The figure axis
|
|
86
|
-
|
|
87
|
-
"""
|
|
88
|
-
return ax
|
|
89
|
-
|
|
90
|
-
@classmethod
|
|
91
|
-
def print_models(cls):
|
|
92
|
-
"""
|
|
93
|
-
Prints all model names.
|
|
94
|
-
"""
|
|
95
|
-
names = sorted([scls.__name__ for scls in all_subclasses(cls)])
|
|
96
|
-
for n in names:
|
|
97
|
-
print(n)
|