Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
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
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
0
def test_person_add_leg_leg_raise_error():
    person = Person('1')
    act = Activity(1, 'home', 1)
    person.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2)
    person.add(leg)
    leg = Leg(2, 'car', start_area=2, end_area=1)
    with pytest.raises(PAMSequenceValidationError):
        person.add(leg)
Exemplo n.º 10
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
Exemplo n.º 11
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)
    ]
Exemplo n.º 12
0
def test_move_activity_with_home_default():
    plan = Plan('a')
    plan.add(Activity(1, 'home', area='a'))
    plan.add(Leg(1))
    plan.add(Activity(2, 'shop', area='b'))
    plan.add(Leg(2))
    plan.add(Activity(3, 'home', area='a'))

    plan.move_activity(2)

    assert plan[2].location == 'a'
Exemplo n.º 13
0
def test_move_activity_with_different_default():
    plan = Plan('a')
    plan.add(Activity(1, 'home', area='a'))
    plan.add(Leg(1))
    plan.add(Activity(2, 'shop', area='b'))
    plan.add(Leg(2))
    plan.add(Activity(3, 'home', area='a'))

    new_loc = Location(area='heyooo')
    plan.move_activity(2, default=new_loc)

    assert plan[2].location == new_loc
Exemplo n.º 14
0
def test_move_activity_with_home_default_updates_legs():
    plan = Plan('a')
    plan.add(Activity(1, 'home', area='a'))
    plan.add(Leg(1))
    plan.add(Activity(2, 'shop', area='b'))
    plan.add(Leg(2))
    plan.add(Activity(3, 'home', area='a'))

    plan.move_activity(2)

    assert plan[1].end_location == 'a'
    assert plan[3].start_location == 'a'
Exemplo n.º 15
0
def test_write_plans_xml_v12_assert_contents(tmp_path):
    population = Population()
    hh = Household('a')
    p = Person('a', attributes={'1':'1'})
    p.add(Activity(
        act="home",
        loc=Point((0,0)),
        start_time=datetime(1900,1,1,0,0,0),
        end_time=datetime(1900,1,1,8,0,0)
        ))
    p.add(Leg(
        mode='car',
        start_loc=Point((0,0)),
        end_loc=Point((0,1000)),
        start_time=datetime(1900,1,1,8,0,0),
        end_time=datetime(1900,1,1,9,0,0)
    ))
    p.add(Activity(
        act="work",
        loc=Point((0,1000)),
        start_time=datetime(1900,1,1,9,0,0),
        end_time=datetime(1900,1,1,18,0,0)
        ))
    p.add(Leg(
        mode='car',
        start_loc=Point((0,1000)),
        end_loc=Point((0,0)),
        start_time=datetime(1900,1,1,18,0,0),
        end_time=datetime(1900,1,1,19,0,0)
    ))
    p.add(Activity(
        act="home",
        loc=Point((0,0)),
        start_time=datetime(1900,1,1,19,0,0),
        end_time=END_OF_DAY
        ))
    hh.add(p)
    population.add(hh)
    plans_location = str(tmp_path / "test_plans.xml")
    write_matsim(
        population,
        plans_path=plans_location,
        comment="test",
        version=12,
        household_key=None
        )
    new = read_matsim(
        plans_location,
        version=12
        )
    assert new == population
    assert new['a']['a'].attributes == {'1':'1'}
    assert new['a']['a'].plan.day[1].distance == 1000
Exemplo n.º 16
0
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
Exemplo n.º 17
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
Exemplo n.º 18
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
Exemplo n.º 19
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
Exemplo n.º 20
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
Exemplo n.º 21
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
Exemplo n.º 22
0
def test_move_activity_with_different_default_updates_legs():
    plan = Plan('a')
    plan.add(Activity(1, 'home', area='a'))
    plan.add(Leg(1))
    plan.add(Activity(2, 'shop', area='b'))
    plan.add(Leg(2))
    plan.add(Activity(3, 'home', area='a'))

    new_loc = Location(area='heyooo')
    plan.move_activity(2, default=new_loc)

    assert plan[1].end_location == new_loc
    assert plan[3].start_location == new_loc
Exemplo n.º 23
0
def test_persons_not_equal_with_diff_plans():
    p1 = Person('1', attributes={1: 1})
    p1.plan.day = [
        Activity(act='a', area=1, start_time=0, end_time=1),
        Leg(mode='car', start_area=1, end_area=2, start_time=1, end_time=2),
        Activity(act='b', area=2, start_time=2, end_time=4)
    ]
    p4 = Person('4', attributes={1: 1})
    p4.plan.day = [
        Activity(act='a', area=1, start_time=0, end_time=1),
        Leg(mode='car', start_area=1, end_area=2, start_time=1, end_time=2),
        Activity(act='b', area=3, start_time=2, end_time=4)
    ]
    assert not p1 == p4
Exemplo n.º 24
0
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
Exemplo n.º 25
0
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', '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', '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(16 * 60 + 5)))
    Hilda.add(Activity(5, 'home', 'a', start_time=mtdt(16 * 60 + 5), end_time=END_OF_DAY))
    return Hilda
Exemplo n.º 26
0
def home_education_shop_education_home():

    person = Person(1)
    person.add(Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(60)))
    person.add(Leg(1, 'car', 'a', 'b', start_time=mtdt(60), end_time=mtdt(70)))
    person.add(Activity(2, 'education', 'b', start_time=mtdt(70), end_time=mtdt(100)))
    person.add(Leg(2, 'bike', 'b', 'c', start_time=mtdt(100), end_time=mtdt(120)))
    person.add(Activity(3, 'shop', 'c', start_time=mtdt(120), end_time=mtdt(180)))
    person.add(Leg(3, 'bike', 'c', 'b', start_time=mtdt(180), end_time=mtdt(200)))
    person.add(Activity(4, 'education', 'b', start_time=mtdt(200), end_time=mtdt(300)))
    person.add(Leg(4, 'car', 'b', 'a', start_time=mtdt(300), end_time=mtdt(310)))
    person.add(Activity(5, 'home', 'a', start_time=mtdt(310), end_time=END_OF_DAY))

    return person
Exemplo n.º 27
0
def test_persons_equal_with_same_plans():
    p1 = Person('1', attributes={1: 1})
    p1.plan.day = [
        Activity(act='a', area=1, start_time=0, end_time=1),
        Leg(mode='car', start_area=1, end_area=2, start_time=1, end_time=2),
        Activity(act='b', area=2, start_time=2, end_time=4)
    ]
    p2 = Person('2', attributes={1: 1})
    p2.plan.day = [
        Activity(act='a', area=1, start_time=0, end_time=1),
        Leg(mode='car', start_area=1, end_area=2, start_time=1, end_time=2),
        Activity(act='b', area=2, start_time=2, end_time=4)
    ]
    assert p1 == p2
Exemplo n.º 28
0
def test_persons_not_equal_with_plans_diff_attributes_same_plan():
    p1 = Person('1', attributes={1: 1})
    p1.plan.day = [
        Activity(act='a', area=1, start_time=0, end_time=1),
        Leg(mode='car', start_area=1, end_area=2, start_time=1, end_time=2),
        Activity(act='b', area=2, start_time=2, end_time=4)
    ]
    p3 = Person('3', attributes={1: 2})
    p3.plan.day = [
        Activity(act='a', area=1, start_time=0, end_time=1),
        Leg(mode='car', start_area=1, end_area=2, start_time=1, end_time=2),
        Activity(act='b', area=2, start_time=2, end_time=4)
    ]
    assert not p1 == p3
Exemplo n.º 29
0
def test_activity_tours_segments_home_to_other_act_nonhome_looped_plan(
        activities_and_tour):
    other_act = Activity(8, 'other', 'e')

    plan = Plan(1)
    plan.add(other_act)
    plan.add(Leg(1))
    for i in range(len(activities_and_tour['activities'])):
        plan.add(activities_and_tour['activities'][i])
        plan.add(Leg(1))
    plan.add(other_act)

    assert plan[0].act == plan[-1].act
    assert plan.activity_tours(
    ) == [[other_act]] + activities_and_tour['tours'] + [[other_act]]
Exemplo n.º 30
0
def test_person_add_leg():
    person = Person('1')
    act = Activity(1, 'home', 1)
    person.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2)
    person.add(leg)
    assert len(person.plan) == 2