コード例 #1
0
        public async Task <IActionResult> PerformPreGenerationChecks([FromBody] ScheduleCreatorDto scheduleCreator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
                                  .Substring(6) + Path.DirectorySeparatorChar + scheduleCreator.AssemblyDirName;


            if (!scheduleCreator.Date.HasValue)
            {
                return(BadRequest());
            }

            ISpeciesOriginator speciesOriginator = DynamicFactory.GetSpeciesOriginator(assemblyPath, scheduleCreator.Date.Value, scheduleCreator.Args);

            List <Requirement> requirements = DynamicFactory.GetRequirements(assemblyPath, scheduleCreator.Date.Value, scheduleCreator.Args);

            await speciesOriginator.SetDataFromCustomApi();

            var messenger = speciesOriginator.PerformPreGenerationChecks();

            return(Ok(messenger.Messages));
        }
コード例 #2
0
        public async Task <IActionResult> GetSchedule([FromBody] ScheduleCreatorDto scheduleCreator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            /*//string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
             *                        .Substring(6) + Path.DirectorySeparatorChar + scheduleCreator.AssemblyDirName;*/

            string assemblyPath = Path.Combine(_environment.ContentRootPath, scheduleCreator.AssemblyDirName);

            if (!scheduleCreator.Date.HasValue)
            {
                return(BadRequest());
            }

            ISpeciesOriginator speciesOriginator = DynamicFactory.GetSpeciesOriginator(assemblyPath, scheduleCreator.Date.Value, scheduleCreator.Args);

            List <Requirement> requirements = DynamicFactory.GetRequirements(assemblyPath, scheduleCreator.Date.Value, scheduleCreator.Args);

            await speciesOriginator.SetDataFromCustomApi();

            foreach (var requirement in requirements)
            {
                await requirement.SetDataFromRemoteApi();
            }

            Population population = new Population(new CostCalculator(requirements), speciesOriginator);

            population.Initialize();

            population.CalculateGeneralCost();

            do
            {
                population.PerformNaturalSelection();

                population.CalculateGeneralCost();
            } while (population.NumberOfGenerations < 100);

            IAllel[,] solution = population.BestSolution.Dna;

            Dictionary <DateTime, object> data = speciesOriginator.CustomFormatSolution(solution, scheduleCreator.Date.Value);

            Dictionary <string, object> dataToReturn = Converter.ConvertDateTimeToString(data);

            return(Ok(dataToReturn));
        }