예제 #1
0
 def test_InitialEquilibrium(self):
     obj = EquationSolver()
     obj.RunEquationReduction = False
     # By forcing 't' into the variable list, no automatic creation of time variables
     obj.ParseString("""
          x=t
          z=x+1
          w=z(k-1)
          z(0) = 2.
          exogenous
          t=[10.]*20
          MaxTime=3""")
     obj.ExtractVariableList()
     obj.SetInitialConditions()
     obj.ParameterInitialSteadyStateMaxTime = 3
     copied_solver = obj.CalculateInitialSteadyState()
     self.assertEqual([
         10.,
     ], obj.TimeSeries['x'])
     self.assertEqual([
         11.,
     ], obj.TimeSeries['z'])
     self.assertEqual([
         11.,
     ], obj.TimeSeries['w'])
     self.assertEqual([2., 11., 11., 11.], copied_solver.TimeSeries['z'])
     self.assertEqual([0., 2., 11., 11.], copied_solver.TimeSeries['w'])
예제 #2
0
 def test_InitialEquilibrium_fail_bad_eqn(self):
     obj = EquationSolver()
     obj.RunEquationReduction = False
     # By forcing 't' into the variable list, no automatic creation of time variables
     obj.ParseString("""
          x=foo
          exogenous
          t=[10.]*20
          MaxTime=3""")
     obj.ExtractVariableList()
     obj.SetInitialConditions()
     Parameters.InitialEquilbriumMaxTime = 3
     obj.MaxIterations = 2
     with self.assertRaises(NameError):
         obj.CalculateInitialSteadyState()
예제 #3
0
 def test_InitialEquilibrium_no_convergence(self):
     obj = EquationSolver()
     obj.RunEquationReduction = False
     # By forcing 't' into the variable list, no automatic creation of time variables
     obj.ParseString("""
          x=t
          u = v+1
          v = u(k-1)
          exogenous
          t=[10.]*20
          MaxTime=3""")
     obj.ExtractVariableList()
     obj.SetInitialConditions()
     Parameters.InitialEquilbriumMaxTime = 3
     Parameters.InitialEquilibriumExcludedVariables = ['x']
     with self.assertRaises(NoEquilibriumError):
         obj.CalculateInitialSteadyState()