예제 #1
0
        private void readFile(string filename)
        {
            StreamReader reader = null;
            try
            {
                reader = File.OpenText(filename);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Failed to open file:\n" + e.StackTrace);
                return;
            }
            string line;
            List<string> fileContent = new List<string>();
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Equals("")) continue;
                else fileContent.Add(line);
            }

            SetName = fileContent[0];
            VehicleNumber = Int32.Parse(fileContent[3].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0]);
            VehicleCapacity = Int32.Parse(fileContent[3].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1]);
            NodeList = new List<Node>();

            for (int i = 6; i < fileContent.Count; i++)
            {
                //Console.Out.WriteLine(fileContent[i]);
                string[] customerParams = fileContent[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (customerParams.Length == 0) continue;
                Node n = new Node();
                n.CustomerNr = Int32.Parse(customerParams[0]);
                n.X = Int32.Parse(customerParams[1]);
                n.Y = Int32.Parse(customerParams[2]);
                n.Demand = Int32.Parse(customerParams[3]);
                n.ReadyTime = Int32.Parse(customerParams[4]);
                n.DueDate = Int32.Parse(customerParams[5]);
                n.Service = Int32.Parse(customerParams[6]);
                NodeList.Add(n);
            }
        }
 public double DistanceBetweenLocations(Node location1, Node location2)
 {
     return Math.Sqrt(Math.Pow((location2.X - location1.X), 2) + Math.Pow((location2.Y - location1.Y), 2));
 }