public Empty_bees[] createNewSolutions(int VarSize, int nScoutBees, double VarMin, double VarMax) { Empty_bees[] bees = new Empty_bees[nScoutBees]; for (int i = 0; i < nScoutBees; i++) { bees[i].Position = unifrnd(VarMin, VarMax, VarSize); switch (objectiveFunc) { case "Функция Шаффера": bees[i].Cost = SchafferFunction(bees[i].Position); break; case "Сферическая функция": bees[i].Cost = SphereFunction(bees[i].Position); break; case "Функция Griewank": bees[i].Cost = GriewankFunction(bees[i].Position); break; case "Функция Растригина": bees[i].Cost = RastriginFunction(bees[i].Position); break; case "Функция Розенброка": bees[i].Cost = RosenbrockFunction(bees[i].Position); break; } } return(bees); }
public Empty_bees[] nonEliteSites(Empty_bees[] bees) { for (int i = Convert.ToInt32(nEliteSite); i < nSelectedSite; i++) { Empty_bees bestnewbee = new Empty_bees(); Empty_bees newbee = new Empty_bees(); bestnewbee.Cost = double.MaxValue; for (int j = 0; j < nSelectedSiteBee; j++) { //Console.WriteLine("{0} {1} ", bees[i].Cost, String.Join(";", bees[i].Position)); newbee.Position = PerformBeeDance(bees[i].Position, r); //Console.WriteLine("{0} {1} ", bees[i].Cost, String.Join(";", bees[i].Position)); switch (objectiveFunc) { case "Функция Шаффера": newbee.Cost = SchafferFunction(newbee.Position); break; case "Сферическая функция": newbee.Cost = SphereFunction(newbee.Position); break; case "Функция Griewank": newbee.Cost = GriewankFunction(newbee.Position); break; case "Функция Растригина": newbee.Cost = RastriginFunction(newbee.Position); break; case "Функция Розенброка": newbee.Cost = RosenbrockFunction(newbee.Position); break; } if (newbee.Cost < bestnewbee.Cost) { bestnewbee = newbee; } } if (bestnewbee.Cost < bees[i].Cost) { bees[i] = bestnewbee; } } return(bees); }
public ContentResult JSON() { nScoutBees = parameters[0]; MaxIt = parameters[1]; VarMin = parameters[2]; VarMax = parameters[3]; nSelectedSite = Math.Round(0.5 * nScoutBees); nEliteSite = Math.Round(0.4 * nSelectedSite); nSelectedSiteBee = Math.Round(0.5 * nScoutBees); nEliteSiteBee = 2 * nSelectedSiteBee; r = 0.1 * (VarMax - VarMin); dataPoints = new List <DataPoint>(); homeController instanceClass = new homeController(); Empty_bees[] Bees = instanceClass.createNewSolutions(VarSize, nScoutBees, VarMin, VarMax); Bees = instanceClass.sortByCost(Bees); Empty_bees bestSol = Bees[0]; Empty_bees[] bestCost = new Empty_bees[MaxIt]; double[] BestCost = new double[MaxIt]; for (int it = 0; it < MaxIt; it++) { Bees = instanceClass.eliteSites(Bees); Bees = instanceClass.nonEliteSites(Bees); Bees = instanceClass.nonSelectedSites(Bees, VarSize, nScoutBees, VarMin, VarMax); Bees = instanceClass.sortByCost(Bees); bestSol = Bees[0]; BestCost[it] = bestSol.Cost; dataPoints.Add(new DataPoint(BestCost[it])); //Console.WriteLine(BestCost[it]); r = r * rdamp; } JsonSerializerSettings _jsonSetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }; return(Content(JsonConvert.SerializeObject(dataPoints, _jsonSetting), "application/json")); }