Ejemplo n.º 1
0
        private void Run(ITashaHousehold household)
        {
            int[][][] eventCount       = new int[NumberOfDistributionsLocal][][];
            bool      invalidHousehold = false;

            var numberOfPeople = household.Persons.Length;

            Time[] workStartTimes = new Time[numberOfPeople];
            Time[] workEndTimes   = new Time[numberOfPeople];
            for (int p = 0; p < numberOfPeople; p++)
            {
                AssignEpisodes(household.Persons[p], ref workStartTimes[p], ref workEndTimes[p], null);
            }
            System.Threading.Tasks.Parallel.For(0, numberOfPeople, delegate(int personNumber)
            {
                ITashaPerson person = household.Persons[personNumber];
                Time workStartTime  = workStartTimes[personNumber];
                Time workEndTime    = workEndTimes[personNumber];
                FirstPass(eventCount, ref invalidHousehold, person);
                AddPimaryWorkEpisode(person, eventCount, workStartTime, workEndTime);
                LunchPass(person, eventCount, workStartTime, workEndTime);
            });


            // check to see if we have an invalid household, if we do we do not add the data!
            if (invalidHousehold)
            {
                return;
            }
            StoreResults(household.ExpansionFactor, eventCount);

            Interlocked.Increment(ref CurrentHousehold);
            Progress = ((float)CurrentHousehold / NumberOfHouseholds) / TotalIterations + CompletedIterationPercentage;
            household.Recycle();
        }
Ejemplo n.º 2
0
        private void Run(int iteration, ITashaHousehold household)
        {
            var persons    = household.Persons;
            var eventCount = new int[NumberOfDistributionsLocal];
            var addZero    = new bool[NumberOfDistributionsLocal];

            household.CreateHouseholdProjects();
            for (int i = 0; i < persons.Length; i++)
            {
                persons[i].InitializePersonalProjects();
            }
            for (int i = 0; i < persons.Length; i++)
            {
                Time         workStartTime;
                Time         workEndTime;
                ITashaPerson person = household.Persons[i];
                AssignWorkSchoolEpisodes(persons[i], out workStartTime, out workEndTime, null);
                var primaryVehicle = PrimaryMode.RequiresVehicle;
                for (int j = 0; j < addZero.Length; j++)
                {
                    eventCount[j] = 0;
                    addZero[j]    = false;
                }
                FirstPass(person, primaryVehicle, eventCount);
                int lunches = LunchPass(person, eventCount, ref workStartTime, ref workEndTime);
                AddWorkTrip(person, eventCount, addZero, ref workStartTime, ref workEndTime);
                ProcessZeroes(person, workStartTime, eventCount, addZero, lunches);
                // while adding the results back we need to do this in serial
                StoreResults(person.ExpansionFactor, eventCount, addZero);
            }
            System.Threading.Interlocked.Increment(ref CurrentHousehold);
            Progress = ((float)CurrentHousehold / NumberOfHouseholds) / TotalIterations + CompletedIterationPercentage;
            household.Recycle();
        }
Ejemplo n.º 3
0
 private void Run(int i, ITashaHousehold household)
 {
     foreach (var module in this.PostHousehold)
     {
         module.Execute(household, i);
     }
     System.Threading.Interlocked.Increment(ref this.CurrentHousehold);
     this.Progress = ((float)this.CurrentHousehold / this.NumberOfHouseholds) / this.TotalIterations + this.CompletedIterationPercentage;
     household.Recycle();
 }
Ejemplo n.º 4
0
        private void Run(ITashaHousehold household)
        {
            var persons = household.Persons;

            Time[] workStartTimes = new Time[persons.Length];
            Time[] workEndTimes   = new Time[persons.Length];
            for (int p = 0; p < persons.Length; p++)
            {
                AssignEpisodes(persons[p], ref workStartTimes[p], ref workEndTimes[p], null);
            }
            System.Threading.Tasks.Parallel.For(0, persons.Length, delegate(int personNumber)
            {
                ITashaPerson person = household.Persons[personNumber];
                Time workStartTime  = workStartTimes[personNumber];
                Time workEndTime    = workEndTimes[personNumber];
                bool invalidPerson  = false;
                var eventCount      = new int[NumberOfDistributionsLocal];
                var startTimeCount  = new int[NumberOfDistributionsLocal][];
                foreach (var tripChain in person.TripChains)
                {
                    List <ITrip> trips = tripChain.Trips;
                    for (int t = 0; t < trips.Count; t++)
                    {
                        if (trips[t].Purpose != Activity.PrimaryWork)
                        {
                            IncreaseID(ref invalidPerson, eventCount, startTimeCount, trips[t], GetID(person, trips[t]));
                        }
                    }
                }
                if (workStartTime > Time.Zero)
                {
                    var workID = Distribution.GetDistributionID(person, Activity.PrimaryWork);
                    if (workID >= 0)
                    {
                        eventCount[workID]++;
                        AddStartTime(startTimeCount, workID, workStartTime);
                    }
                }
                LunchPass(person, eventCount, startTimeCount, ref workStartTime, ref workEndTime);
                // if this person is invalid skip adding the data back to the final results
                if (invalidPerson)
                {
                    return;
                }
                StoreResults(person.ExpansionFactor, eventCount, startTimeCount);
            });
            Interlocked.Increment(ref CurrentHousehold);
            Progress = ((float)CurrentHousehold / NumberOfHouseholds) / TotalIterations + CompletedIterationPercentage;
            household.Recycle();
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
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();
                }
            }
        }
Ejemplo n.º 7
0
        private void Run(ITashaHousehold household, BlockingCollection <Result> resultList)
        {
            var numberOfPeople = household.Persons.Length;

            if (household.NumberOfAdults >= 2)
            {
                Time[] workStartTimes = new Time[numberOfPeople];
                Time[] workEndTimes   = new Time[numberOfPeople];
                for (int i = 0; i < numberOfPeople; i++)
                {
                    AssignEpisodes(household.Persons[i], ref workStartTimes[i], ref workEndTimes[i], null);
                }
                int[] jointMarket = new int[NumberOfAdults];
                int[] jointOther  = new int[NumberOfAdults];
                bool  any         = false;
                foreach (var person in household.Persons)
                {
                    foreach (var tc in person.TripChains)
                    {
                        if (tc.JointTripRep)
                        {
                            var chains = tc.JointTripChains;
                            int adults = 0;
                            for (int i = 0; i < chains.Count; i++)
                            {
                                if (chains[i].Person.Adult)
                                {
                                    adults++;
                                }
                            }
                            any    = true;
                            adults = adults > NumberOfAdults ? NumberOfAdults : adults;
                            foreach (var trip in tc.Trips)
                            {
                                switch (trip.Purpose)
                                {
                                case Activity.JointOther:
                                    jointOther[adults]++;
                                    break;

                                case Activity.JointMarket:
                                    jointMarket[adults]++;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (any)
                {
                    resultList.Add(new Result()
                    {
                        Adults            = household.NumberOfAdults,
                        Children          = household.Persons.Length - household.NumberOfAdults > 0,
                        ExpansionFactor   = household.ExpansionFactor,
                        JointMarketAdults = jointMarket,
                        JointOthersAdults = jointOther
                    });
                }
            }
            System.Threading.Interlocked.Increment(ref CurrentHousehold);
            household.Recycle();
        }
Ejemplo n.º 8
0
 private void Run(int i, ITashaHousehold household)
 {
     var persons = household.Persons;
     Time[] workStartTimes = new Time[persons.Length];
     Time[] workEndTimes = new Time[persons.Length];
     for(int p = 0; p < persons.Length; p++)
     {
         AssignEpisodes(persons[p], ref workStartTimes[p], ref workEndTimes[p], null);
     }
     System.Threading.Tasks.Parallel.For(0, persons.Length, delegate (int personNumber)
     {
         ITashaPerson person = household.Persons[personNumber];
         Time workStartTime = workStartTimes[personNumber];
         Time workEndTime = workEndTimes[personNumber];
         bool invalidPerson = false;
         var eventCount = new int[this.NumberOfDistributionsLocal];
         var startTimeCount = new int[this.NumberOfDistributionsLocal][];
         foreach(var tripChain in person.TripChains)
         {
             List<ITrip> trips = tripChain.Trips;
             for(int t = 0; t < trips.Count; t++)
             {
                 if(trips[t].Purpose != Activity.PrimaryWork)
                 {
                     IncreaseID(ref invalidPerson, eventCount, startTimeCount, trips[t], GetID(person, trips[t]));
                 }
             }
         }
         if(workStartTime > Time.Zero)
         {
             var workID = Distribution.GetDistributionID(person, Activity.PrimaryWork);
             if(workID >= 0)
             {
                 eventCount[workID]++;
                 AddStartTime(startTimeCount, workID, workStartTime);
             }
         }
         int lunches = LunchPass(person, eventCount, startTimeCount, ref workStartTime, ref workEndTime);
         // if this person is invalid skip adding the data back to the final results
         if(invalidPerson)
         {
             return;
         }
         StoreResults(person.ExpansionFactor, eventCount, startTimeCount);
     });
     System.Threading.Interlocked.Increment(ref this.CurrentHousehold);
     this.Progress = ((float)this.CurrentHousehold / this.NumberOfHouseholds) / this.TotalIterations + this.CompletedIterationPercentage;
     household.Recycle();
 }
Ejemplo n.º 9
0
        private void Run(int i, ITashaHousehold household)
        {
            int[][][] eventCount = new int[NumberOfDistributionsLocal][][];
            bool invalidHousehold = false;

            var numberOfPeople = household.Persons.Length;
            Time[] workStartTimes = new Time[numberOfPeople];
            Time[] workEndTimes = new Time[numberOfPeople];
            for (int p = 0; p < numberOfPeople; p++)
            {
                AssignEpisodes(household.Persons[p], ref workStartTimes[p], ref workEndTimes[p], null);
            }
            System.Threading.Tasks.Parallel.For(0, numberOfPeople, delegate (int personNumber)
            {
                ITashaPerson person = household.Persons[personNumber];
                Time workStartTime = workStartTimes[personNumber];
                Time workEndTime = workEndTimes[personNumber];
                FirstPass(eventCount, ref invalidHousehold, person);
                AddPimaryWorkEpisode(person, eventCount, workStartTime, workEndTime);
                LunchPass(person, eventCount, workStartTime, workEndTime);
            });

            // check to see if we have an invalid household, if we do we do not add the data!
            if (invalidHousehold)
            {
                return;
            }
            StoreResults(household.ExpansionFactor, eventCount);

            Interlocked.Increment(ref CurrentHousehold);
            Progress = ((float)CurrentHousehold / NumberOfHouseholds) / TotalIterations + CompletedIterationPercentage;
            household.Recycle();
        }
Ejemplo n.º 10
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);
                    }
                }
                System.Threading.Interlocked.Increment(ref CurrentHousehold);

                if(RecycleHouseholdData)
                {
                    ReleaseModeData(hhld);
                    hhld.Recycle();
                }
            }
        }
 private void Run(ITashaHousehold household, BlockingCollection<Result> resultList)
 {
     var numberOfPeople = household.Persons.Length;
     if ( household.NumberOfAdults >= 2 )
     {
         Time[] workStartTimes = new Time[numberOfPeople];
         Time[] workEndTimes = new Time[numberOfPeople];
         for ( int i = 0; i < numberOfPeople; i++ )
         {
             AssignEpisodes( household.Persons[i], ref workStartTimes[i], ref workEndTimes[i], null );
         }
         int[] jointMarket = new int[this.NumberOfAdults];
         int[] jointOther = new int[this.NumberOfAdults];
         bool any = false;
         foreach ( var person in household.Persons )
         {
             foreach ( var tc in person.TripChains )
             {
                 if ( tc.JointTripRep )
                 {
                     var chains = tc.JointTripChains;
                     int adults = 0;
                     for ( int i = 0; i < chains.Count; i++ )
                     {
                         if ( chains[i].Person.Adult )
                         {
                             adults++;
                         }
                     }
                     any = true;
                     adults = adults > this.NumberOfAdults ? this.NumberOfAdults : adults;
                     foreach ( var trip in tc.Trips )
                     {
                         switch ( trip.Purpose )
                         {
                             case Activity.JointOther:
                                 jointOther[adults]++;
                                 break;
                             case Activity.JointMarket:
                                 jointMarket[adults]++;
                                 break;
                         }
                     }
                 }
             }
         }
         if ( any )
         {
             resultList.Add( new Result()
             {
                 Adults = household.NumberOfAdults,
                 Children = household.Persons.Length - household.NumberOfAdults > 0,
                 ExpansionFactor = household.ExpansionFactor,
                 JointMarketAdults = jointMarket,
                 JointOthersAdults = jointOther
             } );
         }
     }
     System.Threading.Interlocked.Increment( ref this.CurrentHousehold );
     household.Recycle();
 }
Ejemplo n.º 12
0
 private void Run(int i, ITashaHousehold household)
 {
     foreach ( var module in this.PostHousehold )
     {
         module.Execute( household, i );
     }
     System.Threading.Interlocked.Increment( ref this.CurrentHousehold );
     this.Progress = ( (float)this.CurrentHousehold / this.NumberOfHouseholds ) / this.TotalIterations + this.CompletedIterationPercentage;
     household.Recycle();
 }