Exemple #1
0
        public Flight(String xml, Route route)
        {
            // xml parser for flight details

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            XmlElement head = doc.DocumentElement;
            this.flightNo = head.GetAttribute("no");

            this.route = route;

            Regex timeparse = new Regex("([0-9]+):([0-9]+)");

            XmlNode depart = head.SelectSingleNode("/Flight/depart");
            XmlNode arrive = head.SelectSingleNode("/Flight/arrive");
            XmlNode daysflying = head.SelectSingleNode("/Flight/operation");

            Match departMatch = timeparse.Match(depart.InnerText);
            if (departMatch.Success)
            {
                this.departure = new FlightTime(Convert.ToInt16(departMatch.Groups[1].Value), Convert.ToInt16(departMatch.Groups[2].Value), Convert.ToBoolean(depart.Attributes["nextDay"].Value));
            }

            Match arriveMatch = timeparse.Match(arrive.InnerText);
            if (arriveMatch.Success)
            {
                this.arrival = new FlightTime(Convert.ToInt16(arriveMatch.Groups[1].Value), Convert.ToInt16(arriveMatch.Groups[2].Value), Convert.ToBoolean(arrive.Attributes["nextDay"].Value));
            }

            // set default value
            for (int i = 0; i < this.daysFlying.Length; i++)
            {
                this.daysFlying[i] = false;
            }

            if ((daysflying.ChildNodes.Count == 1) && (daysflying.ChildNodes[0].InnerText.ToLower().Equals("alldays")))
            {
                for (int i = 0; i < this.daysFlying.Length; i++)
                {
                    this.daysFlying[i] = true;
                }
            }
            else
            {
                foreach (XmlNode day in daysflying)
                {
                    this.daysFlying[FlightTime.indexForDay(day.InnerText)] = true;
                }

            }
        }
Exemple #2
0
        public static String[] destinationsForRoute(Route[] routes)
        {
            ArrayList destinations = new ArrayList(0);
            destinations.Add(routes[0].Origin);
            destinations.Add(routes[0].Destination);

            if (routes.Length > 1)
            {
                for (int i = 1; i < routes.Length; i++)
                {
                    destinations.Add(routes[i].Destination);
                }
            }

            return (String[])destinations.ToArray(typeof(String));
        }
Exemple #3
0
        private void parse()
        {
            // xml parser that builds object graph
            if (!this.xmlpath.Equals(""))
            {
                XmlDocument doc = new XmlDocument();
                Route newRoute;
                doc.Load(this.xmlpath);

                XmlNodeList routes = doc.DocumentElement.SelectNodes("/Timetable/Route");
                foreach (XmlNode route in routes)
                {
                    newRoute = new Route(route.OuterXml);
                    this.__routes.Add(newRoute);

                    if (!this.__destinations.Contains(newRoute.Origin))
                        this.__destinations.Add(newRoute.Origin);

                    if (!this.__destinations.Contains(newRoute.Destination))
                        this.__destinations.Add(newRoute.Destination);

                    __routeGraph.AddDirectedEdge(newRoute.Origin, newRoute.Destination);

                    foreach (Flight flight in newRoute.Flights)
                    {
                        this.__flights.Add(flight);
                    }

                    newRoute = null;
                }
            }
        }
Exemple #4
0
        // private function to return root node for flight paths for a particular begin node
        private TreeNode<Flight> flightsTree(Route[] routes, FlightTime start, String day, int tolerance)
        {
            TreeNode<Flight> root = new TreeNode<Flight>();
            TreeNode<Flight> currentNode;

            Flight[] flights = routes[0].flightsForTime(start, day, tolerance);
            foreach (Flight flt in flights)
            {
                // do resursive shit then add to root

                currentNode = new TreeNode<Flight>(flt);
                buildFlightTree(ref currentNode, null, routes, routes[routes.Length - 1], 1, day, tolerance);
                if (currentNode.Children.Count > 0)
                    root.Children.Add(currentNode);
            }

            return root;
        }
Exemple #5
0
        // recursive magic to build the tree of flight paths
        private bool buildFlightTree(ref TreeNode<Flight> node, TreeNode<Flight> previous, Route[] routes, Route dest, int nextDestIndex, String day, int tolerance)
        {
            if (node.Value.Route == dest)
            {
                // success
                return true;
            }
            else
            {
                TreeNode<Flight> currentNode;
                bool something = false;
                Flight[] connecting = connectingForFlight(node.Value, routes[nextDestIndex].Destination, day, tolerance);
                String currentDay = (String)day.Clone();

                if (node.Value.Arrival.nextDay)
                {
                    currentDay = FlightTime.dayByAddingDays(day, 1);
                }

                foreach (Flight flt in connecting)
                {
                    currentNode = new TreeNode<Flight>(flt);
                    int ndi = nextDestIndex + 1;

                    if (ndi >= routes.Length)
                    {
                        ndi = routes.Length - 1;
                    }

                    if (buildFlightTree(ref currentNode, node, routes, dest, ndi, currentDay, tolerance))
                    {
                        node.Children.Add(currentNode);
                        if (!something)
                        {
                            something = true;
                        }
                    }

                }

                return something;
            }
        }
Exemple #6
0
        public ArrayList flightsForRoute(Route[] routes, FlightTime start, String day, int tolerance)
        {
            ArrayList flights = new ArrayList(0);

            if (routes.Length == 1)
            {
                Flight[] test;
                foreach (Flight flt in routes[0].Flights)
                {
                    test = new Flight[] { flt };
                    flights.Add(test);
                }

            }
            else if (routes.Length > 1)
            {
                // do the tree thing
                TreeNode<Flight> root = flightsTree(routes, start, day, tolerance);
                Stack<Flight> stack = new Stack<Flight>(0);

                buildFlightsArray(root, ref stack, ref flights);
            }

            return flights;
        }