public override double GetValue(string dimension, string category, string key, SpatialZone curZ) { //string procdKey = ProcessKey(key); // [BF] For now here it will always be income or education if(dimension == "IncomeLevel") { return (double) ComputeIncomeProbablities( category, key, curZ); } else if (dimension == "NumOfWorkers") { return (double) ComputeEducationProbablities( category, key, curZ); } else if (dimension == "NumOfCars") { return (double) ComputeCarProbablities( category, key, curZ); } else if (dimension == "DwellingType") { return (double)ComputeDwellingProbablities( category, key, curZ); } return 0; }
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); }
private List<KeyValPair> ComputeCarCommulative(string procdKey, SpatialZone curZ) { double comVal = 0.00; var comList = new List<KeyValPair>(); var valList = GetUtilityValuesForCar(procdKey, curZ); double utilSum = (double)valList[0] + (double)valList[1] + (double)valList[2] + (double)valList[3]; KeyValPair currPair = new KeyValPair(); currPair.Category = "0";//No Car currPair.Value = (double)valList[0] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "1";//1 Car currPair.Value = comVal + (double)valList[1] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "2"; //2 Cars currPair.Value = comVal + (double)valList[2] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "3"; //3 or more Cars currPair.Value = comVal + (double)valList[3] / utilSum; comList.Add(currPair); return comList; }
public override double GetValue(string dim, string fullKey, SpatialZone curZ) { string cat = fullKey.Substring(0, fullKey.IndexOf(Constants.CATEGORY_DELIMITER) - 1); string key = fullKey.Substring( fullKey.IndexOf(Constants.CATEGORY_DELIMITER) + 1 , fullKey.Length - 1); return GetValue(cat, dim, key, curZ); }
// the method assumes that the conditionals are full conditionals // The data processing has already been done // [BF] The method should be changed so that it can generate any // kind of agents public List<SimulationObject> GenerateAgents(SpatialZone currZone, int numAgents, SimulationObject initAgent, bool warmUpStatus, List<ConditionalDistribution> mobelCond, OutputFileWriter currWriter) { switch(initAgent.GetAgentType()) { case AgentType.Household: return GenerateHousholds(currZone, numAgents, (Household)initAgent, warmUpStatus, mobelCond, currWriter); case AgentType.Person: return GeneratePersons(currZone, numAgents, (Person)initAgent, warmUpStatus, currWriter); } return null; }
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)); }
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 void CreateSpatialZones() { using (TextReader myFileReader = new StreamReader(Path.Combine(Constants.DATA_DIR, "PD_hhldType.txt"))) { string strTok; myFileReader.ReadLine(); while ((strTok = myFileReader.ReadLine()) != null) { string[] strToken = strTok.Split(','); SpatialZone currZone = new SpatialZone(); currZone.SetName(strToken[0]); ZonalCollection.Add(strToken[0], currZone); } } }
public virtual double GetValue(string dimension, string category, string key, SpatialZone curZ) { return 0; }
public virtual List<KeyValPair> GetCommulativeValue(SimulationObject composite, SpatialZone curZ, int personId) { return null; }
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; }
// commulative probability or count for the key public override List<KeyValPair> GetCommulativeValue(string key, SpatialZone curZ) { var currComm = new List<KeyValPair>(); double commCnt = 0; key = ProcessKey(key); foreach (var currEnt in Data) { KeyValPair currPair; double value; currPair.Category = currEnt.Key; if (currEnt.Value.TryGetValue(key, out value)) { currPair.Value = value + commCnt; } else { currPair.Value = commCnt; } commCnt = currPair.Value; currComm.Add(currPair); } return currComm; }
private List<double> GetUtilityValuesForNumberOfVehicles( HouseholdPersonComposite composite,SpatialZone curZ) { Household hhld = composite.getHousehold().CreateNewCopy(); //String key = hhld.GetNewJointKey(GetDimensionName()); //string[] curKeys = key.Split(Constants.CONDITIONAL_DELIMITER[0]); var currValues = new List<double>(4); int myNumOfCars = (int) hhld.GetNumOfCars(); int dwellType = (int) hhld.GetDwellingType(); int hhldSize = (int) hhld.GetHhldSize(); currValues.Add(1); int apart = Convert.ToInt32(dwellType== 1); int town = Convert.ToInt32(dwellType == 2); double z_oneCar = curZ.GetCarMarginal().GetValue("1"); int oneAdult = Convert.ToInt32(hhldSize == 0); int twoAdults = Convert.ToInt32(hhldSize == 2); int twoAdultsChildren = Convert.ToInt32(hhldSize == 3); int twoPlusAdults = Convert.ToInt32(hhldSize == 2 || hhldSize == 4); int h_lYes_1 = Convert.ToInt32(composite.Count_driving_license_yes == 1); int h_lYes_2 = Convert.ToInt32(composite.Count_driving_license_yes == 2); int h_lYes_3 = Convert.ToInt32(composite.Count_driving_license_yes == 3); int h_lNo_1 = Convert.ToInt32(composite.Count_driving_license_no == 1); int h_lNo_2 = Convert.ToInt32(composite.Count_driving_license_no == 2); int h_lNo_3 = Convert.ToInt32(composite.Count_driving_license_no == 3); int h_lNo_4Plus = Convert.ToInt32(composite.Count_driving_license_no >= 4); int h_FT_1 = Convert.ToInt32(composite.Count_full_time == 1); int h_FT_2 = Convert.ToInt32(composite.Count_full_time == 2); int h_FT_3Plus = Convert.ToInt32(composite.Count_full_time >= 3); int h_homeFT_1Plus = Convert.ToInt32(composite.Count_full_time_home >= 1); int h_homePT_1Plus = Convert.ToInt32(composite.Count_full_time_home >= 1); int h_eNE_1 = Convert.ToInt32(composite.Count_unemployed == 1); int h_eNE_2 = Convert.ToInt32(composite.Count_unemployed == 2); int h_eNE_3 = Convert.ToInt32(composite.Count_unemployed == 3); int h_eNE_4Plus = Convert.ToInt32(composite.Count_unemployed >= 4); int h_PT_1 = Convert.ToInt32(composite.Count_part_time == 1); int h_officeCler_1 = Convert.ToInt32(composite.Count_clerical_manufacturing == 1); int h_manConst_1 = Convert.ToInt32(composite.Count_costruction_man == 1); int h_manConst_2Plus = Convert.ToInt32(composite.Count_costruction_man >= 2); int h_profMan_1 = Convert.ToInt32(composite.Count_professional_man == 1); int h_profMan_2Plus = Convert.ToInt32(composite.Count_professional_man >= 2); int h_retail_1 = Convert.ToInt32(composite.Count_retail == 1); int h_retail_2 = Convert.ToInt32(composite.Count_retail == 2); int h_retail_3Plus = Convert.ToInt32(composite.Count_retail >= 3); int h_zero_1 = Convert.ToInt32(composite.Count_less11 == 1); int h_zero_2 = Convert.ToInt32(composite.Count_less11 == 2); int h_zero_3 = Convert.ToInt32(composite.Count_less11 == 3); int h_eleven_1Plus = Convert.ToInt32(composite.Count_11 >= 1); int h_fourteen_1Plus = Convert.ToInt32(composite.Count_14 >= 1); int h_sixteen_1Plus = Convert.ToInt32(composite.Count_16 >= 1); int h_eighteen_1 = Convert.ToInt32(composite.Count_18 == 1); int h_eighteen_2Plus = Convert.ToInt32(composite.Count_18 >= 2); int h_twentysix_1 = Convert.ToInt32(composite.Count_26 == 1); int h_twentysix_2Plus = Convert.ToInt32(composite.Count_26 >= 2); int h_thirtyone_1 = Convert.ToInt32(composite.Count_31 == 1); int h_thirtyone_2Plus = Convert.ToInt32(composite.Count_31 >= 2); int h_fortyone_1 = Convert.ToInt32(composite.Count_41 == 1); int h_fortyone_2Plus = Convert.ToInt32(composite.Count_41 >= 2); int h_fiftyone_1 = Convert.ToInt32(composite.Count_51 == 1); int h_fiftyone_2Plus = Convert.ToInt32(composite.Count_51 >= 2); int h_fiftyfive_1 = Convert.ToInt32(composite.Count_55 == 1); int h_fiftyfive_2Plus = Convert.ToInt32(composite.Count_55 >= 2); int h_sixtyfivePlus_1 = Convert.ToInt32(composite.Count_65 >= 1); int h_sixtyfivePlus_2Plus = Convert.ToInt32(composite.Count_65 >= 2); int h_male_1 = Convert.ToInt32(composite.Count_male == 1); int h_male_3 = Convert.ToInt32(composite.Count_male == 3); int h_female_2 = Convert.ToInt32(composite.Count_female == 2); currValues.Add(Math.Exp(2.48 * 1.00 + -1.19 * apart + -0.185 * town + -2.28 * z_oneCar + -4.09 * oneAdult + -4.25 * twoAdults + 0.197 * twoAdultsChildren + -4.08 * twoPlusAdults + 3.25 * h_lYes_1 + 3.00 * h_lYes_2 + 2.27 * h_lYes_3 + -1.40 * h_lNo_1 + -2.88 * h_lNo_2 + -3.97 * h_lNo_3 + -5.66 * h_lNo_4Plus + 0.583 * h_FT_1 + 0.985 * h_FT_2 + 1.17 * h_FT_3Plus + 0.571 * h_homeFT_1Plus + 0.257 * h_homePT_1Plus + 0.468 * h_eNE_1 + 1.03 * h_eNE_2 + 1.40 * h_eNE_3 + 1.81 * h_eNE_4Plus + 0.125 * h_PT_1 + 0.251 * h_officeCler_1 + 0.655 * h_manConst_1 + 0.891 * h_manConst_2Plus + 0.440 * h_profMan_1 + 0.400 * h_profMan_2Plus + 0.368 * h_retail_1 + 0.560 * h_retail_2 + 1.28 * h_retail_3Plus + -3.05 * h_zero_1 + -1.84 * h_zero_2 + -1.07 * h_zero_3 + 1.16 * h_eleven_1Plus + 1.21 * h_fourteen_1Plus + 1.09 * h_sixteen_1Plus + 0.505 * h_eighteen_1 + 0.973 * h_eighteen_2Plus + 0.328 * h_twentysix_1 + 0.915 * h_twentysix_2Plus + 0.564 * h_thirtyone_1 + 1.16 * h_thirtyone_2Plus + 0.664 * h_fortyone_1 + 1.46 * h_fortyone_2Plus + 0.754 * h_fiftyone_1 + 1.66 * h_fiftyone_2Plus + 0.855 * h_fiftyfive_1 + 2.11 * h_fiftyfive_2Plus + 1.25 * h_sixtyfivePlus_1 + 2.63 * h_sixtyfivePlus_2Plus + 0.0863 * h_male_1 + 0.200 * h_male_3 + -0.127 * h_female_2)); double z_twoCars = curZ.GetCarMarginal().GetValue("2"); int oneAdultChildren = Convert.ToInt32(hhldSize == 3); int h_male_2 = Convert.ToInt32(composite.Count_male == 2); int h_male_4Plus = Convert.ToInt32(composite.Count_male >= 4); int h_female_3 = Convert.ToInt32(composite.Count_female == 3); int h_female_4Plus = Convert.ToInt32(composite.Count_female >= 4); currValues.Add(Math.Exp(-0.577 * 1.00 + -2.39 * apart + -0.858 * town + 5.45 * z_twoCars + -5.05 * oneAdult + 0.460 * oneAdultChildren + -5.13 * twoAdults + 0.308 * twoAdultsChildren + -4.94 * twoPlusAdults + 1.28 * h_lYes_1 + 3.11 * h_lYes_2 + 2.49 * h_lYes_3 + -2.06 * h_lNo_1 + -4.02 * h_lNo_2 + -5.62 * h_lNo_3 + -7.96 * h_lNo_4Plus + 1.09 * h_FT_1 + 1.91 * h_FT_2 + 1.93 * h_FT_3Plus + 0.898 * h_homeFT_1Plus +0.501 * h_homePT_1Plus + 0.450 * h_eNE_1 + 0.891 * h_eNE_2 + 1.26 * h_eNE_3 + 1.51 * h_eNE_4Plus + 0.268 * h_PT_1 + 0.289 * h_officeCler_1 + 0.883 * h_manConst_1 + 0.965 * h_manConst_2Plus + 0.652 * h_profMan_1 + 0.621 * h_profMan_2Plus + 0.512 * h_retail_1 + 0.736 * h_retail_2 + 1.32 * h_retail_3Plus + -3.76 * h_zero_1 + -2.26 * h_zero_2 + -1.38 * h_zero_3 + 1.45 * h_eleven_1Plus + 1.40 * h_fourteen_1Plus + 0.935 * h_sixteen_1Plus + 0.163 * h_eighteen_1 + 0.433 * h_eighteen_2Plus + 0.281 * h_twentysix_1 + 0.870 * h_twentysix_2Plus + 0.480 * h_thirtyone_1 + 1.15 * h_thirtyone_2Plus + 0.702 * h_fortyone_1 + 1.71 * h_fortyone_2Plus + 0.961 * h_fiftyone_1 + 2.11 * h_fiftyone_2Plus + 1.15 * h_fiftyfive_1 + 2.68 * h_fiftyfive_2Plus + 1.45 * h_sixtyfivePlus_1 + 2.97 * h_sixtyfivePlus_2Plus + 0.900 * h_male_1 + 1.21 * h_male_2 + 1.85 * h_male_3 + 2.28 * h_male_4Plus + 0.328 * h_female_2 + 0.817 * h_female_3 + 1.35 * h_female_4Plus)); double z_threePlusCars = curZ.GetCarMarginal().GetValue("3"); currValues.Add(Math.Exp(-1.19 * 1.00 + -3.18 * apart + -1.55 * town + 15.2 * z_threePlusCars + -5.01 * oneAdult + -5.35 * twoAdults + -4.90 * twoPlusAdults + 1.09 * h_lYes_2 + 1.93 * h_lYes_3 + -2.52 * h_lNo_1 + -4.78 * h_lNo_2 + -6.69 * h_lNo_3 + -9.39 * h_lNo_4Plus + 1.18 * h_FT_1 + 2.15 * h_FT_2 + 2.67 * h_FT_3Plus + 1.18 * h_homeFT_1Plus + 0.669 * h_homePT_1Plus + 0.239 * h_eNE_1 + 0.537 * h_eNE_2 + 0.877 * h_eNE_3 + 1.10 * h_eNE_4Plus + 0.250 * h_PT_1 + 0.312 * h_officeCler_1 + 1.02 * h_manConst_1 + 1.10 * h_manConst_2Plus + 0.790 * h_profMan_1 + 0.769 * h_profMan_2Plus + 0.539 * h_retail_1 + 0.786 * h_retail_2 + 1.37 * h_retail_3Plus + -3.64 * h_zero_1 + -2.18 * h_zero_2 + -1.16 * h_zero_3 + 1.28 * h_eleven_1Plus + 1.32 * h_fourteen_1Plus + 0.303 * h_sixteen_1Plus + 0.343 * h_twentysix_1 + 0.841 * h_twentysix_2Plus + 0.572 * h_thirtyone_1 + 1.27 * h_thirtyone_2Plus + 0.857 * h_fortyone_1 + 2.16 * h_fortyone_2Plus + 1.31 * h_fiftyone_1 + 2.87 * h_fiftyone_2Plus + 1.46 * h_fiftyfive_1 + 3.36 * h_fiftyfive_2Plus + 1.70 * h_sixtyfivePlus_1 + 3.34 * 2.63 + 1.46 * h_male_1 + 2.04 * h_male_2 + 3.00 * h_male_3 + 4.02 * h_male_4Plus + 0.594 * h_female_2 + 1.45 * h_female_3 + 2.39 * h_female_4Plus)); return currValues; }
private List<double> GetUtilityValuesForIncome(HouseholdPersonComposite composite, SpatialZone curZ) { Household hhld = composite.getHousehold().CreateNewCopy(); String key = hhld.GetNewJointKey(GetDimensionName()); string[] curKeys = key.Split(Constants.CONDITIONAL_DELIMITER[0]); var currValues = new List<double>(5); currValues.Add(1.00); currValues.Add(Math.Exp(-0.859 + 0.000783 * curZ.GetAverageIncome() / Constants.BFRANC_TO_EURO + 1.16 * Int16.Parse(curKeys[4]) + 1.15 * Int16.Parse(curKeys[1]))); currValues.Add(Math.Exp(-4.57 + 0.674 * Int16.Parse(curKeys[3]) + 0.0012 * curZ.GetAverageIncome() / Constants.BFRANC_TO_EURO + 1.87 * Int16.Parse(curKeys[4]) + 0.409 * Int16.Parse(curKeys[5]) + 2.2 * Int16.Parse(curKeys[1]))); currValues.Add(Math.Exp(-8.11 + 1.38 * Int16.Parse(curKeys[3]) + 0.00157 * curZ.GetAverageIncome() / Constants.BFRANC_TO_EURO + 2.22 * Int16.Parse(curKeys[4]) + 0.415 * Int16.Parse(curKeys[5]) + 2.33 * Int16.Parse(curKeys[1]))); currValues.Add(Math.Exp(-10.5 + 1.61 * Int16.Parse(curKeys[3]) + 0.0016 * curZ.GetAverageIncome() / Constants.BFRANC_TO_EURO + 3.04 * Int16.Parse(curKeys[4]) + 0.415 * Int16.Parse(curKeys[5]) + 1.64 * Int16.Parse(curKeys[1]))); return currValues; }
private List<double> GetUtilityValuesForEducation(HouseholdPersonComposite composite, SpatialZone curZ) { Household hhld = composite.getHousehold().CreateNewCopy(); String key = hhld.GetNewJointKey(GetDimensionName()); string[] curKeys = key.Split(Constants.CONDITIONAL_DELIMITER[0]); List<double> currValues = new List<double>(3); currValues.Add(1.00); currValues.Add(Math.Exp(-2.96 + 0.238 * Int16.Parse(curKeys[4]) + 3.34 * curZ.GetPercentHighEducated() + 0.24 * Int16.Parse(curKeys[3]) + 0.393 * Int16.Parse(curKeys[1]))); currValues.Add(Math.Exp(-7.19 + 0.701 * Int16.Parse(curKeys[4]) + 4.34 * curZ.GetPercentHighEducated() + 1.09 * Int16.Parse(curKeys[3]) + 0.851 * Int16.Parse(curKeys[1]))); return currValues; }
//TODO: //***Update the methode GetValue()*** /* public override double GetValue(string dim,string cat , HouseholdPersonComposite composite, SpatialZone curZ) { string cat = fullKey.Substring(0, fullKey.IndexOf(Constants.CATEGORY_DELIMITER) - 1); string key = fullKey.Substring( fullKey.IndexOf(Constants.CATEGORY_DELIMITER) + 1 , fullKey.Length - 1); return GetValue(cat, dim, key, curZ); }*/ public override double GetValue(string dimension, string category, SimulationObject composite_person, SpatialZone curZ) { //string procdKey = ProcessKey(key); // [BF] For now here it will always be income or education //HouseHold if(dimension == "IncomeLevel") { return (double) ComputeIncomeProbablities( category, (HouseholdPersonComposite)composite_person, curZ); } else if (dimension == "NumOfWorkers") { return (double) ComputeEducationProbablities( category, (HouseholdPersonComposite)composite_person, curZ); } else if (dimension == "DwellingType") { return (double)ComputeDwellingTypeProbablities( category, (HouseholdPersonComposite)composite_person, curZ); } else if (dimension == "NumOfKids") { return (double)ComputeNumberOfChildreProbablities( category, (HouseholdPersonComposite)composite_person); } else if (dimension == "HouseholdSize") { return (double)ComputeHouseholdTypeProbablities( category, (HouseholdPersonComposite)composite_person); } else if (dimension == "NumOfPeople") { return (double)ComputeNumberOfPeopleProbablities( category, (HouseholdPersonComposite)composite_person); } else if (dimension == "NumOfCars") { return (double)ComputeNumberOfVehiclesProbablities( category, (HouseholdPersonComposite)composite_person, curZ); } else if (dimension == "PublicTransitPass") { return (double)ComputePublicTransitPassProbablities( category, (HouseholdPersonComposite)composite_person); } //Person else if (dimension == "Sex") { return (double)ComputeSexProbablities( category, (Person)composite_person); } else if (dimension == "DrivingLicense") { return (double)ComputeDriverLisenceProbablities( category, (Person)composite_person); } else if (dimension == "Occupation") { return (double)ComputeOccupationProbablities( category, (Person)composite_person, curZ); } else if (dimension == "EmploymentStatus") { return (double)ComputeEmploymentStatusProbablities( category, (Person)composite_person); } else if (dimension == "Age") { return (double)ComputeAgeProbablities( category, (Person)composite_person); } return 0; }
public void FillZonalData(Dictionary<string,SpatialZone> currTable) { string strTok; FileReader.ReadLine(); while ((strTok = FileReader.ReadLine()) != null) { string[] strToken = strTok.Split(','); if (!currTable.ContainsKey(strToken[0])) { SpatialZone curZ = new SpatialZone(); curZ.SetName(strToken[0]); curZ.SetEPFLName(strToken[1]); //curZ.SetHhldControlTotal(strToken[0],uint.Parse(strToken[2])); curZ.SetAverageIncome(Double.Parse(strToken[2]) *Constants.BFRANC_TO_EURO); curZ.SetPercentHighEducated(Double.Parse(strToken[3])); curZ.SetSurfaceOne(double.Parse(strToken[4])); curZ.SetSurfaceOne(double.Parse(strToken[5])); curZ.SetSurfaceOne(double.Parse(strToken[6])); curZ.SetSurfaceOne(double.Parse(strToken[7])); //curZ.SetPercUnitsChosen(Double.Parse(strToken[4])); currTable.Add(strToken[0], curZ); } } }
private List<double> GetUtilityValuesForOccupation(Person person, SpatialZone curZ) { var currValues = new List<double>(5); currValues.Add(1); int twoAdultsChildren = Convert.ToInt32(person.GetHhld().GetHhldSize() == HouseholdSize.TwoAdultsChildren); int twoPlusAdultsChildren = Convert.ToInt32(person.GetHhld().GetHhldSize() == HouseholdSize.TwoAdultsChildren || person.GetHhld().GetHhldSize() == HouseholdSize.ThreeOrMoreAdultsChildren); int homeFT = Convert.ToInt32(person.GetEmploymentStatus() == EmploymentStatus.FullTimeHome); int homePT = Convert.ToInt32(person.GetEmploymentStatus() == EmploymentStatus.PartTimeHome); int PT = Convert.ToInt32(person.GetEmploymentStatus() == EmploymentStatus.PartTime); int apart = Convert.ToInt32(person.GetHhld().GetDwellingType() == DwellingType.Apartment); int eighteen = Convert.ToInt32(person.GetAge() == Age.EighteenToTwentyFive); int twentysix = Convert.ToInt32(person.GetAge() == Age.TwentySixToThirty); int fortyone = Convert.ToInt32(person.GetAge() == Age.FortyOneToFifty); int fiftyone = Convert.ToInt32(person.GetAge() == Age.FiftyOneToFiftyFour); int fiftyfive = Convert.ToInt32(person.GetAge() == Age.FiftyfiveToSixtyFour); int thirtyone = Convert.ToInt32(person.GetAge() == Age.ThirtyOneToForty); int threePlusCars = Convert.ToInt32(person.GetHhld().GetNumOfCars() == NumOfCars.ThreeOrMore); double z_manConst = curZ.GetPersonOccuMarginal().GetValue("1"); int oneAdultChildren = Convert.ToInt32(person.GetHhld().GetHhldSize() == HouseholdSize.OneAdultOneChild); int twoAdults = Convert.ToInt32(person.GetHhld().GetHhldSize() == HouseholdSize.Twoadults); int twoPlusAdults = Convert.ToInt32(person.GetHhld().GetHhldSize() == HouseholdSize.ThreeOrMoreAdults || person.GetHhld().GetHhldSize() == HouseholdSize.Twoadults); int oneCar = Convert.ToInt32(person.GetHhld().GetNumOfCars() == NumOfCars.OneCar); int twoCars = Convert.ToInt32(person.GetHhld().GetNumOfCars() == NumOfCars.TwoCars); currValues.Add(Math.Exp(-1.95 * 1.00 + -0.746 * oneAdultChildren + 0.280 * twoAdults + 0.594 * twoAdultsChildren + 0.556 * twoPlusAdults + 0.827 * twoPlusAdultsChildren + 0.247 * apart + 0.0751 * oneCar + 0.0867 * threePlusCars + 2.13 * homeFT + 0.237 * homePT + 0.841 * PT + -0.106 * eighteen + -0.123 * twentysix + -0.137 * thirtyone + 0.145 * fiftyone + 0.140 * fiftyfive + 16.1 * z_manConst)); int town = Convert.ToInt32(person.GetHhld().GetDwellingType() == DwellingType.Townhouse); int fourteen = Convert.ToInt32(person.GetAge() == Age.FourteenToFifteen); int sixteen = Convert.ToInt32(person.GetAge() == Age.SixteenToSeventeen); int sixtyfivePlus = Convert.ToInt32(person.GetAge() == Age.MoreThanSixtyFive); double z_profMan = curZ.GetPersonOccuMarginal().GetValue("2"); currValues.Add(Math.Exp(-0.648 * 1.00 + -0.0753 * twoAdults + 0.121 * twoAdultsChildren + -0.243 * twoPlusAdults + -0.110 * twoPlusAdultsChildren + -0.265 * apart + -0.147 * town + 0.271 * oneCar + 0.337 * twoCars + 0.303 * threePlusCars + 2.31 * homeFT + -1.02 * fourteen + -0.866 * sixteen + -0.389 * eighteen + 0.0738 * thirtyone + 0.229 * sixtyfivePlus + 7.22 * z_profMan)); int eleven = Convert.ToInt32(person.GetAge() == Age.ElevenToThirteen); double z_retail = curZ.GetPersonOccuMarginal().GetValue("3"); currValues.Add(Math.Exp(-1.05 * 1.00 + 0.308 * oneAdultChildren + 0.205 * twoAdults + 0.479 * twoAdultsChildren + 0.379 * twoPlusAdults + 0.781 * twoPlusAdultsChildren + 0.220 * apart + 0.108 * town + -0.152 * oneCar + -0.245 * twoCars + -0.27 * threePlusCars + 2.85 * homeFT + 1.48 * homePT + 2.30 * PT + 3.90 * eleven + 2.20 * fourteen + 2.22 * sixteen + 0.507 * eighteen + 0.160 * twentysix + 0.0563 * fiftyone + 0.129 * fiftyfive + 0.398 * sixtyfivePlus + 6.32 * z_retail)); double z_oNE = curZ.GetPersonOccuMarginal().GetValue("4"); currValues.Add(Math.Exp(0.743 * 1.00 + 2.37 * oneAdultChildren + 0.298 * twoAdults + 2.47 * twoAdultsChildren + 0.437 * twoPlusAdults + 2.12 * twoPlusAdultsChildren + 0.114 * apart + -0.0672 * town + -0.63 * oneCar + -1.08 * twoCars + -1.33 * threePlusCars + 8.71 * eleven + 5.34 * fourteen + 3.87 * sixteen + 0.969 * eighteen + -0.842 * twentysix + -1.70 * thirtyone + -0.528 * fiftyone + 0.517 * fiftyfive + 3.08 * sixtyfivePlus + 0.854 * z_oNE)); return currValues; }
public override double GetValue(string dim, string category, string key, SpatialZone curZ) { Dictionary<string, double> currCat; if (Data.TryGetValue(category, out currCat)) { double ret; if (currCat.TryGetValue(key, out ret)) { return ret; } return Constants.INVALID_UINT_VAL; } return Constants.INVALID_UINT_VAL; }
// Car private double ComputeCarProbablities(string category, HouseholdPersonComposite composite, SpatialZone curZ) { var valList = GetUtilityValuesForCar(composite, curZ); double logsum = ((double)valList[0] + (double)valList[1] + (double)valList[2] + (double)valList[3]); if (int.Parse(category) == (int)NumOfCars.NoCar) { return ((double)valList[0] / logsum); } else if (int.Parse(category) == (int)NumOfCars.OneCar) { return ((double)valList[1] / logsum); } else if (int.Parse(category) == (int)NumOfCars.TwoCars) { return ((double)valList[2] / logsum); } else if (int.Parse(category) == (int)NumOfCars.ThreeOrMore) { return ((double)valList[3] / logsum); } return 0.00; }
private List<SimulationObject> GeneratePersons(SpatialZone currZone, int numPerson, Person initAgent, bool warmUpStatus, OutputFileWriter currWriter) { int seltdDim = 0; List<ConditionalDistribution> condList = currZone.GetPersonDataCollectionsList(); var generatedAgents = new List<SimulationObject>(); Person prevAgent = initAgent; ImportanceSampler currImpSampler = new ImportanceSampler(); int iter = 0; if(warmUpStatus == true) { iter = Constants.WARMUP_ITERATIONS; } else { iter = Constants.SKIP_ITERATIONS * numPerson; } Person newAgent = new Person(); StringBuilder builder = new StringBuilder(); for(int i = 0; i < iter; i++) { seltdDim = randGen.NextInRange(0, condList.Count - 1); DiscreteCondDistribution currDist = (DiscreteCondDistribution)condList[seltdDim]; /*if (currDist.GetDimensionName() == "HouseholdSize2") { newAgent = (Person) currImpSampler.GetNextAgent( currZone.myHhldSize2Marginal, currDist, currDist.GetDimensionName(), (SimulationObject) prevAgent, currZone); } else if (currDist.GetDimensionName() == "Age") { newAgent = (Person)currImpSampler.GetNextAgent( currZone.myAgeMarginal, currDist, currDist.GetDimensionName(), (SimulationObject)prevAgent, currZone); } else*/ if(currDist.GetDimensionName() == "Sex") { newAgent = (Person)currImpSampler.GetNextAgent( currZone.mySexMarginal, currDist, currDist.GetDimensionName(), (SimulationObject)prevAgent, currZone); } /*else if (currDist.GetDimensionName() == "EducationLevel") { newAgent = (Person)currImpSampler.GetNextAgent( currZone.myEducationMarginal, currDist, currDist.GetDimensionName(), (SimulationObject)prevAgent, currZone); }*/ else { List<KeyValPair> currComm = currDist.GetCommulativeValue( prevAgent.GetNewJointKey(currDist.GetDimensionName()) , currZone); newAgent = (Person)GenerateNextAgent(currComm, (SimulationObject)prevAgent, currDist.GetDimensionName()); } prevAgent = newAgent; if(warmUpStatus == false && (i % Constants.SKIP_ITERATIONS == 0)) { //generatedAgents.Add(newAgent); builder.Append((int)newAgent.GetAge()); builder.Append(','); builder.Append(newAgent.GetZoneID()); builder.Append(','); builder.Append((int)newAgent.GetSex()); builder.Append(','); builder.Append((int)newAgent.GetHhldSize()); builder.Append(','); builder.Append((int)newAgent.GetEducationLevel()); currWriter.WriteToFile(builder.ToString()); builder.Clear(); } } return generatedAgents; }
public override List<KeyValPair> GetCommulativeValue(SimulationObject composite, SpatialZone curZ, int personId) { return GetCommValue(GetDimensionName(), composite, curZ, personId); }
public virtual List<KeyValPair> GetCommulativeValue(string key, SpatialZone curZ) { return null; }
private List<KeyValPair> ComputeDwellingTypeCommulative( HouseholdPersonComposite composite, SpatialZone curZ) { double comVal = 0.00; var comList = new List<KeyValPair>(); var valList = GetUtilityValuesForDwellingType(composite, curZ); KeyValPair currPair = new KeyValPair(); double utilSum = (double)valList[0] + (double)valList[1] + (double)valList[2]; currPair.Category = "0";//IncomeLevel.House.ToString(); currPair.Value = (double)valList[0] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "1";//IncomeLevel.Apartment.ToString(); currPair.Value = comVal + (double)valList[1] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "2";//IncomeLevel.Townhouse.ToString(); currPair.Value = comVal + (double)valList[2] / utilSum; comVal = currPair.Value; comList.Add(currPair); return comList; }
public virtual double GetValue(string dim, string fullKey, SpatialZone curZ) { return 0; }
private double ComputeDwellingTypeProbablities(string category, HouseholdPersonComposite composite, SpatialZone curZ) { var valList = GetUtilityValuesForDwellingType(composite, curZ); double logsum = ((double)valList[0] + (double)valList[1] + (double)valList[2] + (double)valList[3]); if (int.Parse(category) == (int)DwellingType.House) { return ((double)valList[0] / logsum); } else if (int.Parse(category) == (int)DwellingType.Apartment) { return ((double)valList[1] / logsum); } else if (int.Parse(category) == (int)DwellingType.Townhouse) { return ((double)valList[2] / logsum); } return 0.00; }
public virtual double GetValue(string dimension, string category, SimulationObject composite_person, SpatialZone curZ) { return 0; }
private List<KeyValPair> ComputeEducationCommulative(HouseholdPersonComposite composite, SpatialZone curZ) { double comVal = 0.00; var comList = new List<KeyValPair>(); var valList = GetUtilityValuesForEducation(composite, curZ); double utilSum = (double)valList[0] + (double)valList[1] + (double)valList[2]; KeyValPair currPair = new KeyValPair(); currPair.Category = "0";//NumWithUnivDeg.None.ToString(); currPair.Value = (double)valList[0] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "1";//NumWithUnivDeg.One.ToString(); currPair.Value = comVal + (double)valList[1] / utilSum; comVal = currPair.Value; comList.Add(currPair); currPair = new KeyValPair(); currPair.Category = "2";//NumWithUnivDeg.TwoOrMore.ToString(); currPair.Value = comVal + (double)valList[2] / utilSum; comList.Add(currPair); return comList; }
void LoadPesronCensusData(SpatialZone currZone) { currZone.myAgeConditional.FlushOutData(); CensusAgeFileReader. FillCollection2(currZone.myAgeConditional); currZone.myAgeConditional.SetDimensionName("Age"); currZone.mySexConditional.FlushOutData(); CensusSexFileReader. FillCollection2(currZone.mySexConditional); currZone.mySexConditional.SetDimensionName("Sex"); currZone.myHhldSizeConditional.FlushOutData(); CensusHhldSizeFileReader. FillCollection2(currZone.myHhldSizeConditional); currZone.myHhldSizeConditional.SetDimensionName("HouseholdSize2"); currZone.myEduLevelConditional.FlushOutData(); CensusEduLevelFileReader. FillCollection2(currZone.myEduLevelConditional); currZone.myEduLevelConditional.SetDimensionName("EducationLevel"); }
// Education private double ComputeEducationProbablities(string category, HouseholdPersonComposite composite, SpatialZone curZ) { var valList = GetUtilityValuesForEducation(composite, curZ); double logsum = ((double)valList[0] + (double)valList[1] + (double)valList[2]); if (int.Parse(category) == (int)NumWithUnivDeg.None) { return ((double)valList[0]/logsum); } else if (int.Parse(category) == (int)NumWithUnivDeg.One) { return ((double)valList[1] / logsum); } else if (int.Parse(category) == (int)NumWithUnivDeg.TwoOrMore) { return ((double)valList[2] / logsum); } return 0.00; }