Example #1
0
 def test_GenerateEquations_2_supply_multicountry_3(self):
     mod = Model()
     # Need to stay in the same currency zone
     can = Country(mod, 'CA', 'Canada, Eh?', currency='LOC')
     US = Country(mod, 'US', 'USA! USA!', currency='LOC')
     mar = Market(can, 'LAB', 'Market')
     bus = Sector(can, 'BUS', 'Business')
     hh = Sector(can, 'HH', 'Household')
     # Somehow, Americans are supplying labour in Canada...
     hh2 = Sector(US, 'HH2', 'Household')
     hh3 = Sector(US, 'HH3', 'Household#3')
     bus.AddVariable('DEM_LAB', 'desc', 'x')
     hh.AddVariable('SUP_LAB', 'desc 2', '')
     hh2.AddVariable('SUP_CA_LAB', 'desc 2', '')
     hh3.AddVariable('SUP_CA_LAB', 'desc 2', '')
     mod._GenerateFullSectorCodes()
     #mar.SupplyAllocation = [[(hh, 'SUP_LAB/2'), (hh3, '0.')], hh2]
     mar.AddSupplier(hh2)
     mar.AddSupplier(hh, 'SUP_LAB/2')
     mar.AddSupplier(hh3, '0.')
     mar._GenerateEquations()
     self.assertEqual('SUP_LAB/2', mar.EquationBlock['SUP_CA_HH'].RHS())
     self.assertEqual('SUP_LAB-SUP_CA_HH-SUP_US_HH3', kill_spaces(mar.EquationBlock['SUP_US_HH2'].RHS()))
     self.assertEqual('CA_LAB__SUP_CA_HH', hh.EquationBlock['SUP_LAB'].RHS())
     self.assertIn('SUP_LAB', hh.EquationBlock['F'].RHS())
     self.assertEqual('CA_LAB__SUP_US_HH2', hh2.EquationBlock['SUP_CA_LAB'].RHS())
     self.assertIn('SUP_CA_LAB', hh2.EquationBlock['F'].RHS())
     self.assertIn('SUP_CA_LAB', hh3.EquationBlock['F'].RHS())
Example #2
0
 def test_GenerateEquations_no_supply(self):
     mod = Model()
     can = Country(mod, 'Eh', 'Canada')
     mar = Market(can, 'LAB', 'Market')
     bus = Sector(can, 'BUS', 'Business')
     bus.AddVariable('DEM_LAB', 'desc', '')
     mod._GenerateFullSectorCodes()
     with self.assertRaises(ValueError):
         mar._GenerateEquations()
Example #3
0
 def test_GenerateEquations_2_supply_fail(self):
     mod = Model()
     can = Country(mod, 'Eh', 'Canada')
     mar = Market(can, 'LAB', 'Market')
     bus = Sector(can, 'BUS', 'Business')
     hh = Sector(can, 'HH', 'Household')
     hh2 = Sector(can, 'HH2', 'Household')
     bus.AddVariable('DEM_LAB', 'desc', 'x')
     hh.AddVariable('SUP_LAB', 'desc 2', '')
     hh2.AddVariable('SUP_LAB', 'desc 2', '')
     mod._GenerateFullSectorCodes()
     with self.assertRaises(LogicError):
         mar._GenerateEquations()
Example #4
0
 def test_GenerateEquations(self):
     mod = Model()
     can = Country(mod, 'Eh', 'Canada')
     mar = Market(can, 'LAB', 'Market')
     bus = Sector(can, 'BUS', 'Business')
     hh = Sector(can, 'HH', 'Household')
     bus.AddVariable('DEM_LAB', 'desc', 'x')
     hh.AddVariable('SUP_LAB', 'desc 2', '')
     mod._GenerateFullSectorCodes()
     mar._GenerateEquations()
     self.assertIn('-DEM_LAB', bus.EquationBlock['F'].RHS())
     self.assertEqual('x', bus.EquationBlock['DEM_LAB'].RHS())
     self.assertEqual('LAG_F+SUP_LAB', hh.EquationBlock['F'].RHS())
     # self.assertEqual('BUS_DEM_LAB', hh.Equations['SUP_LAB'].strip())
     self.assertEqual('SUP_LAB', mar.EquationBlock['SUP_HH'].RHS())
     self.assertEqual('LAB__SUP_HH', hh.EquationBlock['SUP_LAB'].RHS().strip())
Example #5
0
 def test_Market_fail_no_external(self):
     mod = Model()
     ca = Country(mod, 'CA', 'Canada', currency='CAD')
     us = Country(mod, 'US', 'United States', currency='USD')
     # gov_us.AddVariable('T', 'Government Taxes', '0.')
     gov_ca = Sector(ca, 'GOV', 'Gummint')
     gov_ca.AddVariable('DEM_GOOD', 'desc', '20.')
     market = Market(ca, 'GOOD', 'Market')
     supplier_ca = Sector(ca, 'BUS', 'Canada supplier')
     supplier_us = Sector(us, 'BUS', 'US Supplier')
     # Set supply so that CAD$10 is paid to each supplier.
     market.AddSupplier(supplier_ca)
     market.AddSupplier(supplier_us, '10.')
     # Set CAD = 2, so 2 USD = 1 CAD (USD is weaker.)
     with self.assertRaises(LogicError):
         mod._GenerateFullSectorCodes()
         market._GenerateEquations()
Example #6
0
 def test_GenerateEquations_insert_supply(self):
     mod = Model()
     can = Country(mod, 'Eh', 'Canada')
     mar = Market(can, 'LAB', 'Market')
     bus = Sector(can, 'BUS', 'Business')
     hh = Sector(can, 'HH', 'Household')
     hh2 = Sector(can, 'HH2', 'Household')
     bus.AddVariable('DEM_LAB', 'desc', 'x')
     hh.AddVariable('SUP_LAB_WRONG_CODE', 'desc 2', '')
     hh2.AddVariable('SUP_LAB_WRONG_CODE', 'desc 2', '')
     mod._GenerateFullSectorCodes()
     mar.AddSupplier(hh2)
     mar.AddSupplier(hh, 'SUP_LAB/2')
     # mar.SupplyAllocation = [[(hh, 'SUP_LAB/2')], hh2]
     mar._GenerateEquations()
     self.assertEqual('SUP_LAB/2', mar.EquationBlock['SUP_HH'].RHS())
     self.assertEqual('SUP_LAB-SUP_HH', kill_spaces(mar.EquationBlock['SUP_HH2'].RHS()))
     self.assertEqual('LAB__SUP_HH', hh.EquationBlock['SUP_LAB'].RHS())
     self.assertEqual('LAB__SUP_HH2', hh2.EquationBlock['SUP_LAB'].RHS())
Example #7
0
 def test_GenerateEquations_2_supply_multicountry_2(self):
     mod = Model()
     can = Country(mod, 'CA', 'Canada, Eh?')
     US = Country(mod, 'US', 'USA! USA!')
     mar = Market(can, 'LAB', 'Market')
     bus = Sector(can, 'BUS', 'Business')
     hh = Sector(can, 'HH', 'Household')
     hh2 = Sector(can, 'HH2', 'Household')
     bus.AddVariable('DEM_LAB', 'desc', 'x')
     hh.AddVariable('SUP_LAB', 'desc 2', '')
     hh2.AddVariable('SUP_LAB', 'desc 2', '')
     mod._GenerateFullSectorCodes()
     mar.AddSupplier(hh2)
     mar.AddSupplier(hh, 'SUP_LAB/2')
     #nmar.SupplyAllocation = [[(hh, 'SUP_LAB/2')], hh2]
     mar._GenerateEquations()
     self.assertEqual('SUP_LAB/2', mar.EquationBlock['SUP_CA_HH'].RHS())
     self.assertEqual('SUP_LAB-SUP_CA_HH', mar.EquationBlock['SUP_CA_HH2'].RHS())
     self.assertEqual('CA_LAB__SUP_CA_HH', hh.EquationBlock['SUP_LAB'].RHS())
     self.assertIn('SUP_LAB', hh.EquationBlock['F'].RHS())
     self.assertEqual('CA_LAB__SUP_CA_HH2', hh2.EquationBlock['SUP_LAB'].RHS())
     self.assertIn('SUP_LAB', hh2.EquationBlock['F'].RHS())