public override bool checkExisting(Moment moment, bool checkDependenciesInitialized) { if (checkDependenciesInitialized) { Program.allDependenciesInitializedOrException("velocityRestrictionSvetofor"); } if (!(moment.svetofor.exist == true && moment.trainCoordinate.exist == true && moment.trainSvetofor.exist == true)) { return(false); } if (moment.svetofor.coordinate.GetMetricCoord() - moment.trainCoordinate.GetMetricCoord() > this.metricDistance) { return(false); } if (moment.trainSvetofor.color != this.colorSvetofor) { return(false); } return(true); }
public ActiveVelocityExcesses() { Program.allDependenciesInitializedOrException("activeVelocityExcesses"); Moment currentMoment = Program.currentMoment; Moment previousMoment = Program.previousMoment; this.list = new List <VelocityExcess>(); List <VelocityExcess> previousMomentActiveList = new List <VelocityExcess>(); if (previousMoment != null && previousMoment.activeVelocityExcesses.exist == true) { previousMomentActiveList = previousMoment.activeVelocityExcesses.list; } this.exist = false; //Добавление превышений скорости //Новых или из предыдущего момента при условии, что превышение скорости уже существовало для данного типа ограничения скорости if (currentMoment.activeVelocityRestrictions.exist == true && currentMoment.trainVelocity.exist == true) { foreach (VelocityRestriction velocityRestriction in currentMoment.activeVelocityRestrictions.list) { if (currentMoment.trainVelocity.value > velocityRestriction.velocity.value) { foreach (VelocityExcess previousMomentVelocityExcess in previousMomentActiveList) { if (velocityRestriction == previousMomentVelocityExcess.velocityRestriction) { //Добавление уже действующего превышения скорости this.list.Add(previousMomentVelocityExcess); goto endIf; } } //Добавление нового превышения скорости this.list.Add(new VelocityExcess(currentMoment, velocityRestriction)); endIf: this.exist = true; } } } }
static void Main(string[] args) { getDependenciesFromDB(); DateTime begin; DateTime end; begin = DateTime.Now; for (int i = 0; i < 10000; i++) { foreach (InitialParamsForOneMoment initialParamsForOneMoment in Program.allInitialParams) { int index = i * Program.allInitialParams.Count + Program.allInitialParams.IndexOf(initialParamsForOneMoment); Moment newMoment = new Moment(index); Program.allMoments.Add(newMoment); Program.currentMoment = newMoment; Program.previousMoment = Program.allMoments.Count > 1 ? Program.allMoments[Program.allMoments.Count - 2] : null; newMoment.init(initialParamsForOneMoment); } } end = DateTime.Now; Console.WriteLine(end - begin); }
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; } } }
/// <summary> /// Проверка состояния параметров, необходимых для определения события eventName, в заданнный момент времени /// </summary> /// <param name="eventName"></param> /// <param name="moment"></param> /// <returns></returns> static public Program.dependenciesStatus checkDependenciesStatus(string eventName, Moment moment) { List <string> dependencyNames = Program.getDependencyNamesList(eventName); if (dependencyNames.Count == 0) { return(Program.dependenciesStatus.ExistTrue); } Type type = typeof(Moment); string beginOfOutString = "Проверка для поля " + eventName + "."; //int quantityDependenciesInitialized = 0; int quantityDependinciesWithExistTrue = 0; foreach (String dependencyName in dependencyNames) { FieldInfo fieldInfo = type.GetField(dependencyName); //Метод GetField возвращает null, если поле не найдено в классе if (fieldInfo == null) { Console.WriteLine(beginOfOutString + " Поля " + dependencyName + " нет в объекте класса Moment."); //continue; return(Program.dependenciesStatus.NotInitialized); } //если поле dependencyName найдено в классе Moment, получаем его значение var fieldValue = fieldInfo.GetValue(moment); if (!(fieldValue is InterfaceExist)) { //Console.WriteLine(beginOfOutString + " Поле " + dependencyName + " не наследует интерфейс InterfaceExist."); //continue; return(Program.dependenciesStatus.NotInitialized); } if (fieldValue == null) { //Console.WriteLine(beginOfOutString + " Поле " + dependencyName + " не инициализировано."); //continue; return(Program.dependenciesStatus.NotInitialized); } //quantityDependenciesInitialized++; InterfaceExist interfaceExist = (InterfaceExist)fieldValue; if (!interfaceExist.exist) { //Console.WriteLine(beginOfOutString + " Поле " + dependencyName + " имеет значение поля exist равное false."); continue; } quantityDependinciesWithExistTrue++; } //if (quantityDependenciesInitialized != dependencyNames.Count) //{ // return Program.dependenciesStatus.NotInitialized; //} if (quantityDependinciesWithExistTrue != dependencyNames.Count) { return(Program.dependenciesStatus.ExistFalse); } return(Program.dependenciesStatus.ExistTrue); }
static public Program.dependenciesPositiveStatus allDependenciesInitializedOrException(string eventName, Moment moment) { Program.dependenciesStatus dependenciesStatus = Program.checkDependenciesStatus(eventName, moment); if (dependenciesStatus == Program.dependenciesStatus.NotInitialized) { string s = "Нет всех необходимых параметров для создания объекта класса " + eventName; //Console.WriteLine(s); throw new Exception(s); } return((Program.dependenciesPositiveStatus)dependenciesStatus); }
abstract public bool checkExisting(Moment moment, bool checkDependenciesInitialized);
public VelocityExcess(Moment startMoment, VelocityRestriction velocityRestriction) { this.startMoment = startMoment; this.velocityRestriction = velocityRestriction; this.endMoment = null; }