//! Start Pseudo BruteForce method /*! * /param SChedulerInterface scheduler to run * /param SchedulingProblem to solve * /param Main mainform to update Information * Currently can only be called with the greedy scheduler */ public static void startBruteForce(SchedulerInterface scheduler, SchedulingProblem problem, Main mainform) { if (scheduler.GetType() == typeof(GreedyScheduler)) { TimeMeasurement tm = new TimeMeasurement(); GreedyScheduler greedy = (GreedyScheduler)scheduler; double bestFitness = 0.0; for (int iteration = 0; iteration < problem.getContactWindows().Count(); iteration++) { tm.activate(); greedy.BruteForceSchedule(problem, iteration); mainform.updateCalculationTime(tm.getValueAndDeactivate()); ObjectiveFunction obj = problem.getObjectiveFunction(); obj.calculateValues(greedy.getFinischedSchedule()); mainform.updateCalculationTime(tm.getValueAndDeactivate()); mainform.setNumberOfGeneration(iteration); if (bestFitness <= obj.getObjectiveResults()) { bestFitness = obj.getObjectiveResults(); displayResults(mainform, scheduler, iteration); } } } //else do nothing }
protected override void Initialize(IServiceProvider provider) { if (ParentWorkflow.Parameters.ContainsKey("TimeMeasurement")) { _timeMeasurement = FromTimeParameter(ParentWorkflow.Parameters["TimeMeasurement"]); } else { _timeMeasurement = TimeMeasurement.Relative; //Assume relative. } if (ParentWorkflow.Parameters.ContainsKey("MeasurementType")) { _measurementType = FromMeasurementParameter(ParentWorkflow.Parameters["MeasurementType"]); } else { _measurementType = MeasurementType.Relative; //Assume relative. } if (ParentWorkflow.Parameters.ContainsKey("AlertType")) { if (ParentWorkflow.Parameters["AlertType"].ToString().ToLower() == "period") { _alertType = AlertType.Period; } else { _alertType = AlertType.Daily; } } else { _alertType = AlertType.Daily; //Assume daily. } }
public TimeMeasurementThreshold(TimeSpan thresholdTime, string codeBlockName, Logger logger) { this.logger = logger; this.thresholdTime = thresholdTime; this.codeBlockName = codeBlockName; timeMeasurement = new TimeMeasurement(); }
/// <summary> /// Called when intercepting method is invoked. /// </summary> /// <param name="args">The interception arguments.</param> public override void OnInvoke(MethodInterceptionArgs args) { // skip all logging if it is turned off if (ConfigurationManager.AppSettings[Settings.Default.EnableLoggerSettingName]?.EqualIgnoreCase(false.ToString()) ?? false) { base.OnInvoke(args); return; } var methodName = BuildMethodName(args.Method); if (_logger == null) { _logger = IoC.Resolve <ILog>(); } if (LogInputParameters) { var parameters = UseJson ? LogJson(args) : LogCustom(args); _logger.Trace(MethodWithParameters.FormatWith(methodName, parameters)); } else { _logger.Trace(methodName); } try { if (LogMeasure) { using (TimeMeasurement.Measure(_ => LogMethodMeasure(methodName, _))) base.OnInvoke(args); } else { base.OnInvoke(args); } if (!LogOutputValue) { return; } var output = LogArgument(args.ReturnValue); _logger.Trace(output); } catch (Exception exception) { _logger.Error(methodName, exception); throw; } }
/// <summary> /// Gets a new Stopwatch to monitor a call method. Be sure to call MonitoringTimers.Current.AddTime after to save that time ! /// </summary> /// <param name="start">Is the Stopwatch started or not ?</param> public IStopwatch GetNewStopwatch(bool start) { IStopwatch result = new TimeMeasurement(); if (start) { result.Start(); } return(result); }
static void SetTimeProvider(object o, ITimeMeasureProvider provider, IDictionary <ITimeMeasureConsumer, IMeasurement> dictionary) { ITimeMeasureConsumer tc = o.GetLabelObject <ITimeMeasureConsumer>(); IMeasurement timeMeasurement = provider.TimeMeasurement; if (!(timeMeasurement is TimeMeasurement)) { throw new Exception(); } Func <object> f = timeMeasurement.Parameter; if (tc != null) { TimeMeasurement tmr = tc.Time as TimeMeasurement; if (tmr == null) { tc.Time = new TimeMeasurement(() => { return((double)0); }); } tmr = tc.Time as TimeMeasurement; if (dictionary.ContainsKey(tc)) { if (tc.Time != provider.TimeMeasurement) { dictionary[tc] = tc.Time; if (tmr != null) { tmr.TimeParameter = f; } } } else { dictionary[tc] = tc.Time; if (tmr != null) { tmr.TimeParameter = f; } } } IChildrenObject co = o.GetLabelObject <IChildrenObject>(); if (co != null) { IAssociatedObject[] ch = co.Children; if (ch != null) { foreach (object ob in ch) { SetTimeProvider(ob, provider, dictionary); } } } }
public ExecutionTimeLogger([NotNull] string mark) { if (mark == null) { throw new ArgumentNullException(nameof(mark)); } _mark = mark; _log = IoC.GetContainer().Resolve <ILog>(); _timeMeasurement = TimeMeasurement.Measure(WriteLog); }
/// <summary> /// Constructor /// </summary> /// <param name="isAbsolute">True in case of relative time</param> /// <param name="timeUnit">Time unit</param> internal RealtimeProviderAnalysis(bool isAbsolute, TimeType timeUnit) { if (timeUnit.Equals(TimeType.Day)) { time = () => { return((dt - new DateTime(0)).TotalDays); }; } else { double coeff = TimeType.Day.Coefficient <TimeType>(timeUnit); if (!isAbsolute) { time = () => { return(coeff * (dt - start).TotalDays); }; } else { time = () => { return(coeff * (dt - new DateTime(0)).TotalDays); }; } if (isAbsolute) { act = (DateTime dt) => { }; } else { act = (DateTime dt) => { start = dt; act = (DateTime tt) => { }; }; } } Func <object> mea = () => { double t = time(); return(t); }; timeMeasurement = new TimeMeasurement(mea); }
public IActionResult StartTime(int registratorId) { Registrator registrator = new Registrator { RegistratorId = registratorId }; try { registrator = _iRegTempus.GetRegistratorBasedOnRegistratorId(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Did not succed in fetching userdata"; return(View("Index")); } registrator.UserHaveStartedTimeMeasure = true; registrator.StartedTimeMeasurement = 0; TimeMeasurement timeRegistration = TimeMeasurement.startClock(registrator); try { timeRegistration = _iRegTempus.CreateNewMeasurement(timeRegistration); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Saving the new time registration did not succed"; return(View("Index")); } registrator.StartedTimeMeasurement = timeRegistration.TimeMeasurementId; try { registrator = _iRegTempus.UpdateRegistrator(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your data did not succed"; return(View("Index")); } if (registrator.StartedTimeMeasurement != timeRegistration.TimeMeasurementId) { ViewBag.ErrorMessage = "Error: changing your details did not succed"; } ViewBag.SuccessMessage = "Your start time is registered."; UserTimeRegistrationViewModel konvertedRegistrator = UserTimeRegistrationViewModel.RestructureTheRegistratorData(registrator); return(View("Index", konvertedRegistrator)); }
public MainWindowViewModel() { //ViewにViewModelのインスタンス渡す _window = new MainWindow(this); _timeMeasurement = new TimeMeasurement(); IniViewTimer(); _workTimeList = new TimerList(); _relaxTimerList = new TimerList(); _modeChangeVm = new ModeChangeVm(_window); _modeChangeVm.Stop(); }
/// <summary> /// create SyncInfo /// </summary> /// <param name="link">link data (will be copied not referenced)</param> public SyncInfo(SyncLink link) { Link = link; Time = new TimeMeasurement(this); Files = new FilesInfo(this); Dirs = new DirsInfo(this); Paused = false; SyncDirExecutionInfos = new List<SyncDirExecutionInfo>(); SyncFileExecutionInfos = new List<SyncFileExecutionInfo>(); ConflictInfos = new List<ElementConflictInfo>(); LogStack = new Stack<LogMessage>(); MyDirInfo rootDir = new MyDirInfo("\\", ""); SyncDirInfo sdi = new SyncDirInfo(this, rootDir, false); DirTree = new DirTree(rootDir, null, null); Status = SyncStatus.DetectingChanges; }
/// <summary> /// create SyncInfo /// </summary> /// <param name="link">link data (will be copied not referenced)</param> public SyncInfo(SyncLink link) { Link = link; Time = new TimeMeasurement(this); Files = new FilesInfo(this); Dirs = new DirsInfo(this); Paused = false; SyncDirExecutionInfos = new List <SyncDirExecutionInfo>(); SyncFileExecutionInfos = new List <SyncFileExecutionInfo>(); ConflictInfos = new List <ElementConflictInfo>(); LogStack = new Stack <LogMessage>(); MyDirInfo rootDir = new MyDirInfo("\\", ""); SyncDirInfo sdi = new SyncDirInfo(this, rootDir, false); DirTree = new DirTree(rootDir, null, null); Status = SyncStatus.DetectingChanges; }
public UserController(IUserOperation userOperation) { _userOperation = userOperation; _timeMeasurement = new TimeMeasurement(); }
private void ShowTimeMeasurementWindow() { if (tmWindow == null || !tmWindow.IsVisible) { tmWindow = new TimeMeasurement(); tmWindow.Show(); } }
public string Difference(string lang, DateTime d1, DateTime d2, TimeMeasurement measurement = TimeMeasurement.Auto, bool ignoreMinor = true) { // WARNING: THIS METHOD IS INCOMPLETE. DO NOT USE IT. var result = ""; var span = (d1 - d2); var _measurement = TimeMeasurement.Auto; if (measurement == TimeMeasurement.Auto) { if (span.TotalMilliseconds < 0.001) { _measurement = TimeMeasurement.NanoSecond; } else if (span.TotalMilliseconds < 1) { _measurement = TimeMeasurement.MicroSecond; } else if (span.TotalMilliseconds < 1000) { _measurement = TimeMeasurement.MilliSecond; } else if (span.TotalSeconds < 60) { _measurement = TimeMeasurement.Second; } else if (span.TotalMinutes < 60) { _measurement = TimeMeasurement.Minute; } else if (span.TotalHours < 24) { _measurement = TimeMeasurement.Hour; } else if (span.TotalDays < 7) { _measurement = TimeMeasurement.Day; } else if (span.TotalDays < 30) { _measurement = TimeMeasurement.Week; } else if (span.TotalDays < 365) { _measurement = TimeMeasurement.Month; } else if (span.TotalDays < 3650) { _measurement = TimeMeasurement.Year; } else if (span.TotalDays < 36500) { _measurement = TimeMeasurement.Decade; } else if (span.TotalDays < 365000) { _measurement = TimeMeasurement.Century; } else { _measurement = TimeMeasurement.Millennium; } } else { _measurement = measurement; } int x = 0; int y = 0; int z = 0; switch (_measurement) { case TimeMeasurement.NanoSecond: x = (int)(span.TotalMilliseconds * TimeSpan.TicksPerMillisecond); result = x.ToString() + " " + Translator.GetSingle("measurement-unit", "Nano", lang) + " " + Translator.GetSingle("measurement-type-time", "second", lang); break; case TimeMeasurement.MicroSecond: x = (int)(span.TotalMilliseconds * 1000); result = x.ToString() + " " + Translator.GetSingle("measurement-unit", "Micro", lang) + " " + Translator.GetSingle("measurement-type-time", "second", lang); break; case TimeMeasurement.MilliSecond: x = (int)(span.TotalMilliseconds); result = x.ToString() + " " + Translator.GetSingle("measurement-unit", "Milli", lang) + " " + Translator.GetSingle("measurement-type-time", "second", lang); if (!ignoreMinor) { y = (int)((span.TotalMilliseconds - Math.Floor(span.TotalMilliseconds)) * 1000); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-unit", "Micro", lang) + " " + Translator.GetSingle("measurement-type-time", "second", lang); } } break; case TimeMeasurement.Second: x = (int)(span.TotalSeconds); result = x.ToString() + " " + Translator.GetSingle("measurement-type-time", "Second", lang); if (!ignoreMinor) { y = (int)((span.TotalSeconds - Math.Floor(span.TotalSeconds)) * 1000); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-unit", "Milli", lang) + " " + Translator.GetSingle("measurement-type-time", "second", lang); } } break; case TimeMeasurement.Minute: x = (int)(span.TotalMinutes); result = x.ToString() + " " + Translator.GetSingle("measurement-type-time", "Minute", lang); if (!ignoreMinor) { y = (int)((span.TotalMinutes - Math.Floor(span.TotalMinutes)) * 60); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-type-time", "second", lang); } } break; case TimeMeasurement.Hour: x = (int)(span.TotalHours); result = x.ToString() + " " + Translator.GetSingle("measurement-type-time", "Hour", lang); if (!ignoreMinor) { y = (int)((span.TotalHours - Math.Floor(span.TotalHours)) * 60); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-type-time", "minute", lang); } } break; case TimeMeasurement.Day: x = (int)(span.TotalDays); result = x.ToString() + " " + Translator.GetSingle("measurement-type-time", "Day", lang); if (!ignoreMinor) { y = (int)((span.TotalDays - Math.Floor(span.TotalDays)) * 24); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-type-time", "hour", lang); } } break; case TimeMeasurement.Week: x = (int)(Math.Floor(span.TotalDays / 7)); result = x.ToString() + " " + Translator.GetSingle("measurement-type-time", "Day", lang); if (!ignoreMinor) { y = (int)(span.TotalDays - x * 7); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-type-time", "day", lang); } } break; case TimeMeasurement.Month: x = (int)(Math.Floor(span.TotalDays / 30)); result = x.ToString() + " " + Translator.GetSingle("measurement-type-time", "Day", lang); if (!ignoreMinor) { y = (int)(span.TotalDays - x * 30); if (y > 0) { result += " " + Translator.GetSingle("measurement-general", "and", lang) + " " + y + " " + Translator.GetSingle("measurement-type-time", "week", lang); } } break; } return(result); }
public TimeMeasurement CompleteTimeMeasurement(TimeMeasurement timeStop) { throw new NotImplementedException(); }
public TimeMeasurement CreateNewMeasurement(TimeMeasurement timeStart) { _context.TimeMeasurements.Add(timeStart); _context.SaveChanges(); return(timeStart); }
public TimeMeasurement CompleteTimeMeasurement(TimeMeasurement timeStop) { _context.TimeMeasurements.Attach(timeStop); _context.SaveChanges(); return(timeStop); }
public bool runThisRun() { results = new List <string>(); DataBase.DataBase db = new DataBase.DataBase(); bool status = true; List <Ground.Station> stationData = new List <Ground.Station>(); for (int i = 0; i < stationList.Count; i++) { Ground.Station station = db.getStationFromDB(stationList[i]); stationData.Add(station); //updateLog(logfile, "Adding Station: " + station.getName()); } System.Windows.Forms.Application.DoEvents(); List <One_Sgp4.Tle> tleData = new List <Tle>(); for (int i = 0; i < satelliteList.Count; i++) { One_Sgp4.Tle sattle = db.getTleDataFromDB(satelliteList[i]); tleData.Add(sattle); //updateLog(logfile, "Adding Satellite: " + sattle.getName()); } System.Windows.Forms.Application.DoEvents(); ContactWindowsVector contactsVector = MainFunctions2.calculateContactWindows(tleData, stationData, startTime, stopTime); System.Windows.Forms.Application.DoEvents(); scheduler = null; switch (schedulerName) { case "Genetic": string[] settString = settings.Split(';'); scheduler = new GeneticScheduler(Convert.ToInt32(settString[0]), Convert.ToInt32(settString[1]), Convert.ToInt32(settString[2]), Convert.ToInt32(settString[4]), Convert.ToBoolean(settString[5]), Convert.ToDouble(settString[6]), Convert.ToBoolean(settString[7]), Convert.ToBoolean(settString[8])); break; case "Greedy": scheduler = new GreedyScheduler(); break; case "EFT-Greedy": scheduler = new EftGreedyScheduler(); break; case "Hill-Climber": string[] settString2 = settings.Split(';'); scheduler = new HillClimberScheduler(Convert.ToBoolean(settString2[0]), Convert.ToBoolean(settString2[2]), Convert.ToInt32(settString2[1])); break; } ObjectiveFunction objective = new ObjectiveFunction(Forms.ObjectiveBuilderForm.getObjectiveEnumsByName(objectiveFunction)); System.Windows.Forms.Application.DoEvents(); SchedulingProblem problem = new SchedulingProblem(); problem.setContactWindows(contactsVector); problem.removeUnwantedContacts(Properties.Settings.Default.orbit_Minimum_Contact_Duration_sec); problem.setObjectiveFunction(objective); problem.getContactWindows().randomize(Properties.Settings.Default.global_Random_Seed); getScenario(problem, scenario); System.Windows.Forms.Application.DoEvents(); TimeMeasurement tm = new TimeMeasurement(); tm.activate(); scheduler.CalculateSchedule(problem); string time = tm.getValueAndDeactivate(); System.Windows.Forms.Application.DoEvents(); contactsVector = scheduler.getFinischedSchedule(); System.Windows.Forms.Application.DoEvents(); if (scheduler != null) { ObjectiveFunction objfunc = scheduler.getObjectiveFunction(); if (objfunc == null) { objfunc = new ObjectiveFunction(); } objfunc.calculateValues(scheduler.getFinischedSchedule()); double fitness = objfunc.getObjectiveResults(); int _H = scheduler.getFinischedSchedule().getNrOfScheduled(); double _H1 = objfunc.getScheduledContactsValue(); int _H2 = GeneralMeasurments.getNrOfConflicts(scheduler.getFinischedSchedule()); double _H3 = objfunc.getStationFairnessValue(); double _H4 = objfunc.getSatelliteFairnessValue(); double _H5 = GeneralMeasurments.getDurationOfScheduledContacts(scheduler.getFinischedSchedule()); results.Add("Run: " + schedulerName); results.Add("Fitness Value:" + objfunc.getObjectiveResults().ToString()); results.Add("Scheduled Contacts: " + scheduler.getFinischedSchedule().getNrOfScheduled().ToString() + " / " + contactsVector.Count().ToString()); results.Add("Collisions: " + GeneralMeasurments.getNrOfConflicts(scheduler.getFinischedSchedule()).ToString()); results.Add("Fairnes Stations: " + objfunc.getStationFairnessValue().ToString()); results.Add("Fairnes Satellites: " + objfunc.getSatelliteFairnessValue().ToString()); results.Add("Duration: " + GeneralMeasurments.getDurationOfScheduledContacts(scheduler.getFinischedSchedule()).ToString() + " sec."); results.Add("Calculation Time: " + time); results.Add("Scheduled By Priority: " + GeneralMeasurments.getNrOfPrioritysScheduled(scheduler.getFinischedSchedule())); results.Add("Scheduled UWE-3: " + GeneralMeasurments.getNrOfUweContacts(scheduler.getFinischedSchedule()).ToString()); //Log.writeResults(logfile, schedulerName, results); if (results == null) { status = false; } } else { status = false; } cancel = false; return(status); }
protected override void Reset() { n_cycle = 0; time_measurement = new TimeMeasurement(this.Task.Period / Time.sec); this.Task.SetState(A); }
public IActionResult StopTime(int registratorId) { Registrator registrator = new Registrator { RegistratorId = registratorId }; TimeMeasurement measuredTime = new TimeMeasurement(); try { registrator = _iRegTempus.GetRegistratorBasedOnRegistratorId(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Fetching your data did not succed. Please make a manual note of present time."; return(View("Index")); } registrator.UserHaveStartedTimeMeasure = false; try { measuredTime = _iRegTempus.GetTimeMeasurement(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Fetching your start time did not succed. Please make a manual note of present time."; return(View("Index")); } DateTime stopTime = DateTime.Now; if (measuredTime.TimeStart.DayOfYear == stopTime.DayOfYear) { measuredTime = TimeMeasurement.stopClock(measuredTime, stopTime); } else { measuredTime = TimeMeasurement.complexStopClock(measuredTime); TimeMeasurement newMeasuredTime = TimeMeasurement.complexStartAndStopClock(registrator, stopTime); try { newMeasuredTime = _iRegTempus.CompleteTimeMeasurement(newMeasuredTime); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your stop time did not succed. Please make a manual note of present time."; return(View("Index")); } } try { measuredTime = _iRegTempus.CompleteTimeMeasurement(measuredTime); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your stop time did not succed. Please make a manual note of present time."; return(View("Index")); } registrator.StartedTimeMeasurement = 0; try { registrator = _iRegTempus.UpdateRegistrator(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your data did not succed. Please make a manual note of present time."; return(View("Index")); } ViewBag.SuccessMessage = "Your stop time is registered."; UserTimeRegistrationViewModel konvertedRegistrator = UserTimeRegistrationViewModel.RestructureTheRegistratorData(registrator); return(View("Index", konvertedRegistrator)); }
public TimeMeasurement CreateNewMeasurement(TimeMeasurement timeStart) { throw new NotImplementedException(); }
public double StopStopwatch(TimeMeasurement mesureDeTemps) { return((End - Start).TotalMilliseconds); }