Пример #1
0
    def test_additional_logging(self):
        simulation_start = 0
        my_env = simpy.Environment(initial_time=simulation_start)
        registry = {}

        reporting_activity = model.BasicActivity(
            env=my_env,
            name="Reporting activity",
            ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5k",
            registry=registry,
            duration=0,
        )
        basic_activity = model.BasicActivity(
            env=my_env,
            name="Basic activity",
            registry=registry,
            ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5b",
            duration=14,
            additional_logs=[reporting_activity],
        )
        model.register_processes([basic_activity])
        my_env.run()

        assert my_env.now == 14
        assert_log(reporting_activity)
        assert_log(basic_activity)
def test_parallel():
    """Test the parallel activity."""
    simulation_start = 0
    env = simpy.Environment(initial_time=simulation_start)
    registry = {}

    reporting_activity = model.BasicActivity(
        env=env,
        name="Reporting activity",
        registry=registry,
        duration=0,
    )

    sub_processes = [
        model.BasicActivity(
            env=env,
            name="Basic activity1",
            registry=registry,
            duration=14,
            additional_logs=[reporting_activity],
        ),
        model.BasicActivity(
            env=env,
            name="Basic activity2",
            registry=registry,
            duration=5,
            additional_logs=[reporting_activity],
        ),
        model.BasicActivity(
            env=env,
            name="Basic activity3",
            registry=registry,
            duration=220,
            additional_logs=[reporting_activity],
        ),
    ]

    activity = model.ParallelActivity(
        env=env,
        name="Parallel process",
        registry=registry,
        sub_processes=sub_processes,
    )

    model.register_processes([activity])
    env.run()

    assert env.now == 220
    assert_log(activity)
    assert_log(reporting_activity)
def test_sequence():
    """Test the sequence activity."""

    simulation_start = 0
    my_env = simpy.Environment(initial_time=simulation_start)
    registry = {}

    reporting_activity = model.BasicActivity(
        env=my_env,
        name="Reporting activity",
        registry=registry,
        duration=0,
    )

    sub_processes = [
        model.BasicActivity(
            env=my_env,
            name="Basic activity1",
            registry=registry,
            duration=14,
            additional_logs=[reporting_activity],
        ),
        model.BasicActivity(
            env=my_env,
            name="Basic activity2",
            registry=registry,
            duration=5,
            additional_logs=[reporting_activity],
        ),
        model.BasicActivity(
            env=my_env,
            name="Basic activity3",
            registry=registry,
            duration=220,
            additional_logs=[reporting_activity],
        ),
    ]

    activity = model.SequentialActivity(
        env=my_env,
        name="Sequential process",
        registry=registry,
        sub_processes=sub_processes,
    )
    model.register_processes([activity])
    my_env.run()

    assert my_env.now == 239
    assert_log(activity)
def test_repeat_activity():
    """Test the repeat activity."""
    simulation_start = 0
    my_env = simpy.Environment(initial_time=simulation_start)
    registry = {}

    activity = model.BasicActivity(
        env=my_env,
        name="Basic activity",
        registry=registry,
        duration=14,
    )

    repeat_activity = model.RepeatActivity(
        env=my_env,
        name="repeat",
        ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5g",
        registry=registry,
        sub_processes=[activity],
        repetitions=3,
    )
    model.register_processes([repeat_activity])
    my_env.run()

    assert my_env.now == 42
    assert_log(repeat_activity)
Пример #5
0
    def test_repeat_until_timeout(self):
        simulation_start = 0
        my_env = simpy.Environment(initial_time=simulation_start)
        registry = {}

        basic = model.BasicActivity(
            env=my_env,
            name="Basic activity",
            registry=registry,
            duration=10,
        )

        act = model.WhileActivity(
            env=my_env,
            name="While activity of basic activities",
            registry=registry,
            sub_processes=[basic],
            condition_event={
                "type": "time",
                "start_time": 50,
            },
        )
        model.register_processes([act])
        my_env.run()

        assert my_env.now == 50
        assert_log(act)
        assert_log(basic)
def test_process_synchronization():
    """Test process synchronization."""
    simulation_start = 0
    my_env = simpy.Environment(initial_time=simulation_start)
    registry = {}

    reporting_activity = model.BasicActivity(
        env=my_env,
        name="Reporting activity",
        registry=registry,
        duration=0,
    )
    act1 = model.BasicActivity(
        env=my_env,
        name="Activity1",
        registry=registry,
        additional_logs=[reporting_activity],
        duration=14,
    )
    act2 = model.BasicActivity(
        env=my_env,
        name="Activity2",
        registry=registry,
        additional_logs=[reporting_activity],
        start_event=[{
            "type": "activity",
            "name": "Activity1",
            "state": "done"
        }],
        duration=30,
    )
    model.register_processes([reporting_activity, act1, act2])
    my_env.run()

    assert my_env.now == 44
    assert_log(act1)
    assert_log(act2)
    assert_log(reporting_activity)
Пример #7
0
    def test_basic_activity(self):
        simulation_start = 0
        my_env = simpy.Environment(initial_time=simulation_start)
        registry = {}

        act = model.BasicActivity(
            env=my_env,
            name="Basic activity",
            ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5b",
            registry=registry,
            duration=14,
        )
        model.register_processes([act])
        my_env.run()

        assert my_env.now == 14
Пример #8
0
    def test_start_at_timeout(self):
        simulation_start = 0
        my_env = simpy.Environment(initial_time=simulation_start)
        registry = {}

        act = model.BasicActivity(
            env=my_env,
            name="Basic activity",
            registry=registry,
            duration=14,
            start_event={
                "type": "time",
                "start_time": 10,
            },
        )
        model.register_processes([act])
        my_env.run()

        assert my_env.now == 24
        assert_log(act)
def test_complex_synchronization():
    """Test complex synchronization."""

    simulation_start = 0
    my_env = simpy.Environment(initial_time=simulation_start)
    registry = {}
    keep_resources = {}

    reporting_activity = model.BasicActivity(
        env=my_env,
        name="Reporting activity",
        ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5k",
        registry=registry,
        duration=0,
        keep_resources=keep_resources,
    )

    sub_processes = [
        model.BasicActivity(
            env=my_env,
            name="A Basic activity1",
            ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5b",
            registry=registry,
            duration=14,
            additional_logs=[reporting_activity],
            keep_resources=keep_resources,
        ),
        model.BasicActivity(
            env=my_env,
            name="A Basic activity2",
            ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5c",
            registry=registry,
            duration=10,
            additional_logs=[reporting_activity],
            keep_resources=keep_resources,
        ),
        model.BasicActivity(
            env=my_env,
            name="A Basic activity3",
            ID="6dbbbdf7-4589-11e9-bf3b-b469212bff5d",
            registry=registry,
            duration=220,
            additional_logs=[reporting_activity],
            keep_resources=keep_resources,
            start_event=[{
                "type": "activity",
                "name": "B Basic activity2",
                "state": "done"
            }],
        ),
    ]

    sub_processes2 = [
        model.BasicActivity(
            env=my_env,
            name="B Basic activity1",
            ID="5dbbbdf7-4589-11e9-bf3b-b469212bff5b",
            registry=registry,
            duration=1,
            additional_logs=[reporting_activity],
            keep_resources=keep_resources,
        ),
        model.BasicActivity(
            env=my_env,
            name="B Basic activity2",
            ID="5dbbbdf7-4589-11e9-bf3b-b469212bff5c",
            registry=registry,
            duration=500,
            additional_logs=[reporting_activity],
            keep_resources=keep_resources,
        ),
        model.BasicActivity(
            env=my_env,
            name="B Basic activity3",
            ID="5dbbbdf7-4589-11e9-bf3b-b469212bff5d",
            registry=registry,
            duration=120,
            additional_logs=[reporting_activity],
            keep_resources=keep_resources,
        ),
    ]

    B = model.SequentialActivity(
        env=my_env,
        name="B Sequential process",
        ID="5dbbbdf7-4589-11e9-bf3b-b469212bff60",
        registry=registry,
        sub_processes=sub_processes2,
        keep_resources=keep_resources,
    )

    A = model.SequentialActivity(
        env=my_env,
        name="A Sequential process",
        ID="6dbbbdf7-4589-11e9-bf3b-b469212bff60",
        registry=registry,
        sub_processes=sub_processes,
        keep_resources=keep_resources,
    )

    model.register_processes([A, B, reporting_activity])
    my_env.run()

    assert my_env.now == 721
    assert_log(reporting_activity)
    assert_log(A)
    assert_log(B)
Пример #10
0
def test_nested_cycles():
    """Test nested cycles."""

    simulation_start = 0
    my_env = simpy.Environment(initial_time=simulation_start)
    registry = {}

    Site = type(
        "Site",
        (
            core.Identifiable,
            core.Log,
            core.Locatable,
            core.HasContainer,
            core.HasResource,
        ),
        {},
    )

    TransportProcessingResource = type(
        "TransportProcessingResource",
        (
            core.Identifiable,
            core.Log,
            core.ContainerDependentMovable,
            core.Processor,
            core.HasResource,
            core.LoadingFunction,
            core.UnloadingFunction,
        ),
        {},
    )
    location_from_site = shapely.geometry.Point(4.18055556, 52.18664444)
    location_to_site = shapely.geometry.Point(4.25222222, 52.11428333)

    from_site = Site(
        env=my_env,
        name="Winlocatie",
        ID="6dbbbdf4-4589-11e9-a501-b469212bff5d",
        geometry=location_from_site,
        capacity=100,
        level=50,
    )

    to_site = Site(
        env=my_env,
        name="Dumplocatie",
        ID="6dbbbdf5-4589-11e9-82b2-b469212bff5c",
        geometry=location_to_site,
        capacity=50,
        level=0,
    )

    hopper = TransportProcessingResource(
        env=my_env,
        name="Hopper 01",
        ID="6dbbbdf6-4589-11e9-95a2-b469212bff5b",
        geometry=location_from_site,
        loading_rate=0.00001,
        unloading_rate=0.00001,
        capacity=5,
        compute_v=lambda x: 10,
    )

    loading_subcycle_processes = [
        model.BasicActivity(
            env=my_env,
            name="loading activity 1",
            registry=registry,
            duration=100,
            additional_logs=[hopper],
        ),
        model.ShiftAmountActivity(
            env=my_env,
            name="Transfer MP",
            registry=registry,
            processor=hopper,
            origin=from_site,
            destination=hopper,
            amount=1,
            duration=1000,
        ),
        model.BasicActivity(
            env=my_env,
            name="loading activity 2",
            registry=registry,
            duration=100,
            additional_logs=[hopper],
        ),
    ]

    loading_subcycle_process = model.RepeatActivity(
        env=my_env,
        name="while_loading_subcycle",
        registry=registry,
        sub_processes=[
            model.SequentialActivity(
                env=my_env,
                name="Loading subcycle",
                registry=registry,
                sub_processes=loading_subcycle_processes,
            )
        ],
        repetitions=5,
    )

    unloading_subcycle_processes = [
        model.BasicActivity(
            env=my_env,
            name="unloading activity 1",
            registry=registry,
            duration=100,
            additional_logs=[hopper],
        ),
        model.ShiftAmountActivity(
            env=my_env,
            name="Transfer TP",
            registry=registry,
            processor=hopper,
            origin=hopper,
            destination=to_site,
            amount=1,
            duration=1000,
        ),
        model.BasicActivity(
            env=my_env,
            name="unloading activity 2",
            registry=registry,
            duration=100,
            additional_logs=[hopper],
        ),
    ]

    unloading_subcycle_process = model.RepeatActivity(
        env=my_env,
        name="while_unloading_subcycle",
        registry=registry,
        sub_processes=[
            model.SequentialActivity(
                env=my_env,
                name="unloading subcycle",
                registry=registry,
                sub_processes=unloading_subcycle_processes,
            )
        ],
        repetitions=5,
    )

    single_run = [
        model.BasicActivity(
            env=my_env,
            name="Basic activity 3",
            registry=registry,
            duration=100,
            additional_logs=[hopper],
        ),
        model.MoveActivity(
            env=my_env,
            name="sailing empty",
            registry=registry,
            mover=hopper,
            destination=from_site,
            duration=500,
        ),
        loading_subcycle_process,
        model.MoveActivity(
            env=my_env,
            name="sailing filled",
            registry=registry,
            mover=hopper,
            duration=500,
            destination=to_site,
        ),
        unloading_subcycle_process,
        model.BasicActivity(
            env=my_env,
            name="Basic activity",
            registry=registry,
            duration=100,
            additional_logs=[hopper],
        ),
    ]

    activity = model.SequentialActivity(
        env=my_env,
        name="Single run process",
        registry=registry,
        sub_processes=single_run,
    )

    while_activity = model.WhileActivity(
        env=my_env,
        name="while",
        registry=registry,
        sub_processes=[activity],
        condition_event=[{
            "type": "container",
            "concept": to_site,
            "state": "full"
        }],
    )

    model.register_processes([while_activity])
    my_env.run()

    assert my_env.now == 132000
    assert_log(while_activity)