Inheritance: ICloneable
Esempio n. 1
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);
        }
Esempio n. 2
0
        // returns flights that match parameters
        public Flight[] flightsForTime(FlightTime flttime, String fltday, int tolerance)
        {
            // day index, 0 is monday, etc.
            // tolerance is in minutes
            // returns null if not found

            ArrayList  flights = new ArrayList(0);
            FlightTime time    = (FlightTime)flttime.Clone();
            String     day     = (String)fltday.Clone();

            if (time.nextDay)
            {
                day          = FlightTime.dayByAddingDays(day, 1);
                time.nextDay = false;
            }

            time.addMinutes(tolerance);

            foreach (Flight flt in __flights)
            {
                if (flt.hasFlightAtTime(time, day))
                {
                    flights.Add(flt);
                }
            }

            return((Flight[])flights.ToArray(typeof(Flight)));
        }
Esempio n. 3
0
        // checks to see if a path is valid. used by route finding
        private bool validPath(String[] path, FlightTime start, String day, int tolerance)
        {
            Route      rte;
            FlightTime currentTime = (FlightTime)start.Clone();
            String     currentDay  = day;

            Flight[] flts;

            for (int i = 0; i < (path.Length - 1); i++)
            {
                rte = routesForParameters(path[i], path[i + 1])[0];
                if (rte.hasFlightsForTime(currentTime, currentDay, tolerance))
                {
                    flts        = rte.flightsForTime(currentTime, currentDay, tolerance);
                    currentTime = (FlightTime)flts[0].Arrival.Clone();
                    if (currentTime.nextDay)
                    {
                        currentTime.nextDay = false;
                        currentDay          = FlightTime.dayByAddingDays(day, 1);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 4
0
        public int compareFlightTime(FlightTime candidate)
        { // returns -1 for less then, 0 for equals and 1 for more than
            // check for similarity
            if ((candidate.nextDay == this.nextDay) && (candidate.hour == this.hour) && (candidate.min == this.min))
            {
                return(0);
            }

            // deal with larger than
            if ((candidate.nextDay) && (!this.nextDay))
            {
                return(1);
            }

            if (candidate.hour > this.hour)
            {
                return(1);
            }

            if ((candidate.hour == this.hour) && (candidate.min > this.min))
            {
                return(1);
            }

            return(-1);
        }
Esempio n. 5
0
 // checks if there are flights for the parameters set
 public bool hasFlightsForTime(FlightTime time, String day, int tolerance)
 {
     if (this.flightsForTime((FlightTime)time.Clone(), day, tolerance).Length > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 6
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;
                }
            }
        }
Esempio n. 7
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;
                }

            }
        }
Esempio n. 8
0
        public ArrayList flightsForOriginDest(String origin, String dest, FlightTime start, String day, int tolerance)
        {
            // return paths that match the parameters
            ArrayList temp    = pathsForOriginDest(origin, dest, start, day, tolerance);
            ArrayList flights = new ArrayList(0);

            // build path using route objects
            foreach (String[] route in temp)
            {
                // find arraylist of arrays of flights for this route;
                flights.AddRange(flightsForRoute(routeForPath(route), start, day, tolerance));
            }

            return(flights);
        }
Esempio n. 9
0
        public ArrayList pathsForOriginDest(String origin, String dest, FlightTime start, String day, int tolerance)
        {
            ArrayList routes        = pathsForOriginDest(origin, dest);
            ArrayList matchedRoutes = new ArrayList(0);

            foreach (String[] path in routes)
            {
                if (validPath(path, start, day, tolerance))
                {
                    matchedRoutes.Add(path);
                }
            }

            return(matchedRoutes);
        }
Esempio n. 10
0
 public bool hasFlightAtTime(FlightTime time, String day)
 { // returns true if time given is before flight
     if (this.departure.compareFlightTime(time) <= 0)
     {
         if (time.nextDay)
         {
             return(daysFlying[FlightTime.indexForDayByAddingDays(day, 1)]);
         }
         else
         {
             return(daysFlying[FlightTime.indexForDay(day)]);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        public int compareFlightTime(FlightTime candidate)
        {
            // returns -1 for less then, 0 for equals and 1 for more than

            // check for similarity
            if ((candidate.nextDay == this.nextDay) && (candidate.hour == this.hour) && (candidate.min == this.min))
                return 0;

            // deal with larger than
            if ((candidate.nextDay) && (!this.nextDay))
                return 1;

            if (candidate.hour > this.hour)
                return 1;

            if ((candidate.hour == this.hour) && (candidate.min > this.min))
                return 1;

            return -1;
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
 public object Clone()
 {
     FlightTime copy = new FlightTime(this.hour, this.min, this.nextDay);
     return copy;
 }
Esempio n. 15
0
 // checks if there are flights for the parameters set
 public bool hasFlightsForTime(FlightTime time, String day, int tolerance)
 {
     if (this.flightsForTime((FlightTime)time.Clone(), day, tolerance).Length > 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 16
0
        // returns flights that match parameters
        public Flight[] flightsForTime(FlightTime flttime, String fltday, int tolerance)
        {
            // day index, 0 is monday, etc.
            // tolerance is in minutes
            // returns null if not found

            ArrayList flights = new ArrayList(0);
            FlightTime time = (FlightTime)flttime.Clone();
            String day = (String)fltday.Clone();

            if (time.nextDay)
            {
                day = FlightTime.dayByAddingDays(day, 1);
                time.nextDay = false;
            }

            time.addMinutes(tolerance);

            foreach (Flight flt in __flights)
            {
                if (flt.hasFlightAtTime(time, day))
                {
                    flights.Add(flt);
                }
            }

            return (Flight[])flights.ToArray(typeof(Flight));
        }
Esempio n. 17
0
        private void button1_Click(object sender, EventArgs e)
        {
            String day = dateTimePicker1.Value.DayOfWeek.ToString().Substring(0,2);
            String dayReturn = dateTimePicker2.Value.DayOfWeek.ToString().Substring(0, 2);

            String origin = comboBox1.SelectedValue.ToString();
            String dest = comboBox2.SelectedValue.ToString();

            FlightTime start = new FlightTime(dateTimePicker1.Value.Hour, dateTimePicker1.Value.Minute, false);
            FlightTime returnTime = new FlightTime(dateTimePicker2.Value.Hour, dateTimePicker2.Value.Minute, false);
            int tolerance = (int)numericUpDown1.Value;

            toolStripComboBox1.Items.Clear();
            result.Text = "";

            ArrayList flights = tt.flightsForOriginDest(origin, dest, start, day, tolerance);

            if (checkBox1.Checked)
            {
                ArrayList returnFlights = tt.flightsForOriginDest(dest, origin, returnTime, dayReturn, tolerance);
                flights.AddRange(returnFlights);
            }

            bindingSource1.DataSource = flights;

            result.Text = bindingSource1.Count + " path(s) found";

            ArrayList routesForFlightPath = new ArrayList(0);
            String[] flightPath;
            String merged;
            for (int i = 0; i < bindingSource1.Count; i++)
            {
                routesForFlightPath.Clear();
                merged = "";

                for (int q = 0; q < ((Flight[])bindingSource1[i]).Length; q++)
                {
                    routesForFlightPath.Add(((Flight[])bindingSource1[i])[q].Route);
                }
                flightPath = Timetable.destinationsForRoute((Route[])routesForFlightPath.ToArray(typeof(Route)));

                for (int z = 0; z < flightPath.Length; z++)
                {
                    merged += flightPath[z];

                    if (z != flightPath.Length - 1)
                    {
                        merged += "-";
                    }
                }

                toolStripComboBox1.Items.Add(merged);
            }

            if (bindingSource1.Count > 0)
            {
                toggleFlightDetails(true);
                toolStripComboBox1.SelectedIndex = 0;
            }
            else
            {
                flightsBindingSource.DataSource = typeof(Flight);
                toggleFlightDetails(false);
            }
        }
Esempio n. 18
0
 public static String dayByAddingDays(String day, int days)
 {
     return(FlightTime.days[FlightTime.indexForDayByAddingDays(day, days)]);
 }
Esempio n. 19
0
        public object Clone()
        {
            FlightTime copy = new FlightTime(this.hour, this.min, this.nextDay);

            return(copy);
        }
Esempio n. 20
0
        private bool buildMultiStopTree(String origin, String dest, String[] remainingNodes, String endDay, String day, ref TreeNode <String> current, TreeNode <String> previous)
        {
            if (remainingNodes.Length == 0)
            {
                if ((pathsForOriginDest(previous.Value, current.Value, day, 0).Count > 0) &&
                    (current.Value.ToLower().Equals(dest.ToLower())))
                {
                    if (endDay == null)
                    {
                        return(true);
                    }
                    else if (day.ToLower().Equals(endDay.ToLower()))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            if (previous != null)
            {
                if (pathsForOriginDest(previous.Value, current.Value, day, 0).Count == 0)
                {
                    return(false);
                }
            }


            // obviously if those fail, something has to be done
            bool something = false;

            String currentDay = (String)day.Clone();

            if (previous != null)
            {
                Route[] rtes = routesForParameters(previous.Value, current.Value);
                if (rtes.Length > 0)
                {
                    Route    rte  = rtes[0];
                    Flight[] flts = rte.flightsForTime(new FlightTime(0, 0, false), day, 0);

                    foreach (Flight flt in flts)
                    {
                        if (flt.Arrival.nextDay)
                        {
                            currentDay = FlightTime.dayByAddingDays(currentDay, 1);
                            break;
                        }
                    }

                    currentDay = FlightTime.dayByAddingDays(currentDay, 1);
                }
                else
                {
                    return(false);
                }
            }



            TreeNode <String> node;

            for (int i = 0; i < remainingNodes.Length; i++)
            {
                node = new TreeNode <string>(remainingNodes[i]);

                if (buildMultiStopTree(origin, dest, remainingByTakingOut(remainingNodes, remainingNodes[i]), endDay, currentDay, ref node, current))
                {
                    current.Children.Add(node);
                    if (!something)
                    {
                        something = true;
                    }
                }
            }

            return(something);
        }
Esempio n. 21
0
        public ArrayList flightsForOriginDest(String origin, String dest, FlightTime start, String day, int tolerance)
        {
            // return paths that match the parameters
            ArrayList temp = pathsForOriginDest(origin, dest, start, day, tolerance);
            ArrayList flights = new ArrayList(0);

            // build path using route objects
            foreach (String[] route in temp) {
                // find arraylist of arrays of flights for this route;
                flights.AddRange(flightsForRoute(routeForPath(route), start, day, tolerance));
            }

            return flights;
        }
Esempio n. 22
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;
        }
Esempio n. 23
0
        public ArrayList pathsForOriginDest(String origin, String dest, FlightTime start, String day, int tolerance)
        {
            ArrayList routes = pathsForOriginDest(origin, dest);
            ArrayList matchedRoutes = new ArrayList(0);

            foreach (String[] path in routes)
            {
                if (validPath(path, start, day, tolerance))
                {
                    matchedRoutes.Add(path);
                }
            }

            return matchedRoutes;
        }
Esempio n. 24
0
 public bool hasFlightAtTime(FlightTime time, String day)
 {
     // returns true if time given is before flight
     if (this.departure.compareFlightTime(time) <= 0)
     {
         if (time.nextDay)
         {
             return daysFlying[FlightTime.indexForDayByAddingDays(day, 1)];
         }
         else
         {
             return daysFlying[FlightTime.indexForDay(day)];
         }
     }
     else
     {
         return false;
     }
 }
Esempio n. 25
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;
        }
Esempio n. 26
0
        // checks to see if a path is valid. used by route finding
        private bool validPath(String[] path, FlightTime start, String day, int tolerance)
        {
            Route rte;
            FlightTime currentTime = (FlightTime)start.Clone();
            String currentDay = day;
            Flight[] flts;

            for (int i = 0; i < (path.Length-1); i++)
            {
                rte = routesForParameters(path[i], path[i + 1])[0];
                if (rte.hasFlightsForTime(currentTime, currentDay, tolerance))
                {
                    flts = rte.flightsForTime(currentTime, currentDay, tolerance);
                    currentTime = (FlightTime)flts[0].Arrival.Clone();
                    if (currentTime.nextDay)
                    {
                        currentTime.nextDay = false;
                        currentDay = FlightTime.dayByAddingDays(day, 1);
                    }
                }
                else
                {
                    return false;
                }
            }

            return true;
        }