// Last edited on 2000-08-31 01:38:41 by stolfi // Teste de Otimizador, OtimizadorImpl public class otimizadorTeste extends Main { public static void main(String[] argv) { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); out.print("Carregando planta... "); out.flush(); Planta planta = new PlantaImpl(); planta.carrega("unicamp"); out.println("pronto."); out.flush(); Esquina[] esquinas = planta.esquinas(); Trecho[] trechos = planta.trechos(); Servico[] servicos = planta.servicos(); Object start; Object target; out.print("Iníciar em esquina, trecho, ou servico [E, T, ou S]? "); out.flush(); String tipoInicio = in.readLine(); if (tipoInicio == null || tipoInicio.length() == 0) { return; } else if (tipoInicio.equalsIgnoreCase("E")) { out.print("Escolha a esquina [0 - " + esquinas.length + "]: "); out.flush(); start = esquinas[Integer.parseInt(in.readLine())]; } else if (tipoInicio.equalsIgnoreCase("T")) { out.print("Escolha o trecho [0 - " + trechos.length + "]: "); out.flush(); start = trechos[Integer.parseInt(in.readLine())]; } else if (tipoInicio.equalsIgnoreCase("S")) { out.print("Escolha o serviço [0 - " + servicos.length + "]: "); out.flush(); start = servicos[Integer.parseInt(in.readLine())]; } else { System.err.println("Inicio inválido."); return; } out.print("Terminar em esquina, trecho, servico, ou buscar servicos de um dado tipo [E, T, S, ou B]? "); out.flush(); String tipoFim = in.readLine(); if (tipoFim == null || tipoFim.length() == 0) { return; } else if (tipoFim.equalsIgnoreCase("E")) { out.print("Escolha a esquina [0 - " + esquinas.length + "]: "); out.flush(); target = esquinas[Integer.parseInt(in.readLine())]; } else if (tipoFim.equalsIgnoreCase("T")) { out.print("Escolha a trecho [0 - " + trechos.length + "]: "); out.flush(); target = trechos[Integer.parseInt(in.readLine())]; } else if (tipoFim.equalsIgnoreCase("S")) { out.print("Escolha a serviço [0 - " + servicos.length + "]: "); out.flush(); target = servicos[Integer.parseInt(in.readLine())]; } else if (tipoFim.equalsIgnoreCase("B")) { System.err.println("Não implementado."); return; } else { System.err.println("Fim inválido."); return; } OtimizadorImpl otimizador = new OtimizadorImpl(); Caminho melhor = otimizador.melhor_caminho(start, target); if (melhor != null) { out.println("Custo :" + melhor.custo); for (int i = 0; i < melhor.caminho.length; i++) { out.println(melhor.caminho[i].logradouro().nome()); } out.flush(); } } catch (Exception e) { e.printStackTrace(); } } }