public void RegisterResearch(WebResearchParameters webParameters) { string connecionId = Context.ConnectionId; Register(); LandscapeResearch research = new LandscapeResearch(); if (researches.ContainsKey(connecionId)) { research = researches[connecionId]; //reseach.Stop(); } else { research = new LandscapeResearch(); } ResearchParameters parameters = new ResearchParameters() { Sensitivity = webParameters.Sensitivity, RandomWalkNumber = webParameters.RandomWalkNumber, RandomWalkSteps = webParameters.RandomWalkSteps, CrossoverOperators = new List <CrossoverOperator>(), MutationOperators = new List <MutationOperator>(), RoadWeight200 = webParameters.RoadWeight200, RoadWeight400 = webParameters.RoadWeight400, RoadWeight600 = webParameters.RoadWeight600, RoadWeight800 = webParameters.RoadWeight800, RoadWeight1000 = webParameters.RoadWeight1000 }; if (webParameters.CrossoverOperators != null) { foreach (var xOp in webParameters.CrossoverOperators) { parameters.CrossoverOperators.Add(CrossoverOperatorFactory.Create(xOp)); } } if (webParameters.MutationOperators != null) { foreach (var mOp in webParameters.MutationOperators) { parameters.MutationOperators.Add(MutationOperatorFactory.Create(mOp)); } } researches.TryAdd(connecionId, research); string inputPath = HttpContext.Current.Server.MapPath("~/Data/Homberger"); string outputPath = HttpContext.Current.Server.MapPath("~/Results/Homberger"); research.Run(parameters, inputPath, outputPath, UpdateResearch, connecionId); }
public void RegisterAlgorithm(string problemName, ParametersWebsite webParameters) { string filePath = HttpContext.Current.Server.MapPath("~/Data/Homberger/" + problemName.ToUpper() + @".txt"); VrptwProblem problem = new VrptwProblemReader().ReadFromFile(filePath); string connecionId = Context.ConnectionId; Register(); MemeticAlgorithm ma; if (algorithms.ContainsKey(connecionId)) { ma = algorithms[connecionId]; ma.Stop(); } else { ma = new MemeticAlgorithm(); } Parameters parameters = new Parameters { Heuristics = HeuristicsFactory.Create(webParameters.Heuristics), PopulationSize = webParameters.PopulationSize, Selection = SelectionFactory.Create(webParameters.Selection), CrossoverOperators = new List <CrossoverOperator>(), MutationOperators = new List <MutationOperator>(), CrossoverProbability = webParameters.CrossoverProbability, MutationProbability = webParameters.MutationProbability, Fitness = new FitnessFunction(webParameters.FitnessRoutes, webParameters.FitnesDistance), EliteChildrenCount = webParameters.EliteChildrenCount, GeneCount = problem.Customers.Count, FitnessStrategy = FitnessStrategy.MINIMIZE, ConvergenceLimit = webParameters.ConvergenceLimit, PreservedChromosomesNumber = webParameters.PreservedChromosomeNumber, MaxIterations = webParameters.Iterations, ChromosomeFactory = new SolutionFactory(), HeuristicsParameters = webParameters.HeuristicsParameters }; parameters.CrossoverOperators.Add(CrossoverOperatorFactory.Create(webParameters.Crossover)); parameters.MutationOperators.Add(MutationOperatorFactory.Create(webParameters.Mutation)); algorithms.TryAdd(connecionId, ma); var result = ma.Run(problem, parameters, UpdateSolution, connecionId); var solution = result.Result as Solution; string outputPath = HttpContext.Current.Server.MapPath("~/Results/Memetic"); string outputFilePath = outputPath + @"/" + problem.Name + ".txt"; File.WriteAllText(outputFilePath, solution.ToFileText()); }