@Test public void testValidateBatteries () { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("customer.model.liftTruck.instances", "short,long"); map.put("customer.model.liftTruck.short.shiftData", "block,1,2,3,4,5, shift,6,8,8, shift,14,8,6, shift,22,8,4," + "block,6,7, shift,6,8,3, shift,14,8,2"); map.put("customer.model.liftTruck.short.nBatteries", "6"); map.put("customer.model.liftTruck.long.batteryCapacity", "24.0"); map.put("customer.model.liftTruck.long.shiftData", "block,1,2,3,4,5, shift,6,8,5, shift,14,8,3, shift,22,8,7," + "block,6,7, shift,6,8,3, shift,14,8,2"); map.put("customer.model.liftTruck.long.nBatteries", "10"); config = new MapConfiguration(map); Configurator configurator = new Configurator(); configurator.setConfiguration(config); Collection<?> instances = configurator.configureInstances(LiftTruck.class); assertEquals(2, instances.size(), "two instances"); Map<String, LiftTruck> trucks = mapNames(instances); LiftTruck shortTruck = trucks.get("short"); assertEquals(6, shortTruck.getNBatteries(), "short before validation"); shortTruck.validateBatteries(); assertEquals(14, shortTruck.getNBatteries(), "short after validation"); LiftTruck longTruck = trucks.get("long"); assertEquals(10, longTruck.getNBatteries(), "long before validation"); longTruck.validateBatteries(); assertEquals(16, longTruck.getNBatteries(), "long after validation"); }
void validateBatteries () { int minBatteries = 0; Shift s1 = null; Shift s2 = null; for (int i = 0; i < shiftSchedule.length; i++) { Shift s = shiftSchedule[i]; if (null == s) { s1 = s2; } else if (s2 != s) { s1 = s2; s2 = s; if (null != s1) { int n1 = s1.getTrucks(); int d1 = s1.getDuration(); int n2 = s2.getTrucks(); int d2 = s2.getDuration(); double neededBatteries = (n1 * d1 + n2 * d2) * truckKW / getBatteryCapacity(); minBatteries = (int)Math.max(minBatteries, (n1 + n2)); minBatteries = (int)Math.max(minBatteries, Math.ceil(neededBatteries)); } } } int neededBatteries = minBatteries - nBatteries; if (neededBatteries > 0) { log.error("Not enough batteries (" + nBatteries + ") for " + getName()); log.warn("Adding " + neededBatteries + " batteries for " + getName()); setNBatteries(getNBatteries() + neededBatteries); } }
LiftTruck extends AbstractCustomer implements CustomerModelAccessor { void validateBatteries () { int minBatteries = 0; Shift s1 = null; Shift s2 = null; for (int i = 0; i < shiftSchedule.length; i++) { Shift s = shiftSchedule[i]; if (null == s) { s1 = s2; } else if (s2 != s) { s1 = s2; s2 = s; if (null != s1) { int n1 = s1.getTrucks(); int d1 = s1.getDuration(); int n2 = s2.getTrucks(); int d2 = s2.getDuration(); double neededBatteries = (n1 * d1 + n2 * d2) * truckKW / getBatteryCapacity(); minBatteries = (int)Math.max(minBatteries, (n1 + n2)); minBatteries = (int)Math.max(minBatteries, Math.ceil(neededBatteries)); } } } int neededBatteries = minBatteries - nBatteries; if (neededBatteries > 0) { log.error("Not enough batteries (" + nBatteries + ") for " + getName()); log.warn("Adding " + neededBatteries + " batteries for " + getName()); setNBatteries(getNBatteries() + neededBatteries); } } }
LiftTruck extends AbstractCustomer implements CustomerModelAccessor { void validateBatteries () { int minBatteries = 0; Shift s1 = null; Shift s2 = null; for (int i = 0; i < shiftSchedule.length; i++) { Shift s = shiftSchedule[i]; if (null == s) { s1 = s2; } else if (s2 != s) { s1 = s2; s2 = s; if (null != s1) { int n1 = s1.getTrucks(); int d1 = s1.getDuration(); int n2 = s2.getTrucks(); int d2 = s2.getDuration(); double neededBatteries = (n1 * d1 + n2 * d2) * truckKW / getBatteryCapacity(); minBatteries = (int)Math.max(minBatteries, (n1 + n2)); minBatteries = (int)Math.max(minBatteries, Math.ceil(neededBatteries)); } } } int neededBatteries = minBatteries - nBatteries; if (neededBatteries > 0) { log.error("Not enough batteries (" + nBatteries + ") for " + getName()); log.warn("Adding " + neededBatteries + " batteries for " + getName()); setNBatteries(getNBatteries() + neededBatteries); } } LiftTruck();  LiftTruck(String name); }
LiftTruck extends AbstractCustomer implements CustomerModelAccessor { void validateBatteries () { int minBatteries = 0; Shift s1 = null; Shift s2 = null; for (int i = 0; i < shiftSchedule.length; i++) { Shift s = shiftSchedule[i]; if (null == s) { s1 = s2; } else if (s2 != s) { s1 = s2; s2 = s; if (null != s1) { int n1 = s1.getTrucks(); int d1 = s1.getDuration(); int n2 = s2.getTrucks(); int d2 = s2.getDuration(); double neededBatteries = (n1 * d1 + n2 * d2) * truckKW / getBatteryCapacity(); minBatteries = (int)Math.max(minBatteries, (n1 + n2)); minBatteries = (int)Math.max(minBatteries, Math.ceil(neededBatteries)); } } } int neededBatteries = minBatteries - nBatteries; if (neededBatteries > 0) { log.error("Not enough batteries (" + nBatteries + ") for " + getName()); log.warn("Adding " + neededBatteries + " batteries for " + getName()); setNBatteries(getNBatteries() + neededBatteries); } } LiftTruck();  LiftTruck(String name); @Override void initialize(); @Override CustomerInfo getCustomerInfo(); @Override void step(); @Override String getName(); @Override void setName(String name); @ConfigurableValue(valueType = "Double", dump = false, description = "mean power usage when truck is in use") @StateChange void setTruckKW(double value); double getTruckKW(); @ConfigurableValue(valueType = "Double", dump = false, description = "Std dev of truck power usage") @StateChange void setTruckStd(double stdDev); double getTruckStd(); @ConfigurableValue(valueType = "List", dump = false, description = "shift spec [block, shift, ..., block, shift, ...]") void setShiftData(List<String> data); List<String> getShiftData(); @ConfigurableValue(valueType = "Double", dump = false, description = "size of battery pack in kWh") @StateChange void setBatteryCapacity(double value); double getBatteryCapacity(); @ConfigurableValue(valueType = "Integer", dump = false, description = "total number of battery packs") @StateChange void setNBatteries(int value); int getNBatteries(); @ConfigurableValue(valueType = "Integer", dump = false, description = "number of battery chargers") @StateChange void setNChargers(int value); int getNChargers(); @ConfigurableValue(valueType = "Double", dump = false, description = "maximum charge rate of one truck's battery pack") @StateChange void setMaxChargeKW(double value); double getMaxChargeKW(); @ConfigurableValue(valueType = "Double", dump = false, description = "ratio of charge energy to battery energy") @StateChange void setChargeEfficiency(double value); double getChargeEfficiency(); @ConfigurableValue(valueType = "Integer", dump = false, description = "planning horizon in timeslots - should be at least 48") @StateChange void setPlanningHorizon(int horizon); int getPlanningHorizon(); @ConfigurableValue(valueType = "Integer", dump = false, description = "minimum useful horizon of existing plan") @StateChange void setMinPlanningHorizon(int horizon); int getMinPlanningHorizon(); @StateChange void setEnergyCharging(double kwh); double getEnergyCharging(); void addEnergyCharging(double kwh); @StateChange void setEnergyInUse(double kwh); double getEnergyInUse(); void addEnergyInUse(double kwh); @StateChange void setCapacityInUse(double kwh); double getCapacityInUse(); @Override CapacityProfile getCapacityProfile(Tariff tariff); @Override double getBrokerSwitchFactor(boolean isSuperseding); @Override double getTariffChoiceSample(); @Override double getInertiaSample(); @Override void evaluateTariffs(List<Tariff> tariffs); @Override double getShiftingInconvenienceFactor(Tariff tariff); }
LiftTruck extends AbstractCustomer implements CustomerModelAccessor { void validateBatteries () { int minBatteries = 0; Shift s1 = null; Shift s2 = null; for (int i = 0; i < shiftSchedule.length; i++) { Shift s = shiftSchedule[i]; if (null == s) { s1 = s2; } else if (s2 != s) { s1 = s2; s2 = s; if (null != s1) { int n1 = s1.getTrucks(); int d1 = s1.getDuration(); int n2 = s2.getTrucks(); int d2 = s2.getDuration(); double neededBatteries = (n1 * d1 + n2 * d2) * truckKW / getBatteryCapacity(); minBatteries = (int)Math.max(minBatteries, (n1 + n2)); minBatteries = (int)Math.max(minBatteries, Math.ceil(neededBatteries)); } } } int neededBatteries = minBatteries - nBatteries; if (neededBatteries > 0) { log.error("Not enough batteries (" + nBatteries + ") for " + getName()); log.warn("Adding " + neededBatteries + " batteries for " + getName()); setNBatteries(getNBatteries() + neededBatteries); } } LiftTruck();  LiftTruck(String name); @Override void initialize(); @Override CustomerInfo getCustomerInfo(); @Override void step(); @Override String getName(); @Override void setName(String name); @ConfigurableValue(valueType = "Double", dump = false, description = "mean power usage when truck is in use") @StateChange void setTruckKW(double value); double getTruckKW(); @ConfigurableValue(valueType = "Double", dump = false, description = "Std dev of truck power usage") @StateChange void setTruckStd(double stdDev); double getTruckStd(); @ConfigurableValue(valueType = "List", dump = false, description = "shift spec [block, shift, ..., block, shift, ...]") void setShiftData(List<String> data); List<String> getShiftData(); @ConfigurableValue(valueType = "Double", dump = false, description = "size of battery pack in kWh") @StateChange void setBatteryCapacity(double value); double getBatteryCapacity(); @ConfigurableValue(valueType = "Integer", dump = false, description = "total number of battery packs") @StateChange void setNBatteries(int value); int getNBatteries(); @ConfigurableValue(valueType = "Integer", dump = false, description = "number of battery chargers") @StateChange void setNChargers(int value); int getNChargers(); @ConfigurableValue(valueType = "Double", dump = false, description = "maximum charge rate of one truck's battery pack") @StateChange void setMaxChargeKW(double value); double getMaxChargeKW(); @ConfigurableValue(valueType = "Double", dump = false, description = "ratio of charge energy to battery energy") @StateChange void setChargeEfficiency(double value); double getChargeEfficiency(); @ConfigurableValue(valueType = "Integer", dump = false, description = "planning horizon in timeslots - should be at least 48") @StateChange void setPlanningHorizon(int horizon); int getPlanningHorizon(); @ConfigurableValue(valueType = "Integer", dump = false, description = "minimum useful horizon of existing plan") @StateChange void setMinPlanningHorizon(int horizon); int getMinPlanningHorizon(); @StateChange void setEnergyCharging(double kwh); double getEnergyCharging(); void addEnergyCharging(double kwh); @StateChange void setEnergyInUse(double kwh); double getEnergyInUse(); void addEnergyInUse(double kwh); @StateChange void setCapacityInUse(double kwh); double getCapacityInUse(); @Override CapacityProfile getCapacityProfile(Tariff tariff); @Override double getBrokerSwitchFactor(boolean isSuperseding); @Override double getTariffChoiceSample(); @Override double getInertiaSample(); @Override void evaluateTariffs(List<Tariff> tariffs); @Override double getShiftingInconvenienceFactor(Tariff tariff);  }