示例#1
0
        private static List<Route> ParseRoutes(string testCase)
        {
            var result = new List<Route>();
            var routeStrings = testCase.Trim().Split('|').Select(s => s.Trim()).ToList();
            result =
                routeStrings.Select(routeString =>
                {
                    var route = new Route();

                    route.Id = routeString[0].ToString();
                    route.DayNum = int.Parse(routeString[2].ToString());
                    for (int i = 4; i < routeString.Length - 1; i++)
                    {
                        string stopString = routeString[i].ToString();
                        var stop = new Stop();
                        stop.Location = stopString;
                        route.Stops.Add(stop);
                    }

                    route.Stops.First().IsDepot = true;
                    route.Stops.Last().IsDepot = true;

                    return route;
                }).ToList();
            return result;
        }
示例#2
0
        private static string ReportDiff(List<Route> history, Route template)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"Template DAY:{template.DayNum} ID:{template.Id}");

            foreach(var stop in template.Stops)
            {

                if (stop.IsDepot)
                {
                    sb.AppendLine($"{stop.Location}");
                }
                else
                {
                    double routeAffinity = 0;
                    double sequenceAffinity = 0;
                    double buddyAffinity = 0;

                    var matches = history.Select(r => r.StopsString).Where(r => r.Contains(stop.Location)).ToList();

                    if (matches.Count > 0)
                    {
                        routeAffinity = 100 * (double)matches.Count / (double)history.Count;

                        double templateSequence = template.StopsString.IndexOf(stop.Location);
                        double avgSequence = matches.Average(m => m.IndexOf(stop.Location));
                        double offset = Math.Abs(templateSequence - avgSequence);
                        double normalizedOffset = offset / template.StopsString.Length;
                        sequenceAffinity =  100 * (1.0 - normalizedOffset);

                        char previousStop = template.StopsString[(int)templateSequence - 1];
                        var prevBuddyMatches = matches.Where(m => m[m.IndexOf(stop.Location) - 1] == previousStop).ToList();
                        char nextStop = template.StopsString[(int)templateSequence + 1];
                        var nextBuddyMatches = matches.Where(m => m[m.IndexOf(stop.Location) + 1] == nextStop).ToList();
                        double avgBuddyMatches = ((double)prevBuddyMatches.Count + (double)nextBuddyMatches.Count) / 2.0;
                        buddyAffinity = 100.0 * avgBuddyMatches / (double)matches.Count;
                    }
                    sb.Append($"{stop.Location}  ");
                    sb.Append($"Route Match: {((int)routeAffinity).ToString().PadLeft(3)}%  ");
                    sb.Append($"Sequence Match: {((int)sequenceAffinity).ToString().PadLeft(3)}%  ");
                    sb.Append($"Buddy Match: {((int)buddyAffinity).ToString().PadLeft(3)}%  ");
                    sb.AppendLine();
                }

            }

            sb.AppendLine("----------------");
            sb.AppendLine("Matching History...");
            foreach(var r in history)
            {
                sb.AppendLine(r.SummaryString);
            }
            return sb.ToString();
        }
示例#3
0
        public static List<Route> Solve(List<Route> testCase)
        {
            List<Route> solution = new List<Route>();

            Route r = new Route();
            r.Id = "1";
            r.DayNum = 1;
            r.Stops.AddRange(testCase.First().Stops);

            solution.Add(r);

            return solution;
        }