Beispiel #1
0
        public Dictionary <long, OptimisationModel> StartAlgorithm(int iterationsCount, int populationNumber, int elitisam, float mutationRat)
        {
            SetAlgorithmOptions(iterationsCount, populationNumber, elitisam, mutationRat);
            random = new Random();
            ga     = new GeneticAlgorithm <Tuple <long, float> >(NUMBER_OF_POPULATION, optModelMap.Count, random, GetRandomGene,
                                                                 FitnessFunction, MutateFunction, ELITIMS_PERCENTAGE, NecessaryEnergy,
                                                                 ScaleDNA, mutationRate, false);

            ga.Population = PopulateFirstPopulation();
            Tuple <long, float>[] bestGenes = ga.StartAndReturnBest(NUMBER_OF_ITERATION);

            foreach (var item in bestGenes)
            {
                optModelMap.FirstOrDefault(x => x.Key == item.Item1).Value.GenericOptimizedValue        = item.Item2;
                optModelMap.FirstOrDefault(x => x.Key == item.Item1).Value.MeasuredValue                = item.Item2;
                optModelMap.FirstOrDefault(x => x.Key == item.Item1).Value.measurementUnit.CurrentValue = item.Item2;
            }

            foreach (var item in commandedGeneratrs)
            {
                optModelMap.Add(item.Key, item.Value);
            }


            float emCO2 = CalculationEngine.CalculateCO2(optModelMap);

            EmissionCO2 = emCO2;

            TotalCost = CalculateCost();

            Console.WriteLine("Necessery energy: " + NecessaryEnergy);

            return(optModelMap);
        }