public HouseholdPersonComposite GetNextAgentCompositeHhld(DiscreteMarginalDistribution f_x, ConditionalDistribution g_x, string dimension, HouseholdPersonComposite prvAgent, SpatialZone currZone, int agentID) { KeyValPair currDimVal; double currProb = 0.00; double currRatio = 0.00; int cnt = 0; do { currDimVal = GenerateNextFromG_X(g_x, prvAgent, currZone, agentID); currProb = f_x.GetValue(currDimVal.Category); currRatio = currProb / currDimVal.Value; if (currRatio > 1.00) { currRatio = 1.00; } if (cnt > 10000) { currRatio = 1; } cnt++; } while (myRand.NextDouble() > currRatio); // Create the household object based on the currDimVal.category return (HouseholdPersonComposite)prvAgent.CreateNewCopy( g_x.GetDimensionName(), Int16.Parse(currDimVal.Category),agentID); }
public void CheckSexConsisteny(DiscreteMarginalDistribution sexMarginal) { Random myrand = new Random (); double r = 0.0; double mCnt = sexMarginal.GetValue ("0"); //Sex if (persons.Count () > 1) { if (persons [0].GetSex () == persons [1].GetSex ()) { r = myrand.NextDouble (); if (r < mCnt) { persons [0].SetSex(Sex.Male); persons [1].SetSex(Sex.Female); } else { persons [0].SetSex(Sex.Female); persons [1].SetSex(Sex.Male); } } }else if (persons.Count () == 1) { r = myrand.NextDouble (); if (r < mCnt) { persons [0].SetSex(Sex.Male); } else { persons [0].SetSex(Sex.Female); } } }