Ejemplo n.º 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();
             }
         }
     }
 }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 3
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;
        }