Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TopFarm2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TOPFARM
TopFarm2
Commits
b4029abd
Commit
b4029abd
authored
6 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
rewrote RandomizeTurbinePosition functions
parent
bdaac60f
No related branches found
No related tags found
1 merge request
!94
Handle disabled mpi
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
topfarm/drivers/random_search_driver.py
+21
-21
21 additions, 21 deletions
topfarm/drivers/random_search_driver.py
topfarm/tests/test_topfarm_utils/test_drivers.py
+7
-7
7 additions, 7 deletions
topfarm/tests/test_topfarm_utils/test_drivers.py
with
28 additions
and
28 deletions
topfarm/drivers/random_search_driver.py
+
21
−
21
View file @
b4029abd
...
...
@@ -131,7 +131,7 @@ class RandomSearchDriver(Driver):
n_iter
=
0
desvar_info
=
[(
abs2prom
[
name
],
*
self
.
_desvar_idx
[
name
],
meta
[
'
lower
'
],
meta
[
'
upper
'
])
for
name
,
meta
in
iteritems
(
desvars
)]
desvar_dict
=
{
name
:
(
x0
[
i
:
j
],
l
,
u
)
for
(
name
,
i
,
j
,
l
,
u
)
in
desvar_info
}
desvar_dict
=
{
name
:
(
x0
[
i
:
j
],
l
ower_bound
[
i
:
j
],
upper_bound
[
i
:
j
]
)
for
(
name
,
i
,
j
,
l
,
u
)
in
desvar_info
}
while
n_iter
<
max_iter
:
for
name
,
i
,
j
,
_
,
_
in
desvar_info
:
...
...
@@ -223,29 +223,29 @@ class RandomSearchDriver(Driver):
return
obj
,
success
class
RandomizeTurbinePosition
_DirStep
():
def
__init__
(
self
,
max_
move_
step
):
self
.
max_
move_
step
=
max_
move_
step
class
RandomizeTurbinePosition
():
def
__init__
(
self
,
max_step
):
self
.
max_step
=
max_step
def
__call__
(
self
,
desvar_dict
):
i_wt
=
np
.
random
.
randint
(
len
(
desvar_dict
[
'
turbineX
'
][
0
]))
step
=
np
.
random
.
rand
()
*
self
.
max_move_step
theta
=
np
.
random
.
rand
()
*
np
.
pi
*
2
for
(
xy
,
l
,
u
),
dxy
in
[(
desvar_dict
[
'
turbineX
'
],
step
*
np
.
cos
(
theta
)),
(
desvar_dict
[
'
turbineY
'
],
step
*
np
.
sin
(
theta
))]:
xy
[
i_wt
]
=
np
.
maximum
(
np
.
minimum
(
xy
[
i_wt
]
+
dxy
,
u
),
l
)
max_step_xy
=
[
self
.
max_step
or
(
desvar_dict
[
'
turbine
'
+
xy
][
2
][
i_wt
]
-
desvar_dict
[
'
turbine
'
+
xy
][
1
][
i_wt
])
for
xy
in
'
XY
'
]
dxy
=
self
.
_xy_step
(
max_step_xy
)
for
(
xy
,
lbound
,
ubound
),
dxy_
in
zip
([
desvar_dict
[
'
turbineX
'
],
desvar_dict
[
'
turbineY
'
]],
dxy
):
xy
[
i_wt
]
=
np
.
maximum
(
np
.
minimum
(
xy
[
i_wt
]
+
dxy_
,
ubound
[
i_wt
]),
lbound
[
i_wt
])
return
desvar_dict
class
RandomizeTurbinePosition_Uniform
():
def
__call__
(
self
,
desvar_dict
):
i_wt
=
np
.
random
.
randint
(
len
(
desvar_dict
[
'
turbineX
'
][
0
]))
for
xy
,
lbound
,
ubound
in
[(
desvar_dict
[
'
turbineX
'
]),
(
desvar_dict
[
'
turbineY
'
])]:
if
hasattr
(
lbound
,
'
len
'
):
lbound
=
lbound
[
i_wt
]
if
hasattr
(
ubound
,
'
len
'
):
ubound
=
ubound
[
i_wt
]
v
=
np
.
random
.
rand
()
*
(
ubound
-
lbound
)
+
lbound
xy
[
i_wt
]
=
np
.
maximum
(
np
.
minimum
(
v
,
ubound
),
lbound
)
return
desvar_dict
class
RandomizeTurbinePosition_Circle
(
RandomizeTurbinePosition
):
def
_xy_step
(
self
,
max_step_xy
):
step
=
np
.
random
.
rand
()
*
max
(
max_step_xy
)
theta
=
np
.
random
.
rand
()
*
np
.
pi
*
2
return
step
*
np
.
cos
(
theta
),
step
*
np
.
sin
(
theta
)
class
RandomizeTurbinePosition_Square
(
RandomizeTurbinePosition
):
def
_xy_step
(
self
,
max_step_xy
):
return
(
np
.
random
.
rand
()
*
2
-
1
)
*
max_step_xy
[
0
],
(
np
.
random
.
rand
()
*
2
-
1
)
*
max_step_xy
[
1
]
This diff is collapsed.
Click to expand it.
topfarm/tests/test_topfarm_utils/test_drivers.py
+
7
−
7
View file @
b4029abd
...
...
@@ -6,8 +6,8 @@ from topfarm.plotting import NoPlot
from
topfarm.easy_drivers
import
EasyScipyOptimizeDriver
,
EasyPyOptSparseIPOPT
,
\
EasySimpleGADriver
,
EasyRandomSearchDriver
from
topfarm.tests
import
uta
from
topfarm.drivers.random_search_driver
import
RandomizeTurbinePosition_
DirStep
,
\
RandomizeTurbinePosition_
Uniform
from
topfarm.drivers.random_search_driver
import
RandomizeTurbinePosition_
Square
,
\
RandomizeTurbinePosition_
Circle
initial
=
np
.
array
([[
6
,
0
],
[
6
,
-
8
],
[
1
,
1
]])
# initial turbine layouts
...
...
@@ -22,7 +22,7 @@ def topfarm_generator():
from
topfarm.cost_models.dummy
import
DummyCostPlotComp
plot_comp
=
DummyCostPlotComp
(
desired
*
xy_scale
,
plot_improvements_only
=
True
)
plot_comp
=
NoPlot
()
#
plot_comp = NoPlot()
class
DummyCostScaled
(
DummyCost
):
def
cost
(
self
,
**
kwargs
):
...
...
@@ -114,11 +114,11 @@ def find_optimal_scaling(topfarm_generator):
plt
.
show
()
@pytest.mark.parametrize
(
'
randomize_func
'
,
[
RandomizeTurbinePosition_
D
ir
Step
(
1
),
RandomizeTurbinePosition_
Uniform
(
)])
@pytest.mark.parametrize
(
'
randomize_func
'
,
[
RandomizeTurbinePosition_
C
ir
cle
(
1
),
RandomizeTurbinePosition_
Square
(
1
)])
def
test_random_search_driver
(
topfarm_generator
,
randomize_func
):
driver
=
EasyRandomSearchDriver
(
randomize_func
,
max_iter
=
2
000
)
np
.
random
.
seed
(
1
)
driver
=
EasyRandomSearchDriver
(
randomize_func
,
max_iter
=
1
000
)
tf
=
topfarm_generator
(
driver
,
spacing
=
1
)
cost
,
_
,
recorder
=
tf
.
optimize
()
tb_pos
=
tf
.
turbine_positions
[:,
:
2
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment