public DNA <float> Start(float currentFluidLevel) { var scadaProxy = new SF.Common.Proxies.ScadaExportProxy(ConfigurationManager.AppSettings["Scada"]); model = scadaProxy.GetData().GetAwaiter().GetResult(); if (currentFluidLevel == 0 || IsCurrentOptimal(currentFluidLevel)) { var ret = new DNA <float>(); ret.Genes = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; return(ret); } foreach (var m in model) { if (m.Value.Mrid == "Flow_AM1") { pump1flow = m.Value as AnalogPoint; } else if (m.Value.Mrid == "Flow_AM2") { pump2flow = m.Value as AnalogPoint; } else if (m.Value.Mrid == "Flow_AM3") { pump3flow = m.Value as AnalogPoint; } else if (m.Value.Mrid == "Discrete_Tap1") { tapChanger1 = m.Value as AnalogPoint; } else if (m.Value.Mrid == "Discrete_Tap2") { tapChanger2 = m.Value as AnalogPoint; } else if (m.Value.Mrid == "Discrete_Tap3") { tapChanger3 = m.Value as AnalogPoint; } else if (m.Value.Mrid == "FluidLevel_Tank") { fluidLevel = m.Value as AnalogPoint; } } if (pump1flow.Value > 0) { isWorking1 = 0; } else { isWorking1 = 1; } if (pump2flow.Value > 0) { isWorking2 = 0; } else { isWorking2 = 1; } if (pump3flow.Value > 0) { isWorking3 = 0; } else { isWorking3 = 1; } //PRVA GENERACIJA IMA JEDNU JEDINKU firstGenes = new float[] { isWorking1, pump1flow.Value, 0.1f, isWorking2, pump2flow.Value, 0.1f, isWorking3, pump3flow.Value, 0.1f }; DNA <float> firstHromozome = new DNA <float>(9, random, GetRandomGene, FitnessFunction, false, true, GetGene); hromozomes.Add(firstHromozome); ga = new GeneticAlgorithm <float>(1, 9, random, GetRandomGene, FitnessFunction, elitism, mutationRate, hromozomes, GetGene); population = ga.Population; do { Update(); population = ga.Population; results = new List <float>(); for (int i = 0; i < population.Count(); i++) { results.Add(currentFluidLevel - FitnessFunction(i)); } List <Tuple <int, float> > potentialSolutions = utils.FindPotentialSolutions(results, workingTimes); if (potentialSolutions.Count() > 0) { Tuple <int, float> bestSolution = utils.FindBestSolution(potentialSolutions); if (bestSolution.Item2 < lastBestSolution) { lastBestSolution = bestSolution.Item2; bestSolutionIndex = bestSolution.Item1; bestIndividual = population[bestSolution.Item1]; } } countIteration++; if (countIteration == iterations || utils.IsSolutionCorrect(lastBestSolution, workingTimes[bestSolutionIndex])) { break; } } while (true); return(bestIndividual); }