当前位置: 首页>>代码示例>>Python>>正文


Python simpy.Environment方法代码示例

本文整理汇总了Python中simpy.Environment方法的典型用法代码示例。如果您正苦于以下问题:Python simpy.Environment方法的具体用法?Python simpy.Environment怎么用?Python simpy.Environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simpy的用法示例。


在下文中一共展示了simpy.Environment方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_store_sim

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def test_store_sim(benchmark):
    def producer(env, store, n):
        for i in range(n):
            yield env.timeout(1)
            yield store.put(i)

    def consumer(env, store):
        while True:
            yield store.get()
            yield env.timeout(2)

    def sim():
        env = simpy.Environment()
        store = simpy.Store(env, capacity=5)
        for _ in range(2):
            env.process(producer(env, store, 10))
        for _ in range(3):
            env.process(consumer(env, store))
        env.run()
        return next(env._eid)

    num_events = benchmark(sim)
    assert num_events == 87 
开发者ID:cristiklein,项目名称:simpy,代码行数:25,代码来源:test_benchmark.py

示例2: test_resource_sim

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def test_resource_sim(benchmark):
    def worker(env, resource):
        while True:
            with resource.request() as req:
                yield req
                yield env.timeout(1)

    def sim():
        env = simpy.Environment()
        resource = simpy.Resource(env, capacity=2)
        for _ in range(5):
            env.process(worker(env, resource))
        env.run(until=15)
        return next(env._eid)

    num_events = benchmark(sim)
    assert num_events == 94 
开发者ID:cristiklein,项目名称:simpy,代码行数:19,代码来源:test_benchmark.py

示例3: test_container_sim

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def test_container_sim(benchmark):
    def producer(env, container, full_event):
        while True:
            yield container.put(1)
            if container.level == container.capacity:
                full_event.succeed()
            yield env.timeout(1)

    def consumer(env, container):
        while True:
            yield container.get(1)
            yield env.timeout(3)

    def sim():
        env = simpy.Environment()
        container = simpy.Container(env, capacity=10)
        full_event = env.event()
        env.process(producer(env, container, full_event))
        for _ in range(2):
            env.process(consumer(env, container))
        env.run(until=full_event)
        return next(env._eid)

    num_events = benchmark(sim)
    assert num_events == 104 
开发者ID:cristiklein,项目名称:simpy,代码行数:27,代码来源:test_benchmark.py

示例4: __runGUI__

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def __runGUI__(self):
        """
        Simulation run using GUI for environment.
        """

        self.__root = tk.Tk()
        self.__root.wm_title("Environment")
        
        # Create the queue
        self.__queue = queue.Queue( )

        # Set up the GUI part
        self.__environmentGUI = GuiPart(self.__env, self.__root, self.__queue, self.__endGui__)

        # Set up the thread to do asynchronous I/O -- taken from Python cookbook
        self.__running = True
        self.__thread1 = threading.Thread(target=self.__workerThread1__)
        self.__thread1.start( )

        # Start the periodic call in the GUI to check if the queue contains
        # anything
        self.__periodicCall__( )
        self.__root.mainloop( )
        self.__running = False 
开发者ID:jakdot,项目名称:pyactr,代码行数:26,代码来源:simulation.py

示例5: __init__

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def __init__(self,
                 sim_duration: int,
                 initial_time: int,
                 config_file: str,
                 measured_latency: str,
                 measured_throughput_received: str,
                 measured_throughput_sent: str,
                 measured_delays: str):
        self._measured_delays = self._read_json_file(measured_delays)
        self._sim_duration = sim_duration
        self._initial_time = initial_time
        self._config = self._read_json_file(config_file)
        self._measured_latency = measured_latency
        self._measured_throughput_received = measured_throughput_received
        self._measured_throughput_sent = measured_throughput_sent
        # Set the SimPy Environment
        self._env = simpy.Environment(initial_time=self._initial_time)
        self._set_configs()
        self._set_delays()
        self._set_latencies()
        self._set_throughputs()
        # Set the monitor
        end_simulation = self._initial_time + self._sim_duration
        self._env.data = {
            'start_simulation_time': datetime.utcfromtimestamp(
                self._initial_time).strftime('%m-%d %H:%M:%S'),
            'end_simulation_time': datetime.utcfromtimestamp(end_simulation).strftime('%m-%d %H:%M:%S'),
            'created_transactions': 0,
            'tx_propagation': {},
            'block_propagation': {}
        } 
开发者ID:carlosfaria94,项目名称:blocksim,代码行数:33,代码来源:world.py

示例6: env

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def env():
    return simpy.Environment() 
开发者ID:cristiklein,项目名称:simpy,代码行数:4,代码来源:conftest.py

示例7: env

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def env():
    """Fixture providing simpy.Environment for tests with `env` argument."""
    return simpy.Environment() 
开发者ID:SanDisk-Open-Source,项目名称:desmod,代码行数:5,代码来源:conftest.py

示例8: __init__

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def __init__(self, machine_configs, task_configs, algorithm, event_file):
        self.env = simpy.Environment()
        cluster = Cluster()
        cluster.add_machines(machine_configs)

        task_broker = Episode.broker_cls(self.env, task_configs)

        scheduler = Scheduler(self.env, algorithm)

        self.simulation = Simulation(self.env, cluster, task_broker, scheduler, event_file) 
开发者ID:RobertLexis,项目名称:CloudSimPy,代码行数:12,代码来源:episode.py

示例9: __init__

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def __init__(self, machine_configs, task_configs, algorithm, event_file):
        self.env = simpy.Environment()
        cluster = Cluster()
        cluster.add_machines(machine_configs)

        task_broker = Broker(self.env, task_configs)

        scheduler = Scheduler(self.env, algorithm)

        self.simulation = Simulation(self.env, cluster, task_broker, scheduler, event_file) 
开发者ID:RobertLexis,项目名称:CloudSimPy,代码行数:12,代码来源:episode.py

示例10: simulate_network

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def simulate_network(seedinit, num_nodes, network, initial_inv, ROP,
                     base_stock, demand, lead_time, lead_time_delay):

    env = simpy.Environment()  # initialize SimPy simulation instance
    np.random.seed(seedinit)

    nodes = []  # list of the objects of the storage facility class

    for i in range(num_nodes):
        if i == 0:  # then it is the first supply node, which is assumed to have infinite inventory
            s = stocking_facility(env, i, 1, initial_inv[i], ROP[i], base_stock[i],
                                  None, np.zeros(100), lead_time[i], lead_time_delay)
        else:
            # first find the upstream facility before invoking the processes
            for j in range(num_nodes):
                if network[j][i] == 1: # then j serves i
                    s = stocking_facility(env, i, 0, initial_inv[i], ROP[i], base_stock[i],
                                          nodes[j], demand[:, i - 1], lead_time[i], lead_time_delay)
                    break
        
        nodes.append(s)

    env.run(until=360)

    # find the service level of each node
    for i in range(num_nodes):
        nodes[i].serviceLevel = 1 - nodes[i].totalLateSales / (nodes[i].totalDemand + 1.0e-5)

    # find the average on-hand inventory of each node
    for i in range(num_nodes):
        if i == 0: # then it is the first supply node, which is assumed to have infinite inventory
            nodes[i].avgOnHand = 0.0
        else:
            nodes[i].avgOnHand = np.mean(nodes[i].onHandMon)

    return nodes  # return the storageNode objects 
开发者ID:anshul-musing,项目名称:multi-echelon-inventory-optimization,代码行数:38,代码来源:simBackorder.py

示例11: simulate_network

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def simulate_network(seedinit, num_nodes, network, initial_inv, ROP,
                     base_stock, demand, lead_time, lead_time_delay):

    env = simpy.Environment()  # initialize SimPy simulation instance
    np.random.seed(seedinit)

    nodes = []  # list of the objects of the storage facility class

    for i in range(num_nodes):
        if i == 0:  # then it is the first supply node, which is assumed to have infinite inventory
            s = stocking_facility(env, i, 1, initial_inv[i], ROP[i], base_stock[i],
                                  None, np.zeros(100), lead_time[i], lead_time_delay)
        else:
            # first find the upstream facility before invoking the processes
            for j in range(num_nodes):
                if network[j][i] == 1: # then j serves i
                    s = stocking_facility(env, i, 0, initial_inv[i], ROP[i], base_stock[i],
                                          nodes[j], demand[:, i - 1], lead_time[i], lead_time_delay)
                    break
        
        nodes.append(s)

    env.run(until=360)

    # find the service level of each node
    for i in range(num_nodes):
        nodes[i].serviceLevel = nodes[i].totalShipped / (nodes[i].totalDemand + 1.0e-5)

    # find the average on-hand inventory of each node
    for i in range(num_nodes):
        if i == 0: # then it is the first supply node, which is assumed to have infinite inventory
            nodes[i].avgOnHand = 0.0
        else:
            nodes[i].avgOnHand = np.mean(nodes[i].onHandMon)

    return nodes  # return the storageNode objects 
开发者ID:anshul-musing,项目名称:multi-echelon-inventory-optimization,代码行数:38,代码来源:simLostSales.py

示例12: __init__

# 需要导入模块: import simpy [as 别名]
# 或者: from simpy import Environment [as 别名]
def __init__(self, environment, realtime, trace, gui, buffers, used_productions, initial_time=0, environment_process=None, **kwargs):

        self.gui = environment and gui and GUI

        self.__simulation = simpy.Environment(initial_time=round(initial_time, 4))

        self.__env = environment
        if self.__env:
            self.__env.gui = gui and GUI #set the GUI of the environment in the same way as this one; it is used so that Environment prints its output directly in simpy simulation

        self.__realtime = realtime

        if not self.gui and realtime:
            self.__simulation = simpy.RealtimeEnvironment()

        self.__trace = trace

        self.__dict_extra_proc = {key: None for key in buffers}

        self.__buffers = buffers

        self.__pr = used_productions

        self.__simulation.process(self.__procprocessGenerator__())

        self.__interruptibles = {} #interruptible processes

        self.__dict_extra_proc_activate = {}

        for each in self.__dict_extra_proc:
            if each != self.__pr._PROCEDURAL:
                self.__dict_extra_proc[each] = self.__simulation.process(self.__extraprocessGenerator__(each)) #create simulation processes for all buffers, store them in dict_extra_proc
                self.__dict_extra_proc_activate[each] = self.__simulation.event() #create simulation events for all buffers that control simulation flow (they work as locks)
        
        self.__proc_activate = self.__simulation.event() #special event (lock) for procedural module
        
        self.__procs_started = [] #list of processes that are started as a result of production rules

        #activate environment process, if environment present
        if self.__env:

            self.__proc_environment = self.__simulation.process(self.__envGenerator__(ep=environment_process, **kwargs))
            self.__environment_activate = self.__simulation.event()

        self.__last_event = None #used when stepping thru simulation

        #here below -- simulation values, accessible by user
        self.current_event = None
        self.now = self.__simulation.now 
开发者ID:jakdot,项目名称:pyactr,代码行数:51,代码来源:simulation.py


注:本文中的simpy.Environment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。