/// <summary> /// Configure the map accoding to the assigned task /// </summary> private void setMode() { if (mode == MODE_WORLD) { //Dibuja ciudades drawCities(controller.getCities()); gboxSolution.Visible = false; } else if (mode == MODE_SOLUTION) { btn_simulate.Visible = false; //controller.simulate(); Simulation s = controller.getSimulation(); if (s != null) { while (s.isSimulating()) { } Console.WriteLine(s.getBest().ToString()); Console.WriteLine("Time " + s.getTime()); draw_simulation(s); } else { throw new Exception("Map needs a simulation to show"); } } else { throw new Exception("Map needs a valid mode"); } }
private void btn_run_Click(object sender, EventArgs e) { try { int seed = (int)numUpSeeds.Value; int cities = (int)numUpNumberCities.Value; if (txt_file.Text.Equals("")) { controller.set_simulation(seed, cities); } else { controller.set_simulation(seed, cities, txt_file.Text); } controller.simulate(); Thread.Sleep(5000); btn_run.Enabled = false; while (controller.getSimulation().isSimulating()) { } this.Hide(); btn_run.Enabled = true; MapView map = new MapView(MapView.MODE_SOLUTION, this); map.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(String[] args) { if (args.Length > 0) { try { TravelerSalesmanProblem controller = TravelerSalesmanProblem.getInstance(); int cities; int seed; try { cities = int.Parse(args[0]); seed = int.Parse(args[1]); } catch { throw new Exception("Value cities and seed must be numerical"); } if (args.Length == 2) { //Opción 1: Solo entrega semilla y ciudad controller.set_simulation(seed, cities); } else if (args.Length == 3) { String arg3 = args[2]; String[] split = arg3.Split(','); if (split.Length > 0) { List <int> id = new List <int>(); foreach (String v in split) { try { id.Add(int.Parse(v)); } catch { throw new Exception("All id values must be numerical"); } } controller.set_simulation(seed, cities, id); } } else { throw new Exception("Invalid command"); } controller.simulate(); while (controller.getSimulation().isSimulating()) { } Console.WriteLine("Best solution: " + controller.getSimulation().getBest().ToString()); Console.WriteLine("Time " + controller.getSimulation().getTime()); } catch (Exception e) { Console.WriteLine(e.Message); } } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SimulatedAnneling.View.MapView a = new SimulatedAnneling.View.MapView(SimulatedAnneling.View.MapView.MODE_WORLD); Application.Run(a); // } }