package psoAlgoCode; import java.util.Vector; import classes.AbstractCpsObject; import classes.HolonElement; import classes.HolonObject; import ui.controller.Control; import ui.model.Model; public class SGFunctions { private Model model; private Control control; private Particle p; public SGFunctions(Particle p, Model model, Control control) { this.p = p; this.model = model; this.control = control; } public void implementState() { Coordinate> pos = p.getPositionAdv(); // Set states of the HolonSwitches depending on the pos of the swarm (dim=0) for (int i = 0; i < pos.getCoord(0).size(); i++) { model.getSwitches().get(i).setManualMode(true); model.getSwitches().get(i).setManualState((boolean) pos.getCoord(0).get(i)); } int position = 0; for (int j = 0; j < model.getObjectsOnCanvas().size(); j++) { if (model.getObjectsOnCanvas().get(j) instanceof HolonObject) { for (int h = 0; h < ((HolonObject) model.getObjectsOnCanvas().get(j)).getElements().size(); h++) { ((HolonObject) model.getObjectsOnCanvas().get(j)).getElements().get(h) .setActive((boolean) pos.getCoord(1).get(position)); position++; } } } } public double calcValuewithSliderState() { implementState(); HelpFunctions.calculateStateForTimeStepPSO(model, control); double value = 0.0; for (AbstractCpsObject obj : model.getObjectsOnCanvas()) { if (obj instanceof HolonObject) { int state = ((HolonObject) obj).getState(); double suppliedPerc = ((HolonObject) obj).getSuppliedPercentage(); double elementsActive = (double) elementsActive((HolonObject) obj); double totalElements = (double) ((HolonObject) obj).getElements().size(); double difference = Math.abs(1.0 - suppliedPerc) * 100; double differenceEle = (1.0 - (elementsActive / totalElements)) * 100; // Supply States (see HolonObject class for more informations) switch (state) { case 0: value += (100 * 8); break; case 1: value += difference * 4 + differenceEle; break; case 2: value += difference + differenceEle; break; case 4: value += difference + differenceEle; break; case 5: value += difference * 2 + differenceEle; break; default: break; } } } return value; } // Check the amount of HolonElements that are active private int elementsActive(HolonObject obj) { int counter = 0; for (HolonElement ele : obj.getElements()) { if (ele.isActive()) { counter++; } } return counter; } }