Exemplo n.º 1
0
        public ActionResult Search(LocalSearchModel local)
        {
            List <Local> listaLoc = null;

            if (local.departamento == 0 && local.nombre != null)
            {
                listaLoc = db.Local.AsNoTracking().Where(c => c.descripcion.Contains(local.nombre)).ToList();
            }
            else if (local.departamento != 0 && local.nombre == null)
            {
                listaLoc = db.Local.AsNoTracking().Where(c => local.departamento == c.idRegion).ToList();
            }
            else if (local.departamento != 0 && local.nombre != null)
            {
                listaLoc = db.Local.AsNoTracking().Where(c => c.descripcion.Contains(local.nombre) && local.departamento == c.idRegion).ToList();
            }
            else
            {
                TempData["ListaL"] = null;
            }
            if (listaLoc != null)
            {
                TempData["ListaL"] = listaLoc;
            }
            else
            {
                TempData["ListaL"] = null;
            }
            return(RedirectToAction("Index", "Local"));
        }
Exemplo n.º 2
0
        public LocalSearchModel Get(string problema, string algoritmo, string versao, string iteracao)
        {
            var pathRoot  = _env.ContentRootPath;
            var pathDados = Path.Combine(pathRoot, $"dados\\{problema}\\{versao}");
            var pathArquivoConfiguracoes = Path.Combine(pathRoot, $"dados\\configuracoes\\{problema}-configuracao-{versao}.cfg");

            var textoArquivoConfig = System.IO.File.ReadAllText(Path.Combine(pathRoot, pathArquivoConfiguracoes));
            var configuracao       = JsonSerializer.Deserialize <Configuracao>(textoArquivoConfig, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            });
            var coordenadas = new List <NodeModel>();

            if (!string.IsNullOrEmpty(configuracao.ArquivoCidades))
            {
                foreach (string linha in System.IO.File.ReadAllLines(Path.Combine(pathRoot, configuracao.ArquivoCidades)))
                {
                    var coords = linha.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    coordenadas.Add(new NodeModel {
                        X = double.Parse(coords[0], System.Globalization.CultureInfo.GetCultureInfo("en-US")), Y = double.Parse(coords[1], System.Globalization.CultureInfo.GetCultureInfo("en-US"))
                    });
                }
            }

            NodeRoot        primeiroNode = null;
            NodeRoot        bestNode     = null;
            NodeRoot        ultimoNode   = null;
            List <Execucao> execucoes    = null;

            if (!string.IsNullOrEmpty(problema) && !string.IsNullOrEmpty(algoritmo) && !string.IsNullOrEmpty(iteracao))
            {
                var pathArquivo  = $"{algoritmo}-{iteracao}.dat";
                var textoArquivo = System.IO.File.ReadAllText(Path.Combine(pathDados, pathArquivo));

                execucoes = JsonSerializer.Deserialize <List <Execucao> >(textoArquivo, new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                });
                primeiroNode = execucoes.First().Atual.Root;
                bestNode     = execucoes.First(x => x.Atual.Root.Best == x.Atual.Root.Value).Atual.Root;
                ultimoNode   = execucoes.Last().Atual.Root;
            }

            var bestNodeModel  = _mapper.Map <NodeRootModel>(bestNode);
            var execucoesModel = _mapper.Map <List <ExecucaoModel> >(execucoes.Select(p => p).ToList());

            _cache.Remove(CACHE_KEY);
            var entry = _cache.Set(CACHE_KEY, execucoesModel);

            var model = new LocalSearchModel
            {
                Algoritmo            = algoritmo,
                Problema             = problema,
                Estado               = bestNodeModel.State,
                Valor                = primeiroNode.Best,
                ValorInicial         = primeiroNode.Value,
                ValorFinal           = ultimoNode.Best,
                PopulacaoInicial     = _mapper.Map <List <NodeModel> >(primeiroNode.Populacao),
                Coordenadas          = coordenadas,
                Execucoes            = execucoesModel.Skip(0).Take(1000).ToList(),
                NumeroTotalExecucoes = execucoesModel.Count
            };

            return(model);
        }