From 0c6c857252e379ba76e90ff3f5bf58f9efe828ee Mon Sep 17 00:00:00 2001
From: mikf <mikf@dtu.dk>
Date: Tue, 12 Oct 2021 13:40:56 +0200
Subject: [PATCH] updated structure

---
 edwin/__init__.py                     |  4 +-
 edwin/method.py                       | 45 +++++++++++++++
 edwin/tests/test_wind_farm_network.py | 21 +++++--
 edwin/wind_farm_network.py            | 79 ++++++++++-----------------
 4 files changed, 93 insertions(+), 56 deletions(-)
 create mode 100644 edwin/method.py

diff --git a/edwin/__init__.py b/edwin/__init__.py
index b3d0436..d0f8dbd 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 0000000..e255c05
--- /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 94383c3..d663ed6 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 be167c1..0ee2626 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()
-- 
GitLab