def combine_withoutincrement(lines): # we return a new PolyLine which is a composite (summed horizontally) of inputs composite = PolyLine() if len(lines) < 2: if isinstance(lines[0], list): for point in lines[0]: composite.add(Point(point[0], point[1])) return composite return lines[0] # find the range defined by the curves ys = [] for l in lines: ys = ys + l.vectorize()[1] ys = remove(ys) ys.sort(reverse=True) for y in ys: xt = None for line in lines: x = line.x(y) if x is not None: xt = x if xt is None else xt + x composite.add(Point(xt, y)) return composite
def create_demand_curve(self, index): hvac_index = self.determine_hvac_index(index) demand_curve = PolyLine() oat = self.oat_predictions[index] if self.oat_predictions else self.tOut prices = self.determine_prices() price_max_bound = max( max(prices) + 0.1 * max(prices), max(self.prices) + max(self.prices) * 0.1) price_min_bound = min( min(prices) + 0.1 * min(prices), min(self.prices) - min(self.prices) * 0.1) temp = self.temp[index] quantities = [] for i in range(len(prices)): if self.hvac_avail[hvac_index]: temp_stpt = self.tsets[i] else: temp_stpt = self.tMinAdjUnoc quantity = min( max(self.getM(oat, temp, temp_stpt, hvac_index), self.mDotMin), self.mDotMax) quantities.append(quantity) demand_curve.add(Point(price=price_max_bound, quantity=min(quantities))) prices.sort(reverse=True) quantities.sort() for i in range(len(prices)): demand_curve.add(Point(price=prices[i], quantity=quantities[i])) demand_curve.add(Point(price=price_min_bound, quantity=max(quantities))) _log.debug("{} debug demand_curve4 - curve: {}".format( self.agent_name, demand_curve.points)) _log.debug("{} market {} has cleared airflow: {}".format( self.agent_name, index, demand_curve.x(self.prices[index]))) return demand_curve
def create_demand_curve(self, load_index, index): demand_curve = PolyLine() price_min, price_max = self.determine_prices() try: if len(self.market_name) > 1: qMin = self.q_uc[load_index] qMax = self.q_uc[load_index] else: qMin = self.single_timestep_power qMax = self.single_timestep_power demand_curve.add( Point(price=max(price_min, price_max), quantity=min(qMin, qMax))) demand_curve.add( Point(price=min(price_min, price_max), quantity=max(qMin, qMax))) except: demand_curve.add( Point(price=max(price_min, price_max), quantity=0.1)) demand_curve.add( Point(price=min(price_min, price_max), quantity=0.1)) topic_suffix = "/".join([self.agent_name, "DemandCurve"]) message = { "MarketIndex": index, "Curve": demand_curve.tuppleize(), "Commodity": "Electric" } self.publish_record(topic_suffix, message) _log.debug("{} debug demand_curve - curve: {}".format( self.agent_name, demand_curve.points)) return demand_curve
def create_supply_curve(self, clear_price, supply_market): index = self.supplier_market.index(supply_market) supply_curve = PolyLine() min_quantity = self.aggregate_demand[index].min_x()*0.8 max_quantity = self.aggregate_demand[index].max_x()*1.2 supply_curve.add(Point(price=clear_price, quantity=min_quantity)) supply_curve.add(Point(price=clear_price, quantity=max_quantity)) return supply_curve
def create_air_supply_curve(self, electric_price, electric_quantity): supply_curve = PolyLine() price = 65 quantity = 100000 supply_curve.add(Point(price=price, quantity=quantity)) price = 65 quantity = 0 # negative quantities are not real -1*10000 supply_curve.add(Point(price=price, quantity=quantity)) return supply_curve
def create_supply_curve(): supply_curve = PolyLine() price = 0 quantity = 0 supply_curve.add(Point(price, quantity)) price = 1000 quantity = 1000 supply_curve.add(Point(price, quantity)) return supply_curve
def create_demand_curve(): demand_curve = PolyLine() price = 0 quantity = 1000 demand_curve.add(Point(price, quantity)) price = 1000 quantity = 0 demand_curve.add(Point(price, quantity)) return demand_curve
def create_supply_curve(self): supply_curve = PolyLine() price = self.price quantity = self.infinity supply_curve.add(Point(price=price, quantity=quantity)) price = self.price quantity = 0 supply_curve.add(Point(price=price, quantity=quantity)) return supply_curve
def create_supply_curve(self, clear_price, supply_market): _log.debug("{}: clear consumer market price {}".format( self.agent_name, clear_price)) index = self.supplier_market.index(supply_market) supply_curve = PolyLine() min_quantity = self.aggregate_demand[index].min_x() * 0.8 max_quantity = self.aggregate_demand[index].max_x() * 1.2 supply_curve.add(Point(price=clear_price, quantity=min_quantity)) supply_curve.add(Point(price=clear_price, quantity=max_quantity)) return supply_curve
def create_demand_curve(self): if self.power_min is not None and self.power_max is not None: demand_curve = PolyLine() price_min, price_max = self.generate_price_points() demand_curve.add(Point(price=price_max, quantity=self.power_min)) demand_curve.add(Point(price=price_min, quantity=self.power_max)) else: demand_curve = None self.demand_curve = demand_curve return demand_curve
def create_air_supply_curve(self, electric_price): _log.debug("{}: clear air price {}".format(self.agent_name, electric_price)) air_supply_curve = PolyLine() price = electric_price min_quantity = self.load[0] max_quantity = self.load[-1] air_supply_curve.add(Point(price=price, quantity=min_quantity)) air_supply_curve.add(Point(price=price, quantity=max_quantity)) return air_supply_curve
def translate_aggregate_demand(self, agg_demand, index): electric_supply_curve = PolyLine() if self.market_prices is not None: self.price = self.market_prices[0] else: self.price = (agg_demand.min_y() + agg_demand.max_y()) / 2 electric_supply_curve.add(Point(price=self.price, quantity=0)) electric_supply_curve.add(Point(price=self.price, quantity=10000)) _log.debug("{}: electric demand : {}".format( self.agent_name, electric_supply_curve.points)) self.supplier_curve[index] = electric_supply_curve
def create_demand_curve(self, load_index, index): demand_curve = PolyLine() price_min, price_max = self.determine_prices() try: qMin = self.q_uc[load_index] qMax = self.q_uc[load_index] _log.debug("{}: demand curve for {} - {}".format(self.agent_name, self.market_name[index], [(qMin, price_max), (qMax, price_min)])) demand_curve.add(Point(price=max(price_min, price_max), quantity=min(qMin, qMax))) demand_curve.add(Point(price=min(price_min, price_max), quantity=max(qMin, qMax))) except: demand_curve.add(Point(price=max(price_min, price_max), quantity=0.1)) demand_curve.add(Point(price=min(price_min, price_max), quantity=0.1)) return demand_curve
def create_demand_curve(self): """ Create electric demand curve for agents respective lighting zone. :return: """ self.demand_curve = PolyLine() p_min = 10. p_max = 100. if self.hvac_avail: self.demand_curve.add(Point(price=min(p_min, p_max), quantity=max(self.qmin, self.qmax) * self.power_absnom)) self.demand_curve.add(Point(price=max(p_min, p_max), quantity=min(self.qmin, self.qmax)* self.power_absnom)) else: self.demand_curve.add(Point(price=max(p_min, p_max), quantity=0.)) self.demand_curve.add(Point(price=min(p_min, p_max), quantity=0.)) return self.demand_curve
def create_demand_curve(self): self.demand_curve = PolyLine() p_min = 10. p_max = 100. qMin = abs(self.get_q_min()) qMax = abs(self.get_q_max()) if self.hvac_avail: self.demand_curve.add(Point(price=max(p_min, p_max), quantity=min(qMin, qMax))) self.demand_curve.add(Point(price=min(p_min, p_max), quantity=max(qMin, qMax))) else: self.demand_curve.add(Point(price=max(p_min, p_max), quantity=0.1)) self.demand_curve.add(Point(price=min(p_min, p_max), quantity=0.1)) if self.hvac_avail: _log.debug("{} - Tout {} - Tin {} - q {}".format(self.agent_name, self.tOut, self.tIn, self.qHvacSens)) return self.demand_curve
def create_demand_curve(self): self.demand_curve = PolyLine() pMin = 10 pMax = 100 qMin = abs(self.getQMin()) qMax = abs(self.getQMax()) if (self.hvacAvail > 0): self.demand_curve.add( Point(price=max(pMin, pMax), quantity=min(qMin, qMax))) self.demand_curve.add( Point(price=min(pMin, pMax), quantity=max(qMin, qMax))) 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 combine(lines, increment): # we return a new PolyLine which is a composite (summed horizontally) of inputs composite = PolyLine() # find the range defined by the curves minY = None maxY = None for l in lines: minY = PolyLine.min(minY, l.min_y()) maxY = PolyLine.max(maxY, l.max_y()) # special case if the lines are already horizontal or None if minY == maxY: minSumX = None maxSumX = None for line in lines: minX = None maxX = None for point in line.points: minX = PolyLine.min(minX, point.x) maxX = PolyLine.max(maxX, point.x) minSumX = PolyLine.sum(minSumX, minX) maxSumX = PolyLine.sum(maxSumX, maxX) composite.add(Point(minSumX, minY)) if minX != maxX: composite.add(Point(maxSumX, maxY)) return composite # create an array of ys in equal increments, with highest first # this is assuming that price decreases with increase in demand (buyers!) # but seems to work with multiple suppliers? ys = sorted(np.linspace(minY, maxY, num=increment), reverse=True) # print ys # print minY, maxY # now find the cumulative x associated with each y in the array # starting with the highest y for y in ys: xt = None for line in lines: x = line.x(y, left=np.nan) # print x, y if x is not None: xt = x if xt is None else xt + x composite.add(Point(xt, y)) return composite
def create_demand_curve(self, market_index, sched_index, occupied): """ Create demand curve. market_index (0-23) where next hour is 0 (or for single market 0 for next market). sched_index (0-23) is hour of day corresponding to market that demand_curve is being created. :param market_index: int; current market index where 0 is the next hour. :param sched_index: int; 0-23 corresponding to hour of day :param occupied: bool; true if occupied :return: """ _log.debug("%s create_demand_curve - index: %s - sched: %s", self.core.identity, market_index, sched_index) demand_curve = PolyLine() prices = self.determine_prices() self.update_prediction_error() for control, price in zip(self.ct_flexibility, prices): if occupied: _set = control else: _set = self.off_setpoint q = self.get_q(_set, sched_index, market_index, occupied) demand_curve.add(Point(price=price, quantity=q)) topic_suffix = "DemandCurve" message = { "MarketIndex": market_index, "Curve": demand_curve.tuppleize(), "Commodity": self.commodity } _log.debug("%s debug demand_curve - curve: %s", self.core.identity, demand_curve.points) self.publish_record(topic_suffix, message) return demand_curve
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 create_electric_demand_curve(self, aggregate_air_demand): curve = PolyLine() for point in aggregate_air_demand.points: curve.add(Point(price=point.y, quantity=self.calcTotalLoad(point.x))) self.buyBidCurve = curve _log.debug("Report aggregated curve : {}".format(curve.points)) return curve
def translate_aggregate_demand(self, air_demand, index): electric_demand_curve = PolyLine() oat = self.oat_predictions[index] if self.oat_predictions else None for point in air_demand.points: electric_demand_curve.add(Point(price=point.y, quantity=self.model.calculate_load(point.x, oat))) _log.debug("{}: electric demand : {}".format(self.agent_name, electric_demand_curve.points)) return electric_demand_curve
def translate_aggregate_demand(self, air_demand, index): electric_demand_curve = PolyLine() oat = self.oat_predictions[index] if self.oat_predictions else None for point in air_demand.points: electric_demand_curve.add(Point(price=point.y, quantity=self.model.calculate_load(point.x, oat))) _log.debug("{}: electric demand : {}".format(self.agent_name, electric_demand_curve.points)) # Hard-coding the market names is not ideal. Need to come up with more robust solution for market in self.consumer_market: self.consumer_demand_curve[market][index] = electric_demand_curve
def electric_price_callback(self, timestamp, market_name, buyer_seller, price, quantity): _log.debug("{}: cleared price {} for {} at timestep {}".format( self.agent_name, price, market_name, timestamp)) self.report_cleared_price(buyer_seller, market_name, price, quantity, timestamp) if price is not None: self.make_air_market_offer(price) _log.debug("{}: agent making offer on air market".format( self.agent_name)) else: supply_curve = PolyLine() supply_curve.add(Point(price=10, quantity=0.1)) supply_curve.add(Point(price=10, quantity=0.1)) success, message = self.make_offer(self.air_market_name, SELLER, supply_curve) if success: _log.debug("price_check: just use the place holder")
def translate_aggregate_demand(self, agg_demand, index): electric_supply_curve = PolyLine() if self.demand_limit is not None: electric_supply_curve.add(Point(price=0, quantity=self.demand_limit)) electric_supply_curve.add(Point(price=1000, quantity=self.demand_limit)) else: if self.market_prices is not None: if self.market_type == "rtp": self.price = self.current_price else: self.price = self.market_prices[0] else: self.price = (agg_demand.min_y() + agg_demand.max_y())/2 min_q = agg_demand.min_x()*0.9 max_q = agg_demand.max_x()*1.1 electric_supply_curve.add(Point(price=self.price, quantity=min_q)) electric_supply_curve.add(Point(price=self.price, quantity=max_q)) _log.debug("{}: electric demand : {}".format(self.agent_name, electric_supply_curve.points)) self.supplier_curve[index] = electric_supply_curve
def create_demand_curve(self, index): demand_curve = PolyLine() price_min, price_max = self.determine_prices() quantity = self.determin_quantity(index) price = np.linspace(price_max, price_min, num=len(quantity)).tolist() for pr, qt in zip(price, quantity): demand_curve.add(Point(price=pr, quantity=qt)) _log.debug("{}: demand curve for {} - {}".format( self.agent_name, self.market_name[index], demand_curve.points)) return demand_curve
def create_electric_demand_curve(self, aggregate_air_demand): electric_demand_curve = PolyLine() self.load = [] for point in aggregate_air_demand.points: electric_demand_curve.add( Point(price=point.y, quantity=self.calcTotalLoad(point.x))) self.load.append(point.x) _log.debug("{}: aggregated curve : {}".format( self.agent_name, electric_demand_curve.points)) return electric_demand_curve
def create_demand_curve(self, index): self.demand_curve[index] = PolyLine() p_min = 10. p_max = 100. qMin = self.q_uc[index] qMax = self.q_uc[index] if self.hvac_avail: self.demand_curve[index].add( Point(price=max(p_min, p_max), quantity=min(qMin, qMax))) self.demand_curve[index].add( Point(price=min(p_min, p_max), quantity=max(qMin, qMax))) else: self.demand_curve[index].add( Point(price=max(p_min, p_max), quantity=0.1)) self.demand_curve[index].add( Point(price=min(p_min, p_max), quantity=0.1)) # if self.hvac_avail: # _log.debug("{} - Tout {} - Tin {} - q {}".format(self.agent_name, self.tOut, self.tIn, self.qHvacSens)) return self.demand_curve[index]
def air_aggregate_callback(self, timestamp, market_name, buyer_seller, aggregate_air_demand): if buyer_seller == BUYER: _log.debug("{} - Received aggregated {} curve".format( self.agent_name, market_name)) electric_demand = self.create_electric_demand_curve( aggregate_air_demand) success, message = self.make_offer(self.electric_market_name, BUYER, electric_demand) if success: _log.debug("{}: make a offer for {}".format( self.agent_name, market_name)) else: _log.debug("{}: offer for the {} was rejected".format( self.agent_name, market_name)) supply_curve = PolyLine() supply_curve.add(Point(price=10, quantity=0.001)) supply_curve.add(Point(price=10, quantity=0.001)) success, message = self.make_offer(self.air_market_name, SELLER, supply_curve) _log.debug("{}: offer for {} was accepted: {}".format( self.agent_name, self.air_market_name, success))
def offer_callback(self, timestamp, market_name, buyer_seller): if market_name in self.market_names: # Get the price for the corresponding market idx = int(market_name.split('_')[-1]) price = self.prices[idx+1] #price *= 1000. # Convert to mWh to be compatible with the mixmarket # Quantity min_quantity = 0 max_quantity = 10000 # float("inf") # Create supply curve supply_curve = PolyLine() supply_curve.add(Point(quantity=min_quantity, price=price)) supply_curve.add(Point(quantity=max_quantity, price=price)) # Make offer _log.debug("{}: offer for {} as {} at {} - Curve: {} {}".format(self.agent_name, market_name, SELLER, timestamp, supply_curve.points[0], supply_curve.points[1])) success, message = self.make_offer(market_name, SELLER, supply_curve) _log.debug("{}: offer has {} - Message: {}".format(self.agent_name, success, message))
def create_supply_curve(self): supply_curve = PolyLine() if self.demand_limit: min_price = self.price_min max_price = self.price_max supply_curve.add( Point(price=min_price, quantity=self.demand_limit_threshold)) supply_curve.add( Point(price=max_price, quantity=self.demand_limit_threshold)) else: if self.prices is None: price = self.price elif self.price_index < len(self.prices) - 1: price = float(self.prices[self.price_index]) self.price_index = self.price_index + 1 else: self.price_index = 0 price = float(self.prices[self.price_index]) supply_curve.add(Point(price=price, quantity=self.infinity)) supply_curve.add(Point(price=price, quantity=0.0)) return supply_curve