public static double Parse2FinalSolLenght(string input) { if (String.IsNullOrWhiteSpace(input)) { throw new ArgumentException(input); } DVRPPartialSolution instance = new DVRPPartialSolution(); //instance.ElemCount = new List<int>(); var lines = input.Split(new[] { '\n' }); int ind = 0; for (int i = 0; i < lines.Length - 1; i++) { string[] split = DVRPHelper.SplitText(lines[i]); switch (split[0]) { case "SOLUTION": instance.PartialPaths = new List <Location> [int.Parse(split[1])]; instance.PartialPathsArrivalsTimes = new List <double> [int.Parse(split[1])]; instance.PartialPathLen = new List <double>(); instance.pathLen = double.Parse(split[2]); break; case "TIMES": instance.PartialPathsArrivalsTimes[ind] = new List <double>(); for (int n = 1; n < split.Length; n++) { instance.PartialPathsArrivalsTimes[ind].Add(double.Parse(split[n])); } break; case "PATHLEN": for (int n = 1; n < split.Length; n++) { instance.PartialPathLen.Add(double.Parse(split[n])); } ind++; break; } } return(instance.pathLen); }
public static DVRPPartialDataToSolve ParsePartialProblemData(byte[] data) { DVRPPartialDataToSolve pd2s = new DVRPPartialDataToSolve(); pd2s.partial = new int[0][]; string text = Communication_Library.CommunicationModule.ConvertDataToString(data, data.Length); string[] lines = text.Split(new[] { '\n' }); int set = 0; int indeks = 0; for (int i = 0; i < lines.Length - 1; i++) { string[] split = DVRPHelper.SplitText(lines[i]); switch (split[0]) { case "NUMSETS": pd2s.partial = new int[int.Parse(split[1])][]; pd2s.NodeNumber = int.Parse(split[2]); break; case "SET": set = int.Parse(split[1]); pd2s.partial[set] = new int[int.Parse(split[2])]; //set++; break; default: for (int j = 0; j < split.Length; j++) { pd2s.partial[set][j] = int.Parse(split[j]); } break; } } return(pd2s); }
public static int[][] ParsePartialProblemData(byte[] data) { int[][] result = new int[0][]; string text = Communication_Library.CommunicationModule.ConvertDataToString(data, data.Length); string[] lines = text.Split(new[] { '\n' }); int set = 0; int indeks = 0; for (int i = 0; i < lines.Length - 1; i++) { string[] split = DVRPHelper.SplitText(lines[i]); switch (split[0]) { case "NUMSETS": result = new int[int.Parse(split[1])][]; indeks = int.Parse(split[2]); break; case "SET": set = int.Parse(split[1]); result[set] = new int[int.Parse(split[2])]; //set++; break; default: for (int j = 0; j < split.Length; j++) { result[set][j] = int.Parse(split[j]); } break; } } return(result); }
public static DVRP Parse(string input) { if (String.IsNullOrWhiteSpace(input)) { throw new ArgumentException(input); } var instance = new DVRP(); var lines = input.Split(new[] { '\n' }); for (int i = 0; i < lines.Length; i++) { string[] split = DVRPHelper.SplitText(lines[i]); switch (split[0]) { case "VRPTEST": instance.FormatVersionNumber = split[1]; break; case "COMMENT": instance.Comment += lines[i].Substring(9, lines[i].Length - 9).Trim(new Char[] { ' ', '\r' }); // split[j] + " "; break; case "NAME": instance.Name = split[1]; break; case "NUM_DEPOTS": instance.NumDepots = int.Parse(split[1]); instance.Depots = new Depot[instance.NumDepots]; break; case "NUM_CAPACITIES": instance.NumCapacities = int.Parse(split[1]); break; case "NUM_VISITS": instance.NumVistis = int.Parse(split[1]); instance.Clients = new Client[instance.NumVistis]; instance.ClientID = new int[instance.NumVistis]; break; case "NUM_LOCATIONS": instance.NumLocations = int.Parse(split[1]); instance.Locations = new Location[instance.NumLocations]; break; case "NUM_VEHICLES": instance.NumVehicles = int.Parse(split[1]); break; case "CAPACITIES": instance.Capacities = int.Parse(split[1]); break; //case "DATA_SECTION": case "DEPOTS": for (int j = 0; j < instance.NumDepots; j++) { instance.Depots[j] = new Depot(); instance.Depots[j].depotID = int.Parse(lines[++i]); } break; case "DEMAND_SECTION": for (int j = 0; j < instance.NumVistis; j++) { instance.Clients[j] = new Client(); string[] clientsSplit = DVRPHelper.SplitText(lines[++i]); instance.Clients[j].visitID = int.Parse(clientsSplit[0]); instance.Clients[j].size = int.Parse(clientsSplit[1]); instance.ClientID[j] = j;//int.Parse(clientsSplit[0]); } break; case "LOCATION_COORD_SECTION": for (int j = 0; j < instance.NumLocations; j++) { instance.Locations[j] = new Location(); string[] locationsSplit = DVRPHelper.SplitText(lines[++i]); instance.Locations[j].locationID = int.Parse(locationsSplit[0]); instance.Locations[j].x = int.Parse(locationsSplit[1]); instance.Locations[j].y = int.Parse(locationsSplit[2]); } break; case "DEPOT_LOCATION_SECTION": for (int j = 0; j < instance.NumDepots; j++) { string[] depotLocationsSplit = DVRPHelper.SplitText(lines[++i]); int depotId = int.Parse(depotLocationsSplit[0]); instance.Depots.First(x => x.depotID == depotId).locationID = int.Parse(depotLocationsSplit[1]); } break; case "VISIT_LOCATION_SECTION": for (int j = 0; j < instance.NumVistis; j++) { string[] clientsSplit = DVRPHelper.SplitText(lines[++i]); int visitId = int.Parse(clientsSplit[0]); instance.Clients.First(x => x.visitID == visitId).locationID = int.Parse(clientsSplit[1]); } break; case "DURATION_SECTION": for (int j = 0; j < instance.NumVistis; j++) { string[] clientsSplit = DVRPHelper.SplitText(lines[++i]); int visitId = int.Parse(clientsSplit[0]); instance.Clients.First(x => x.visitID == visitId).unld = double.Parse(clientsSplit[1]); } break; case "DEPOT_TIME_WINDOW_SECTION": for (int j = 0; j < instance.NumDepots; j++) { string[] depotLocationsSplit = DVRPHelper.SplitText(lines[++i]); int depotId = int.Parse(depotLocationsSplit[0]); Depot d = instance.Depots.First(x => x.depotID == depotId); d.start = double.Parse(depotLocationsSplit[1]); d.end = double.Parse(depotLocationsSplit[2]); } break; //COMMENT: TIMESTEP: 7 case "TIME_AVAIL_SECTION": for (int j = 0; j < instance.NumVistis; j++) { string[] clientsSplit = DVRPHelper.SplitText(lines[++i]); int visitId = int.Parse(clientsSplit[0]); instance.Clients.First(x => x.visitID == visitId).time = double.Parse(clientsSplit[1]); } break; case "EOF": break; } } instance.distances = new double[instance.Locations.Length, instance.Locations.Length]; for (int j = 0; j < instance.Locations.Length; j++) { for (int k = 0; k < instance.Locations.Length; k++) { instance.distances[j, k] = DVRPHelper.Distance(instance.Locations[j], instance.Locations[k]); } } return(instance); }
public static DVRPPartialSolution Parse(string input, DVRP dvrp) { if (String.IsNullOrWhiteSpace(input)) { throw new ArgumentException(input); } DVRPPartialSolution instance = new DVRPPartialSolution(); //instance.ElemCount = new List<int>(); var lines = input.Split(new[] { '\n' }); int ind = 0; for (int i = 0; i < lines.Length - 1; i++) { string[] split = DVRPHelper.SplitText(lines[i]); switch (split[0]) { case "SOL": instance.ElemCount = int.Parse(split[1]); instance.PartialPaths = new List <Location> [int.Parse(split[1])]; instance.PartialPathsArrivalsTimes = new List <double> [int.Parse(split[1])]; instance.PartialPathLen = new List <double>(); instance.PartialClientID = new List <int> [int.Parse(split[1])]; instance.NodeNumber = int.Parse(split[2]); break; case "SET": i++; split = DVRPHelper.SplitText(lines[i]); instance.PartialClientID[ind] = new List <int>(); for (int n = 0; n < split.Length; n++) { instance.PartialClientID[ind].Add(int.Parse(split[n])); } ind++; break; case "SOLUTION": instance.PartialPathLen.Add(Double.Parse(split[2])); break; case "PATH": instance.PartialPaths[ind] = new List <Location>(); for (int n = 1; n < split.Length; n++) { if (int.Parse(split[n]) != -1) { instance.PartialPaths[ind].Add(dvrp.Locations.First(x => x.locationID == int.Parse(split[n]))); } else { instance.PartialPaths[ind].Add(new Location() { locationID = -1 }); } } break; case "TIMES": instance.PartialPathsArrivalsTimes[ind] = new List <double>(); for (int n = 1; n < split.Length; n++) { instance.PartialPathsArrivalsTimes[ind].Add(double.Parse(split[n])); } break; } } return(instance); }