diff --git a/edwin/__init__.py b/edwin/__init__.py index b3d043635510958ad1d6e505cb48e582fbf98ac0..d0f8dbd7faa5b160a7e62d66c8462d18ef61f539 100644 --- a/edwin/__init__.py +++ b/edwin/__init__.py @@ -1,3 +1,3 @@ # 'filled_by_setup.py' -__version__ = 'filled_by_setup.py' -__release__ = 'filled_by_setup.py' +__version__ = '4fbf778c0f6c9c019f2bb08835d3e6596a380f1' +__release__ = '4fbf778c0f6c9c019f2bb08835d3e6596a380f1' diff --git a/edwin/method.py b/edwin/method.py new file mode 100644 index 0000000000000000000000000000000000000000..e255c05bf364dc3f970e4b0ca2c7705a3f669764 --- /dev/null +++ b/edwin/method.py @@ -0,0 +1,45 @@ +from abc import ABC, abstractmethod + + +class Method(ABC): + def __init__(self, **kwargs): + return + + @abstractmethod + def _design(geometry, financial, electrical, contraints, **settings): + ''' + + Parameters + ---------- + **settings : dict + Configuration of algorithm. + + Returns + ------- + dictionary of connections. + + ''' + + +class HeuristicMethod(Method): + def __init__(self, **kwargs): + Method.__init__(self) + + def _design(self, geometry, financial, electrical, contraints, **settings): + return {'hello from': 'HeuristicMethod'} + + +class MetaHeuristicMethod(Method): + def __init__(self, **kwargs): + Method.__init__(self) + + def _design(self, geometry, financial, electrical, contraints, **settings): + return {'hello from': 'MetaHeuristicMethod'} + + +class GlobalMethod(Method): + def __init__(self, **kwargs): + Method.__init__(self) + + def _design(self, geometry, financial, electrical, contraints, **settings): + return {'hello from': 'GlobalMethod'} diff --git a/edwin/tests/test_wind_farm_network.py b/edwin/tests/test_wind_farm_network.py index 94383c39542e136728643577476889c94033c689..d663ed60718a93e92553cad8ce825d327d1b72ad 100644 --- a/edwin/tests/test_wind_farm_network.py +++ b/edwin/tests/test_wind_farm_network.py @@ -1,9 +1,22 @@ -from edwin.tests import npt from edwin.wind_farm_network import WindFarmNetwork +from edwin.method import MetaHeuristicMethod -method = 'test' -wfn = WindFarmNetwork(method) +method = MetaHeuristicMethod() +geometry = {'turbine_coordinates': {'x': [1, 1, 1, 2, 2, 2, 3, 3, 3], + 'y': [1, 2, 3, 2, 3, 4, 3, 4, 5], }, + 'sub_station_coordinates': {'x': [2.5], + 'y': [3.5], }} +financial = {} +electrical = {} +constraints = {'crossing': False, + 'tree': False, + 'thermal capacity': False, + 'number of main feeders': False} +settings = {} +wfn = WindFarmNetwork(method=method, geometry=geometry, financial=financial, + electrical=electrical, constraints=constraints) def test_wind_farm_network(): - assert wfn.method == 'test' + result_dict = wfn.design(settings) + assert result_dict == {'hello from': 'MetaHeuristicMethod'} diff --git a/edwin/wind_farm_network.py b/edwin/wind_farm_network.py index be167c14aa2075fae0d5b3af0b09406bcb3edfbe..0ee2626c8b0e3a77e1e69c5598565957fb9e5d7e 100644 --- a/edwin/wind_farm_network.py +++ b/edwin/wind_farm_network.py @@ -1,70 +1,49 @@ -from abc import ABC, abstractmethod +import matplotlib.pyplot as plt class WindFarmNetwork(): - def __init__(self, method, geometry, financial, electrical, contraints): + def __init__(self, method, geometry, financial, electrical, constraints): self.method = method + self.geometry = geometry + self.financial = financial + self.electrical = electrical + self.constraints = constraints def design(self, settings): self.settings = settings - return self.method._design(**settings) + return self.method._design(self.geometry, self.financial, self.electrical, + self.constraints, **settings) -class Method(ABC): - def __init__(self, **kwargs): - return - - @abstractmethod - def _design(**settings): - ''' + def plot(self): + x = self.geometry['turbine_coordinates']['x'] + y = self.geometry['turbine_coordinates']['y'] + xss = self.geometry['sub_station_coordinates']['x'] + yss = self.geometry['sub_station_coordinates']['y'] + plt.plot(x, y, '.') + plt.plot(xss, yss, 'or', label='Sub station') + plt.legend() - Parameters - ---------- - **settings : dict - Configuration of algorithm. - - Returns - ------- - dictionary of connections. - - ''' - -class HeuristicMethod(Method): - def __init__(self, **kwargs): - Method.__init__(self) - - def _design(self, **settings): - return {'hello from': 'HeuristicMethod'} - -class MetaHeuristicMethod(Method): - def __init__(self, **kwargs): - Method.__init__(self) - - def _design(self, **settings): - return {'hello from': 'MetaHeuristicMethod'} - -class GlobalMethod(Method): - def __init__(self, **kwargs): - Method.__init__(self) - - def _design(self, **settings): - return {'hello from': 'GlobalMethod'} def main(): if __name__ == '__main__': - hm = MetaHeuristicMethod() - geometry = {'turbine_coordinates': {'x': [1], - 'y': [1],}, - 'sub_station_coordinates': {'x': [2], - 'y': [2],}} + from edwin.method import MetaHeuristicMethod + method = MetaHeuristicMethod() + geometry = {'turbine_coordinates': {'x': [1, 1, 1, 2, 2, 2, 3, 3, 3], + 'y': [1, 2, 3, 2, 3, 4, 3, 4, 5], }, + 'sub_station_coordinates': {'x': [2.5], + 'y': [3.5], }} financial = {} electrical = {} - contraints = {'crossing': False, + constraints = {'crossing': False, 'tree': False, 'thermal capacity': False, 'number of main feeders': False} settings = {} - wfn = WindFarmNetwork(method=hm, geometry=geometry, financial=financial, - electrical=electrical, contraints=contraints) + wfn = WindFarmNetwork(method=method, geometry=geometry, financial=financial, + electrical=electrical, constraints=constraints) result_dict = wfn.design(settings) print(result_dict) -main() \ No newline at end of file + wfn.plot() + + +main()