Esempio n. 1
0
 public Moment(int index)
 {
     this.index                                 = index;
     this.trainCoordinate                       = null;
     this.trainSvetofor                         = null;
     this.svetofor                              = null;
     this.trainVelocity                         = null;
     this.activeVelocityRestrictions            = null;
     this.activeVelocityExcesses                = null;
     this.endedInPreviousMomentVelocityExcesses = null;
     this.formulation                           = null;
 }
        public Formulation()
        {
            Program.allDependenciesInitializedOrException("formulation");
            Moment currentMoment = Program.currentMoment;

            this.list  = new List <String>();
            this.exist = false;
            List <VelocityExcess> endedInPreviousMomentList = currentMoment.endedInPreviousMomentVelocityExcesses.exist == true ? currentMoment.endedInPreviousMomentVelocityExcesses.list : new List <VelocityExcess>();

            foreach (VelocityExcess endedVelocityExcess in endedInPreviousMomentList)
            {
                if (
                    endedVelocityExcess.velocityRestriction is VelocityRestrictionSvetofor &&
                    endedVelocityExcess.velocityRestriction.type == "velocityRestrictionSvetofor"
                    )
                {
                    VelocityRestrictionSvetofor velocityRestrictionSvetofor = (VelocityRestrictionSvetofor)endedVelocityExcess.velocityRestriction;
                    Svetofor svetofor    = endedVelocityExcess.endMoment.svetofor;
                    Velocity maxVelocity = endedVelocityExcess.startMoment.trainVelocity;
                    for (int i = endedVelocityExcess.startMoment.index + 1; i <= endedVelocityExcess.endMoment.index; i++)
                    {
                        Velocity currentVelocity = Program.allMoments[i].trainVelocity;
                        if (currentVelocity.value > maxVelocity.value)
                        {
                            maxVelocity = currentVelocity;
                        }
                    }
                    string formulation = String.Format("Превышение скорости {0} км/ч за {1} метров до светофора {2} максимально на {3} км/ч.\nС {4} по {5} секунду.",
                                                       velocityRestrictionSvetofor.velocity.value.ToString(),
                                                       velocityRestrictionSvetofor.metricDistance.ToString(),
                                                       svetofor.name,
                                                       (maxVelocity.value - velocityRestrictionSvetofor.velocity.value).ToString(),
                                                       endedVelocityExcess.startMoment.index,
                                                       endedVelocityExcess.endMoment.index
                                                       );
                    list.Add(formulation);
                    Console.WriteLine(formulation);
                    this.exist = true;
                }
                if (
                    endedVelocityExcess.velocityRestriction is VelocityRestrictionPermanent &&
                    endedVelocityExcess.velocityRestriction.type == "velocityRestrictionPermanent"
                    )
                {
                    VelocityRestrictionPermanent velocityRestrictionPermanent = (VelocityRestrictionPermanent)endedVelocityExcess.velocityRestriction;
                    Velocity maxVelocity = endedVelocityExcess.startMoment.trainVelocity;
                    for (int i = endedVelocityExcess.startMoment.index + 1; i <= endedVelocityExcess.endMoment.index; i++)
                    {
                        Velocity currentVelocity = Program.allMoments[i].trainVelocity;
                        if (currentVelocity.value > maxVelocity.value)
                        {
                            maxVelocity = currentVelocity;
                        }
                    }
                    string formulation = String.Format("Превышение постоянного скорости {0} км/ч на {1} км {2} пк с {3} км {4} пк по {5} км {6} пк максимально на {7} км/ч.\nС {8} по {9} секунду.",
                                                       velocityRestrictionPermanent.velocity.value.ToString(),
                                                       velocityRestrictionPermanent.coordBegin.km,
                                                       velocityRestrictionPermanent.coordBegin.pk.ToString(),
                                                       endedVelocityExcess.startMoment.trainCoordinate.km,
                                                       endedVelocityExcess.startMoment.trainCoordinate.pk,
                                                       endedVelocityExcess.endMoment.trainCoordinate.km,
                                                       endedVelocityExcess.endMoment.trainCoordinate.pk,
                                                       (maxVelocity.value - velocityRestrictionPermanent.velocity.value).ToString(),
                                                       endedVelocityExcess.startMoment.index,
                                                       endedVelocityExcess.endMoment.index
                                                       );
                    list.Add(formulation);
                    Console.WriteLine(formulation);
                    this.exist = true;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Заполняем момент исходя из данных поездки (текущего состояния параметров)
        /// </summary>
        /// <param name="initialParams"></param>
        public void init(InitialParamsForOneMoment initialParams)
        {
            Type type = this.GetType();

            //получить массив полей класса Moment
            FieldInfo[] allFields      = type.GetFields();
            int         maxCycles      = allFields.Length;
            int         quantityCycles = 0;

            while (Program.checkDependinciesStatus("moment") == Program.dependenciesStatus.NotInitialized && quantityCycles < maxCycles)
            {
                if (this.trainCoordinate == null)
                {
                    try
                    {
                        this.trainCoordinate = new TrainCoordinate(initialParams.kmCoordinate, initialParams.pkCoordinate, initialParams.mCoordiante);
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.trainSvetofor == null)
                {
                    try
                    {
                        this.trainSvetofor = new TrainSvetofor(initialParams.colorLocoSvetofor);
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.svetofor == null)
                {
                    try
                    {
                        this.svetofor = new Svetofor(initialParams.kmSvetofor, initialParams.pkSvetofor, initialParams.mSvetofor, initialParams.nameSvetofor);
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.trainVelocity == null)
                {
                    try
                    {
                        this.trainVelocity = new TrainVelocity(initialParams.valueVelocity);
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.activeVelocityRestrictions == null)
                {
                    try
                    {
                        this.activeVelocityRestrictions = new ActiveVelocityRestrictions();
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.activeVelocityExcesses == null)
                {
                    try
                    {
                        this.activeVelocityExcesses = new ActiveVelocityExcesses();
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.endedInPreviousMomentVelocityExcesses == null)
                {
                    try
                    {
                        this.endedInPreviousMomentVelocityExcesses = new EndedInPreviousMomentVelocityExcesses();
                    }
                    catch (Exception e)
                    {
                    }
                }
                if (this.formulation == null)
                {
                    try
                    {
                        this.formulation = new Formulation();
                    }
                    catch (Exception e)
                    {
                    }
                }
                quantityCycles++;
            }
        }