@Test public void ex1_down () { BalancingOrder bo1 = new BalancingOrder(b1, spec1, -0.6, -0.03); tariffRepo.addBalancingOrder(bo1); when(capacityControlService.getRegulationCapacity(bo1)). thenReturn(new RegulationAccumulator(1.2, -3.5)); BalancingOrder bo2 = new BalancingOrder(b3, spec3, -0.6, -0.042); tariffRepo.addBalancingOrder(bo2); when(capacityControlService.getRegulationCapacity(bo2)). thenReturn(new RegulationAccumulator(0.5, -2.0)); BalancingOrder bo3 = new BalancingOrder(b2, spec2, -0.6, -0.051); tariffRepo.addBalancingOrder(bo3); when(capacityControlService.getRegulationCapacity(bo3)). thenReturn(new RegulationAccumulator(12.1, -6.7)); BalancingOrder bo4 = new BalancingOrder(b3, spec3, -0.6, -0.062); tariffRepo.addBalancingOrder(bo4); when(capacityControlService.getRegulationCapacity(bo4)). thenReturn(new RegulationAccumulator(6.2, -3.9)); BalancingOrder bo5 = new BalancingOrder(b2, spec2, -0.6, -0.08); tariffRepo.addBalancingOrder(bo5); when(capacityControlService.getRegulationCapacity(bo5)). thenReturn(new RegulationAccumulator(0.1, -3.0)); BalancingOrder bo6 = new BalancingOrder(b1, spec1, -0.6, -0.091); tariffRepo.addBalancingOrder(bo6); when(capacityControlService.getRegulationCapacity(bo6)). thenReturn(new RegulationAccumulator(6.2, -5.4)); BalancingOrder bo6d = new BalancingOrder(b1, spec1, 0.6, 0.091); tariffRepo.addBalancingOrder(bo6d); when(capacityControlService.getRegulationCapacity(bo6d)). thenReturn(new RegulationAccumulator(6.2, -5.4)); ChargeInfo ci1 = new ChargeInfo(b1, 0); ci1.addBalancingOrder(bo1); ci1.addBalancingOrder(bo6); brokerData.add(ci1); ChargeInfo ci2 = new ChargeInfo(b2, -4); ci2.addBalancingOrder(bo3); ci2.addBalancingOrder(bo5); brokerData.add(ci2); ChargeInfo ci3 = new ChargeInfo(b3, 8); ci3.addBalancingOrder(bo2); ci3.addBalancingOrder(bo4); brokerData.add(ci3); ChargeInfo ci4 = new ChargeInfo(b4, 14); brokerData.add(ci4); pplus = 0.1; pplusPrime = 0.0; pminus = -0.029; pminusPrime = 0.0; uut.settle(context, brokerData); assertEquals(-0.2046, ci1.getBalanceChargeP2(), 1e-6, "b1.p2 = -0.2046"); assertEquals(-0.2818, ci2.getBalanceChargeP2(), 1e-6, "b2.p2 = -0.2818"); assertEquals(-0.138, ci3.getBalanceChargeP2(), 1e-6, "b3.p2 = -0.138"); assertEquals( 0.0, ci4.getBalanceChargeP2(), 1e-6, "b4.p2 = 0"); assertEquals(-5.4, ci1.getCurtailment(), 1e-6, "b1.ex = -5.4"); assertEquals(-8.7, ci2.getCurtailment(), 1e-6, "b2.ex = -8.7"); assertEquals(-3.9, ci3.getCurtailment(), 1e-6, "b3.ex = -3.9"); assertEquals(0.0, ci4.getCurtailment(), 1e-6, "b4.ex = 0.0"); assertEquals(0.0, ci1.getBalanceChargeP1(), 1e-4, "b1.p1 = 0"); assertEquals(0.07476, ci2.getBalanceChargeP1(), 1e-4, "b2.p1 = 0.116"); assertEquals(0.0025778, ci3.getBalanceChargeP1(), 1e-4, "b3.p1 = -0.232"); assertEquals(-0.26164, ci4.getBalanceChargeP1(), 1e-4, "b4.p1 = -0.406"); }
@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);  }