Ejemplo n.º 1
0
        private void AddNewLeg(LegType Type, Connection C, ref SolutionLeg LegPrev, ref SolutionLeg Leg, double Time)
        {
            if (C is RConnection)
            {
                Type = LegType.Foot;
            }
            else if (C is TConnection)
            {
                Type = LegType.Transport;
            }
            else if (C is CConnection)
            {
                Type = LegType.Carpool;
            }

            LegPrev = Leg;
            Leg     = new SolutionLeg(Time, Type);
            Legs.Add(Leg);
        }
Ejemplo n.º 2
0
        private void ConstructLegs()
        {
            double     Time   = this.StartTime;
            Connection C      = null;
            Connection C_prev = null;

            LegType Type = LegType.Foot;

            if (Modes == TravelMode.Car)
            {
                Type = LegType.Car;
            }

            SolutionLeg Leg     = new SolutionLeg(StartTime, Type);
            SolutionLeg LegPrev = Leg;

            Legs.Add(Leg);

            for (int i = 0; i < Connections.Count; ++i)
            {
                C = Connections[i];

                if ((C is LConnection) && (i < Connections.Count - 1))
                {
                    AddNewLeg(Type, Connections[i + 1], ref LegPrev, ref Leg, Time);
                }
                else if (Modes == TravelMode.Carpool)
                {
                    double TTime;

                    TTime = C.GetTravelTime(Date, Time, Modes);

                    Leg.AddConnection(C, TTime, C.GetWaitingTime());

                    Time += TTime;
                }
                else
                {
                    double TTime, TTimeWithWaitings;

                    TTime             = C.GetTravelTime(Date, Time, Modes);
                    TTimeWithWaitings = TTime;

                    /* Remove waiting times from the single legs */
                    TTime -= C.GetWaitingTime();
                    if (TTime < 0)
                    {
                        //TODO in rare cases TTime is negative, unfortunately this is not deterministic. Instead to make the RP crash set to 0 the TTime for this connection.
                        TTime = 0;
                        //throw new Exception("negative time value");
                    }

                    Leg.AddConnection(C, TTime, C.GetWaitingTime());
                    //Leg.AddConnection(C, TTime);

                    TTime = TTimeWithWaitings;
                    Time += TTime;

                    /* If there are 2 adjacent TConnections, split them */
                    if ((i < Connections.Count - 1) && (Connections[i + 1] is TConnection))
                    {
                        //if (String.Compare(C.GetRouteId(), Connections[i + 1].GetRouteId()) != 0)
                        if ((String.Compare(C.GetRouteShortName(), Connections[i + 1].GetRouteShortName()) != 0) ||
                            (String.Compare(C.GetRouteLongName(), Connections[i + 1].GetRouteLongName()) != 0))
                        {
                            AddNewLeg(Type, Connections[i + 1], ref LegPrev, ref Leg, Time);
                        }
                    }
                }

                C_prev = C;
            }
        }