Beispiel #1
0
        public MRTRoute(MRTExit from, MRTLink[] links)
        {
            this.from        = from;
            this.links       = links;
            this.Description = from.name;
            string lastRouteID = this.links[0].routeID;

            if (this.links.Count() < 2)
            {
                this.Description += string.Format(" -{0}-> {1}", this.links.Last().routeID, this.links.Last().to.name);
                return;
            }
            for (int x = 1; x < this.links.Count(); x++)
            {
                MRTLink link = this.links[x];
                if (link.routeID != lastRouteID)
                {
                    this.Description += string.Format(" -{0}-> {1}", lastRouteID, this.links[x - 1].to.name);
                    TransionCount++;
                }
                lastRouteID = link.routeID;
            }

            this.Description += string.Format(" -{0}-> {1}", this.links.Last().routeID, this.links.Last().to.name);
        }
Beispiel #2
0
        public MRTRoute[] FindRoutes(string from, string to)
        {
            if (from == null)
            {
                throw new Exception("from is null");
            }
            else if (to == null)
            {
                throw new Exception("to is null");
            }
            else if (from == to)
            {
                throw new Exception("Begin and destination should be different.");
            }

            MRTExit fromExit = this.exits[from];
            MRTExit toExit   = this.exits[to];

            if (fromExit == null)
            {
                throw new Exception("Unable to find this exit as begin.");
            }
            else if (toExit == null)
            {
                throw new Exception("Unable to find this exit as destination.");
            }
            MRTRouteFinder finder = new MRTRouteFinder(fromExit, toExit);

            return(finder.routes);
        }
Beispiel #3
0
        private void Load()
        {
            string data = MRTData.data;

            foreach (string line in data.Split('\r'))
            {
                string[] components = line.Split(',');
                if (components.Length == 3)
                {
                    string routeID = components[0];
                    string from    = components[1];
                    string to      = components[2];

                    if (!this.exits.ContainsKey(from))
                    {
                        this.exits.Add(from, new MRTExit(from));
                    }

                    if (!this.exits.ContainsKey(to))
                    {
                        this.exits.Add(to, new MRTExit(to));
                    }
                    MRTExit fromExit = this.exits[from];
                    MRTExit toExit   = this.exits[to];
                    fromExit.AddLink(routeID, toExit);
                    toExit.AddLink(routeID, fromExit);
                }
            }
        }
Beispiel #4
0
 public MRTRouteFinder(MRTExit fromExit, MRTExit toExit)
 {
     this.fromExit = fromExit;
     this.toExit   = toExit;
     this.travelLinksOfExit(fromExit);
     this.foundRoutes.Sort((a, b) => a.CompareTo(b));
 }
Beispiel #5
0
 void travelLinksOfExit(MRTExit exit)
 {
     MRTLink[] links = exit.links.ToArray();
     foreach (MRTLink link in links)
     {
         if (link.to == this.toExit)
         {
             visitedLinks.Push(link);
             List <MRTLink> copy = this.visitedLinks.ToList();
             copy.Reverse();
             foundRoutes.Add(new MRTRoute(this.fromExit, copy.ToArray()));
             visitedLinks.Pop();
         }
         else if (!visitedExits.Contains(link.to))
         {
             visitedExits.Push(exit);
             visitedLinks.Push(link);
             travelLinksOfExit(link.to);
             visitedExits.Pop();
             visitedLinks.Pop();
         }
     }
 }
Beispiel #6
0
        public void AddLink(string routeID, MRTExit to)
        {
            MRTLink link = new MRTLink(routeID, to);

            this.links.Add(link);
        }