@Test public void testSingleBO () { pplusPrime = 0.00005; pminusPrime = -0.00005; BalancingOrder bo1 = new BalancingOrder(b1, spec1, 0.6, 0.05); tariffRepo.addBalancingOrder(bo1); ChargeInfo ci1 = new ChargeInfo(b1, -20.0); ci1.addBalancingOrder(bo1); brokerData.add(ci1); ChargeInfo ci2 = new ChargeInfo(b2, 10.0); brokerData.add(ci2); when(capacityControlService.getRegulationCapacity(bo1)). thenReturn(new RegulationAccumulator(5.0, 0.0)); uut.settle(context, brokerData); verify(capacityControlService).exerciseBalancingControl(eq(bo1), eq(5.0), eq(0.30375, 1e-6)); assertEquals(-1.21, ci1.getBalanceChargeP1(), 1e-6, "b1.p1"); assertEquals(0.605, ci2.getBalanceChargeP1(), 1e-6, "b2.p1"); }
@Override public void settle (SettlementContext service, List<ChargeInfo> brokerData) { pPlus = service.getPPlus(); pPlusPrime = service.getPPlusPrime(); pMinus = service.getPMinus(); pMinusPrime = service.getPMinusPrime(); double totalImbalance = 0.0; double totalQty = 0.0; for (ChargeInfo info : brokerData) { totalImbalance += info.getNetLoadKWh(); totalQty += Math.abs(info.getNetLoadKWh()); } log.info("totalImbalance=" + totalImbalance); if (Math.abs(totalImbalance) < epsilon) { if (totalQty < epsilon) return; totalImbalance = epsilon / 2.0; } double sgn = Math.signum(totalImbalance); SortedSet<BOWrapper> candidates = findCandidateOrders(brokerData, totalImbalance); ArrayList<BOWrapper> possibles = new ArrayList<BOWrapper> (); possibles.addAll(candidates); for (BOWrapper bo: possibles) { RegulationAccumulator cap = capacityControlService.getRegulationCapacity(bo.balancingOrder); log.info("tariff " + bo.balancingOrder.getTariffId() + ": up=" + cap.getUpRegulationCapacity() + ", down=" + cap.getDownRegulationCapacity()); if (sgn < 0.0) { bo.availableCapacity = cap.getUpRegulationCapacity(); } else { bo.availableCapacity = cap.getDownRegulationCapacity(); } if (Math.abs(bo.availableCapacity) < epsilon) candidates.remove(bo); } insertDummyOrders(candidates, totalImbalance * 2); determineExerciseSet(totalImbalance, candidates); SortedSet<BOWrapper> nonExercised = determineNonExercisedSet(candidates); HashSet<ChargeInfo> nonParticipants = new HashSet<ChargeInfo>(); for (ChargeInfo info: brokerData) { info.setBalanceChargeP2(computeVcgCharges(info, totalImbalance, candidates, nonExercised, nonParticipants)); } computeImbalanceCharges(brokerData, totalImbalance, candidates); double exercisedCapacity = 0.0; for (ChargeInfo info : brokerData) { exercisedCapacity += exerciseControls(info, candidates, info.getBalanceChargeP2()); } if (log.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("DU static settlement <broker(p2,p1)>:"); for (ChargeInfo info : brokerData) { sb.append(" ").append(info.getBrokerName()).append("("); sb.append(info.getBalanceChargeP2()).append(","); sb.append(info.getBalanceChargeP1()).append(")"); } log.info(sb.toString()); double rmCost = 0.0; for (BOWrapper bo: candidates) { if (bo.isDummy()) { rmCost = bo.exercisedCapacity * bo.getMarginalPrice(bo.exercisedCapacity); } } double brokerCost = 0.0; for (ChargeInfo info : brokerData) { brokerCost += info.getBalanceChargeP1() + info.getBalanceChargeP2(); } log.info("DU budget: rm cost = {}, broker cost = {}, exercised capacity = {}", rmCost, brokerCost, exercisedCapacity); } }
StaticSettlementProcessor extends SettlementProcessor { @Override public void settle (SettlementContext service, List<ChargeInfo> brokerData) { pPlus = service.getPPlus(); pPlusPrime = service.getPPlusPrime(); pMinus = service.getPMinus(); pMinusPrime = service.getPMinusPrime(); double totalImbalance = 0.0; double totalQty = 0.0; for (ChargeInfo info : brokerData) { totalImbalance += info.getNetLoadKWh(); totalQty += Math.abs(info.getNetLoadKWh()); } log.info("totalImbalance=" + totalImbalance); if (Math.abs(totalImbalance) < epsilon) { if (totalQty < epsilon) return; totalImbalance = epsilon / 2.0; } double sgn = Math.signum(totalImbalance); SortedSet<BOWrapper> candidates = findCandidateOrders(brokerData, totalImbalance); ArrayList<BOWrapper> possibles = new ArrayList<BOWrapper> (); possibles.addAll(candidates); for (BOWrapper bo: possibles) { RegulationAccumulator cap = capacityControlService.getRegulationCapacity(bo.balancingOrder); log.info("tariff " + bo.balancingOrder.getTariffId() + ": up=" + cap.getUpRegulationCapacity() + ", down=" + cap.getDownRegulationCapacity()); if (sgn < 0.0) { bo.availableCapacity = cap.getUpRegulationCapacity(); } else { bo.availableCapacity = cap.getDownRegulationCapacity(); } if (Math.abs(bo.availableCapacity) < epsilon) candidates.remove(bo); } insertDummyOrders(candidates, totalImbalance * 2); determineExerciseSet(totalImbalance, candidates); SortedSet<BOWrapper> nonExercised = determineNonExercisedSet(candidates); HashSet<ChargeInfo> nonParticipants = new HashSet<ChargeInfo>(); for (ChargeInfo info: brokerData) { info.setBalanceChargeP2(computeVcgCharges(info, totalImbalance, candidates, nonExercised, nonParticipants)); } computeImbalanceCharges(brokerData, totalImbalance, candidates); double exercisedCapacity = 0.0; for (ChargeInfo info : brokerData) { exercisedCapacity += exerciseControls(info, candidates, info.getBalanceChargeP2()); } if (log.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("DU static settlement <broker(p2,p1)>:"); for (ChargeInfo info : brokerData) { sb.append(" ").append(info.getBrokerName()).append("("); sb.append(info.getBalanceChargeP2()).append(","); sb.append(info.getBalanceChargeP1()).append(")"); } log.info(sb.toString()); double rmCost = 0.0; for (BOWrapper bo: candidates) { if (bo.isDummy()) { rmCost = bo.exercisedCapacity * bo.getMarginalPrice(bo.exercisedCapacity); } } double brokerCost = 0.0; for (ChargeInfo info : brokerData) { brokerCost += info.getBalanceChargeP1() + info.getBalanceChargeP2(); } log.info("DU budget: rm cost = {}, broker cost = {}, exercised capacity = {}", rmCost, brokerCost, exercisedCapacity); } } }
StaticSettlementProcessor extends SettlementProcessor { @Override public void settle (SettlementContext service, List<ChargeInfo> brokerData) { pPlus = service.getPPlus(); pPlusPrime = service.getPPlusPrime(); pMinus = service.getPMinus(); pMinusPrime = service.getPMinusPrime(); double totalImbalance = 0.0; double totalQty = 0.0; for (ChargeInfo info : brokerData) { totalImbalance += info.getNetLoadKWh(); totalQty += Math.abs(info.getNetLoadKWh()); } log.info("totalImbalance=" + totalImbalance); if (Math.abs(totalImbalance) < epsilon) { if (totalQty < epsilon) return; totalImbalance = epsilon / 2.0; } double sgn = Math.signum(totalImbalance); SortedSet<BOWrapper> candidates = findCandidateOrders(brokerData, totalImbalance); ArrayList<BOWrapper> possibles = new ArrayList<BOWrapper> (); possibles.addAll(candidates); for (BOWrapper bo: possibles) { RegulationAccumulator cap = capacityControlService.getRegulationCapacity(bo.balancingOrder); log.info("tariff " + bo.balancingOrder.getTariffId() + ": up=" + cap.getUpRegulationCapacity() + ", down=" + cap.getDownRegulationCapacity()); if (sgn < 0.0) { bo.availableCapacity = cap.getUpRegulationCapacity(); } else { bo.availableCapacity = cap.getDownRegulationCapacity(); } if (Math.abs(bo.availableCapacity) < epsilon) candidates.remove(bo); } insertDummyOrders(candidates, totalImbalance * 2); determineExerciseSet(totalImbalance, candidates); SortedSet<BOWrapper> nonExercised = determineNonExercisedSet(candidates); HashSet<ChargeInfo> nonParticipants = new HashSet<ChargeInfo>(); for (ChargeInfo info: brokerData) { info.setBalanceChargeP2(computeVcgCharges(info, totalImbalance, candidates, nonExercised, nonParticipants)); } computeImbalanceCharges(brokerData, totalImbalance, candidates); double exercisedCapacity = 0.0; for (ChargeInfo info : brokerData) { exercisedCapacity += exerciseControls(info, candidates, info.getBalanceChargeP2()); } if (log.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("DU static settlement <broker(p2,p1)>:"); for (ChargeInfo info : brokerData) { sb.append(" ").append(info.getBrokerName()).append("("); sb.append(info.getBalanceChargeP2()).append(","); sb.append(info.getBalanceChargeP1()).append(")"); } log.info(sb.toString()); double rmCost = 0.0; for (BOWrapper bo: candidates) { if (bo.isDummy()) { rmCost = bo.exercisedCapacity * bo.getMarginalPrice(bo.exercisedCapacity); } } double brokerCost = 0.0; for (ChargeInfo info : brokerData) { brokerCost += info.getBalanceChargeP1() + info.getBalanceChargeP2(); } log.info("DU budget: rm cost = {}, broker cost = {}, exercised capacity = {}", rmCost, brokerCost, exercisedCapacity); } } StaticSettlementProcessor(TariffRepo tariffRepo,
                                    CapacityControl capacityControl); }
StaticSettlementProcessor extends SettlementProcessor { @Override public void settle (SettlementContext service, List<ChargeInfo> brokerData) { pPlus = service.getPPlus(); pPlusPrime = service.getPPlusPrime(); pMinus = service.getPMinus(); pMinusPrime = service.getPMinusPrime(); double totalImbalance = 0.0; double totalQty = 0.0; for (ChargeInfo info : brokerData) { totalImbalance += info.getNetLoadKWh(); totalQty += Math.abs(info.getNetLoadKWh()); } log.info("totalImbalance=" + totalImbalance); if (Math.abs(totalImbalance) < epsilon) { if (totalQty < epsilon) return; totalImbalance = epsilon / 2.0; } double sgn = Math.signum(totalImbalance); SortedSet<BOWrapper> candidates = findCandidateOrders(brokerData, totalImbalance); ArrayList<BOWrapper> possibles = new ArrayList<BOWrapper> (); possibles.addAll(candidates); for (BOWrapper bo: possibles) { RegulationAccumulator cap = capacityControlService.getRegulationCapacity(bo.balancingOrder); log.info("tariff " + bo.balancingOrder.getTariffId() + ": up=" + cap.getUpRegulationCapacity() + ", down=" + cap.getDownRegulationCapacity()); if (sgn < 0.0) { bo.availableCapacity = cap.getUpRegulationCapacity(); } else { bo.availableCapacity = cap.getDownRegulationCapacity(); } if (Math.abs(bo.availableCapacity) < epsilon) candidates.remove(bo); } insertDummyOrders(candidates, totalImbalance * 2); determineExerciseSet(totalImbalance, candidates); SortedSet<BOWrapper> nonExercised = determineNonExercisedSet(candidates); HashSet<ChargeInfo> nonParticipants = new HashSet<ChargeInfo>(); for (ChargeInfo info: brokerData) { info.setBalanceChargeP2(computeVcgCharges(info, totalImbalance, candidates, nonExercised, nonParticipants)); } computeImbalanceCharges(brokerData, totalImbalance, candidates); double exercisedCapacity = 0.0; for (ChargeInfo info : brokerData) { exercisedCapacity += exerciseControls(info, candidates, info.getBalanceChargeP2()); } if (log.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("DU static settlement <broker(p2,p1)>:"); for (ChargeInfo info : brokerData) { sb.append(" ").append(info.getBrokerName()).append("("); sb.append(info.getBalanceChargeP2()).append(","); sb.append(info.getBalanceChargeP1()).append(")"); } log.info(sb.toString()); double rmCost = 0.0; for (BOWrapper bo: candidates) { if (bo.isDummy()) { rmCost = bo.exercisedCapacity * bo.getMarginalPrice(bo.exercisedCapacity); } } double brokerCost = 0.0; for (ChargeInfo info : brokerData) { brokerCost += info.getBalanceChargeP1() + info.getBalanceChargeP2(); } log.info("DU budget: rm cost = {}, broker cost = {}, exercised capacity = {}", rmCost, brokerCost, exercisedCapacity); } } StaticSettlementProcessor(TariffRepo tariffRepo,
                                    CapacityControl capacityControl); @Override void settle(SettlementContext service,
                      List<ChargeInfo> brokerData); }
StaticSettlementProcessor extends SettlementProcessor { @Override public void settle (SettlementContext service, List<ChargeInfo> brokerData) { pPlus = service.getPPlus(); pPlusPrime = service.getPPlusPrime(); pMinus = service.getPMinus(); pMinusPrime = service.getPMinusPrime(); double totalImbalance = 0.0; double totalQty = 0.0; for (ChargeInfo info : brokerData) { totalImbalance += info.getNetLoadKWh(); totalQty += Math.abs(info.getNetLoadKWh()); } log.info("totalImbalance=" + totalImbalance); if (Math.abs(totalImbalance) < epsilon) { if (totalQty < epsilon) return; totalImbalance = epsilon / 2.0; } double sgn = Math.signum(totalImbalance); SortedSet<BOWrapper> candidates = findCandidateOrders(brokerData, totalImbalance); ArrayList<BOWrapper> possibles = new ArrayList<BOWrapper> (); possibles.addAll(candidates); for (BOWrapper bo: possibles) { RegulationAccumulator cap = capacityControlService.getRegulationCapacity(bo.balancingOrder); log.info("tariff " + bo.balancingOrder.getTariffId() + ": up=" + cap.getUpRegulationCapacity() + ", down=" + cap.getDownRegulationCapacity()); if (sgn < 0.0) { bo.availableCapacity = cap.getUpRegulationCapacity(); } else { bo.availableCapacity = cap.getDownRegulationCapacity(); } if (Math.abs(bo.availableCapacity) < epsilon) candidates.remove(bo); } insertDummyOrders(candidates, totalImbalance * 2); determineExerciseSet(totalImbalance, candidates); SortedSet<BOWrapper> nonExercised = determineNonExercisedSet(candidates); HashSet<ChargeInfo> nonParticipants = new HashSet<ChargeInfo>(); for (ChargeInfo info: brokerData) { info.setBalanceChargeP2(computeVcgCharges(info, totalImbalance, candidates, nonExercised, nonParticipants)); } computeImbalanceCharges(brokerData, totalImbalance, candidates); double exercisedCapacity = 0.0; for (ChargeInfo info : brokerData) { exercisedCapacity += exerciseControls(info, candidates, info.getBalanceChargeP2()); } if (log.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("DU static settlement <broker(p2,p1)>:"); for (ChargeInfo info : brokerData) { sb.append(" ").append(info.getBrokerName()).append("("); sb.append(info.getBalanceChargeP2()).append(","); sb.append(info.getBalanceChargeP1()).append(")"); } log.info(sb.toString()); double rmCost = 0.0; for (BOWrapper bo: candidates) { if (bo.isDummy()) { rmCost = bo.exercisedCapacity * bo.getMarginalPrice(bo.exercisedCapacity); } } double brokerCost = 0.0; for (ChargeInfo info : brokerData) { brokerCost += info.getBalanceChargeP1() + info.getBalanceChargeP2(); } log.info("DU budget: rm cost = {}, broker cost = {}, exercised capacity = {}", rmCost, brokerCost, exercisedCapacity); } } StaticSettlementProcessor(TariffRepo tariffRepo,
                                    CapacityControl capacityControl); @Override void settle(SettlementContext service,
                      List<ChargeInfo> brokerData);  }