コード例 #1
0
ファイル: World.cs プロジェクト: Nasterska/Simpsynz_
        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;
                }
            }
        }
コード例 #2
0
ファイル: World.cs プロジェクト: Nasterska/Simpsynz_
        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;
                    }
                }
            }
        }