Example #1
0
        public async Task <TipoErro> RunTest(string filename)
        {
            RouteService.LoadCache();
            var config = await PRVJTFinder.GetConfigByFile(filename, RouteService);

            foreach (MutateEnum mut in Enum.GetValues(typeof(MutateEnum)))
            {
                foreach (CrossoverEnum cro in Enum.GetValues(typeof(CrossoverEnum)))
                {
                    // Altera a configuração do GA
                    config.Settings.Mutation  = mut;
                    config.Settings.Crossover = cro;

                    // Carrega a configuração do roteiro
                    var finder = new PRVJTFinder(config, RouteService);
                    // Executa a divisão de rotas
                    RouteService.LoadCache();
                    var result = await finder.Run();

                    RouteService.SaveCache();

                    if (result.Erro)
                    {
                        return(result.TipoErro);
                    }

                    //while (!result.Concluido)
                    //{
                    //    foreach (var item in result.ListEntregadores)
                    //    {
                    //        if (item.NextRoute == null)
                    //            continue;
                    //        var entreresult = await finder.Step(item);

                    //        if (entreresult.Erro)
                    //            return result.TipoErro;
                    //    }
                    //}
                }
            }

            return(TipoErro.Concluido);
        }
Example #2
0
        public async static Task <IEnumerable <Result> > RunTest(string filename)
        {
            var ret          = new List <Result>();
            var http         = new HttpClient();
            var routeService = new CachedGoogleMatrixService(http);

            foreach (MutateEnum mut in Enum.GetValues(typeof(MutateEnum)))
            {
                foreach (CrossoverEnum cro in Enum.GetValues(typeof(CrossoverEnum)))
                {
                    var settings = new GASettings
                    {
                        // Altera a configuração do GA
                        Mutation  = mut,
                        Crossover = cro
                    };

                    for (int i = 0; i < 10; i++)
                    {
                        var file = Path.GetFileName(filename);
                        Console.WriteLine($"A:{file} I:{i} M:{mut} C:{cro}");
                        var config = await PRVJTFinder.GetConfigByFile(filename, routeService, settings);

                        // Carrega a configuração do roteiro
                        var finder = new PRVJTFinder(config, routeService);
                        // Executa a divisão de rotas

                        routeService.LoadCache();
                        var result = await finder.Run();

                        routeService.SaveCache();

                        if (result.Erro)
                        {
                            ret.Add(new Result(
                                        result.TipoErro,
                                        i,
                                        filename,
                                        result.ListEntregadores.Count(),
                                        mut,
                                        cro,
                                        result.BestGenome.Fitness
                                        ));
                            continue;
                        }

                        ret.Add(new Result(
                                    result.TipoErro,
                                    i,
                                    filename,
                                    result.ListEntregadores.Count(),
                                    mut,
                                    cro,
                                    result.BestGenome.Fitness
                                    ));
                    }
                }
            }
            http.Dispose();
            return(ret);
        }