├── .gitignore ├── Genetic Algorithms Test ├── AuthoringTests.txt ├── Genetic Algorithms Test.csproj ├── GeneticAlgorithmsTest.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Genetic Algorithms.sln ├── Genetic Algorithms ├── COPYING.txt ├── Chromosome.cs ├── ExampleClasses │ ├── AlphaSelector.cs │ ├── AsymetricCrossoverRecombinator.cs │ ├── AsymmetricZipRecombinator.cs │ ├── BoolGene.cs │ ├── BoolGrowthLimitedFitness.cs │ ├── BoolSumFitness.cs │ ├── CrossoverRecombinator.cs │ ├── IntGene.cs │ ├── Mondlandungs │ │ ├── MondlandungsSimulation.cs │ │ ├── Raumfahrer.cs │ │ └── Raumschiff.cs │ ├── PieCakeSelector.cs │ ├── RandomSelector.cs │ └── UniformMultiPointCrossoverRecombinator.cs ├── Genetic Algorithms.csproj ├── GeneticSimulation.cs ├── IChromosome.cs ├── IFitnessFunctionProvider.cs ├── IGene.cs ├── IRecombinationProvider.cs ├── ISelectionProvider.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── GeneticAlgorithmsGUI ├── Explosion.gif ├── Fahne.png ├── GUI.Designer.cs ├── GUI.cs ├── GUI.resx ├── GeneticAlgorithmsGUI.csproj ├── Mond.ico ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Raumfahrer.gif ├── Raumschiff.gif ├── Raumschiff_leer.gif ├── Triebwerk.gif ├── Weltraum.bmp └── bin │ └── Debug │ ├── ZedGraph.dll │ └── de │ └── ZedGraph.resources.dll ├── GeneticAlgorithmsGUI_EN ├── Engine.gif ├── Explosion.gif ├── Flag.png ├── GUI.Designer.cs ├── GUI.cs ├── GUI.resx ├── GeneticAlgorithmsGUI_EN.csproj ├── Moon.ico ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Space.bmp ├── Spaceman.gif ├── Spaceship.gif └── SpaceshipEmpty.gif └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | */bin 2 | */obj 3 | *.user 4 | *.suo 5 | _ReSharper.* 6 | *.sln.cache -------------------------------------------------------------------------------- /Genetic Algorithms Test/AuthoringTests.txt: -------------------------------------------------------------------------------- 1 | ========================================================================== 2 | Visual Studio Team System: Übersicht über das Erstellen und Durchführen von Tests 3 | ========================================================================== 4 | 5 | In dieser Übersicht werden die Features zum Erstellen und Durchführen von Tests in 6 | Visual Studio Team System und Visual Studio Team Edition for Software Testers beschrieben. 7 | 8 | Öffnen von Tests 9 | ------------- 10 | Wenn Sie einen Test öffnen möchten, öffnen Sie ein Testprojekt oder eine 11 | Testmetadatendatei (eine Datei mit der Erweiterung .vsmdi), die die Definition des Tests enthält. Sie finden Testprojekte und 12 | Metadatendateien im Projektmappen-Explorer. 13 | 14 | Anzeigen von Tests 15 | ------------- 16 | Um anzuzeigen, welche Tests verfügbar sind, öffnen Sie das Fenster "Testansicht". Oderwenn Sie Team Edition for Software Testers installiert haben, können Sie auch 17 | das Testlisten-Editorfenster zum Anzeigen der Tests öffnen. 18 | 19 | Klicken Sie zum Öffnen des Fensters "Testansicht" auf das Menü "Test", zeigen Sie auf "Windows", und 20 | klicken Sie dann auf "Testansicht". Klicken Sie zum Öffnen des Fensters "Testlisten-Editor" (sofern Sie 21 | Team Edition for Software Testers installiert haben) auf "Test", zeigen Sie auf "Windows", 22 | und klicken Sie dann auf "Testlisten-Editor". 23 | 24 | Durchführen von Tests 25 | ------------- 26 | Sie können Tests im Fenster "Testansicht" und im Fenster "Testlisten-Editor" durchführen. 27 | Anweisungen zum Öffnen dieser Fenster finden Sie unter "Anzeigen von Tests". Wenn ein oder mehrere im Fenster 28 | "Testansicht" angezeigte Tests durchgeführt werden sollen, markieren Sie diese Tests zunächst in 29 | diesem Fenster. Wenn Sie mehrere Tests markieren möchten, klicken Sie bei gedrückter UMSCHALT- oder STRG-TASTE 30 | auf die Tests. Klicken Sie anschließend auf der Symbolleiste im Fenster "Testansicht" auf die 31 | Schaltfläche "Tests durchführen". 32 | 33 | Wenn Sie Visual Studio Team Edition for Software Testers installiert haben, können Sie auch 34 | das Fenster "Testlisten-Editor" zum Durchführen von Tests verwenden. Wenn Sie Tests im Testlisten-Editor ausführen möchten, 35 | aktivieren Sie das Kontrollkästchen neben dem jeweils durchzuführenden Test. Klicken Sie anschließend 36 | auf der Symbolleiste im Fenster "Testlisten-Editor" auf die Schaltfläche "Tests durchführen". 37 | 38 | Anzeigen von Testergebnissen 39 | -------------------- 40 | Wenn Sie einen oder mehrere Tests durchführen, werden die Ergebnisse der durchgeführten Tests 41 | im Fenster "Testergebnisse" angezeigt. Jeder einzelne Test wird in einer separaten 42 | Zeile angezeigt, sodass sein Status erkennbar ist. In der oberen Hälfte des Fensters 43 | befindet sich eine eingebettete Statusleiste. Die Leiste enthält 44 | eine Zusammenfassung von Details zum gesamten Testlauf. 45 | 46 | Zum Anzeigen von ausführlicheren Informationen zu einem bestimmten Testergebnis doppelklicken Sie im 47 | Fenster "Testergebnisse" auf das Ergebnis. Hierdurch wird ein Fenster geöffnet, in dem weitere Informationen 48 | zu dem bestimmten Testergebnis angezeigt werden, z. B. alle im Test zurückgegebenen 49 | Fehlermeldungen. 50 | 51 | Ändern der Art der Testdurchführung 52 | ----------------------------------- 53 | Beim Durchführen eines oder mehrerer Tests wird eine Reihe von Einstellungen verwendet, 54 | die bestimmen, auf welche Weise diese Tests durchgeführt werden. Diese Einstellungen sind in einer Konfigurationsdatei für Testläufe 55 | enthalten. 56 | 57 | Im Folgenden ist eine Liste mit einigen der Änderungen aufgeführt, die an einer Testlauf-Konfigurationsdatei vorgenommen 58 | werden können: 59 | 60 | – Ändern des Benennungsschemas für jeden Testlauf. 61 | – Ändern des Testcontrollers, auf dem die Tests durchgeführt werden, sodass Tests 62 | remote durchgeführt werden können. 63 | – Erfassen von Codeabdeckungsdaten für den zu testenden Code, sodass ersichtlich wird, 64 | welche Codezeilen durch die Tests abgedeckt werden. 65 | - Aktivieren und Deaktivieren der Testbereitstellung. 66 | – Angeben zusätzlicher, vor dem Ausführen der Tests bereitzustellender Dateien. 67 | – Auswählen eines anderen Hosts (ASP.NET) zum Durchführen von ASP.NET-Komponententests. 68 | – Auswählen eines anderen Hosts, des Testhosts für intelligente Geräte, zum Durchführen von Komponententests für intelligente Geräte. 69 | – Festlegen verschiedener Eigenschaften für die Test-Agents, die die Tests durchführen. 70 | – Ausführen benutzerdefinierter Skripts zum Anfang und Ende jedes Testlaufs, sodass die 71 | Testumgebung für jeden Testlauf genau nach Wunsch eingerichtet werden kann. 72 | – Festlegen von Zeitlimits für Tests und Testläufe. 73 | – Festlegen der verwendbaren Browser und der Anzahl der Wiederholungen von Webtests im 74 | Testlauf. 75 | 76 | Standardmäßig wird eine Konfigurationsdatei für Testläufe immer dann erstellt, wenn Sie ein 77 | neues Testprojekt erstellen. Änderungen an dieser Datei können Sie vornehmen, indem Sie im 78 | Projektmappen-Explorer auf die Datei doppelklicken und dann die Einstellungen ändern. (Konfigurationsdateien für Testläufe 79 | besitzen die Erweiterung ".testrunconfig".) 80 | 81 | Eine Projektmappe kann mehrere Konfigurationsdateien für Testläufe enthalten. Nur in einer dieser 82 | Dateien (der "aktiven" Konfigurationsdatei für Testläufe) werden 83 | die Einstellungen bestimmt, die gegenwärtig für Testläufe verwendet werden. Sie wählen 84 | die aktive Konfigurationsdatei für Testläufe aus, indem Sie im Menü "Test" auf 85 | "Aktive Testlaufkonfiguration auswählen" klicken. 86 | 87 | ------------------------------------------------------------------------------- 88 | 89 | Testtypen 90 | ---------- 91 | Bei Verwendung von Visual Studio Team Edition for Software Testers können Sie verschiedene 92 | Testtypen erstellen: 93 | 94 | Komponententest: Erstellen Sie mithilfe eines Komponententests einen programmgesteuerten Test in C++, Visual C# oder 95 | Visual Basic, der Quellcode ausführt. Ein Komponententest ruft die Methoden einer 96 | Klasse auf, übergibt passende Parameter und überprüft, ob der zurückgegebene Wert 97 | Ihren Erwartungen entspricht. 98 | Es stehen drei spezielle Varianten von Komponententests zur Verfügung: 99 | – Datengesteuerte Komponententests werden erstellt, wenn Sie einen Komponententest so konfigurieren, dass er 100 | für jede Zeile einer Datenquelle erneut aufgerufen wird. Die Daten jeder Zeile 101 | werden für den Komponententest als Eingabedaten verwendet. 102 | – ASP.NET-Komponententests sind Komponententests, bei denen Code in einer ASP.NET-Webanwendung 103 | ausgeführt wird. 104 | - Komponententests für intelligente Geräte sind Komponententests, die für ein intelligentes Gerät 105 | oder einen Emulator bereitgestellt werden und dann vom Testhost für intelligente Geräte ausgeführt werden. 106 | 107 | Webtest: Webtests bestehen aus einer geordneten Folge von HTTP-Anforderungen, die 108 | in einer Browsersitzung von Microsoft Internet Explorer aufgezeichnet werden. Sie können festlegen, dass 109 | der Test über bestimmte Details zu den angeforderten Seiten oder Websites informiert, beispielsweise 110 | ob eine bestimmte Seite eine angegebene Zeichenfolge enthält. 111 | 112 | Auslastungstest: Ein Auslastungstest wird zum Kapseln von nicht manuellen Tests wie 113 | Komponententests, Webtests und generischen Tests sowie zum anschließenden Durchführen der Tests durch 114 | virtuelle Benutzer verwendet. Beim Durchführen dieser Tests unter Last werden Testergebnisse, 115 | einschließlich Leistungsindikatoren und weiterer Indikatoren, in Tabellen und Diagrammen generiert. 116 | 117 | Generischer Test: Ein generischer Test ist ein vorhandenes Programm, das umschlossen ist, damit es 118 | in Visual Studio als Test funktioniert. Im Folgenden sind Beispiele für Tests oder Programme aufgeführt, die 119 | in generische Tests umgewandelt werden können: 120 | – Ein vorhandener Test, der mithilfe von Prozessbeendigungscodes darüber informiert, ob der 121 | Test erfolgreich war. 0 (null) bedeutet, dass der Test erfolgreich war. Jeder andere Wert bedeutet, 122 | dass ein Fehler aufgetreten ist. 123 | – Ein allgemeines Programm, durch das während eines Testszenarios bestimmte Funktionen verfügbar sind. 124 | – Ein Test oder Programm, bei dem eine spezielle XML-Datei (eine "Ergebniszusammenfassungsdatei") verwendet wird, 125 | um detaillierte Ergebnisse zu übermitteln. 126 | 127 | Manueller Test: Dieser Testtyp wird verwendet, wenn die Testaufgaben 128 | von einem Testingenieur durchgeführt werden sollen und nicht von einem automatischen Skript. 129 | 130 | Testreihe: Verwenden Sie eine Testreihe zum Durchführen mehrerer Tests in einer 131 | von Ihnen angegebenen Reihenfolge. 132 | 133 | ------------------------------------------------------------------------------- 134 | 135 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/Genetic Algorithms Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Debug 4 | AnyCPU 5 | 9.0.21022 6 | 2.0 7 | {1E5B7DF8-7895-4284-86FE-ACAD38FC5C98} 8 | Library 9 | Properties 10 | GeneticAlgorithmsTest 11 | GeneticAlgorithmsTest 12 | v3.5 13 | 512 14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 3.5 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | {6E92618B-EE42-4427-8924-F5FA675B1735} 50 | Genetic Algorithms 51 | 52 | 53 | 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/GeneticAlgorithmsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using GeneticAlgorithms; 7 | using GeneticAlgorithms.ExampleClasses; 8 | using GeneticAlgorithms.ExampleClasses.MondLandungs; 9 | 10 | using System.Collections; 11 | 12 | namespace GeneticAlgorithmsTest 13 | { 14 | 15 | /// 16 | /// Zusammenfassungsbeschreibung für UnitTest1 17 | /// 18 | [TestClass] 19 | public class GeneticAlgorithmsTest 20 | { 21 | public GeneticAlgorithmsTest() 22 | { 23 | // 24 | // TODO: Konstruktorlogik hier hinzufügen 25 | // 26 | } 27 | 28 | private TestContext testContextInstance; 29 | 30 | /// 31 | ///Ruft den Textkontext mit Informationen über 32 | ///den aktuellen Testlauf sowie Funktionalität für diesen auf oder legt diese fest. 33 | /// 34 | public TestContext TestContext 35 | { 36 | get 37 | { 38 | return testContextInstance; 39 | } 40 | set 41 | { 42 | testContextInstance = value; 43 | } 44 | } 45 | 46 | #region Zusätzliche Testattribute 47 | // 48 | // Sie können beim Schreiben der Tests folgende zusätzliche Attribute verwenden: 49 | // 50 | // Verwenden Sie ClassInitialize, um vor Ausführung des ersten Tests in der Klasse Code auszuführen. 51 | // [ClassInitialize()] 52 | // public static void MyClassInitialize(TestContext testContext) { } 53 | // 54 | // Verwenden Sie ClassCleanup, um nach Ausführung aller Tests in einer Klasse Code auszuführen. 55 | // [ClassCleanup()] 56 | // public static void MyClassCleanup() { } 57 | // 58 | // Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen. 59 | // [TestInitialize()] 60 | // public void MyTestInitialize() { } 61 | // 62 | // Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen. 63 | // [TestCleanup()] 64 | // public void MyTestCleanup() { } 65 | // 66 | #endregion 67 | 68 | [TestMethod] 69 | public void TestBoolGene() 70 | { 71 | 72 | BoolGene gene = new BoolGene(); 73 | gene = true; 74 | Assert.AreEqual(true, (Boolean) gene); 75 | Assert.AreNotEqual(false, (Boolean)gene); 76 | 77 | gene = false; 78 | Assert.AreEqual(false, (Boolean)gene); 79 | Assert.AreNotEqual(true, (Boolean)gene); 80 | if (false != gene) 81 | Assert.Fail("Implicit typecast not functioning"); 82 | 83 | BoolGene anotherGene = gene; 84 | Assert.AreEqual(false, (Boolean)anotherGene); 85 | Assert.AreNotEqual(true, (Boolean)anotherGene); 86 | 87 | gene = true; 88 | Assert.AreEqual(false, (Boolean)anotherGene); 89 | Assert.AreNotEqual(true, (Boolean)anotherGene); 90 | 91 | 92 | gene.Mutate(); 93 | } 94 | 95 | [TestMethod] 96 | public void TestAsymmetricZipRecombinator() 97 | { 98 | Chromosome father = new Chromosome(2); 99 | Chromosome mother = new Chromosome(2); 100 | IRecombinationProvider recombinator = new AsymmetricZipRecombinator(); 101 | 102 | father[0] = true; 103 | father[1] = false; 104 | mother[0] = false; 105 | mother[1] = true; 106 | 107 | Chromosome child = father.Recombine(mother, recombinator); 108 | Assert.IsTrue(child.GeneCount == 2); 109 | Assert.IsTrue(child[0] == false && child[1] == false, "Fix recombination not correct!"); 110 | 111 | father[0].Mutate(); 112 | mother[1].Mutate(); 113 | 114 | child = father.Recombine(mother, recombinator); 115 | Assert.IsTrue(child[0].Equals(mother[0]) && child[1].Equals(father[1]), "Variable recombination not correct!"); 116 | 117 | father = new Chromosome(3); 118 | mother = new Chromosome(5); 119 | 120 | father[0] = true; 121 | father[1] = false; 122 | father[2] = true; 123 | mother[0] = false; 124 | mother[1] = true; 125 | mother[2] = false; 126 | mother[3] = true; 127 | mother[4] = false; 128 | 129 | child = father.Recombine(mother, recombinator); 130 | Assert.IsTrue(child.GeneCount == 5, "Gene Count wrong in asymmeric test"); 131 | Assert.IsTrue(child[0] == true && child[1] == true && child[2] == true && child[3] == true && child[4] == false, "Fix recombination in asymetric Mother/Father not correct!"); 132 | } 133 | 134 | [TestMethod] 135 | public void TestBoolChromosome() 136 | { 137 | Chromosome chromosome = new Chromosome(2); 138 | 139 | Assert.AreEqual(2, chromosome.GeneCount); 140 | chromosome[0] = true; 141 | Assert.AreEqual(true, (Boolean)chromosome[0]); 142 | if (true != chromosome[0]) 143 | Assert.Fail("Implicit typecast not functioning"); 144 | 145 | chromosome[0].Mutate(); 146 | } 147 | 148 | [TestMethod] 149 | public void TestCrossoverRecombinator() 150 | { 151 | Chromosome father = new Chromosome(2); 152 | Chromosome mother = new Chromosome(2); 153 | IRecombinationProvider recombinator = new CrossoverRecombinator(); 154 | 155 | father[0] = true; 156 | father[1] = false; 157 | mother[0] = false; 158 | mother[1] = true; 159 | 160 | Chromosome child = father.Recombine(mother, recombinator); 161 | Assert.IsTrue(child[0] == true && child[1] == true, "Fix recombination not correct!"); 162 | 163 | // Following only functional with inverting Mutation! 164 | father[0].Mutate(); 165 | Assert.IsFalse(father[0]); 166 | father[0].Mutate(); 167 | Assert.IsTrue(father[0]); 168 | mother[1].Mutate(); 169 | 170 | child = father.Recombine(mother, recombinator); 171 | Assert.IsTrue(child[0].Equals(father[0]) && child[1].Equals(mother[1]), "Variable recombination not correct!"); 172 | } 173 | private bool delegateRun = false; 174 | private int delegateRunCount = 0; 175 | private GeneticSimulation simulation; 176 | private void TestDelegate(object sender, EventArgs e) 177 | { 178 | delegateRun = true; 179 | delegateRunCount++; 180 | } 181 | 182 | [TestMethod] 183 | public void TestGeneticSimulation() 184 | { 185 | simulation = new GeneticSimulation(100, 5, new BoolGrowthLimitedFitness(), new AsymmetricCrossoverRecombinator(), new AlphaSelector() ,new PieCakeSelector()); 186 | //simulation.GeneDuplicationRate = 0.00001; 187 | simulation.SimulationTurn += new OnSimulationTurn(TestDelegate); 188 | simulation.RunSimulation(); 189 | 190 | Assert.IsTrue(delegateRun); 191 | 192 | delegateRunCount = 0; 193 | simulation.RunSimulation(1000); 194 | 195 | Assert.AreEqual(1000, delegateRunCount, "Did not run 1000 times!"); 196 | 197 | /* Assert.AreEqual(5.0, simulation.AverageFitness, 0.5, "This may occur, rerun Test and see if it keeps happening!"); 198 | Assert.AreEqual(5.0, simulation.MostSuccessfullIndividual.Fitness, "This may occur, rerun Test and see if it keeps happening!");*/ 199 | 200 | simulation.ResetSimulation(); 201 | delegateRunCount = 0; 202 | delegateRun = false; 203 | simulation.GeneDuplicationRate = 0.01; 204 | 205 | simulation.RunSimulation(); 206 | 207 | Assert.IsTrue(delegateRun); 208 | 209 | delegateRunCount = 0; 210 | simulation.RunSimulation(10); 211 | 212 | /* Assert.AreEqual(10, delegateRunCount, "Did not run 10 times!"); 213 | Assert.IsTrue(simulation.AverageChromosomeLength > 5, "Average Chromosome Lengtrh not > 5"); */ 214 | } 215 | 216 | [TestMethod] 217 | public void TestAsymetricCrossoverRecombinator() 218 | { 219 | Chromosome father = new Chromosome(2); 220 | Chromosome mother = new Chromosome(2); 221 | IRecombinationProvider recombinator = new AsymmetricCrossoverRecombinator(); 222 | 223 | father[0] = true; 224 | father[1] = false; 225 | mother[0] = false; 226 | mother[1] = true; 227 | 228 | Chromosome child = father.Recombine(mother, recombinator); 229 | Assert.IsTrue(child.GeneCount == 2); 230 | Assert.IsTrue(child[0] == true && child[1] == true, "Fix recombination not correct!"); 231 | 232 | father[0].Mutate(); 233 | mother[1].Mutate(); 234 | 235 | child = father.Recombine(mother, recombinator); 236 | Assert.IsTrue(child[0].Equals(father[0]) && child[1].Equals(mother[1]), "Variable recombination not correct!"); 237 | 238 | father = new Chromosome(3); 239 | mother = new Chromosome(5); 240 | 241 | father[0] = true;//child 0 242 | father[1] = false;//child 1 243 | father[2] = true; 244 | mother[0] = false; 245 | mother[1] = true; 246 | mother[2] = false; 247 | mother[3] = true; //child 2 248 | mother[4] = false; // child 3 249 | 250 | child = father.Recombine(mother, recombinator); 251 | Assert.IsTrue(child.GeneCount == 4); 252 | Assert.IsTrue(child[0] == true && child[1] == false && child[2] == true && child[3] == false, "Fix recombination in asymetric Mother/Father not correct!"); 253 | } 254 | 255 | [TestMethod] 256 | public void TestBoolSumFitness() 257 | { 258 | Chromosome chromosome = new Chromosome(5); 259 | IFitnessFunctionProvider fitnessFunction = new BoolSumFitness(); 260 | 261 | chromosome[0] = true; 262 | chromosome[1] = true; 263 | chromosome[2] = true; 264 | chromosome[3] = true; 265 | chromosome[4] = true; 266 | 267 | chromosome.computeFitness(fitnessFunction); 268 | 269 | Assert.AreEqual(5.0f, chromosome.Fitness); 270 | 271 | chromosome[2] = false; 272 | chromosome[3] = false; 273 | 274 | chromosome.computeFitness(fitnessFunction); 275 | 276 | Assert.AreEqual(3.0f, chromosome.Fitness); 277 | } 278 | 279 | [TestMethod] 280 | [ExpectedException(typeof(GenesIncompatibleException))] 281 | public void TestCrossoverRecombinatorException() 282 | { 283 | Chromosome chrom1 = new Chromosome(1); 284 | Chromosome chrom2 = new Chromosome(2); 285 | IRecombinationProvider recom = new CrossoverRecombinator(); 286 | Chromosome newChrom = chrom1.Recombine(chrom2, recom); 287 | } 288 | 289 | [TestMethod] 290 | public void TestRaumschiff() 291 | { 292 | ArrayList kommandos = new ArrayList(0); 293 | Raumfahrer pilot = new Raumfahrer(kommandos); 294 | Raumschiff schiff = new Raumschiff(pilot, 100, 100, 100, true); 295 | 296 | Assert.AreEqual(100, schiff.Treibstoff); 297 | Assert.AreEqual(100, schiff.Hoehe); 298 | Assert.AreEqual(100, schiff.Gewicht); 299 | } 300 | 301 | [TestMethod] 302 | public void TestRaumfahrer() 303 | { 304 | ArrayList kommandos = new ArrayList(10); 305 | for (int i = 0; i < 10; i++) 306 | kommandos.Add(new IntGene(1)); 307 | 308 | Raumfahrer pilot = new Raumfahrer(kommandos); 309 | Assert.AreEqual(10, pilot.Gewicht); 310 | Raumschiff schiff = new Raumschiff(pilot, 100, 100, 1, true); 311 | pilot.SteuereRaumschiff(schiff); 312 | Assert.AreEqual(100 - 1, schiff.Treibstoff); 313 | Assert.AreEqual(1, schiff.Geschwindigkeit); 314 | pilot.SteuereRaumschiff(schiff); 315 | Assert.AreEqual(100 - 2, schiff.Treibstoff); 316 | Assert.AreEqual(2, schiff.Geschwindigkeit); 317 | 318 | } 319 | 320 | [TestMethod] 321 | public void TestMondlandungsSimulation() 322 | { 323 | ArrayList kommandos = new ArrayList(10); 324 | for (int i = 0; i < 10; i++) 325 | kommandos.Add(new IntGene(1)); 326 | 327 | MondlandungsSimulation sim = new MondlandungsSimulation(100, 100, 1, true); 328 | Assert.AreEqual(10, sim.TestComputeFitness(kommandos)); 329 | 330 | } 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("Genetic Algorithms Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Genetic Algorithms Test")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("9d520f8f-7163-4020-8eed-7a0573081ca4")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Revisions- und Buildnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:2.0.50727.4927 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithmsTest.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GeneticAlgorithmsTest.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | text/microsoft-resx 91 | 92 | 93 | 1.3 94 | 95 | 96 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 97 | 98 | 99 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 100 | 101 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:2.0.50727.4927 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithmsTest.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Genetic Algorithms Test/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Genetic Algorithms.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Genetic Algorithms", "Genetic Algorithms\Genetic Algorithms.csproj", "{6E92618B-EE42-4427-8924-F5FA675B1735}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Genetic Algorithms Test", "Genetic Algorithms Test\Genetic Algorithms Test.csproj", "{1E5B7DF8-7895-4284-86FE-ACAD38FC5C98}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneticAlgorithmsGUI", "GeneticAlgorithmsGUI\GeneticAlgorithmsGUI.csproj", "{203AA8CA-AD21-484B-B8DB-7612889C328C}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneticAlgorithmsGUI_EN", "GeneticAlgorithmsGUI_EN\GeneticAlgorithmsGUI_EN.csproj", "{D718E6ED-A75F-4CA6-BA40-7323EBAE5460}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {6E92618B-EE42-4427-8924-F5FA675B1735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {6E92618B-EE42-4427-8924-F5FA675B1735}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {6E92618B-EE42-4427-8924-F5FA675B1735}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {6E92618B-EE42-4427-8924-F5FA675B1735}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {1E5B7DF8-7895-4284-86FE-ACAD38FC5C98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {1E5B7DF8-7895-4284-86FE-ACAD38FC5C98}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {1E5B7DF8-7895-4284-86FE-ACAD38FC5C98}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {1E5B7DF8-7895-4284-86FE-ACAD38FC5C98}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {203AA8CA-AD21-484B-B8DB-7612889C328C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {203AA8CA-AD21-484B-B8DB-7612889C328C}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {203AA8CA-AD21-484B-B8DB-7612889C328C}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {203AA8CA-AD21-484B-B8DB-7612889C328C}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {D718E6ED-A75F-4CA6-BA40-7323EBAE5460}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {D718E6ED-A75F-4CA6-BA40-7323EBAE5460}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {D718E6ED-A75F-4CA6-BA40-7323EBAE5460}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {D718E6ED-A75F-4CA6-BA40-7323EBAE5460}.Release|Any CPU.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /Genetic Algorithms/Chromosome.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections; 26 | 27 | namespace GeneticAlgorithms 28 | { 29 | /* generic class Chromosome 30 | * implementiert: IChromosome, IComparable> 31 | * Gene implementiert: IGene, einen Konstruktor 32 | * 33 | * Chromosome ist eine allgemeine (generische) Chromosomklasse. Sieht implementiert das 34 | * Chromosome-Interface und das Sortier-Interface IComparable. 35 | * Die Klasse beherbergt einen Strang von Genen und erlaubt es mit diesen durch Methoden zu 36 | * interagieren. 37 | */ 38 | public class Chromosome: IChromosome, IComparable> where Gene: IGene, new() 39 | { 40 | // Liste von Genen; es wird davon ausgegangen, dass hier nur Objekte vom Typ Gene abgelegt werden. 41 | protected ArrayList genes; 42 | // Die Fitness des Chromosoms wird hier gespeichert 43 | private float fitness; 44 | 45 | // Zugriffs Property auf die Fitness des Chromosoms 46 | public float Fitness 47 | { 48 | get 49 | { 50 | return this.fitness; 51 | } 52 | } 53 | 54 | // Dupliziert ein Gen an der durch index bestimmten Position 55 | public void DuplicateGene(int index) 56 | { 57 | Gene gene = new Gene(); 58 | gene = (Gene) this[index].Clone(); 59 | this.genes.Insert(index, gene); 60 | } 61 | 62 | // Entfernt ein Gen an der durch index bestimmten Position 63 | public void DropGene(int index) 64 | { 65 | this.genes.RemoveAt(index); 66 | } 67 | 68 | // Errechnet mithilfe eines IFitnessFunctionProvider Interface die Fitness des Chromosoms 69 | public void computeFitness(IFitnessFunctionProvider provider) 70 | { 71 | this.fitness = provider.ComputeFitness(this.genes); 72 | } 73 | 74 | // Geschützter Konstruktor, der ein Chromosom aus einer ArrayList von Gegen erzeugt (für Rekombination erforderlich) 75 | protected Chromosome(ArrayList genes) 76 | { 77 | if (genes.Count > 0) 78 | if (genes[genes.Count - 1].GetType() == typeof(Gene)) 79 | this.genes = new ArrayList(genes); 80 | else 81 | throw new ArrayTypeMismatchException(); 82 | else 83 | this.genes = new ArrayList(); 84 | } 85 | 86 | // Konstruktor, der ein Chromosom mit geneCount zufällig initialisierten Genen erzeugt 87 | public Chromosome(int geneCount) 88 | { 89 | this.genes = new ArrayList(geneCount); 90 | while (this.genes.Count < geneCount) 91 | this.genes.Add(new Gene()); 92 | } 93 | 94 | // Rekombiniert dieses Chromosom mit einem durch partner spezifizierten anderen Chromosom 95 | // Das IRecombinatorProvider Interface recombinator stellt dafür die Methode zur Verfügung. 96 | public Chromosome Recombine(Chromosome partner, IRecombinationProvider recombinator) 97 | { 98 | return new Chromosome(recombinator.Recombine(this.genes, partner.genes)); 99 | } 100 | 101 | // Array-Zugriffs-Property für die Gen-Liste 102 | public Gene this[int index] 103 | { 104 | get 105 | { 106 | return (Gene) genes[index]; 107 | } 108 | set 109 | { 110 | genes[index] = value; 111 | } 112 | } 113 | 114 | // Zugriffs-Property für die Chromosom-Länge 115 | public int GeneCount 116 | { 117 | get 118 | { 119 | return this.genes.Count; 120 | } 121 | } 122 | 123 | // Wandelt das Chromosom in eine menschen-lesbare Form um 124 | override public string ToString() 125 | { 126 | string resultString = ""; 127 | foreach (Gene gene in genes) 128 | { 129 | resultString += gene.ToString() + " "; 130 | } 131 | return resultString; 132 | } 133 | 134 | #region IComparable> Member 135 | 136 | // Implementation des IComparable Interfaces zum sortieren von Chromosomen. 137 | public int CompareTo(Chromosome other) 138 | { 139 | return this.fitness.CompareTo(other.fitness); 140 | } 141 | 142 | #endregion 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/AlphaSelector.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System.Collections; 25 | 26 | namespace GeneticAlgorithms.ExampleClasses 27 | { 28 | public class AlphaSelector : ISelectionProvider 29 | { 30 | 31 | #region ISelectionProvider Member 32 | 33 | public IChromosome select(ArrayList population, float totalFitness) 34 | { 35 | IChromosome alphaChromosome = null; 36 | foreach (IChromosome chromosome in population) 37 | if (alphaChromosome == null || alphaChromosome.Fitness < chromosome.Fitness) 38 | alphaChromosome = chromosome; 39 | return alphaChromosome; 40 | } 41 | 42 | #endregion 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/AsymetricCrossoverRecombinator.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections; 26 | 27 | namespace GeneticAlgorithms.ExampleClasses 28 | { 29 | public class AsymmetricCrossoverRecombinator : IRecombinationProvider 30 | { 31 | 32 | Random random = new Random(); 33 | #region IRecombinationProvider Member 34 | 35 | public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes) 36 | { 37 | double maleConstraint = random.NextDouble(); 38 | int maleCount = (int)Math.Ceiling(maleGenes.Count * maleConstraint); 39 | int femaleCount = (int)Math.Floor(femaleGenes.Count * (1-maleConstraint)); 40 | ArrayList child = new ArrayList(maleCount + femaleCount); 41 | child.InsertRange(0, maleGenes.GetRange(0, maleCount)); 42 | child.InsertRange(maleCount, femaleGenes.GetRange(femaleGenes.Count - femaleCount, femaleCount)); 43 | 44 | for (int i = 0; i < child.Count; i++) 45 | child[i] = (child[i] as IGene).Clone(); 46 | 47 | return child; 48 | } 49 | 50 | #endregion 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/AsymmetricZipRecombinator.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections; 26 | 27 | namespace GeneticAlgorithms.Example_Classes 28 | { 29 | public class AsymmetricZipRecombinator : IRecombinationProvider 30 | { 31 | #region IRecombinationProvider Member 32 | 33 | public System.Collections.ArrayList Recombine(System.Collections.ArrayList maleGenes, System.Collections.ArrayList femaleGenes) 34 | { 35 | ArrayList child; 36 | 37 | if (maleGenes.Count < femaleGenes.Count) 38 | { 39 | child = femaleGenes.Clone() as ArrayList; 40 | for (int i = 0; i < maleGenes.Count; i++) 41 | { 42 | if (!Convert.ToBoolean(i % 2)) 43 | child[i] = maleGenes[i]; 44 | // Deep Copy 45 | child[i] = (child[i] as IGene).Clone(); 46 | } 47 | } 48 | else 49 | { 50 | child = maleGenes.Clone() as ArrayList; 51 | for (int i = 0; i < femaleGenes.Count; i++) 52 | { 53 | if (!Convert.ToBoolean(i % 2)) 54 | child[i] = femaleGenes[i]; 55 | // Deep Copy 56 | child[i] = (child[i] as IGene).Clone(); 57 | } 58 | } 59 | return child; 60 | } 61 | 62 | #endregion 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/BoolGene.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | 26 | namespace GeneticAlgorithms.ExampleClasses 27 | { 28 | public class BoolGene : 29 | IGene 30 | { 31 | private static Random randomizer = null; 32 | protected bool value; 33 | 34 | public BoolGene(bool value) 35 | { 36 | if (BoolGene.randomizer == null) 37 | BoolGene.randomizer = new Random(); 38 | this.value = value; 39 | } 40 | 41 | public BoolGene() 42 | { 43 | if (BoolGene.randomizer == null) 44 | BoolGene.randomizer = new Random(); 45 | this.Mutate(); 46 | } 47 | 48 | public override string ToString() 49 | { 50 | if (this.value) 51 | return "1"; 52 | else 53 | return "0"; 54 | //return value.ToString(); 55 | } 56 | 57 | #region IGene Member 58 | 59 | public void Mutate() 60 | { 61 | this.value = !this.value;//Convert.ToBoolean(randomizer.Next(0, 2)); 62 | } 63 | 64 | #endregion 65 | 66 | public static implicit operator BoolGene(bool other) 67 | { 68 | return new BoolGene(other); 69 | } 70 | 71 | public static implicit operator bool(BoolGene other) 72 | { 73 | return other.value; 74 | } 75 | 76 | public object Clone() 77 | { 78 | return new BoolGene(this.value); 79 | } 80 | 81 | new public bool Equals(object o) 82 | { 83 | return (o as BoolGene).value == this.value; 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/BoolGrowthLimitedFitness.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System.Collections; 25 | 26 | namespace GeneticAlgorithms.ExampleClasses 27 | { 28 | public class BoolGrowthLimitedFitness : IFitnessFunctionProvider 29 | { 30 | #region IFitnessFunctionProvider Member 31 | 32 | public float ComputeFitness(ArrayList genes) 33 | { 34 | float sum = 0; 35 | foreach (BoolGene gene in genes) 36 | { 37 | if (gene == true) 38 | sum += 1; 39 | } 40 | return sum * 10 - genes.Count*genes.Count; 41 | } 42 | 43 | #endregion 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/BoolSumFitness.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System.Collections; 25 | 26 | namespace GeneticAlgorithms.ExampleClasses 27 | { 28 | public class BoolSumFitness : 29 | IFitnessFunctionProvider 30 | { 31 | #region IFitnessFunctionProvider Member 32 | 33 | public float ComputeFitness(ArrayList genes) 34 | { 35 | float sum = 0; 36 | foreach(BoolGene gene in genes) 37 | { 38 | if (gene == true) 39 | sum += 1; 40 | } 41 | return sum; 42 | } 43 | 44 | #endregion 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/CrossoverRecombinator.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System.Collections; 25 | 26 | namespace GeneticAlgorithms 27 | { 28 | public class CrossoverRecombinator : 29 | IRecombinationProvider 30 | { 31 | #region IRecombinationProvider Member 32 | 33 | public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes) 34 | { 35 | if (maleGenes.Count != femaleGenes.Count) 36 | throw new GenesIncompatibleException(); 37 | ArrayList child = new ArrayList(maleGenes.Count); 38 | int middle = maleGenes.Count / 2; 39 | child.InsertRange(0, maleGenes.GetRange(0, middle).Clone() as ArrayList); 40 | child.InsertRange(middle, femaleGenes.GetRange(middle, femaleGenes.Count - middle).Clone() as ArrayList); 41 | 42 | // Create Deep Copy 43 | for (int i = 0; i < child.Count; i++) 44 | child[i] = (child[i] as IGene).Clone(); 45 | 46 | return child; 47 | } 48 | 49 | #endregion 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/IntGene.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | 26 | namespace GeneticAlgorithms.ExampleClasses 27 | { 28 | public class IntGene : 29 | IGene 30 | { 31 | public static int MaxValue = 100; 32 | private static Random randomizer = null; 33 | protected int value; 34 | 35 | public IntGene(int value) 36 | { 37 | if (IntGene.randomizer == null) 38 | IntGene.randomizer = new Random(); 39 | this.value = value; 40 | } 41 | 42 | public IntGene() 43 | { 44 | if (IntGene.randomizer == null) 45 | IntGene.randomizer = new Random(); 46 | this.Mutate(); 47 | } 48 | 49 | public override string ToString() 50 | { 51 | return value.ToString(); 52 | } 53 | 54 | #region IGene Member 55 | 56 | public void Mutate() 57 | { 58 | this.value = randomizer.Next() % IntGene.MaxValue; 59 | } 60 | 61 | #endregion 62 | 63 | public static implicit operator IntGene(int other) 64 | { 65 | return new IntGene(other); 66 | } 67 | 68 | public static implicit operator int(IntGene other) 69 | { 70 | return other.value; 71 | } 72 | 73 | public object Clone() 74 | { 75 | return new IntGene(this.value); 76 | } 77 | 78 | new public bool Equals(object o) 79 | { 80 | return (o as IntGene).value == this.value; 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/Mondlandungs/MondlandungsSimulation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using GeneticAlgorithms; 7 | using GeneticAlgorithms.ExampleClasses; 8 | 9 | namespace GeneticAlgorithms.ExampleClasses.MondLandungs 10 | { 11 | public class MondlandungsSimulationEventArgs : EventArgs 12 | { 13 | private Raumschiff raumschiff; 14 | private int schub; 15 | 16 | public int Schub 17 | { 18 | get 19 | { 20 | return schub; 21 | } 22 | } 23 | 24 | public Raumschiff Raumschiff 25 | { 26 | get 27 | { 28 | return this.raumschiff; 29 | } 30 | } 31 | 32 | public MondlandungsSimulationEventArgs(Raumschiff raumschiff, int schub) 33 | { 34 | this.raumschiff = raumschiff; 35 | this.schub = schub; 36 | } 37 | } 38 | 39 | public class MondlandungsSimulation : IFitnessFunctionProvider 40 | { 41 | private int startHoehe; 42 | private int startTreibstoff; 43 | private int raumschiffGewicht; 44 | private bool nutzeRaumfahrerGewicht; 45 | 46 | public OnSimulationTurn SimulationTurn; 47 | 48 | public MondlandungsSimulation(int raumschiffStartHoehe, int raumschiffStartTreibstoff, int raumschiffStartGewicht, bool nutzeRaumfahrerGewicht) 49 | { 50 | startHoehe = raumschiffStartHoehe; 51 | startTreibstoff = raumschiffStartTreibstoff; 52 | raumschiffGewicht = raumschiffStartGewicht; 53 | this.nutzeRaumfahrerGewicht = nutzeRaumfahrerGewicht; 54 | } 55 | 56 | #region IFitnessFunctionProvider Member 57 | 58 | public float ComputeFitness(ArrayList genes) 59 | { 60 | float fitness = 0.0f; 61 | Raumfahrer pilot = new Raumfahrer(genes); 62 | Raumschiff raumschiff = new Raumschiff(pilot, startHoehe, startTreibstoff, raumschiffGewicht, nutzeRaumfahrerGewicht); 63 | int schub = 0; 64 | while (raumschiff.Hoehe > 0) 65 | { 66 | schub = pilot.SteuereRaumschiff(raumschiff); 67 | raumschiff.SimuliereRunde(); 68 | if (SimulationTurn != null) 69 | SimulationTurn(this, new MondlandungsSimulationEventArgs(raumschiff, schub)); 70 | } 71 | /*if (SimulationTurn != null) 72 | SimulationTurn(this, new MondlandungsSimulationEventArgs(raumschiff, schub));*/ 73 | // Convert.ToInt32(Math.Sqrt((raumschiff.Hoehe * raumschiff.Hoehe))) + 74 | /*int toleranz = Convert.ToInt32(Math.Sqrt((raumschiff.Geschwindigkeit * raumschiff.Geschwindigkeit))) - 5; 75 | if (toleranz < 0) 76 | toleranz = 0;*/ 77 | 78 | //fitness = ((1000 + raumschiff.Geschwindigkeit) / 1000.0f * 0.9f) + (raumschiff.Treibstoff / (float) startTreibstoff * 0.1f); 79 | //fitness = 0.7f / (1.0f + toleranz/10) + (raumschiff.Treibstoff / (float)startTreibstoff * 0.3f); 80 | //fitness = 0.6f * Convert.ToInt32(Math.Pow(1.01, -toleranz)) + (raumschiff.Treibstoff / (float)startTreibstoff * 0.4f); 81 | fitness = 0.7f * Convert.ToSingle(Math.Pow(1.02f, raumschiff.Geschwindigkeit)) + (raumschiff.Treibstoff / (float)startTreibstoff * 0.3f); 82 | //fitness = 1 / (1.0f - raumschiff.Geschwindigkeit/10.0f); 83 | 84 | return fitness; 85 | } 86 | 87 | // Methode nur für Unit Tests 88 | public float TestComputeFitness(ArrayList genes) 89 | { 90 | float fitness = 0.0f; 91 | Raumfahrer pilot = new Raumfahrer(genes); 92 | 93 | foreach (IntGene gene in genes) 94 | { 95 | fitness += gene; 96 | } 97 | return fitness; 98 | } 99 | 100 | #endregion 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/Mondlandungs/Raumfahrer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections; 6 | using GeneticAlgorithms.ExampleClasses; 7 | 8 | namespace GeneticAlgorithms.ExampleClasses.MondLandungs 9 | { 10 | /// 11 | /// Repräsentiert einen Raumfahrer mit den Eigenschaften Kommandoliste, nächstes Kommando und Gewicht 12 | /// 13 | public class Raumfahrer 14 | { 15 | /// 16 | /// Die Liste der Steuerbefehle 17 | /// 18 | protected ArrayList kommandoListe; 19 | /// 20 | /// Das nächste auszuführende Kommando 21 | /// 22 | protected int naechstesKommando; 23 | 24 | /// 25 | /// Gibt das Gewicht zurück. Das Gewicht eines Raumfahrers entspricht der Chromosomenlänge bzw. der Anzahl an Kommandos 26 | /// 27 | public int Gewicht 28 | { 29 | get { return kommandoListe.Count; } 30 | } 31 | 32 | /// 33 | /// Konstruktor, weist dem Raumfahrer eine Kommandoliste zu 34 | /// 35 | /// Die zuzuweisende Kommandoliste 36 | public Raumfahrer(ArrayList kommandoListe) 37 | { 38 | if (kommandoListe == null) 39 | throw new NullReferenceException(); 40 | this.kommandoListe = kommandoListe; 41 | this.naechstesKommando = 0; 42 | } 43 | 44 | /// 45 | /// Weist dem Raumfahrer ein Raumschiff zu und lässt es ihn steuern. 46 | /// 47 | /// Das zuzuweisende Raumschiff 48 | /// Ausgeführtes Kommando, also Schubkraft 49 | public int SteuereRaumschiff(Raumschiff raumschiff) 50 | { 51 | int schub = raumschiff.Beschleunigen(kommandoListe[naechstesKommando] as IntGene); 52 | if (++naechstesKommando == kommandoListe.Count) 53 | naechstesKommando = 0; 54 | return schub; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/Mondlandungs/Raumschiff.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace GeneticAlgorithms.ExampleClasses.MondLandungs 7 | { 8 | /// 9 | /// Repräsentiert ein Raumschiff mit den Eigenschaften Treibstoff, Gewicht, Geschwindigkeit, Höhe und einem Raumfahrer 10 | /// 11 | public class Raumschiff 12 | { 13 | private int treibstoff; 14 | private int gewicht; 15 | private int geschwindigkeit; 16 | private int hoehe; 17 | private bool nutzeRaumfahrerGewicht; 18 | private Raumfahrer pilot; 19 | 20 | 21 | /// 22 | /// Konstruktor des Raumschiffs 23 | /// 24 | /// Pilot, der das Raumschiff steuern soll 25 | /// Die Starthöhe des Raumschiffs 26 | /// Der Starttreibstoff des Raumschiffs 27 | /// Das Startgewicht des Raumschiffs 28 | /// Gibt an, ob das Gewicht des Raumfahrers mit einberechnet werden soll 29 | public Raumschiff(Raumfahrer pilot, int startHoehe, int startTreibstoff, int startGewicht, bool nutzeRaumfahrerGewicht) 30 | { 31 | this.pilot = pilot; 32 | this.hoehe = startHoehe; 33 | this.treibstoff = startTreibstoff; 34 | this.gewicht = startGewicht; 35 | this.geschwindigkeit = 0; 36 | this.nutzeRaumfahrerGewicht = nutzeRaumfahrerGewicht; 37 | } 38 | 39 | /// 40 | /// Beschleunigt das Raumschiff, wenn genügend Treibstoff übrig ist und berechnet anschließend die neuen Werte für Geschwindigkeit und Treibstoff 41 | /// 42 | /// Anzahl der zu gebenden Schubs 43 | /// Tatsächlich gegegebener Schub 44 | public int Beschleunigen(int schub) 45 | { 46 | if (treibstoff > 0) 47 | { 48 | if (treibstoff >= schub) 49 | { 50 | this.geschwindigkeit += schub; 51 | this.treibstoff -= schub; 52 | return schub; 53 | } 54 | else 55 | { 56 | this.geschwindigkeit += treibstoff; 57 | int tmpTreibstoff = this.treibstoff; 58 | this.treibstoff = 0; 59 | return tmpTreibstoff; 60 | } 61 | } 62 | else 63 | return 0; 64 | } 65 | 66 | /// 67 | /// Simuliert eine Runde, berechnet die neue Höhe und Geschwindigkeit 68 | /// 69 | public void SimuliereRunde() 70 | { 71 | geschwindigkeit -= gewicht; 72 | if (nutzeRaumfahrerGewicht) 73 | geschwindigkeit -= pilot.Gewicht; 74 | hoehe += geschwindigkeit; 75 | } 76 | 77 | 78 | public int Treibstoff 79 | { 80 | get { return treibstoff; } 81 | } 82 | 83 | public int Gewicht 84 | { 85 | get { return gewicht; } 86 | } 87 | 88 | public int Geschwindigkeit 89 | { 90 | get { return geschwindigkeit; } 91 | } 92 | 93 | public int Hoehe 94 | { 95 | get { return hoehe; } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/PieCakeSelector.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections; 26 | 27 | namespace GeneticAlgorithms.Example_Classes 28 | { 29 | public class PieCakeSelector : ISelectionProvider 30 | { 31 | private static Random randomizer; 32 | 33 | public PieCakeSelector() 34 | { 35 | if (randomizer == null) 36 | randomizer = new Random(); 37 | } 38 | 39 | public IChromosome select(ArrayList population, float totalFitness) 40 | { 41 | float selectionPoint = Convert.ToSingle(PieCakeSelector.randomizer.NextDouble() * totalFitness); 42 | int index = 0; 43 | try 44 | { 45 | while (selectionPoint > (population[index] as IChromosome).Fitness) 46 | selectionPoint -= (population[index++] as IChromosome).Fitness; 47 | } 48 | catch (ArgumentOutOfRangeException ignore) 49 | { // kann evtl. aufgrund von numerischen Effekten auftreten, wenn wird letztes Chromosome ausgewählt 50 | index--; 51 | } 52 | return (population[index] as IChromosome); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/RandomSelector.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections.Generic; 26 | 27 | namespace GeneticAlgorithms.ExampleClasses 28 | { 29 | public class RandomSelector : ISelectionProvider 30 | { 31 | #region ISelectionProvider Member 32 | 33 | static protected Random randomizer; 34 | 35 | public RandomSelector() 36 | { 37 | if (RandomSelector.randomizer == null) 38 | RandomSelector.randomizer = new Random(); 39 | } 40 | 41 | public IChromosome select(System.Collections.ArrayList population, float totalFitness) 42 | { 43 | return population[RandomSelector.randomizer.Next(0, population.Count)] as IChromosome; 44 | } 45 | 46 | #endregion 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Genetic Algorithms/ExampleClasses/UniformMultiPointCrossoverRecombinator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace GeneticAlgorithms.Example_Classes 5 | { 6 | public class UniformMultiPointCrossoverRecombinator : IRecombinationProvider 7 | { 8 | public static float GenesPerCrossover = 5; 9 | 10 | Random random = new Random(); 11 | #region IRecombinationProvider Member 12 | 13 | public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes) 14 | { 15 | ArrayList Child = maleGenes.Clone() as ArrayList; 16 | 17 | bool usingMale = true; 18 | for (int i = 0; i < maleGenes.Count; i++) 19 | { 20 | Child[i] = usingMale ? ((IGene)maleGenes[i]).Clone() : Child[i] = ((IGene)femaleGenes[i]).Clone(); 21 | if (i % GenesPerCrossover == 0) usingMale = !usingMale; 22 | } 23 | 24 | return Child; 25 | } 26 | 27 | #endregion 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Genetic Algorithms/Genetic Algorithms.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {6E92618B-EE42-4427-8924-F5FA675B1735} 9 | Library 10 | Properties 11 | GeneticAlgorithms 12 | Genetic Algorithms 13 | v3.5 14 | 512 15 | 16 | 17 | 3.5 18 | 19 | false 20 | publish\ 21 | true 22 | Disk 23 | false 24 | Foreground 25 | 7 26 | Days 27 | false 28 | false 29 | true 30 | 0 31 | 1.0.0.%2a 32 | false 33 | true 34 | 35 | 36 | true 37 | full 38 | true 39 | bin\Debug\ 40 | DEBUG;TRACE 41 | prompt 42 | 4 43 | AnyCPU 44 | true 45 | AllRules.ruleset 46 | 47 | 48 | pdbonly 49 | true 50 | bin\Release\ 51 | TRACE 52 | prompt 53 | 4 54 | AllRules.ruleset 55 | 56 | 57 | 58 | 59 | 3.5 60 | 61 | 62 | 63 | 64 | 3.5 65 | 66 | 67 | 3.5 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | True 80 | True 81 | Resources.resx 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | ResXFileCodeGenerator 107 | Resources.Designer.cs 108 | Designer 109 | 110 | 111 | 112 | 113 | False 114 | .NET Framework 3.5 SP1 Client Profile 115 | false 116 | 117 | 118 | False 119 | .NET Framework 3.5 SP1 120 | true 121 | 122 | 123 | False 124 | Windows Installer 3.1 125 | true 126 | 127 | 128 | 129 | 130 | 137 | -------------------------------------------------------------------------------- /Genetic Algorithms/GeneticSimulation.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections; 26 | 27 | 28 | namespace GeneticAlgorithms 29 | { 30 | public delegate void OnSimulationTurn(object sender, EventArgs e); 31 | 32 | public class GeneticSimulation where Gene: IGene, new() 33 | { 34 | private IFitnessFunctionProvider fitnessComputer; 35 | private IRecombinationProvider recombinator; 36 | private ISelectionProvider maleSelector; 37 | private ISelectionProvider femaleSelector; 38 | private double geneMutationRate; 39 | private double geneDropRate; 40 | private double geneDuplicationRate; 41 | private float totalFitness; 42 | private float averageChromosomeLength; 43 | private int populationSize; 44 | private int defaultChromosomeLength; 45 | private Chromosome mostSuccessfullIndividual; 46 | private Chromosome leastSuccessfullIndividual; 47 | protected Random randomizer; 48 | private bool abort = false; 49 | 50 | protected ArrayList population; 51 | 52 | protected Chromosome selectMaleChromosome() 53 | { 54 | return this.maleSelector.select(this.population, this.totalFitness) as Chromosome; 55 | } 56 | 57 | protected Chromosome selectFemaleChromosome() 58 | { 59 | return this.femaleSelector.select(this.population, this.totalFitness) as Chromosome; 60 | } 61 | 62 | public ArrayList Population 63 | { 64 | get 65 | { 66 | return population; 67 | } 68 | } 69 | 70 | public Chromosome this[int index] 71 | { 72 | get 73 | { 74 | return population[index] as Chromosome; 75 | } 76 | } 77 | 78 | public void AbortSimulation() 79 | { 80 | abort = true; 81 | } 82 | 83 | public int PoppulationSize 84 | { 85 | get 86 | { 87 | return this.populationSize; 88 | } 89 | } 90 | 91 | public int DefaultGeneCount 92 | { 93 | get 94 | { 95 | return this.defaultChromosomeLength; 96 | } 97 | } 98 | 99 | public GeneticSimulation(int populationSize, int defaultGeneCount,IFitnessFunctionProvider fitnessComputer, IRecombinationProvider recombinator, ISelectionProvider selector): 100 | this(populationSize, defaultGeneCount, fitnessComputer, recombinator, selector, selector) 101 | { 102 | } 103 | 104 | public GeneticSimulation(int populationSize, int defaultGeneCount, IFitnessFunctionProvider fitnessComputer, IRecombinationProvider recombinator, ISelectionProvider maleSelector, ISelectionProvider femaleSelector) 105 | { 106 | this.fitnessComputer = fitnessComputer; 107 | this.recombinator = recombinator; 108 | this.maleSelector = maleSelector; 109 | this.femaleSelector = femaleSelector; 110 | this.populationSize = populationSize; 111 | this.defaultChromosomeLength = defaultGeneCount; 112 | 113 | this.geneMutationRate = 0.01d; 114 | this.geneDuplicationRate = 0.0d; 115 | this.geneDropRate = 0.0d; 116 | 117 | this.randomizer = new Random(); 118 | 119 | this.ResetSimulation(); 120 | } 121 | 122 | public float AverageChromosomeLength 123 | { 124 | get 125 | { 126 | return this.averageChromosomeLength; 127 | } 128 | } 129 | 130 | public Chromosome MostSuccessfullIndividual 131 | { 132 | get 133 | { 134 | return mostSuccessfullIndividual; 135 | } 136 | } 137 | 138 | public Chromosome LeasSuccessfullIndividual 139 | { 140 | get 141 | { 142 | return leastSuccessfullIndividual; 143 | } 144 | } 145 | 146 | public float TotalFitness 147 | { 148 | get 149 | { 150 | return totalFitness; 151 | } 152 | } 153 | 154 | public float AverageFitness 155 | { 156 | get 157 | { 158 | return totalFitness / population.Count; 159 | } 160 | } 161 | 162 | public double GeneMutationRate 163 | { 164 | get { return geneMutationRate; } 165 | set { geneMutationRate = value; } 166 | } 167 | 168 | public double GeneDuplicationRate 169 | { 170 | get { return geneDuplicationRate; } 171 | set { geneDuplicationRate = value; } 172 | } 173 | 174 | public double GeneDropRate 175 | { 176 | get { return geneDropRate; } 177 | set { geneDropRate = value; } 178 | } 179 | 180 | public IFitnessFunctionProvider FitnessComputer 181 | { 182 | get 183 | { 184 | return fitnessComputer; 185 | } 186 | set 187 | { 188 | fitnessComputer = value; 189 | } 190 | } 191 | 192 | public IRecombinationProvider Recombinator 193 | { 194 | get 195 | { 196 | return recombinator; 197 | } 198 | set 199 | { 200 | recombinator = value; 201 | } 202 | } 203 | 204 | public OnSimulationTurn SimulationTurn; 205 | 206 | virtual public void ResetSimulation() 207 | { 208 | population = new ArrayList(this.populationSize); 209 | while (this.population.Count < this.populationSize) 210 | { 211 | Chromosome chromosome = new Chromosome(this.defaultChromosomeLength); 212 | chromosome.computeFitness(this.fitnessComputer); 213 | this.population.Add(chromosome); 214 | } 215 | populateStatistics(); 216 | } 217 | 218 | virtual protected void populateStatistics() 219 | { 220 | this.totalFitness = 0; 221 | this.averageChromosomeLength = 0; 222 | this.leastSuccessfullIndividual = null; 223 | this.mostSuccessfullIndividual = null; 224 | foreach (Chromosome chromosome in this.population) 225 | { 226 | if (this.leastSuccessfullIndividual == null || this.leastSuccessfullIndividual.Fitness > chromosome.Fitness) 227 | this.leastSuccessfullIndividual = chromosome; 228 | if (this.mostSuccessfullIndividual == null || this.mostSuccessfullIndividual.Fitness < chromosome.Fitness) 229 | this.mostSuccessfullIndividual = chromosome; 230 | totalFitness += chromosome.Fitness; 231 | averageChromosomeLength += chromosome.GeneCount; 232 | } 233 | this.averageChromosomeLength /= this.population.Count; 234 | } 235 | 236 | virtual public void RunSimulation() 237 | { 238 | ArrayList newPopulation = new ArrayList(populationSize); 239 | Chromosome newChromosome = null; 240 | while (newPopulation.Count < this.populationSize) 241 | { 242 | try 243 | { 244 | newChromosome = this.selectMaleChromosome().Recombine(this.selectFemaleChromosome(), this.recombinator); 245 | for (int i = 0; i < newChromosome.GeneCount; i++) 246 | { 247 | if (this.randomizer.NextDouble() < this.geneMutationRate) 248 | newChromosome[i].Mutate(); 249 | if (this.randomizer.NextDouble() < this.geneDuplicationRate) 250 | newChromosome.DuplicateGene(i); 251 | if (newChromosome.GeneCount > 1 && this.randomizer.NextDouble() < this.geneDropRate) 252 | newChromosome.DropGene(i); 253 | } 254 | newChromosome.computeFitness(this.fitnessComputer); 255 | newPopulation.Add(newChromosome); 256 | } 257 | catch (GenesIncompatibleException ignore) 258 | { 259 | } 260 | } 261 | 262 | this.population = newPopulation; 263 | 264 | this.populateStatistics(); 265 | 266 | if (SimulationTurn != null) 267 | SimulationTurn(this, EventArgs.Empty); 268 | } 269 | 270 | public void RunSimulation(int turns) 271 | { 272 | for (int i = 0; i < turns; i++) 273 | { 274 | this.RunSimulation(); 275 | if (abort) 276 | { 277 | abort = false; 278 | break; 279 | } 280 | } 281 | } 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /Genetic Algorithms/IChromosome.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | 25 | namespace GeneticAlgorithms 26 | { 27 | /* IChromosome 28 | * 29 | * IChromosome muss von allen Chromosomklassen implementiert werden. 30 | * - IChromosome.Fitness liefert die Fitness des Chromosoms zurück 31 | * - IChromosome.DuplicateGene dupliziert das Gen an der durch index bestimmten Position im Chromosom 32 | * - IChromosome.DropGene entfernt das Gen an der durch index bestimmten Position im Chromosom 33 | */ 34 | public interface IChromosome 35 | { 36 | float Fitness 37 | { 38 | get; 39 | } 40 | void DuplicateGene(int index); 41 | void DropGene(int index); 42 | }// 43 | } 44 | -------------------------------------------------------------------------------- /Genetic Algorithms/IFitnessFunctionProvider.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System.Collections; 25 | 26 | namespace GeneticAlgorithms 27 | { 28 | public interface IFitnessFunctionProvider 29 | { 30 | float ComputeFitness(ArrayList genes); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Genetic Algorithms/IGene.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | 26 | namespace GeneticAlgorithms 27 | { 28 | /* IGene 29 | * implementiert: ICloneable 30 | * 31 | * Alle Genklassen müssen dieses Interface implementieren. 32 | * - ICloneable.Clone() muss eine value-Kopie des Objektes erzeugen 33 | * - IGene.Equals() muss einen value-Vergleich der Objekte vornehmen 34 | * - IGene.Mutate() muss den Wert des Gens (zufällig) verändern; bei binären Genen ist eine invertierung erlaubt 35 | */ 36 | public interface IGene : ICloneable 37 | { 38 | void Mutate(); 39 | bool Equals(object gene); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Genetic Algorithms/IRecombinationProvider.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System; 25 | using System.Collections; 26 | 27 | namespace GeneticAlgorithms 28 | { 29 | public interface IRecombinationProvider 30 | { 31 | ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes); 32 | } 33 | 34 | public class GenesIncompatibleException : Exception 35 | { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Genetic Algorithms/ISelectionProvider.cs: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Daniel Baulig 2 | * 3 | * This file is part of the Genetic Algorithms library. 4 | * 5 | * The Genetic Algorithms library is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * The Genetic Algorithms library is distributed in the hope that it will 11 | * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with the Genetic Algorithms library. If not, see 17 | * . 18 | * 19 | * e-mail: daniel dot baulig at gmx dot de 20 | * 21 | * If you wish to donate, please have a look at my Amazon Wishlist: 22 | * http://www.amazon.de/wishlist/1GWSB78PYVFBQ 23 | */ 24 | using System.Collections; 25 | 26 | namespace GeneticAlgorithms 27 | { 28 | public interface ISelectionProvider 29 | { 30 | IChromosome select(ArrayList population, float totalFitness); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Genetic Algorithms/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("Genetic Algorithms")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Genetic Algorithms")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("e3aff6ec-f310-4e9b-a496-2d610c28f973")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Genetic Algorithms/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Dieser Code wurde von einem Tool generiert. 4 | // Laufzeitversion:2.0.50727.4927 5 | // 6 | // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn 7 | // der Code erneut generiert wird. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithms.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. 17 | /// 18 | // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert 19 | // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. 20 | // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen 21 | // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GeneticAlgorithms.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle 51 | /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Genetic Algorithms/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Explosion.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Explosion.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Fahne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Fahne.png -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/GUI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Reflection; 9 | using System.Text; 10 | using System.Windows.Forms; 11 | using GeneticAlgorithms; 12 | using GeneticAlgorithms.ExampleClasses; 13 | using GeneticAlgorithms.ExampleClasses.MondLandungs; 14 | using ZedGraph; 15 | 16 | namespace GeneticAlgorithmsGUI 17 | { 18 | public partial class GUI : Form 19 | { 20 | private PointPairList avgFitnessList, avgLengthList, avgVariationList, maxFitnessList, minFitnessList; 21 | private LineItem avgFitnessCurve, avgLengthCurve, avgVariationCurve, maxFitnessCurve, minFitnessCurve; 22 | private GeneticSimulation GenSim = null; 23 | private MondlandungsSimulation MondSim = null; 24 | private IRecombinationProvider recombinationProvider = null; 25 | private ISelectionProvider selectionProvider = null; 26 | private Bitmap _backBuffer = null; 27 | private Graphics gBuffer = null; 28 | private Bitmap bmpWeltraum = null; 29 | private Bitmap bmpRaumschiffIntakt = null; 30 | private Bitmap bmpRaumschiffKaputt = null; 31 | private Bitmap bmpRaumschiff = null; 32 | private Bitmap bmpRaumschiffLeer = null; 33 | private Bitmap bmpTriebwerk = null; 34 | private Bitmap bmpRaumfahrer = null; 35 | private Bitmap bmpFahne = null; 36 | private bool simulationAbbrechen = false; 37 | private bool closingApplication = false; 38 | 39 | private int letzteHoehe = 0; 40 | 41 | private int turn = 0; 42 | 43 | /// 44 | /// Konstruktor - Initialisierung der Bedienoberfläche 45 | /// 46 | public GUI() 47 | { 48 | InitializeComponent(); 49 | //Initialisireung des ZedGraph 50 | GraphPane graphPane = zgc_Simulationsgraph.GraphPane; 51 | graphPane.Title.Text = "Population"; 52 | graphPane.XAxis.Title.Text = "Runden"; 53 | graphPane.XAxis.Scale.Min = 1; 54 | graphPane.XAxis.Scale.MaxAuto = true; 55 | graphPane.YAxis.Title.Text = "Fitness"; 56 | graphPane.YAxis.Scale.Max = 1.0; 57 | graphPane.YAxis.Scale.Min = 0.0; 58 | graphPane.YAxisList.Add("Länge"); 59 | graphPane.YAxisList[1].IsVisible = false; 60 | graphPane.YAxisList[1].Scale.MaxAuto = true; 61 | graphPane.YAxisList[1].Scale.Min = 0; 62 | 63 | //Initialisireung der Graphen 64 | this.avgFitnessList = new PointPairList(); 65 | this.avgLengthList = new PointPairList(); 66 | this.avgVariationList = new PointPairList(); 67 | this.maxFitnessList = new PointPairList(); 68 | this.minFitnessList = new PointPairList(); 69 | this.avgFitnessCurve = graphPane.AddCurve("Ø Fitness", avgFitnessList, Color.Green, SymbolType.None); 70 | this.avgLengthCurve = graphPane.AddCurve("Ø Länge", avgLengthList, Color.Purple, SymbolType.None); 71 | this.minFitnessCurve = graphPane.AddCurve("min. Fitness", minFitnessList, Color.Red, SymbolType.None); 72 | this.maxFitnessCurve = graphPane.AddCurve("max. Fitness", maxFitnessList, Color.Blue, SymbolType.None); 73 | avgLengthCurve.YAxisIndex = 1; 74 | avgFitnessCurve.IsVisible = true; 75 | avgLengthCurve.IsVisible = false; 76 | minFitnessCurve.IsVisible = false; 77 | maxFitnessCurve.IsVisible = false; 78 | 79 | //Initialisireung der ComboBoxen 80 | cmb_Rekombinator.SelectedIndex = 0; 81 | recombinationProvider = new AsymmetricCrossoverRecombinator(); 82 | cmb_Selektor.SelectedIndex = 1; 83 | selectionProvider = new PieCakeSelector(); 84 | 85 | //Assembly erzeugen 86 | Assembly myAssembly = Assembly.GetExecutingAssembly(); 87 | Stream stream = null; 88 | 89 | // Bilder aus den Ressourcen der Assembly holen 90 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Weltraum.bmp"); 91 | bmpWeltraum = new Bitmap(stream); 92 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumschiff.gif"); 93 | bmpRaumschiffIntakt = new Bitmap(stream); 94 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Explosion.gif"); 95 | bmpRaumschiffKaputt = new Bitmap(stream); 96 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Triebwerk.gif"); 97 | bmpTriebwerk = new Bitmap(stream); 98 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumschiff_leer.gif"); 99 | bmpRaumschiffLeer = new Bitmap(stream); 100 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumfahrer.gif"); 101 | bmpRaumfahrer = new Bitmap(stream); 102 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Fahne.png"); 103 | bmpFahne = new Bitmap(stream); 104 | 105 | //Initialisierung des DoubleBuffer 106 | _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); 107 | gBuffer = Graphics.FromImage(_backBuffer); 108 | gBuffer.Clear(Color.White); 109 | } 110 | 111 | 112 | /// 113 | /// Paint Ereignis 114 | /// 115 | /// aufrufendes Objekt 116 | /// EreignisObjekt 117 | private void pnl_Animation_Paint(object sender, PaintEventArgs e) 118 | { 119 | drawClearBackground(); 120 | } 121 | 122 | 123 | /// 124 | /// leere Weltraum-/Mondlandschaft zeichnen 125 | /// 126 | private void drawClearBackground() 127 | { 128 | gBuffer.DrawImage(bmpWeltraum, 1, 1, 300, 650); 129 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 130 | } 131 | 132 | /// 133 | /// Raumschiffbild auf dem Hintergrund in bestimmter Höhe platzieren 134 | /// 135 | /// Höhe des Raumschiffs 136 | /// gegebener Schub 137 | public void setzeRaumschiff(int hoehe, int schub) 138 | { 139 | gBuffer.DrawImage(bmpWeltraum, 0, 0, 300, 650); 140 | float yPosition = 550.0f/Convert.ToInt64(txt_Hoehe.Text); 141 | yPosition *= hoehe; 142 | yPosition = 550 - yPosition; 143 | int skalierterSchub = schub * 2; 144 | 145 | gBuffer.DrawImage(bmpTriebwerk, 150 - (skalierterSchub / 2), yPosition + 65, skalierterSchub, skalierterSchub); 146 | gBuffer.DrawImage(bmpRaumschiff, 100, Convert.ToInt32(yPosition), 100, 100); 147 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 148 | } 149 | 150 | /// 151 | /// Beenden der Anwendung 152 | /// 153 | /// aufrufendes Objekt 154 | /// EreignisObjekt 155 | private void beendenToolStripMenuItem_Click(object sender, EventArgs e) 156 | { 157 | Application.Exit(); 158 | } 159 | 160 | /// 161 | /// "Über"-Dialogfenster anzeigen 162 | /// 163 | /// aufrufendes Objekt 164 | /// EreignisObjekt 165 | private void überToolStripMenuItem_Click(object sender, EventArgs e) 166 | { 167 | MessageBox.Show(this, "Mondlandungs-Simulation mit genetischen Algorithmen\n\nVersion 1.0\n\nEntwickelt von Daniel Baulig, Jonas Heil, Christian Kleemann, Sven Sperner\n\nZedGraph Control von http://www.zedgraph.org unter LGPL", "Über"); 168 | } 169 | 170 | 171 | /// 172 | /// Validierung eines eingegebenen Ganzzahl-Parameters 173 | /// 174 | /// aufrufendes Objekt 175 | /// EreignisObjekt 176 | private void txt_Int_Validating(object sender, CancelEventArgs e) 177 | { 178 | try 179 | { 180 | if (Convert.ToInt32((sender as TextBox).Text) < 0) 181 | throw new FormatException(); 182 | } 183 | catch (FormatException exception) 184 | { 185 | MessageBox.Show("Kein positiver Ganzzahlwert!"); 186 | (sender as TextBox).SelectAll(); 187 | e.Cancel = true; 188 | } 189 | } 190 | 191 | /// 192 | /// Validierung eines eingegebenen Fliesskomma-Parameters 193 | /// 194 | /// aufrufendes Objekt 195 | /// EreignisObjekt 196 | private void txt_Float_Validating(object sender, CancelEventArgs e) 197 | { 198 | try 199 | { 200 | if (Convert.ToDouble((sender as TextBox).Text) < 0) 201 | throw new FormatException(); 202 | } 203 | catch (FormatException exception) 204 | { 205 | MessageBox.Show("Kein positiver Gleitkommawert!"); 206 | (sender as TextBox).SelectAll(); 207 | e.Cancel = true; 208 | } 209 | } 210 | 211 | /// 212 | /// Durchschnittliche Fitness der Population ein-/ausblenden 213 | /// 214 | /// aufrufendes Objekt 215 | /// EreignisObjekt 216 | private void chk_AVGFitness_CheckedChanged(object sender, EventArgs e) 217 | { 218 | avgFitnessCurve.IsVisible = (sender as CheckBox).Checked; 219 | zgc_Simulationsgraph.GraphPane.YAxisList[0].IsVisible = chk_AVGFitness.Checked || chk_maxFitness.Checked || chk_minFitness.Checked; 220 | zgc_Simulationsgraph.AxisChange(); 221 | zgc_Simulationsgraph.Invalidate(); 222 | } 223 | 224 | /// 225 | /// Durchschnittliche Chromosomlänge der Population ein-/ausblenden 226 | /// 227 | /// aufrufendes Objekt 228 | /// EreignisObjekt 229 | private void chk_Laenge_CheckedChanged(object sender, EventArgs e) 230 | { 231 | avgLengthCurve.IsVisible = (sender as CheckBox).Checked; 232 | zgc_Simulationsgraph.GraphPane.YAxisList[1].IsVisible = avgLengthCurve.IsVisible = (sender as CheckBox).Checked; 233 | zgc_Simulationsgraph.AxisChange(); 234 | zgc_Simulationsgraph.Invalidate(); 235 | } 236 | 237 | /// 238 | /// Minimale Fitness der Population ein-/ausblenden 239 | /// 240 | /// aufrufendes Objekt 241 | /// EreignisObjekt 242 | private void chk_minFitness_CheckedChanged(object sender, EventArgs e) 243 | { 244 | minFitnessCurve.IsVisible = (sender as CheckBox).Checked; 245 | zgc_Simulationsgraph.GraphPane.YAxisList[0].IsVisible = chk_AVGFitness.Checked || chk_maxFitness.Checked || chk_minFitness.Checked; 246 | zgc_Simulationsgraph.AxisChange(); 247 | zgc_Simulationsgraph.Invalidate(); 248 | } 249 | 250 | /// 251 | /// Maximale Fitness der Population ein-/ausblenden 252 | /// 253 | /// aufrufendes Objekt 254 | /// EreignisObjekt 255 | private void chk_maxFitness_CheckedChanged(object sender, EventArgs e) 256 | { 257 | maxFitnessCurve.IsVisible = (sender as CheckBox).Checked; 258 | zgc_Simulationsgraph.GraphPane.YAxisList[0].IsVisible = chk_AVGFitness.Checked || chk_maxFitness.Checked || chk_minFitness.Checked; 259 | zgc_Simulationsgraph.AxisChange(); 260 | zgc_Simulationsgraph.Invalidate(); 261 | } 262 | 263 | /// 264 | /// Simulationsergebnisse zurücksetzen 265 | /// 266 | /// aufrufendes Objekt 267 | /// EreignisObjekt 268 | private void btn_Zuruecksetzten_Click(object sender, EventArgs e) 269 | { 270 | avgLengthList.Clear(); 271 | avgVariationList.Clear(); 272 | avgFitnessList.Clear(); 273 | maxFitnessList.Clear(); 274 | minFitnessList.Clear(); 275 | GenSim = null; 276 | MondSim = null; 277 | turn = 0; 278 | cmb_Selektor.Enabled = true; 279 | cmb_Rekombinator.Enabled = true; 280 | txt_Chromosomlaenge.Enabled = true; 281 | txt_Gewicht.Enabled = true; 282 | txt_Hoehe.Enabled = true; 283 | txt_Treibstoff.Enabled = true; 284 | txt_Mutationsrate.Enabled = true; 285 | txt_Verlustrate.Enabled = true; 286 | txt_Duplikationsrate.Enabled = true; 287 | dgv_Population.Rows.Clear(); 288 | btn_Abspielen.Enabled = false; 289 | lbl_AktGeschwindigkeit.Text = "0"; 290 | lbl_AktHoehe.Text = "0"; 291 | lbl_AktSchub.Text = "0"; 292 | lbl_AktTank.Text = "0"; 293 | chk_AVGFitness.Checked = true; 294 | chk_maxFitness.Checked = false; 295 | chk_minFitness.Checked = false; 296 | chk_Laenge.Checked = false; 297 | chk_Live.Checked = false; 298 | zgc_Simulationsgraph.GraphPane.GraphObjList.Clear(); 299 | zgc_Simulationsgraph.AxisChange(); 300 | zgc_Simulationsgraph.Invalidate(); 301 | drawClearBackground(); 302 | GraphPane p = zgc_Simulationsgraph.GraphPane; 303 | zgc_Simulationsgraph.ZoomOutAll(p); 304 | p.YAxisList[1].Scale.Max = 10; 305 | p.YAxisList[1].Scale.MaxAuto = true; 306 | 307 | } 308 | 309 | /// 310 | /// Simulationsrunde durchlaufen 311 | /// 312 | /// aufrufendes Objekt 313 | /// EreignisObjekt 314 | private void OnSimulationTurn(object sender, EventArgs e) 315 | { 316 | turn ++; 317 | if (simulationAbbrechen) 318 | { 319 | GenSim.AbortSimulation(); 320 | simulationAbbrechen = false; 321 | } 322 | this.avgFitnessList.Add(turn, GenSim.AverageFitness); 323 | this.avgLengthList.Add(turn, GenSim.AverageChromosomeLength); 324 | if (zgc_Simulationsgraph.GraphPane.YAxisList[1].Scale.Max < GenSim.AverageChromosomeLength) 325 | zgc_Simulationsgraph.GraphPane.YAxisList[1].Scale.Max = GenSim.AverageChromosomeLength + 1; 326 | this.maxFitnessList.Add(turn, GenSim.MostSuccessfullIndividual.Fitness); 327 | this.minFitnessList.Add(turn, GenSim.LeasSuccessfullIndividual.Fitness); 328 | if (turn % 10 == 0 && chk_Live.Checked) 329 | { 330 | zgc_Simulationsgraph.AxisChange(); 331 | zgc_Simulationsgraph.Invalidate(); 332 | } 333 | Application.DoEvents(); 334 | } 335 | 336 | /// 337 | /// Simulation starten 338 | /// 339 | /// aufrufendes Objekt 340 | /// EreignisObjekt 341 | private void btn_Simuliere_Click(object sender, EventArgs e) 342 | { 343 | Cursor = Cursors.WaitCursor; 344 | btn_Simuliere.Enabled = false; 345 | btn_Zuruecksetzen.Enabled = false; 346 | btn_AutoSim.Enabled = false; 347 | btn_SimAbbrechen.Focus(); 348 | //erster Durchlauf der Simulation 349 | if (GenSim == null) 350 | { 351 | btn_Abspielen.Enabled = true; 352 | txt_Chromosomlaenge.Enabled = false; 353 | cmb_Rekombinator.Enabled = false; 354 | cmb_Selektor.Enabled = false; 355 | txt_Gewicht.Enabled = false; 356 | txt_Hoehe.Enabled = false; 357 | txt_Treibstoff.Enabled = false; 358 | txt_Mutationsrate.Enabled = false; 359 | txt_Verlustrate.Enabled = false; 360 | txt_Duplikationsrate.Enabled = false; 361 | IntGene.MaxValue = Convert.ToInt32(txt_Treibstoff.Text); 362 | MondSim = new MondlandungsSimulation(Convert.ToInt32(txt_Hoehe.Text), Convert.ToInt32(txt_Treibstoff.Text), Convert.ToInt32(txt_Gewicht.Text), tsmi_RaumfahrerGewicht.Checked); 363 | GenSim = new GeneticSimulation(100, Convert.ToInt32(txt_Chromosomlaenge.Text), MondSim, recombinationProvider, selectionProvider); 364 | GenSim.SimulationTurn += OnSimulationTurn; 365 | GenSim.GeneMutationRate = Convert.ToDouble(txt_Mutationsrate.Text); 366 | GenSim.GeneDuplicationRate = Convert.ToDouble(txt_Duplikationsrate.Text); 367 | GenSim.GeneDropRate = Convert.ToDouble(txt_Verlustrate.Text); 368 | } 369 | //automatisierte Simulation bis Erreichen der Delta-Fitness 370 | if (sender == btn_AutoSim) 371 | { 372 | btn_SimAbbrechen.Focus(); 373 | float fitnessGrenze = Convert.ToSingle(txt_Fitness.Text); 374 | float startFitness = GenSim.AverageFitness; 375 | while (fitnessGrenze + startFitness > GenSim.AverageFitness && !simulationAbbrechen) 376 | { 377 | Application.DoEvents(); 378 | GenSim.RunSimulation(); 379 | } 380 | simulationAbbrechen = false; 381 | btn_Simuliere.Enabled = true; 382 | btn_Zuruecksetzen.Enabled = true; 383 | btn_AutoSim.Enabled = true; 384 | } 385 | //einfache Simulation mit angegebener Rundenzahl 386 | else 387 | GenSim.RunSimulation(Convert.ToInt32(txt_Rundenazahl.Text)); 388 | 389 | if (!closingApplication) 390 | { 391 | dgv_Population.Rows.Clear(); 392 | 393 | dgv_Population.Rows.Add(GenSim.PoppulationSize); 394 | for (int i = 0; i < GenSim.PoppulationSize; i++) 395 | { 396 | dgv_Population.Rows[i].Cells[0].Value = GenSim[i].GeneCount.ToString(); 397 | dgv_Population.Rows[i].Cells[1].Value = GenSim[i].ToString(); 398 | dgv_Population.Rows[i].Cells[2].Value = GenSim[i].Fitness.ToString(); 399 | dgv_Population.Rows[i].Tag = GenSim[i]; 400 | } 401 | 402 | zgc_Simulationsgraph.AxisChange(); 403 | zgc_Simulationsgraph.Invalidate(); 404 | Cursor = Cursors.Default; 405 | btn_Simuliere.Enabled = true; 406 | btn_Zuruecksetzen.Enabled = true; 407 | btn_AutoSim.Enabled = true; 408 | } 409 | } 410 | 411 | /// 412 | /// Selektor ausgewählt 413 | /// 414 | /// aufrufendes Objekt 415 | /// EreignisObjekt 416 | private void cmb_Selektor_SelectedIndexChanged(object sender, EventArgs e) 417 | { 418 | switch ((sender as ComboBox).SelectedIndex) 419 | { 420 | case 0: // Alpha 421 | selectionProvider = new AlphaSelector(); 422 | break; 423 | case 1: // Pie Cake 424 | selectionProvider = new PieCakeSelector(); 425 | break; 426 | case 2: // Random 427 | selectionProvider = new RandomSelector(); 428 | break; 429 | default: 430 | selectionProvider = new PieCakeSelector(); 431 | break; 432 | } 433 | } 434 | 435 | /// 436 | /// Rekombinator ausgewählt 437 | /// 438 | /// aufrufendes Objekt 439 | /// EreignisObjekt 440 | private void cmb_Rekombinator_SelectedIndexChanged(object sender, EventArgs e) 441 | { 442 | switch ((sender as ComboBox).SelectedIndex) 443 | { 444 | case 0: // Crossover 445 | recombinationProvider = new AsymmetricCrossoverRecombinator(); 446 | break; 447 | case 1: // Zip 448 | recombinationProvider = new AsymmetricZipRecombinator(); 449 | break; 450 | default: 451 | recombinationProvider = new AsymmetricCrossoverRecombinator(); 452 | break; 453 | } 454 | } 455 | 456 | /// 457 | /// Raumfahrer und Raumschiff in bestimmter Höhe auf den Hintergrund zeichnen 458 | /// 459 | /// Höhe 460 | private void setzeRaumfahrer(int x) 461 | { 462 | setzeRaumschiff(0, 0); 463 | gBuffer.DrawImage(bmpRaumfahrer, x, 590, 25, 50); 464 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 465 | } 466 | 467 | /// 468 | /// Mondlandungsssimulationsrunde durchlaufen 469 | /// 470 | /// aufrufendes Objekt 471 | /// EreignisObjekt 472 | private void OnMondlandungsSimulationTurn(object sender, EventArgs e) 473 | { 474 | MondlandungsSimulationEventArgs mondlandungsArgs = e as MondlandungsSimulationEventArgs; 475 | lbl_AktGeschwindigkeit.Text = Convert.ToString(mondlandungsArgs.Raumschiff.Geschwindigkeit); 476 | lbl_AktHoehe.Text = Convert.ToString(mondlandungsArgs.Raumschiff.Hoehe); 477 | lbl_AktSchub.Text = Convert.ToString(mondlandungsArgs.Schub); 478 | lbl_AktTank.Text = Convert.ToString(mondlandungsArgs.Raumschiff.Treibstoff); 479 | Application.DoEvents(); 480 | if (!closingApplication) 481 | { 482 | float floatHoehe = letzteHoehe; 483 | //Raumschiff fliegt aufwärts 484 | if (mondlandungsArgs.Raumschiff.Geschwindigkeit > 0) 485 | while (floatHoehe < mondlandungsArgs.Raumschiff.Hoehe) 486 | { 487 | floatHoehe += mondlandungsArgs.Raumschiff.Geschwindigkeit / 10.0f; 488 | System.Threading.Thread.Sleep(10); 489 | setzeRaumschiff(Convert.ToInt32(floatHoehe), mondlandungsArgs.Schub); 490 | } 491 | //Raumschiff fliegt abwärts 492 | else 493 | while (floatHoehe > mondlandungsArgs.Raumschiff.Hoehe) 494 | { 495 | floatHoehe += mondlandungsArgs.Raumschiff.Geschwindigkeit / 10.0f; 496 | System.Threading.Thread.Sleep(10); 497 | if (floatHoehe <= 0) 498 | { 499 | setzeRaumschiff(0, mondlandungsArgs.Schub); 500 | } 501 | else 502 | setzeRaumschiff(Convert.ToInt32(floatHoehe), mondlandungsArgs.Schub); 503 | } 504 | letzteHoehe = mondlandungsArgs.Raumschiff.Hoehe; 505 | 506 | 507 | //Raumschiff ist gelandet 508 | if (letzteHoehe <= 0) 509 | { 510 | if ((mondlandungsArgs.Raumschiff.Geschwindigkeit + 10) < 0) 511 | { 512 | bmpRaumschiff = bmpRaumschiffKaputt; 513 | setzeRaumschiff(0, 0); 514 | } 515 | else 516 | { 517 | //wegsehen: ugly code! 518 | //Raumfahrer-Animation 519 | setzeRaumschiff(0, 0); 520 | System.Threading.Thread.Sleep(500); 521 | bmpRaumschiff = bmpRaumschiffLeer; 522 | setzeRaumschiff(0, 0); 523 | System.Threading.Thread.Sleep(500); 524 | setzeRaumfahrer(100); 525 | System.Threading.Thread.Sleep(100); 526 | setzeRaumfahrer(110); 527 | System.Threading.Thread.Sleep(100); 528 | setzeRaumfahrer(120); 529 | System.Threading.Thread.Sleep(100); 530 | setzeRaumfahrer(130); 531 | System.Threading.Thread.Sleep(100); 532 | setzeRaumfahrer(140); 533 | System.Threading.Thread.Sleep(100); 534 | setzeRaumfahrer(150); 535 | System.Threading.Thread.Sleep(100); 536 | setzeRaumfahrer(160); 537 | System.Threading.Thread.Sleep(100); 538 | setzeRaumfahrer(170); 539 | System.Threading.Thread.Sleep(100); 540 | gBuffer.DrawImage(bmpFahne, 200, 560, 37, 75); 541 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 542 | //end of ugly code! 543 | } 544 | } 545 | } 546 | 547 | } 548 | 549 | /// 550 | /// Abspielen einer Mondlandung mit aus Populationsliste gewähltem Chromosom 551 | /// 552 | /// aufrufendes Objekt 553 | /// EreignisObjekt 554 | private void btn_Abspielen_Click(object sender, EventArgs e) 555 | { 556 | if (dgv_Population.SelectedRows.Count > 0) 557 | { 558 | btn_Abspielen.Enabled = false; 559 | Cursor = Cursors.WaitCursor; 560 | bmpRaumschiff = bmpRaumschiffIntakt; 561 | letzteHoehe = Convert.ToInt32(txt_Hoehe.Text); 562 | MondSim.SimulationTurn += OnMondlandungsSimulationTurn; 563 | (dgv_Population.SelectedRows[0].Tag as Chromosome).computeFitness(MondSim); 564 | MondSim.SimulationTurn -= OnMondlandungsSimulationTurn; 565 | Cursor = Cursors.Default; 566 | btn_Abspielen.Enabled = true; 567 | } 568 | } 569 | 570 | /// 571 | /// Simulationsdurchlauf abbrechen 572 | /// 573 | /// aufrufendes Objekt 574 | /// EreignisObjekt 575 | private void btn_SimAbbrechen_Click(object sender, EventArgs e) 576 | { 577 | simulationAbbrechen = true; 578 | } 579 | 580 | /// 581 | /// Gewicht des Raumfahrers zum Raumschiffgewicht hinzuzählen / abziehen 582 | /// 583 | /// aufrufendes Objekt 584 | /// EreignisObjekt 585 | private void gewichtToolStripMenuItem_Click(object sender, EventArgs e) 586 | { 587 | (sender as ToolStripMenuItem).Checked = !(sender as ToolStripMenuItem).Checked; 588 | } 589 | 590 | /// 591 | /// Abbrechen evtl. laufender Simulation beim Beenden des Programms. 592 | /// 593 | /// aufrufendes Objekt 594 | /// EreignisObjekt 595 | private void GUI_FormClosing(object sender, FormClosingEventArgs e) 596 | { 597 | simulationAbbrechen = true; 598 | closingApplication = true; 599 | } 600 | } 601 | 602 | } 603 | 604 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/GeneticAlgorithmsGUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {203AA8CA-AD21-484B-B8DB-7612889C328C} 9 | WinExe 10 | Properties 11 | GeneticAlgorithmsGUI 12 | GeneticAlgorithmsGUI 13 | v3.5 14 | 512 15 | Mond.ico 16 | C34F6D4F9EE9ABFF79FF99EF16A3FCACB7F719CF 17 | GeneticAlgorithmsGUI_1_TemporaryKey.pfx 18 | true 19 | false 20 | false 21 | publish\ 22 | true 23 | Disk 24 | false 25 | Foreground 26 | 7 27 | Days 28 | false 29 | false 30 | true 31 | 4 32 | 1.0.0.%2a 33 | false 34 | true 35 | 36 | 37 | true 38 | full 39 | false 40 | bin\Debug\ 41 | DEBUG;TRACE 42 | prompt 43 | 4 44 | 45 | 46 | pdbonly 47 | true 48 | bin\Release\ 49 | TRACE 50 | prompt 51 | 4 52 | 53 | 54 | 55 | 56 | 3.5 57 | 58 | 59 | 3.5 60 | 61 | 62 | 3.5 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | False 71 | C:\Dokumente und Einstellungen\Jones\Desktop\zedgraph_dll_v515\zedgraph_dll_v515\zedgraph_dll_v5.1.5\ZedGraph.dll 72 | 73 | 74 | 75 | 76 | Form 77 | 78 | 79 | GUI.cs 80 | 81 | 82 | 83 | 84 | GUI.cs 85 | Designer 86 | 87 | 88 | ResXFileCodeGenerator 89 | Resources.Designer.cs 90 | Designer 91 | 92 | 93 | True 94 | Resources.resx 95 | 96 | 97 | SettingsSingleFileGenerator 98 | Settings.Designer.cs 99 | 100 | 101 | True 102 | Settings.settings 103 | True 104 | 105 | 106 | 107 | 108 | {6E92618B-EE42-4427-8924-F5FA675B1735} 109 | Genetic Algorithms 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | False 131 | .NET Framework 2.0 %28x86%29 132 | false 133 | 134 | 135 | False 136 | .NET Framework 3.0 %28x86%29 137 | false 138 | 139 | 140 | False 141 | .NET Framework 3.5 142 | true 143 | 144 | 145 | False 146 | Windows Installer 3.1 147 | true 148 | 149 | 150 | 151 | 158 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Mond.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Mond.ico -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace GeneticAlgorithmsGUI 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// Der Haupteinstiegspunkt für die Anwendung. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new GUI()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("GeneticAlgorithmsGUI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("GeneticAlgorithmsGUI")] 13 | [assembly: AssemblyCopyright("Copyright © 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("1e4a2fca-5886-4bb5-89a6-547e3b5942fc")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18449 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithmsGUI.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GeneticAlgorithmsGUI.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18449 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithmsGUI.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Raumfahrer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Raumfahrer.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Raumschiff.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Raumschiff.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Raumschiff_leer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Raumschiff_leer.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Triebwerk.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Triebwerk.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/Weltraum.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/Weltraum.bmp -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/bin/Debug/ZedGraph.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/bin/Debug/ZedGraph.dll -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI/bin/Debug/de/ZedGraph.resources.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI/bin/Debug/de/ZedGraph.resources.dll -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Engine.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Engine.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Explosion.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Explosion.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Flag.png -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/GUI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Reflection; 9 | using System.Text; 10 | using System.Windows.Forms; 11 | using GeneticAlgorithms; 12 | using GeneticAlgorithms.ExampleClasses; 13 | using GeneticAlgorithms.ExampleClasses.MondLandungs; 14 | using ZedGraph; 15 | 16 | namespace GeneticAlgorithmsGUI_EN 17 | { 18 | public partial class GUI : Form 19 | { 20 | private PointPairList avgFitnessList, avgLengthList, avgVariationList, maxFitnessList, minFitnessList; 21 | private LineItem avgFitnessCurve, avgLengthCurve, avgVariationCurve, maxFitnessCurve, minFitnessCurve; 22 | private GeneticSimulation GenSim = null; 23 | private MondlandungsSimulation MoonSim = null; 24 | private IRecombinationProvider recombinationProvider = null; 25 | private ISelectionProvider selectionProvider = null; 26 | private Bitmap _backBuffer = null; 27 | private Graphics gBuffer = null; 28 | private Bitmap bmpSpace = null; 29 | private Bitmap bmpSpaceshipIntact = null; 30 | private Bitmap bmpSpaceshipBroken = null; 31 | private Bitmap bmpSpaceship = null; 32 | private Bitmap bmpSpaceshipEmpty = null; 33 | private Bitmap bmpEngine = null; 34 | private Bitmap bmpSpaceman = null; 35 | private Bitmap bmpFlag = null; 36 | private bool simulationAbort = false; 37 | private bool closingApplication = false; 38 | 39 | private int finalHeight = 0; 40 | 41 | private int turn = 0; 42 | 43 | /// 44 | /// Constructor - Initialisation of the UI 45 | /// 46 | public GUI() 47 | { 48 | InitializeComponent(); 49 | // Initialisation of the ZedGraph 50 | GraphPane graphPane = zgc_Simulationsgraph.GraphPane; 51 | graphPane.Title.Text = "Population"; 52 | graphPane.XAxis.Title.Text = "Rounding"; 53 | graphPane.XAxis.Scale.Min = 1; 54 | graphPane.XAxis.Scale.MaxAuto = true; 55 | graphPane.YAxis.Title.Text = "Fitness"; 56 | graphPane.YAxis.Scale.Max = 1.0; 57 | graphPane.YAxis.Scale.Min = 0.0; 58 | graphPane.YAxisList.Add("Length"); 59 | graphPane.YAxisList[1].IsVisible = false; 60 | graphPane.YAxisList[1].Scale.MaxAuto = true; 61 | graphPane.YAxisList[1].Scale.Min = 0; 62 | 63 | // Initialisation of the Graph 64 | this.avgFitnessList = new PointPairList(); 65 | this.avgLengthList = new PointPairList(); 66 | this.avgVariationList = new PointPairList(); 67 | this.maxFitnessList = new PointPairList(); 68 | this.minFitnessList = new PointPairList(); 69 | this.avgFitnessCurve = graphPane.AddCurve("Ø Fitness", avgFitnessList, Color.Green, SymbolType.None); 70 | this.avgLengthCurve = graphPane.AddCurve("Ø Length", avgLengthList, Color.Purple, SymbolType.None); 71 | this.minFitnessCurve = graphPane.AddCurve("min. Fitness", minFitnessList, Color.Red, SymbolType.None); 72 | this.maxFitnessCurve = graphPane.AddCurve("max. Fitness", maxFitnessList, Color.Blue, SymbolType.None); 73 | avgLengthCurve.YAxisIndex = 1; 74 | avgFitnessCurve.IsVisible = true; 75 | avgLengthCurve.IsVisible = false; 76 | minFitnessCurve.IsVisible = false; 77 | maxFitnessCurve.IsVisible = false; 78 | 79 | // Initialisation of the ComboBox 80 | cmb_Recombinator.SelectedIndex = 0; 81 | recombinationProvider = new AsymmetricCrossoverRecombinator(); 82 | cmb_Selector.SelectedIndex = 1; 83 | selectionProvider = new PieCakeSelector(); 84 | 85 | // Assembly Creation 86 | Assembly myAssembly = Assembly.GetExecutingAssembly(); 87 | Stream stream = null; 88 | 89 | // Load Pictures from the Assembly Resources 90 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Space.bmp"); 91 | bmpSpace = new Bitmap(stream); 92 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Spaceship.gif"); 93 | bmpSpaceshipIntact = new Bitmap(stream); 94 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Explosion.gif"); 95 | bmpSpaceshipBroken = new Bitmap(stream); 96 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Engine.gif"); 97 | bmpEngine = new Bitmap(stream); 98 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.SpaceshipEmpty.gif"); 99 | bmpSpaceshipEmpty = new Bitmap(stream); 100 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Spaceman.gif"); 101 | bmpSpaceman = new Bitmap(stream); 102 | stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Flag.png"); 103 | bmpFlag = new Bitmap(stream); 104 | 105 | // Initialisation of the DoubleBuffer 106 | _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); 107 | gBuffer = Graphics.FromImage(_backBuffer); 108 | gBuffer.Clear(Color.White); 109 | } 110 | 111 | 112 | /// 113 | /// Paint Event 114 | /// 115 | /// Caller Object 116 | /// Event Object 117 | private void pnl_Animation_Paint(object sender, PaintEventArgs e) 118 | { 119 | drawClearBackground(); 120 | } 121 | 122 | 123 | /// 124 | /// empty Space-/Moonscape draw 125 | /// 126 | private void drawClearBackground() 127 | { 128 | gBuffer.DrawImage(bmpSpace, 1, 1, 300, 650); 129 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 130 | } 131 | 132 | /// 133 | /// Spaceship Image on the Background in place at certain level 134 | /// 135 | /// Height of the Spaceship 136 | /// Given Thrust 137 | public void setSpaceship(int height, int thrust) 138 | { 139 | gBuffer.DrawImage(bmpSpace, 0, 0, 300, 650); 140 | float yPosition = 550.0f/Convert.ToInt64(txt_Height.Text); 141 | yPosition *= height; 142 | yPosition = 550 - yPosition; 143 | int scaledThrust = thrust * 2; 144 | 145 | gBuffer.DrawImage(bmpEngine, 150 - (scaledThrust / 2), yPosition + 65, scaledThrust, scaledThrust); 146 | gBuffer.DrawImage(bmpSpaceship, 100, Convert.ToInt32(yPosition), 100, 100); 147 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 148 | } 149 | 150 | /// 151 | /// End the Application 152 | /// 153 | /// Sender Object 154 | /// Event Object 155 | private void quitToolStripMenuItem_Click(object sender, EventArgs e) 156 | { 157 | Application.Exit(); 158 | } 159 | 160 | /// 161 | /// "About"-ViewDialogBox 162 | /// 163 | /// Sender Object 164 | /// Event Object 165 | private void überToolStripMenuItem_Click(object sender, EventArgs e) 166 | { 167 | MessageBox.Show(this, "Mondlandungs-Simulation mit genetischen Algorithmen\n\nVersion 1.0\n\nEntwickelt von Daniel Baulig, Jonas Heil, Christian Kleemann, Sven Sperner\n\nZedGraph Control von http://www.zedgraph.org unter LGPL", "Über"); 168 | } 169 | 170 | 171 | /// 172 | /// Validation of an input integer parameter 173 | /// 174 | /// Sender Object 175 | /// Event Object 176 | private void txt_Int_Validating(object sender, CancelEventArgs e) 177 | { 178 | try 179 | { 180 | if (Convert.ToInt32((sender as TextBox).Text) < 0) 181 | throw new FormatException(); 182 | } 183 | catch (FormatException exception) 184 | { 185 | MessageBox.Show("No positive integer!"); 186 | (sender as TextBox).SelectAll(); 187 | e.Cancel = true; 188 | } 189 | } 190 | 191 | /// 192 | /// Validation of an input floating-point parameter 193 | /// 194 | /// Sender Object 195 | /// Event Object 196 | private void txt_Float_Validating(object sender, CancelEventArgs e) 197 | { 198 | try 199 | { 200 | if (Convert.ToDouble((sender as TextBox).Text) < 0) 201 | throw new FormatException(); 202 | } 203 | catch (FormatException exception) 204 | { 205 | MessageBox.Show("No positive floating point value!"); 206 | (sender as TextBox).SelectAll(); 207 | e.Cancel = true; 208 | } 209 | } 210 | 211 | /// 212 | /// Hide average fitness of the population 213 | /// 214 | /// Sender Object 215 | /// Event Object 216 | private void chk_AVGFitness_CheckedChanged(object sender, EventArgs e) 217 | { 218 | avgFitnessCurve.IsVisible = (sender as CheckBox).Checked; 219 | zgc_Simulationsgraph.GraphPane.YAxisList[0].IsVisible = chk_AVGFitness.Checked || chk_maxFitness.Checked || chk_minFitness.Checked; 220 | zgc_Simulationsgraph.AxisChange(); 221 | zgc_Simulationsgraph.Invalidate(); 222 | } 223 | 224 | /// 225 | /// Toggle average chromosome length of the population 226 | /// 227 | /// Sender Object 228 | /// Event Object 229 | private void chk_Duration_CheckedChanged(object sender, EventArgs e) 230 | { 231 | avgLengthCurve.IsVisible = (sender as CheckBox).Checked; 232 | zgc_Simulationsgraph.GraphPane.YAxisList[1].IsVisible = avgLengthCurve.IsVisible = (sender as CheckBox).Checked; 233 | zgc_Simulationsgraph.AxisChange(); 234 | zgc_Simulationsgraph.Invalidate(); 235 | } 236 | 237 | /// 238 | /// Hide Minimum fitness of the population 239 | /// 240 | /// Sender Object 241 | /// Event Object 242 | private void chk_minFitness_CheckedChanged(object sender, EventArgs e) 243 | { 244 | minFitnessCurve.IsVisible = (sender as CheckBox).Checked; 245 | zgc_Simulationsgraph.GraphPane.YAxisList[0].IsVisible = chk_AVGFitness.Checked || chk_maxFitness.Checked || chk_minFitness.Checked; 246 | zgc_Simulationsgraph.AxisChange(); 247 | zgc_Simulationsgraph.Invalidate(); 248 | } 249 | 250 | /// 251 | /// Hide Maximum fitness of the population 252 | /// 253 | /// Sender Object 254 | /// Event Object 255 | private void chk_maxFitness_CheckedChanged(object sender, EventArgs e) 256 | { 257 | maxFitnessCurve.IsVisible = (sender as CheckBox).Checked; 258 | zgc_Simulationsgraph.GraphPane.YAxisList[0].IsVisible = chk_AVGFitness.Checked || chk_maxFitness.Checked || chk_minFitness.Checked; 259 | zgc_Simulationsgraph.AxisChange(); 260 | zgc_Simulationsgraph.Invalidate(); 261 | } 262 | 263 | /// 264 | /// Reset the simulation results 265 | /// 266 | /// Sender Object 267 | /// Event Object 268 | private void btn_Zuruecksetzten_Click(object sender, EventArgs e) 269 | { 270 | avgLengthList.Clear(); 271 | avgVariationList.Clear(); 272 | avgFitnessList.Clear(); 273 | maxFitnessList.Clear(); 274 | minFitnessList.Clear(); 275 | GenSim = null; 276 | MoonSim = null; 277 | turn = 0; 278 | cmb_Selector.Enabled = true; 279 | cmb_Recombinator.Enabled = true; 280 | txt_ChromosomeLength.Enabled = true; 281 | txt_Weight.Enabled = true; 282 | txt_Height.Enabled = true; 283 | txt_Engine.Enabled = true; 284 | txt_MutationsRate.Enabled = true; 285 | txt_LossRate.Enabled = true; 286 | txt_DuplicationsRate.Enabled = true; 287 | dgv_Population.Rows.Clear(); 288 | btn_Play.Enabled = false; 289 | lbl_SpeedValue.Text = "0"; 290 | lbl_HeightValue.Text = "0"; 291 | lbl_ThrustValue.Text = "0"; 292 | lbl_TankValue.Text = "0"; 293 | chk_AVGFitness.Checked = true; 294 | chk_maxFitness.Checked = false; 295 | chk_minFitness.Checked = false; 296 | chk_Length.Checked = false; 297 | chk_Live.Checked = false; 298 | zgc_Simulationsgraph.GraphPane.GraphObjList.Clear(); 299 | zgc_Simulationsgraph.AxisChange(); 300 | zgc_Simulationsgraph.Invalidate(); 301 | drawClearBackground(); 302 | GraphPane p = zgc_Simulationsgraph.GraphPane; 303 | zgc_Simulationsgraph.ZoomOutAll(p); 304 | p.YAxisList[1].Scale.Max = 10; 305 | p.YAxisList[1].Scale.MaxAuto = true; 306 | 307 | } 308 | 309 | /// 310 | /// Go through the simulation rounds 311 | /// 312 | /// Sender Object 313 | /// Event Object 314 | private void OnSimulationTurn(object sender, EventArgs e) 315 | { 316 | turn ++; 317 | if (simulationAbort) 318 | { 319 | GenSim.AbortSimulation(); 320 | simulationAbort = false; 321 | } 322 | this.avgFitnessList.Add(turn, GenSim.AverageFitness); 323 | this.avgLengthList.Add(turn, GenSim.AverageChromosomeLength); 324 | if (zgc_Simulationsgraph.GraphPane.YAxisList[1].Scale.Max < GenSim.AverageChromosomeLength) 325 | zgc_Simulationsgraph.GraphPane.YAxisList[1].Scale.Max = GenSim.AverageChromosomeLength + 1; 326 | this.maxFitnessList.Add(turn, GenSim.MostSuccessfullIndividual.Fitness); 327 | this.minFitnessList.Add(turn, GenSim.LeasSuccessfullIndividual.Fitness); 328 | if (turn % 10 == 0 && chk_Live.Checked) 329 | { 330 | zgc_Simulationsgraph.AxisChange(); 331 | zgc_Simulationsgraph.Invalidate(); 332 | } 333 | Application.DoEvents(); 334 | } 335 | 336 | /// 337 | /// Simulation start 338 | /// 339 | /// Sender Object 340 | /// Event Object 341 | private void btn_Simuliere_Click(object sender, EventArgs e) 342 | { 343 | Cursor = Cursors.WaitCursor; 344 | btn_Simulate.Enabled = false; 345 | btn_Reset.Enabled = false; 346 | btn_AutoSim.Enabled = false; 347 | btn_SimAbort.Focus(); 348 | //erster Durchlauf der Simulation 349 | if (GenSim == null) 350 | { 351 | btn_Play.Enabled = true; 352 | txt_ChromosomeLength.Enabled = false; 353 | cmb_Recombinator.Enabled = false; 354 | cmb_Selector.Enabled = false; 355 | txt_Weight.Enabled = false; 356 | txt_Height.Enabled = false; 357 | txt_Engine.Enabled = false; 358 | txt_MutationsRate.Enabled = false; 359 | txt_LossRate.Enabled = false; 360 | txt_DuplicationsRate.Enabled = false; 361 | IntGene.MaxValue = Convert.ToInt32(txt_Engine.Text); 362 | MoonSim = new MondlandungsSimulation(Convert.ToInt32(txt_Height.Text), Convert.ToInt32(txt_Engine.Text), Convert.ToInt32(txt_Weight.Text), tsmi_SpacemanHeight.Checked); 363 | GenSim = new GeneticSimulation(100, Convert.ToInt32(txt_ChromosomeLength.Text), MoonSim, recombinationProvider, selectionProvider); 364 | GenSim.SimulationTurn += OnSimulationTurn; 365 | GenSim.GeneMutationRate = Convert.ToDouble(txt_MutationsRate.Text); 366 | GenSim.GeneDuplicationRate = Convert.ToDouble(txt_DuplicationsRate.Text); 367 | GenSim.GeneDropRate = Convert.ToDouble(txt_LossRate.Text); 368 | } 369 | //automatisierte Simulation bis Erreichen der Delta-Fitness 370 | if (sender == btn_AutoSim) 371 | { 372 | btn_SimAbort.Focus(); 373 | float fitnessGrenze = Convert.ToSingle(txt_Fitness.Text); 374 | float startFitness = GenSim.AverageFitness; 375 | while (fitnessGrenze + startFitness > GenSim.AverageFitness && !simulationAbort) 376 | { 377 | Application.DoEvents(); 378 | GenSim.RunSimulation(); 379 | } 380 | simulationAbort = false; 381 | btn_Simulate.Enabled = true; 382 | btn_Reset.Enabled = true; 383 | btn_AutoSim.Enabled = true; 384 | } 385 | //einfache Simulation mit angegebener Rundenzahl 386 | else 387 | GenSim.RunSimulation(Convert.ToInt32(txt_RoundNumber.Text)); 388 | 389 | if (!closingApplication) 390 | { 391 | dgv_Population.Rows.Clear(); 392 | 393 | dgv_Population.Rows.Add(GenSim.PoppulationSize); 394 | for (int i = 0; i < GenSim.PoppulationSize; i++) 395 | { 396 | dgv_Population.Rows[i].Cells[0].Value = GenSim[i].GeneCount.ToString(); 397 | dgv_Population.Rows[i].Cells[1].Value = GenSim[i].ToString(); 398 | dgv_Population.Rows[i].Cells[2].Value = GenSim[i].Fitness.ToString(); 399 | dgv_Population.Rows[i].Tag = GenSim[i]; 400 | } 401 | 402 | zgc_Simulationsgraph.AxisChange(); 403 | zgc_Simulationsgraph.Invalidate(); 404 | Cursor = Cursors.Default; 405 | btn_Simulate.Enabled = true; 406 | btn_Reset.Enabled = true; 407 | btn_AutoSim.Enabled = true; 408 | } 409 | } 410 | 411 | /// 412 | /// Selected selector 413 | /// 414 | /// Sender Object 415 | /// Event Object 416 | private void cmb_Selektor_SelectedIndexChanged(object sender, EventArgs e) 417 | { 418 | switch ((sender as ComboBox).SelectedIndex) 419 | { 420 | case 0: // Alpha 421 | selectionProvider = new AlphaSelector(); 422 | break; 423 | case 1: // Pie Cake 424 | selectionProvider = new PieCakeSelector(); 425 | break; 426 | case 2: // Random 427 | selectionProvider = new RandomSelector(); 428 | break; 429 | default: 430 | selectionProvider = new PieCakeSelector(); 431 | break; 432 | } 433 | } 434 | 435 | /// 436 | /// Selected recombinator 437 | /// 438 | /// Sender Object 439 | /// Event Object 440 | private void cmb_Rekombinator_SelectedIndexChanged(object sender, EventArgs e) 441 | { 442 | switch ((sender as ComboBox).SelectedIndex) 443 | { 444 | case 0: // Crossover 445 | recombinationProvider = new AsymmetricCrossoverRecombinator(); 446 | break; 447 | case 1: // Zip 448 | recombinationProvider = new AsymmetricZipRecombinator(); 449 | break; 450 | default: 451 | recombinationProvider = new AsymmetricCrossoverRecombinator(); 452 | break; 453 | } 454 | } 455 | 456 | /// 457 | /// Draw spaceman and spaceship at a certain level on the background 458 | /// 459 | /// Height 460 | private void setSpaceman(int x) 461 | { 462 | setSpaceship(0, 0); 463 | gBuffer.DrawImage(bmpSpaceman, x, 590, 25, 50); 464 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 465 | } 466 | 467 | /// 468 | /// Moon touchdown simulations round through 469 | /// 470 | /// Sender Object 471 | /// Event Object 472 | private void OnMondlandungsSimulationTurn(object sender, EventArgs e) 473 | { 474 | MondlandungsSimulationEventArgs mondlandungsArgs = e as MondlandungsSimulationEventArgs; 475 | lbl_SpeedValue.Text = Convert.ToString(mondlandungsArgs.Raumschiff.Geschwindigkeit); 476 | lbl_HeightValue.Text = Convert.ToString(mondlandungsArgs.Raumschiff.Hoehe); 477 | lbl_ThrustValue.Text = Convert.ToString(mondlandungsArgs.Schub); 478 | lbl_TankValue.Text = Convert.ToString(mondlandungsArgs.Raumschiff.Treibstoff); 479 | Application.DoEvents(); 480 | if (!closingApplication) 481 | { 482 | float floatHoehe = finalHeight; 483 | //Raumschiff fliegt aufwärts 484 | if (mondlandungsArgs.Raumschiff.Geschwindigkeit > 0) 485 | while (floatHoehe < mondlandungsArgs.Raumschiff.Hoehe) 486 | { 487 | floatHoehe += mondlandungsArgs.Raumschiff.Geschwindigkeit / 10.0f; 488 | System.Threading.Thread.Sleep(10); 489 | setSpaceship(Convert.ToInt32(floatHoehe), mondlandungsArgs.Schub); 490 | } 491 | //Raumschiff fliegt abwärts 492 | else 493 | while (floatHoehe > mondlandungsArgs.Raumschiff.Hoehe) 494 | { 495 | floatHoehe += mondlandungsArgs.Raumschiff.Geschwindigkeit / 10.0f; 496 | System.Threading.Thread.Sleep(10); 497 | if (floatHoehe <= 0) 498 | { 499 | setSpaceship(0, mondlandungsArgs.Schub); 500 | } 501 | else 502 | setSpaceship(Convert.ToInt32(floatHoehe), mondlandungsArgs.Schub); 503 | } 504 | finalHeight = mondlandungsArgs.Raumschiff.Hoehe; 505 | 506 | 507 | //Raumschiff ist gelandet 508 | if (finalHeight <= 0) 509 | { 510 | if ((mondlandungsArgs.Raumschiff.Geschwindigkeit + 10) < 0) 511 | { 512 | bmpSpaceship = bmpSpaceshipBroken; 513 | setSpaceship(0, 0); 514 | } 515 | else 516 | { 517 | //wegsehen: ugly code! 518 | //Raumfahrer-Animation 519 | setSpaceship(0, 0); 520 | System.Threading.Thread.Sleep(500); 521 | bmpSpaceship = bmpSpaceshipEmpty; 522 | setSpaceship(0, 0); 523 | System.Threading.Thread.Sleep(500); 524 | setSpaceman(100); 525 | System.Threading.Thread.Sleep(100); 526 | setSpaceman(110); 527 | System.Threading.Thread.Sleep(100); 528 | setSpaceman(120); 529 | System.Threading.Thread.Sleep(100); 530 | setSpaceman(130); 531 | System.Threading.Thread.Sleep(100); 532 | setSpaceman(140); 533 | System.Threading.Thread.Sleep(100); 534 | setSpaceman(150); 535 | System.Threading.Thread.Sleep(100); 536 | setSpaceman(160); 537 | System.Threading.Thread.Sleep(100); 538 | setSpaceman(170); 539 | System.Threading.Thread.Sleep(100); 540 | gBuffer.DrawImage(bmpFlag, 200, 560, 37, 75); 541 | pnl_Animation.CreateGraphics().DrawImageUnscaled(_backBuffer, 0, 0); 542 | //end of ugly code! 543 | } 544 | } 545 | } 546 | 547 | } 548 | 549 | /// 550 | /// Playing a moon landing with the selected population list of chromosomes 551 | /// 552 | /// Sender Object 553 | /// Event Object 554 | private void btn_Abspielen_Click(object sender, EventArgs e) 555 | { 556 | if (dgv_Population.SelectedRows.Count > 0) 557 | { 558 | btn_Play.Enabled = false; 559 | Cursor = Cursors.WaitCursor; 560 | bmpSpaceship = bmpSpaceshipIntact; 561 | finalHeight = Convert.ToInt32(txt_Height.Text); 562 | MoonSim.SimulationTurn += OnMondlandungsSimulationTurn; 563 | (dgv_Population.SelectedRows[0].Tag as Chromosome).computeFitness(MoonSim); 564 | MoonSim.SimulationTurn -= OnMondlandungsSimulationTurn; 565 | Cursor = Cursors.Default; 566 | btn_Play.Enabled = true; 567 | } 568 | } 569 | 570 | /// 571 | /// Abort simulation running 572 | /// 573 | /// Sender Object 574 | /// Event Object 575 | private void btn_SimAbbrechen_Click(object sender, EventArgs e) 576 | { 577 | simulationAbort = true; 578 | } 579 | 580 | /// 581 | /// Weight of the space traveler should include / remove the spacecraft weight 582 | /// 583 | /// Sender Object 584 | /// Event Object 585 | private void gewichtToolStripMenuItem_Click(object sender, EventArgs e) 586 | { 587 | (sender as ToolStripMenuItem).Checked = !(sender as ToolStripMenuItem).Checked; 588 | } 589 | 590 | /// 591 | /// Cancel any simulation is running when you exit the program. 592 | /// 593 | /// Sender Object 594 | /// Event Object 595 | private void GUI_FormClosing(object sender, FormClosingEventArgs e) 596 | { 597 | simulationAbort = true; 598 | closingApplication = true; 599 | } 600 | } 601 | 602 | } 603 | 604 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/GeneticAlgorithmsGUI_EN.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {D718E6ED-A75F-4CA6-BA40-7323EBAE5460} 9 | WinExe 10 | Properties 11 | GeneticAlgorithmsGUI_EN 12 | GeneticAlgorithmsGUI 13 | v3.5 14 | 512 15 | Moon.ico 16 | C34F6D4F9EE9ABFF79FF99EF16A3FCACB7F719CF 17 | GeneticAlgorithmsGUI_1_TemporaryKey.pfx 18 | true 19 | false 20 | false 21 | 22 | 23 | 3.5 24 | 25 | publish\ 26 | true 27 | Disk 28 | false 29 | Foreground 30 | 7 31 | Days 32 | false 33 | false 34 | true 35 | 4 36 | 1.0.0.%2a 37 | false 38 | true 39 | 40 | 41 | true 42 | full 43 | false 44 | bin\Debug\ 45 | DEBUG;TRACE 46 | prompt 47 | 4 48 | AllRules.ruleset 49 | 50 | 51 | pdbonly 52 | true 53 | bin\Release\ 54 | TRACE 55 | prompt 56 | 4 57 | AllRules.ruleset 58 | 59 | 60 | 61 | 62 | 3.5 63 | 64 | 65 | 3.5 66 | 67 | 68 | 3.5 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | False 77 | C:\Dokumente und Einstellungen\Jones\Desktop\zedgraph_dll_v515\zedgraph_dll_v515\zedgraph_dll_v5.1.5\ZedGraph.dll 78 | 79 | 80 | 81 | 82 | Form 83 | 84 | 85 | GUI.cs 86 | 87 | 88 | 89 | 90 | GUI.cs 91 | Designer 92 | 93 | 94 | ResXFileCodeGenerator 95 | Resources.Designer.cs 96 | Designer 97 | 98 | 99 | True 100 | Resources.resx 101 | True 102 | 103 | 104 | SettingsSingleFileGenerator 105 | Settings.Designer.cs 106 | 107 | 108 | True 109 | Settings.settings 110 | True 111 | 112 | 113 | 114 | 115 | {6E92618B-EE42-4427-8924-F5FA675B1735} 116 | Genetic Algorithms 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | False 138 | .NET Framework 3.5 SP1 Client Profile 139 | false 140 | 141 | 142 | False 143 | .NET Framework 2.0 %28x86%29 144 | false 145 | 146 | 147 | False 148 | .NET Framework 3.0 %28x86%29 149 | false 150 | 151 | 152 | False 153 | .NET Framework 3.5 154 | true 155 | 156 | 157 | False 158 | .NET Framework 3.5 SP1 159 | false 160 | 161 | 162 | False 163 | Windows Installer 3.1 164 | true 165 | 166 | 167 | 168 | 175 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Moon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Moon.ico -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace GeneticAlgorithmsGUI_EN 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// Der Haupteinstiegspunkt für die Anwendung. 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new GUI()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Allgemeine Informationen über eine Assembly werden über die folgenden 6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, 7 | // die mit einer Assembly verknüpft sind. 8 | [assembly: AssemblyTitle("GeneticAlgorithmsGUI")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("GeneticAlgorithmsGUI")] 13 | [assembly: AssemblyCopyright("Copyright © 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar 18 | // für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von 19 | // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. 20 | [assembly: ComVisible(false)] 21 | 22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird 23 | [assembly: Guid("1e4a2fca-5886-4bb5-89a6-547e3b5942fc")] 24 | 25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 26 | // 27 | // Hauptversion 28 | // Nebenversion 29 | // Buildnummer 30 | // Revision 31 | // 32 | // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern 33 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18449 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithmsGUI_EN.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GeneticAlgorithmsGUI_EN.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18449 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace GeneticAlgorithmsGUI_EN.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Space.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Space.bmp -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Spaceman.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Spaceman.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/Spaceship.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/Spaceship.gif -------------------------------------------------------------------------------- /GeneticAlgorithmsGUI_EN/SpaceshipEmpty.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBaulig/Genetic-Algorithms/5e00adc14f50b56f04f6e5e74d558b1c0073d7a0/GeneticAlgorithmsGUI_EN/SpaceshipEmpty.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # _Genetic Algorithms_ 2 | This repository includes 4 C# projects in a single solution 3 | 4 | 1. Genetic Algorithms Library (GAL) 5 | 2. Unit-Tests for GAL 6 | 3. GUI application built on GAL (DE & EN) 7 | 8 | ## Build & Run 9 | To run the GUI application simply build the solution and run the executable artifact. 10 | 11 | 12 | 13 | If you like this software project please consider flattring it: 14 | 15 | [![Flattr this](http://api.flattr.com/button/button-compact-static-100x17.png)](https://flattr.com/thing/42363/Lunar-Lander-Genetic-Algorithms-in-C) 16 | --------------------------------------------------------------------------------