Ejemplo n.º 1
0
 public TimeHorizonCutOffWeighting(Timestep cutoffYear, string name)
     : base()
 {
     m_baseYear = 50;
     m_cutoffYear = cutoffYear;
     m_name = name;
 }
Ejemplo n.º 2
0
        private static void StandardWeightingCombinations(out WeightingCombination[] WeightingCombinations, Timestep baseYear)
        {
            var i_weightingCombinations = new List<WeightingCombination>();

            WeightingCombination w;

            w = new WeightingCombination();
            w.Add(new RamseyRegionalDiscounting(0.00));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new ConstantDiscountrate(0.0));
            w.Add(new EquityWeighting(50, -1, 1.0));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new RamseyRegionalDiscounting(0.01));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new ConstantDiscountrate(0.01));
            w.Add(new EquityWeighting(50, -1, 1.0));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new RamseyRegionalDiscounting(0.03));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new ConstantDiscountrate(0.03));
            w.Add(new EquityWeighting(50, -1, 1.0));
            i_weightingCombinations.Add(w);

            WeightingCombinations = i_weightingCombinations.ToArray();
        }
Ejemplo n.º 3
0
 public TimeHorizonCutOffWeighting(Timestep cutoffYear)
     : base()
 {
     m_baseYear = 50;
     m_cutoffYear = cutoffYear;
     m_name = string.Format("cut off [year={0}]", m_cutoffYear);
 }
Ejemplo n.º 4
0
 //public void WriteDamage(int RunId, Damage i_Damage, int WeightingschemeId, double Weight, WeightingCombination[] WeightingCombinations)
 //{
 //    if (m_YearRegionSectorWeightingSchemeCsv != null)
 //    {
 //        m_YearRegionSectorWeightingSchemeCsv.WriteLine(
 //            (_run.OutputVerbal ? _run.Scenario.Name : _run.Scenario.Id.ToString()) +
 //            ";" +
 //            (_run.OutputVerbal ? (RunId == 0 ? "Best guess" : RunId == -1 ? "Mean" : RunId.ToString()) : RunId.ToString()) +
 //            ";" +
 //            "" +
 //            ";" +
 //            "" +
 //            ";" +
 //            (i_Damage.Year + 1950).ToString() +
 //            ";" +
 //            (_run.OutputVerbal ? LegacyRegionNames.GetName(i_Damage.Region) : i_Damage.Region.ToString()) +
 //            ";" +
 //            (_run.OutputVerbal ? Enum.GetName(typeof(Sector), i_Damage.Sector) : ((int)i_Damage.Sector).ToString()) +
 //            ";" +
 //            (_run.OutputVerbal ? WeightingCombinations[WeightingschemeId].Name : WeightingschemeId.ToString()) +
 //            ";" +
 //            (i_Damage.DamageValue * Weight).ToString("f15")
 //            );
 //    }
 //}
 public TotalDamage(Run runData, string outputPath, Parameters parameters, Timestep emissionYear, Random rand = null)
 {
     _parameters = parameters;
     _run = runData;
     _outputPath = outputPath;
     _emissionYear = emissionYear;
     _rand = rand;
 }
Ejemplo n.º 5
0
 public static void GetWeightingCombinationsFromName(string name, out WeightingCombination[] i_WeightingCombinations, Timestep baseYear)
 {
     switch (name)
     {
         case "Standard": StandardWeightingCombinations(out i_WeightingCombinations, baseYear); break;
         case "Raw": RawWeightingCombinations(out i_WeightingCombinations, baseYear); break;
         default: throw new ApplicationException("Invalid weighting scheme");
     }
 }
Ejemplo n.º 6
0
 public TMarginalRun(Run runData, MarginalGas gas, Timestep emissionyear, string outputPath, Parameters parameters, Random rand = null)
 {
     _parameters = parameters;
     _run = runData;
     _gas = gas;
     _emissionyear = emissionyear;
     _outputPath = outputPath;
     _rand = rand;
 }
Ejemplo n.º 7
0
 public TMarginalRun(MarginalGas gas, Timestep emissionyear, string outputPath, Parameters parameters, string weightingCombination, Random rand = null)
 {
     _parameters = parameters;
     _gas = gas;
     _emissionyear = emissionyear;
     _outputPath = outputPath;
     _rand = rand;
     this.WeightingCombination = weightingCombination;
     YearsToAggregate = 1000;
 }
Ejemplo n.º 8
0
        private static void RawWeightingCombinations(out WeightingCombination[] WeightingCombinations, Timestep baseYear)
        {
            var i_weightingCombinations = new List<WeightingCombination>();

            WeightingCombination w;

            w = new WeightingCombination("RAW");
            w.Add(new UnityWeight());
            i_weightingCombinations.Add(w);

            WeightingCombinations = i_weightingCombinations.ToArray();
        }
Ejemplo n.º 9
0
        public double AddDamagesUp(Damages Damages, int yearsToAggregate, Timestep emissionPeriod)
        {
            double i_totalDamage = 0.0;

            for (int year = emissionPeriod.Value; year < Math.Min(LegacyConstants.NYear, emissionPeriod.Value + yearsToAggregate); year++)
            {
                for (int region = 0; region < LegacyConstants.NoReg; region++)
                {
                    for (int sector = 0; sector < LegacyConstants.NoSector; sector++)
                    {
                        i_totalDamage += Damages[year, region, (Sector)sector] * this[year, region];
                    }
                }
            }

            return i_totalDamage;
        }
Ejemplo n.º 10
0
 public virtual void OnUpdate(Timestep ts)
 {
 }
Ejemplo n.º 11
0
        public static void GetWeightingCombinationsFromName(string name, out WeightingCombination[] i_WeightingCombinations, Timestep baseYear)
        {
            switch (name)
            {
            case "Standard": StandardWeightingCombinations(out i_WeightingCombinations, baseYear); break;

            case "Raw": RawWeightingCombinations(out i_WeightingCombinations, baseYear); break;

            default: throw new ApplicationException("Invalid weighting scheme");
            }
        }
 public override void Update(Timestep timestep, EntityUniverseFacade entityUniverseFacade)
 {
 }
Ejemplo n.º 13
0
        public void Run(Clock clock, IImpactSeaLevelRiseState state, IDimensions dimensions)
        {
            var s = state;
            var t = clock.Current;

            if (clock.IsFirstTimestep)
            {
                foreach (var r1 in dimensions.GetValues <Region>())
                {
                    foreach (var r2 in dimensions.GetValues <Region>())
                    {
                        double immsumm = 0;
                        foreach (var i in dimensions.GetValues <Region>())
                        {
                            immsumm += s.migrate[i, r1];
                        }
                        s.imigrate[r1, r2] = s.migrate[r2, r1] / immsumm;
                    }

                    var t0 = clock.StartTime;
                    s.landloss[t0, r1]       = 0.0;
                    s.cumlandloss[t0, r1]    = 0.0;
                    s.cumwetlandloss[t0, r1] = 0.0;
                    s.wetlandgrowth[t0, r1]  = 0.0;
                }
            }
            else
            {
                // slr in m/year
                double ds = s.sea[t] - s.sea[t - 1];

                foreach (var r in dimensions.GetValues <Region>())
                {
                    double ypc       = s.income[t, r] / s.population[t, r] * 1000.0;
                    double ypcprev   = s.income[t - 1, r] / s.population[t - 1, r] * 1000.0;
                    double ypcgrowth = ypc / ypcprev - 1.0;

                    if (t == Timestep.FromYear(1951))
                    {
                        ypcgrowth = 0;
                    }

                    // Needs to be in $bn per km^2
                    // Income is in billion, area is in km^2
                    double incomedens = s.income[t, r] / s.area[t, r];

                    double incomedensprev = s.income[t - 1, r] / s.area[t - 1, r];

                    double incomedensgrowth = incomedens / incomedensprev - 1.0;

                    // In population/km^2
                    // population is in million, area is in km^2
                    double popdens       = s.population[t, r] / s.area[t, r] * 1000000.0;
                    double popdensprev   = s.population[t - 1, r] / s.area[t - 1, r] * 1000000.0;
                    double popdensgrowth = popdens / popdensprev - 1.0;

                    // Unit of dryval is $bn/km^2
                    s.dryval[t, r] = s.dvbm * Math.Pow(incomedens / s.incdens, s.dvydl);

                    // Unit of wetval is $bn/km^2
                    s.wetval[t, r] = s.wvbm *
                                     Math.Pow(ypc / s.slrwvypc0, s.wvel) *
                                     Math.Pow(popdens / s.slrwvpopdens0, s.wvpdl) *
                                     Math.Pow((s.wetland90[r] - s.cumwetlandloss[t - 1, r]) / s.wetland90[r], s.wvsl);

                    double potCumLandloss = Math.Min(s.maxlandloss[r], s.dlbm[r] * Math.Pow(s.sea[t], s.drylandlossparam[r]));

                    double potLandloss = potCumLandloss - s.cumlandloss[t - 1, r];

                    // If sea levels fall, no protection is build
                    if (ds < 0)
                    {
                        s.npprotcost[t, r] = 0;
                        s.npwetcost[t, r]  = 0;
                        s.npdrycost[t, r]  = 0;
                        s.protlev[t, r]    = 0;
                    }
                    // If the discount rate < -100% people will not build protection
                    else if ((1.0 + s.slrprtp[r] + ypcgrowth) < 0.0)
                    {
                        s.npprotcost[t, r] = 0;
                        s.npwetcost[t, r]  = 0;
                        s.npdrycost[t, r]  = 0;
                        s.protlev[t, r]    = 0;
                    }
                    // Dryland value is worthless
                    else if (((1.0 + s.dvydl * incomedensgrowth) < 0.0))
                    {
                        s.npprotcost[t, r] = 0;
                        s.npwetcost[t, r]  = 0;
                        s.npdrycost[t, r]  = 0;
                        s.protlev[t, r]    = 0;
                    }
                    // Is protecting the coast infinitly expensive?
                    else if ((1.0 / (1.0 + s.slrprtp[r] + ypcgrowth)) >= 1)
                    {
                        s.npprotcost[t, r] = 0;
                        s.npwetcost[t, r]  = 0;
                        s.npdrycost[t, r]  = 0;
                        s.protlev[t, r]    = 0;
                    }
                    // Is dryland infinitly valuable?
                    else if (((1.0 + s.dvydl * incomedensgrowth) / (1.0 + s.slrprtp[r] + ypcgrowth)) >= 1.0)
                    {
                        s.npprotcost[t, r] = 0;
                        s.npwetcost[t, r]  = 0;
                        s.npdrycost[t, r]  = 0;
                        s.protlev[t, r]    = 1;
                    }
                    // Is wetland infinitly valuable?
                    else if (((1.0 + s.wvel * ypcgrowth + s.wvpdl * popdensgrowth + s.wvsl * s.wetlandgrowth[t - 1, r]) / (1.0 + s.slrprtp[r] + ypcgrowth)) >= 1.0)
                    {
                        s.npprotcost[t, r] = 0;
                        s.npwetcost[t, r]  = 0;
                        s.npdrycost[t, r]  = 0;
                        s.protlev[t, r]    = 0;
                    }
                    else
                    {
                        // NPV of protecting the whole coast
                        // pc is in $bn/m
                        s.npprotcost[t, r] = s.pc[r] * ds * (1.0 + s.slrprtp[r] + ypcgrowth) / (s.slrprtp[r] + ypcgrowth);

                        // NPV of wetland
                        if ((1.0 + s.wvel * ypcgrowth + s.wvpdl * popdensgrowth + s.wvsl * s.wetlandgrowth[t - 1, r]) < 0.0)
                        {
                            s.npwetcost[t, r] = 0;
                        }
                        else
                        {
                            s.npwetcost[t, r] = s.wmbm[r] * ds * s.wetval[t, r] * (1.0 + s.slrprtp[r] + ypcgrowth) / (s.slrprtp[r] + ypcgrowth - s.wvel * ypcgrowth - s.wvpdl * popdensgrowth - s.wvsl * s.wetlandgrowth[t - 1, r]);
                        }

                        // NPV of dryland
                        if ((1.0 + s.dvydl * incomedensgrowth) < 0.0)
                        {
                            s.npdrycost[t, r] = 0;
                        }
                        else
                        {
                            s.npdrycost[t, r] = potLandloss * s.dryval[t, r] * (1 + s.slrprtp[r] + ypcgrowth) / (s.slrprtp[r] + ypcgrowth - s.dvydl * incomedensgrowth);
                        }

                        // Calculate protection level
                        s.protlev[t, r] = Math.Max(0.0, 1.0 - 0.5 * (s.npprotcost[t, r] + s.npwetcost[t, r]) / s.npdrycost[t, r]);

                        if (s.protlev[t, r] > 1)
                        {
                            throw new Exception("protlevel >1 should not happen");
                        }
                    }

                    // Calculate actual wetland loss and cost
                    s.wetlandloss[t, r] = Math.Min(
                        s.wlbm[r] * ds + s.protlev[t, r] * s.wmbm[r] * ds,
                        s.wetmax[r] - s.cumwetlandloss[t - 1, r]);

                    s.cumwetlandloss[t, r] = s.cumwetlandloss[t - 1, r] + s.wetlandloss[t, r];

                    // Calculate wetland growth
                    s.wetlandgrowth[t, r] = (s.wetland90[r] - s.cumwetlandloss[t, r]) / (s.wetland90[r] - s.cumwetlandloss[t - 1, r]) - 1.0;

                    s.wetcost[t, r] = s.wetval[t, r] * s.wetlandloss[t, r];

                    s.landloss[t, r] = (1.0 - s.protlev[t, r]) * potLandloss;

                    s.cumlandloss[t, r] = s.cumlandloss[t - 1, r] + s.landloss[t, r];
                    s.drycost[t, r]     = s.dryval[t, r] * s.landloss[t, r];

                    s.protcost[t, r] = s.protlev[t, r] * s.pc[r] * ds;

                    if (s.landloss[t, r] < 0)
                    {
                        s.leave[t, r] = 0;
                    }
                    else
                    {
                        s.leave[t, r] = s.coastpd[r] * popdens * s.landloss[t, r];
                    }

                    s.leavecost[t, r] = s.emcst * ypc * s.leave[t, r] / 1000000000;
                }

                foreach (var destination in dimensions.GetValues <Region>())
                {
                    double enter = 0.0;
                    foreach (var source in dimensions.GetValues <Region>())
                    {
                        enter += s.leave[t, source] * s.imigrate[source, destination];
                    }
                    s.enter[t, destination] = enter;
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    double ypc = s.income[t, r] / s.population[t, r] * 1000.0;
                    s.entercost[t, r] = s.immcst * ypc * s.enter[t, r] / 1000000000;
                }
            }
        }
Ejemplo n.º 14
0
 public override void Update(Entity entity, Timestep step, EntityUniverseFacade entityUniverseFacade)
 {
 }
 public IEffect Instance(Timestep step, Entity entity, EntityPainter painter, EntityUniverseFacade facade, Blob data,
                         EffectDefinition definition, EffectMode mode)
 {
     return(new ModOptionsEvent());
 }
 public override void RenderUpdate(Timestep timestep, Entity entity, AvatarController avatarController, EntityUniverseFacade facade, int updateSteps)
 {
 }
        public override void Render(DeviceContext graphics, Matrix4F matrix, Vector3D renderOrigin, Entity entity, AvatarController avatarController, Timestep renderTimestep, RenderMode renderMode)
        {
            if (renderMode == RenderMode.Normal)
            {
                this.WorldTextRenderer.Draw(graphics, renderOrigin, matrix);

                if (GameContext.DebugGraphics.Enabled)
                {
                    BetterSignTileStateEntityLogic logic = entity.TileStateEntityLogic as BetterSignTileStateEntityLogic;
                    if (logic != null)
                    {
                        Vector2F size          = logic.GetTextRegionSize();
                        Vector3D rotatedRadius = VectorHelper.RotatePosition(this._rotation, new Vector3D(size.X, size.Y, 0) * 0.5);
                        GameContext.DebugGraphics.DrawBoxCentered(this._position, rotatedRadius, Color.Yellow, 1);
                    }
                }
            }
        }
        /// <summary>
        /// Clear out any old pending draw calls pre-render
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="renderOrigin"></param>
        /// <param name="entity"></param>
        /// <param name="avatarController"></param>
        /// <param name="renderTimestep"></param>
        public override void BeforeRender(DeviceContext graphics, Vector3D renderOrigin, Entity entity, AvatarController avatarController, Timestep renderTimestep)
        {
            this.WorldTextRenderer.Init(graphics);

            if (!this._textInitialized)
            {
                //GameContext.DebugGraphics.Enabled = true;

                BetterSignTileStateEntityLogic logic = entity.TileStateEntityLogic as BetterSignTileStateEntityLogic;
                if (logic != null)
                {
                    this._position = logic.GetCenterPosition();
                    if (this._position != Vector3D.Zero)
                    {
                        this._rotation = (logic.GetVariation() >> 10) & 3;
                        this._message  = logic.GetMessage();
                        this._color    = logic.GetColor();
                        this._scale    = logic.GetScale();
                        this._align    = logic.GetAlign();

                        this.WorldTextRenderer.DrawString(
                            this._message,
                            logic.GetTextRegionSize(),
                            this._align,
                            Vector3D.Zero,
                            this._position,
                            this._scale,
                            this._rotation,
                            this._color
                            );

                        this._textInitialized = true;
                    }
                }
            }
        }
 public override void StartEmote(Entity entity, Timestep renderTimestep, EmoteConfiguration emote)
 {
 }
Ejemplo n.º 20
0
 static void BeforeUniverseUpdateBefore(Universe universe, Timestep step)
 {
     SunbeamController.Instance.UniverseUpdateBefore(universe, step);
 }
Ejemplo n.º 21
0
        private static void RawWeightingCombinations(out WeightingCombination[] WeightingCombinations, Timestep baseYear)
        {
            var i_weightingCombinations = new List <WeightingCombination>();

            WeightingCombination w;

            w = new WeightingCombination("RAW");
            w.Add(new UnityWeight());
            i_weightingCombinations.Add(w);

            WeightingCombinations = i_weightingCombinations.ToArray();
        }
Ejemplo n.º 22
0
        private static void StandardWeightingCombinations(out WeightingCombination[] WeightingCombinations, Timestep baseYear)
        {
            var i_weightingCombinations = new List <WeightingCombination>();

            WeightingCombination w;

            w = new WeightingCombination();
            w.Add(new RamseyRegionalDiscounting(0.00));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new ConstantDiscountrate(0.0));
            w.Add(new EquityWeighting(50, -1, 1.0));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new RamseyRegionalDiscounting(0.01));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new ConstantDiscountrate(0.01));
            w.Add(new EquityWeighting(50, -1, 1.0));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new RamseyRegionalDiscounting(0.03));
            i_weightingCombinations.Add(w);

            w = new WeightingCombination();
            w.Add(new ConstantDiscountrate(0.03));
            w.Add(new EquityWeighting(50, -1, 1.0));
            i_weightingCombinations.Add(w);

            WeightingCombinations = i_weightingCombinations.ToArray();
        }
Ejemplo n.º 23
0
 public virtual void OnUpdateInternal(Timestep ts)
 {
 }
Ejemplo n.º 24
0
        public void RenderScore(DeviceContext graphics, Matrix4F matrix, Vector3D renderOrigin, Entity entity, AvatarController avatarController, Timestep renderTimestep, RenderMode renderMode)
        {
            if (renderMode != RenderMode.Normal)
            {
                return;
            }

            var logic = entity.TileStateEntityLogic as SoccerTotemTileStateEntityLogic;

            if (logic == null || !logic.HasGameStarted())
            {
                return;
            }

            var delta = (logic.GetTileCenter() - renderOrigin).ToVector3F();

            var m1 = Matrix4F.CreateTranslation(logic.Component.BlueTeamScorePos.ToVector3F())
                     .RotateUnitY(logic.GetRotationInRadians())
                     .Translate(delta);



            logic.Component.BlueNumbers[logic.BlueTeamScore].Render(graphics, m1.Multiply(matrix));

            var m2 = Matrix4F.CreateTranslation(logic.Component.RedTeamScorePos.ToVector3F())
                     .RotateUnitY(logic.GetRotationInRadians())
                     .Translate(delta);

            logic.Component.RedNumbers[logic.RedTeamScore].Render(graphics, m2.Multiply(matrix));
        }
 public override void Render(DeviceContext graphics, Matrix4F matrix, Vector3D renderOrigin, Entity entity,
                             AvatarController avatarController, Timestep renderTimestep, RenderMode renderMode)
 {
 }
Ejemplo n.º 26
0
 public void Render(Entity entity, EntityPainter painter, Timestep renderTimestep, DeviceContext graphics, ref Matrix4F matrix,
                    Vector3D renderOrigin, Vector3D position, RenderMode renderMode)
 {
 }
        public override void Render(DeviceContext graphics, Matrix4F matrix, Vector3D renderOrigin, Entity entity, AvatarController avatarController, Timestep renderTimestep, RenderMode renderMode)
        {
            if (renderMode != RenderMode.Normal)
            {
                return;
            }

            var logic = entity.TileStateEntityLogic as CenterTileStateEntityLogic;

            if (logic == null || _numberToDraw < 0)
            {
                return;
            }

            var delta = (logic.GetSpawningPosition() - renderOrigin).ToVector3F();

            var m = Matrix4F.CreateTranslation(delta);

            logic.Component.Numbers[_numberToDraw].Render(graphics, m.Multiply(matrix));
        }
Ejemplo n.º 28
0
        public void UniverseUpdateBefore(Universe universe, Timestep step)
        {
            if (!universe.Server)
            {
                var entities = new Lyst <Entity>();

                universe.GetPlayers(entities);

                Entity entity = null;

                foreach (var e in entities)
                {
                    if (ClientContext.PlayerFacade.IsLocalPlayer(e))
                    {
                        entity = e;
                    }
                }

                if (entity == null)
                {
                    return;
                }

                var tags = new List <Vector3I>();

                if (entity.Inventory.ActiveItem().Item is MultiMeterItem)
                {
                    universe.ForAllEntitiesInRange(entity.FeetLocation(), 5, tile => {
                        if (tile.Logic is ChargeableTileEntityLogic logic)
                        {
                            if (!tags.Contains(logic.Location))
                            {
                                tags.Add(logic.Location);
                            }
                        }
                    });
                }

                NameTags.Clear();
                NameTags.AddRange(tags);

                var showCables = new List <Vector3I>();

                if (!entity.Inventory.ActiveItem().IsNull())
                {
                    var item = entity.Inventory.ActiveItem().Item;

                    var config = GameContext.TileDatabase.AllMaterials()
                                 .FirstOrDefault(x => x.Code == item.GetItemCode());

                    if (config != default(TileConfiguration) || item is CableDrillItem)
                    {
                        var component = config?.Components.Select <ChargeableComponent>().FirstOrDefault();

                        if (component != default(ChargeableComponent) || item is CableDrillItem)
                        {
                            universe.ForAllEntitiesInRange(entity.FeetLocation(), 5, tile => {
                                if (tile.Logic is InnerCableTileEntityLogic logic)
                                {
                                    if (!showCables.Contains(logic.Location))
                                    {
                                        showCables.Add(logic.Location);
                                    }
                                }
                            });
                        }
                    }
                }

                ShowCables.Clear();
                ShowCables.AddRange(showCables);
            }
        }
Ejemplo n.º 29
0
        public void Run(Clock clock, IEmissionsState state, IDimensions dimensions)
        {
            var s = state;
            var t = clock.Current;

            if (clock.IsFirstTimestep)
            {
                // Initial values, should eventually also come from parameter file
                var t0 = Timestep.FromSimulationYear(0);

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.energint[t0, r]       = 1;
                    s.energuse[t0, r]       = s.gdp0[r];
                    s.emissint[t0, r]       = s.emissint0[r];
                    s.so2[t0, r]            = s.so20[r];
                    s.emission[t0, r]       = s.emissint[t0, r] / s.energuse[t0, r];
                    s.ch4cost[t0, r]        = 0;
                    s.n2ocost[t0, r]        = 0;
                    s.ryg[t0, r]            = 0;
                    s.reei[t0, r]           = 0;
                    s.rcei[t0, r]           = 0;
                    s.seei[t0, r]           = 0;
                    s.scei[t0, r]           = 0;
                    s.co2red[t0, r]         = 0;
                    s.know[t0, r]           = 1;
                    s.ch4red[t0, r]         = 0;
                    s.n2ored[t0, r]         = 0;
                    s.mitigationcost[t0, r] = 0;
                }

                s.globknow[t0]   = 1;
                s.cumglobco2[t0] = 0.0;
                s.cumglobch4[t0] = 0.0;
                s.cumglobn2o[t0] = 0.0;
                s.cumglobsf6[t0] = 0.0;
                s.cumglobso2[t0] = 0.0;

                //SocioEconomicState.minint[t0]=Double.PositiveInfinity;
                var minint = double.PositiveInfinity;
                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.emission[t0, r] / s.income[t0, r] < minint)
                    {
                        minint = s.emission[t0, r] / s.income[t0, r];
                    }
                }
                //s.minint[t0] = minint;
                s.minint[t0] = 0;
            }
            else
            {
                // Calculate emission and carbon intensity
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.energint[t, r] = (1.0 - 0.01 * s.aeei[t, r] - s.reei[t - 1, r]) * s.energint[t - 1, r];
                    s.emissint[t, r] = (1.0 - 0.01 * s.acei[t, r] - s.rcei[t - 1, r]) * s.emissint[t - 1, r];
                }

                // Calculate so2 emissions
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.so2[t, r] = s.so2[t - 1, r] *
                                  Math.Pow(1 + 0.01 * s.pgrowth[t - 1, r], s.so2pop) *
                                  Math.Pow(1 + 0.01 * s.ypcgrowth[t - 1, r], s.so2inc) *
                                  Math.Pow(1 - 0.01 * s.aeei[t, r] - s.reei[t - 1, r] - 0.01 * s.acei[t, r] - s.rcei[t - 1, r], s.so2carb);

                    s.so2WithSeeiAndScei[t, r] = s.so2[t, r] * (1 - s.seei[t - 1, r] - s.scei[t - 1, r]);
                }

                // Calculate sf6 emissions
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.sf6[t, r] = (s.sf60[r] + s.sf6gdp * (s.income[t, r] - s.GDP90[r]) + s.sf6ypc * (s.income[t - 1, r] / s.population[t - 1, r] - s.GDP90[r] / s.pop90[r])) * (t <= Timestep.FromSimulationYear(60) ? 1 + (t.Value - 40.0) / 40.0 : 1.0 + (60.0 - 40.0) / 40.0) * (t > Timestep.FromSimulationYear(60) ? Math.Pow(0.99, t.Value - 60.0) : 1.0);
                }
                // Check for unrealistic values
                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.sf6[t, r] < 0.0)
                    {
                        s.sf6[t, r] = 0;
                    }
                }
                // Calculate energy use
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.energuse[t, r] = (1 - s.seei[t - 1, r]) * s.energint[t, r] * s.income[t, r];
                }

                // Calculate co2 emissions
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.emission[t, r]             = (1 - s.scei[t - 1, r]) * s.emissint[t, r] * s.energuse[t, r];
                    s.emissionwithforestry[t, r] = s.emission[t, r] + s.forestemm[t, r];
                }

                // Calculate ch4 emissions
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ch4[t, r] = s.ch4em[t, r] * (1 - s.ch4red[t - 1, r]);
                }

                // Calculate n2o emissions
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.n2o[t, r] = s.n2oem[t, r] * (1 - s.n2ored[t - 1, r]);
                }


                // TODO RT check
                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.emission[t, r] / s.income[t, r] - s.minint[t - 1] <= 0)
                    {
                        s.taxpar[t, r] = s.TaxConstant;
                    }
                    else
                    {
                        s.taxpar[t, r] = s.TaxConstant - s.TaxEmInt * Math.Sqrt(s.emission[t, r] / s.income[t, r] - s.minint[t - 1]);
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.co2red[t, r] = s.currtax[t, r] * s.emission[t, r] * s.know[t - 1, r] * s.globknow[t - 1] / 2 / s.taxpar[t, r] / s.income[t, r] / 1000;

                    if (s.co2red[t, r] < 0)
                    {
                        s.co2red[t, r] = 0;
                    }
                    else if (s.co2red[t, r] > 0.99)
                    {
                        s.co2red[t, r] = 0.99;
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ryg[t, r] = s.taxpar[t, r] * Math.Pow(s.co2red[t, r], 2) / s.know[t - 1, r] / s.globknow[t - 1];
                }

                // TODO RT check
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.perm[t, r] = 1.0 - 1.0 / s.TaxThreshold * s.currtax[t, r] / (1 + 1.0 / s.TaxThreshold * s.currtax[t, r]);
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.reei[t, r] = s.perm[t, r] * 0.5 * s.co2red[t, r];
                }

                // TODO RT check
                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.currtax[t, r] < s.TaxThreshold)
                    {
                        s.rcei[t, r] = s.perm[t, r] * 0.5 * Math.Pow(s.co2red[t, r], 2);
                    }
                    else
                    {
                        s.rcei[t, r] = s.perm[t, r] * 0.5 * s.co2red[t, r];
                    }
                }

                // TODO RT check
                // TODO RT what is the 1.7?
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.seei[t, r] = (1.0 - s.TaxDepreciation) * s.seei[t - 1, r] + (1.0 - s.perm[t, r]) * 0.5 * s.co2red[t, r] * 1.7;
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.currtax[t, r] < 100)
                    {
                        s.scei[t, r] = 0.9 * s.scei[t - 1, r] + (1 - s.perm[t, r]) * 0.5 * Math.Pow(s.co2red[t, r], 2);
                    }
                    else
                    {
                        s.scei[t, r] = 0.9 * s.scei[t - 1, r] + (1 - s.perm[t, r]) * 0.5 * s.co2red[t, r] * 1.7;
                    }
                }

                // TODO RT check
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.know[t, r] = s.know[t - 1, r] * Math.Sqrt(1 + s.knowpar * s.co2red[t, r]);

                    if (s.know[t, r] > Math.Sqrt(s.MaxCostFall))
                    {
                        s.know[t, r] = Math.Sqrt(s.MaxCostFall);
                    }
                }

                s.globknow[t] = s.globknow[t - 1];
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.globknow[t] = s.globknow[t] * Math.Sqrt(1 + s.knowgpar * s.co2red[t, r]);
                }
                if (s.globknow[t] > 3.16)
                {
                    s.globknow[t] = 3.16;
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ch4red[t, r] = s.currtaxch4[t, r] * s.ch4em[t, r] / 2 / s.ch4par1[r] / s.ch4par2[r] / s.ch4par2[r] / s.income[t, r] / 1000;

                    if (s.ch4red[t, r] < 0)
                    {
                        s.ch4red[t, r] = 0;
                    }
                    else if (s.ch4red[t, r] > 0.99)
                    {
                        s.ch4red[t, r] = 0.99;
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.n2ored[t, r] = s.gwpn2o * s.currtaxn2o[t, r] * s.n2oem[t, r] / 2 / s.n2opar1[r] / s.n2opar2[r] / s.n2opar2[r] / s.income[t, r] / 1000;

                    if (s.n2ored[t, r] < 0)
                    {
                        s.n2ored[t, r] = 0;
                    }
                    else if (s.n2ored[t, r] > 0.99)
                    {
                        s.n2ored[t, r] = 0.99;
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ch4cost[t, r]         = s.ch4par1[r] * Math.Pow(s.ch4par2[r], 2) * Math.Pow(s.ch4red[t, r], 2);
                    s.ch4costindollar[t, r] = s.ch4cost[t, r] * s.income[t, r];
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.n2ocost[t, r] = s.n2opar1[r] * Math.Pow(s.n2opar2[r], 2) * Math.Pow(s.n2ored[t, r], 2);
                }

                var minint = Double.PositiveInfinity;
                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.emission[t, r] / s.income[t, r] < minint)
                    {
                        minint = s.emission[t, r] / s.income[t, r];
                    }
                }
                s.minint[t] = minint;

                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (t > Timestep.FromYear(2000))
                    {
                        s.cumaeei[t, r] = s.cumaeei[t - 1, r] * (1.0 - 0.01 * s.aeei[t, r] - s.reei[t, r] + s.seei[t - 1, r] - s.seei[t, r]);
                    }
                    else
                    {
                        s.cumaeei[t, r] = 1.0;
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.mitigationcost[t, r] = (s.taxmp[r] * s.ryg[t, r] /*+ s.ch4cost[t, r]*/ + s.n2ocost[t, r]) * s.income[t, r];
                }

                double globco2 = 0;
                double globch4 = 0;
                double globn2o = 0;
                double globsf6 = 0;
                double globso2 = 34.4;

                foreach (var r in dimensions.GetValues <Region>())
                {
                    globco2 = globco2 + s.emissionwithforestry[t, r];
                    globch4 = globch4 + s.ch4[t, r];
                    globn2o = globn2o + s.n2o[t, r];
                    globsf6 = globsf6 + s.sf6[t, r];
                    globso2 = globso2 + s.so2WithSeeiAndScei[t, r];
                }

                s.mco2[t]    = globco2;
                s.globch4[t] = Math.Max(0.0, globch4 + (t.Value > 50 ? s.ch4add * (t.Value - 50) : 0.0));
                s.globn2o[t] = Math.Max(0.0, globn2o + (t.Value > 50 ? s.n2oadd * (t.Value - 50) : 0));
                s.globsf6[t] = Math.Max(0.0, globsf6 + (t.Value > 50 ? s.sf6add * (t.Value - 50) : 0.0));
                s.globso2[t] = globso2;

                s.cumglobco2[t] = s.cumglobco2[t - 1] + s.mco2[t];
                s.cumglobch4[t] = s.cumglobch4[t - 1] + s.globch4[t];
                s.cumglobn2o[t] = s.cumglobn2o[t - 1] + s.globn2o[t];
                s.cumglobsf6[t] = s.cumglobsf6[t - 1] + s.globsf6[t];
                s.cumglobso2[t] = s.cumglobso2[t - 1] + s.globso2[t];
            }
        }
Ejemplo n.º 30
0
 public void UniverseUpdateBefore(Universe universe, Timestep step)
 {
 }
 public override void BeforeRender(DeviceContext graphics, Vector3D renderOrigin, Entity entity, AvatarController avatarController,
                                   Timestep renderTimestep)
 {
 }
 public override void ClientPostUpdate(Timestep timestep, Entity entity, AvatarController avatarController, EntityUniverseFacade facade)
 {
 }
Ejemplo n.º 33
0
        internal void DrawTop(DeviceContext graphics, ref Matrix4F matrix, Entity avatar,
                              EntityPainter avatarPainter, Universe universe, Timestep timestep, Vector2 mouseLocation)
        {
            if (_spriteBatch == null)
            {
                _spriteBatch = new SpriteBatch(graphics.Graphics.GraphicsDevice);
            }
            else if (_spriteBatch.IsDisposed)
            {
                _spriteBatch = new SpriteBatch(graphics.Graphics.GraphicsDevice);
            }

            if (_escape)
            {
                if (!graphics.IsActive())
                {
                    Dispose();
                    return;
                }
            }

            try {
                _spriteBatch.End();
            } catch {
                // ignore
            }

            _spriteBatch.Begin();

            var size = Container.GetSize();

            Vector2 origin;

            ViewPort = graphics.Graphics.GraphicsDevice.Viewport;

            switch (Alignment)
            {
            case UiAlignment.TopLeft:
                origin = new Vector2(0, 0);
                break;

            case UiAlignment.TopCenter:
                origin = new Vector2((ViewPort.Width / 2) - (size.X / 2), 0);
                break;

            case UiAlignment.TopRight:
                origin = new Vector2(ViewPort.Width - size.X, 0);
                break;

            case UiAlignment.MiddleLeft:
                origin = new Vector2(0, (ViewPort.Height / 2) - (size.Y / 2));
                break;

            case UiAlignment.MiddleCenter:
            default:
                origin = new Vector2((ViewPort.Width / 2) - (size.X / 2), (ViewPort.Height / 2) - (size.Y / 2));
                break;

            case UiAlignment.MiddleRight:
                origin = new Vector2(ViewPort.Width - size.X, (ViewPort.Height / 2) - (size.Y / 2));
                break;

            case UiAlignment.BottomLeft:
                origin = new Vector2(0, ViewPort.Height - size.Y);
                break;

            case UiAlignment.BottomCenter:
                origin = new Vector2((ViewPort.Width / 2) - (size.X / 2), ViewPort.Height - size.Y);
                break;

            case UiAlignment.BottomRight:
                origin = new Vector2(ViewPort.Width - size.X, ViewPort.Height - size.Y);
                break;
            }

            Container.Draw(graphics, avatar, universe, origin, _spriteBatch, mouseLocation, _spriteBatch.GraphicsDevice.ScissorRectangle);
            if (!_spriteBatch.IsDisposed)
            {
                _spriteBatch.End();
            }
        }
Ejemplo n.º 34
0
        public void Run(Clock clock, ISocioEconomicState state, IDimensions dimensions)
        {
            var s = state;
            var t = clock.Current;

            double savingsrate = 0.2;

            if (clock.IsFirstTimestep)
            {
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.income[t, r]        = s.gdp0[r];
                    s.population[t, r]    = s.pop0[r];
                    s.populationin1[t, r] = s.population[t, r] * 1000000.0;
                    s.ypc[t, r]           = s.income[t, r] / s.population[t, r] * 1000.0;
                    s.consumption[t, r]   = s.income[t, r] * 1000000000.0 * (1.0 - savingsrate);
                }

                s.globalpopulation[t]  = dimensions.GetValues <Region>().Select(r => s.populationin1[t, r]).Sum();
                s.globalconsumption[t] = dimensions.GetValues <Region>().Select(r => s.consumption[t, r]).Sum();

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ypc90[r] = s.gdp90[r] / s.pop90[r] * 1000;
                }
            }
            else
            {
                var totalPopulation = 0.0;
                // Calculate population
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.population[t, r] = (1 + 0.01 * s.pgrowth[t - 1, r]) * (s.population[t - 1, r] +
                                                                             (
                                                                                 (t >= Timestep.FromSimulationYear(40)) && !s.runwithoutpopulationperturbation ? (s.enter[t - 1, r] / 1000000.0) - (s.leave[t - 1, r] / 1000000.0) - (s.dead[t - 1, r] >= 0 ? s.dead[t - 1, r] / 1000000.0 : 0) : 0
                                                                             )
                                                                             );

                    if (s.population[t, r] < 0)
                    {
                        s.population[t, r] = 0.000001;
                    }
                    //raise new Exception;

                    s.populationin1[t, r] = s.population[t, r] * 1000000.0;
                    totalPopulation       = totalPopulation + s.populationin1[t, r];
                }
                s.globalpopulation[t] = totalPopulation;

                // Calculate income growth rate
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ygrowth[t, r] = (1 + 0.01 * s.pgrowth[t - 1, r]) * (1 + 0.01 * s.ypcgrowth[t - 1, r]) - 1;
                }

                // Calculate income
                foreach (var r in dimensions.GetValues <Region>())
                {
                    double oldincome = s.income[t - 1, r] - ((t >= Timestep.FromSimulationYear(40)) && !s.runwithoutdamage ? s.consleak * s.eloss[t - 1, r] / 10.0 : 0);

                    s.income[t, r] = (1 + s.ygrowth[t, r]) * oldincome - s.mitigationcost[t - 1, r];
                }

                // Check for unrealistic values
                foreach (var r in dimensions.GetValues <Region>())
                {
                    if (s.income[t, r] < 0.01 * s.population[t, r])
                    {
                        s.income[t, r] = 0.1 * s.population[t, r];
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.ypc[t, r] = s.income[t, r] / s.population[t, r] * 1000.0;
                }

                var totalConsumption = 0.0;
                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.consumption[t, r] = Math.Max(
                        s.income[t, r] * 1000000000.0 * (1.0 - savingsrate) - (s.runwithoutdamage ? 0.0 : (s.eloss[t - 1, r] + s.sloss[t - 1, r]) * 1000000000.0),
                        0.0);

                    totalConsumption = totalConsumption + s.consumption[t, r];
                }
                s.globalconsumption[t] = totalConsumption;

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.plus[t, r] = s.plus90[r] * Math.Pow(s.ypc[t, r] / s.ypc90[r], s.plusel);

                    if (s.plus[t, r] > 1)
                    {
                        s.plus[t, r] = 1.0;
                    }
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.popdens[t, r] = s.population[t, r] / s.area[t, r] * 1000000.0;
                }

                foreach (var r in dimensions.GetValues <Region>())
                {
                    s.urbpop[t, r] = (0.031 * Math.Sqrt(s.ypc[t, r]) - 0.011 * Math.Sqrt(s.popdens[t, r])) / (1.0 + 0.031 * Math.Sqrt(s.ypc[t, r]) - 0.011 * Math.Sqrt(s.popdens[t, r]))
                                     / (1 + s.urbcorr[r] / (1 + 0.001 * Math.Pow(Convert.ToDouble(t.Value) - 40.0, 2))); // (* DA: urbcorr needs to be changed to a function if this is to be made uncertain *)
                }

                s.globalincome[t] = dimensions.GetValues <Region>().Select(r => s.income[t, r]).Sum();

                s.globalypc[t] = dimensions.GetValues <Region>().Select(r => s.income[t, r] * 1000000000.0).Sum() /
                                 dimensions.GetValues <Region>().Select(r => s.populationin1[t, r]).Sum();
            }
        }
Ejemplo n.º 35
0
 public void NextTimestep()
 {
     Timestep = Timestep.NextTimestep();
 }