示例#1
0
class FastCharging(LimitedWaitingResourceEntity):
    tag="fastCharging"
    def __init__(self, transaction, xmlSource):
        super().__init__(transaction, xmlSource)
        self.voltage = getXValue(xmlSource, "voltage", XValueHelper(self))
        self.current = getXValue(xmlSource, "current", XValueHelper(self))
        #output properties
        self.chargedEnergy = None
    
    def action(self):
        # yield from super().action()
        shopTime = float(self.duration)
        self.alarm = Alarm(self.transaction)
        self.simulation.activate(self.alarm, self.alarm.wakeup(delay=float(self.maxWaiting)))
        yield self.request()
        if self.gotResource():
            yield self.hold(shopTime)
            yield self.release()
            self.usedResource = True
        else:
            yield self.hold(shopTime)
        
        if self.usedResource:    
            actor = self.transaction.actor.props
            initialEnergy = actor["energy"]
            actor["energy"] = charging(self.voltage, self.current, actor["energy"],
                                   actor["capacity"], shopTime)
            self.chargedEnergy = actor["energy"] - initialEnergy
        else:
            self.chargedEnergy = 0.0
示例#2
0
 def action(self):
     # yield from super().action()
     shopTime = float(self.duration)
     self.alarm = Alarm(self.transaction)
     self.simulation.activate(self.alarm, self.alarm.wakeup(delay=float(self.maxWaiting)))
     yield self.request()
     if self.gotResource():
         yield self.hold(shopTime)
         yield self.release()
         self.usedResource = True
     else:
         yield self.hold(shopTime)
     
     if self.usedResource:    
         actor = self.transaction.actor.props
         initialEnergy = actor["energy"]
         actor["energy"] = charging(self.voltage, self.current, actor["energy"],
                                actor["capacity"], shopTime)
         self.chargedEnergy = actor["energy"] - initialEnergy
     else:
         self.chargedEnergy = 0.0