Exemple #1
0
 private void RunStartIteration(int i)
 {
     if (ModeChoice != null)
     {
         if (!_ExitRequested)
         {
             ModeChoice.IterationStarted(i, TotalIterations);
         }
     }
     if (PostScheduler != null)
     {
         foreach (var module in PostScheduler)
         {
             if (!_ExitRequested)
             {
                 module.IterationStarting(i);
             }
         }
     }
     if (PostHousehold != null)
     {
         foreach (var module in PostHousehold)
         {
             if (!_ExitRequested)
             {
                 module.IterationStarting(i);
             }
         }
     }
 }
        private void RunTasha(int householdIndex)
        {
            var hhld = Households[householdIndex];

            try
            {
                if (ModeChoice.Run(hhld))
                {
                    HouseholdEvaluation[householdIndex] = EvaluateHousehold(hhld);
                }
                else
                {
                    SetToMax(householdIndex, hhld);
                }
            }
            catch (Exception e)
            {
                if (e is XTMFRuntimeException)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Console.WriteLine(e.Message + "\r\n" + e.StackTrace);
                }
                SetToMax(householdIndex, hhld);
            }
            Interlocked.Increment(ref ProcessedSoFar);
            Progress = ProcessedSoFar / (float)HouseholdEvaluation.Length;
        }
 private void ProcessTashaRequests()
 {
     // Tell the host that we are ready
     Client.SendCustomMessage(null, 0);
     ModeChoice.LoadOneTimeLocalData();
     ModeChoice.IterationStarted(0, 1);
     // now lets wait for some parameters
     while (!Exit)
     {
         var queue = ServerMessages;
         if (queue == null)
         {
             return;
         }
         var job = queue.GetMessageOrTimeout(200);
         if (job != null)
         {
             job.Result = RunJob(job);
             ReportResult(job);
             // after we have reported clean the memory
             GC.Collect();
         }
         Thread.MemoryBarrier();
     }
     ModeChoice.IterationFinished(0, 1);
 }
Exemple #4
0
        private void Run(int i, ITashaHousehold hhld)
        {
            if (!_ExitRequested)
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                if (Scheduler != null)
                {
                    Scheduler.Run(hhld);
                    if (PostScheduler != null)
                    {
                        foreach (var module in PostScheduler)
                        {
                            module.Execute(hhld);
                        }
                    }
                }

                if (ModeChoice != null)
                {
                    if (!ModeChoice.Run(hhld))
                    {
                        Interlocked.Increment(ref FailedModeChoice);
                    }
                }

                if (PostHousehold != null)
                {
                    foreach (var module in PostHousehold)
                    {
                        module.Execute(hhld, i);
                    }
                }
                Interlocked.Increment(ref CurrentHousehold);
                if (CurrentHousehold % 1000 == 0)
                {
                    watch.Stop();
                    Console.WriteLine($"hhld#{hhld.HouseholdId} : {watch.ElapsedMilliseconds}");
                }
                if (RecycleHouseholdData)
                {
                    ReleaseModeData(hhld);
                    hhld.Recycle();
                }
            }
        }
Exemple #5
0
        private void Run(int i, ITashaHousehold hhld)
        {
            if (!_ExitRequested)
            {
                if (Scheduler != null)
                {
                    Scheduler.Run(hhld);
                    if (PostScheduler != null)
                    {
                        foreach (var module in PostScheduler)
                        {
                            module.Execute(hhld);
                        }
                    }
                }

                if (ModeChoice != null)
                {
                    if (!ModeChoice.Run(hhld))
                    {
                        Interlocked.Increment(ref FailedModeChoice);
                    }
                }

                if (PostHousehold != null)
                {
                    foreach (var module in PostHousehold)
                    {
                        module.Execute(hhld, i);
                    }
                }
                Interlocked.Increment(ref CurrentHousehold);

                if (RecycleHouseholdData)
                {
                    ReleaseModeData(hhld);
                    hhld.Recycle();
                }
            }
        }
Exemple #6
0
        public void Start()
        {
            // setup the status to be initializing
            _Status          = null;
            _Progress        = () => 0f;
            CurrentIteration = 0;
            if (!VehicleTypes.Contains(AutoType))
            {
                VehicleTypes.Add(AutoType);
            }
            ZoneSystem.LoadData();
            if (PreRun != null)
            {
                foreach (var module in PreRun)
                {
                    module.Start();
                }
            }
            IterationPercentage = 1f / TotalIterations;
            if (PostScheduler != null)
            {
                foreach (var module in PostScheduler)
                {
                    module.Load(TotalIterations);
                }
            }
            if (PostHousehold != null)
            {
                foreach (var module in PostHousehold)
                {
                    module.Load(TotalIterations);
                }
            }

            if (OverrideModeParameters)
            {
                InitializeParameters();
            }
            LoadNetworkData(0);
            if (Scheduler != null)
            {
                Scheduler.LoadOneTimeLocalData();
            }

            if (ModeChoice != null)
            {
                ModeChoice.LoadOneTimeLocalData();
            }

            for (int i = 0; i < TotalIterations; i++)
            {
                if (!_ExitRequested)
                {
                    CurrentHousehold             = 0;
                    CurrentIteration             = i;
                    CompletedIterationPercentage = i * IterationPercentage;
                    if (LoadAllHouseholds)
                    {
                        if (!SkipLoadingHouseholds)
                        {
                            HouseholdLoader.LoadData();
                        }
                    }
                    RunIteration(i);
                }
            }
            if (PostRun != null)
            {
                foreach (var module in PostRun)
                {
                    module.Start();
                }
            }
            ZoneSystem.UnloadData();
        }