Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import unittest
import numpy as np
from topfarm.cost_models.dummy import DummyCost, DummyCostPlotComp
from topfarm import TopFarm
from topfarm.constraint_components.boundary_component import PolygonBoundaryComp
from topfarm.plotting import NoPlot, PlotComp
class TestBoundaryPolygon(unittest.TestCase):
def testPolygon(self):
optimal = [(0, 0)]
boundary = [(0, 0), (1, 1), (2, 0), (2, 2), (0, 2)]
tf = TopFarm(optimal, DummyCost(optimal), 2, boundary=boundary, boundary_type='polygon')
np.testing.assert_array_equal(tf.boundary, [[0, 0],
[1, 1],
[2, 0],
[2, 2],
[0, 2],
[0, 0]])
def testPolygonConcave(self):
optimal = [(1.5, 1.3), (4, 1)]
boundary = [(0, 0), (5, 0), (5, 2), (3, 2), (3, 1), (2, 1), (2, 2), (0, 2), (0, 0)]
plot_comp = NoPlot() # DummyCostPlotComp(optimal)
initial = [(-0, .1), (4, 1.5)][::-1]
tf = TopFarm(initial, DummyCost(optimal), 0, boundary=boundary, boundary_type='polygon', plot_comp=plot_comp)
tf.evaluate()
tf.optimize()
np.testing.assert_array_almost_equal(tf.turbine_positions, optimal, 4)
plot_comp.show()
def testPolygonTwoRegionsStartInWrong(self):
optimal = [(1, 1), (4, 1)]
boundary = [(0, 0), (5, 0), (5, 2), (3, 2), (3, 0), (2, 0), (2, 2), (0, 2), (0, 0)]
plot_comp = NoPlot() # DummyCostPlotComp(optimal, delay=.1)
initial = [(3.5, 1.5), (2, 1)]
tf = TopFarm(initial, DummyCost(optimal), 0, boundary=boundary, boundary_type='polygon', plot_comp=plot_comp)
tf.evaluate()
tf.optimize()
plot_comp.show()
np.testing.assert_array_almost_equal(tf.turbine_positions, optimal, 4)
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()