Exemplo n.º 1
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.º 2
0
        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();
        }