@Override // natural ordering is by decreasing utility values public int compareTo (TariffUtility other) { double result = other.utility - utility; if (result == 0.0) // consistent with equals... return (int) (other.tariff.getId() - tariff.getId()); else if (result > 0.0) return 1; else return -1; } }
/** * You need a CustomerInfo and a Tariff to create one of these. */ public TariffSubscription (CustomerInfo customer, Tariff tariff) { super(); this.customer = customer; this.tariff = tariff; this.tariffId = tariff.getId(); expirations = new ArrayList<ExpirationRecord>(); setRegulationCap(new RegulationAccumulator(0.0, 0.0)); }
/** Subscribing a certain population amount to a certain subscription */ void subscribe (Tariff tariff, int customerCount, CustomerInfo customer) { tariffMarketService.subscribeToTariff(tariff, customer, customerCount); log.info(this.toString() + " " + tariff.getPowerType().toString() + ": " + customerCount + " were subscribed to tariff " + tariff.getId()); }
private void subscribe (Tariff tariff, CapacityBundle bundle, int customerCount, boolean verbose) { getTariffMarket().subscribeToTariff(tariff, bundle.getCustomerInfo(), customerCount); if (verbose) { log.info(bundle.getName() + ": Subscribed " + customerCount + " customers to tariff " + tariff.getId() + " successfully"); } }
private void revokeTariffsForDisabledBrokers () { for (Broker broker : brokerRepo.findDisabledBrokers()) { if (!disabledBrokers.contains(broker)) { // this is a new one disabledBrokers.add(broker); for (Tariff tariff : tariffRepo.findTariffsByBroker(broker)) { if (Tariff.State.KILLED != tariff.getState()) { log.info("Revoking tariff " + tariff.getId() + " from disabled broker " + broker.getUsername()); addPendingRevoke(tariff); } } } } }
private void updateSubscriptions () { int check = 0; for (Tariff tariff : allocations.keySet()) { int count = allocations.get(tariff); check += count; if (count < 0) { //unsubscribe TariffSubscription sub = getTariffSubscriptionRepo().findSubscriptionForTariffAndCustomer (tariff, customerInfo); sub.unsubscribe(-count); log.info("customer " + customerInfo.getName() + " unsubscribes " + -count + " from tariff " + tariff.getId()); } else if (count > 0) { // subscribe getTariffMarket().subscribeToTariff(tariff, customerInfo, count); log.info("customer " + customerInfo.getName() + " subscribes " + count + " to tariff " + tariff.getId()); } } // sanity check if (check != 0) { log.error("Subscription updates do not add up for " + customerInfo.getName() + ": " + check); } }
private double forecastCost (Tariff tariff) { CapacityProfile profile = accessor.getCapacityProfile(tariff); if (0 == profile.getProfile().length) { log.error("Zero-length profile for " + customerInfo.getName()); return 0.0; } setProfileLength(profile.getProfile().length); // NOTE: must call the next function after the previous, // since the previous writes inconv. factors. // Always 0 except for AdaptiveCapacityOriginator double inconv = accessor.getShiftingInconvenienceFactor(tariff); double profileCost = helper.estimateCost(tariff, profile.getProfile(), profile.getStart()); if (Double.isNaN(profileCost)) { log.error(getName() + ": profile cost NaN for tariff " + tariff.getId()); } //double scale = preferredDuration * 24.0 / profile.length; double scale = stdDuration * 24.0 / getProfileLength(); if (Double.isNaN(scale)) { log.error(getName() + ": scale NaN for tariff " + tariff.getId()); } log.debug("tariff {}: profileCost={}, inconv={}, scaled-charge={}, scaled (cost+inconv)={}", tariff.getId(), profileCost, inconv, profileCost * scale, (profileCost + inconv) * scale, (profileCost + inconv) * scale / (profileCost * scale)); return (profileCost + inconv) * scale; }
/** Unsubscribing a certain population amount from a certain subscription */ void unsubscribe (TariffSubscription subscription, int customerCount) { subscription.unsubscribe(customerCount); log.info(this.toString() + " " + subscription.getTariff().getPowerType().toString() + ": " + customerCount + " were unsubscribed from tariff " + subscription.getTariff().getId()); } }
@Override public CapacityAccumulator useCapacity (TariffSubscription subscription) { int timeslot = timeslotRepo.currentSerialNumber(); // we don't re-adjust for current weather here; // would not be accurate for wind/solar production // // Daniel: try to get per sub first, if doesn't work get the // old, averaged one double forecastCapacity = getForecastCapacityPerSub(timeslot, subscription); double adjustedCapacity = forecastCapacity; adjustedCapacity = adjustCapacityForSubscription( timeslot, adjustedCapacity, subscription); if (Double.isNaN(adjustedCapacity)) { throw new Error("Adjusted capacity is NaN for forecast capacity = " + forecastCapacity); } CapacityAccumulator result = addRegCapacityMaybe(subscription, timeslot, adjustedCapacity); actualCapacities.put(timeslot, result.getCapacity()); log.info(logIdentifier + ": Adjusted capacity for tariff " + subscription.getTariff().getId() + " = " + result.getCapacity()); return result; }
@Override public boolean apply (TariffSubscription sub) { return (null != tariffRepo.findTariffById(sub.getTariff().getId()) && sub.getTariff().getState() == Tariff.State.KILLED && sub.getCustomersCommitted() > 0); } });
replacementTariff = currentTariff.getIsSupersededBy(); log.info("Customer " + customerInfo.getName() + ": tariff " + currentTariff.getId() + " revoked, superseded by " + ((null == replacementTariff) ? "default": replacementTariff.getId())); if (null == replacementTariff) { replacementTariff = defaultTariff; if (Double.isNaN(cost)) { log.error(getName() + ": cost is NaN for tariff " + tariff.getId()); + tariff.getId()); tariff.getId(), finalCost.costEstimate, defaultEval.costEstimate, utility); TariffUtility tu = util.tariff.getId(), util.probability); for (TariffUtility tu : evals) { log.debug("tariff {}: sample={}, probability={}", tu.tariff.getId(), tariffSample, tu.probability); if (tariffSample <= tu.probability) { addAllocation(currentTariff, tu.tariff, count);
@Override public CapacityAccumulator useCapacity (TariffSubscription subscription) { int timeslot = timeslotRepo.currentSerialNumber(); double baseCapacity = getBaseCapacity(timeslot); if (Double.isNaN(baseCapacity)) { throw new Error("Base capacity is NaN!"); } //else if (parentBundle.getPowerType().isProduction()) { // // correct sign before going further // baseCapacity *= -1.0; //} logCapacityDetails(logIdentifier + ": Base capacity for timeslot " + timeslot + " = " + baseCapacity); // total adjusted capacity double adjustedCapacity = baseCapacity; adjustedCapacity = adjustCapacityForPeriodicSkew(adjustedCapacity, timeService.getCurrentDateTime(), true); adjustedCapacity = adjustCapacityForCurrentWeather(adjustedCapacity, true); // moved up one level //adjustedCapacity = // adjustCapacityForSubscription(timeslot, adjustedCapacity, subscription); CapacityAccumulator result = addRegCapacityMaybe(subscription, timeslot, adjustedCapacity); actualCapacities.put(timeslot, result.getCapacity()); log.info(logIdentifier + ": Adjusted capacity for tariff " + subscription.getTariff().getId() + " = " + result.getCapacity()); return result; }
if (0 == pendingUnsubscribeCount) { log.info("regulation capacity for " + getCustomer().getName() + ":" + this.getTariff().getId() + " (" + up + ", " + down + ")"); return new RegulationAccumulator(up, down); / customersCommitted; log.info("remaining regulation capacity for " + getCustomer().getName() + ":" + this.getTariff().getId() + " reduced by " + ratio + " to (" + up * ratio + ", " + down * ratio + ")");
/** * Handles changes in tariff expiration date. */ public void handleMessage (TariffExpire update) { ValidationResult result = validateUpdate(update); if (result.tariff == null) send(result.message); else { Instant newExp = update.getNewExpiration(); if (newExp != null && newExp.isBefore(timeService.getCurrentTime())) { // new expiration date in the past log.warn("attempt to set expiration for tariff " + result.tariff.getId() + " in the past:" + newExp.toString()); send(new TariffStatus(update.getBroker(), update.getTariffId(), update.getId(), TariffStatus.Status.invalidUpdate) .withMessage("attempt to set expiration in the past")); } else { // update expiration date result.tariff.setExpiration(newExp); log.info("Tariff " + update.getTariffId() + "now expires at " + new DateTime(result.tariff.getExpiration(), DateTimeZone.UTC).toString()); success(update); } } }
log.info("Evaluated tariff " + tariff.getId() + ": cost=" + cost + ", inconvenience=" + hassle);
private ProfileRecommendation getProfileRecommendationPerSub (CapacityOriginator capacityOriginator, CapacityBundle bundle, ForecastRecord forecastRecord, Map<CapacityOriginator, Map<TariffSubscription, List<CapacityProfile>>> permsPerSub, TariffSubscription sub) { logRecommendationDetails("getProfileRecommendationPerSub(" + sub.getCustomer().getName() + ", " + sub.getTariff().getId() + ") Forecast " + forecastRecord.capacityProfile + " usage charge = " + forecastRecord.usageCharge); ProfileRecommendation rec = new ProfileRecommendation(); for (CapacityProfile perm : permsPerSub.get(capacityOriginator).get(sub)) { double usageCharge = computeProfileUsageChargePerSub(perm, sub, capacityOriginator); if (isPermutationAcceptable(capacityOriginator, bundle.getOptimizerStructure(), usageCharge, forecastRecord.usageCharge)) { Opinion opinion = rec.new Opinion(); // avoid duplication opinion.usageCharge = usageCharge; opinion.profileChange = forecastRecord.capacityProfile.distanceTo(perm); rec.setOpinion(perm, opinion); } } if (!rec.isEmpty()) { computeDerivedValues(rec, bundle.getOptimizerStructure()); } return rec; }
log.error("tariff " + tariff.getId() + " customer " + customer.getName() + ": attempt to unsubscribe " + customerCount +