diff --git a/edwin/tests/test_wind_farm_network.py b/edwin/tests/test_wind_farm_network.py index bc45abd5e6634bf2c4df1fde38556665bbfed16c..ce4a2e614343bdba21b78572c388df14c517202a 100644 --- a/edwin/tests/test_wind_farm_network.py +++ b/edwin/tests/test_wind_farm_network.py @@ -2,25 +2,25 @@ import numpy as np from edwin.wind_farm_network import WindFarmNetwork, HeuristicDriver import numpy.testing as npt -layout = dict(x=np.array([0., 2000., 4000., 6000., - 8000., 498.65600569, 2498.65600569, 4498.65600569, - 6498.65600569, 8498.65600569, 997.31201137, 2997.31201137, - 4997.31201137, 11336.25662483, 8997.31201137, 1495.96801706, - 3495.96801706, 5495.96801706, 10011.39514341, 11426.89538545, - 1994.62402275, 3994.62402275, 5994.62402275, 7994.62402275, - 10588.90471566]), - y=np.array([0., 0., 0., 0., - 0., 2000., 2000., 2000., - 2000., 2000., 4000., 4000., - 4000., 6877.42528387, 4000., 6000., - 6000., 6000., 3179.76530545, 5953.63051694, - 8000., 8000., 8000., 8000., - 4734.32972738])) +initial_layout = dict(x=np.array([0., 2000., 4000., 6000., + 8000., 498.65600569, 2498.65600569, 4498.65600569, + 6498.65600569, 8498.65600569, 997.31201137, 2997.31201137, + 4997.31201137, 11336.25662483, 8997.31201137, 1495.96801706, + 3495.96801706, 5495.96801706, 10011.39514341, 11426.89538545, + 1994.62402275, 3994.62402275, 5994.62402275, 7994.62402275, + 10588.90471566]), + y=np.array([0., 0., 0., 0., + 0., 2000., 2000., 2000., + 2000., 2000., 4000., 4000., + 4000., 6877.42528387, 4000., 6000., + 6000., 6000., 3179.76530545, 5953.63051694, + 8000., 8000., 8000., 8000., + 4734.32972738])) settings = {'option': 3, 'Inters_const': True, 'max_it': 20000} cables = np.array([[500, 3, 100000], [800, 5, 150000], [1000, 10, 250000]]) -wfn = WindFarmNetwork(layout=layout, +wfn = WindFarmNetwork(initial_layout=initial_layout, driver=HeuristicDriver(**settings), cables=cables) diff --git a/edwin/wind_farm_network.py b/edwin/wind_farm_network.py index 883fe6a9ea17e0e66bfe648985fb989f8bd745eb..9016895c6cdd15e758356aeec3266bdb004a86ea 100644 --- a/edwin/wind_farm_network.py +++ b/edwin/wind_farm_network.py @@ -20,9 +20,9 @@ class HeuristicDriver(Driver): self.max_it = max_it Driver.__init__(self) - def run(self): - T, cables_cost = collection_system(self.wfn.x, - self.wfn.y, + def run(self, x, y): + T, cables_cost = collection_system(x, + y, self.option, self.Inters_const, self.max_it, @@ -31,10 +31,8 @@ class HeuristicDriver(Driver): class WindFarmNetwork(): - def __init__(self, layout, driver=HeuristicDriver(), cables=[]): - self.layout = layout - for k, v in layout.items(): - setattr(self, k, v) + def __init__(self, initial_layout, driver=HeuristicDriver(), cables=[]): + self.initial_layout = initial_layout self.driver = driver self.cables = cables self.state = None @@ -45,8 +43,12 @@ class WindFarmNetwork(): def setup(self): setattr(self.driver, 'wfn', self) - def design(self): - T, cost = self.driver.run() + def design(self, x=None, y=None, **kwargs): + x = x or self.initial_layout['x'] + y = y or self.initial_layout['y'] + self.x = x + self.y = y + T, cost = self.driver.run(x, y) state = pd.DataFrame(T, columns=self.columns) state = state.astype({'from_node': int, 'to_node': int, @@ -73,30 +75,25 @@ class Constraints(dict): def main(): if __name__ == '__main__': - # layout = {'x': [473095,471790,471394,470998,470602,470207,469811,472523,469415,472132,471742,471351,470960,470569,470179,469788,472866,472480,472094,471708,471322,470937,470551,473594,473213,472833,472452,472071,471691,471310,470929], - # 'y': [5992345,5991544,5991899,5992252,5992607,5992960,5993315,5991874,5993668,5992236,5992598,5992960,5993322,5993684,5994047,5994409,5992565,5992935,5993306,5993675,5994045,5994416,5994786,5992885,5993264,5993643,5994021,5994400,5994779,5995156,5995535]} - layout = dict(x=np.array([0., 2000., 4000., 6000., - 8000., 498.65600569, 2498.65600569, 4498.65600569, - 6498.65600569, 8498.65600569, 997.31201137, 2997.31201137, - 4997.31201137, 11336.25662483, 8997.31201137, 1495.96801706, - 3495.96801706, 5495.96801706, 10011.39514341, 11426.89538545, - 1994.62402275, 3994.62402275, 5994.62402275, 7994.62402275, - 10588.90471566]), - y=np.array([0., 0., 0., 0., - 0., 2000., 2000., 2000., - 2000., 2000., 4000., 4000., - 4000., 6877.42528387, 4000., 6000., - 6000., 6000., 3179.76530545, 5953.63051694, - 8000., 8000., 8000., 8000., - 4734.32972738])) - # layout = {'x': [387100, 383400, 383400, 383900, 383200, 383200, 383200, 383200, 383200, 383200, 383200, 383200, 383300, 384200, 384200, 384100, 384000, 383800, 383700, 383600, 383500, 383400, 383600, 384600, 385400, 386000, 386100, 386200, 386300, 386500, 386600, 386700, 386800, 386900, 387000, 387100, 387200, 383900, 387400, 387500, 387600, 387800, 387900, 388000, 387600, 386800, 385900, 385000, 384100, 384500, 384800, 385000, 385100, 385200, 385400, 385500, 385700, 385800, 385900, 385900, 385500, 385500, 386000, 386200, 386200, 384500, 386200, 386700, 386700, 386700, 384300, 384400, 384500, 384600, 384300, 384700, 384700, 384700, 385500, 384300, 384300], - # 'y': [6109500, 6103800, 6104700, 6105500, 6106700, 6107800, 6108600, 6109500, 6110500, 6111500, 6112400, 6113400, 6114000, 6114200, 6115100, 6115900, 6116700, 6118400, 6119200, 6120000, 6120800, 6121800, 6122400, 6122000, 6121700, 6121000, 6120000, 6119100, 6118100, 6117200, 6116200, 6115300, 6114300, 6113400, 6112400, 6111500, 6110700, 6117600, 6108900, 6108100, 6107400, 6106300, 6105200, 6104400, 6103600, 6103600, 6103500, 6103400, 6103400, 6104400, 6120400, 6119500, 6118400, 6117400, 6116500, 6115500, 6114600, 6113500, 6112500, 6111500, 6105400, 6104200, 6110400, 6109400, 6108400, 6121300, 6107500, 6106400, 6105300, 6104400, 6113300, 6112500, 6111600, 6110800, 6110100, 6109200, 6108400, 6107600, 6106500, 6106600, 6105000]} - + initial_layout = dict(x=np.array([0., 2000., 4000., 6000., + 8000., 498.65600569, 2498.65600569, 4498.65600569, + 6498.65600569, 8498.65600569, 997.31201137, 2997.31201137, + 4997.31201137, 11336.25662483, 8997.31201137, 1495.96801706, + 3495.96801706, 5495.96801706, 10011.39514341, 11426.89538545, + 1994.62402275, 3994.62402275, 5994.62402275, 7994.62402275, + 10588.90471566]), + y=np.array([0., 0., 0., 0., + 0., 2000., 2000., 2000., + 2000., 2000., 4000., 4000., + 4000., 6877.42528387, 4000., 6000., + 6000., 6000., 3179.76530545, 5953.63051694, + 8000., 8000., 8000., 8000., + 4734.32972738])) settings = {'option': 3, 'Inters_const': True, 'max_it': 20000} cables = np.array([[500, 3, 100000], [800, 5, 150000], [1000, 10, 250000]]) - wfn = WindFarmNetwork(layout=layout, + wfn = WindFarmNetwork(initial_layout=initial_layout, driver=HeuristicDriver(**settings), cables=cables) cost, state = wfn.design()