예제 #1
0
        public void CreatePersonPopulation(string popPoolFileNm,
                            string outFileNm, int cnt)
        {
            using (TextReader currReader = new StreamReader(popPoolFileNm))
            {
                currReader.ReadLine();
                RandomNumberGen currRandGen = new RandomNumberGen();
                using (TextWriter currOutputFile = new StreamWriter(outFileNm))
                {
                    currOutputFile.WriteLine("Age,Sex,HhldSize,Edu_Lvl");
                    string currInStr;
                    int currCnt = 0;
                    while ((currInStr = currReader.ReadLine()) != null)
                    {
                        //string[] currStrTok = currInStr.Split(',');

                        if (currRandGen.NextDouble() < 0.5 && currCnt < cnt)
                        {
                            currCnt++;
                            // we can just write the file back since it is just parsing CSV to begin with
                            currOutputFile.WriteLine(currInStr);
                        }
                    }
                }
            }
        }
예제 #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
        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;
        }
예제 #4
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();
             }
         }
     }
 }
예제 #5
0
 public void Initialze(int seed)
 {
     randGen = new RandomNumberGen(seed);
 }
예제 #6
0
 public void Initialze()
 {
     randGen = new RandomNumberGen();
 }
예제 #7
0
 public MetropolisHasting()
 {
     randGen = new RandomNumberGen();
 }
예제 #8
0
        // Note that the parameters are given as log-normal ones
        // Internally they are converted into normal
        public void SetParameters(double meu, double sigma)
        {
            double meuSqr = Math.Pow(meu,2);
            double sigSqr = Math.Pow(sigma,2);

            mean = Math.Log(meuSqr/Math.Pow((meuSqr+sigSqr),0.5));
            stdev = Math.Pow(Math.Log(Math.Pow((sigma/meu),2)+1),0.5);

            myRandGen = new RandomNumberGen();
        }
예제 #9
0
 public ImportanceSampler()
 {
     myRand = new RandomNumberGen();
 }