//-----------------------------------------------------
        // 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);
        }
Пример #2
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);
        }