Exemplo n.º 1
0
 public Person(string currZone)
 {
     ZoneID = currZone;
     Age = Age.EighteenToTwentyFive;
     Sex = Sex.Male;
     EducationLevel = EducationLevel.primary;
     household = new Household();
     Occupation = Occupation.TradesProfessional;
     PublicTransitPass = PublicTransitPass.MetroPass;
     EmploymentStatus = EmploymentStatus.PartTime;
     DrivingLicense = DrivingLicense.No;
     Type = AgentType.Person;
     myID = idCounter++;
 }
Exemplo n.º 2
0
 private Person(Person original)
 {
     Type = AgentType.Person;
     //copy the values
     ZoneID = original.ZoneID;
     Age = original.Age;
     Sex = original.Sex;
     EducationLevel = original.EducationLevel;
     Occupation = original.Occupation;
     PublicTransitPass = original.PublicTransitPass;
     EmploymentStatus = original.EmploymentStatus;
     DrivingLicense = original.DrivingLicense;
     household = original.household;
     myID = idCounter++;
 }
Exemplo n.º 3
0
        public HouseholdPersonComposite(Household hhld)
        {
            SetAgentType(AgentType.HouseholdPersonComposite);
            household = hhld;
            persons = new List<Person>();

            fillHouseholdWithPersons();

            foreach (Person person in persons)
            {
                person.SetHhld(household);
                updateCounts(person);
            }
            myID = idCounter++;
        }
Exemplo n.º 4
0
        public Household GetNextAgent(ModelDistribution g_x, 
            string dimension, Household prvAgent, SpatialZone currZone)
        {
            StateGenerator currStateGen = new StateGenerator();
            currStateGen.SetParameters(currZone.GetAverageIncome(),
                                            currZone.GetAverageIncome() * 2);
            double q_previous;
            double q_current = 0.00;
            double expIncome = Math.Log(prvAgent.GetIncome());
            KeyValDoublePair currPair = new KeyValDoublePair();
            //start with mean value
            currPair.Category = currStateGen.GetMean();
            currPair.Val = currStateGen.GetTransitionProbablity(currPair.Category);

            for (int i = 0; i < Constants.WARMUP_ITERATIONS; i++)
            {
                q_previous = currStateGen.GetTransitionProbablity(
                               Math.Log((double)prvAgent.GetIncome()));
                q_current = currPair.Val;
                IncomeLevel prevLvl = IncomeConvertor.ConvertValueToLevel(
                                        (uint) Math.Exp(expIncome));
                IncomeLevel currLvl = IncomeConvertor.ConvertValueToLevel(
                                        (uint) Math.Exp(currPair.Category));
                double b_prev = g_x.GetValue(dimension, prevLvl.ToString(),
                    prvAgent.GetNewJointKey(dimension), currZone);
                double b_curr = g_x.GetValue(dimension, currLvl.ToString(),
                    prvAgent.GetNewJointKey(dimension), currZone);
                if (b_prev == 0.00)
                    b_prev = 0.0000001;
                if (b_curr == 0.00)
                    b_curr = 0.0000001;
                if (q_current == 0.00)
                    q_current = 0.0000001;
                double comVal = (b_curr * q_previous) / (b_prev * q_current);
                if (comVal == 0.00)
                    comVal = 0.0000001;
                if (randGen.NextDouble() < comVal)
                {
                    expIncome = currPair.Category;
                }
                currPair = currStateGen.GetNextState();
            }
            return prvAgent.CreateNewCopy((uint)Math.Exp(expIncome));
        }
Exemplo n.º 5
0
        private List<SimulationObject> GenerateHousholds(SpatialZone currZone, int numHousehold,
                        Household initAgent, bool warmUpStatus,
                        List<ConditionalDistribution> mobelCond,
                        OutputFileWriter currWriter)
        {
            int seltdDim = 0;
            List<ConditionalDistribution> condList = currZone.GetDataHhldCollectionsList();
            for(int i = 0; i < mobelCond.Count; i++)
            {
                condList.Add(mobelCond[i]);
            }
            var generatedAgents = new List<SimulationObject>();
            Household prevAgent = initAgent;

            ImportanceSampler currImpSampler = new ImportanceSampler();
            MetropolisHasting currMHSampler = new MetropolisHasting();
            int iter = 0;
            if(warmUpStatus == true)
            {
                iter = Constants.WARMUP_ITERATIONS;
            }
            else
            {
                iter = Constants.SKIP_ITERATIONS * numHousehold;
            }
            Household newAgent = new Household();
            StringBuilder builder = new StringBuilder();
            for(int i = 0; i < iter; i++)
            {
                seltdDim = randGen.NextInRange(0, condList.Count - 1);

                ConditionalDistribution currDist = condList[seltdDim];

                // If the selected distribution is dwelling/cars
                // call important sampling

                /*if (currDist.GetDimensionName() == "DwellingType")
                {
                    newAgent = currImpSampler.GetNextAgent(currZone.myDwellMarginal,
                        currDist, currDist.GetDimensionName(),
                        prevAgent, currZone);
                }
                else if (currDist.GetDimensionName() == "NumOfCars")
                {
                    newAgent = currImpSampler.GetNextAgent(currZone.myCarsMarginal,
                        currDist, currDist.GetDimensionName(),
                        prevAgent, currZone);
                }*/

                // If the selected distribution is income
                // call MH
                //                else if (((ConditionalDistribution)condList[seltdDim])
                //                                .GetDimensionName() == "IncomeLevel")
                //                {
                //                    newAgent = myMHSampler.GetNextAgent((ModelDistribution)currDist,
                //                            currDist.GetDimensionName(), prevAgent, currZone);
                //                }
                if(currDist.GetDimensionName() == "HouseholdSize")
                {
                    newAgent = (Household)currImpSampler.GetNextAgent(
                        currZone.GetHousholdSizeDist(),
                        currDist, currDist.GetDimensionName(),
                        prevAgent, currZone);
                }
                else
                {
                    var currComm = currDist.GetCommulativeValue(
                        prevAgent.GetNewJointKey(currDist.GetDimensionName())
                        , currZone);
                    newAgent = (Household)GenerateNextAgent(currComm, prevAgent,
                        currDist.GetDimensionName());
                }

                prevAgent = newAgent;
                if(warmUpStatus == false && (i % Constants.SKIP_ITERATIONS == 0))
                {
                    generatedAgents.Add(newAgent);
                    uint currIncome = IncomeConvertor.GetEuroIncome((uint)
                                        newAgent.GetIncome());
                    builder.Append(newAgent.GetZoneID()); builder.Append(',');
                    builder.Append(currZone.GetEPFLName()); builder.Append(',');
                    builder.Append((int)newAgent.GetHhldSize()); builder.Append(',');
                    builder.Append((int)newAgent.GetNumOfWorkers()); builder.Append(',');
                    builder.Append((int)newAgent.GetNumOfKids()); builder.Append(',');
                    builder.Append((int)newAgent.GetNumOfUnivDegree()); builder.Append(',');
                    builder.Append((int)newAgent.GetIncomeLevel()); builder.Append(',');
                    builder.Append((int)newAgent.GetNumOfCars()); builder.Append(',');
                    builder.Append((int)newAgent.GetDwellingType());
                    currWriter.WriteToFile(builder.ToString());
                    builder.Clear();
                }
            }
            return generatedAgents;
        }
Exemplo n.º 6
0
 public void SetHhld(Household Household)
 {
     household = Household;
 }
Exemplo n.º 7
0
        public Household GetNextAgentHousehold(DiscreteMarginalDistribution f_x, 
            ConditionalDistribution g_x, string dimension, 
            Household prvAgent, SpatialZone currZone)
        {
            KeyValPair currDimVal;
            double currProb = 0.00;
            double currRatio = 0.00;
            int cnt = 0;
            do{
                currDimVal = GenerateNextFromG_X(g_x, prvAgent,currZone,0);
                currProb = f_x.GetValue(currDimVal.Category);
                currRatio = currProb / currDimVal.Value;
                if (currRatio > 1.00)
                {
                    currRatio = 1.00;
                }
                if (cnt > 1000)
                {
                    currRatio = 1;
                }
                cnt++;
            } while (myRand.NextDouble() > currRatio);

            // Create the household object based on the currDimVal.category
            return (Household) prvAgent.CreateNewCopy(g_x.GetDimensionName(), Int16.Parse(currDimVal.Category),0);
        }
Exemplo n.º 8
0
        private bool CheckLogicalInconsistencies(Household currHhld)
        {
            int totPer = (int)currHhld.GetHhldSize();
            int totWrk = (int)currHhld.GetNumOfWorkers();
            int totUnv = (int)currHhld.GetNumOfUnivDegree();
            int totKid = (int)currHhld.GetNumOfKids();

            if (totPer == 0)
            {
                totPer = 1;
            }

            if (totUnv > totPer)
            {
                currHhld.SetNumOfUnivDegree((NumWithUnivDeg)totPer);
                currHhld.SetNumOfWorkers((NumOfWorkers)totPer);
                currHhld.SetNumOfKids(NumOfKids.None);
                return true;
            }
            if (totWrk > totPer)
            {
                currHhld.SetNumOfWorkers((NumOfWorkers)totPer);
                currHhld.SetNumOfUnivDegree((NumWithUnivDeg)totPer);
                currHhld.SetNumOfKids(NumOfKids.None);
                return true;
            }
            if (totKid >= totPer)
            {
                currHhld.SetNumOfWorkers((NumOfWorkers)totPer);
                currHhld.SetNumOfUnivDegree((NumWithUnivDeg)totPer);
                currHhld.SetNumOfKids(NumOfKids.None);
                return true;
            }

            // number of univ degrees
            if (totKid > 0)
            {
                if ((totWrk < totUnv)
                    && (totPer < (totWrk - totUnv) + totKid + totWrk))
                {
                    currHhld.SetNumOfUnivDegree((NumWithUnivDeg)(totWrk));
                }
            }

            // number of kids
            if (totWrk == 0)
            {
                currHhld.SetNumOfKids(NumOfKids.None);
            }

            if ((totPer - totWrk == 0 && totKid > 0)
               || (totPer - totUnv == 0 && totKid > 0))
            {
                currHhld.SetNumOfKids(NumOfKids.None);
            }
            else if (totKid > totPer - totWrk)
            {
                currHhld.SetNumOfKids(NumOfKids.None);
            }
            return true;
        }
Exemplo n.º 9
0
        public Household CreateNewCopy(uint income)
        {
            Household myCopy = new Household(this);

            myCopy.myIncome = income;
            myCopy.myIncomeLevel = IncomeConvertor.ConvertValueToLevel(income);
            CheckLogicalInconsistencies(myCopy);
            return myCopy;
        }
Exemplo n.º 10
0
        public override SimulationObject CreateNewCopy(string baseDim,
            int baseDimVal, int personId)
        {
            Household myCopy = new Household(this);

            if (baseDim == "HouseholdSize")
            {
                myCopy.myHhhldSize = (HouseholdSize)baseDimVal;
            }
            else if (baseDim == "DwellingType")
            {
                myCopy.myDwellType = (DwellingType)baseDimVal;
            }
            else if (baseDim == "NumOfCars")
            {
                myCopy.myNumOfCars = (NumOfCars)baseDimVal;
            }
            else if (baseDim == "NumOfWorkers")
            {
                myCopy.myNumOfWorkers = (NumOfWorkers)baseDimVal;
            }
            else if (baseDim == "NumOfKids")
            {
                myCopy.myNumOfKids = (NumOfKids)baseDimVal;
            }
            else if (baseDim == "NumWithUnivDeg")
            {
                myCopy.myNumofUnivDeg = (NumWithUnivDeg)baseDimVal;
            }
            else if (baseDim == "IncomeLevel")
            {
                myCopy.myIncomeLevel = (IncomeLevel)baseDimVal;
            }
            else
            {
                return null;
            }
            CheckLogicalInconsistencies(myCopy);
            return myCopy;
        }
Exemplo n.º 11
0
 private Household(Household copyFrom)
 {
     myHhhldSize = copyFrom.myHhhldSize;
     numberOfAdults = copyFrom.numberOfAdults;
     myDwellType = copyFrom.myDwellType;
     myNumOfCars = copyFrom.myNumOfCars;
     myNumOfWorkers = copyFrom.myNumOfWorkers;
     myNumOfPeople = copyFrom.myNumOfPeople;
     myNumOfKids = copyFrom.myNumOfKids;
     myNumofUnivDeg = copyFrom.myNumofUnivDeg;
     myIncomeLevel = copyFrom.myIncomeLevel;
     myIncome = copyFrom.myIncome;
     Type = copyFrom.Type;
     myZoneID = copyFrom.myZoneID;
     myID = idCounter++;
 }