コード例 #1
0
    def run(self):

        while True:

            # add truck moving time
            if self.num_of_truck > 0:
                add_time = \
                    self.drive + self.r_dock_dist[self.machine_id] / self.con_belt_speed
                yield self.env.timeout(add_time)

            truck = yield self.last_queue.get()
            truck = truck.item

            print(f"Get a truck: {truck.truck_id} at {self.env.now}, truck_num: "
                  f"{self.num_of_truck}, machine_id: {self.machine_id}")

            for _, package_record in truck.store.iterrows():
                # request package every 3.6s
                yield self.env.timeout(self.unload_efficiency)

                package = Package(attr=package_record)
                probra_check = random.random()
                probra_customs = random.random()

                if probra_check <= 0.05:
                    package.check = True
                if probra_customs <= 0.05:
                    package.customs = True
                if probra_check or probra_customs:
                    self.tmp_queue.put(simpy.PriorityItem(self.env.now, package))
                else:
                    self.wait_queue.put(simpy.PriorityItem(self.env.now, package))

            self.num_of_truck += 1
コード例 #2
0
ファイル: priorty_store.py プロジェクト: maniaabdi/wlmod
def inspector(env, issues):
    for issue in [
            simpy.PriorityItem('P2', '#0000'),
            simpy.PriorityItem('P0', '#0001'),
            simpy.PriorityItem('P3', '#0002'),
            simpy.PriorityItem('P1', '#0003')
    ]:
        yield env.timeout(1)
        print(env.now, 'log', issue)
        yield issues.put(issue)
コード例 #3
0
def con_belt_process(env, con_belt_time, package, next_q):

    while True:
        print(f"item: {package} start move at {env.now}")
        yield env.timeout(con_belt_time)
        next_q.put(simpy.PriorityItem(priority=env.now, item=package))
        print(f"item: {package} end move at {env.now}")
        env.exit()
コード例 #4
0
def generator_pack(env, pack_queue):
    i = 0
    while True:

        pack = simpy.PriorityItem(env.now, {'id':env.now, 'name': i})
        yield pack_queue.put(pack)
        print('%d package was put at %d' % (i, env.now))
        #  print('all packages num: ', len(issues.items))
        random_time = rm.randint(3,6)
        yield env.timeout(random_time)
        i += 1
コード例 #5
0
 def check_and_customs(self, name):
     """
     :param name: a name for single process
     :return:
     des:
         package needed to be added time will be deal here
     """
     name = name
     while True:
         package = yield self.tmp_queue.get()
         package = package.item
         if package.check:
             yield self.env.timeout(1800)
         if package.customs:
             yield self.env.timeout(3600)
         self.wait_queue.put(simpy.PriorityItem(self.env.now, package))
コード例 #6
0
def truck_come_controller(trucks: simpy.PriorityStore, trucks_dict: dict):
    """
    :param env: from simpy
    :param trucks: a queue (FIFO)
    :param trucks_dict: a dict contain dataframe, {(truck_id, come_time): df1, (truck_id, come_time): df2, ...}
    :return:
    des: put truck into trucks, at 0s
    """

    for truck_key in trucks_dict.keys():
        (truck_id, come_time) = truck_key
        trucks.put(simpy.PriorityItem(
            priority=come_time,
            item=Truck(truck_id=truck_id,
                       come_time=come_time,
                       packages=trucks_dict[truck_key]))
        )
コード例 #7
0
def test_priority_store_stable_order(env):
    pstore = simpy.PriorityStore(env, 3)
    log = []

    def getter(wait):
        yield env.timeout(wait)
        _, item = yield pstore.get()
        log.append(item)

    items = [object() for _ in range(3)]

    # Unorderable items are inserted with same priority.
    env.process((pstore.put(simpy.PriorityItem(0, item)) for item in items))
    env.process(getter(1))
    env.process(getter(2))
    env.process(getter(3))
    env.run()

    # Since the priorities were the same for all items, ensure that items are
    # retrieved in insertion order.
    assert log == items
コード例 #8
0
 def put(self, pkt):
     self.store.put(simpy.PriorityItem(pkt, [self, pkt]))
コード例 #9
0
        print(f"item: {package} end move at {env.now}")
        env.exit()


def machine(env: simpy.Environment(), last_q: simpy.PriorityStore,
            next_q: simpy.PriorityStore, machine_id: str):

    while True:
        package = yield last_q.get()
        item = package.item
        yield env.timeout(PROCESS_TIME)
        env.process(con_belt_process(env, CON_BELT_TIME, item, next_q))
        print(
            f'Time at {env.now}, machine: {machine_id}, done item {machine_id}'
        )


if __name__ == '__main__':

    env = simpy.Environment()

    last_q = simpy.PriorityStore(env)
    next_q = simpy.PriorityStore(env)

    for i in range(100):
        last_q.put(simpy.PriorityItem(priority=1, item=f'item_{i}'))

    for i in range(5):
        env.process(machine(env, last_q, next_q, machine_id=f'm_{i}'))
    env.run()
コード例 #10
0
    def sorter(self):
        """
        :return:
        des:
            package send to reload, will be sort
        """
        while True:
            package = yield self.wait_queue.get()
            package = package.item
            destination = package.attr['destination_city']
            now_position = self.r_dock_unload.get(self.machine_id, None)
            package.now_position = now_position
            try:
                # fixme: The length of pipeline to next machine should not count here
                # go to reload
                if package.attr['pcs_type'] in ["NC", "irregular"]:

                    # convert destination for Domestic
                    if package.attr['destination_type'] == 'D':
                        destination = self.city_apt.get(destination)

                    next_position = choiceW(self.apt_reload, destination)
                    package.next_position = next_position

                    path_record = dict(
                        now_position=package.now_position,
                        next_position=package.next_position,
                        last_timestamp=self.env.now,)

                    package.path.append(path_record)

                    if package.attr["destination_type"] in ["I", "INF"]:
                        self.i_reload_queue[next_position].put(simpy.PriorityItem(self.env.now, package))
                        # for test log fixme
                        self.log_record.info(f"package: {package} go to {package.next_position} at time {self.env.now}")

                    elif package.attr["destination_type"] == "R":
                        self.r_reload_queue[next_position].put(simpy.PriorityItem(self.env.now, package))
                        # for test log fixme
                        self.log_record.info(f"package: {package} go to {package.next_position} at time {self.env.now}")

                    elif package.attr["destination_type"] == "D":
                        self.d_reload_queue[next_position].put(simpy.PriorityItem(self.env.now, package))
                        # for test log fixme
                        self.log_record.info(f"package: {package} go to {package.next_position} at time {self.env.now}")

                    else:
                        pass

                # go to small
                elif package.attr['pcs_type'] == "small":
                    next_position = self.r_dock_s_road.get(self.machine_id, None)
                    package.next_position = next_position

                    path_record = dict(
                        now_position=package.now_position,
                        next_position=package.next_position,
                        last_timestamp=self.env.now,)

                    package.path.append(path_record)

                    self.r_small_queue[next_position].put(simpy.PriorityItem(self.env.now, package))
                    # for test log fixme
                    self.log_record.info(f"package: {package} go to {package.next_position} at time {self.env.now}")

                # go to presort infeed
                else:
                    next_position = self.r_dock_r_presort_infeed_rule[self.machine_id]
                    package.next_position = next_position

                    path_record = dict(
                        now_position=package.now_position,
                        next_position=package.next_position,
                        last_timestamp=self.env.now,)

                    package.path.append(path_record)

                    self.r_presort_infeed_queue[next_position].put(simpy.PriorityItem(self.env.now, package))
                    # for test log fixme
                    self.log_record.info(f"package: {package} go to {package.next_position} at time {self.env.now}")

            except Exception as exc:
                self.log_error.info(f"package: {package}, error: {exc}")