def test_GenerateAssetWeightings_2(self): mod = Model() us = Country(mod, 'US', 'USA') s = Sector(us, 'HH', 'Household') s.GenerateAssetWeighting([('BOND', '0.5'), ], 'MON') self.assertEqual('0.5', s.EquationBlock['WGT_BOND'].RHS()) self.assertEqual('F*WGT_BOND', kill_spaces(s.EquationBlock['DEM_BOND'].RHS())) self.assertEqual('1.0-WGT_BOND', kill_spaces(s.EquationBlock['WGT_MON'].RHS())) self.assertEqual('F*WGT_MON', kill_spaces(s.EquationBlock['DEM_MON'].RHS()))
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())
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())