Пример #1
0
 public void CreateHouseholdPopulation()
 {
     using (var currReader = new InputDataReader(
         Constants.DATA_DIR + "SyntheticHhld_withourImpSamp.csv"))
     {
         ArrayList currPool = new ArrayList();
         RandomNumberGen currRandGen = new RandomNumberGen();
         using (var currOutputFile = new OutputFileWriter(Constants.DATA_DIR + "PopulationRealization20k.csv"))
         {
             currOutputFile.WriteToFile("HhldID,SectorID,HhldSize,NbOfWorkers,"
                         + "NbofKids,NbofUnivDegree,IncLvl,NumbCars,"
                         + "DwellTyp(PopSynt),EPFL_SectorID,BuildingID");
             while (currReader.LoadZonalPopulationPool(currPool) == true)
             {
                 string[] currStrTok = ((string)currPool[0]).Split(',');
                 int indx = 0;
                 string currKey = "";
                 if (zonalControlTotals.ContainsKey(currStrTok[1]))
                 {
                     currKey = (string)currStrTok[1];
                     indx = (int)zonalControlTotals[currKey];
                     ArrayList currRandList = currRandGen.GetNNumbersInRange(0,
                         Constants.POOL_COUNT - 1, indx);
                     for (int i = 0; i < currRandList.Count; i++)
                     {
                         string[] hhldValues = ((string)
                             currPool[(int)currRandList[i]]).Split(',');
                         int bld = Int16.Parse(hhldValues[9]) + 1;
                         currOutputFile.WriteToFile(hhldValues[0] + "," + hhldValues[1]
                                 + "," + hhldValues[3] + "," + hhldValues[4]
                                 + "," + hhldValues[5] + "," + hhldValues[6]
                                 + "," + hhldValues[7] + "," + hhldValues[8]
                                 + "," + hhldValues[9] + ","
                                 + hhldValues[2] + "," + hhldValues[2]
                                 + "0" + bld);
                     }
                 }
                 currPool.Clear();
             }
         }
     }
 }
Пример #2
0
        public void CreatePopulationByDwellingType(int seed, string poolfileName,
                string fileName)
        {
            ArrayList hhldPool = GetHouseholdPoolForClonning(poolfileName);

            using (InputDataReader currReader = new InputDataReader(poolfileName))
            using (OutputFileWriter currOutputFile = new OutputFileWriter(fileName))
            {
                ArrayList currPool = new ArrayList();
                RandomNumberGen currRandGen = new RandomNumberGen(seed);
                currOutputFile.WriteToFile("HhldID,SectorID,HhldSize,NbOfWorkers,"
                            + "NbofKids,NbofUnivDegree,IncLvl,NumbCars,"
                            + "DwellTyp(PopSynt),EPFL_SectorID,BuildingID");
                int totSingle = 0;
                int totSemi = 0;
                int totDb = 0;
                int toApt = 0;

                while (currReader.LoadZonalPopulationPool(currPool) == true)
                {
                    string[] currStrTok = ((string)currPool[0]).Split(',');
                    int indx = 0;

                    string currKey = "";
                    if (zonalControlTotals.ContainsKey(currStrTok[1]))
                    {
                        // for each type of dwelling
                        for (int i = 0; i < 4; i++)
                        {
                            ArrayList currDwellHhld = new ArrayList();
                            foreach (string currHhld in currPool)
                            {
                                string[] currHhldVal = currHhld.Split(',');
                                if (currHhldVal[(currHhldVal.Length - 1)] == i.ToString())
                                {
                                    currDwellHhld.Add(currHhld);
                                }
                            }
                            currKey = (string)currStrTok[1];
                            string[] contTotStr = (string[])zonalControlTotals[currKey];

                            // number of dwellings of certain type
                            indx = int.Parse(contTotStr[i + 2]);
                            string ZnID = contTotStr[0];
                            string ZnEFPLID = contTotStr[1];
                            string bldId = "0" + (i + 1).ToString();

                            if (indx > currDwellHhld.Count)
                            {
                                indx = indx - currDwellHhld.Count;
                                for (int x = 0; x < currDwellHhld.Count; x++)
                                {
                                    string[] hhldValues = ((string)
                                            currDwellHhld[x]).Split(',');
                                    string currHhldStr = hhldValues[0] + "," + ZnID.Substring(0, 5)
                                                + "," + hhldValues[3] + "," + hhldValues[4]
                                                + "," + hhldValues[5] + "," + hhldValues[6]
                                                + "," + hhldValues[7] + "," + hhldValues[8]
                                                + "," + hhldValues[9] + ","
                                                + contTotStr[1] + "," + contTotStr[1] + bldId;
                                    currOutputFile.WriteToFile(currHhldStr);
                                    //Console.WriteLine(currHhldStr);
                                    if (i == 0) totSingle++;
                                    else if (i == 1) totSemi++;
                                    else if (i == 2) totDb++;
                                    else toApt++;
                                }
                                ArrayList currRandList = currRandGen.GetNNumbersInRange(0,
                                    hhldPool.Count - 1, indx);
                                for (int j = 0; j < currRandList.Count; j++)
                                {
                                    string[] hhldValues = ((string)
                                        hhldPool[(int)currRandList[j]]).Split(',');
                                    string currHhldStr = ZnID + i.ToString() + j.ToString()
                                            + "," + ZnID.Substring(0, 5)
                                            + "," + hhldValues[0] + "," + hhldValues[1]
                                            + "," + hhldValues[2] + "," + hhldValues[3]
                                            + "," + hhldValues[4] + "," + hhldValues[5]
                                            + "," + hhldValues[6] + ","
                                            + ZnEFPLID + "," + ZnEFPLID + bldId;
                                    currOutputFile.WriteToFile(currHhldStr);
                                    //Console.WriteLine(currHhldStr);
                                    if (i == 0) totSingle++;
                                    else if (i == 1) totSemi++;
                                    else if (i == 2) totDb++;
                                    else toApt++;
                                }
                            }
                            else
                            {
                                ArrayList currRandList = currRandGen.GetNNumbersInRange(0,
                                    currDwellHhld.Count - 1, indx);
                                for (int j = 0; j < currRandList.Count; j++)
                                {
                                    string[] hhldValues = ((string)
                                        currDwellHhld[(int)currRandList[j]]).Split(',');
                                    string currHhldStr = hhldValues[0] + "," + ZnID.Substring(0, 5)
                                            + "," + hhldValues[3] + "," + hhldValues[4]
                                            + "," + hhldValues[5] + "," + hhldValues[6]
                                            + "," + hhldValues[7] + "," + hhldValues[8]
                                            + "," + hhldValues[9] + ","
                                            + contTotStr[1] + "," + contTotStr[1] + bldId;
                                    currOutputFile.WriteToFile(currHhldStr);
                                    //Console.WriteLine(currHhldStr);
                                    if (i == 0) totSingle++;
                                    else if (i == 1) totSemi++;
                                    else if (i == 2) totDb++;
                                    else toApt++;
                                }
                            }
                        }
                    }
                    currPool.Clear();
                }
                Console.WriteLine("Total Detached:\t" + totSingle.ToString()
                              + "\nTotal SemiDetached:\t" + totSemi.ToString()
                              + "\nTotal Attached:\t" + totDb.ToString()
                              + "\nTotal Apartment:\t" + toApt.ToString());
            }
        }
Пример #3
0
        private void OpenCensusFiles(AgentType currType)
        {
            if (currType == AgentType.Household)
            {
                CensusPersonFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Household\\CensusNumOfPers.csv");
                CensusDwellFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Household\\CensusDwellingType.csv");
                CensusCarFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Household\\CensusNumOfCars.csv");

                CensusPersonFileReader.GetConditionalList();
                CensusDwellFileReader.GetConditionalList();
                CensusCarFileReader.GetConditionalList();
            }
            else if (currType == AgentType.Person)
            {
                CensusAgeFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Person\\Person Z-Stats.csv");

                CensusSexFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Person\\Person Z-Stats.csv");

                CensusHhldSizeFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Person\\Person Z-Stats.csv");

                CensusEduLevelFileReader = new InputDataReader(
                    Constants.DATA_DIR + "\\Person\\Person Z-Stats.csv");
                CensusEduLevelFileReader.GetConditionalList();
            }
        }
Пример #4
0
        void LoadMobelData()
        {
            using (var mobelWrkrsFileReader = new InputDataReader(
                Constants.DATA_DIR + "Household\\MobelNbWrkr.csv"))
            {
                mobelWrkrsConditionals.FlushOutData();
                mobelWrkrsFileReader.FillCollection2(mobelWrkrsConditionals);
                mobelWrkrsConditionals.SetDimensionName("NumOfWorkers");
            }

            using (var mobelKidsFileReader = new InputDataReader(
                Constants.DATA_DIR + "Household\\MobelNbKids.csv"))
            {
                mobelKidsConditionals.FlushOutData();
                mobelKidsFileReader.FillCollection2(mobelKidsConditionals);
                mobelKidsConditionals.SetDimensionName("NumOfKids");
            }

            using (var mobelPersFileReader = new InputDataReader(
                Constants.DATA_DIR + "Household\\MobelNbPers.csv"))
            {
                mobelPersConditionals.FlushOutData();
                mobelPersFileReader.FillCollection2(mobelPersConditionals);
                mobelPersConditionals.SetDimensionName("HouseholdSize");
            }
        }
Пример #5
0
 public void LoadZones(AgentType CurrType)
 {
     if (CurrType == AgentType.Household)
     {
         using (var currReader = new InputDataReader(
             Constants.DATA_DIR + "Household\\CensusZonalData.csv"))
         {
             currReader.FillZonalData(ZonalCollection);
         }
     }
     else if (CurrType == AgentType.Person)
     {
         CreateSpatialZones();
     }
     else if (CurrType == AgentType.HouseholdPersonComposite)
     {
         CreateSpatialZones();
     }
 }
Пример #6
0
 public void Initialize(bool createPool, AgentType currType)
 {
     InitializeInputData(currType);
     if (createPool == true)
     {
         LoadZones(currType);
         LoadZonalData(currType);
     }
     else
     {
         if (currType != AgentType.Person)
         {
             using (InputDataReader currReader = new InputDataReader(Constants.DATA_DIR
                         + "Household\\CensusHhldCountByDwell.csv"))
             {
                 zonalControlTotals = new Hashtable();
                 currReader.FillControlTotalsByDwellType(zonalControlTotals);
             }
         }
     }
 }
Пример #7
0
        public ArrayList GetHouseholdPoolForClonning(string fileName)
        {
            ArrayList currArrayList = new ArrayList();
            ArrayList currPool = new ArrayList();
            using (var currReader = new InputDataReader(Constants.DATA_DIR + "Household\\SyntheticHhld.csv"))
            {
                RandomNumberGen currRand = new RandomNumberGen();
                while (currReader.LoadZonalPopulationPoolByType
                    (currPool, "3") == true)
                {
                    if (currArrayList.Count > 60000)
                    {
                        return currArrayList;
                    }

                    if (currPool.Count > 0)
                    {
                        int numB = (int)Math.Ceiling((currPool.Count * 0.1));
                        ArrayList curDrw = currRand.GetNNumbersInRange(
                                                0, currPool.Count - 1, (numB));
                        if (curDrw.Count > 0)
                        {
                            for (int i = 0; i < numB; i++)
                            {
                                currArrayList.Add(currPool[(int)curDrw[i]]);
                            }
                        }
                    }
                    currPool.Clear();
                }
            }
            return currArrayList;
        }