Beispiel #1
0
        /****************************************/
        // TrainConnections' related methods
        /****************************************/

        /// <summary>
        /// Funtion creates trainConnecion off path of (optimalized) edges.
        /// </summary>
        /// <param name="edges"></param>
        /// <returns></returns>
        public static TrainConnection createTrainConnection(List <Edge> edges)
        {
            // if there is path with length 0 or list of edges doesn't exist
            if (edges.Count.Equals(0) || edges.Equals(null))
            {
                return(null);
            }
            // determine start and destination station
            TrainStation from = edges[0].FromStation;
            TrainStation to   = edges[edges.Count - 1].ToStation;

            // createConstraintSet new connection with start and destination stattion, and path of edges
            TrainConnection connection = new TrainConnection(from, to, edges);

            // randomizeTimetable changing station and set them in connection
            connection.setChangingStation(TrainConnection.generateChangingStation(edges));
            // randomizeTimetable variableLines of connection and set them in connection
            connection.setLinesOfConnection(TrainConnection.generateLinesOfConnection(edges));

            // calculate other variabiles
            connection.calculateDistance();
            connection.calculatePassengers();
            connection.calculateTime();

            return(connection);
        }
        //-----------------------------------------------------
        // Methods generating STAGES based on CONNECTION
        //-----------------------------------------------------

        /// <summary>
        /// Function generates and returns all stages existed at trainConnection.
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        public static List <Stage> generateStages(TrainConnection connection)
        {
            List <Stage> stages = new List <Stage>();

            TrainStation from = connection.FromStation;

            // randomizeTimetable changing station according edges
            List <TrainStation> changingStation = TrainConnection.generateChangingStation(connection.getEdges());

            // loop over all changing station at connection
            foreach (TrainStation station in changingStation)
            {
                // randomizeTimetable connection
                Stage stage = generateStage(connection.getEdges(), from, station);
                // if exists, then addConstraint
                if (stage != null)
                {
                    stages.Add(stage);
                }

                // set up actual toStation as a fromStation for next loop
                from = station;
            }

            // randomizeTimetable last stage
            Stage lastStage = generateStage(connection.getEdges(), from, connection.ToStation);

            // if exists, then addConstraint last stage
            if (lastStage != null)
            {
                stages.Add(lastStage);
            }

            return(stages);
        }
        private void prepareListViewListOfStations(int lineNumber)
        {
            // get trainLine1 on lineNumber
            TrainLine trainLine = TrainLineCache.getInstance().getCacheContentOnNumber(lineNumber);
            // get trainStop of line_
            List <TrainStop> stops = trainLine.getTrainStops();

            // starting update list, protected before method Draw
            listViewListOfStations.BeginUpdate();
            // clearStableLines previous list's items
            listViewListOfStations.Items.Clear();
            // and prepare new list view accordind trainStops of line_
            foreach (TrainStop stop in stops)
            {
                // get station of stop
                TrainStation station = stop.TrainStation;

                ListViewItem lvi = new ListViewItem();
                // fill item with throughStation's information
                lvi.Text = station.Id.ToString();
                lvi.Tag  = station.Id.ToString();

                lvi.SubItems.Add(station.Name);
                lvi.SubItems.Add(station.TownCategory.ToString());
                lvi.SubItems.Add(station.Inhabitation.ToString());
                lvi.SubItems.Add(station.Town);

                // addConstraint item into the list
                listViewListOfStations.Items.Add(lvi);
            }
            // release list view
            listViewListOfStations.EndUpdate();
        }
Beispiel #4
0
        public static TrainStation findChangingStation(List <Stage> stages, int line1, int line2)
        {
            TrainStation station       = null;
            Stage        previousStage = null;

            // loop over all stages in path
            foreach (Stage stage in stages)
            {
                // if previous stage doesn' exist, than continue with next stage
                if (previousStage == null)
                {
                    previousStage = stage;
                    continue;
                }
                if (previousStage.LineNumber.Equals(line1) && stage.LineNumber.Equals(line2))
                {
                    station = stage.FromStation;
                    break;
                }

                previousStage = stage;
            }

            return(station);
        }
Beispiel #5
0
        /// <summary>
        /// Returns arrival on specified station within this line.
        /// </summary>
        /// <param name="station">The station.</param>
        /// <returns></returns>
        public Time arrivalOnStation(TrainStation station)
        {
            TrainStop stop = trainLine.getTrainStopOnStation(station.Name);
            Time      time;

            // if arrival is not equal 00:00
            if (!stop.TimeArrival.Equals(Time.MinValue))
            {
                time = stop.TimeArrival;
            }
            else
            {
                // if stop is the first, there no arrival exists
                if (stop.OrderInTrainLine.Equals(0))
                {
                    time = Time.EmptyValue;
                }
                // otherwise (time is 00:00 but the stop is not first) use departure
                else
                {
                    time = stop.TimeDeparture;
                }
            }

            return(time);
        }
        /// <summary>
        /// Updates the field town category for stations from file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        public static void updateStationDetailsFromFile(String fileName)
        {
            List <StationDetail> stationDetails = IOUtil.readTrainStationFromFile(fileName);

            foreach (StationDetail stationDetail in stationDetails)
            {
                // if station exits in train station cache
                if (TrainStationCache.getInstance().doesStationExist(stationDetail.StationName))
                {
                    // find station in cache
                    TrainStation s = TrainStationCache.getInstance()
                                     .getCacheContentOnName(stationDetail.StationName);
                    // copy inhabitation
                    s.Inhabitation = stationDetail.Inhabitation;
                    // update town category according inhabitation
                    s.updateTownCategory();

                    if (stationDetail.MinimalTransferTime != Time.EmptyValue)
                    {
                        s.MinimalTransferTime = stationDetail.MinimalTransferTime;
                    }

                    if (stationDetail.Town != "")
                    {
                        s.Town = stationDetail.Town;
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns departures from specified station with in this line.
        /// </summary>
        /// <param name="station">The station.</param>
        /// <returns>The arrival time.</returns>
        public Time departureFromStation(TrainStation station)
        {
            TrainStop stop = trainLine.getTrainStopOnStation(station.Name);
            Time      time;

            // if departure is not equal 00:00
            if (!stop.TimeDeparture.Equals(Time.MinValue))
            {
                time = stop.TimeDeparture;
            }
            else
            {
                // if stop is a first one, there it is a legal time, use it
                if (stop.OrderInTrainLine.Equals(0))
                {
                    time = stop.TimeDeparture;
                }
                // otherwise (time is 00:00 but the stop is not first)
                else
                {
                    // it has to be last stop, which has no departure (not continue)
                    time = Time.EmptyValue;
                }
            }

            return(time);
        }
        /// <summary>
        /// Function finds and returns a list of stages generated off first station.
        /// Finds all next transfers stages.
        /// </summary>
        /// <param name="off"></param>
        /// <returns></returns>
        public static List <Stage> findNextTransferStages(TrainStation from)
        {
            List <Stage> stages = new List <Stage>();
            // retreive all available trainLine1 passing trough toStation of previousStage
            List <TrainLine> availableTrainLines = from.getTrainLines();

            // loop over all available trainLines
            foreach (TrainLine line in availableTrainLines)
            {
                // find all available possible changing station on trainLine1
                List <TrainStation> changingStations = findChangingStationOnTrainLine(line);
                // loop over all changing station
                foreach (TrainStation to in changingStations)
                {
                    // randomizeTimetable stage on line between stations off and to
                    Stage stage = generateStage(line, from, to);
                    // if exists
                    if (stage != null)
                    {
                        // addConstraint to stages
                        stages.Add(stage);
                    }
                }
            }
            return(stages);
        }
Beispiel #9
0
        public FormDetailsOfStation(TrainStation station)
        {
            InitializeComponent();
            trainStation = station;

            comboBoxCategory.DataSource = Enum.GetValues(typeof(TownCategory));
            fillStationInformation();
        }
Beispiel #10
0
 public TrainConnection(TrainStation from, TrainStation to, List <Edge> edges_)
 {
     setDefaultValues();
     fromStation = from;
     toStation   = to;
     edges       = edges_;
     createTrainConnection(edges_);
 }
        /// <summary>
        /// Function randomizeTimetable stage off a train line, only between stations off and to.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="off"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static Stage generateStage(TrainLine line, TrainStation from, TrainStation to)
        {
            List <Edge> edges = FloydWarshallUtil.createEdges(line);

            return(generateStage(edges, from, to));
            // with null checking
            //return generateStage(edges);
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Stage"/> class.
 /// </summary>
 /// <param name="from">From station.</param>
 /// <param name="to">To station.</param>
 /// <param name="line_">By the line.</param>
 public Stage(TrainStation from, TrainStation to, TrainLine line_)
 {
     edges       = FloydWarshallUtil.createEdges(line_, from, to);
     line        = line_;
     fromStation = from;
     toStation   = to;
     time        = TrainConnection.calculateTime(edges);
     distance    = TrainConnection.calculateDistance(edges);
 }
Beispiel #13
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="station">The station.</param>
 public TrainStation(TrainStation station)
 {
     this.id           = station.id;
     this.stationName  = station.stationName;
     this.inhabitation = station.inhabitation;
     this.townCategory = station.townCategory;
     this.track        = station.track;
     this.trainLines   = station.trainLines;
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Stage"/> class.
 /// </summary>
 /// <param name="edges_">The list of edges.</param>
 public Stage(List <Edge> edges_)
 {
     edges       = edges_;
     line        = TrainLineCache.getInstance().getCacheContentOnNumber(edges[0].Line);
     fromStation = edges[0].FromStation;
     toStation   = edges[edges.Count - 1].ToStation;
     time        = TrainConnection.calculateTime(edges);
     distance    = TrainConnection.calculateDistance(edges);
 }
Beispiel #15
0
 public Edge()
 {
     from        = -1;
     to          = -1;
     time        = Time.MaxValue;
     distance    = int.MaxValue;
     line        = 0;
     fromStation = null;
     toStation   = null;
 }
Beispiel #16
0
 /// <summary>
 /// Method sets default values for variables of this instance.
 /// </summary>
 private void setDefaultValues()
 {
     fromStation       = null;
     toStation         = null;
     edges             = new List <Edge>();
     passengers        = 0;
     time              = Time.MinValue;
     linesOfConnection = new List <TrainLine>();
     changingStations  = new List <TrainStation>();
 }
 /// <summary>
 /// Sets the default values of private fields.
 /// </summary>
 private void setDefaultValues()
 {
     off        = 0;
     on         = 0;
     stationID  = -1;
     passengers = 0;
     offLine    = null;
     onLine     = null;
     station    = null;
 }
Beispiel #18
0
 public Edge(int from_, int to_, Time time_, int distance_, int line_)
 {
     from        = from_;
     fromStation = TrainStationCache.getInstance().getCacheContentOnSelect(from_);
     to          = to_;
     toStation   = TrainStationCache.getInstance().getCacheContentOnSelect(to_);
     time        = time_;
     distance    = distance_;
     line        = line_;
 }
Beispiel #19
0
 public Edge(TrainStation from_, TrainStation to_, Time time_, int distance_, int line_)
 {
     fromStation = from_;
     from        = fromStation.Id;
     toStation   = to_;
     to          = toStation.Id;
     time        = time_;
     distance    = distance_;
     line        = line_;
 }
Beispiel #20
0
        /// <summary>
        /// Function determine if specific connection off to already exists/
        /// </summary>
        /// <param name="off"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public Boolean doesConnectionExist(TrainStation from, TrainStation to)
        {
            Boolean exists = true;

            // try to find connection, if null value returns, connection doesn't exist
            if (findConnection(from, to) == null)
            {
                exists = false;
            }

            return(exists);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Transfer"/> class.
 /// </summary>
 /// <param name="off_">The line, transfer off.</param>
 /// <param name="on_">The line, transfer on.</param>
 /// <param name="station_">The station, where transfers at.</param>
 public Transfer(TrainLine off_, TrainLine on_, TrainStation station_)
 {
     setDefaultValues();
     offLine   = off_;
     onLine    = on_;
     off       = off_.LineNumber;
     on        = on_.LineNumber;
     stationID = station_.Id;
     station   = station_;
     // indices
     trainStopIndexOffLine = off_.getTrainStopOnStation(station).OrderInTrainLine;
     trainStopIndexOnLine  = on_.getTrainStopOnStation(station).OrderInTrainLine;
 }
Beispiel #22
0
        /// <summary>
        /// Gets the cache content on select.
        /// </summary>
        /// <param name="idStation">The id of station.</param>
        /// <returns>Train Station</returns>
        public TrainStation getCacheContentOnSelect(int idStation)
        {
            TrainStation station = null;

            foreach (TrainStation s in cacheContent) //loop all stations
            {
                if (s.Id.Equals(idStation))          //searching for the same idStation
                {
                    station = s;                     //if found, then break
                    break;
                }
            }
            return(station);
        }
        //-----------------------------------------------------
        // Method generating ALL AVAILABLE STAGES
        //-----------------------------------------------------

        /// <summary>
        /// Function finds and returns a list of stages generated off first station.
        /// Finds all available transfers stages and available final stage.
        /// </summary>
        /// <param name="off"></param>
        /// <param name="toStation"></param>
        /// <returns></returns>
        public static List <Stage> findAvailableStages(TrainStation fromStation, TrainStation toStation)
        {
            List <Stage> availableStages = new List <Stage>();

            // find all stages from start station to all possible changing stations
            availableStages.AddRange(findNextTransferStages(fromStation));

            // if toStation is also transfer station, is already included, if not find for the posibiliy of direct stage
            if (toStation.Transfers.Count == 0)
            {
                availableStages.AddRange(findNextFinalStages(fromStation, toStation));
            }
            return(availableStages);
        }
Beispiel #24
0
 /// <summary>
 /// Sets the default values.
 /// </summary>
 private void setDefaultValues()
 {
     this.trainStation         = null;
     this.trainLine            = -1;
     this.timeFromStart        = Time.EmptyValue;
     this.timeFromPreviousStop = Time.EmptyValue;
     this.timeDeparture        = Time.MinValue;
     this.timeArrival          = Time.MinValue;
     this.platform             = -1;
     this.orderInTrainLine     = -1;
     this.kmFromStart          = -1;
     this.kmFromPreviousStop   = -1;
     this.daysInWeek           = 0;
 }
Beispiel #25
0
        /// <summary>
        /// Function finds connection between station off and to.
        /// </summary>
        /// <param name="off"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private TrainConnection findConnection(TrainStation from, TrainStation to)
        {
            TrainConnection connection = null;

            foreach (TrainConnection c in trainConnections)
            {
                if (c.FromStation.Equals(from) && c.ToStation.Equals(to))
                {
                    connection = c;
                    break;
                }
            }

            return(connection);
        }
        /// <summary>
        /// Function finds and return index of edge with toStation in list of edges.
        /// </summary>
        /// <param name="stops"></param>
        /// <param name="station"></param>
        /// <returns></returns>
        private static int findToStation(List <Edge> edges, TrainStation toStation)
        {
            int index = -1;

            for (int i = 0; i < edges.Count; i++)
            {
                // if station of stops equals the id of finding station
                if (edges[i].ToStation.Id.Equals(toStation.Id))
                {
                    index = i;
                    break;
                }
            }

            return(index);
        }
Beispiel #27
0
        /// <summary>
        /// Finds the station in cache.
        /// </summary>
        /// <param name="stationName">The name of train station.</param>
        /// <returns>Train station</returns>
        private TrainStation findStation(String stationName)
        {
            //set default
            TrainStation station = null;

            //loop all throughStation
            foreach (TrainStation s in cacheContent)
            {
                //if stationName found
                if (s.Name.Equals(stationName))
                {
                    //return throughStation
                    station = s;
                    break;
                }
            }
            return(station);
        }
        //-----------------------------------------------------
        // Method generating NEXT FINAL STAGES
        //-----------------------------------------------------

        /// <summary>
        /// Function finds and returns a list of final stage
        /// generated off previous stage and toStation.
        /// </summary>
        /// <param name="previousStage"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static List <Stage> findNextFinalStages(TrainStation from, TrainStation to)
        {
            List <Stage> stages = new List <Stage>();
            // retreive all available trainLine1 passing trough toStation of previousStage
            List <TrainLine> availableTrainLines = from.getTrainLines();

            // loop over all available trainLines
            foreach (TrainLine line in availableTrainLines)
            {
                Stage stage = generateStage(line, from, to);

                // if exists
                if (stage != null)
                {
                    // addConstraint to stages
                    stages.Add(stage);
                }
            }
            return(stages);
        }
Beispiel #29
0
        /// <summary>
        /// Function creates trainConnecion off path of (optimalized) edges.
        /// </summary>
        /// <param name="edges"></param>
        /// <returns></returns>
        public void createTrainConnection(List <Edge> edges_)
        {
            // if there is path with length 0 or list of edges doesn't exist
            if (edges_.Count.Equals(0) || edges_.Equals(null))
            {
                return;
            }
            // determine start and destination station
            fromStation = edges_[0].FromStation;
            toStation   = edges_[edges_.Count - 1].ToStation;
            // set the edges
            edges = edges_;
            // randomizeTimetable local variables
            generateStages();

            generateLinesOfConnection();
            generateChangingStation();
            calculateTime();
            calculateDistance();
            calculatePassengers();
        }
Beispiel #30
0
        /// <summary>
        /// Gets the train stop on station.
        /// </summary>
        /// <param name="stationName">Name of the station.</param>
        /// <returns>The train stop.</returns>
        public TrainStop getTrainStopOnStation(TrainStation station)
        {
            TrainStop newStop = null;

            // not initialized
            if (trainStops == null)
            {
                return(null);
            }

            foreach (TrainStop stop in trainStops)
            {
                if (stop.TrainStation == station)
                {
                    newStop = stop;
                    break;
                }
            }

            return(newStop);
        }