123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package classes.holonControlUnit;
- import java.util.ArrayList;
- import java.util.List;
- import classes.Holon;
- import classes.holonControlUnit.messages.Message;
- import classes.holonControlUnit.messages.StateMsg;
- import classes.holonControlUnit.messages.StateRequestMsg;
- public class HolonControlUnit {
-
- private Holon holon;
- private FlexibilityManager flexMan;
- private ForecastComputationUnit forecaster;
- private HierarchyControlUnit hierarchyController;
- private OptimizationManager optimizer;
- private StateEstimator stateEstimator;
- private TargetStateAssembler stateAssembler;
- private CommunicationModule communicator;
-
- public HolonControlUnit(Holon h) {
- this.holon = h;
- this.hierarchyController = new HierarchyControlUnit(this);
- this.flexMan = new FlexibilityManager(this);
- this.forecaster = new ForecastComputationUnit(this);
- this.optimizer = new OptimizationManager(this);
- this.stateEstimator = new StateEstimator(this);
- this.stateAssembler = new TargetStateAssembler(this);
- this.communicator = new CommunicationModule(this);
- }
- public ArrayList<Holon> getSubHolon() {
- return this.holon.childHolons;
- }
-
- public void addSubHolon(Holon subHolon) {
- this.hierarchyController.addSubHolon(subHolon.getUniqueID());
- }
-
- public void addNewVirtualNeighbor(String virtualNeighbor) {
- this.hierarchyController.addVirtualNeighbor(virtualNeighbor);
- }
-
- public void addNewVirtualNeighbors(ArrayList<String> virtualNeighbor) {
- this.hierarchyController.addVirtualNeighbors(virtualNeighbor);
- }
- public Holon getHolon() {
- return holon;
- }
- public FlexibilityManager getFlexMan() {
- return flexMan;
- }
- public ForecastComputationUnit getForecaster() {
- return forecaster;
- }
- public HierarchyControlUnit getHierarchyController() {
- return hierarchyController;
- }
- public OptimizationManager getOptimizer() {
- return optimizer;
- }
- public StateEstimator getStateEstimator() {
- return stateEstimator;
- }
- public TargetStateAssembler getStateAssembler() {
- return stateAssembler;
- }
- public CommunicationModule getCommunicator() {
- return communicator;
- }
-
- public void computeState(int timeStep) {
- //compute current state
- this.stateEstimator.computeState(timeStep);
- //compute target state
- this.stateAssembler.assembleTargetState(timeStep);
- //evaluate optimization scheme
- this.optimizer.evaluateOptimizationScheme(timeStep);
- }
- public boolean matchPowerRange(float power, float des, ArrayList<Float> prePower, float threshold) {
- float diff = Math.abs(des - threshold * des);
- float tres = Math.max(10-threshold*10, diff); //otherwise the range could be 0
- if(power > des + tres || power < des - tres)
- return false;
- for(int i=0; i<prePower.size(); i++) {
- if(prePower.get(i) > des + tres || prePower.get(i) < des - tres)
- return false;
- }
- return true;
- }
- public boolean matchPowerRange(float power, float des, float threshold) {
- float diff = Math.abs(des - threshold * des);
- float tres = Math.max(10-threshold*10, diff); //otherwise the range could be 0
- if(power > des + tres || power < des - tres)
- return false;
-
- return true;
- }
- public boolean matchPowerRange(float power, float des) {
- float threshold = this.optimizer.getCurrentPowerThreshold();
- float diff = Math.abs(des - threshold * des);
- float tres = Math.max(10-threshold*10, diff); //otherwise the range could be 0
- if(power > des + tres || power < des - tres)
- return false;
- return true;
- }
-
- @Deprecated
- public boolean decreasesPowerUsage(float requiredPower, float powerUsage, List<Float> predictedPowerUsage) {
- if(Math.abs(powerUsage) > Math.abs(requiredPower))
- return false;
-
- for(int i=0; i<predictedPowerUsage.size(); i++) {
- if(Math.abs(predictedPowerUsage.get(i)) > Math.abs(requiredPower))
- return false;
- }
- return true;
- }
-
- /**
- * checks whether addedPower + currentPower decreases the absolute value of the power usage
- * @param addedPower
- * @param currentPower
- * @param predictedPower
- * @param desiredPower
- * @return
- */
- public boolean decreasesPowerUsage(List<Float> addedPower, float currentPower, List<Float> predictedPower, float desiredPower) {
- // float threshold = this.optimizer.getCurrentPowerThreshold();
- // float diff = Math.abs(desiredPower - threshold * desiredPower);
- // float thres = Math.abs(desiredPower) + Math.max(10-threshold*10, diff); //otherwise the range could be 0
-
- if(Math.abs(currentPower + addedPower.get(0)) > Math.abs(currentPower - desiredPower))
- return false;
- for(int i=1; i<addedPower.size(); i++){
- if(Math.abs(predictedPower.get(i-1) + addedPower.get(i) - desiredPower) > Math.abs(predictedPower.get(i-1) - desiredPower))
- return false;
- }
-
- return true;
- }
- }
|