예제 #1
0
def test_activity_with_different_times_not_in_list(list_of_acts):
    different_times_act = Activity(2,
                                   'act_2',
                                   'loc',
                                   start_time=mtdt(18 * 60 + 999),
                                   end_time=mtdt(19 * 60 + 999))
    assert different_times_act in list_of_acts
예제 #2
0
def test_very_similar_activity_in_list_exact(list_of_acts):
    v_similar_act = Activity(9999999,
                             'act_2',
                             'loc',
                             start_time=mtdt(18 * 60),
                             end_time=mtdt(19 * 60))
    assert v_similar_act.isin_exact(list_of_acts)
예제 #3
0
파일: spam.py 프로젝트: fredshone/spam
 def add_activity(self, end_time, leg=True):
     self.person.add(
         Activity(act=self.state,
                  start_time=mtdt(self.start_time),
                  end_time=mtdt(end_time)))
     if leg:
         self.person.add(
             Leg(mode="stumble",
                 start_time=mtdt(end_time),
                 end_time=mtdt(end_time)))
예제 #4
0
def test_reverse_iter():
    plan = Plan()
    act = Activity(1, 'home', 1, start_time=mtdt(0))
    plan.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2, start_time=mtdt(900), end_time=mtdt(930))
    plan.add(leg)
    act = Activity(2, 'work', 1, start_time=mtdt(930))
    plan.add(act)
    idxs = list(i for i, c in plan.reversed())
    assert idxs == [2,1,0]
예제 #5
0
def test_leg_duration():
    plan = Plan('a')
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    plan.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    plan.add(
        Activity(seq=2,
                 act='work',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(180)))

    plan.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(180),
                 end_time=mtdt(24 * 60 - 1)))

    plan.mode_shift(3,
                    'rail',
                    mode_speed={
                        'car': 37,
                        'bus': 10,
                        'walk': 4,
                        'cycle': 14,
                        'pt': 23,
                        'rail': 37
                    },
                    update_duration=True)

    assert [act.duration for act in plan] == [
        timedelta(seconds=3603),
        timedelta(seconds=1800),
        timedelta(seconds=1800),
        timedelta(seconds=3600),
        timedelta(seconds=75597)
    ]
예제 #6
0
def test_plan():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(180)))
    plan.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(180),
            end_time=mtdt(190)))
    plan.add(
        Activity(seq=2,
                 act='work',
                 area='b',
                 start_time=mtdt(190),
                 end_time=mtdt(200)))
    plan.add(
        Leg(seq=1,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(200),
            end_time=mtdt(390)))
    plan.add(
        Activity(seq=3,
                 act='home',
                 area='b',
                 start_time=mtdt(390),
                 end_time=END_OF_DAY))
    return plan
예제 #7
0
def act_leg_act_leg_act_bad_locations2():
    person = Person('1')
    person.plan.day = [
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(180)),
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(180),
            end_time=mtdt(190)),
        Activity(seq=2,
                 act='work',
                 area='b',
                 start_time=mtdt(190),
                 end_time=mtdt(200)),
        Leg(seq=1,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(200),
            end_time=mtdt(390)),
        Activity(seq=3,
                 act='home',
                 area='b',
                 start_time=mtdt(390),
                 end_time=END_OF_DAY)
    ]
    return person
예제 #8
0
def test_finalise():
    plan = Plan()
    act = Activity(1, 'home', 1, start_time=mtdt(0))
    plan.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2, start_time=mtdt(900), end_time=mtdt(930))
    plan.add(leg)
    act = Activity(2, 'work', 1, start_time=mtdt(930))
    plan.add(act)
    plan.finalise()
    assert plan.day[0].end_time == mtdt(900)
    assert plan.day[-1].end_time == END_OF_DAY
예제 #9
0
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(18 * 60 + 30), end_time=END_OF_DAY))
    return Bobby
예제 #10
0
def test_duration():
    plan = Plan()
    act = Activity(1, 'home', 1, start_time=mtdt(0))
    plan.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2, start_time=mtdt(900), end_time=mtdt(930))
    plan.add(leg)
    act = Activity(2, 'work', 1, start_time=mtdt(930))
    plan.add(act)
    plan.finalise()
    assert plan.day[0].duration == timedelta(minutes=900)
    assert plan.day[1].duration == timedelta(minutes=30)
    assert plan.day[-1].duration == timedelta(seconds=(24*60-930)*60)
예제 #11
0
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
예제 #12
0
def test_Activities_are_exact():
    a_1 = Activity(1,
                   'act',
                   'loc',
                   start_time=mtdt(18 * 60),
                   end_time=mtdt(19 * 60))
    a_2 = Activity(2,
                   'act',
                   'loc',
                   start_time=mtdt(18 * 60),
                   end_time=mtdt(19 * 60))

    assert a_1.is_exact(a_2)
예제 #13
0
def test_Activities_start_time_differ_and_are_not_exact():
    a_1 = Activity(1,
                   'act',
                   'loc',
                   start_time=mtdt(18 * 60),
                   end_time=mtdt(19 * 60))
    a_2 = Activity(2,
                   'act',
                   'loc',
                   start_time=mtdt(18 * 60 + 1),
                   end_time=mtdt(19 * 60))

    assert not a_1.is_exact(a_2)
예제 #14
0
def home_education_home_university_student():

    person = Person(1, attributes={'age': 18, 'job': 'education'})
    person.add(Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(60)))
    person.add(Leg(1, 'bike', 'a', 'b', start_time=mtdt(60), end_time=mtdt(2*60)))
    person.add(Activity(2, 'education', 'b', start_time=mtdt(2*60), end_time=mtdt(3*60)))
    person.add(Leg(2, 'bike', 'b', 'a', start_time=mtdt(3*60), end_time=mtdt(4*60)))
    person.add(Activity(3, 'home', 'a', start_time=mtdt(4*60), end_time=END_OF_DAY))

    return person
예제 #15
0
def act_act_sequence():
    person = Person('1')
    person.plan.day = [
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(180)),
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY)
    ]
    return person
예제 #16
0
def test_mode_shift_single_tour():
    plan = Plan('a')
    plan.add(Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(60)))
    plan.add(Leg(1, mode='car', start_time=mtdt(60), end_time=mtdt(90)))
    plan.add(Activity(2, 'shop', 'b', start_time=mtdt(90), end_time=mtdt(500)))
    plan.add(Leg(2, mode='car', start_time=mtdt(500), end_time=mtdt(400)))
    plan.add(
        Activity(3,
                 'home',
                 'a',
                 start_time=mtdt(400),
                 end_time=mtdt(24 * 60 - 1)))

    plan.mode_shift(1, 'pt')

    assert [leg.mode for leg in plan.legs] == ['pt', 'pt']
예제 #17
0
def assert_correct_activities(person, ordered_activities_list):
    assert len(person.plan) % 2 == 1
    for i in range(0, len(person.plan), 2):
        assert isinstance(person.plan.day[i], Activity)
    assert [a.act for a in person.plan.activities] == ordered_activities_list
    assert person.plan[0].start_time == mtdt(0)
    assert person.plan[len(person.plan)-1].end_time == END_OF_DAY
예제 #18
0
def assert_single_home_activity(person):
    assert len(person.plan) == 1
    assert isinstance(person.plan.day[0], Activity)
    assert person.plan.day[0].act == 'home'
    assert person.plan.day[0].location == person.home
    assert person.plan.day[0].start_time == mtdt(0)
    assert person.plan.day[0].end_time == END_OF_DAY
예제 #19
0
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
예제 #20
0
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
예제 #21
0
def person_home_education_home():

    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
예제 #22
0
def leg_leg_sequence():
    person = Person('1')
    person.plan.day = [
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(0),
            end_time=mtdt(90)),
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(0),
            end_time=mtdt(90))
    ]
    return person
예제 #23
0
def act_leg_leg_act_plan():
    person = Person('1')
    person.plan.day = [
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(180)),
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(0),
            end_time=mtdt(90)),
        Leg(seq=1,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(0),
            end_time=mtdt(90)),
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY)
    ]
    return person
예제 #24
0
def test_shared_activities_for_removal_finds_shared_activities(Betty, Bobber):
    hhld = instantiate_household_with([Betty, Bobber])
    act_1 = Activity(8,
                     'shop_2',
                     'b',
                     start_time=mtdt(19 * 60),
                     end_time=mtdt(19 * 60 + 50))
    act_2 = Activity(7,
                     'shop_1',
                     'b',
                     start_time=mtdt(18 * 60 + 20),
                     end_time=mtdt(18 * 60 + 50))

    shared_acts = modify.ReduceSharedActivity(
        ['shop_1', 'shop_2']).shared_activities_for_removal(hhld)

    assert shared_acts
    assert act_1.in_list_exact(shared_acts)
    assert act_2.in_list_exact(shared_acts)
예제 #25
0
파일: fixtures.py 프로젝트: zhwlxl/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()
    population.add(household)
    return population
예제 #26
0
def test_extract_household_mode_classes():
    household = Household(hid='1')
    for i, (act, mode) in enumerate(zip(['work', 'school'], ['car', 'pt'])):
        person = Person(pid=str(i))
        person.add(
            Activity(seq=1,
                     act='home',
                     area='A',
                     start_time=mtdt(0),
                     end_time=mtdt(600)))
        person.add(
            Leg(seq=2,
                mode=mode,
                start_area='A',
                end_area='B',
                start_time=mtdt(600),
                end_time=mtdt(620)))
        person.add(
            Activity(seq=3,
                     act=act,
                     area='B',
                     start_time=mtdt(620),
                     end_time=mtdt(1200)))
        household.add(person)

    assert household.mode_classes == set(['car', 'pt'])
예제 #27
0
def test_extract_population_mode_classes():
    population = Population()
    for hid, (_act, _mode) in enumerate(zip(['work', 'shop'], ['pt', 'walk'])):
        household = Household(hid=str(hid))
        population.add(household)
        for i, (act, mode) in enumerate(zip(['work', _act], ['car', _mode])):
            person = Person(pid=str(i))
            person.add(
                Activity(seq=1,
                         act='home',
                         area='A',
                         start_time=mtdt(0),
                         end_time=mtdt(600)))
            person.add(
                Leg(seq=2,
                    mode=mode,
                    start_area='A',
                    end_area='B',
                    start_time=mtdt(600),
                    end_time=mtdt(620)))
            person.add(
                Activity(seq=3,
                         act=act,
                         area='B',
                         start_time=mtdt(620),
                         end_time=mtdt(1200)))
            household.add(person)

    assert population.mode_classes == set(['car', 'pt', 'walk'])
예제 #28
0
def test_plan_fix():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='B',
            end_area='B',
            start_time=mtdt(610),
            end_time=mtdt(620)))
    plan.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(12000)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='B',
            end_area='A',
            start_time=mtdt(12000),
            end_time=mtdt(11000)))
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(11000),
                 end_time=END_OF_DAY))
    plan.fix()
    assert plan.length == 3
    assert plan.day[-1].end_time == END_OF_DAY
    assert plan[1].start_time == mtdt(600)
    assert plan[1].start_location.area == 'A'
예제 #29
0
def test_MoveActivityToHomeLocation_performs_mode_shift_to_walk_due_to_lack_of_driving_licence(
):
    Hilda = Person(1,
                   attributes={
                       'age': 45,
                       'job': 'influencer',
                       'gender': 'female',
                       'driving_licence': False
                   })
    Hilda.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    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(16 * 60 + 30)))
    Hilda.add(
        Leg(1,
            'pt',
            'b',
            'a',
            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))
    hhld = instantiate_household_with([Hilda])

    policy = modify.PersonPolicy(
        modify.MoveActivityTourToHomeLocation(['shop']),
        modify.PersonProbability(1))
    policy.apply_to(hhld)

    assert Hilda.plan[1].mode == 'walk'
    assert Hilda.plan[3].mode == 'walk'
예제 #30
0
def test_crop_act_past_end_of_day():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    plan.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(12000)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='B',
            end_area='A',
            start_time=mtdt(12000),
            end_time=mtdt(12020)))
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(12020),
                 end_time=mtdt(12030)))
    plan.crop()
    assert plan.length == 3
    assert plan.day[-1].end_time == END_OF_DAY