public void Run(Clock clock, IGlobalWelfareState state, IDimensions dimensions) { var s = state; var t = clock.Current; if (clock.IsFirstTimestep) { s.cummulativewelfare[t] = 0; } else { if (t >= s.starttimestep) { var U = Funcifier.Funcify( (double consumption) => { if (s.elasticityofmarginalutility == 1.0) { return(s.utilitycalibrationadditive + s.utilitycalibrationmultiplicative * Math.Log(consumption)); } else { return(s.utilitycalibrationadditive + s.utilitycalibrationmultiplicative * Math.Pow(consumption, 1.0 - s.elasticityofmarginalutility) / (1.0 - s.elasticityofmarginalutility)); } } ); var DF = Funcifier.Funcify( (Timestep year) => { return(Math.Pow(1.0 + s.prtp, -(year.Value - s.starttimestep.Value))); } ); var perCapitaConsumption = s.consumption[t] / s.population[t]; if (perCapitaConsumption <= 0.0) { perCapitaConsumption = 1.0; } s.cummulativewelfare[t] = s.cummulativewelfare[t - 1] + (U(perCapitaConsumption) * s.population[t] * DF(t)); s.marginalwelfare[t] = DF(t) * s.utilitycalibrationmultiplicative / Math.Pow(perCapitaConsumption, s.elasticityofmarginalutility); if (t == s.stoptimestep) { s.totalwelfare = s.cummulativewelfare[t]; } } else { s.cummulativewelfare[t] = 0; } } }
public void Run(Clock clock, IRegionalWelfareState state, IDimensions dimensions) { var s = state; var t = clock.Current; if (clock.IsFirstTimestep) { foreach (var r in dimensions.GetValues <Region>()) { s.cummulativewelfare[t, r] = 0; } } else { if (t >= s.starttimestep) { var U = Funcifier.Funcify( (double consumption) => { if (s.elasticityofmarginalutility == 1.0) { return(s.utilitycalibrationadditive + s.utilitycalibrationmultiplicative * Math.Log(consumption)); } else { return(s.utilitycalibrationadditive + s.utilitycalibrationmultiplicative * Math.Pow(consumption, 1.0 - s.elasticityofmarginalutility) / (1.0 - s.elasticityofmarginalutility)); } } ); var DF = Funcifier.Funcify( (Timestep year) => { return(Math.Pow(1.0 + s.prtp, -(year.Value - s.starttimestep.Value))); } ); foreach (var r in dimensions.GetValues <Region>()) { var w = s.cummulativewelfare[t - 1, r]; var perCapitaConsumption = s.consumption[t, r] / s.population[t, r]; // This is a lower bound if (perCapitaConsumption <= 0.0) { perCapitaConsumption = 1.0; } w = w + (U(perCapitaConsumption) * s.population[t, r] * DF(t)); s.marginalwelfare[t, r] = DF(t) * s.utilitycalibrationmultiplicative / Math.Pow(perCapitaConsumption, s.elasticityofmarginalutility); s.cummulativewelfare[t, r] = w; if (t == s.stoptimestep) { s.totalwelfare[r] = s.cummulativewelfare[t, r]; } } } else { foreach (var r in dimensions.GetValues <Region>()) { s.cummulativewelfare[t, r] = 0; } } } }