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 SimulationObject GetNextAgent(DiscreteMarginalDistribution f_x, ConditionalDistribution g_x, string dimension, SimulationObject prvAgent, SpatialZone currZone, int agentID) { switch(prvAgent.GetAgentType()) { case AgentType.Household: return GetNextAgentHousehold( f_x, g_x, dimension, (Household)prvAgent, currZone); case AgentType.Person: return GetNextAgentPerson( f_x, g_x, dimension, (Person)prvAgent, currZone); case AgentType.HouseholdPersonComposite: return GetNextAgentCompositeHhld( f_x, g_x, dimension, (HouseholdPersonComposite)prvAgent, currZone, agentID); default: return null; } }
private KeyValPair GenerateNextFromG_X(ConditionalDistribution curG_X, SimulationObject prvAgent, SpatialZone currZone, int agentID) { List <KeyValPair> curCom = curG_X.GetCommulativeValue( prvAgent, currZone, agentID); double randVal = myRand.NextDoubleInRange(0, (double) ((KeyValPair)curCom[curCom.Count - 1]).Value); for (int i = 0; i < curCom.Count; i++) { if (randVal <= ((KeyValPair)curCom[i]).Value) { KeyValPair myPair; myPair.Category = ((KeyValPair)curCom[i]).Category; myPair.Value = curG_X.GetValue(curG_X.GetDimensionName(), myPair.Category, prvAgent.GetNewJointKey(curG_X.GetDimensionName()), currZone); return myPair; } } return new KeyValPair(); }