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


Python Simulation.now方法代码示例

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


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

示例1: receive

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [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

示例2: sendRequest

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [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: update

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [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

示例4: visit_greeter

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
 def visit_greeter(self):       
     name = 'greeter'
     if self.debug:
         print self.name, "at ",name, simpy.now()
     
     arrive = simpy.now()
     yield simpy.request, self, self.resources[name]
     wait = simpy.now() - arrive
     self.monitors[name].observe(wait)
     GREETER_ENABLED = True
     if GREETER_ENABLED:
         time = random.triangular(low=5/60.0, high=92/60.0, mode=23/60.0)
         #time = random.triangular(low=1.77/60.0, high=2.66/60.0, mode=2.38/60.0)
         tib = self.numberOfForms * time
     else:
         tib = 0
     yield simpy.hold,self,tib
     yield simpy.release, self, self.resources[name]
     p = random.random()
     if self.preScreened:
         for i in self.visit_dispenser():
             yield i
     else:
         for i in self.visit_screener():
             yield i
开发者ID:ivihernandez,项目名称:staff-allocation,代码行数:27,代码来源:Customer.py

示例5: __init__

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
	def __init__(self, lang_x, lang_y, speak_rate, learn_rate, innovation):
		'''Initializes the agent. The variables used are:
				lang_x: the x parameter for this agent's language
				lang_y: the y parameter for this agent's language
				speak_rate: the rate at which this agent initiates conversation.
					time between conversation events is random.expovariate(speak_rate)
					speak_rate is floored at 0.001.
				learn_rate: the amount the speaker changes his language when he hears
					another speaker. Changes his language by 
					learn_rate*(self.lang - other.lang)
				innovation: The rate at which this speaker randomly changes his language.
					time between innovation events is random.expovaraiate(innovation).
				next_conversation: the simulation time for the next conversation initiated
					by this agent.
				next_innovation: the simulation time for the next innovation introduced by
					this agent.'''
		Sim.Process.__init__(self)
		self.lang_x = lang_x
		self.lang_y = lang_y
		if speak_rate < 0.001:
			speak_rate = 0.001
		self.speak_rate = speak_rate
		self.learn_rate = learn_rate
		self.innovation = innovation
		self.next_conversation = Sim.now() + expovariate(speak_rate)
		self.next_innovation = Sim.now() + expovariate(innovation)
		
		Agent.all_agents.append(self);
开发者ID:adambaker,项目名称:language-evolution-modeling,代码行数:30,代码来源:Agent.py

示例6: visit_medic

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
 def visit_medic(self):
     """
         Lognormal with :
         logarithmic mean: 1.024
         logarithmic std dev: 0.788
     """       
     name = 'medic'
     if self.debug:
         print self.name, "at ",name, simpy.now()
     
     arrive = simpy.now()
     yield simpy.request, self, self.resources[name]
     wait = simpy.now() - arrive
     self.monitors[name].observe(wait)
     time = random.lognormvariate(mu=1.024, sigma=0.788) 
     tib = self.numberOfForms * time 
     yield simpy.hold,self,tib
     yield simpy.release, self, self.resources[name]
 
     p = random.random()
     if p < 0.99:
         for i in self.visit_dispenser():
             yield i
     else:
         for i in self.visit_exit():
             yield i
开发者ID:ivihernandez,项目名称:staff-allocation,代码行数:28,代码来源:Customer.py

示例7: operate

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
 def operate(self, repairduration, triplength): 
     """Travel until the trip is finished.
     
     The bus may break down down several times during the trip.
     
     Parameters:
     repairduration -- time to recover from a breakdown and continue
     triplength     -- duration of the trip
      
     """
     tripleft = triplength
     # "tripleft"is the driving time to finish trip
     # if there are no further breakdowns
     while tripleft > 0:
         yield sim.hold, self, tripleft # try to finish the trip
         # if a breakdown intervenes
         if self.interrupted():
             print self.interruptCause.name, 'at %s' % sim.now()
             tripleft = self.interruptLeft
             # update driving time to finish
             # the trip if no more breakdowns
             self.interruptReset() 
             # end self interrupted state
             #update next breakdown time
             sim.reactivate(br, delay=repairduration)
             #impose delay for repairs on self
             yield sim.hold, self, repairduration
             print 'Bus repaired at %s' % sim.now()
         else: # no breakdowns intervened, so bus finished trip
             break
     print 'Bus has arrived at %s' % sim.now()
开发者ID:buguen,项目名称:wsnpy,代码行数:33,代码来源:sim_bus.py

示例8: test_run_simulation_no_event

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
def test_run_simulation_no_event():
    run_simulation()
    assert sim.now() == 0
    assert pynnn.get_current_time() == 0.0
    assert sim.Globals.allEventTimes() == []
    run_simulation(end_time=50)
    assert sim.now() == 50
    assert pynnn.get_current_time() == 50.0
    assert sim.Globals.allEventTimes() == []
开发者ID:agravier,项目名称:pycogmo,代码行数:11,代码来源:pynn_scheduling_tests.py

示例9: maybeSendShadowReads

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
 def maybeSendShadowReads(self, replicaToServe, replicaSet):
     if (random.uniform(0, 1.0) < self.shadowReadRatio):
         for replica in replicaSet:
             if (replica is not replicaToServe):
                 shadowReadTask = task.Task("ShadowRead", None)
                 self.taskArrivalTimeTracker[shadowReadTask] =\
                     Simulation.now()
                 self.taskSentTimeTracker[shadowReadTask] = Simulation.now()
                 self.sendRequest(shadowReadTask, replica)
                 self.rateLimiters[replica].forceUpdates()
开发者ID:jean-li,项目名称:kwiken,代码行数:12,代码来源:client.py

示例10: visit_exit

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
 def visit_exit(self):       
     name = 'exit'
     if self.debug:
         print self.name, "at ",name, simpy.now()
     
     arrive = simpy.now()
     yield simpy.request, self, self.exitResource
     wait = simpy.now() - arrive
     self.exitMonitor.observe(wait)
     tib = 0#random.expovariate(1.0/self.times[name])   
     yield simpy.hold,self,tib
     yield simpy.release, self, self.exitResource
开发者ID:ivihernandez,项目名称:staff-allocation,代码行数:14,代码来源:Customer.py

示例11: visit_entry

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
 def visit_entry(self):       
     name = 'entry'
     if self.debug:
         print self.name, "at ",name, simpy.now()
     
     arrive = simpy.now()
     yield simpy.request, self, self.entryResource
     wait = simpy.now() - arrive
     self.entryMonitor.observe(wait)
     tib = 0   
     yield simpy.hold,self,tib
     yield simpy.release, self, self.entryResource
开发者ID:ivihernandez,项目名称:staff-allocation,代码行数:14,代码来源:Customer.py

示例12: updateRates

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
    def updateRates(self, replica, metricMap, task):
        # Cubic Parameters go here
        # beta = 0.2
        # C = 0.000004
        # Smax = 10
        beta = self.cubicBeta
        C = self.cubicC
        Smax = self.cubicSmax
        hysterisisFactor = self.hysterisisFactor
        currentSendingRate = self.rateLimiters[replica].rate
        currentReceiveRate = self.receiveRate[replica].getRate()

        if (currentSendingRate < currentReceiveRate):
            # This means that we need to bump up our own rate.
            # For this, increase the rate according to a cubic
            # window. Rmax is the sending-rate at which we last
            # observed a congestion event. We grow aggressively
            # towards this point, and then slow down, stabilise,
            # and then advance further up. Every rate
            # increase is capped by Smax.
            T = Simulation.now() - self.lastRateDecrease[replica]
            self.lastRateIncrease[replica] = Simulation.now()
            Rmax = self.valueOfLastDecrease[replica]

            newSendingRate = C * (T - (Rmax * beta/C)**(1.0/3.0))**3 + Rmax

            if (newSendingRate - currentSendingRate > Smax):
                self.rateLimiters[replica].rate += Smax
            else:
                self.rateLimiters[replica].rate = newSendingRate
        elif (currentSendingRate > currentReceiveRate
              and Simulation.now() - self.lastRateIncrease[replica]
              > self.rateInterval * hysterisisFactor):
            # The hysterisis factor in the condition is to ensure
            # that the receive-rate measurements have enough time
            # to adapt to the updated rate.

            # So we're in here now, which means we need to back down.
            # Multiplicatively decrease the rate by a factor of beta.
            self.valueOfLastDecrease[replica] = currentSendingRate
            self.rateLimiters[replica].rate *= beta
            self.rateLimiters[replica].rate = \
                max(self.rateLimiters[replica].rate, 0.0001)
            self.lastRateDecrease[replica] = Simulation.now()

        assert (self.rateLimiters[replica].rate > 0)
        alphaObservation = (replica.id,
                            self.rateLimiters[replica].rate)
        receiveRateObs = (replica.id,
                          self.receiveRate[replica].getRate())
        self.rateMonitor.observe("%s %s" % alphaObservation)
        self.receiveRateMonitor.observe("%s %s" % receiveRateObs)
开发者ID:jean-li,项目名称:kwiken,代码行数:54,代码来源:client.py

示例13: visit

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
	def visit(self, res):
		arrive = Sim.now() 	#arrival time
		print "%.3f: %s Arrived" % (Sim.now(), self.name)

		yield Sim.request, self, res
		wait = Sim.now()-arrive	#waiting time
		print "%.3f: %s Waited for %6.3f" % (Sim.now(), self.name, wait)

		tib = random.expovariate(1.0/timeInBank)
		yield Sim.hold, self, tib 
		yield Sim.release, self, res
		print "%.3f: %s took %.3f minutes to complete. Done." \
				% (Sim.now(), self.name, tib)
开发者ID:lzmacro,项目名称:pyDES,代码行数:15,代码来源:EmergencyDepartment.py

示例14: run

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
    def run(self, client, task, replicaThatServed):
        yield Simulation.hold, self,
        yield Simulation.waitevent, self, task.completionEvent

        delay = constants.NW_LATENCY_BASE + \
            random.normalvariate(constants.NW_LATENCY_MU,
                                 constants.NW_LATENCY_SIGMA)
        yield Simulation.hold, self, delay

        # OMG request completed. Time for some book-keeping
        client.pendingRequestsMap[replicaThatServed] -= 1
        client.pendingXserviceMap[replicaThatServed] = \
            (1 + client.pendingRequestsMap[replicaThatServed]) \
            * replicaThatServed.serviceTime

        client.pendingRequestsMonitor.observe(
            "%s %s" % (replicaThatServed.id,
                       client.pendingRequestsMap[replicaThatServed]))

        client.responseTimesMap[replicaThatServed] = \
            Simulation.now() - client.taskSentTimeTracker[task]
        client.latencyTrackerMonitor\
              .observe("%s %s" % (replicaThatServed.id,
                       Simulation.now() - client.taskSentTimeTracker[task]))
        metricMap = task.completionEvent.signalparam
        metricMap["responseTime"] = client.responseTimesMap[replicaThatServed]
        metricMap["nw"] = metricMap["responseTime"] - metricMap["serviceTime"]
        client.updateEma(replicaThatServed, metricMap)
        client.receiveRate[replicaThatServed].add(1)

        # Backpressure related book-keeping
        if (client.backpressure):
            client.updateRates(replicaThatServed, metricMap, task)

        client.lastSeen[replicaThatServed] = Simulation.now()

        if (client.REPLICA_SELECTION_STRATEGY == "ds"):
            client.latencyEdma[replicaThatServed]\
                  .update(metricMap["responseTime"])

        del client.taskSentTimeTracker[task]
        del client.taskArrivalTimeTracker[task]

        # Does not make sense to record shadow read latencies
        # as a latency measurement
        if (task.latencyMonitor is not None):
            task.latencyMonitor.observe("%s %s" %
                                        (Simulation.now() - task.start,
                                         client.id))
开发者ID:jean-li,项目名称:kwiken,代码行数:51,代码来源:client.py

示例15: run

# 需要导入模块: from SimPy import Simulation [as 别名]
# 或者: from SimPy.Simulation import now [as 别名]
    def run(self):
        start = Simulation.now()
        queueSizeBefore = len(self.server.queueResource.waitQ)
        yield Simulation.hold, self
        yield Simulation.request, self, self.server.queueResource
        waitTime = Simulation.now() - start         # W_i
        serviceTime = self.server.getServiceTime()  # Mu_i
        yield Simulation.hold, self, serviceTime
        yield Simulation.release, self, self.server.queueResource

        queueSizeAfter = len(self.server.queueResource.waitQ)
        self.task.sigTaskComplete({"waitingTime": waitTime,
                                   "serviceTime": serviceTime,
                                   "queueSizeBefore": queueSizeBefore,
                                   "queueSizeAfter": queueSizeAfter})
开发者ID:jean-li,项目名称:kwiken,代码行数:17,代码来源:server.py


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