Exemplo n.º 1
0
        public Visualisation(DVRPDescription _dvrpDescription, int[][] _permutations)
        {
            InitializeComponent();

            m_dvrpDescription    = _dvrpDescription;
            m_clientsCoordinates = new Point[_dvrpDescription.clients.Count];
            bitmap = new Bitmap(panel1.Width, panel1.Height);
            foreach (Client client in _dvrpDescription.clients)
            {
                if ((int)client.coordinate.X < m_minX)
                {
                    m_minX = (int)client.coordinate.X;
                }
                if ((int)client.coordinate.X > m_maxX)
                {
                    m_maxX = (int)client.coordinate.X;
                }
                if ((int)client.coordinate.Y < m_minY)
                {
                    m_minY = (int)client.coordinate.Y;
                }
                if ((int)client.coordinate.Y > m_maxY)
                {
                    m_maxY = (int)client.coordinate.Y;
                }
            }

            drawDepot(m_dvrpDescription);
            drawEllipses(m_dvrpDescription);
            drawLines(_permutations);
        }
Exemplo n.º 2
0
        private void drawDepot(DVRPDescription _dvrpDescription)
        {
            SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            int x = (int)_dvrpDescription.coordinateDepot.X + Math.Abs(m_minX) + m_margin;
            int y = (int)_dvrpDescription.coordinateDepot.Y + Math.Abs(m_minY) + 30;

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.FillRectangle(myBrush, new Rectangle(x, y, 10, 10));
            }
            m_depotCoordinates = new Point(x + 5, y + 5);
            myBrush.Dispose();
            panel1.Refresh();
        }
Exemplo n.º 3
0
        private void drawEllipses(DVRPDescription _dvrpDescription)
        {
            int        x, y;
            SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                for (int i = 0; i < _dvrpDescription.clients.Count; i++)
                {
                    x = (int)_dvrpDescription.clients[i].coordinate.X + Math.Abs(m_minX) + m_margin;
                    y = (int)_dvrpDescription.clients[i].coordinate.Y + Math.Abs(m_minY) + 30;
                    m_clientsCoordinates[i] = new Point(x + 5, y + 5);
                    g.FillEllipse(myBrush, new Rectangle(x, y, 13, 13));
                    g.DrawString(i.ToString(), new Font("Arial", 9), new SolidBrush(Color.White), new PointF(x, y));
                }
            }
            myBrush.Dispose();
            panel1.Refresh();
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Text files (*.txt)|*.txt";
            ofd.ShowDialog();
            DVRPDescription dvrpDescription = new DVRPDescription();

            try
            {
                using (StreamReader sr = new StreamReader(ofd.FileName))
                {
                    sr.ReadLine();
                    string line = sr.ReadLine().Trim();
                    while (line != "EOF")
                    {
                        string[] lineParts = line.Split(':');
                        if (lineParts.Length == 1)
                        {
                            int index = 0;
                            switch (line.Trim())
                            {
                            case "DEPOTS":
                                dvrpDescription.depotCoordinateIndex = Int32.Parse(sr.ReadLine().Trim());
                                break;

                            case "DEMAND_SECTION":
                                index = 0;
                                while (true)
                                {
                                    dvrpDescription.clients[index].coordinateIndex = Int32.Parse(lineParts[0]);
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    if (Int32.Parse(lineParts[0]) > dvrpDescription.depotCoordinateIndex)
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0]) - 1].demand = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                    else
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0])].demand = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                }
                                continue;

                            case "LOCATION_COORD_SECTION":
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    dvrpDescription.locations[Int32.Parse(lineParts[0])] = new Point(Math.Abs(Int32.Parse(lineParts[lineParts.Length - 2])), Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1])));
                                }
                                continue;

                            case "DEPOT_LOCATION_SECTION":
                                break;

                            case "VISIT_LOCATION_SECTION":
                                break;

                            case "DURATION_SECTION":
                                index = 0;
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    dvrpDescription.clients[Int32.Parse(lineParts[0])].durationTime = Int32.Parse(lineParts[lineParts.Length - 1]);
                                }
                                continue;

                            /*case "DEPOT_TIME_WINDOW_SECTION":
                             *  while (true)
                             *  {
                             *      line = sr.ReadLine().Trim();
                             *      lineParts = line.Split(' ');
                             *      if (lineParts.Length == 1)
                             *          break;
                             *      dvrpDescription.clients[Int32.Parse(lineParts[0])].availableTime = Int32.Parse(lineParts[lineParts.Length - 1]);
                             *  }
                             *  continue;*/
                            case "TIME_AVAIL_SECTION":
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    dvrpDescription.clients[Int32.Parse(lineParts[0])].availableTime = Int32.Parse(lineParts[lineParts.Length - 1]);
                                }
                                continue;
                            }
                        }
                        else
                        {
                            switch (lineParts[0])
                            {
                            case "NAME":
                                break;

                            case "NUM_VISITS":
                                dvrpDescription.clients = new List <Client>();
                                for (int i = 0; i < Int32.Parse(lineParts[1]); i++)
                                {
                                    dvrpDescription.clients.Add(new Client());
                                }
                                break;

                            case "NUM_VEHICLES":
                                dvrpDescription.vehicles = new List <Vehicle>();
                                for (int i = 0; i < Int32.Parse(lineParts[1]); i++)
                                {
                                    dvrpDescription.vehicles.Add(new Vehicle());
                                }
                                break;

                            case "CAPACITIES":
                                foreach (Vehicle v in dvrpDescription.vehicles)
                                {
                                    v.capacity = Int32.Parse(lineParts[1]);
                                }
                                break;

                            case "SPEED":
                                foreach (Vehicle v in dvrpDescription.vehicles)
                                {
                                    v.speed = Int32.Parse(lineParts[1]);
                                }
                                break;

                            case "EDGE_WEIGHT_TYPE":
                                dvrpDescription.edgeWeightType = (EdgeWeightType)Enum.Parse(typeof(EdgeWeightType), lineParts[1].Trim());
                                break;

                            default:
                                break;
                            }
                        }
                        line = sr.ReadLine().Trim();
                    }
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(ee.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (solvingTimeoutText.Text != "")
            {
                timeoutSpecified = true;
                try
                {
                    timeout = long.Parse(solvingTimeoutText.Text);
                }
                catch
                {
                    timeoutSpecified = false;
                }
            }
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Vehicle Routing Problem File (*.vrp)|*.vrp";
            ofd.ShowDialog();
            if (ofd.FileName == null || ofd.FileName == "")
            {
                return;
            }
            dvrpDescription = new DVRPDescription();
            try
            {
                using (StreamReader sr = new StreamReader(ofd.FileName))
                {
                    sr.ReadLine();
                    string line = sr.ReadLine().Trim();
                    int    depotCoordinateIndex = 0;
                    while (line != "EOF")
                    {
                        string[] lineParts = line.Split(':');
                        if (lineParts.Length == 1)
                        {
                            int index = 0;
                            switch (line.Trim())
                            {
                            case "DEPOTS":
                                depotCoordinateIndex = Int32.Parse(sr.ReadLine().Trim());
                                break;

                            case "DEMAND_SECTION":
                                index = 0;
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    if (Int32.Parse(lineParts[0]) > depotCoordinateIndex)
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0]) - 1].demand = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                    else
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0])].demand = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                }
                                continue;

                            case "LOCATION_COORD_SECTION":
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    if (Int32.Parse(lineParts[0]) == depotCoordinateIndex)
                                    {
                                        dvrpDescription.coordinateDepot = new Point((Int32.Parse(lineParts[lineParts.Length - 2])), (Int32.Parse(lineParts[lineParts.Length - 1])));
                                    }
                                    else if (Int32.Parse(lineParts[0]) < depotCoordinateIndex)
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0])].coordinate = new Point((Int32.Parse(lineParts[lineParts.Length - 2])), (Int32.Parse(lineParts[lineParts.Length - 1])));
                                    }
                                    else
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0]) - 1].coordinate = new Point((Int32.Parse(lineParts[lineParts.Length - 2])), (Int32.Parse(lineParts[lineParts.Length - 1])));
                                    }
                                }
                                continue;

                            case "DEPOT_LOCATION_SECTION":
                                break;

                            case "VISIT_LOCATION_SECTION":
                                break;

                            case "DURATION_SECTION":
                                index = 0;
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    if (Int32.Parse(lineParts[0]) > depotCoordinateIndex)
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0]) - 1].durationTime = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                    else
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0])].durationTime = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                }
                                continue;

                            case "DEPOT_TIME_WINDOW_SECTION":
                                // while (true)
                                // {
                                line      = sr.ReadLine().Trim();
                                lineParts = line.Split(' ');
                                if (lineParts.Length == 1)
                                {
                                    break;
                                }
                                dvrpDescription.startTimeDepot = Int32.Parse(lineParts[1]);
                                dvrpDescription.endTimeDepot   = Int32.Parse(lineParts[2]);
                                // }
                                break;

                            case "TIME_AVAIL_SECTION":
                                while (true)
                                {
                                    line      = sr.ReadLine().Trim();
                                    lineParts = line.Split(' ');
                                    if (lineParts.Length == 1)
                                    {
                                        break;
                                    }
                                    if (Int32.Parse(lineParts[0]) > depotCoordinateIndex)
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0]) - 1].availableTime = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                    else
                                    {
                                        dvrpDescription.clients[Int32.Parse(lineParts[0])].availableTime = Math.Abs(Int32.Parse(lineParts[lineParts.Length - 1]));
                                    }
                                }
                                continue;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            switch (lineParts[0])
                            {
                            case "NAME":
                                break;

                            case "NUM_VISITS":
                                dvrpDescription.clients = new List <Client>();
                                for (int i = 0; i < Int32.Parse(lineParts[1]); i++)
                                {
                                    dvrpDescription.clients.Add(new Client());
                                }
                                // dvrpDescription.locations = new List<Point>();
                                // dvrpDescription.coordinateDepot
                                // for (int i = 0; i < Int32.Parse(lineParts[1]) + 1; i++)
                                //     dvrpDescription.clients[i].locations.Add(new Point());
                                break;

                            case "NUM_VEHICLES":
                                dvrpDescription.vehiclesCount = Int32.Parse(lineParts[1]);
                                //.vehicles = new List<Vehicle>();
                                //for (int i = 0; i < ; i++)
                                //     dvrpDescription.vehicles.Add(new Vehicle());
                                break;

                            case "CAPACITIES":
                                // foreach (Vehicle v in dvrpDescription.vehicles)
                                dvrpDescription.vehicleCapacity = Int32.Parse(lineParts[1]);
                                break;

                            case "SPEED":
                                //foreach (Vehicle v in dvrpDescription.vehicles)
                                //    v.speed = Int32.Parse(lineParts[1]);
                                break;

                            case "EDGE_WEIGHT_TYPE":
                                // dvrpDescription.edgeWeightType = (EdgeWeightType)Enum.Parse(typeof(EdgeWeightType), lineParts[1].Trim());
                                break;

                            default:
                                break;
                            }
                        }
                        line = sr.ReadLine().Trim();
                    }
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(ee.Message);
            }

            this.Close();
        }