コード例 #1
0
ファイル: SolowModel.cs プロジェクト: jrising/Open-World-v1
        public static double[,] Run()
        {
            Stock          labor      = new SimplePopulationStock("Labor (L)", 10000, .1);
            Stock          capital    = new Stock("Capital (K)", 1000, GlobalDimensions.get("k"));
            Stock          technology = new Stock("Technology (A)", 4, GlobalDimensions.get("a"));
            RandomVariable shock      = new RandomVariable("Shock (epsilon)", .9, 1.1, Dimensionless.Instance);

            //technology.IncreasesBy(new Constant("Technological Advancement (gamma)", .1, GlobalDimensions.get("a").DividedBy(GlobalDimensions.Time).DividedBy(GlobalDimensions.get("k"))) * new PassiveDelay(capital, 0) / new PassiveDelay(labor, 0));

            TemporalVariable effectiveLabor = labor * technology;
            TemporalVariable production     = new Function("Production (Y)", x => Math.Pow(x[0], x[2]) * Math.Pow(x[1], (1 - x[2])) * x[3],
                                                           GlobalDimensions.get("k"), capital, effectiveLabor, new Constant("Preference (alpha)", .3, Dimensionless.Instance), shock);
            Constant savingsRate = new Constant("Savings Rate (s)", .1, GlobalDimensions.Time.RaisedTo(-1));

            capital.IncreasesBy(production * savingsRate
                                - (capital * (new Constant("Depreciation Rate (delta)", .1, GlobalDimensions.Time.RaisedTo(-1)))));

            TemporalVariable capitalPerEffectiveLaborer = capital / effectiveLabor;
            TemporalVariable productionPerLaborer       = production / labor;

            double[,] result = new double[100, 3];
            for (int tt = 0; tt < 100; tt++)
            {
                result[tt, 0] = capitalPerEffectiveLaborer.Evaluate(tt);
                result[tt, 1] = (1 - savingsRate.Evaluate(tt)) * productionPerLaborer.Evaluate(tt);
                result[tt, 2] = labor.Evaluate(tt);
            }

            return(result);
        }
コード例 #2
0
        public static double[,] Run()
        {
            const int    count     = 100;
            const double timescale = 1.0 / 4;

            // First get this working like SolowModel, then move into SOCSolowModel
            Stock            labor     = new SimplePopulationStock("Labor (L)", 10000, .01 * timescale);
            TemporalVariable firmLabor = labor / new Constant("Firms", count, Dimensionless.Instance);

            CircleGraph firms = new CircleGraph(count, 4);

            firmCapital = new NodeStock("Capital (K)", firms.GraphStack, new NodeConstant("initial", firms.GraphStack, NodeRandomInitial, GlobalDimensions.get("k")));

            TemporalVariable firmEffectiveLabor = firmLabor * (firms.NodeEdgeCount() + 1);
            TemporalVariable firmProduction     = new Function("Production (Y)", x => timescale * Math.Pow(count * x[0], x[2]) * Math.Pow(count * x[1], (1 - x[2])),
                                                               GlobalDimensions.get("k"), firmCapital, firmEffectiveLabor, new Constant("Preference (alpha)", .3, Dimensionless.Instance));

            Constant savingsRate = new Constant("Savings Rate (s)", .1, GlobalDimensions.Time.RaisedTo(-1));

            firms.AddAction(new StepNodeAction(.1 * timescale, AddRandomEdge));             // technological advancement
            firms.AddAction(new StepNodeAction(GrowOrDie, new PassiveDelay(firmProduction, 1), savingsRate, firmCapital, new Constant("Depreciation Rate (delta)", .1 * timescale, GlobalDimensions.Time.RaisedTo(-1))));

            //TemporalVariable capitalPerEffectiveLaborer = firms.Sum(firmCapital) / firms.Sum(firmEffectiveLabor);
            TemporalVariable capitalPerLaborer    = firms.Sum(firmCapital) / firms.Sum(firmLabor);
            TemporalVariable productionPerLaborer = firms.Sum(firmProduction) / firms.Sum(firmLabor);

            double[,] result = new double[1000, 4];
            for (int tt = 0; tt < 1000; tt++)
            {
                collapses     = 0;
                result[tt, 0] = capitalPerLaborer.Evaluate(tt);
                result[tt, 1] = (1 - savingsRate.Evaluate(tt)) * productionPerLaborer.Evaluate(tt);
                result[tt, 2] = labor.Evaluate(tt);
                result[tt, 3] = collapses;
            }

            return(result);
        }