public GeneticSimulation(int populationSize, int defaultGeneCount, IFitnessFunctionProvider fitnessComputer, IRecombinationProvider recombinator, ISelectionProvider maleSelector, ISelectionProvider femaleSelector)
        {
            this.fitnessComputer         = fitnessComputer;
            this.recombinator            = recombinator;
            this.maleSelector            = maleSelector;
            this.femaleSelector          = femaleSelector;
            this.populationSize          = populationSize;
            this.defaultChromosomeLength = defaultGeneCount;

            this.geneMutationRate    = 0.01d;
            this.geneDuplicationRate = 0.0d;
            this.geneDropRate        = 0.0d;

            this.randomizer = new Random();

            this.ResetSimulation();
        }
Beispiel #2
0
        /// <summary>
        /// Selected recombinator
        /// </summary>
        /// <param name="sender">Sender Object</param>
        /// <param name="e">Event Object</param>
        private void cmb_Rekombinator_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch ((sender as ComboBox).SelectedIndex)
            {
            case 0:     // Crossover
                recombinationProvider = new AsymmetricCrossoverRecombinator();
                break;

            case 1:     // Zip
                recombinationProvider = new AsymmetricZipRecombinator();
                break;

            default:
                recombinationProvider = new AsymmetricCrossoverRecombinator();
                break;
            }
        }
 public GeneticSimulation(int populationSize, int defaultGeneCount, IFitnessFunctionProvider fitnessComputer, IRecombinationProvider recombinator, ISelectionProvider selector) :
     this(populationSize, defaultGeneCount, fitnessComputer, recombinator, selector, selector)
 {
 }
Beispiel #4
0
        /// <summary>
        /// Konstruktor - Initialisierung der Bedienoberfläche
        /// </summary>
        public GUI()
        {
            InitializeComponent();
            //Initialisireung des ZedGraph
            GraphPane graphPane = zgc_Simulationsgraph.GraphPane;
            graphPane.Title.Text = "Population";
            graphPane.XAxis.Title.Text = "Runden";
            graphPane.XAxis.Scale.Min = 1;
            graphPane.XAxis.Scale.MaxAuto = true;
            graphPane.YAxis.Title.Text = "Fitness";
            graphPane.YAxis.Scale.Max = 1.0;
            graphPane.YAxis.Scale.Min = 0.0;
            graphPane.YAxisList.Add("Länge");
            graphPane.YAxisList[1].IsVisible = false;
            graphPane.YAxisList[1].Scale.MaxAuto = true;
            graphPane.YAxisList[1].Scale.Min = 0;

            //Initialisireung der Graphen
            this.avgFitnessList = new PointPairList();
            this.avgLengthList = new PointPairList();
            this.avgVariationList = new PointPairList();
            this.maxFitnessList = new PointPairList();
            this.minFitnessList = new PointPairList();
            this.avgFitnessCurve = graphPane.AddCurve("Ø Fitness", avgFitnessList, Color.Green, SymbolType.None);
            this.avgLengthCurve = graphPane.AddCurve("Ø Länge", avgLengthList, Color.Purple, SymbolType.None);
            this.minFitnessCurve = graphPane.AddCurve("min. Fitness", minFitnessList, Color.Red, SymbolType.None);
            this.maxFitnessCurve = graphPane.AddCurve("max. Fitness", maxFitnessList, Color.Blue, SymbolType.None);
            avgLengthCurve.YAxisIndex = 1;
            avgFitnessCurve.IsVisible = true;
            avgLengthCurve.IsVisible = false;
            minFitnessCurve.IsVisible = false;
            maxFitnessCurve.IsVisible = false;

            //Initialisireung der ComboBoxen
            cmb_Rekombinator.SelectedIndex = 0;
            recombinationProvider = new AsymmetricCrossoverRecombinator();
            cmb_Selektor.SelectedIndex = 1;
            selectionProvider = new PieCakeSelector();

            //Assembly erzeugen
            Assembly myAssembly = Assembly.GetExecutingAssembly();
            Stream stream = null;

            // Bilder aus den Ressourcen der Assembly holen
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Weltraum.bmp");
            bmpWeltraum = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumschiff.gif");
            bmpRaumschiffIntakt = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Explosion.gif");
            bmpRaumschiffKaputt = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Triebwerk.gif");
            bmpTriebwerk = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumschiff_leer.gif");
            bmpRaumschiffLeer = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumfahrer.gif");
            bmpRaumfahrer = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Fahne.png");
            bmpFahne = new Bitmap(stream);

            //Initialisierung des DoubleBuffer
            _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            gBuffer = Graphics.FromImage(_backBuffer);
            gBuffer.Clear(Color.White);
        }
Beispiel #5
0
 /// <summary>
 /// Rekombinator ausgewählt
 /// </summary>
 /// <param name="sender">aufrufendes Objekt</param>
 /// <param name="e">EreignisObjekt</param>
 private void cmb_Rekombinator_SelectedIndexChanged(object sender, EventArgs e)
 {
     switch ((sender as ComboBox).SelectedIndex)
     {
         case 0: // Crossover
             recombinationProvider = new AsymmetricCrossoverRecombinator();
             break;
         case 1: // Zip
             recombinationProvider = new AsymmetricZipRecombinator();
             break;
         default:
             recombinationProvider = new AsymmetricCrossoverRecombinator();
             break;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Constructor - Initialisation of the UI
        /// </summary>
        public GUI()
        {
            InitializeComponent();
            // Initialisation of the ZedGraph
            GraphPane graphPane = zgc_Simulationsgraph.GraphPane;
            graphPane.Title.Text = "Population";
            graphPane.XAxis.Title.Text = "Rounding";
            graphPane.XAxis.Scale.Min = 1;
            graphPane.XAxis.Scale.MaxAuto = true;
            graphPane.YAxis.Title.Text = "Fitness";
            graphPane.YAxis.Scale.Max = 1.0;
            graphPane.YAxis.Scale.Min = 0.0;
            graphPane.YAxisList.Add("Length");
            graphPane.YAxisList[1].IsVisible = false;
            graphPane.YAxisList[1].Scale.MaxAuto = true;
            graphPane.YAxisList[1].Scale.Min = 0;

            // Initialisation of the Graph
            this.avgFitnessList = new PointPairList();
            this.avgLengthList = new PointPairList();
            this.avgVariationList = new PointPairList();
            this.maxFitnessList = new PointPairList();
            this.minFitnessList = new PointPairList();
            this.avgFitnessCurve = graphPane.AddCurve("Ø Fitness", avgFitnessList, Color.Green, SymbolType.None);
            this.avgLengthCurve = graphPane.AddCurve("Ø Length", avgLengthList, Color.Purple, SymbolType.None);
            this.minFitnessCurve = graphPane.AddCurve("min. Fitness", minFitnessList, Color.Red, SymbolType.None);
            this.maxFitnessCurve = graphPane.AddCurve("max. Fitness", maxFitnessList, Color.Blue, SymbolType.None);
            avgLengthCurve.YAxisIndex = 1;
            avgFitnessCurve.IsVisible = true;
            avgLengthCurve.IsVisible = false;
            minFitnessCurve.IsVisible = false;
            maxFitnessCurve.IsVisible = false;

            // Initialisation of the ComboBox
            cmb_Recombinator.SelectedIndex = 0;
            recombinationProvider = new AsymmetricCrossoverRecombinator();
            cmb_Selector.SelectedIndex = 1;
            selectionProvider = new PieCakeSelector();

            // Assembly Creation
            Assembly myAssembly = Assembly.GetExecutingAssembly();
            Stream stream = null;

            // Load Pictures from the Assembly Resources
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Space.bmp");
            bmpSpace = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Spaceship.gif");
            bmpSpaceshipIntact = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Explosion.gif");
            bmpSpaceshipBroken = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Engine.gif");
            bmpEngine = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.SpaceshipEmpty.gif");
            bmpSpaceshipEmpty = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Spaceman.gif");
            bmpSpaceman = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Flag.png");
            bmpFlag = new Bitmap(stream);

            // Initialisation of the DoubleBuffer
            _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            gBuffer = Graphics.FromImage(_backBuffer);
            gBuffer.Clear(Color.White);
        }
Beispiel #7
0
        /// <summary>
        /// Constructor - Initialisation of the UI
        /// </summary>
        public GUI()
        {
            InitializeComponent();
            // Initialisation of the ZedGraph
            GraphPane graphPane = zgc_Simulationsgraph.GraphPane;

            graphPane.Title.Text          = "Population";
            graphPane.XAxis.Title.Text    = "Rounding";
            graphPane.XAxis.Scale.Min     = 1;
            graphPane.XAxis.Scale.MaxAuto = true;
            graphPane.YAxis.Title.Text    = "Fitness";
            graphPane.YAxis.Scale.Max     = 1.0;
            graphPane.YAxis.Scale.Min     = 0.0;
            graphPane.YAxisList.Add("Length");
            graphPane.YAxisList[1].IsVisible     = false;
            graphPane.YAxisList[1].Scale.MaxAuto = true;
            graphPane.YAxisList[1].Scale.Min     = 0;

            // Initialisation of the Graph
            this.avgFitnessList       = new PointPairList();
            this.avgLengthList        = new PointPairList();
            this.avgVariationList     = new PointPairList();
            this.maxFitnessList       = new PointPairList();
            this.minFitnessList       = new PointPairList();
            this.avgFitnessCurve      = graphPane.AddCurve("Ø Fitness", avgFitnessList, Color.Green, SymbolType.None);
            this.avgLengthCurve       = graphPane.AddCurve("Ø Length", avgLengthList, Color.Purple, SymbolType.None);
            this.minFitnessCurve      = graphPane.AddCurve("min. Fitness", minFitnessList, Color.Red, SymbolType.None);
            this.maxFitnessCurve      = graphPane.AddCurve("max. Fitness", maxFitnessList, Color.Blue, SymbolType.None);
            avgLengthCurve.YAxisIndex = 1;
            avgFitnessCurve.IsVisible = true;
            avgLengthCurve.IsVisible  = false;
            minFitnessCurve.IsVisible = false;
            maxFitnessCurve.IsVisible = false;

            // Initialisation of the ComboBox
            cmb_Recombinator.SelectedIndex = 0;
            recombinationProvider          = new AsymmetricCrossoverRecombinator();
            cmb_Selector.SelectedIndex     = 1;
            selectionProvider = new PieCakeSelector();

            // Assembly Creation
            Assembly myAssembly = Assembly.GetExecutingAssembly();
            Stream   stream     = null;

            // Load Pictures from the Assembly Resources
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Space.bmp");
            bmpSpace           = new Bitmap(stream);
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Spaceship.gif");
            bmpSpaceshipIntact = new Bitmap(stream);
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Explosion.gif");
            bmpSpaceshipBroken = new Bitmap(stream);
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Engine.gif");
            bmpEngine          = new Bitmap(stream);
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.SpaceshipEmpty.gif");
            bmpSpaceshipEmpty  = new Bitmap(stream);
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Spaceman.gif");
            bmpSpaceman        = new Bitmap(stream);
            stream             = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI_EN.Flag.png");
            bmpFlag            = new Bitmap(stream);

            // Initialisation of the DoubleBuffer
            _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            gBuffer     = Graphics.FromImage(_backBuffer);
            gBuffer.Clear(Color.White);
        }
 // Rekombiniert dieses Chromosom mit einem durch partner spezifizierten anderen Chromosom
 // Das IRecombinatorProvider Interface recombinator stellt dafür die Methode zur Verfügung.
 public Chromosome <Gene> Recombine(Chromosome <Gene> partner, IRecombinationProvider recombinator)
 {
     return(new Chromosome <Gene>(recombinator.Recombine(this.genes, partner.genes)));
 }
Beispiel #9
0
        /// <summary>
        /// Konstruktor - Initialisierung der Bedienoberfläche
        /// </summary>
        public GUI()
        {
            InitializeComponent();
            //Initialisireung des ZedGraph
            GraphPane graphPane = zgc_Simulationsgraph.GraphPane;

            graphPane.Title.Text          = "Population";
            graphPane.XAxis.Title.Text    = "Runden";
            graphPane.XAxis.Scale.Min     = 1;
            graphPane.XAxis.Scale.MaxAuto = true;
            graphPane.YAxis.Title.Text    = "Fitness";
            graphPane.YAxis.Scale.Max     = 1.0;
            graphPane.YAxis.Scale.Min     = 0.0;
            graphPane.YAxisList.Add("Länge");
            graphPane.YAxisList[1].IsVisible     = false;
            graphPane.YAxisList[1].Scale.MaxAuto = true;
            graphPane.YAxisList[1].Scale.Min     = 0;

            //Initialisireung der Graphen
            this.avgFitnessList       = new PointPairList();
            this.avgLengthList        = new PointPairList();
            this.avgVariationList     = new PointPairList();
            this.maxFitnessList       = new PointPairList();
            this.minFitnessList       = new PointPairList();
            this.avgFitnessCurve      = graphPane.AddCurve("Ø Fitness", avgFitnessList, Color.Green, SymbolType.None);
            this.avgLengthCurve       = graphPane.AddCurve("Ø Länge", avgLengthList, Color.Purple, SymbolType.None);
            this.minFitnessCurve      = graphPane.AddCurve("min. Fitness", minFitnessList, Color.Red, SymbolType.None);
            this.maxFitnessCurve      = graphPane.AddCurve("max. Fitness", maxFitnessList, Color.Blue, SymbolType.None);
            avgLengthCurve.YAxisIndex = 1;
            avgFitnessCurve.IsVisible = true;
            avgLengthCurve.IsVisible  = false;
            minFitnessCurve.IsVisible = false;
            maxFitnessCurve.IsVisible = false;

            //Initialisireung der ComboBoxen
            cmb_Rekombinator.SelectedIndex = 0;
            recombinationProvider          = new AsymmetricCrossoverRecombinator();
            cmb_Selektor.SelectedIndex     = 1;
            selectionProvider = new PieCakeSelector();

            //Assembly erzeugen
            Assembly myAssembly = Assembly.GetExecutingAssembly();
            Stream   stream     = null;

            // Bilder aus den Ressourcen der Assembly holen
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Weltraum.bmp");
            bmpWeltraum         = new Bitmap(stream);
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumschiff.gif");
            bmpRaumschiffIntakt = new Bitmap(stream);
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Explosion.gif");
            bmpRaumschiffKaputt = new Bitmap(stream);
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Triebwerk.gif");
            bmpTriebwerk        = new Bitmap(stream);
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumschiff_leer.gif");
            bmpRaumschiffLeer   = new Bitmap(stream);
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Raumfahrer.gif");
            bmpRaumfahrer       = new Bitmap(stream);
            stream              = myAssembly.GetManifestResourceStream("GeneticAlgorithmsGUI.Fahne.png");
            bmpFahne            = new Bitmap(stream);

            //Initialisierung des DoubleBuffer
            _backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            gBuffer     = Graphics.FromImage(_backBuffer);
            gBuffer.Clear(Color.White);
        }