Beispiel #1
0
        public void CreateHoseholdPopulationPool(string fileName)
        {
            using (var agentsOutputFile = new OutputFileWriter(fileName))
            {
                uint agentsCreated = 1;
                uint counter = 0;
                var mobelCond = new List<ConditionalDistribution>()
                {
                    mobelWrkrsConditionals,
                    mobelKidsConditionals,
                    mobelPersConditionals
                };

                foreach (var entry in ZonalCollection)
                {
                    GibbsSampler sampler = new GibbsSampler();
                    SpatialZone currZone = (SpatialZone)entry.Value;
                    // warmup time
                    sampler.GenerateAgents(currZone,
                                    Constants.WARMUP_ITERATIONS,
                                    new Household(currZone.GetName()), true,
                                    mobelCond,
                        agentsOutputFile, null);
                    HhldsPool.Clear();
                    sampler.SetAgentCounter(agentsCreated + counter);
                    // actual generation
                    HhldsPool = sampler.GenerateAgents(currZone,
                                    Constants.POOL_COUNT,
                                    new Household(currZone.GetName()), false,
                                    mobelCond,
                        agentsOutputFile,null);
                    agentsCreated += (uint)HhldsPool.Count;
                }
            }
        }
Beispiel #2
0
 public void CreatePersonPopulationPool(string fileName)
 {
     using (var agentsOutputFile = new OutputFileWriter(fileName))
     {
         var mobelCond = new List<ConditionalDistribution>();
         foreach (var entry in ZonalCollection)
         {
             SpatialZone currZone = (SpatialZone)entry.Value;
             if (currZone.GetName() != "1004")
             {
                 continue;
             }
             var rangePartitioner = Partitioner.Create(0, Constants.POOL_COUNT);
             Parallel.ForEach(rangePartitioner, (range, loopState) =>
             {
                 using (var localWriter = new OutputFileWriter())
                 {
                     GibbsSampler sampler = new GibbsSampler();
                     var amountToSample = range.Item2 - range.Item1;
                     // warmup time
                     sampler.GenerateAgents(currZone,
                                     Constants.WARMUP_ITERATIONS,
                                     new Person(currZone.GetName()), true,
                                     mobelCond,
                             localWriter,null);
                     PersonPool.Clear();
                     // actual generation
                     PersonPool = sampler.GenerateAgents(currZone,
                                     amountToSample,
                                     new Person(currZone.GetName()), false,
                                     mobelCond,
                             localWriter,null);
                     localWriter.CopyTo(agentsOutputFile);
                 }
             });
         }
     }
 }
Beispiel #3
0
        public void CreateHoseholdCompositePopulationPool(string fileName)
        {
            List<int[]> PD = new List<int[]>();
            using (TextReader myFileReader = new StreamReader(Path.Combine(Constants.DATA_DIR, "PD_hhldType.txt")))
            {
                string strTok;
                myFileReader.ReadLine();
                while ((strTok = myFileReader.ReadLine()) != null)
                {
                    string[] strToken = strTok.Split(',');

                    int SingleAdult = int.Parse(strToken[1]);
                    int OneAdultOneChild = int.Parse(strToken[2]);
                    int Twoadults = int.Parse(strToken[3]);
                    int TwoAdultsChildren = int.Parse(strToken[4]);
                    int ThreeOrMoreAdults = int.Parse(strToken[5]);
                    int ThreeOrMoreAdultsChildren = int.Parse(strToken[6]);

                    int[] hhldTypes = { SingleAdult, OneAdultOneChild, Twoadults, TwoAdultsChildren
                                         , ThreeOrMoreAdults, ThreeOrMoreAdultsChildren};
                    PD.Add(hhldTypes);

                }
            }

            using (var agentsOutputFile = new OutputFileWriter(fileName))
            {
                uint agentsCreated = 1;
                uint counter = 0;
                StringBuilder builderHhld = new StringBuilder();
                builderHhld.Append("HouseholdID,Zone,ExpansionFactor,DwellingType,NumberOfPersons,NumberOfVehicles");

                StringBuilder builderPers = new StringBuilder();
                builderPers.Append("HouseholdID,PersonNumber,Age,Sex,License,TransitPass,EmploymentStatus,Occupation,FreeParking,StudentStatus,EmploymentZone,SchoolZone");

                agentsOutputFile.WriteToFile(builderHhld.ToString());

                String[] cc = fileName.Split ('.');
                OutputFileWriter personOutputFile = new OutputFileWriter (cc[0] + "pers.csv");
                personOutputFile.WriteToFile(builderPers.ToString());

                foreach (var entry in ZonalCollection)
                {
                    GibbsSampler sampler = new GibbsSampler();
                    SpatialZone currZone = (SpatialZone)entry.Value;
                    int[] types = PD[int.Parse(currZone.GetName()) - 1];
                    foreach (HouseholdSize size in Enum.GetValues(typeof(HouseholdSize)))
                    {
                        var type_entry = types[(int)size];
                        // warmup time
                        sampler.GenerateAgents(currZone,
                                        Constants.WARMUP_ITERATIONS,
                            new HouseholdPersonComposite(new Household(size, currZone.GetName())), true, null,
                            agentsOutputFile,personOutputFile);
                        HhldscompositePool.Clear();
                        sampler.SetAgentCounter(agentsCreated + counter);
                        // actual generation
                        HhldscompositePool = sampler.GenerateAgents(currZone,
                                        Constants.POOL_COUNT * type_entry,
                            new HouseholdPersonComposite(new Household(size, currZone.GetName())), false,  null,
                            agentsOutputFile,personOutputFile);
                        agentsCreated += (uint)HhldscompositePool.Count;
                    }
                }
            }
        }