From 9666200f74a3136854bf326222cc58d07623f3a5 Mon Sep 17 00:00:00 2001 From: Dollars Date: Sun, 19 May 2013 17:16:58 +0200 Subject: [PATCH] My Year project as a BA3 student. --- input/ferraraNetwork.dot | 76 ++ input/myNetwork.dot | 6 + input/myNetwork.dot~ | 6 + input/randomNetwork.dot | 7 + input/testNetwork.dot | 6 + input/testNetwork.dot~ | 5 + src/graphical_interface/__init__.py | 0 src/graphical_interface/__init__.pyc | Bin 0 -> 172 bytes src/graphical_interface/graph_overview.py | 65 ++ src/graphical_interface/graph_overview.pyc | Bin 0 -> 2482 bytes .../graphical_interface.py | 1017 +++++++++++++++++ .../graphical_interface.pyc | Bin 0 -> 21427 bytes src/hydraulic_network/__init__.py | 16 + src/hydraulic_network/__init__.pyc | Bin 0 -> 848 bytes src/hydraulic_network/globalnetwork.py | 80 ++ src/hydraulic_network/globalnetwork.pyc | Bin 0 -> 3749 bytes src/hydraulic_network/networks.py | 217 ++++ src/hydraulic_network/networks.pyc | Bin 0 -> 10189 bytes src/hydraulic_network/node.py | 53 + src/hydraulic_network/node.pyc | Bin 0 -> 2926 bytes src/hydraulic_network/pipe.py | 66 ++ src/hydraulic_network/pipe.pyc | Bin 0 -> 3645 bytes src/hydraulic_network/segmentgraph.py | 163 +++ src/hydraulic_network/segmentgraph.pyc | Bin 0 -> 6962 bytes src/hydraulic_network/valve.py | 16 + src/hydraulic_network/valve.pyc | Bin 0 -> 1043 bytes src/infodata.py | 34 + src/optimization/__init__.py | 4 + src/optimization/__init__.pyc | Bin 0 -> 473 bytes src/optimization/backtracking.py | 28 + src/optimization/backtracking.pyc | Bin 0 -> 1757 bytes src/optimization/genetic_algorithm.py | 150 +++ src/optimization/genetic_algorithm.pyc | Bin 0 -> 6031 bytes src/optimization/simulated_annealing.py | 83 ++ src/optimization/simulated_annealing.pyc | Bin 0 -> 3274 bytes src/test.py | 67 ++ src/test.pyc | Bin 0 -> 612 bytes 37 files changed, 2165 insertions(+) create mode 100644 input/ferraraNetwork.dot create mode 100644 input/myNetwork.dot create mode 100644 input/myNetwork.dot~ create mode 100644 input/randomNetwork.dot create mode 100644 input/testNetwork.dot create mode 100644 input/testNetwork.dot~ create mode 100644 src/graphical_interface/__init__.py create mode 100644 src/graphical_interface/__init__.pyc create mode 100644 src/graphical_interface/graph_overview.py create mode 100644 src/graphical_interface/graph_overview.pyc create mode 100644 src/graphical_interface/graphical_interface.py create mode 100644 src/graphical_interface/graphical_interface.pyc create mode 100644 src/hydraulic_network/__init__.py create mode 100644 src/hydraulic_network/__init__.pyc create mode 100644 src/hydraulic_network/globalnetwork.py create mode 100644 src/hydraulic_network/globalnetwork.pyc create mode 100644 src/hydraulic_network/networks.py create mode 100644 src/hydraulic_network/networks.pyc create mode 100644 src/hydraulic_network/node.py create mode 100644 src/hydraulic_network/node.pyc create mode 100644 src/hydraulic_network/pipe.py create mode 100644 src/hydraulic_network/pipe.pyc create mode 100644 src/hydraulic_network/segmentgraph.py create mode 100644 src/hydraulic_network/segmentgraph.pyc create mode 100644 src/hydraulic_network/valve.py create mode 100644 src/hydraulic_network/valve.pyc create mode 100644 src/infodata.py create mode 100644 src/optimization/__init__.py create mode 100644 src/optimization/__init__.pyc create mode 100644 src/optimization/backtracking.py create mode 100644 src/optimization/backtracking.pyc create mode 100644 src/optimization/genetic_algorithm.py create mode 100644 src/optimization/genetic_algorithm.pyc create mode 100644 src/optimization/simulated_annealing.py create mode 100644 src/optimization/simulated_annealing.pyc create mode 100644 src/test.py create mode 100644 src/test.pyc diff --git a/input/ferraraNetwork.dot b/input/ferraraNetwork.dot new file mode 100644 index 0000000..c735a10 --- /dev/null +++ b/input/ferraraNetwork.dot @@ -0,0 +1,76 @@ +1 -- 2; +2 -- 3; +2 -- 11; +2 -- 13; +3 -- 4; +4 -- 5; +4 -- 15; +5 -- 22; +5 -- 6; +6 -- 7; +6 -- 30; +7 -- 41; +7 -- 8; +8 -- 49; +8 -- 47; +8 -- 9; +9 -- 10; +10 -- 11; +10 -- 42; +12 -- 30; +12 -- 32; +12 -- 39; +12 -- 48; +13 -- 14; +13 -- 16; +14 -- 15; +14 -- 17; +15 -- 19; +16 -- 17; +16 -- 24; +17 -- 18; +17 -- 23; +18 -- 19; +19 -- 20; +19 -- 27; +20 -- 21; +20 -- 28; +21 -- 22; +21 -- 29; +22 -- 30; +23 -- 25; +24 -- 25; +24 -- 33; +25 -- 26; +26 -- 27; +26 -- 34; +27 -- 31; +28 -- 29; +28 -- 31; +29 -- 30; +29 -- 32; +31 -- 32; +31 -- 35; +32 -- 38; +33 -- 34; +33 -- 42; +34 -- 35; +34 -- 43; +35 -- 36; +35 -- 44; +36 -- 37; +36 -- 45; +37 -- 38; +37 -- 40; +38 -- 39; +39 -- 40; +39 -- 48; +40 -- 41; +40 -- 46; +41 -- 47; +41 -- 48; +42 -- 43; +43 -- 44; +44 -- 45; +45 -- 46; +46 -- 47; diff --git a/input/myNetwork.dot b/input/myNetwork.dot new file mode 100644 index 0000000..49f493f --- /dev/null +++ b/input/myNetwork.dot @@ -0,0 +1,6 @@ +A -- B -- D -- E -- G -- I -- H -- C; +B -- C -- F -- H; +D -- F -- I; +F -- M -- O -- G -- J -- K; +M -- N -- O; +J -- L; diff --git a/input/myNetwork.dot~ b/input/myNetwork.dot~ new file mode 100644 index 0000000..49f493f --- /dev/null +++ b/input/myNetwork.dot~ @@ -0,0 +1,6 @@ +A -- B -- D -- E -- G -- I -- H -- C; +B -- C -- F -- H; +D -- F -- I; +F -- M -- O -- G -- J -- K; +M -- N -- O; +J -- L; diff --git a/input/randomNetwork.dot b/input/randomNetwork.dot new file mode 100644 index 0000000..e580cba --- /dev/null +++ b/input/randomNetwork.dot @@ -0,0 +1,7 @@ +A -- B -- D -- E -- G -- I -- H -- C; +B -- C -- F -- H; +D -- F -- I; +F -- M -- O -- G -- J -- K; +M -- N -- O; +C -- F -- I; +J -- L; diff --git a/input/testNetwork.dot b/input/testNetwork.dot new file mode 100644 index 0000000..cfb51a2 --- /dev/null +++ b/input/testNetwork.dot @@ -0,0 +1,6 @@ +A -- B -- C -- D -- E -- F -- G -- B; +C -- G; +D -- F -- L; +G -- H -- I -- J -- K -- L -- I; +E -- M -- H; +B -- J; diff --git a/input/testNetwork.dot~ b/input/testNetwork.dot~ new file mode 100644 index 0000000..e428424 --- /dev/null +++ b/input/testNetwork.dot~ @@ -0,0 +1,5 @@ +A -- B -- C -- D -- E -- F -- G -- B; +C -- G; +D -- F -- L; +G -- H -- I -- J -- K -- L -- I; +E -- M -- H; diff --git a/src/graphical_interface/__init__.py b/src/graphical_interface/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/graphical_interface/__init__.pyc b/src/graphical_interface/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e2b0cd2e20406e24e066ce8861e40af8cbbfdd9c GIT binary patch literal 172 zcmZSn%*z#0FCLi800oRd+5w1*S%5?e14FO|NW@PANHCxg#i2kk{fzwFRQ;6voSej> zV*T>`qU_>=#N}|6-$9C;a z)0~{A9k$nUJE7%-pf`NdF-naxiU?7a@ z6{yo~@CK3UGsdHcafp%q0AS&WVqbEiTu~0hrJDjNo^Y89sgQl66!3n5Il}@Ci?XvM zB>ZxSrx$(&1aDYV%QDQ&Yi<5eL=6X&U~_Vn^)qjBZP}>f)EjBL0<7ORk+J>0u-jgw zL%|ZkSmuF=0?YfKe1F<+@1L|z?FOg|j#)om1kJi&9UCjQ%uUhZx#c(~UaBK2%1t1$ zt+AnQV2T7}&w(`u@klp=I1IfsYfj?yRhD?ZZa(otlVrMow&aY%m!D);VKYnprWj#- zFN70Tr{}!mzG1t`w8LJoB^moms-|{S&G9)J?_rcNBu9wsB1arw2YH~G!#SC`1pkmM zBpZuns5O^nMS&%OWxC#T@&X;b_{^EDaB7h_PAeA8D^tWNo+!ygnSv5)z^8JoD$}E- z#C(N<6{;h}0csZdS1DiR`VA^VRzv|Hz9Qw2<3b2TuPx{tWx}i?&A=+rY@K1S1|223 z{#jYjA}v78tM)EaW)HOa6K9+(t{aeKK48F=FU(vz^<_BL z(w7&h){&`TR&40VI&P1)hxR%;>~IswmN-F6Gu73$4V1f||J-0;9i-!IAR_OuED4R3 zg-M*q!lTrioa$?9StApNCiO!tYhIhXHBU{XMQca<*6u78cj9pr=zw`%bP;NqT1-@l2Vt8yq-S+IjvWFqWj8iR9xfVF>Z1Qf7s*&R_gc+?k(3wc| z2VS}_Sms^93D(TmR9s6;qEDjpSYi}m)5+0t*MazwLg70+0{Q&rn=bnrfSd=aq&6}5 zt>Qp@=v07hgSU;BxfSPgK%UuF4?%4SzJu90_CBx=omN9ikkj7pN4QdOk8n2o{ZSl@ zLnis~ZN-t6Q@F!++_^2-|9<>KrCh`rn^IB_${oJHvX237@BF$Q=z69v$2#(LRyR@o zUb{8er+GVY(WhP%#G?)ueFuZ2qT18086~0KPZFtM4}V^K&NuC+f*zs>bt)0*4&sSa k$~S1Or*WLT0 and ua<1 and ub>0 and ub<1: + total+=1 + return total + + def space_count(self, posNodes): + nodesPos = [(posNodes[i*2], posNodes[i*2+1]) for i in range(len(self.nodes[::2]))] + total=0 + for i in range(len(nodesPos)): + for j in range(i+1, len(nodesPos)): + (x1,y1)=nodesPos[i] + (x2,y2)=nodesPos[j] + den = abs(x1-x2)+abs(y1-y2) + if den < 25: + total+=1 + return total + +class GuiAlgorithmChoice(wx.Frame): + + def __init__(self, x, y): + wx.Frame.__init__(self, wx.GetApp().TopWindow, size=(442, 280), style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)) + self.x=x + self.y=y + self.Center() + self.SetTitle("Paramètres de l'algorithme") + self.initialize() + self.Show(True) + + def initialize(self): + self.label = wx.StaticText(self,-1,label='Choisissez un algorithme à appliquer sur le graphe:', pos=(5, 10)) + self.cb_chooseSim = wx.CheckBox(self, -1, "Exécuter l'algorithme de recuit simulé", pos=(30, 30)) + self.cb_chooseGen = wx.CheckBox(self, -1, "Exécuter l'algorithme génétique", pos=(30, 50)) + + self.label = wx.StaticText(self,-1,label="Ensuite, sélectionnez selon quel critère l'algorithme sera exécuté:", pos=(5, 70)) + self.cb_chooseCriteria_safe = wx.CheckBox(self, -1, 'Selon la taille moyenne de chaque segment', pos=(30, 130)) + self.cb_chooseCriteria_cost = wx.CheckBox(self, -1, "Selon la moyenne de différence de taille entre chaque segment", pos=(30, 90)) + self.cb_chooseCriteria_distance = wx.CheckBox(self, -1, 'Selon le nombre moyen de vannes requis pour isoler un segment', pos=(30, 110)) + self.cb_chooseCriteria_isolation = wx.CheckBox(self, -1, "Selon le nombre moyen d'isolements involontaires", pos=(30, 150)) + + + self.label = wx.StaticText(self,-1,label="Compléxite de l'algorithme de recuit simulé (température):", pos=(5, 175)) + self.inputNumberSimulatedAnnealing = wx.SpinCtrl(self, value='10000', pos=(290, 172), size=(60, -1), min=1, max=100000) + + self.label = wx.StaticText(self,-1,label="Compléxite de l'algorithme génétique (itérations max):", pos=(5, 200)) + self.inputNumberGenetic = wx.SpinCtrl(self, value='30', pos=(270, 197), size=(60, -1), min=1, max=5000) + + + + button_next = wx.Button(self,-1,label="Suivant", pos = (330, 220), size=(100, 25)) + self.Bind(wx.EVT_BUTTON, self.OnClick_button_Next, button_next) + + self.failVerify = wx.StaticText(self, -1, '', (5, 230)) + + self.Show(True) + + def OnClick_button_Next(self,event): + if self.verifyInput() == True: + self.failVerify.SetLabel("L'algorithme est entraîn de calculer, veuillez attendre...") + self.failVerify.SetForegroundColour((78,50,255)) + self.failVerify.Update() + self.network = GlobalNetwork("randomNetwork", '../../input/randomNetwork.dot') + + fitnessFunct = [self.network.nbr_valves] + + if self.cb_chooseCriteria_safe.GetValue()==True: + fitnessFunct.append(self.network.average_segment_size) + + if self.cb_chooseCriteria_cost.GetValue()==True: + fitnessFunct.append(self.network.standard_deviation_segment_size) + + if self.cb_chooseCriteria_distance.GetValue()==True: + fitnessFunct.append(self.network.average_valves_per_segment) + + if self.cb_chooseCriteria_isolation.GetValue()==True: + fitnessFunct.append(self.network.average_unintended_isolation) + + if self.cb_chooseGen.GetValue()==True: + miter = self.inputNumberGenetic.GetValue() + solGen = GuiShowSolution(self.x, self.y, "L'algorithme génétique", fitnessFunct, miter) + solGen.Show() + + if self.cb_chooseSim.GetValue()==True: + mtemperature = self.inputNumberSimulatedAnnealing.GetValue() + solSim = GuiShowSolution(self.x, self.y, "L'algorithme de recuit simulé", fitnessFunct, mtemperature) + solSim.Show() + + self.Close(True) + else: + self.failVerify.SetLabel('Données erronées ou incomplètes dans un ou plusieurs champs.') + self.failVerify.SetForegroundColour((255,0,0)) + + def verifyInput(self): + verify = True + if self.cb_chooseSim.GetValue()==False and self.cb_chooseGen.GetValue()==False: + verify=False + #elif self.cb_chooseCriteria_isolation.GetValue()==False and self.cb_chooseCriteria_cost.GetValue()==False and self.cb_chooseCriteria_distance.GetValue()==False and self.cb_chooseCriteria_safe.GetValue()==False: + #verify=False + return verify + +class GuiShowSolution(wx.Frame): + + def __init__(self, x, y, algotitle, fitnessFunct, complexity): + wx.Frame.__init__(self, wx.GetApp().TopWindow, size=(500, 550), style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)) + self.x=x + self.y=y + self.Center() + self.algo="gen" + if algotitle == "L'algorithme de recuit simulé": + self.algo="sim" + self.SetTitle("Le graphe de solution : " + algotitle) + self.network=GlobalNetwork("randomNetwork", '../../input/randomNetwork.dot') + self.iterationCount=0 + self.updateVar() + self.Show(True) + self.panel = wx.Panel(self, size=(500, 500)) + self.panel.Bind(wx.EVT_PAINT, self.draw_graph) + self.initialize() + self.runAlgorithm(fitnessFunct, complexity) + self.Fit() + + def runAlgorithm(self, fitnessFunct, complexity): + pattern = [(0,1) for i in range(self.network.network.nbrPipes*2)] + if self.algo=="gen": + solution = GeneticAlgorithm(pattern, fitnessFunct, showInfo = self.updateValves, nbrOfGenerations = complexity) + else: + solution = SimulatedAnnealing(pattern, fitnessFunct, showInfo = self.updateValves, temperature=complexity) + + self.network.update(solution.solution) + self.updateVar() + self.iterationCount=0 + self.panel.Refresh() + self.showSolutionScores() + + def initialize(self): + self.label = wx.StaticText(self,-1,label='', pos=(0, 0)) + button_next = wx.Button(self, -1, label='Suivant', pos = (398, 525), size=(100, 25)) + self.Bind(wx.EVT_BUTTON, self.on_button_click_next, button_next) + button_prec = wx.Button(self, -1, label='Précédent', pos = (398, 500), size=(100, 25)) + self.Bind(wx.EVT_BUTTON, self.on_button_click_prec, button_prec) + self.showScores(); + self.Show(True) + + def showSolutionScores(self): + self.label2 = wx.StaticText(self,-1,label="Nombre moyen de segments : " + str(round(self.network.average_segment_size(), 3)), pos=(0, 500)) + self.label3 = wx.StaticText(self,-1,label="Taille de la déviation de segments : " + str(round(self.network.standard_deviation_segment_size(), 3)), pos=(0, 515)) + self.label4 = wx.StaticText(self,-1,label="Nombre moyen de vannes par segment : " + str(round(self.network.average_valves_per_segment(), 3)), pos=(0, 530)) + self.label5 = wx.StaticText(self,-1,label="Nombre de valves : " + str(self.network.nbr_valves()) + " ; Coût (pour le prix d'une vanne de 500€) : " + str(self.network.nbr_valves()*500) + "€", pos=(0, 545)) + #self.label8 = wx.StaticText(self,-1,label="Nombre moyen d'isolements involontaires" + str(round(self.network.average_unintended_isolation)), pos=(0, 545)) + self.label7 = wx.StaticText(self,-1,label="___________________________________________________________________________________", pos=(0, 557)) + self.label6 = wx.StaticText(self,-1,label="Paramètres de l'algorithme:", pos=(0, 575)) + self.label6.SetForegroundColour((255,0,0)) + + def showCriteria(self): + self.labelRed = wx.StaticText(self,-1,label="Critère d'exécution:", pos=(250, 575)) + self.labelRed.SetForegroundColour((255,0,0)) + self.cb_chooseCriteria_cost = wx.CheckBox(self, -1, 'Moyenne de la taille de chaque segment', pos=(250, 590)) + self.cb_chooseCriteria_distance = wx.CheckBox(self, -1, "Différence de taille entre chaque segment", pos=(250, 605)) + self.cb_chooseCriteria_safe = wx.CheckBox(self, -1, 'Nbre moyen de vannes pour isoler un segment', pos=(250, 620)) + self.cb_chooseCriteria_isolation = wx.CheckBox(self, -1, "Nombre moyen d'isolements involontaires", pos=(250, 635)) + + def showScores(self): + self.showSolutionScores() + self.showCriteria() + if self.algo=="sim": + self.initSim() + else: + self.initGen() + + + def initSim(self): + self.label = wx.StaticText(self,-1,label="Vitesse de refroidissement (1-1000):", pos=(0, 590)) + self.inputCoolSpeed = wx.SpinCtrl(self, value='5', pos=(178, 587), size=(60, -1), min=0, max=1000) + + self.label = wx.StaticText(self,-1,label="Echelle de modification (1-100):", pos=(0, 610)) + self.inputModifictionRate = wx.SpinCtrl(self, value='10', pos=(178, 607), size=(60, -1), min=0, max=100) + + self.label = wx.StaticText(self,-1,label="Compléxite (température):", pos=(0, 630)) + self.inputTemperature = wx.SpinCtrl(self, value='100000', pos=(158, 627), size=(80, -1), min=1, max=9999999) + + button_sim = wx.Button(self, -1, label='Mettre à jour', pos = (398, 655), size=(100, 25)) + self.Bind(wx.EVT_BUTTON, self.on_button_click_sim, button_sim) + + def initGen(self): + self.label = wx.StaticText(self,-1,label="Taille de la population:", pos=(0, 590)) + self.inputPopulationSize = wx.SpinCtrl(self, value='40', pos=(150, 587), size=(60, -1), min=0, max=250) + + self.label = wx.StaticText(self,-1,label="Taille du tournoi:", pos=(0, 610)) + self.inputTournmanetSize = wx.SpinCtrl(self, value='2', pos=(150, 607), size=(60, -1), min=0, max=100) + + self.label = wx.StaticText(self,-1,label="Facteur de sélection (%):", pos=(0, 630)) + self.inputSelectionRate = wx.SpinCtrl(self, value='50', pos=(150, 627), size=(60, -1), min=0, max=100) + + self.label = wx.StaticText(self,-1,label="Probabilité de crossover (%): ", pos=(0, 650)) + self.inputCrossOverProb = wx.SpinCtrl(self, value='50', pos=(150, 647), size=(60, -1), min=0, max=100) + + self.label = wx.StaticText(self,-1,label="Probabilité de mutation (%):", pos=(0, 670)) + self.inputMutationProba = wx.SpinCtrl(self, value='1', pos=(150, 667), size=(60, -1), min=0, max=100) + + self.label = wx.StaticText(self,-1,label="Facteur d'élitisme (1-1000):", pos=(0, 690)) + self.inputElitisme = wx.SpinCtrl(self, value='125', pos=(150, 687), size=(60, -1), min=0, max=1000) + + + self.label = wx.StaticText(self,-1,label="Compléxite (itérations max):", pos=(0, 710)) + self.inputMaxIter = wx.SpinCtrl(self, value='30', pos=(150, 707), size=(60, -1), min=1, max=99999999) + + button_gen = wx.Button(self, -1, label='Mettre à jour', pos = (398, 710), size=(100, 25)) + self.Bind(wx.EVT_BUTTON, self.on_button_click_gen, button_gen) + + def on_button_click_sim(self,event): + self.labelWorking = wx.StaticText(self,-1,label="L'algorithme est entraîn de calculer..", pos=(218, 660)) + self.labelWorking.SetForegroundColour((78, 50, 255)) + self.labelWorking.Update() + + fitnessFunct = [self.network.nbr_valves] + + if self.cb_chooseCriteria_safe.GetValue()==True: + fitnessFunct.append(self.network.average_segment_size) + + if self.cb_chooseCriteria_cost.GetValue()==True: + fitnessFunct.append(self.network.standard_deviation_segment_size) + if self.cb_chooseCriteria_distance.GetValue()==True: + fitnessFunct.append(self.network.average_valves_per_segment) + + if self.cb_chooseCriteria_isolation.GetValue()==True: + fitnessFunct.append(self.network.average_unintended_isolation) + + coolS=float(self.inputCoolSpeed.GetValue())/1000 + modif=float(self.inputModifictionRate.GetValue())/100 + + self.network=GlobalNetwork("randomNetwork", '../../input/randomNetwork.dot') + pattern = [(0,1) for i in range(self.network.network.nbrPipes*2)] + #solution = SimulatedAnnealing(pattern, self.network.average_segment_size, temperature=self.inputTemperature.GetValue(), coolSpeed=self.inputCoolSpeed.GetValue(), modificationRate=self.inputModifictionRate.GetValue()) + solution = SimulatedAnnealing(pattern, fitnessFunct, showInfo = self.updateValves, temperature=self.inputTemperature.GetValue(), coolSpeed=coolS, modificationRate=modif) + + self.network.update(solution.solution) + self.updateVar() + self.iterationCount=0 + self.panel.Refresh() + self.showSolutionScores() + + self.labelWorking.SetLabel("") + self.labelWorking.Update() + + def on_button_click_gen(self,event): + self.labelWorking = wx.StaticText(self,-1,label="L'algorithme est entraîn de calculer..", pos=(218, 715)) + self.labelWorking.SetForegroundColour((78, 50, 255)) + self.labelWorking.Update() + + fact = float(self.inputSelectionRate.GetValue())/100 + elit = float(self.inputElitisme.GetValue())/1000 + cross = float(self.inputCrossOverProb.GetValue())/100 + muta = float(self.inputMutationProba.GetValue())/100 + + fitnessFunct = [self.network.nbr_valves] + + if self.cb_chooseCriteria_safe.GetValue()==True: + fitnessFunct.append(self.network.average_segment_size) + + if self.cb_chooseCriteria_cost.GetValue()==True: + fitnessFunct.append(self.network.standard_deviation_segment_size) + + if self.cb_chooseCriteria_distance.GetValue()==True: + fitnessFunct.append(self.network.average_valves_per_segment) + + if self.cb_chooseCriteria_isolation.GetValue()==True: + fitnessFunct.append(self.network.average_unintended_isolation) + + self.network=GlobalNetwork("randomNetwork", '../../input/randomNetwork.dot') + pattern = [(0,1) for i in range(self.network.network.nbrPipes*2)] + solution = GeneticAlgorithm(pattern, fitnessFunct, showInfo = self.updateValves, nbrOfGenerations = self.inputMaxIter.GetValue(), populationSize=self.inputPopulationSize.GetValue(), tournamentSize=self.inputTournmanetSize.GetValue(), selectionRate=fact, elitisme=elit, crossoverProb=cross, mutationProba=muta) + + self.network.update(solution.solution) + self.updateVar() + self.iterationCount=0 + self.panel.Refresh() + self.showSolutionScores() + + self.labelWorking.SetLabel("") + self.labelWorking.Update() + + def on_button_click_next(self,event): + algo = GuiTerminateSimulation() + algo.Show() + self.Close(True) + + def on_button_click_prec(self,event): + algo = GuiAlgorithmChoice(self.x, self.y) + algo.Show() + self.Close(True) + + def updateVar(self): + self.nodes = self.network.network.nodeMap.values() + self.pipes = self.network.network.pipeMap.values() + + def updateValves(self, valvesCode, data): + self.data=data + + self.network.update(valvesCode) + self.updateVar() + + self.iterationCount=self.iterationCount+1 + self.showUpdateScores(data) + + self.panel.Refresh() + self.panel.Update() + + def showUpdateScores(self, data): + if self.algo=="gen": + self.label5.SetLabel("Nombre de valves : " + str(data[0]) + " ; Coût (pour le prix d'une vanne de 500€) : " + str(data[0]*500) + "€") + self.label5.Update() + + def draw_graph(self, event): + #LINES = PIPES, CIRCLE = NODES, RECTANGLE = VALVES + dc = wx.PaintDC(self.panel) + r=5 + dc.SetPen(wx.Pen('red', 1)) + dc.SetBrush(wx.Brush('yellow')) + + x_positions= self.x + y_positions= self.y + + scoreTotal=0 + for score in self.data: + scoreTotal=scoreTotal+score + + if self.iterationCount!=0: + + dc.DrawText("Itération " + str(self.iterationCount) + " ; Score : " + str(round(scoreTotal, 3)), 5, 5) + else: + dc.DrawText("Qualité globale de la solution : " + str(round(scoreTotal, 3)) , 5, 5) + + for i, node in enumerate(self.nodes): + if i==0: + dc.DrawRectangle(x_positions[node]-7, y_positions[node]-7, r+10, r+10) + else: + dc.DrawCircle(x_positions[node], y_positions[node], r) + + for pipe in self.pipes: + nodeA = pipe.id[0] + nodeB = pipe.id[1] + dc.SetPen(wx.Pen('green', 1)) + dc.SetBrush(wx.Brush('blue')) + dc.DrawLine(x_positions[nodeA], y_positions[nodeA], x_positions[nodeB], y_positions[nodeB]) + + y2 = float(y_positions[nodeB]) + y1 = float(y_positions[nodeA]) + x2 = float(x_positions[nodeB]) + x1 = float(x_positions[nodeA]) + + b=0 + if x1==x2: + dist=0 + signe=1 + if y1>y2: + dist=y1-y2 + signe=-1 + else: + dist=y2-y1 + + if pipe.valveAtStart: + dc.SetPen(wx.Pen('blue', 1)) + dc.SetBrush(wx.Brush('blue')) + rect = wx.Rect(x1, y1+(dist*0.2*signe), 6, 6) + dc.DrawRoundedRectangleRect(rect, 1) + if pipe.valveAtEnd : + dc.SetPen(wx.Pen('blue', 1)) + dc.SetBrush(wx.Brush('blue')) + #rect = wx.Rect(x2 + (-signe*15) , a*(x2-signe*15)+b, 6, 6) + rect = wx.Rect(x2, y2+(dist*0.2*(-signe)), 6, 6) + dc.DrawRoundedRectangleRect(rect, 1) + + if x1!=x2: + b = (y2-(y1*x2/x1))/(1-(x2/x1)) + a = (y1-b)/x1 + pixel = 15 + if abs(a)>4: + pixel=2 + signe = -1 + if x1%&EdKH=l-AncK*Zs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YvnEu^zvU-RF2mI+eT=o=;W5i~;x)$*izKp+xMm$X)6c&>Q zg&r~!Lk+ws=+VhHCb(<~-qBw~^3a9R-=ecGU-L|!V{nE6tynTzNe2=Swmty=%mUJH z4T=Z%au{a*_Fv~#N&|S!{yo1pxS=w;_rMou5dVgAqkW@Kj*gDLH~PZpiP6VKk2Cjw E0f@zeMgRZ+ literal 0 HcmV?d00001 diff --git a/src/hydraulic_network/__init__.py b/src/hydraulic_network/__init__.py new file mode 100644 index 0000000..a62f963 --- /dev/null +++ b/src/hydraulic_network/__init__.py @@ -0,0 +1,16 @@ +from hydraulic_network.networks import Network +from hydraulic_network.networks import NetworkMatrix +from hydraulic_network.networks import ValveDeficiencyMatrix +from hydraulic_network.networks import ValveLocationMatrix + +from hydraulic_network.segmentgraph import SegmentValveGraph +from hydraulic_network.segmentgraph import Segment +from hydraulic_network.segmentgraph import SegmentValveMatrix + +from hydraulic_network.globalnetwork import GlobalNetwork + +from hydraulic_network.pipe import Pipe + +from hydraulic_network.node import Node + +from hydraulic_network.valve import Valve \ No newline at end of file diff --git a/src/hydraulic_network/__init__.pyc b/src/hydraulic_network/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c19cdb6b77246235b88223aeff933d7099e34576 GIT binary patch literal 848 zcmZ{h&5qMB5XUD;KeO#pzNJ0DwHG!outFR_dtobZC6IiHvWaOe#z_>rg}xVW#sk2N z9iXtqj>q}U-}cPd$@h7RHy7_q=vz$lD;oA2nToy$5WqwrBZ!z|&oRh2aN;=unFJnq z9)KJK9s&-*j6jY8k35e-jsuT9Pe4urPXMQ2QjlrjDc~8H8OT}S6mSma9OQZ6Gr)Ub z79bbIGgvR@l(_yuZ5h#@8@!+4e$LDZr*Vx<^_*cdQa=+893I{N) znyRNEk&n4rau)7_%=S=q#SV3u*P-ysezt;C5PUC!A6g`2+%qzFx7bk6hD#9~Q*bCT z;vLUV?%4Ru`%r@K-90(Eu%%kWHjkG&Js%avA8DhZ2UD6lkH4&<=%W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H`Bk8fhfp})Wp>naA z#%42W^1Kxs*grP-bozaKJ5UM8;K-&dsXzP)f0#Yv4*;fl>JJq#p@_~QYl^nU+mkq= z;a7vI-|N{p&>WchF+xiNt7D`^2JLf>;&C+7;O?IK6uo8N9-Va{KJ}^t@p#?t8S;3# zkqpwVWd=uq1xjig>bxK9p-hRpN00nG4TtJ^IsFn780v)iE^5m)8>u(rWGy98U-hEU z21QZ8%IIWdJ1xsR9L9Knl%ci5MY;2J>Ru-MK^(?8;I@GmW=W*k<0C5jIhw+unKI^_ z+s=YnFgH!hX_+ZF_=35FwqfcHX7zu;yo=wKx$KmM0@DhOzKU=5H5!z!McoAfGzL#e zyt@-O1epq_XHBbN0V^P&rj7M=VUmGZeJF(aQLik)ipr|YLYWq=%8UOe6=|%0#A~yF z5VK_FO;O*|-kulx2iEhn9Q3?{Bp5{KY8_jYD-5_U&Ezt_yUT3oDW?ok>Ax+jX*zvV zU`?-8tt{#Bpr8$|KeKuf6co9#WjXc3k9L)XnY` PKz~X9R=do@D)Y`iI!7xo literal 0 HcmV?d00001 diff --git a/src/hydraulic_network/networks.py b/src/hydraulic_network/networks.py new file mode 100644 index 0000000..7bca7df --- /dev/null +++ b/src/hydraulic_network/networks.py @@ -0,0 +1,217 @@ +# -*-coding:Utf-8 -* + +from hydraulic_network.node import Node +from hydraulic_network.pipe import Pipe +from math import sqrt +from compiler.ast import Print +import copy +import pipes + +class Network(object): + """Contient les information d'un réseau. + Attributs: + - nodes : liste de nodes + - pipeMap : liste de pipeMap""" + + def __init__(self, inId, dotFilePath="none"): #construit le graphe a partir d'un fichier DOT + super(Network, self).__init__() + + self.id=inId; + + self.nbrNodes = 0 + self.nbrPipes = 0 + + self.nodeMap = dict() + self.pipeMap = dict() + + if dotFilePath != "none": + lecture = open(dotFilePath, "r") + + for i in lecture: + lineNodes = i[:-2].split(" ") + firstNode = Node(lineNodes.pop(0)) + if not self.is_in_nodes(firstNode): + self.add_node(firstNode) + else: + firstNode = self.get_node_by_id(firstNode.id) + + for pipeInfo, nodeID in zip(lineNodes[0::2], lineNodes[1::2]): + secondNode = Node(nodeID) + if not self.is_in_nodes(secondNode): + self.add_node(secondNode) + else: + secondNode = self.get_node_by_id(secondNode.id) + currPipe = Pipe(firstNode, secondNode) + if pipeInfo[0] == "|": + currPipe.set_valve_node_side(firstNode, True) + if pipeInfo[1] == "|" : + currPipe.set_valve_node_side(secondNode, True) + self.add_pipe(currPipe) + firstNode = secondNode + lecture.close + + self.networkMatrix = NetworkMatrix(self) + self.valveLocationMatrix = ValveLocationMatrix(self) + self.valveDeficiencyMatrix = ValveDeficiencyMatrix(self) + + def is_in_nodes(self, node): + for currNode in self.nodeMap.values(): + if currNode == node: + return True + return False + + def get_node_by_id(self, inId): + for currNode in self.nodeMap.values(): + if currNode.id == inId: + return currNode + + def get_valve_count(self): + valveCount = 0 + for valveIter in range(self.nbrPipes): + if self.pipeMap[valveIter].valveAtStart: + valveCount += 1 + if self.pipeMap[valveIter].valveAtEnd: + valveCount += 1 + return valveCount + + def __str__(self): + string = "" + for node in self.nodeMap.values(): + for connectedNode in node.connected_nodes(): + string += (node.id + " -- "+ connectedNode.id) + return string + + def str_elements(self): + string = "Nodes: " + for node in self.nodeMap.values(): + string += node.id+" " + string += "\n" + string += "Pipes: " + for pipe in self.pipeMap.values(): + string += str(pipe)+" " + string +="\n" + return string + + def set_valves(self, valvesCode): + """Méthode permettant de positionner les valves selon un + vecteur""" + if len(valvesCode) != 2*self.nbrPipes: + print("Erreur, longueur du code génétique invalide") + else: + for i in range(self.nbrPipes): + if valvesCode[i*2] == 1: + self.pipeMap[i].set_valve_at_start(True) + elif valvesCode[i*2] == 0: + self.pipeMap[i].set_valve_at_start(False) + + if valvesCode[i*2+1] == 1: + self.pipeMap[i].set_valve_at_end(True) + elif valvesCode[i*2+1] == 0: + self.pipeMap[i].set_valve_at_end(False) + self.update() + + def add_node(self, inNode, key = -1): + if key > -1: + self.nodeMap[key] = inNode + else: + self.nodeMap[self.nbrNodes] = inNode + self.nbrNodes+=1 + + def add_pipe(self, inPipe, key = -1): + if key > -1: + self.pipeMap[key] = inPipe + else: + self.pipeMap[self.nbrPipes] = inPipe + self.nbrPipes+=1 + + def __len__(self): + return len(self.nbrPipes) + + def update(self): + self.networkMatrix.update(self) + self.valveLocationMatrix.update(self) + self.valveDeficiencyMatrix.update(self) + + +class NetworkMatrix(object): + + def __init__(self, inNetwork): + super(NetworkMatrix, self).__init__() + + self.network = inNetwork + self.rowNbr = inNetwork.nbrNodes + self.columnNbr = inNetwork.nbrPipes + self.matrix = [ [ 0 for i in range(self.columnNbr) ] for j in range(self.rowNbr) ] + self.update(inNetwork) + + def __str__(self): + string = "" + string += str(len(self.network.pipeMap))+'\n' + string += str(self.network.pipeMap.values())+'\n' + for i,v in enumerate(self.matrix): + string += self.network.nodeMap.values()[i].id + str(v) + "\n" + return string + + def get_value(self, inRow, inColumn): + return self.matrix[inRow][inColumn] + + def update(self, inNetwork): + for row in range(inNetwork.nbrNodes): + currNode = inNetwork.nodeMap[row] + for column in range(self.columnNbr): + currPipe = inNetwork.pipeMap[column] + if currPipe in currNode.connectedPipes: + self.matrix[row][column] = 1 + +class ValveLocationMatrix(object): + + def __init__(self, inNetwork): + super(ValveLocationMatrix, self).__init__() + self.network = inNetwork + self.rowNbr = inNetwork.nbrNodes + self.columnNbr = inNetwork.nbrPipes + self.matrix = [ [ 0 for i in range(self.columnNbr) ] for j in range(self.rowNbr) ] + self.update(inNetwork) + + def __str__(self): + string = "" + for i in self.matrix: + string = string + str(i) + "\n" + return string + + def update(self, inNetwork): + self.matrix = [ [ 0 for i in range(self.columnNbr) ] for j in range(self.rowNbr) ] + for row in range(self.rowNbr): + currNode = inNetwork.nodeMap[row] + for column in range(self.columnNbr): + currPipe = inNetwork.pipeMap[column] + if (currPipe.startingNode == currNode and currPipe.valveAtStart) or (currPipe.endingNode == currNode and currPipe.valveAtEnd): + self.matrix[row][column] = 1 + + def get_value(self, inRow, inColumn): + return self.matrix[inRow][inColumn] + +class ValveDeficiencyMatrix(object): + + def __init__(self, inNetwork): + super(ValveDeficiencyMatrix, self).__init__() + self.network = inNetwork + self.rowNbr = inNetwork.nbrNodes + self.columnNbr = inNetwork.nbrPipes + self.matrix = [ [ 0 for i in range(self.columnNbr) ] for j in range(self.rowNbr) ] + self.update(inNetwork) + + def __str__(self): + string = "" + for i in self.matrix: + string = string + str(i) + "\n" + return string + + def get_value(self, inRow, inColumn): + return self.matrix[inRow][inColumn] + + def update(self, inNetwork): + self.matrix = [ [ 0 for i in range(self.columnNbr) ] for j in range(self.rowNbr) ] + for i in range(self.rowNbr): + for j in range(self.columnNbr): + self.matrix[i][j] = inNetwork.networkMatrix.get_value(i, j) - inNetwork.valveLocationMatrix.get_value(i, j) diff --git a/src/hydraulic_network/networks.pyc b/src/hydraulic_network/networks.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2aab43b9a804f31431def2faf9691e3b7a587ccb GIT binary patch literal 10189 zcmd^F+ix6K9X_+W-t}(m#LdN*Hk54LyDx`MPrfN(wZfk1cj@CO9dz{_b z-I>|cuACxBK?n);0r7+cZ-`1ffK)(2NJx}7ctS$(z$~QcJpV zYTG8z^GX~>>1tZypdfv{9bX@CCI{LxNXZ+>0z-y?9~(Kc2wZs!EXo@{&+Tj!j9*Y; zf_oyR$V0PG$_`DIOo{@2;8W2I6_s&P%m$83sRNjxQ*KNf*Pbug#U7U1Q5ptOT5SeN zHH@yc<5oQl+fmhjuoqS1_uff@dhdLtd?8KaaI2RlPgTn2su6gRRG+Fg!z2x=eqae~ z>3}bn>z&cIj3g#T?I>taJ&qxfLCZ+V-@xP)AIBU(kU6uPqd1)d)jcr87Qhf&m@sLP zJw^zM=BJv{wdtqgImhRBRdOM%3ViNk-v&{V93G>}j>$LyeX zmc7_D>2-qGEwDO?%=5x1Og%5v0AI9dE2fbq{R(X~k=prTBb7Z;aiN|nkLqQ+0~^pX zoo1N2Siq!I(@whsy}*_dtmjGXHGAFnRZ9sJ+d-;|x3%wu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diff --git a/src/hydraulic_network/node.py b/src/hydraulic_network/node.py new file mode 100644 index 0000000..b695569 --- /dev/null +++ b/src/hydraulic_network/node.py @@ -0,0 +1,53 @@ +# -*-coding:Utf-8 -* + +from hydraulic_network.pipe import Pipe + +class Node(object): + """Classe qui contient les informations sur un noeud + Attributs: + - id + - rowNbr : int + - connectedPipes : liste de Pipe""" + + def __init__(self, inId): + super(Node, self).__init__() + self.id = inId + self.connectedPipes = [] + + def __hash__(self): + return hash(self.id) + + def __eq__(self, other): + return self.id == other + + def __repr__(self): + return self.id + + def __str__(self): + return self.id + + def add_pipe(self, inPipe): #connecte un tuyau à self + self.connectedPipes.append(inPipe) + + def nbr_near_valves(self): #renvoie le nombre de valves proche du noeud + toReturn=0 + for pipe in self.connectedPipes: + if (self==pipe.startingNode and pipe.valveAtStart) or (self==pipe.endingNode and pipe.valveAtEnd): + toReturn += 1 + return toReturn + + def set_valve_at_pipe(self, inPipe, inValve): #place ou retire une valve sur le tuyau inPipe près de self + if (inPipe in self.connectedPipes): + if inPipe.startingNode == self: + inPipe.set_valve_at_start(inValve) + else: + inPipe.set_valve_at_end(inValve) + + def connected_nodes(self): + connectedNodes = [] + for pipe in self.connectedPipes: + if pipe.startingNode == self: + connectedNodes.append(pipe.endingNode) + else: + connectedNodes.append(pipe.startingNode) + return connectedNodes \ No newline at end of file diff --git a/src/hydraulic_network/node.pyc b/src/hydraulic_network/node.pyc new file mode 100644 index 0000000000000000000000000000000000000000..30c4e9fbccb3774fcbaf9cc984ad153400427c21 GIT binary patch literal 2926 zcmd5;U2oeq6up$cVs~BKrPzQC1N1g;K;vOAD~h6M>vh0hyiNgDEW<#^A`>%_B}b&w z6-b}DAGZIrAF$nXWhu$_>|(Y^U6K;-;o;%E>il(g^ym3EKV`K2b@=|2i~ou%!u?hasX!sy@CdREQ zU(Xj+{D@x+X!B%+&4M*ptmppR`CwyXV{~K@yG8-4GcNv1t^!|*u9&}w&LXg=uB5Fy zbV?Y|ymn$z!PQ)-4d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001 diff --git a/src/hydraulic_network/segmentgraph.py b/src/hydraulic_network/segmentgraph.py new file mode 100644 index 0000000..75f5e45 --- /dev/null +++ b/src/hydraulic_network/segmentgraph.py @@ -0,0 +1,163 @@ +# -*-coding:Utf-8 -* + +''' +Created on 13 déc. 2012 + +@author: jwillaim +''' + +from hydraulic_network.networks import Network +from hydraulic_network.valve import Valve +import copy + +class SegmentValveGraph(object): + + def __init__(self, inNetwork): + super(SegmentValveGraph, self).__init__() + + self.segmentMap = dict() + self.valveMap = dict() + self.segmentNbr = 0 + self.valveNbr = 0 + + self.nodes = copy.copy(inNetwork.nodeMap) + self.pipes = copy.copy(inNetwork.pipeMap) + + self.nodesExplored = [] + self.pipesExplored = [] + + self.defMatrix = inNetwork.valveDeficiencyMatrix + + for node in self.nodes.keys(): + if inNetwork.valveLocationMatrix.matrix[node] == inNetwork.networkMatrix.matrix[node]: + newSegment = Segment("Seg "+ str(self.segmentNbr)) + newSegment.add_node(self.nodes[node], node) + self.add_new_segment(newSegment) + self.nodesExplored.append(node) + + for columnNbr in self.pipes.keys(): + pipesToAdd = [] + nodesToAdd = [] + if columnNbr not in self.pipesExplored: + self.explore_pipe(columnNbr, pipesToAdd, nodesToAdd) + newSegment = Segment("Seg "+ str(self.segmentNbr)) + for node in nodesToAdd: + newSegment.add_node(self.nodes[node], node) + for pipe in pipesToAdd: + newSegment.add_pipe(self.pipes[pipe], pipe) + self.add_new_segment(newSegment) + + for segment in self.segmentMap.values(): + valvesOfSegment = segment.names_of_valves() + for name in valvesOfSegment: + needNew = True + for valve in self.valveMap.values(): + if name == valve.id: + segment.add_valve(valve) + valve.endingSegment = segment + needNew = False + + if needNew: + newValve = Valve(name, segment) + self.add_new_valve(newValve) + + self.segValveMatrix = SegmentValveMatrix(self) + + def explore_pipe(self, pipe, inPipesToAdd, inNodesToAdd): + if pipe not in self.pipesExplored: + inPipesToAdd.append(pipe) + self.pipesExplored.append(pipe) + for row in range(len(self.defMatrix.matrix)): + if self.defMatrix.get_value(row, pipe) == 1: + self.explore_node(row, inPipesToAdd, inNodesToAdd) + + def explore_node(self, node, inPipesToAdd, inNodesToAdd): + if node not in self.nodesExplored: + inNodesToAdd.append(node) + self.nodesExplored.append(node) + for column in range(len(self.defMatrix.matrix[node])): + if self.defMatrix.get_value(node, column) == 1: + self.explore_pipe(column, inPipesToAdd, inNodesToAdd) + + def add_new_segment(self, inSegment): + self.segmentMap[self.segmentNbr] = inSegment + self.segmentNbr+=1 + + def add_new_valve(self, inValve): + self.valveMap[self.valveNbr] = inValve + self.valveNbr+=1 + + def str_segments(self): + string = "" + for seg in self.segmentMap.values(): + string += seg.id + ", " + string += seg.str_elements() + string += "\n" + return string + + def str_valves(self): + string = "" + for valve in self.valveMap.values(): + string += str(valve) + "\n" + return string + +class Segment(Network): + + def __init__(self,inId, dotFilePath="none"): + super(Segment, self).__init__(inId, dotFilePath="none") + self.connectedValves = [] + + def add_valve(self, inValve): + self.connectedValves.append(inValve) + + def names_of_valves(self): + valvesNames = [] + + for pipe in self.pipeMap.values(): + if pipe.valveAtStart: + name = str(pipe) + "-" + str(pipe.startingNode) + if not name in valvesNames: + valvesNames.append(name) + if pipe.valveAtEnd: + name = str(pipe) + "-"+ str(pipe.endingNode) + if not name in valvesNames: + valvesNames.append(name) + + for node in self.nodeMap.values(): + for pipe in node.connectedPipes: + if pipe.valveAtStart and pipe.startingNode == node: + name = str(pipe) + "-" + str(node) + if not name in valvesNames: + valvesNames.append(name) + if pipe.valveAtEnd and pipe.endingNode == node: + name = str(pipe) + "-"+ str(node) + if not name in valvesNames: + valvesNames.append(name) + return valvesNames + +class SegmentValveMatrix(object): + + def __init__(self, inSegmentValveGraph): + super(SegmentValveMatrix, self).__init__() + + self.rowNbr = inSegmentValveGraph.segmentNbr + self.columnNbr = inSegmentValveGraph.valveNbr + + self.matrix = [ [ 0 for i in range(self.columnNbr) ] for j in range(self.rowNbr) ] + + for row in range(self.rowNbr): + currSeg = inSegmentValveGraph.segmentMap[row] + for column in range(self.columnNbr): + currValve = inSegmentValveGraph.valveMap[column] + if currValve in currSeg.connectedValves: + self.matrix[row][column] = 1 + + def __str__(self): + string = "" + for i in self.matrix: + string = string + str(i) + "\n" + return string + + def get_value(self, inRow, inColumn): + return self.matrix[inRow][inColumn] + \ No newline at end of file diff --git a/src/hydraulic_network/segmentgraph.pyc b/src/hydraulic_network/segmentgraph.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d1392db26d9af0dffae7f1267e4d7584c42e31db GIT binary patch literal 6962 zcmcgx&u<&Y6@Ig%D3KOzIkqIrc4FCXQZ|jP+6m$|aa-Gx?K)@}XJwd;3YDO_D`{zJ zN$##J3ZM!UG7z9`&|cC@4nZzyd+4dRqUfbS4+i=_w0}cSKDFQXW=YDje5)nz3}@c_ zdcWqIH{;BIiiO|&xn~vgC+iJtNJGtY>8@YwKBQ zj>yu8cq8KHWCcBP@>pa?7?(@5JH>1CubozAFZAs76HOPpXMdTFI7 zjTuhPdgpV&SLyyu$Bhp-`IBsC$@KP!<~iwQwZ~z3I4aQ@o#&(yN2CWPGSJ_P`0BpS zE(^=As&xA^*@;bs{YGrRQ5EJ?%2aO@iWpU4I$xN|GXiza7<`rP@3n7M8mFx)e<#~8 z5e)Sz>)Uzh{z7_r%)TYtFxG3beMq`Db>EpolXRCz7ae~gIgRjy%B+*looY$da2Z=#UUXXA~wAG!2m_#M2n8iYYottRa01@$B;u#??bAJ*F1=@GXa zE4$jt529fkE1aO-YH#VT4O^ZL;EF8AN^J-20hQ%ADfZiMcH7NX>vp8BYmp^wo--MwhTPiU9GQ^7b^n^h%PA_!Oe3{tJPYR%Yp6(=c8pEWz=6;RU7_pR|% zVFWJlzKc{MN!O44=87&Hgem4KS!Ji)Lw~csJoR30H8<8n8lH`6v3srSo~KncxvkPF zssbt)YZI_l2g+#t(Mo?(cBEdc|MRa7nzu2&bS#jd6Rc0&7{NMac9cRni(@~ie?(+9R3|K$3Q8XQ<{#0I*wA#OrfQS z(M5-SPB?YWPCGKqBgL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Y8_y{lhPK$@T796@0aw2)gBpZ8e07;@Z~f&Md#`X2#h%~hbG zEc!GNgl=n7L&6}O*C(oj5lk=DUx8h{d&vHf_6gdx;Q( zN=@Ol>Ij<|7(e$Qb}@Yzi+Nj>M6q%2quE70bMzU~EwC3?X+3Bl64Xa#jcawgAE3-? a|Eu;A@B?mreO1Ug6L2%U+5L3t-2VWI8QMtz literal 0 HcmV?d00001 diff --git a/src/hydraulic_network/valve.py b/src/hydraulic_network/valve.py new file mode 100644 index 0000000..5b12721 --- /dev/null +++ b/src/hydraulic_network/valve.py @@ -0,0 +1,16 @@ +# -*-coding:Utf-8 -* + +class Valve(object): + + def __init__(self, inId, inStartingSeg): + super(Valve, self).__init__() + + self.id = inId + self.startingSegment = inStartingSeg + self.endingSegment = None + + def __str__(self): #imprime l'id de la valve, ainsi que l'ID des deux segments qu'elle délimite + if(self.endingSegment!= None): + return self.id+ ": " + self.startingSegment.id +" - "+ self.endingSegment.id + else: + return self.id+ ": " + self.startingSegment.id +" - None" \ No newline at end of file diff --git a/src/hydraulic_network/valve.pyc b/src/hydraulic_network/valve.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1e92b0d56ef9318c45b18f8c29f947ae986bc917 GIT binary patch literal 1043 zcmcgr!A=`75FLAILQoNh9*{Ui;<6W5DMwUQRjVF)39u`Hh*Vk2t^*sK-DvHkij*6C z5x>R{FmDo?17{k=kxK0Hf(Ae_Svy@xlOGPioCaOEWoP%T?(+Ov+X`HLr9FjU@y6ErZy=X=knGk*G>E2 zXL(_hUxlk?-kNP>?ru-~!X>^flKW-Z=5tpShPnLZqGSPiPiM;%?B#Sg6R9t{r+TWu z(J_z}3D4PKX(n=c4-vHkS&I6HNJLQeknd1d9AGa);vFR7gy<{kc(gd{dt6xmr0*d& z&rmG}Anm|_VG2l!nA}VXp_OpfjZVgZu1c8d}{e2>R uQ8q?O>kj2(2w>dYPHYk6>HZHcqRQ8`4&Q_mbD&oNW#upc literal 0 HcmV?d00001 diff --git a/src/infodata.py b/src/infodata.py new file mode 100644 index 0000000..a3d8bed --- /dev/null +++ b/src/infodata.py @@ -0,0 +1,34 @@ +# -*-coding:Utf-8 -* + +from hydraulic_network.globalnetwork import GlobalNetwork +from optimization import * + +import time + +def evol_qual(num, best): + f = open('/home/dollars/Desktop/gen_var-best.txt', 'a') + f.write('{0} {1}\n'.format(num, best)) + f.close() + + +def avg_result(): + f = open('/home/dollars/Desktop/gen_var-avg_qual.txt', 'a') + avgQual = GeneticAlgorithmVariation(pattern, [myNetwork.average_valves_per_segment, myNetwork.average_segment_size, myNetwork.standard_deviation_segment_size, myNetwork.nbr_valves, myNetwork.average_unintended_isolation]) + f.write('{0}\n'.format(avgQual.assess_fitness(avgQual.bestSolution))) + f.close() + +if __name__=="__main__": + print("Collecting information.") + myNetwork = GlobalNetwork("ferraraNetwork", "../input/ferraraNetwork.dot") + pattern = [(0,1) for i in range(myNetwork.network.nbrPipes*2)] + + t0 = time.time() + evolQual = GeneticAlgorithmVariation(pattern, [myNetwork.average_valves_per_segment, myNetwork.average_segment_size, myNetwork.standard_deviation_segment_size, myNetwork.nbr_valves, myNetwork.average_unintended_isolation], evol_qual) + print(time.time()-t0) + + for i in range(50): + avg_result() + + + + \ No newline at end of file diff --git a/src/optimization/__init__.py b/src/optimization/__init__.py new file mode 100644 index 0000000..40d475c --- /dev/null +++ b/src/optimization/__init__.py @@ -0,0 +1,4 @@ +from optimization.genetic_algorithm import GeneticAlgorithm +from optimization.genetic_algorithm import GeneticAlgorithmVariation +from optimization.simulated_annealing import SimulatedAnnealing +from optimization.backtracking import Backtracking \ No newline at end of file diff --git a/src/optimization/__init__.pyc b/src/optimization/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f083d73ae0b41d8023a12d42a4b2cc690eeecf82 GIT binary patch literal 473 zcmZutO-sZu5S@N(6;W8cd09O6;^q&CxT1JlunP*kglrnRVe?U%RM7w6ul43dr;Wub zCYhJKdBeOR$@|IC+Xs8#@V#QZuQA*$LWL&+1)w7+BZzt)4?Ko44m<&sfKH)I15ZKC zKxa^9$Y-$0Gi)S3ape)d{2bw47~v&fsoJ*E?{rYk{!t!TE18$pgpyM%*+|_f=0&wK zMldB!9kgTAZW!PD76G&C`~Wk4fnXaiwR{~KE$d)T+2~$i1r)<@=YNacXhzxSR`g%w z`(b~z-A=5F1l1g40&b0z?5q}~vP!Ymktf^kUBkE_cU;NF3Hp=i)b_$XE8<#CrapvH cX{4ug*}V8eY-&Y{}7%UMuw7AYUpRxa59tb1He(r!}bc~seMzpTb~8pUb%U7TlA zn})ZRSw7gYr+L>_akrehY?7TvE-Q=f;7)SSreEDM-0tPkWROJr49kKfrql%Ss}Y|= zxbWmcB!pm8Fyde_a#^ds3=w>TOCz7gx1Tm;4js!4*+#zGpFKI*)w50AraWw^yu@bE z|FWuW76?vEBKPaGf=Jv0u=F&_XPT6CYtU_(&zNEm6~ol|u;gjsTJ?A6jvW)KbdgD4 zZ`YO&QtNtG=N)gjb?(|wbv-VtwAQX`*r7|L3~y#YiV>40CM=*fi;tPNu=bWOM$4?Pv|9)IJ}Z*T!6=O#-{3o;Xiy7%nCp`4Yh1khA44a2_y7O^ literal 0 HcmV?d00001 diff --git a/src/optimization/genetic_algorithm.py b/src/optimization/genetic_algorithm.py new file mode 100644 index 0000000..d08ce88 --- /dev/null +++ b/src/optimization/genetic_algorithm.py @@ -0,0 +1,150 @@ +# -*-coding:Utf-8 -* + +''' +Created on Dec 14, 2012 +''' +import math +import random + +class GeneticAlgorithm(object): + ''' + Class that take a hydraulic network and try to build + the merely best solution. + ''' + def __init__(self, speciesCharac, fitnessFunct, showInfo = lambda a,c: 0, nbrOfGenerations = 100, populationSize = 40, tournamentSize = 2, selectionRate = 0.50, crossoverProb = 0.50, mutationProba = 0.01, elitisme = 0.025): + self.speciesCharac = speciesCharac + self.characteristicLength = len(speciesCharac) + self.population = [self.generate_random_indiv()for i in range(populationSize)] + self.fitnessFunct = fitnessFunct + self.elitisme = elitisme + self.selectionRate = selectionRate + self.popSize = populationSize + self.nbrOfGenerations = nbrOfGenerations + self.mutationProba = mutationProba + self.crossoverProb = crossoverProb + self.tournamentSize = tournamentSize + self.showInfo = showInfo + self.generationNbr = 1 + + self.solution = self.genetic_process() + + def generate_random_indiv(self): + chromosome = [random.randint(self.speciesCharac[i][0], self.speciesCharac[i][1]) for i in range(self.characteristicLength)] + return chromosome + + #The top solution are added to the next generation ("not dead yet ones, because the best for the moment") + def elitism(self, rankedPop): + elitePop = int(self.popSize*self.elitisme) + return rankedPop[0:elitePop] + + #Returning two children per crossover + #Multi-point crossover, the number depending on the length of the chromosome and the rate wanted + #Uniform crossover, each allele have a chance to be switch + #Uniform crossover or multi-point crosover ? + def crossover(self, indiv1, indiv2): + child1 = indiv1[:] + child2 = indiv2[:] + + #Multi-Point Crossover +# nbrPoints = int(self.characteristicLength*self.crossoverProb) +# points = random.sample(range(self.characteristicLength)[1:self.characteristicLength-2], nbrPoints) +# points.append(0) +# points.append(self.characteristicLength) +# points.sort() +# points = [(i1, i2, i3) for (i1, i2, i3) in zip(points[:(len(points)-2):2], points[1:(len(points)-1):2],points[2::2])] +# for i1, i2, i3 in points: +# child1[i1:i3] = indiv1[i1:i2]+indiv2[i2:i3] +# child2[i1:i3] = indiv2[i1:i2]+indiv1[i2:i3] + + #Uniform Crossover + for i in range(self.characteristicLength): + if self.crossoverProb < random.random(): + child1[i] = indiv2[i] + child2[i] = indiv1[i] + + return [child1, child2] + + #Bit-flip Mutation, each allele has the same probability to flip + def mutate(self, indiv): + subject = indiv[:] + for allelePos in range(len(subject)): + if random.random() < self.mutationProba: + subject[allelePos] = ((((indiv[allelePos] - self.speciesCharac[allelePos][0]) + + random.randint(1, self.speciesCharac[allelePos][1])) + % (self.speciesCharac[allelePos][1] + 1)) + + self.speciesCharac[allelePos][0]) + return subject + + #Fitness function must be a 'less is better' evaluation + def assess_fitness (self, indiv): + result = 0 + for fitness in self.fitnessFunct: + result += fitness(indiv) + return result + + def selection (self, rankedPop): + #Tournament Selection + selectionPopSize = int(self.popSize*self.selectionRate) + best = random.randint(0, selectionPopSize) + + for i in range(self.tournamentSize-1): + adv = random.randint(0, selectionPopSize) + if adv < best: + best = adv + return rankedPop[best] + + def genetic_process(self): + for i in range(self.nbrOfGenerations): + scores = [(self.assess_fitness(indiv), indiv) for indiv in self.population] + scores.sort() + ranked = [indiv[1] for indiv in scores] + + if i%1 == 0: + info=[] + for fitness in self.fitnessFunct: + info.append(fitness(ranked[0])) + self.showInfo(ranked[0], info) + + self.population = self.elitism(ranked) + + while len(self.population) < self.popSize: + dad = self.selection(ranked) + mom = self.selection(ranked) + child1, child2 = self.crossover(dad, mom) + self.population.append(self.mutate(child1)) + self.population.append(self.mutate(child2)) + + if len(self.population)%2 != self.popSize%2: + self.population.pop() + self.generationNbr+=1 + + #Si tout les individus sont les même -> stop + if self.population.count(self.population[0]) == self.popSize: + break + + scores = [(self.assess_fitness(indiv), indiv) for indiv in self.population] + scores.sort() + self.population = [indiv[1] for indiv in scores] + return self.population[0] + + +class GeneticAlgorithmVariation(GeneticAlgorithm): + + def __init__(self, speciesCharac, fitnessFunct, showInfo = lambda a,b,c: 0, nbrOfGenerations = 100, populationSize = 40, tournamentSize = 2, selectionRate = 0.50, crossoverProb = 0.50, elitisme = 0.125, mutationVariation = 510000, mutationStart = 0.05, power = 2.2): + self.mutationVariation = mutationVariation + self.mutationStart = mutationStart + self.power = power + GeneticAlgorithm.__init__(self, speciesCharac, fitnessFunct, showInfo, nbrOfGenerations, populationSize, tournamentSize, selectionRate, crossoverProb, 0.1, elitisme) + + #Variation of the mutation rate in the time. + #Each allele has the same probability to be flip but this probability change with the time. + def mutate(self, indiv): + subject = indiv[:] + self.mutationProba = (self.mutationStart-(math.pow(self.generationNbr, self.power)/self.mutationVariation)) + for allelePos in range(len(subject)): + if random.random() < self.mutationProba: + subject[allelePos] = ((((indiv[allelePos] - self.speciesCharac[allelePos][0]) + + random.randint(1, self.speciesCharac[allelePos][1])) + % (self.speciesCharac[allelePos][1] + 1)) + + self.speciesCharac[allelePos][0]) + return subject \ No newline at end of file diff --git a/src/optimization/genetic_algorithm.pyc b/src/optimization/genetic_algorithm.pyc new file mode 100644 index 0000000000000000000000000000000000000000..296270125757ab3d7d228cec9b5531c0bdc4ecc3 GIT binary patch literal 6031 zcmcgwTXP&o6+S(yUG1)HNp@^mvauNl2R0*NK zRx`b}Y@{cPDyV`VK>k4<$U9G@iWeSu(B`{!0 z2@E@<1O}f~qAu~Y5)FxGlxRw@-Xd@1I;v)4B@4^aw>zQrZMc{Cp}+GaF2a76Mn0H- zoELk3*o}Q#Jn?PrZ}!tHZZ_;r;&+lF$)5O|NooBu&-ymayEmJS$iuoU24w}MoIr(h zt+&{_mZFlDR%}}i3$>11FJF}#s1|qfPO=#1Sr!)M;s!V=dtsC;elyC_UYWGVJ^gI+ zo$^t(SQgP@-m_^ZeHxOT#cij6b~x0)&E6AR$J$F-*x8K3_oulTilmUgq~staTiYo3 z{cU;s7Z*PL@b6ELm$yIuo&J`iDZDs?QbExJ{vO1kkwcNT9tiX^*YvoMt;k`OJ*yAT z%h43a?M~3te&)&k8#=8jhn^BOIczF1DTjElVx5yoG~{qX2@C*@9xR2oAkN4kCW1IC zhu93nG$l@AhV||&w`21h?QEzCioSIol|759>?Ki}lq)-75k}xyBul#X0{%y?D=E?v z*8KgXyKQ%D6)%dgyPepJpeX19?$Ab8oOjx3H%=efCf@Y&UO!W9SPE?`wcVsFzt!(X zRyC1isZGmH;&@21B%YKQE$<&=zVaD=6i+QPHT?o_5vJS0CP#BO}(6U9~<~H(X!=7Pvs;8?-!G zc;>0i&&m<3ooLFH9U`P^j5Ml%Y7e-dW#tS?ZGmLkwJLF)8q9I%Jcm*N(N2+f@)D>) zKYsP%3}{GSL{W$nvuYIlcqkSX*L4shSy39ETmTeM02+xPhU-Ir#8A<5srT`u^h>pp z@o_C<2PCnV#P@-9WPvV}pm92}+B z(M+3*o>~`=$kV8RKL()!_T=CDGs!oFB?Y5%g|*+A=M_f{>ad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K&l`7KIGfMNpw=5r~$%e3FatAN?!q1vEUon4?1^1Rr9`Dcgg4y86qsI jNHqrLdLMEQ#aXAwrADbG7nk0rqV)z)L*9ADn|u0ipeOUL literal 0 HcmV?d00001 diff --git a/src/optimization/simulated_annealing.py b/src/optimization/simulated_annealing.py new file mode 100644 index 0000000..2179878 --- /dev/null +++ b/src/optimization/simulated_annealing.py @@ -0,0 +1,83 @@ +# -*-coding:Utf-8 -* + +import random +import math + +class SimulatedAnnealing(object): + + def __init__(self, system, fitnessFunct, showInfo = lambda a,b: 0, temperature = 5, coolSpeed = 0.000002, modificationRate = 0.1, limitTemp = 0, power = 1.8): + super(SimulatedAnnealing, self).__init__() + + self.showInfo = showInfo + + self.coolSpeed = float(coolSpeed) + self.power = float(power) + self.temperature = float(temperature) + self.limitTemp = limitTemp + self.modificationRate = modificationRate + self.criterions = fitnessFunct + self.metal = system + + self.solution = self.simulated_annealing_algorithm() + + def randomize_solution (self, lenSolution): + nbrAtoms = lenSolution + solution = [0]*lenSolution + for i in range(nbrAtoms): + solution[i] = random.randint(self.metal[i][0], self.metal[i][1]) + return solution + + def change_solution(self, solution): + nbrAtoms = int(len(solution)*self.modificationRate) + proposition = solution[:] + + randPos = random.sample(range(len(solution)), nbrAtoms) + + for pos in randPos: + proposition[pos] = ((((solution[pos] - self.metal[pos][0]) + + random.randint(1, self.metal[pos][1])) + % (self.metal[pos][1] + 1)) + + self.metal[pos][0]) + + return proposition + + #Fitness function must be a 'less is better' evaluation + def assess_scores (self, solution): + result = 0 + for fitness in self.criterions: + result += fitness(solution) + return result + + def simulated_annealing_algorithm(self): + firstTemp = self.temperature + currentSolution = self.randomize_solution(len(self.metal)) + currentScore = self.assess_scores(currentSolution) + bestSolution = currentSolution[:] + bestScore = currentScore + x = 0.00 + + while firstTemp > self.limitTemp: + newSolution = self.change_solution(currentSolution) + newScore = self.assess_scores(newSolution) + prob = math.exp((-(newScore-currentScore))/self.temperature) + + info = [] + for fitness in self.criterions: + info.append(fitness(bestSolution)) + self.showInfo(bestSolution, info) + + if newScore < currentScore or random.random() < prob: + currentSolution = newSolution + currentScore = newScore + + if currentScore < bestScore: + bestSolution = currentSolution[:] + bestScore = currentScore + else: + currentSolution = bestSolution[:] + currentScore = bestScore + + firstTemp = (self.temperature-(math.pow(x, self.power)*self.coolSpeed)) + x+=1 + + return bestSolution \ No newline at end of file diff --git a/src/optimization/simulated_annealing.pyc b/src/optimization/simulated_annealing.pyc new file mode 100644 index 0000000000000000000000000000000000000000..afb9a47ea9dbcc6743e37ab336299bd199f311d5 GIT binary patch literal 3274 zcmcguOK%)S5U!qmc^x}8iQ`8C7FL3^mt;{mZi}SzM z(+547J{A1Gh2gGZ>f>i55!s&6Mz)Rg1F?bZf~d$#kryJ5wks6vw5oV5{u|GIe+FbH zPRB{)ZU1(b*(iy#!R(|4w%^BaA7QdM1L}n8pa%y)b-yb8n)K`PvM$@;G`P!y=9Iv0 zQwhk-D^ZuQ(>eupy#N!3!T12f(JnQR-1{*mY3anZr&y%(PRZq#dxWXIm#4Pf&yyr7 zT>D{OJaMC_XWMssNj!44d(0UpJD1((N!t~@c0TfP8b6PGoM&x! z2Y@4xVL(vKK}E3cR>W83pe8SjE^E4+J6hItSv^`da5%rypj!xeD$kdE`Cs)64Uu zGqSd?{89eY7M^f=n?hIQ$Awk71kUxJfa#a9o96v^H}0vkL&Tb&r>Y|Mwt)Mc>PoGT z68{!9UV}zAN(MRP_tMh1JQ)+X7EOZZ@QzJ(eVxQJ2V49C$lcgy*13D*tmi}Sg*-MS zk|Fm)8Xi)`NkvphuWKZ&fDm&wXa-A$f6ekQ(6pcwhXxK3o1h*dyNnEgu920)icD@X zoB%sQ=Fa1*a#&@KAgYKvf~qPTkl%P^703qSjsaJd>-%rZLy(vxmoL4X?6VE zcHPvhH5lR;0%GcB(VR8!8g(~AgG1f@9f)b3nrXtpsVnd@5P55DRXDK6 zyaf~iVVLaE!*?EkCWkdm$65&kQWX?IS*L;qODN%)@=JKu{>_2N+UhG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