@Test public void revokeToKilledSuperseding () { TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION). addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff); TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION). withMinDuration(TimeService.DAY * 5). addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); double[] profile = {1.0, 2.0}; cma.capacityProfile = new CapacityProfile(profile, start); cma.setChoiceSamples(0.45, 0.55); subscribeTo(bobTariff, 5000); subscribeTo(jimTariff, 5000); jimTariff.setState(Tariff.State.KILLED); TariffSpecification jimSTS = new TariffSpecification(jim, PowerType.CONSUMPTION). withMinDuration(TimeService.DAY * 5). addSupersedes(jimTariff.getId()). addRate(new Rate().withValue(-0.4)); Tariff jimSuper = new Tariff(jimSTS); when(tariffRepo.findTariffById(jimTariff.getId())) .thenReturn(jimTariff); initTariff(jimSuper); jimSuper.setState(Tariff.State.KILLED); final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals(customer, args[1], "correct customer"); calls.put((Tariff)args[0], (Integer)args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))) .thenReturn(tariffs); evaluator.evaluateTariffs(); assertEquals(2, calls.size(), "two calls"); assertEquals(-5000, calls.get(jimTariff).intValue(), "-5000 for jim"); assertEquals(5000, calls.get(bobTariff).intValue(), "+5000 for defaultConsumption"); }
public void evaluateTariffs () { allocations.clear(); HashSet<Tariff> newTariffs = new LinkedHashSet<>(getTariffRepo() .findRecentActiveTariffs(tariffEvalDepth, customerInfo.getPowerType())); addSupersedingTariffs(newTariffs); double actualInertia = Math.max(0.0, (1.0 - Math.pow(2, 1 - evaluationCounter)) * inertia); evaluationCounter += 1; EvalData defaultEval = getDefaultTariffEval(); log.info("customer {}: defaultEval={}", getName(), defaultEval.costEstimate); for (Tariff tariff : newTariffs) { EvalData eval = evaluatedTariffs.get(tariff); if (evaluateAllTariffs || null == eval) { double cost = forecastCost(tariff); double hassle = computeInconvenience(tariff); log.info("Evaluated tariff " + tariff.getId() + ": cost=" + cost + ", inconvenience=" + hassle); eval = new EvalData(cost, hassle); evaluatedTariffs.put(tariff, eval); } } for (TariffSubscription subscription : getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo)) { Tariff subTariff = subscription.getTariff(); double withdrawCost = subTariff.getEarlyWithdrawPayment(); int committedCount = subscription.getCustomersCommitted(); int expiredCount = subscription.getExpiredCustomerCount(); if (withdrawCost == 0.0 || (expiredCount > 0 && expiredCount == committedCount)) { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, committedCount, getDefaultTariff(), defaultEval, newTariffs); } else { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, expiredCount, getDefaultTariff(), defaultEval, newTariffs); evaluateAlternativeTariffs(subscription, actualInertia, withdrawCost, committedCount - expiredCount, getDefaultTariff(), defaultEval, newTariffs); } } updateSubscriptions(); }
TariffEvaluator { public void evaluateTariffs () { allocations.clear(); HashSet<Tariff> newTariffs = new LinkedHashSet<>(getTariffRepo() .findRecentActiveTariffs(tariffEvalDepth, customerInfo.getPowerType())); addSupersedingTariffs(newTariffs); double actualInertia = Math.max(0.0, (1.0 - Math.pow(2, 1 - evaluationCounter)) * inertia); evaluationCounter += 1; EvalData defaultEval = getDefaultTariffEval(); log.info("customer {}: defaultEval={}", getName(), defaultEval.costEstimate); for (Tariff tariff : newTariffs) { EvalData eval = evaluatedTariffs.get(tariff); if (evaluateAllTariffs || null == eval) { double cost = forecastCost(tariff); double hassle = computeInconvenience(tariff); log.info("Evaluated tariff " + tariff.getId() + ": cost=" + cost + ", inconvenience=" + hassle); eval = new EvalData(cost, hassle); evaluatedTariffs.put(tariff, eval); } } for (TariffSubscription subscription : getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo)) { Tariff subTariff = subscription.getTariff(); double withdrawCost = subTariff.getEarlyWithdrawPayment(); int committedCount = subscription.getCustomersCommitted(); int expiredCount = subscription.getExpiredCustomerCount(); if (withdrawCost == 0.0 || (expiredCount > 0 && expiredCount == committedCount)) { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, committedCount, getDefaultTariff(), defaultEval, newTariffs); } else { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, expiredCount, getDefaultTariff(), defaultEval, newTariffs); evaluateAlternativeTariffs(subscription, actualInertia, withdrawCost, committedCount - expiredCount, getDefaultTariff(), defaultEval, newTariffs); } } updateSubscriptions(); } }
TariffEvaluator { public void evaluateTariffs () { allocations.clear(); HashSet<Tariff> newTariffs = new LinkedHashSet<>(getTariffRepo() .findRecentActiveTariffs(tariffEvalDepth, customerInfo.getPowerType())); addSupersedingTariffs(newTariffs); double actualInertia = Math.max(0.0, (1.0 - Math.pow(2, 1 - evaluationCounter)) * inertia); evaluationCounter += 1; EvalData defaultEval = getDefaultTariffEval(); log.info("customer {}: defaultEval={}", getName(), defaultEval.costEstimate); for (Tariff tariff : newTariffs) { EvalData eval = evaluatedTariffs.get(tariff); if (evaluateAllTariffs || null == eval) { double cost = forecastCost(tariff); double hassle = computeInconvenience(tariff); log.info("Evaluated tariff " + tariff.getId() + ": cost=" + cost + ", inconvenience=" + hassle); eval = new EvalData(cost, hassle); evaluatedTariffs.put(tariff, eval); } } for (TariffSubscription subscription : getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo)) { Tariff subTariff = subscription.getTariff(); double withdrawCost = subTariff.getEarlyWithdrawPayment(); int committedCount = subscription.getCustomersCommitted(); int expiredCount = subscription.getExpiredCustomerCount(); if (withdrawCost == 0.0 || (expiredCount > 0 && expiredCount == committedCount)) { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, committedCount, getDefaultTariff(), defaultEval, newTariffs); } else { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, expiredCount, getDefaultTariff(), defaultEval, newTariffs); evaluateAlternativeTariffs(subscription, actualInertia, withdrawCost, committedCount - expiredCount, getDefaultTariff(), defaultEval, newTariffs); } } updateSubscriptions(); } TariffEvaluator(CustomerModelAccessor cma,
                          ServerConfiguration config);  TariffEvaluator(CustomerModelAccessor cma); }
TariffEvaluator { public void evaluateTariffs () { allocations.clear(); HashSet<Tariff> newTariffs = new LinkedHashSet<>(getTariffRepo() .findRecentActiveTariffs(tariffEvalDepth, customerInfo.getPowerType())); addSupersedingTariffs(newTariffs); double actualInertia = Math.max(0.0, (1.0 - Math.pow(2, 1 - evaluationCounter)) * inertia); evaluationCounter += 1; EvalData defaultEval = getDefaultTariffEval(); log.info("customer {}: defaultEval={}", getName(), defaultEval.costEstimate); for (Tariff tariff : newTariffs) { EvalData eval = evaluatedTariffs.get(tariff); if (evaluateAllTariffs || null == eval) { double cost = forecastCost(tariff); double hassle = computeInconvenience(tariff); log.info("Evaluated tariff " + tariff.getId() + ": cost=" + cost + ", inconvenience=" + hassle); eval = new EvalData(cost, hassle); evaluatedTariffs.put(tariff, eval); } } for (TariffSubscription subscription : getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo)) { Tariff subTariff = subscription.getTariff(); double withdrawCost = subTariff.getEarlyWithdrawPayment(); int committedCount = subscription.getCustomersCommitted(); int expiredCount = subscription.getExpiredCustomerCount(); if (withdrawCost == 0.0 || (expiredCount > 0 && expiredCount == committedCount)) { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, committedCount, getDefaultTariff(), defaultEval, newTariffs); } else { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, expiredCount, getDefaultTariff(), defaultEval, newTariffs); evaluateAlternativeTariffs(subscription, actualInertia, withdrawCost, committedCount - expiredCount, getDefaultTariff(), defaultEval, newTariffs); } } updateSubscriptions(); } TariffEvaluator(CustomerModelAccessor cma,
                          ServerConfiguration config);  TariffEvaluator(CustomerModelAccessor cma); void initializeCostFactors(double wtExpected, double wtMax,
                                     double wtRealized, double soldThreshold); void initializeInconvenienceFactors(double touFactor,
                                              double tieredRateFactor,
                                              double variablePricingFactor,
                                              double interruptibilityFactor); void initializeRegulationFactors(double expectedCurtailment,
                                           double expectedDischarge,
                                           double expectedDownRegulation); TariffEvaluator withChunkSize(int size); TariffEvaluator withTariffEvalDepth(int depth); TariffEvaluator withEvaluateAllTariffs(boolean value); TariffEvaluator withInertia(double inertia); TariffEvaluator withSignupBonusFactor(double factor); TariffEvaluator withRationality(double rationality); TariffEvaluator withInconvenienceWeight(double weight); TariffEvaluator withTariffSwitchFactor(double factor); TariffEvaluator withPreferredContractDuration(double days); void evaluateTariffs(); double getTouFactor(); double getTieredRateFactor(); double getVariablePricingFactor(); double getInterruptibilityFactor(); double computeInconvenience(Tariff tariff); }
TariffEvaluator { public void evaluateTariffs () { allocations.clear(); HashSet<Tariff> newTariffs = new LinkedHashSet<>(getTariffRepo() .findRecentActiveTariffs(tariffEvalDepth, customerInfo.getPowerType())); addSupersedingTariffs(newTariffs); double actualInertia = Math.max(0.0, (1.0 - Math.pow(2, 1 - evaluationCounter)) * inertia); evaluationCounter += 1; EvalData defaultEval = getDefaultTariffEval(); log.info("customer {}: defaultEval={}", getName(), defaultEval.costEstimate); for (Tariff tariff : newTariffs) { EvalData eval = evaluatedTariffs.get(tariff); if (evaluateAllTariffs || null == eval) { double cost = forecastCost(tariff); double hassle = computeInconvenience(tariff); log.info("Evaluated tariff " + tariff.getId() + ": cost=" + cost + ", inconvenience=" + hassle); eval = new EvalData(cost, hassle); evaluatedTariffs.put(tariff, eval); } } for (TariffSubscription subscription : getTariffSubscriptionRepo(). findActiveSubscriptionsForCustomer(customerInfo)) { Tariff subTariff = subscription.getTariff(); double withdrawCost = subTariff.getEarlyWithdrawPayment(); int committedCount = subscription.getCustomersCommitted(); int expiredCount = subscription.getExpiredCustomerCount(); if (withdrawCost == 0.0 || (expiredCount > 0 && expiredCount == committedCount)) { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, committedCount, getDefaultTariff(), defaultEval, newTariffs); } else { evaluateAlternativeTariffs(subscription, actualInertia, 0.0, expiredCount, getDefaultTariff(), defaultEval, newTariffs); evaluateAlternativeTariffs(subscription, actualInertia, withdrawCost, committedCount - expiredCount, getDefaultTariff(), defaultEval, newTariffs); } } updateSubscriptions(); } TariffEvaluator(CustomerModelAccessor cma,
                          ServerConfiguration config);  TariffEvaluator(CustomerModelAccessor cma); void initializeCostFactors(double wtExpected, double wtMax,
                                     double wtRealized, double soldThreshold); void initializeInconvenienceFactors(double touFactor,
                                              double tieredRateFactor,
                                              double variablePricingFactor,
                                              double interruptibilityFactor); void initializeRegulationFactors(double expectedCurtailment,
                                           double expectedDischarge,
                                           double expectedDownRegulation); TariffEvaluator withChunkSize(int size); TariffEvaluator withTariffEvalDepth(int depth); TariffEvaluator withEvaluateAllTariffs(boolean value); TariffEvaluator withInertia(double inertia); TariffEvaluator withSignupBonusFactor(double factor); TariffEvaluator withRationality(double rationality); TariffEvaluator withInconvenienceWeight(double weight); TariffEvaluator withTariffSwitchFactor(double factor); TariffEvaluator withPreferredContractDuration(double days); void evaluateTariffs(); double getTouFactor(); double getTieredRateFactor(); double getVariablePricingFactor(); double getInterruptibilityFactor(); double computeInconvenience(Tariff tariff);  }