public ElitismOpr(OptimisationTemplate Template, GAParameters gaParameters, Population.Population parentPopulation, Population.Population childPopulation)
 {
     this.Template         = Template;
     this.gaParameters     = gaParameters;
     this.parentPopulation = parentPopulation;
     this.childPopulation  = childPopulation;
 }
示例#2
0
 public GeneticAlgorithmTravelSalesman(CitiesCollection cities, GAParameters gap)
     : this(cities)
 {
     //SetParameters(gap);
     _gap     = gap;
     tmrTimer = new System.Timers.Timer(10);                                      //инициализация таймера
     //tmrTimer.Elapsed += new ElapsedEventHandler(tmrTimer_Elapsed); //подписка на событие таймера "Elapsed"
 }
示例#3
0
 /// <summary>
 /// Создать новое поколение
 /// </summary>
 /// <param name="gap">Параметры генетического алгоритма</param>
 /// <param name="cities">Города для расчёта</param>
 public Generation(GAParameters gap, CitiesCollection cities)
 {
     _gap      = gap;
     _cities   = cities;
     _liAgents = new List <Agent>();
     for (int i = 0; i < _gap.Population; i++)
     {
         _liAgents.Add(new Agent(_cities));
     }
 }
示例#4
0
    public void Awake()
    {
        // Do all the GetComponent calls upfront - Justin said it's much more efficient!
        penManagers       = new List <GameObject>(GameObject.FindGameObjectsWithTag("PenManager"));
        penManagerScripts = new List <ManagePen>();
        frogs             = new List <GameObject>();
        frogPlayerInfo    = new List <PlayerInfo>();
        neuralNetSteering = new List <NeuralNetSteering>();

        // Get references to the frogs and some of their components
        for (int i = 0; i < penManagers.Count; i++)
        {
            penManagerScripts.Add(penManagers[i].GetComponent <ManagePen>());
            GameObject frog = penManagers[i].GetComponent <ManagePen>().frog;
            frogs.Add(frog);
            frogPlayerInfo.Add(frog.GetComponent <PlayerInfo>());
            neuralNetSteering.Add(frog.GetComponent <NeuralNetSteering>());
        }

        // Set up directory for saving neural nets, etc
        saveDataPath = "SaveData/" + System.DateTime.Now.ToString("yyMMddHHmmss");
        Directory.CreateDirectory(saveDataPath);

        if (LoadPath != "")
        {
            // Load the population from a saved file
            LoadPopulation();
            populationSize = population.Count;
        }
        else
        {
            // Create a new population from scratch
            currentParams  = parameters[parameterIndexToUse];
            population     = new List <NeuralNet>();
            populationSize = currentParams.NumberOfBatches * FrogsOnScreen;

            for (int i = 0; i < populationSize; i++)
            {
                population.Add(new NeuralNet(currentParams.neuralNetSettings.NumFlyPositions,
                                             currentParams.neuralNetSettings.NumSnakePositions,
                                             currentParams.neuralNetSettings.NumObstaclePositions,
                                             currentParams.neuralNetSettings.FeedObstacleInfo,
                                             currentParams.neuralNetSettings.FeedOwnVelocity,
                                             currentParams.neuralNetSettings.FeedLakePosition,
                                             currentParams.neuralNetSettings.FeedWaterLevel,
                                             currentParams.neuralNetSettings.HiddenNeurons,
                                             currentParams.neuralNetSettings.inputTransformation,
                                             currentParams.neuralNetSettings.inputSmoothingSegments));
            }
        }

        // Create snakes if need be
        ResetSnakes();
    }
示例#5
0
 public SingleObjectivePopulation(OptimisationTemplate Template, GAParameters gaParameters, int populationSize, bool empty)
     : base(Template, gaParameters, populationSize)
 {
     //initialising population chromosomes
     chromosomes = new SingleObjectiveChromosome[populationSize];
     for (int i = 0; i < Size; i++)
     {
         chromosomes[i] = new SingleObjectiveChromosome(Template, gaParameters, empty);
     }
     //initialising best chromosome
     bestChromosome = new SingleObjectiveChromosome(Template, gaParameters, true);
 }
示例#6
0
        private void OnExecuteMainWindow()
        {
            est = new Estimation(dataContext.Inputs);

            if (dataContext.Inputs.IsOptimizing)
            {
                gaView             = new GAParameters();
                gaView.DataContext = dataContext;
                gaView.Show();
            }
            else
            {
                ResultsView resView = new ResultsView(est.Estimate());
                resView.Show();
            }
        }
示例#7
0
    // Load the entire population from a binary file
    private void LoadPopulation()
    {
        BinaryFormatter bf = new BinaryFormatter();

        FileStream paramsFile = File.Open("SaveData/" + LoadPath + "/params.bin", FileMode.Open);

        currentParams = (GAParameters)bf.Deserialize(paramsFile);
        paramsFile.Close();

        CurrentEpoch = LoadEpoch;
        string saveFilename = "SaveData/" + LoadPath + "/population" + LoadEpoch + ".bin";

        FileStream popFile = File.Open(saveFilename, FileMode.Open);

        population = (List <NeuralNet>)bf.Deserialize(popFile);
        popFile.Close();
    }
示例#8
0
        public frmMain()
        {
            InitializeComponent();

            // Начальная инициализация параметров расчета. Используются параметры по умолчанию.
            _paramAnt = new AntParameters();
            _paramBnB = new BnBParameters();
            _paramGA  = new GAParameters();

            // Отправляем ссылку на Лист Маршрутов контроллу прорисовки
            liRoute        = new List <Route>();
            ucCP.ListRoute = liRoute;

            //инициализация списков экземпляров алгоритмов
            _prAntList = new List <ProcessAnt>();
            _prNNList  = new List <ProcessNearestNeighbour>();
            _prBnBList = new List <ProcessBranchAndBound>();
            _prGAList  = new List <ProcessGeneticAlgorithm>();
        }
        public MultiObjectivePopulation(OptimisationTemplate Template, GAParameters gaParameters, int populationSize, bool empty)
            : base(Template, gaParameters, populationSize)
        {
            //initialising population chromosomes
            chromosomes = new MultiObjectiveChromosome[size];
            for (int i = 0; i < size; i++)
            {
                chromosomes[i] = new MultiObjectiveChromosome(Template, gaParameters, empty);
            }

            //initialising the seven statistics variables
            int noOfObjectives = Template.Objectives.Count;

            bestObjectives    = new double[noOfObjectives];
            worstObjectives   = new double[noOfObjectives];
            averageObjectives = new double[noOfObjectives];
            maximumFitnesses  = new double[noOfObjectives];
            minimumFitnesses  = new double[noOfObjectives];
            averageFitnesses  = new double[noOfObjectives];
            fitnessVariances  = new double[noOfObjectives];
        }
        public Chromosome(OptimisationTemplate Template, GAParameters gaParameters, bool empty)
        {
            this.Template     = Template;
            this.gaParameters = gaParameters;


            int noOfDesignVariables = Template.DesignVariables.Count;

            genes = new double[noOfDesignVariables];
            for (int i = 0; i < noOfDesignVariables; i++)
            {
                if (Template.DesignVariables[i].Type == DesignVariableType.Integer)
                {
                    if (!empty)
                    {
                        genes[i] = GARandom.BoundedRandomInteger((int)Template.DesignVariables[i].LowerBound, (int)Template.DesignVariables[i].UpperBound);
                    }
                    else
                    {
                        genes[i] = 0.0;
                    }
                }
                if (Template.DesignVariables[i].Type == DesignVariableType.Double)
                {
                    if (!empty)
                    {
                        genes[i] = GARandom.BoundedRandomDouble(Template.DesignVariables[i].LowerBound, Template.DesignVariables[i].UpperBound);
                    }
                    else
                    {
                        genes[i] = 0.0;
                    }
                }
            }
            constraintValues          = new double[Template.Constraints.Count];
            constraintViolationValues = new double[Template.Constraints.Count];
        }
 public Population(OptimisationTemplate Template, GAParameters gaParameters, int size)
 {
     this.Template     = Template;
     this.gaParameters = gaParameters;
     this.size         = size;
 }
 public Population(OptimisationTemplate Template, GAParameters gaParameters)
     : this(Template, gaParameters, gaParameters.PopulationSize)
 {
 }
示例#13
0
 protected SelectionOpr(OptimisationTemplate Template, GAParameters gaParameters)
 {
     this.Template     = Template;
     this.gaParameters = gaParameters;
 }
示例#14
0
 public SimulatedBinaryCrossoverOpr(OptimisationTemplate Template, GAParameters gaParameters, double genewiseSwapProb, int polynomialOrder)
     : base(Template, gaParameters)
 {
     this.genewiseSwapProb = genewiseSwapProb;
     this.polynomialOrder  = polynomialOrder;
 }
 public TournamentSelectionOprWithoutReplacement(OptimisationTemplate Template, GAParameters gaParameters)
     : this(Template, gaParameters, 2)
 {
 }
 public ProportionalElitismOpr(OptimisationTemplate Template, GAParameters gaParameters, Population.Population parentPopulation, Population.Population childPopulation)
     : base(Template, gaParameters, parentPopulation, childPopulation)
 {
 }
        protected double crowdingDistance; //will be initialised to 0.0 upon object creation


        public MultiObjectiveChromosome(OptimisationTemplate Template, GAParameters gaParameters, bool empty)
            : base(Template, gaParameters, empty)
        {
            objectiveValues = new double[Template.Objectives.Count];
            fitnessValues   = new double[Template.Objectives.Count];
        }
示例#18
0
 public CrossoverOpr(OptimisationTemplate Template, GAParameters gaParameters)
 {
     this.Template     = Template;
     this.gaParameters = gaParameters;
 }
示例#19
0
 public SelectiveMutationOpr(OptimisationTemplate Template, GAParameters gaParameters)
     : base(Template, gaParameters)
 {
 }
示例#20
0
 public MutationOpr(OptimisationTemplate Template, GAParameters gaParameters)
 {
     this.Template     = Template;
     this.gaParameters = gaParameters;
 }
        //public Treatment Treatment { get; }

        public override bool Execute()
        {
            bool status = true;



            /*
             #region Atif
             * string databaseFileName = Path.Combine(AircadiaProject.ProjectPath, "Studies\\" + this.Name + "\\" + this.Name + ".sdf"); // Microsoft SQL server compact edition file
             *
             * // Create database for optimisation results
             * string connectionString;
             *
             * connectionString = string.Format("Data Source = " + databaseFileName + ";Persist Security Info=False");
             * SqlCeEngine engine = new SqlCeEngine(connectionString);
             *
             * // Create tables
             * SqlCeConnection connection = new SqlCeConnection(connectionString);
             * if (connection.State == ConnectionState.Closed)
             * {
             *  connection.Open();
             * }
             *
             *
             *
             *
             *
             * // Create SQL statement command for "SQL Server Compact Edition"
             * SqlCeCommand command1 = new SqlCeCommand(sqlStatement1, connection);
             * SqlCeCommand command2 = new SqlCeCommand(sqlStatement2, connection);
             * // Execute the SQL command
             * try
             * {
             *  command1.ExecuteNonQuery();
             *  command2.ExecuteNonQuery();
             * }
             * catch (SqlCeException sqlexception)
             * {
             *  Console.WriteLine(sqlexception.Message);
             * }
             * catch (Exception ex)
             * {
             *  Console.WriteLine(ex.Message);
             * }
             #endregion Atif
             */



            if (Treatment is NSGAIIOptimiser opt)
            {
                //throw new NotImplementedException("NSGAII or SGA  used a GUI to define some parameters, removing this dependencies needs to be implemented");

                //opt.GAParameters.SelectionOprMethod = Treatments.Optimisers.GA.Selection.SelectionOprMethods.TournamentSelectionWithoutReplacement;
                //opt.GAParameters.CrossoverOprMethod = Treatments.Optimisers.GA.Crossover.CrossoverOprMethods.UniformCrossover;
                //opt.GAParameters.MutationOprMethod = Treatments.Optimisers.GA.Mutation.MutationOprMethods.PolynomialMutation;
                //opt.GAParameters.EvaluatedSolutionsFile = Path.Combine(AircadiaProject.ProjectPath, "evaluatedSolutions.txt");

                // UI Code
                //    NoOfGenerations = (int)numericUpDownNoOfGenerations.Value;
                //GAParameters.NoOfGenerations = NoOfGenerations;

                //PopulationSize = (int)numericUpDownPopulationSize.Value;
                //GAParameters.PopulationSize = PopulationSize;

                //if ((comboBoxSelectionOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Roulette Wheel")
                //    GAParameters.SelectionOprMethod = SelectionOprMethods.RouletteWheelSelection;
                //else if ((comboBoxSelectionOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Tournament Without Replacement")
                //    GAParameters.SelectionOprMethod = SelectionOprMethods.TournamentSelectionWithoutReplacement;
                //else if ((comboBoxSelectionOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Tournament With Replacement")
                //    GAParameters.SelectionOprMethod = SelectionOprMethods.TournamentSelectionWithReplacement;

                //if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "One-Point")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.OnePointCrossover;
                //else if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Two-Point")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.TwoPointCrossover;
                //else if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Uniform")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.UniformCrossover;
                //else if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Simulated Binary")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.SimulatedBinaryCrossover;

                //if ((comboBoxMutationOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Genewise")
                //    GAParameters.MutationOprMethod = MutationOprMethods.GenewiseMutation;
                //else if ((comboBoxMutationOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Selective")
                //    GAParameters.MutationOprMethod = MutationOprMethods.SelectiveMutation;
                //else if ((comboBoxMutationOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Polynomial")
                //    GAParameters.MutationOprMethod = MutationOprMethods.PolynomialMutation;

                // GA setup
                GASetup gaSetup = new GASetup(this.OptimisationTemplate);
                if (gaSetup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    GAParameters gaParameters = gaSetup.GAParameters;
                    //gaParameters.EvaluatedSolutionsFile = Path.Combine(AircadiaProject.ProjectPath, "evaluatedSolutions.txt");
                    ((NSGAIIOptimiser)(Treatment)).GAParameters = gaParameters;
                }
            }
            else if (Treatment is SGAOptimizer)
            {
                throw new NotImplementedException("NSGAII or SGA  used a GUI to define some parameters, removing this dependencies needs to be implemented");
            }

            Treatment.Result = ActiveResult;

            status = Treatment.ApplyOn();

            return(status);
        }
 public SingleObjectiveChromosome(OptimisationTemplate Template, GAParameters gaParameters, bool empty)
     : base(Template, gaParameters, empty)
 {
 }
 public TournamentSelectionOprWithoutReplacement(OptimisationTemplate Template, GAParameters gaParameters, int tournamentSize)
     : base(Template, gaParameters, tournamentSize)
 {
 }
 public TournamentSelectionOpr(OptimisationTemplate Template, GAParameters gaParameters, int tournamentSize)
     : base(Template, gaParameters)
 {
     this.tournamentSize = tournamentSize;
 }
示例#25
0
 public SimulatedBinaryCrossoverOpr(OptimisationTemplate Template, GAParameters gaParameters)
     : this(Template, gaParameters, 0.5, 10)
 {
 }
 public MultiObjectivePopulation(OptimisationTemplate Template, GAParameters gaParameters, bool empty)
     : this(Template, gaParameters, gaParameters.PopulationSize, empty)
 {
 }
示例#27
0
 public PolynomialMutationOpr(OptimisationTemplate Template, GAParameters gaParameters)
     : base(Template, gaParameters)
 {
 }
 public OnePointCrossoverOpr(OptimisationTemplate Template, GAParameters gaParameters)
     : base(Template, gaParameters)
 {
 }
 public SGAOptimizer(string name, string description, GAParameters gaParameters)
     : base(name, description, gaParameters)
 {
 }
示例#30
0
 public GASetup(OptimisationTemplate template)
 {
     InitializeComponent();
     gaParameters = new GAParameters(template);
 }