/// <summary>
        /// Creates the train line variables dependent on solution.
        /// </summary>
        /// <param name="solution">The solution.</param>
        /// <param name="trainLineMap">The train line map.</param>
        /// <returns>Train line variables.</returns>
        private static List <TrainLineVariable> createTrainLineVariablesDependentOnSolution(Solution solution, List <TrainLine> trainLineMap)
        {
            // new train lines variable
            List <TrainLineVariable> newTrainLineVariables = new List <TrainLineVariable>();

            // loop index
            int index = 0;

            // for all mapped line at solution
            foreach (TrainLine line in trainLineMap)
            {
                // create a trainLine
                TrainLineVariable tlv = new TrainLineVariable(line);
                //initialize fields

                Time normalizeTime = PeriodUtil.normalizeTime(Time.ToTime(solution.SolutionVector[index].Minute), line.Period);
                tlv.StartTime = normalizeTime;
                //tlv.RatingValue = solution.SolutionFactor;

                // add to the list
                newTrainLineVariables.Add(tlv);
                // increment index
                index++;
            }

            return(newTrainLineVariables);
        }
Beispiel #2
0
        /// <summary>
        /// Calculates the transfers.
        /// </summary>
        /// <param name="timetable">The timetable.</param>
        /// <param name="line">The line.</param>
        /// <param name="startTime">The start time.</param>
        /// <returns></returns>
        private CurrentState calculateTransfers(Timetable timetable, TrainLineVariable line, Time startTime)
        {
            // Changes, in case we need to revert the state (it is worse than the current one).
            List <Change> changes = new List <Change>();

            //////SET SELECED LINES
            // Set the start time for the given line.
            changes.Add(new Change(line, line.StartTime));
            line.StartTime = startTime;

            ///SET ALL CONNECTED LINES
            // Set the appropriate start time for each connected variable.
            foreach (TrainLineVariable connectedVariable in line.ConnectedLinesVariable)
            {
                // Set the start for variable.
                changes.Add(new Change(line, line.StartTime));
                connectedVariable.StartTime = startTime - connectedVariable.Line.ConnectedLineShift;
                connectedVariable.StartTime = PeriodUtil.normalizeTime(connectedVariable.StartTime, connectedVariable.Period);
            }

            // Compute the factor.
            int factor = Timetable.calculateTimetableRatingValue(timetable);

            // Current state returned.
            return(new CurrentState(changes, factor));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Constraint"/> class.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="modulo">The modulo.</param>
 public ConnectedLineConstraint(TrainLine line1, TrainLine line2, int modulo)
     : base(
         new int[] {
     PeriodUtil.normalizeTime(line2.ConnectedLineShift.ToMinutes() - line1.ConnectedLineShift.ToMinutes(), modulo)
 },
         modulo
         )
 {
     setConnectedConstraintDefaultValues();
     TrainLine1      = line1;
     TrainLine2      = line2;
     ConstantMember1 = line1.ConnectedLineShift.ToMinutes();
     ConstantMember2 = line2.ConnectedLineShift.ToMinutes();
     // create min factor for single set
     DiscreteSet.createMinimizationFactor(0);
 }
 /// <summary>
 /// Fills fields with information about train line from header.
 /// </summary>
 /// <param name="trainLine">The train line.</param>
 /// <param name="header">The header.</param>
 private static void fillHeader(TrainLine trainLine, Hashtable header)
 {
     if (header.ContainsKey(TRAIN_LINE_NUMBER))
     {
         trainLine.LineNumber = Convert.ToInt32(header[TRAIN_LINE_NUMBER]);
     }
     if (header.ContainsKey(DIRECTION))
     {
         trainLine.Direction = DirectionUtil.getDirection(header[DIRECTION].ToString());
     }
     if (header.ContainsKey(PROVIDER))
     {
         trainLine.Provider = header[PROVIDER].ToString();
     }
     if (header.ContainsKey(PERIOD))
     {
         trainLine.Period = PeriodUtil.getPeriod(header[PERIOD].ToString());
     }
     if (header.ContainsKey(TYPE_OF_TRAIN))
     {
         trainLine.TypeTrain = TypeOfTrainUtil.getTypeOfTrain(header[TYPE_OF_TRAIN].ToString());
     }
 }