@Override public org.powertac.common.CapacityProfile getCapacityProfile(Tariff tariff) { double usageSign = bundle.getPowerType().isConsumption() ? +1 : -1; // New code: shifted prediction - correct for tariff-eval purposes // =============================================================== double[] newForecast; // new code HashMap<CapacityOriginator, double[]> originator2usage = new HashMap<>(); for (CapacityOriginator capacityOriginator : bundle.getCapacityOriginators()) { double[] usageForecast = new double[CapacityProfile.NUM_TIMESLOTS]; // BUG FIX: this function is called from forecastCost() and used // by TariffEvaluationHelper, which assumes the forcast starts // at the next timeslot CapacityProfile forecast = capacityOriginator.getForecastForNextTimeslot(); for (int i = 0; i < CapacityProfile.NUM_TIMESLOTS; ++i) { double hourlyUsage = usageSign * forecast.getCapacity(i); usageForecast[i] = hourlyUsage; // don't divide yet / bundle.getPopulation(); } originator2usage.put(capacityOriginator, usageForecast); } // Refactored the following code for LearningUtilityOptimizer - shift profile // // create dummy subscription for the above usage vector: // 1 population member under 'tariff', (consuming the sum // of the originators' usage) TariffSubscription dummySubscription = new DummyTariffSubscription(getCustomerInfo(), tariff); newForecast = adjustForecastPerTariff(originator2usage, dummySubscription, bundle); double[] result = newForecast; Instant start = service.getTimeService().getCurrentTime().plus(TimeService.HOUR); return new org.powertac.common.CapacityProfile(result, start); }
private void usePower(Timeslot timeslot) { for (CapacityBundle bundle : capacityBundles) { List<TariffSubscription> subscriptions = getTariffSubscriptionRepo().findActiveSubscriptionsForCustomer(bundle.getCustomerInfo()); double totalCapacity = 0.0; double totalUsageCharge = 0.0; for (TariffSubscription subscription : subscriptions) { double usageSign = bundle.getPowerType().isConsumption() ? +1 : -1; double currCapacity = usageSign * useCapacity(subscription, bundle); if (Config.getInstance().isUsageChargesLogging()) { double charge = subscription .getTariff() .getUsageCharge(currCapacity, subscription.getTotalUsage(), false); totalUsageCharge += charge; } subscription.usePower(currCapacity); totalCapacity += currCapacity; } log.info( bundle.getName() + ": Total " + bundle.getPowerType() + " capacity for timeslot " + timeslot.getSerialNumber() + " = " + totalCapacity); logUsageCharges( bundle.getName() + ": Total " + bundle.getPowerType() + " usage charge for timeslot " + timeslot.getSerialNumber() + " = " + totalUsageCharge); } }
/** @Override hook */ protected void subscribeDefault() { for (CapacityBundle bundle : capacityBundles) { PowerType powerType = bundle.getPowerType(); if (getTariffMarket().getDefaultTariff(powerType) != null) { log.info( bundle.getName() + ": Subscribing " + bundle.getPopulation() + " customers to default " + powerType + " tariff"); subscribe( getTariffMarket().getDefaultTariff(powerType), bundle, bundle.getPopulation(), false); } else { log.info( bundle.getName() + ": No default tariff for power type " + powerType + "; trying generic type"); PowerType genericType = powerType.getGenericType(); if (getTariffMarket().getDefaultTariff(genericType) == null) { log.error( bundle.getName() + ": No default tariff for generic power type " + genericType + " either!"); } else { log.info( bundle.getName() + ": Subscribing " + bundle.getPopulation() + " customers to default " + genericType + " tariff"); subscribe( getTariffMarket().getDefaultTariff(genericType), bundle, bundle.getPopulation(), false); } } } }