本文整理汇总了Python中volttron.platform.agent.base_market_agent.poly_line.PolyLine.x方法的典型用法代码示例。如果您正苦于以下问题:Python PolyLine.x方法的具体用法?Python PolyLine.x怎么用?Python PolyLine.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类volttron.platform.agent.base_market_agent.poly_line.PolyLine
的用法示例。
在下文中一共展示了PolyLine.x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LightAgent
# 需要导入模块: from volttron.platform.agent.base_market_agent.poly_line import PolyLine [as 别名]
# 或者: from volttron.platform.agent.base_market_agent.poly_line.PolyLine import x [as 别名]
class LightAgent(MarketAgent, FirstOrderZone):
"""
The SampleElectricMeterAgent serves as a sample of an electric meter that
sells electricity for a single building at a fixed price.
"""
def __init__(self, market_name,agent_name,k,qmax,Pabsnom,nonResponsive,verbose_logging,subscribing_topic, **kwargs):
super(LightAgent, self).__init__(verbose_logging, **kwargs)
self.market_name = market_name
self.agent_name = agent_name
self.k = k
self.qmax = qmax
self.Pabsnom=Pabsnom
self.nonResponsive = nonResponsive
self.iniState()
self.subscribing_topic=subscribing_topic
self.join_market(self.market_name, BUYER, None, self.offer_callback, None, self.price_callback, self.error_callback)
@Core.receiver('onstart')
def setup(self, sender, **kwargs):
_log.debug('Subscribing to '+'devices/CAMPUS/BUILDING1/AHU1/all')
self.vip.pubsub.subscribe(peer='pubsub',
prefix='devices/CAMPUS/BUILDING1/AHU1/all',
callback=self.updateState)
def offer_callback(self, timestamp, market_name, buyer_seller):
result,message=self.make_offer(market_name, buyer_seller, self.create_demand_curve())
_log.debug("results of the make offer {}".format(result))
if not result:
_log.debug("the new lightingt (maintain{}".format(self.qMax))
gevent.sleep(random.random())
self.vip.rpc.call('platform.actuator','set_point', self.agent_name,self.subscribing_topic+'/'+self.agent_name,round(self.qNorm,2)).get(timeout=6)
def create_demand_curve(self):
self.demand_curve = PolyLine()
pMin = 10
pMax = 100
if (self.hvacAvail > 0):
self.demand_curve.add(Point(price=min(pMin, pMax),quantity=max(self.qMin, self.qMax)*self.Pabsnom))
self.demand_curve.add(Point(price=max(pMin, pMax),quantity=min(self.qMin, self.qMax)*self.Pabsnom))
else:
self.demand_curve.add(Point(price=max(pMin, pMax), quantity=0))
self.demand_curve.add(Point(price=min(pMin, pMax),quantity=0))
return self.demand_curve
def iniState(self):
self.hvacAvail = 1
self.pClear = None
self.qMin = 0.7
self.qMax = self.qmax
self.qNorm=self.qMax
self.qClear=self.qNorm
def updateState(self, peer, sender, bus, topic, headers, message):
'''Subscribe to device data from message bus
'''
_log.debug('Received one new dataset')
info = {}
for key, value in message[0].items():
info[key] = value
self.hvacAvail = info['SupplyFanStatus']
if (self.hvacAvail > 0):
self.qNorm=self.qMax
else:
self.qNorm=0
def updateSet(self):
if self.pClear is not None and not self.nonResponsive and self.hvacAvail:
self.qClear = self.clamp(self.demand_curve.x(self.pClear), self.qMax, self.qMin)
else:
self.qClear = 0
# if self.qClear is None:
# self.qClear = 0.
def clamp(self, value, x1, x2):
minValue = min(x1, x2)
maxValue = max(x1, x2)
return min(max(value, minValue), maxValue)
def price_callback(self, timestamp, market_name, buyer_seller, price, quantity):
_log.debug("the price is {}".format(price))
self.pClear=price
if self.pClear is not None:
self.updateSet()
_log.debug("the new lightingt is {}".format(self.qClear))
gevent.sleep(random.random())
self.vip.rpc.call('platform.actuator','set_point', self.agent_name,self.subscribing_topic+'/'+self.agent_name,round(self.qClear,2)).get(timeout=5)
def error_callback(self, timestamp, market_name, buyer_seller, error_code, error_message, aux):
_log.debug("the new lightingt is {}".format(self.qNorm))
self.vip.rpc.call('platform.actuator','set_point', self.agent_name,self.subscribing_topic+'/'+self.agent_name,round(self.qNorm,2)).get(timeout=5)
def ease(self, target, current, limit):
return current - np.sign(current-target)*min(abs(current-target), abs(limit))