示例#1
0
def test_writes_od_matrix_to_expected_file(tmpdir):
    population = Population()

    household = Household(hid='0')
    person = Person(pid='0', home_area='Barnet', attributes={'occ': 'white'})
    person.add(Activity(1, 'home', 'Barnet', start_time=mtdt(0)))
    person.add(
        Leg(1,
            mode='car',
            start_area='Barnet',
            end_area='Southwark',
            start_time=mtdt(400),
            purp='work'))
    person.add(Activity(2, 'work', 'Southwark', start_time=mtdt(420)))
    person.add(
        Leg(2,
            'car',
            start_area='Southwark',
            end_area='Barnet',
            start_time=mtdt(1020),
            purp='work'))
    person.add(
        Activity(3,
                 'home',
                 'Barnet',
                 start_time=mtdt(1040),
                 end_time=mtdt(1439)))
    household.add(person)
    population.add(household)

    household = Household(hid='1')
    person = Person(pid='1', home_area='Ealing', attributes={'occ': 'white'})
    person.add(Activity(1, 'home', 'Ealing', start_time=mtdt(0)))
    person.add(
        Leg(1,
            mode='cycle',
            start_area='Ealing',
            end_area='Westminster,City of London',
            start_time=mtdt(500),
            purp='education'))
    person.add(
        Activity(2,
                 'education',
                 'Westminster,City of London',
                 start_time=mtdt(550)))
    person.add(
        Leg(2,
            'cycle',
            start_area='Westminster,City of London',
            end_area='Ealing',
            start_time=mtdt(700),
            purp='education'))
    person.add(
        Activity(3,
                 'home',
                 'Ealing',
                 start_time=mtdt(750),
                 end_time=mtdt(1439)))
    household.add(person)
    population.add(household)

    household = Household(hid='2')
    person = Person(pid='2', home_area='Ealing', attributes={'occ': 'white'})
    person.add(Activity(1, 'home', 'Ealing', start_time=mtdt(0)))
    person.add(
        Leg(1,
            mode='car',
            start_area='Ealing',
            end_area='Westminster,City of London',
            start_time=mtdt(450),
            purp='work'))
    person.add(
        Activity(2, 'work', 'Westminster,City of London',
                 start_time=mtdt(480)))
    person.add(
        Leg(2,
            'car',
            start_area='Westminster,City of London',
            end_area='Ealing',
            start_time=mtdt(1050),
            purp='work'))
    person.add(
        Activity(3,
                 'home',
                 'Ealing',
                 start_time=mtdt(1080),
                 end_time=mtdt(1439)))
    household.add(person)
    population.add(household)

    household = Household(hid='3')
    person = Person(pid='3', home_area='Barnet', attributes={'occ': 'blue'})
    person.add(Activity(1, 'home', 'Barnet', start_time=mtdt(0)))
    person.add(
        Leg(1,
            mode='walk',
            start_area='Barnet',
            end_area='Barnet',
            start_time=mtdt(450),
            purp='shop'))
    person.add(Activity(2, 'shop', 'Barnet', start_time=mtdt(470)))
    person.add(
        Leg(2,
            'walk',
            start_area='Barnet',
            end_area='Barnet',
            start_time=mtdt(600),
            purp='shop'))
    person.add(
        Activity(3,
                 'home',
                 'Barnet',
                 start_time=mtdt(620),
                 end_time=mtdt(1439)))
    household.add(person)
    population.add(household)

    household = Household(hid='4')
    person = Person(pid='4', home_area='Ealing', attributes={'occ': 'blue'})
    person.add(Activity(1, 'home', 'Ealing', start_time=mtdt(0)))
    person.add(
        Leg(1,
            mode='cycle',
            start_area='Ealing',
            end_area='Ealing',
            start_time=mtdt(400),
            purp='work'))
    person.add(Activity(2, 'work', 'Ealing', start_time=mtdt(420)))
    person.add(
        Leg(2,
            'cycle',
            start_area='Ealing',
            end_area='Ealing',
            start_time=mtdt(1030),
            purp='work'))
    person.add(
        Activity(3,
                 'home',
                 'Ealing',
                 start_time=mtdt(1050),
                 end_time=mtdt(1439)))
    household.add(person)
    population.add(household)

    attribute_list = ['white', 'blue', 'total']
    mode_list = ['car', 'cycle', 'walk', 'total']
    time_slice = [(400, 500), (1020, 1060)]

    write_od_matrices(population, tmpdir, leg_filter='Mode')
    for m in mode_list:
        od_matrix_file = os.path.join(tmpdir, m + "_od.csv")
        od_matrix_csv_string = open(od_matrix_file).read()
        if m == 'car':
            expected_od_matrix = \
                    'Origin,Barnet,Ealing,Southwark,"Westminster,City of London"\n' \
                    'Barnet,0,0,1,0\n' \
                    'Ealing,0,0,0,1\n' \
                    'Southwark,1,0,0,0\n' \
                    '"Westminster,City of London",0,1,0,0\n'
            assert od_matrix_csv_string == expected_od_matrix
        if m == 'cycle':
            expected_od_matrix = \
                    'Origin,Ealing,"Westminster,City of London"\n' \
                    'Ealing,2,1\n' \
                    '"Westminster,City of London",1,0\n'
            assert od_matrix_csv_string == expected_od_matrix
        if m == 'walk':
            expected_od_matrix = \
                    'Origin,Barnet\n' \
                    'Barnet,2\n'
            assert od_matrix_csv_string == expected_od_matrix
        if m == 'total':
            expected_od_matrix = \
                    'Origin,Barnet,Ealing,Southwark,"Westminster,City of London"\n' \
                    'Barnet,2,0,1,0\n' \
                    'Ealing,0,2,0,2\n' \
                    'Southwark,1,0,0,0\n' \
                    '"Westminster,City of London",0,2,0,0\n'
            assert od_matrix_csv_string == expected_od_matrix

    write_od_matrices(population, tmpdir, person_filter='occ')
    for a in attribute_list:
        od_matrix_file = os.path.join(tmpdir, a + "_od.csv")
        od_matrix_csv_string = open(od_matrix_file).read()
        if a == 'white':
            expected_od_matrix = \
                    'Origin,Barnet,Ealing,Southwark,"Westminster,City of London"\n' \
                    'Barnet,0,0,1,0\n' \
                    'Ealing,0,0,0,2\n' \
                    'Southwark,1,0,0,0\n' \
                    '"Westminster,City of London",0,2,0,0\n'
            assert od_matrix_csv_string == expected_od_matrix
        if a == 'blue':
            expected_od_matrix = \
                    'Origin,Barnet,Ealing\n' \
                    'Barnet,2,0\n' \
                    'Ealing,0,2\n'
            assert od_matrix_csv_string == expected_od_matrix
        if a == 'total':
            expected_od_matrix = \
                    'Origin,Barnet,Ealing,Southwark,"Westminster,City of London"\n' \
                    'Barnet,2,0,1,0\n' \
                    'Ealing,0,2,0,2\n' \
                    'Southwark,1,0,0,0\n' \
                    '"Westminster,City of London",0,2,0,0\n'
            assert od_matrix_csv_string == expected_od_matrix

    write_od_matrices(population,
                      tmpdir,
                      time_minutes_filter=[(400, 500), (1020, 1060)])
    for start_time, end_time in time_slice:
        file_name = str(start_time) + '_to_' + str(end_time)
        od_matrix_file = os.path.join(tmpdir, 'time_' + file_name + '_od.csv')
        od_matrix_csv_string = open(od_matrix_file).read()
        if (start_time, end_time) == (400, 500):
            expected_od_matrix = \
                    'Origin,Barnet,Ealing,Southwark,"Westminster,City of London"\n' \
                    'Barnet,1,0,1,0\n' \
                    'Ealing,0,1,0,1\n'
            assert od_matrix_csv_string == expected_od_matrix
        if (start_time, end_time) == (1020, 1060):
            expected_od_matrix = \
                    'Origin,Barnet,Ealing\n' \
                    'Ealing,0,1\n' \
                    'Southwark,1,0\n' \
                    '"Westminster,City of London",0,1\n'
            assert od_matrix_csv_string == expected_od_matrix
示例#2
0
def test_home_work_home_education_home_removal_of_education_act():

    household = Household(1)
    person = Person(1)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(0),
                 end_time=minutes_to_datetime(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(60),
            end_time=minutes_to_datetime(90)))
    person.add(
        Activity(seq=2,
                 act='work',
                 area='b',
                 start_time=minutes_to_datetime(90),
                 end_time=minutes_to_datetime(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(120),
            end_time=minutes_to_datetime(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(180),
                 end_time=minutes_to_datetime(300)))
    person.add(
        Leg(seq=3,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(300),
            end_time=minutes_to_datetime(390)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(390),
                 end_time=minutes_to_datetime(520)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(520),
            end_time=minutes_to_datetime(580)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(680),
                 end_time=minutes_to_datetime(24 * 60 - 1)))
    household.add(person)

    policy = policies.RemoveEducationActivity(1)
    policy.apply_to(household)
示例#3
0
def home_education_shop_home():

    person = Person(1)
    person.add(Activity(1, 'home', 'a'))
    person.add(Leg(1, 'car', 'a', 'b'))
    person.add(Activity(2, 'education', 'b'))
    person.add(Leg(2, 'car', 'b', 'b'))
    person.add(Activity(2, 'shop', 'b'))
    person.add(Leg(2, 'car', 'b', 'a'))
    person.add(Activity(3, 'home', 'a'))

    return person
示例#4
0
def test_person_not_home_based():
    person = Person(1)
    person.add(Activity(1, 'work', 1))
    person.add(Leg(1, 'car', start_area=1, end_area=2))
    person.add(Activity(2, 'home', 1))
    person.add(Leg(2, 'car', start_area=2, end_area=1))
    person.add(Activity(3, 'work', 1))
    assert not person.home_based
def population():

    population = Population()
    for hid in range(1, 11):
        household = HouseHold(hid)
        for pid in range(2):
            pid = f"{hid}-{pid}"
            person = Person(pid)

            person.add(Activity(1, 'home', 'a'))
            person.add(Leg(1, 'car', 'a', 'b'))
            person.add(Activity(2, 'work', 'b'))
            person.add(Leg(2, 'car', 'b', 'a'))
            person.add(Activity(3, 'home', 'a'))

            household.add(person)
        population.add(household)

    for hid in range(10, 21):
        household = HouseHold(hid)
        for pid in range(2):
            pid = f"{hid}-{pid}"
            person = Person(pid)

            person.add(Activity(1, 'home', 'a'))
            person.add(Leg(1, 'bus', 'a', 'b'))
            person.add(Activity(2, 'education', 'b'))
            person.add(Leg(2, 'bus', 'b', 'a'))
            person.add(Activity(3, 'home', 'a'))

            household.add(person)
        population.add(household)
    return population
示例#6
0
文件: fixtures.py 项目: cyechow/pam
def person_work_home_work_not_closed():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='work',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='home',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='c',
            start_time=mtdt(120),
            end_time=mtdt(180)))
    person.add(
        Activity(seq=3,
                 act='work',
                 area='c',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY))

    return person
示例#7
0
def test_person_add_activity():
    person = Person(1)
    act = Activity(1, 'home', 1)
    person.add(act)
    assert len(person.plan) == 1
示例#8
0
def test_person_add_leg_first_raise_error():
    person = Person('1')
    leg = Leg(1, 'car', start_area=1, end_area=2)
    with pytest.raises(PAMSequenceValidationError):
        person.add(leg)
示例#9
0
def Bobber():
    Bobber = Person('Bobber',
                    attributes={
                        'age': 6,
                        'job': 'education',
                        'gender': 'male',
                        'key_worker': False
                    })
    Bobber.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Bobber.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Bobber.add(
        Activity(2,
                 'education',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(16 * 60)))
    Bobber.add(
        Leg(2,
            'walk',
            'b',
            'c',
            start_time=mtdt(16 * 60),
            end_time=mtdt(16 * 60 + 30)))
    Bobber.add(
        Activity(3,
                 'home',
                 'a',
                 start_time=mtdt(16 * 60 + 30),
                 end_time=mtdt(18 * 60)))
    Bobber.add(
        Leg(3,
            'car',
            'a',
            'b',
            start_time=mtdt(18 * 60),
            end_time=mtdt(18 * 60 + 20)))
    Bobber.add(
        Activity(4,
                 'shop_1',
                 'b',
                 start_time=mtdt(18 * 60 + 20),
                 end_time=mtdt(18 * 60 + 50)))
    Bobber.add(
        Leg(4,
            'walk',
            'b',
            'b',
            start_time=mtdt(18 * 60 + 50),
            end_time=mtdt(19 * 60)))
    Bobber.add(
        Activity(5,
                 'shop_2',
                 'b',
                 start_time=mtdt(19 * 60),
                 end_time=mtdt(19 * 60 + 50)))
    Bobber.add(
        Leg(5,
            'car',
            'b',
            'a',
            start_time=mtdt(19 * 60 + 50),
            end_time=mtdt(20 * 60 + 10)))
    Bobber.add(
        Activity(6,
                 'home',
                 'a',
                 start_time=mtdt(20 * 60 + 10),
                 end_time=END_OF_DAY))
    return Bobber
示例#10
0
def test_get_hh_freq_if_None():
    hh = Household('1')
    hh.add(Person('1', freq=None))
    hh.add(Person('2', freq=2))
    assert hh.freq is None
示例#11
0
def test_get_hh_freq_mean():
    hh = Household('1')
    hh.add(Person('1', freq=1))
    hh.add(Person('2', freq=3))
    assert hh.freq == 2
示例#12
0
def test_population_get_random_person():
    population = Population()
    population.add(Household('1'))
    population['1'].add(Person('0'))
    population['1'].add(Person('1'))
    assert isinstance(population.random_person(), Person)
示例#13
0
def test_extract_person_mode_classes():
    person = Person(pid=str(1))
    person.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    person.add(
        Leg(seq=2,
            mode='bike',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    person.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(1200)))
    person.add(
        Leg(seq=2,
            mode='pt',
            start_area='B',
            end_area='A',
            start_time=mtdt(1200),
            end_time=mtdt(1220)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='A',
                 start_time=mtdt(1220),
                 end_time=mtdt(1500)))

    assert person.mode_classes == set(['bike', 'pt'])
示例#14
0
def test_writes_od_matrix_to_expected_file(tmpdir):
    population = Population()
    for hid in range(1, 11):
        household = Household(hid)
        population.add(household)

        for pid in range (2):
            person = Person(pid)
            person.add(Activity(1,'home', 'Barnet'))
            person.add(Leg(1,'car', start_area='Barnet', end_area='Southwark'))
            person.add(Activity(2,'work', 'Southwark'))
            person.add(Leg(2,'car', start_area='Southwark', end_area='Barnet'))
            person.add(Activity(3,'work', 'Barnet'))
            household.add(person)

    od_matrix_file = os.path.join(tmpdir, "od_matrix_test.csv")

    extract_od(population, od_matrix_file)

    od_matrix_csv_string = open(od_matrix_file).read()
    assert od_matrix_csv_string == 'ozone,Barnet,Southwark\nBarnet,0,20\nSouthwark,20,0\n'
示例#15
0
文件: fixtures.py 项目: cyechow/pam
def person_whshw():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='work',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='home',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='c',
            start_time=mtdt(120),
            end_time=mtdt(190)))
    person.add(
        Activity(seq=3,
                 act='shop',
                 area='c',
                 start_time=mtdt(190),
                 end_time=mtdt(220)))
    person.add(
        Leg(seq=3,
            mode='car',
            start_area='c',
            end_area='b',
            start_time=mtdt(220),
            end_time=mtdt(280)))
    person.add(
        Activity(seq=4,
                 act='home',
                 area='b',
                 start_time=mtdt(280),
                 end_time=mtdt(320)))
    person.add(
        Leg(seq=4,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(320),
            end_time=mtdt(380)))
    person.add(
        Activity(seq=5,
                 act='work',
                 area='a',
                 start_time=mtdt(380),
                 end_time=END_OF_DAY))

    return person
示例#16
0
def Betty():
    Betty = Person('Betty',
                   attributes={
                       'age': 40,
                       'job': 'work',
                       'gender': 'female',
                       'key_worker': True
                   })
    Betty.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Betty.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 5)))
    Betty.add(
        Activity(2,
                 'escort',
                 'b',
                 start_time=mtdt(8 * 60 + 5),
                 end_time=mtdt(8 * 60 + 30)))
    Betty.add(
        Leg(2,
            'pt',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Betty.add(
        Activity(3,
                 'work',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(14 * 60)))
    Betty.add(
        Leg(3,
            'pt',
            'b',
            'c',
            start_time=mtdt(14 * 60),
            end_time=mtdt(14 * 60 + 20)))
    Betty.add(
        Activity(4,
                 'leisure',
                 'c',
                 start_time=mtdt(14 * 60 + 20),
                 end_time=mtdt(16 * 60 - 20)))
    Betty.add(
        Leg(4,
            'pt',
            'c',
            'b',
            start_time=mtdt(16 * 60 - 20),
            end_time=mtdt(16 * 60)))
    Betty.add(
        Activity(5,
                 'escort',
                 'b',
                 start_time=mtdt(16 * 60),
                 end_time=mtdt(16 * 60 + 30)))
    Betty.add(
        Leg(5,
            'walk',
            'a',
            'b',
            start_time=mtdt(16 * 60 + 30),
            end_time=mtdt(17 * 60)))
    Betty.add(
        Activity(6,
                 'home',
                 'a',
                 start_time=mtdt(17 * 60),
                 end_time=mtdt(18 * 60)))
    Betty.add(
        Leg(6,
            'car',
            'a',
            'b',
            start_time=mtdt(18 * 60),
            end_time=mtdt(18 * 60 + 20)))
    Betty.add(
        Activity(7,
                 'shop_1',
                 'b',
                 start_time=mtdt(18 * 60 + 20),
                 end_time=mtdt(18 * 60 + 50)))
    Betty.add(
        Leg(7,
            'walk',
            'b',
            'b',
            start_time=mtdt(18 * 60 + 50),
            end_time=mtdt(19 * 60)))
    Betty.add(
        Activity(8,
                 'shop_2',
                 'b',
                 start_time=mtdt(19 * 60),
                 end_time=mtdt(19 * 60 + 50)))
    Betty.add(
        Leg(8,
            'car',
            'b',
            'a',
            start_time=mtdt(19 * 60 + 50),
            end_time=mtdt(20 * 60 + 10)))
    Betty.add(
        Activity(9,
                 'home',
                 'a',
                 start_time=mtdt(20 * 60 + 10),
                 end_time=END_OF_DAY))
    return Betty
示例#17
0
文件: fixtures.py 项目: cyechow/pam
def Hilda():
    Hilda = Person(2,
                   attributes={
                       'age': 45,
                       'job': 'influencer',
                       'gender': 'female'
                   })
    Hilda.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Hilda.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 5)))
    Hilda.add(
        Activity(2,
                 'escort_education',
                 'b',
                 start_time=mtdt(8 * 60 + 5),
                 end_time=mtdt(8 * 60 + 30)))
    Hilda.add(
        Leg(1,
            'pt',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Hilda.add(
        Activity(2,
                 'shop',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(14 * 60)))
    Hilda.add(
        Leg(2,
            'pt',
            'b',
            'c',
            start_time=mtdt(14 * 60),
            end_time=mtdt(14 * 60 + 20)))
    Hilda.add(
        Activity(3,
                 'leisure',
                 'c',
                 start_time=mtdt(14 * 60 + 20),
                 end_time=mtdt(16 * 60 - 20)))
    Hilda.add(
        Leg(3,
            'pt',
            'c',
            'b',
            start_time=mtdt(16 * 60 - 20),
            end_time=mtdt(16 * 60)))
    Hilda.add(
        Activity(2,
                 'escort_education',
                 'b',
                 start_time=mtdt(16 * 60),
                 end_time=mtdt(16 * 60 + 30)))
    Hilda.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(16 * 60 + 30),
            end_time=mtdt(17 * 60)))
    Hilda.add(
        Activity(5, 'home', 'a', start_time=mtdt(17 * 60),
                 end_time=END_OF_DAY))
    return Hilda
示例#18
0
文件: fixtures.py 项目: cyechow/pam
def Timmy():
    Timmy = Person(3,
                   attributes={
                       'age': 18,
                       'job': 'education',
                       'gender': 'male'
                   })
    Timmy.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(10 * 60)))
    Timmy.add(
        Leg(1,
            'bike',
            'a',
            'b',
            start_time=mtdt(10 * 60),
            end_time=mtdt(11 * 60)))
    Timmy.add(
        Activity(2,
                 'education',
                 'b',
                 start_time=mtdt(11 * 60),
                 end_time=mtdt(13 * 60)))
    Timmy.add(
        Leg(2,
            'bike',
            'b',
            'c',
            start_time=mtdt(13 * 60),
            end_time=mtdt(13 * 60 + 5)))
    Timmy.add(
        Activity(3,
                 'shop',
                 'c',
                 start_time=mtdt(13 * 60 + 5),
                 end_time=mtdt(13 * 60 + 30)))
    Timmy.add(
        Leg(3,
            'bike',
            'c',
            'b',
            start_time=mtdt(13 * 60 + 30),
            end_time=mtdt(13 * 60 + 35)))
    Timmy.add(
        Activity(4,
                 'education',
                 'b',
                 start_time=mtdt(13 * 60 + 35),
                 end_time=mtdt(15 * 60)))
    Timmy.add(
        Leg(4,
            'bike',
            'b',
            'd',
            start_time=mtdt(15 * 60),
            end_time=mtdt(15 * 60 + 10)))
    Timmy.add(
        Activity(5,
                 'leisure',
                 'd',
                 start_time=mtdt(15 * 60 + 10),
                 end_time=mtdt(18 * 60)))
    Timmy.add(
        Leg(5,
            'bike',
            'd',
            'a',
            start_time=mtdt(18 * 60),
            end_time=mtdt(18 * 60 + 20)))
    Timmy.add(
        Activity(6,
                 'home',
                 'a',
                 start_time=mtdt(18 * 60 + 20),
                 end_time=END_OF_DAY))
    return Timmy
示例#19
0
def test_person_not_closed_plan_different_areas():
    person = Person(1)
    person.add(Activity(1, 'work', 1))
    person.add(Leg(1, 'car', start_area=1, end_area=2))
    person.add(Activity(2, 'home', 1))
    person.add(Leg(2, 'car', start_area=2, end_area=3))
    person.add(Activity(3, 'work', 3))
    assert not person.closed_plan
示例#20
0
文件: fixtures.py 项目: cyechow/pam
def Bobby():
    Bobby = Person(4,
                   attributes={
                       'age': 6,
                       'job': 'education',
                       'gender': 'non-binary'
                   })
    Bobby.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Bobby.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Bobby.add(
        Activity(2,
                 'education',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(16 * 60)))
    Bobby.add(
        Leg(2,
            'walk',
            'b',
            'c',
            start_time=mtdt(16 * 60),
            end_time=mtdt(16 * 60 + 30)))
    Bobby.add(
        Activity(5,
                 'home',
                 'a',
                 start_time=mtdt(16 * 60 + 30),
                 end_time=END_OF_DAY))
    return Bobby
示例#21
0
def test_person_add_leg_first_raise_error():
    person = Person(1)
    leg = Leg(1, 'car', start_area=1, end_area=2)
    with pytest.raises(UserWarning):
        person.add(leg)
示例#22
0
文件: fixtures.py 项目: cyechow/pam
def Steve():
    Steve = Person(1, attributes={'age': 50, 'job': 'work', 'gender': 'male'})
    Steve.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(5 * 60)))
    Steve.add(
        Leg(1, 'car', 'a', 'b', start_time=mtdt(5 * 60),
            end_time=mtdt(6 * 60)))
    Steve.add(
        Activity(2,
                 'work',
                 'b',
                 start_time=mtdt(6 * 60),
                 end_time=mtdt(12 * 60)))
    Steve.add(
        Leg(2,
            'walk',
            'b',
            'c',
            start_time=mtdt(12 * 60),
            end_time=mtdt(12 * 60 + 10)))
    Steve.add(
        Activity(3,
                 'leisure',
                 'c',
                 start_time=mtdt(12 * 60 + 10),
                 end_time=mtdt(13 * 60 - 10)))
    Steve.add(
        Leg(3,
            'walk',
            'c',
            'b',
            start_time=mtdt(13 * 60 - 10),
            end_time=mtdt(13 * 60)))
    Steve.add(
        Activity(4,
                 'work',
                 'b',
                 start_time=mtdt(13 * 60),
                 end_time=mtdt(18 * 60)))
    Steve.add(
        Leg(4,
            'car',
            'b',
            'a',
            start_time=mtdt(18 * 60),
            end_time=mtdt(19 * 60)))
    Steve.add(
        Activity(5, 'home', 'a', start_time=mtdt(19 * 60),
                 end_time=END_OF_DAY))
    return Steve
示例#23
0
def test_person_closed_plan():
    person = Person(1)
    person.add(Activity(1, 'home', 1))
    person.add(Leg(1, 'car', start_area=1, end_area=2))
    person.add(Activity(2, 'work', 1))
    person.add(Leg(2, 'car', start_area=2, end_area=1))
    person.add(Activity(3, 'home', 1))
    assert person.closed_plan
示例#24
0
文件: fixtures.py 项目: cyechow/pam
def person_crop_last_act():

    person = Person('1', attributes={'old': True})
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY))

    return person
示例#25
0
def test_home_education_home_education_home_removal_of_education_act():

    household = Household(1)
    person = Person(1)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(0),
                 end_time=minutes_to_datetime(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(60),
            end_time=minutes_to_datetime(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(90),
                 end_time=minutes_to_datetime(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(120),
            end_time=minutes_to_datetime(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(180),
                 end_time=minutes_to_datetime(300)))
    person.add(
        Leg(seq=3,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(300),
            end_time=minutes_to_datetime(390)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(390),
                 end_time=minutes_to_datetime(520)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(520),
            end_time=minutes_to_datetime(580)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(680),
                 end_time=minutes_to_datetime(24 * 60 - 1)))
    household.add(person)

    policy = policies.RemoveEducationActivity(1)
    policy.apply_to(household)
    assert [p.act for p in household.people[1].activities] == ['home']
    assert household.people[1].plan[0].start_time == minutes_to_datetime(0)
    assert household.people[1].plan[0].end_time == minutes_to_datetime(24 *
                                                                       60 - 1)
示例#26
0
文件: fixtures.py 项目: cyechow/pam
def person_crop_last_leg():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(2600)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(2600),
                 end_time=mtdt(3000)))

    return person
示例#27
0
def person_home_education_home():

    person = Person(1)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(0),
                 end_time=minutes_to_datetime(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(60),
            end_time=minutes_to_datetime(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(90),
                 end_time=minutes_to_datetime(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(120),
            end_time=minutes_to_datetime(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(180),
                 end_time=minutes_to_datetime(24 * 60 - 1)))

    return person
示例#28
0
文件: fixtures.py 项目: cyechow/pam
def population_heh():
    home_loc = Point(0, 0)
    education_loc = Point(110, 110)
    attributes = {'hid': 0, 'hh_size': 3, 'inc': "high"}
    person = Person('1', attributes=attributes)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 loc=home_loc,
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 loc=education_loc,
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 loc=home_loc,
                 start_time=mtdt(180),
                 end_time=END_OF_DAY))
    person.plan.autocomplete_matsim()
    household = Household('0')
    household.add(person)
    population = Population('populus')
    population.add(household)
    return population
示例#29
0
文件: fixtures.py 项目: zhwlxl/pam
def person_heh():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY))

    return person
def test_PersonProbability_compute_probability_for_household_returns_same_level_p_for_floats(
):
    prob = modify.PersonProbability(0.5)
    assert prob.compute_probability_for_person(Person(1)) == 0.5