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


Python Simulation.activate方法代码示例

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


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

示例1: testBackPressureLoopTwoServers

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
 def testBackPressureLoopTwoServers(self):
     Simulation.initialize()
     s1 = server.Server(1,
                        resourceCapacity=1,
                        serviceTime=4,
                        serviceTimeModel="constant")
     s2 = server.Server(2,
                        resourceCapacity=1,
                        serviceTime=4,
                        serviceTimeModel="constant")
     c1 = client.Client(id_="Client1",
                        serverList=[s1, s2],
                        replicaSelectionStrategy="primary",
                        accessPattern="uniform",
                        replicationFactor=2,
                        backpressure=True,
                        shadowReadRatio=0.0,
                        rateInterval=20,
                        cubicC=0.000004,
                        cubicSmax=10,
                        cubicBeta=0.2,
                        hysterisisFactor=2,
                        demandWeight=1.0)
     observer = Observer([s1, s2], c1)
     Simulation.activate(observer,
                         observer.testBackPressureLoopTwoServers(),
                         at=0.1)
     Simulation.simulate(until=100)
开发者ID:jean-li,项目名称:kwiken,代码行数:30,代码来源:backpressure_test.py

示例2: sendRequest

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
    def sendRequest(self, task, replicaToServe):
        delay = constants.NW_LATENCY_BASE + \
            random.normalvariate(constants.NW_LATENCY_MU,
                                 constants.NW_LATENCY_SIGMA)

        # Immediately send out request
        messageDeliveryProcess = DeliverMessageWithDelay()
        Simulation.activate(messageDeliveryProcess,
                            messageDeliveryProcess.run(task,
                                                       delay,
                                                       replicaToServe),
                            at=Simulation.now())

        responseHandler = ResponseHandler()
        Simulation.activate(responseHandler,
                            responseHandler.run(self, task, replicaToServe),
                            at=Simulation.now())

        # Book-keeping for metrics
        self.pendingRequestsMap[replicaToServe] += 1
        self.pendingXserviceMap[replicaToServe] = \
            (1 + self.pendingRequestsMap[replicaToServe]) \
            * replicaToServe.serviceTime
        self.pendingRequestsMonitor.observe(
            "%s %s" % (replicaToServe.id,
                       self.pendingRequestsMap[replicaToServe]))
        self.taskSentTimeTracker[task] = Simulation.now()
开发者ID:jean-li,项目名称:kwiken,代码行数:29,代码来源:client.py

示例3: generate

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
 def generate(self, number, 
              interval, 
              resources, 
              monitors, 
              times,  
              exitResource, 
              exitMonitor,
              entryResource,
              entryMonitor,
              preScreenedPercentage):
     """
         @param number: number of entitites to generate (integer)
         @param interval: mean (in minutes) of times inter arrival
         @param resources: array of resources (servers)
         @param monitors:   array of monitors to collect statistics
         @param times: avg. service time depending on the resource
     """
     for i in range(number):
         customerName = "customer%d"%i
         c = Customer.Customer(name=customerName,
                               resources=resources,
                               monitors=monitors,
                               times=times,
                               exitResource=exitResource,
                               exitMonitor=exitMonitor,
                               entryResource=entryResource,
                               entryMonitor=entryMonitor,
                               preScreenedPercentage=preScreenedPercentage
                               )
         
         simpy.activate(c,c.visit())
         
         t = random.expovariate(1.0/interval)
         yield simpy.hold, self, t
开发者ID:ivihernandez,项目名称:staff-allocation,代码行数:36,代码来源:Source.py

示例4: receive

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
    def receive(self, source, pre_spike_time):
        #print(simpy.now(), ":", str(self), "at", self.membrane_potential, "receive", self.dendrites[source])

        #increse membrane potential
        membrane_potential_increment = self.dendrites[source]
        #self.membrane_potential += membrane_potential_increment
        
        #insert the source into the left window
        left_window_item = [source, pre_spike_time, simpy.now()]
        self.left_window.append(left_window_item)

        #check to weaken the dendrite by each action in the right window
        for post_spike_time in self.right_window:
            self.adjust_weight(source, pre_spike_time - post_spike_time)

        #check if it can fire
        if self.membrane_potential >= self.threshold:
            if simpy.now() > self.last_firing_time:
                self.last_firing_time = simpy.now()
                event = Event(name = str(self) + " fire")
                simpy.activate(event, event.fire(self), delay = 0.0)

        #remove the source from the left window when it's over, and decrease the membrane potential
        event = Event(name = str(self) + "remove an item from left window")
        simpy.activate(event, event.remove_from_left_window(self, left_window_item, membrane_potential_increment), 
                delay = self.left_window_width)
开发者ID:sensong,项目名称:Jupiter.Himalia,代码行数:28,代码来源:LIF_STDP_Neuron.py

示例5: update

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
 def update(self, now):
     #print(self.membrane_potential)
     if self.type == 'current':
         self.value_record.append(self.value)
         self.value *= self.output_current_decay
     if self.refact == 'yes':
         self.spikes_record.append(self.membrane_potential)
         return
     self.membrane_potential -= (self.membrane_potential - self.reset_potential)*0.1  #leak
     input = 0.0
     for source in self.dendrites.keys():
         if source.type == 'current':
             input += source.value
         elif source.type == 'voltage':
             pass # Voltage type input, add code here
     self.membrane_potential += input * 0.1
     if self.membrane_potential < self.reset_potential:
         self.membrane_potential = self.reset_potential
     record = self.membrane_potential
     if self.membrane_potential >= self.threshold:
         if simpy.now() > self.last_firing_time:
             self.last_firing_time = simpy.now()
             event = Event(name = str(self) + " fire")
             simpy.activate(event, event.fire(self), delay = 0.0)
             record = self.spike_potential
     self.spikes_record.append(record)
开发者ID:sensong,项目名称:Jupiter.Himalia,代码行数:28,代码来源:LIF_STDP_Neuron.py

示例6: schedule_arrival

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
    def schedule_arrival(self, transducer, params, pos):
        """

        :param transducer:
        :param params:
        :param pos:
        """
        distance_to = distance(pos, params["pos"]())

        if distance_to > 0.01:  # I should not receive my own transmissions
            receive_power = params["power"] - \
                            attenuation_db(params["frequency"], distance_to)
            # Speed of sound in water = 1482.0 m/s
            travel_time = distance_to / transducer.physical_layer.medium_speed

            packet = params['packet']
            if DEBUG:
                transducer.logger.debug("{type} from {source} to {dest} will take {t} to get to me {d}m away".format(
                    type=packet['type'], source=packet['source'],
                    dest=packet['dest'], t=travel_time, d=int(distance_to))
                )

            yield Sim.hold, self, travel_time

            new_incoming_packet = IncomingPacket(
                db2linear(receive_power), params["packet"], transducer.physical_layer)
            Sim.activate(
                new_incoming_packet, new_incoming_packet.receive(params["duration"]))
开发者ID:andrewbolster,项目名称:aietes,代码行数:30,代码来源:PhysicalLayer.py

示例7: __init__

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
    def __init__(self, physical_layer, ambient_noise, channel_event, position_query, sir_thresh, on_success,
                 name="a_transducer"):
        # A resource with large capacity, because we don't want incoming messages to queue,
        # We want them to interfere.

        Sim.Resource.__init__(self, name=name, capacity=1000)

        self.physical_layer = physical_layer
        self.logger = physical_layer.logger.getChild(
            "{0}".format(self.__class__.__name__))

        # Interference is initialized as ambient noise
        self.interference = ambient_noise

        # Setup our event listener
        self.channel_event = channel_event
        self.listener = AcousticEventListener(self)
        Sim.activate(self.listener, self.listener.listen(
            self.channel_event, position_query))

        # Function to call when we've received a packet
        self.on_success = on_success

        # SIR threshold
        self.SIR_thresh = sir_thresh

        # Controls the half-duplex behavior
        self.transmitting = False

        # Takes statistics about the collisions
        self.collision = False
        self.collisions = []
开发者ID:andrewbolster,项目名称:aietes,代码行数:34,代码来源:PhysicalLayer.py

示例8: transmit_packet

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
    def transmit_packet(self, packet):

        if not self.is_idle():
            # The MAC protocol is the one that should check this before
            # transmitting
            self.logger.warn(
                "I should not do this... the channel is not idle!"
                "Trying to send {typ} to {dest}"
                "Currently have {q}".format(
                    typ=packet['type'],
                    dest=packet['dest'],
                    q=self.transducer.activeQ
                ))

        if self.variable_power:
            tx_range = self.level2distance[str(packet["level"])]
            power = distance2intensity(
                self.bandwidth, self.freq, tx_range, self.SNR_threshold)
        else:
            power = self.transmit_power

        if power > self.max_output_power_used:
            self.max_output_power_used = power

        if power > self.max_output_power:
            power = self.max_output_power

        new_transmission = OutgoingPacket(self)
        Sim.activate(
            new_transmission, new_transmission.transmit(packet, power))
开发者ID:andrewbolster,项目名称:aietes,代码行数:32,代码来源:PhysicalLayer.py

示例9: test_accumulate_in_time

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
def test_accumulate_in_time():
    """Tests accumulation over simulation time"""
    s=Simulation()
    s.initialize()
    m3 = Monitor(name = 'third',sim=s)
    T3 = Thing(name = 'Job', M = m3,sim=s)
    assert m3.startTime == 0, 'Accumulate startTime wrong'
    s.activate(T3, T3.execute(),0.0)
    s.simulate(until = 30.0)
    assert m3.startTime == 0, 'Accumulate startTime wrong'
开发者ID:prajeshbhat,项目名称:simulacao-trabalho,代码行数:12,代码来源:test_monitor.py

示例10: test_observe_no_time

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
def test_observe_no_time():
    """Observe with time being picked up from now()"""
    s = Simulation()
    s.initialize()
    m = Monitor(name = 'No time',sim=s)
    t = Thing(m,sim=s)
    s.activate(t, t.execute(),0.0)
    s.simulate(until = 20.0)
    assert m.yseries() == [0, 10, 5],'yseries wrong:%s' % (m.yseries(),)
    assert m.tseries() == [0, 10, 20],'tseries wrong:%s' % (m.tseries(),)
    assert m.total() == 15, 'total wrong:%s'%m.total()
    assert m.timeAverage(10.0) == 5.0, 'time average is wrong: %s'%m.timeAverage(10.0)
开发者ID:prajeshbhat,项目名称:simulacao-trabalho,代码行数:14,代码来源:test_monitor.py

示例11: listen

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
    def listen(self, channel_event, position_query):
        """

        :param channel_event:
        :param position_query:
        """
        while True:
            yield Sim.waitevent, self, channel_event
            params = channel_event.signalparam
            sched = ArrivalScheduler(name="ArrivalScheduler" + self.name[-1])
            Sim.activate(sched, sched.schedule_arrival(
                self.transducer, params, position_query()))
开发者ID:andrewbolster,项目名称:aietes,代码行数:14,代码来源:PhysicalLayer.py

示例12: new_agent

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
	def new_agent(self):
		x = gauss(self.mean_x, self.sd_x)
		y = gauss(self.mean_y, self.sd_y)
		speak = expovariate(1.0/self.mean_speak)
		learn = expovariate(1.0/self.mean_learn)
		innovation = expovariate(1.0/self.mean_innovation)
		
		agent = Agent(x, y, speak, learn, innovate)
		self.agents.append(agent)
		
		Sim.activate(agent, agent.go())
		return agent
开发者ID:adambaker,项目名称:language-evolution-modeling,代码行数:14,代码来源:Population.py

示例13: test_put_store

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
def test_put_store():
    """Test of "yield put,self,store" """
    s = Simulation()
    s.initialize()
    store = Store( ) # wrong sim
    r = PutStoretest(sim=s)
    s.activate(r,r.run(store = store))
    try:
        s.simulate(until=1)
    except FatalSimerror:
        pass
    else:
        assert False, "expected FatalSimerror"
开发者ID:MaximeCheramy,项目名称:simso-web,代码行数:15,代码来源:test_simident.py

示例14: test_request

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
def test_request():
    """Test of "yield request,self,res" """
    s = Simulation()
    s.initialize()
    res = Resource( ) # wrong sim
    r = Requesttest(sim=s)
    s.activate(r,r.run(res = res))
    try:
        s.simulate(until=1)
    except FatalSimerror:
        pass
    else:
        assert False, "expected FatalSimerror"
开发者ID:MaximeCheramy,项目名称:simso-web,代码行数:15,代码来源:test_simident.py

示例15: test_get_level

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import activate [as 别名]
def test_get_level():
    """Test of "yield get,self,level" """
    s = Simulation()
    s.initialize()
    levl = Level( ) # wrong sim
    r = GetLeveltest(sim=s)
    s.activate(r,r.run(level = levl))
    try:
        s.simulate(until=1)
    except FatalSimerror:
        pass
    else:
        assert False, "expected FatalSimerror"
开发者ID:MaximeCheramy,项目名称:simso-web,代码行数:15,代码来源:test_simident.py


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