|
@@ -14,7 +14,7 @@ import ui.model.Model;
|
|
import ui.view.MyCanvas;
|
|
import ui.view.MyCanvas;
|
|
|
|
|
|
public class SimulationManager {
|
|
public class SimulationManager {
|
|
- private Model model;
|
|
|
|
|
|
+ private Model model;cpsobjec
|
|
private ArrayList<AbstractCpsObject> objectsToHandle;
|
|
private ArrayList<AbstractCpsObject> objectsToHandle;
|
|
private ArrayList<CpsEdge> allConnections;
|
|
private ArrayList<CpsEdge> allConnections;
|
|
private ArrayList<subNet> subNets;
|
|
private ArrayList<subNet> subNets;
|
|
@@ -22,54 +22,55 @@ public class SimulationManager {
|
|
private int timeStep;
|
|
private int timeStep;
|
|
private boolean simMode;
|
|
private boolean simMode;
|
|
private HashMap<Integer, Float> tagTable = new HashMap<Integer, Float>();
|
|
private HashMap<Integer, Float> tagTable = new HashMap<Integer, Float>();
|
|
-
|
|
|
|
- public SimulationManager(Model m){
|
|
|
|
|
|
+
|
|
|
|
+ public SimulationManager(Model m) {
|
|
canvas = null;
|
|
canvas = null;
|
|
model = m;
|
|
model = m;
|
|
subNets = new ArrayList<subNet>();
|
|
subNets = new ArrayList<subNet>();
|
|
simMode = model.getIsSimulation();
|
|
simMode = model.getIsSimulation();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* calculates the flow of the edges and the supply for objects
|
|
* calculates the flow of the edges and the supply for objects
|
|
|
|
+ *
|
|
* @param x
|
|
* @param x
|
|
*/
|
|
*/
|
|
- public void calculateStateForTimeStep(int x){
|
|
|
|
|
|
+ public void calculateStateForTimeStep(int x) {
|
|
simMode = model.getIsSimulation();
|
|
simMode = model.getIsSimulation();
|
|
timeStep = x;
|
|
timeStep = x;
|
|
searchForSubNets();
|
|
searchForSubNets();
|
|
- for(subNet singleSubNet: subNets){
|
|
|
|
|
|
+ for (subNet singleSubNet : subNets) {
|
|
ResetConnections(singleSubNet.getObjects().get(0), new ArrayList<Integer>(), new ArrayList<CpsEdge>());
|
|
ResetConnections(singleSubNet.getObjects().get(0), new ArrayList<Integer>(), new ArrayList<CpsEdge>());
|
|
}
|
|
}
|
|
- for(subNet singleSubNet: subNets){
|
|
|
|
|
|
+ for (subNet singleSubNet : subNets) {
|
|
float production = calculateEnergy("prod", singleSubNet, timeStep);
|
|
float production = calculateEnergy("prod", singleSubNet, timeStep);
|
|
float consumption = calculateEnergy("cons", singleSubNet, timeStep);
|
|
float consumption = calculateEnergy("cons", singleSubNet, timeStep);
|
|
- float minConsumption = calculateMinimumEnergy( singleSubNet, timeStep);
|
|
|
|
|
|
+ float minConsumption = calculateMinimumEnergy(singleSubNet, timeStep);
|
|
setFlow(singleSubNet, simMode);
|
|
setFlow(singleSubNet, simMode);
|
|
- for(HolonObject hl: singleSubNet.getObjects()){
|
|
|
|
- if(!(hl.getState() == 0) && !(hl.getState() == 3)){
|
|
|
|
- for(int i = 0; i < hl.getConnections().size(); i++){
|
|
|
|
|
|
+ for (HolonObject hl : singleSubNet.getObjects()) {
|
|
|
|
+ if (!(hl.getState() == 0) && !(hl.getState() == 3)) {
|
|
|
|
+ for (int i = 0; i < hl.getConnections().size(); i++) {
|
|
CpsEdge edge = hl.getConnectedTo().get(i);
|
|
CpsEdge edge = hl.getConnectedTo().get(i);
|
|
- if(edge.getState() && edge.getFlow() > 0 || edge.getCapacity() == -1){
|
|
|
|
- // 0 = no energy, 1 = not supplied, 2 = supplied, 3 = producer, 4 = partially supplied
|
|
|
|
- if((production + consumption) >= 0){
|
|
|
|
|
|
+ if (edge.getState() && edge.getFlow() > 0 || edge.getCapacity() == -1) {
|
|
|
|
+ // 0 = no energy, 1 = not supplied, 2 = supplied, 3
|
|
|
|
+ // = producer, 4 = partially supplied
|
|
|
|
+ if ((production + consumption) >= 0) {
|
|
hl.setState(2);
|
|
hl.setState(2);
|
|
}
|
|
}
|
|
- if((production + consumption) < 0 ){
|
|
|
|
- if((production + minConsumption) >= 0){
|
|
|
|
|
|
+ if ((production + consumption) < 0) {
|
|
|
|
+ if ((production + minConsumption) >= 0) {
|
|
hl.setState(4);
|
|
hl.setState(4);
|
|
- }else if(hl.checkIfPartiallySupplied(timeStep)){
|
|
|
|
|
|
+ } else if (hl.checkIfPartiallySupplied(timeStep)) {
|
|
hl.setState(4);
|
|
hl.setState(4);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
hl.setState(1);
|
|
hl.setState(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- hl.setState(1);
|
|
|
|
|
|
+ hl.setState(1);
|
|
}
|
|
}
|
|
- if(hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)){
|
|
|
|
|
|
+ if (hl.checkIfPartiallySupplied(timeStep) && !(hl.getState() == 2)) {
|
|
hl.setState(4);
|
|
hl.setState(4);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -77,50 +78,50 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
canvas.repaint();
|
|
canvas.repaint();
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setFlow(subNet sN, boolean simulation){
|
|
|
|
- if(simulation){
|
|
|
|
|
|
+
|
|
|
|
+ public void setFlow(subNet sN, boolean simulation) {
|
|
|
|
+ if (simulation) {
|
|
setFlowSimulation(sN);
|
|
setFlowSimulation(sN);
|
|
} else {
|
|
} else {
|
|
setFlowModelation(sN);
|
|
setFlowModelation(sN);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setFlowModelation(subNet sN){
|
|
|
|
- for(HolonObject hl: sN.getObjects()){
|
|
|
|
|
|
+
|
|
|
|
+ public void setFlowModelation(subNet sN) {
|
|
|
|
+ for (HolonObject hl : sN.getObjects()) {
|
|
float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
|
|
float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
|
|
- if(energy > 0){
|
|
|
|
- for(CpsEdge e : sN.getEdges()){
|
|
|
|
|
|
+ if (energy > 0) {
|
|
|
|
+ for (CpsEdge e : sN.getEdges()) {
|
|
e.setFlow(e.getFlow() + energy);
|
|
e.setFlow(e.getFlow() + energy);
|
|
e.calculateState(simMode);
|
|
e.calculateState(simMode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setFlowSimulation(subNet sN){
|
|
|
|
|
|
+
|
|
|
|
+ public void setFlowSimulation(subNet sN) {
|
|
ArrayList<AbstractCpsObject> producers = new ArrayList<AbstractCpsObject>();
|
|
ArrayList<AbstractCpsObject> producers = new ArrayList<AbstractCpsObject>();
|
|
AbstractCpsObject tmp = null;
|
|
AbstractCpsObject tmp = null;
|
|
tagTable = new HashMap<Integer, Float>();
|
|
tagTable = new HashMap<Integer, Float>();
|
|
- for(HolonObject hl: sN.getObjects()){
|
|
|
|
|
|
+ for (HolonObject hl : sN.getObjects()) {
|
|
float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
|
|
float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
|
|
- if(energy > 0){
|
|
|
|
|
|
+ if (energy > 0) {
|
|
tagTable.put(hl.getID(), energy);
|
|
tagTable.put(hl.getID(), energy);
|
|
hl.addTag(hl.getID());
|
|
hl.addTag(hl.getID());
|
|
- for(CpsEdge edge: hl.getConnections()){
|
|
|
|
- if(edge.getState()){
|
|
|
|
- if(edge.getA().getID() == hl.getID()){
|
|
|
|
|
|
+ for (CpsEdge edge : hl.getConnections()) {
|
|
|
|
+ if (edge.getState()) {
|
|
|
|
+ if (edge.getA().getID() == hl.getID()) {
|
|
edge.getB().addTag(hl.getID());
|
|
edge.getB().addTag(hl.getID());
|
|
tmp = edge.getB();
|
|
tmp = edge.getB();
|
|
}
|
|
}
|
|
- if(edge.getB().getID() == hl.getID()){
|
|
|
|
|
|
+ if (edge.getB().getID() == hl.getID()) {
|
|
edge.getA().addTag(hl.getID());
|
|
edge.getA().addTag(hl.getID());
|
|
tmp = edge.getA();
|
|
tmp = edge.getA();
|
|
}
|
|
}
|
|
edge.setFlow(edge.getFlow() + energy);
|
|
edge.setFlow(edge.getFlow() + energy);
|
|
edge.calculateState(true);
|
|
edge.calculateState(true);
|
|
edge.addTag(hl.getID());
|
|
edge.addTag(hl.getID());
|
|
- if(edge.getState() && !producers.contains(tmp)){
|
|
|
|
|
|
+ if (edge.getState() && !producers.contains(tmp)) {
|
|
producers.add(tmp);
|
|
producers.add(tmp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -129,157 +130,151 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
setFlowSimRec(producers, 0);
|
|
setFlowSimRec(producers, 0);
|
|
}
|
|
}
|
|
-
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
- public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes){
|
|
|
|
|
|
+
|
|
|
|
+ public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
|
|
ArrayList<AbstractCpsObject> newNodes = new ArrayList<AbstractCpsObject>();
|
|
ArrayList<AbstractCpsObject> newNodes = new ArrayList<AbstractCpsObject>();
|
|
- AbstractCpsObject tmp = null;
|
|
|
|
-=======
|
|
|
|
- public void setFlowSimRec(ArrayList<CpsObject> nodes, int iter){
|
|
|
|
- ArrayList<CpsObject> newNodes = new ArrayList<CpsObject>();
|
|
|
|
ArrayList<Integer> pseudoTags = new ArrayList<Integer>();
|
|
ArrayList<Integer> pseudoTags = new ArrayList<Integer>();
|
|
- CpsObject tmp = null;
|
|
|
|
->>>>>>> branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons.git
|
|
|
|
- if(nodes.size() != 0){
|
|
|
|
- for(AbstractCpsObject cps: nodes){
|
|
|
|
- for(CpsEdge edge: cps.getConnections()){
|
|
|
|
- for(Integer tag: cps.getTag()){
|
|
|
|
- if(edge.getState() && !(edge.getTags().contains(tag))){
|
|
|
|
|
|
+ AbstractCpsObject tmp = null;
|
|
|
|
+ if (nodes.size() != 0) {
|
|
|
|
+ for (AbstractCpsObject cps : nodes) {
|
|
|
|
+ for (CpsEdge edge : cps.getConnections()) {
|
|
|
|
+ for (Integer tag : cps.getTag()) {
|
|
|
|
+ if (edge.getState() && !(edge.getTags().contains(tag))) {
|
|
edge.setFlow(edge.getFlow() + tagTable.get(tag));
|
|
edge.setFlow(edge.getFlow() + tagTable.get(tag));
|
|
edge.calculateState(true);
|
|
edge.calculateState(true);
|
|
edge.addTag(tag);
|
|
edge.addTag(tag);
|
|
- if(edge.getA().getID() == cps.getID()){
|
|
|
|
|
|
+ if (edge.getA().getID() == cps.getID()) {
|
|
tmp = edge.getB();
|
|
tmp = edge.getB();
|
|
}
|
|
}
|
|
- if(edge.getB().getID() == cps.getID()){
|
|
|
|
|
|
+ if (edge.getB().getID() == cps.getID()) {
|
|
tmp = edge.getA();
|
|
tmp = edge.getA();
|
|
}
|
|
}
|
|
- if(tmp.getPseudoTags() != null){
|
|
|
|
|
|
+ if (tmp.getPseudoTags() != null) {
|
|
pseudoTags.addAll(tmp.getPseudoTags());
|
|
pseudoTags.addAll(tmp.getPseudoTags());
|
|
}
|
|
}
|
|
pseudoTags.addAll(cps.getTag());
|
|
pseudoTags.addAll(cps.getTag());
|
|
tmp.setPseudoTags(mergeLists(tmp.getTag(), pseudoTags));
|
|
tmp.setPseudoTags(mergeLists(tmp.getTag(), pseudoTags));
|
|
- if(!edge.getState()){
|
|
|
|
|
|
+ if (!edge.getState()) {
|
|
newNodes.remove(edge.getA());
|
|
newNodes.remove(edge.getA());
|
|
newNodes.remove(edge.getB());
|
|
newNodes.remove(edge.getB());
|
|
- if(edge.getA().getID() == cps.getID()){
|
|
|
|
|
|
+ if (edge.getA().getID() == cps.getID()) {
|
|
edge.getB().getPseudoTags().removeAll(edge.getTags());
|
|
edge.getB().getPseudoTags().removeAll(edge.getTags());
|
|
|
|
|
|
}
|
|
}
|
|
- if(edge.getB().getID() == cps.getID()){
|
|
|
|
|
|
+ if (edge.getB().getID() == cps.getID()) {
|
|
edge.getA().getPseudoTags().removeAll(edge.getTags());
|
|
edge.getA().getPseudoTags().removeAll(edge.getTags());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(edge.getState() && !(newNodes.contains(tmp))){
|
|
|
|
|
|
+ if (edge.getState() && !(newNodes.contains(tmp))) {
|
|
newNodes.add(tmp);
|
|
newNodes.add(tmp);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- edge.calculateState(true);
|
|
|
|
|
|
+ edge.calculateState(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //printNodes(newNodes);
|
|
|
|
|
|
+ // printNodes(newNodes);
|
|
setPseudoTags(newNodes);
|
|
setPseudoTags(newNodes);
|
|
setFlowSimRec(newNodes, iter + 1);
|
|
setFlowSimRec(newNodes, iter + 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
- public String getString(AbstractCpsObject cps){
|
|
|
|
-=======
|
|
|
|
- public void setPseudoTags(ArrayList<CpsObject> nodes){
|
|
|
|
- for(CpsObject node: nodes){
|
|
|
|
|
|
+
|
|
|
|
+ public void setPseudoTags(ArrayList<AbstractCpsObject> nodes) {
|
|
|
|
+ for (AbstractCpsObject node : nodes) {
|
|
node.setTags(node.getPseudoTags());
|
|
node.setTags(node.getPseudoTags());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public void printNodes(ArrayList<CpsObject> nodes){
|
|
|
|
|
|
+
|
|
|
|
+ public void printNodes(ArrayList<AbstractCpsObject> nodes) {
|
|
System.out.println("new Nodes:");
|
|
System.out.println("new Nodes:");
|
|
- for(CpsObject node: nodes){
|
|
|
|
|
|
+ for (AbstractCpsObject node : nodes) {
|
|
System.out.println(node.getID());
|
|
System.out.println(node.getID());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public String getString(ArrayList<Integer> tags){
|
|
|
|
->>>>>>> branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons.git
|
|
|
|
|
|
+
|
|
|
|
+ public String getString(ArrayList<Integer> tags) {
|
|
String result = "";
|
|
String result = "";
|
|
- for(Integer i: tags){
|
|
|
|
|
|
+ for (Integer i : tags) {
|
|
result = result + ", " + i;
|
|
result = result + ", " + i;
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public ArrayList<Integer> mergeLists(ArrayList<Integer> A, ArrayList<Integer> B){
|
|
|
|
|
|
+
|
|
|
|
+ public ArrayList<Integer> mergeLists(ArrayList<Integer> A, ArrayList<Integer> B) {
|
|
ArrayList<Integer> result = new ArrayList<Integer>();
|
|
ArrayList<Integer> result = new ArrayList<Integer>();
|
|
- for(Integer i: A){
|
|
|
|
- if(!(result.contains(i))){
|
|
|
|
|
|
+ for (Integer i : A) {
|
|
|
|
+ if (!(result.contains(i))) {
|
|
result.add(i);
|
|
result.add(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- for(Integer j: B){
|
|
|
|
- if(!(result.contains(j))){
|
|
|
|
|
|
+ for (Integer j : B) {
|
|
|
|
+ if (!(result.contains(j))) {
|
|
result.add(j);
|
|
result.add(j);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void ResetConnections(AbstractCpsObject cps, ArrayList<Integer> visitedObj, ArrayList<CpsEdge> visitedEdges){
|
|
|
|
|
|
+
|
|
|
|
+ public void ResetConnections(AbstractCpsObject cps, ArrayList<Integer> visitedObj,
|
|
|
|
+ ArrayList<CpsEdge> visitedEdges) {
|
|
visitedObj.add(cps.getID());
|
|
visitedObj.add(cps.getID());
|
|
cps.resetTags();
|
|
cps.resetTags();
|
|
- for(CpsEdge e: cps.getConnections()){
|
|
|
|
- if(!(visitedEdges.contains(e))){
|
|
|
|
|
|
+ for (CpsEdge e : cps.getConnections()) {
|
|
|
|
+ if (!(visitedEdges.contains(e))) {
|
|
e.setFlow(0);
|
|
e.setFlow(0);
|
|
e.calculateState(simMode);
|
|
e.calculateState(simMode);
|
|
e.setTags(new ArrayList<Integer>());
|
|
e.setTags(new ArrayList<Integer>());
|
|
visitedEdges.add(e);
|
|
visitedEdges.add(e);
|
|
- if(!(visitedObj.contains(e.getA().getID()))){
|
|
|
|
|
|
+ if (!(visitedObj.contains(e.getA().getID()))) {
|
|
ResetConnections(e.getA(), visitedObj, visitedEdges);
|
|
ResetConnections(e.getA(), visitedObj, visitedEdges);
|
|
e.getA().resetTags();
|
|
e.getA().resetTags();
|
|
}
|
|
}
|
|
- if(!(visitedObj.contains(e.getB().getID()))){
|
|
|
|
|
|
+ if (!(visitedObj.contains(e.getB().getID()))) {
|
|
ResetConnections(e.getB(), visitedObj, visitedEdges);
|
|
ResetConnections(e.getB(), visitedObj, visitedEdges);
|
|
e.getB().resetTags();
|
|
e.getB().resetTags();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* calculates the energy of either all producers or consumers
|
|
* calculates the energy of either all producers or consumers
|
|
|
|
+ *
|
|
* @param type
|
|
* @param type
|
|
* @param sN
|
|
* @param sN
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public float calculateEnergy(String type, subNet sN, int x){
|
|
|
|
|
|
+ public float calculateEnergy(String type, subNet sN, int x) {
|
|
float energy = 0;
|
|
float energy = 0;
|
|
- for(HolonObject hl: sN.getObjects()){
|
|
|
|
- if(type.equals("prod")){
|
|
|
|
- if(hl.getCurrentEnergyAtTimeStep(x) > 0){
|
|
|
|
|
|
+ for (HolonObject hl : sN.getObjects()) {
|
|
|
|
+ if (type.equals("prod")) {
|
|
|
|
+ if (hl.getCurrentEnergyAtTimeStep(x) > 0) {
|
|
energy = energy + hl.getCurrentEnergyAtTimeStep(x);
|
|
energy = energy + hl.getCurrentEnergyAtTimeStep(x);
|
|
hl.setState(3);
|
|
hl.setState(3);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(type.equals("cons")){
|
|
|
|
- if(hl.getCurrentEnergyAtTimeStep(x) < 0){
|
|
|
|
|
|
+ if (type.equals("cons")) {
|
|
|
|
+ if (hl.getCurrentEnergyAtTimeStep(x) < 0) {
|
|
energy = energy + hl.getCurrentEnergyAtTimeStep(x);
|
|
energy = energy + hl.getCurrentEnergyAtTimeStep(x);
|
|
hl.setState(1);
|
|
hl.setState(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(hl.getCurrentEnergyAtTimeStep(x) == 0){
|
|
|
|
|
|
+ if (hl.getCurrentEnergyAtTimeStep(x) == 0) {
|
|
hl.setState(0);
|
|
hl.setState(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return energy;
|
|
return energy;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public float calculateMinimumEnergy(subNet sN, int x){
|
|
|
|
|
|
+
|
|
|
|
+ public float calculateMinimumEnergy(subNet sN, int x) {
|
|
float min = 0;
|
|
float min = 0;
|
|
float minElement = 0;
|
|
float minElement = 0;
|
|
- for(HolonObject hl: sN.getObjects()){
|
|
|
|
- if(hl.getElements().size() > 0 && hl.getElements().get(0).getTotalEnergyAtTimeStep(x) < 0 ){
|
|
|
|
|
|
+ for (HolonObject hl : sN.getObjects()) {
|
|
|
|
+ if (hl.getElements().size() > 0 && hl.getElements().get(0).getTotalEnergyAtTimeStep(x) < 0) {
|
|
minElement = hl.getElements().get(0).getTotalEnergyAtTimeStep(x);
|
|
minElement = hl.getElements().get(0).getTotalEnergyAtTimeStep(x);
|
|
}
|
|
}
|
|
- for(HolonElement he: hl.getElements()){
|
|
|
|
- if(minElement < he.getTotalEnergyAtTimeStep(x) && he.getTotalEnergyAtTimeStep(x) < 0){
|
|
|
|
|
|
+ for (HolonElement he : hl.getElements()) {
|
|
|
|
+ if (minElement < he.getTotalEnergyAtTimeStep(x) && he.getTotalEnergyAtTimeStep(x) < 0) {
|
|
minElement = he.getTotalEnergyAtTimeStep(x);
|
|
minElement = he.getTotalEnergyAtTimeStep(x);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -287,152 +282,156 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
return min;
|
|
return min;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* generates all subNets from all objectsToHandle
|
|
* generates all subNets from all objectsToHandle
|
|
*/
|
|
*/
|
|
- public void searchForSubNets(){
|
|
|
|
|
|
+ public void searchForSubNets() {
|
|
subNets = new ArrayList<subNet>();
|
|
subNets = new ArrayList<subNet>();
|
|
boolean end = false;
|
|
boolean end = false;
|
|
int i = 0;
|
|
int i = 0;
|
|
AbstractCpsObject cps;
|
|
AbstractCpsObject cps;
|
|
- if(objectsToHandle.size() > 0){
|
|
|
|
- while(!end){
|
|
|
|
|
|
+ if (objectsToHandle.size() > 0) {
|
|
|
|
+ while (!end) {
|
|
cps = objectsToHandle.get(i);
|
|
cps = objectsToHandle.get(i);
|
|
- subNet singleSubNet = new subNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>(), new ArrayList<HolonSwitch>());
|
|
|
|
|
|
+ subNet singleSubNet = new subNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>(),
|
|
|
|
+ new ArrayList<HolonSwitch>());
|
|
singleSubNet = buildSubNet(cps, new ArrayList<Integer>(), singleSubNet);
|
|
singleSubNet = buildSubNet(cps, new ArrayList<Integer>(), singleSubNet);
|
|
- if(singleSubNet.getObjects().size() != 0){
|
|
|
|
|
|
+ if (singleSubNet.getObjects().size() != 0) {
|
|
subNets.add(singleSubNet);
|
|
subNets.add(singleSubNet);
|
|
}
|
|
}
|
|
- if(0 == objectsToHandle.size()){
|
|
|
|
|
|
+ if (0 == objectsToHandle.size()) {
|
|
end = true;
|
|
end = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * recursivly generates a subnet of all objects, that one specific object is connected to
|
|
|
|
|
|
+ * recursivly generates a subnet of all objects, that one specific object is
|
|
|
|
+ * connected to
|
|
|
|
+ *
|
|
* @param cps
|
|
* @param cps
|
|
* @param visited
|
|
* @param visited
|
|
* @param sN
|
|
* @param sN
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public subNet buildSubNet(AbstractCpsObject cps, ArrayList<Integer> visited, subNet sN){
|
|
|
|
|
|
+ public subNet buildSubNet(AbstractCpsObject cps, ArrayList<Integer> visited, subNet sN) {
|
|
visited.add(cps.getID());
|
|
visited.add(cps.getID());
|
|
- if(cps instanceof HolonObject){
|
|
|
|
|
|
+ if (cps instanceof HolonObject) {
|
|
sN.getObjects().add((HolonObject) cps);
|
|
sN.getObjects().add((HolonObject) cps);
|
|
}
|
|
}
|
|
- if(cps instanceof HolonSwitch){
|
|
|
|
|
|
+ if (cps instanceof HolonSwitch) {
|
|
sN.getSwitches().add((HolonSwitch) cps);
|
|
sN.getSwitches().add((HolonSwitch) cps);
|
|
}
|
|
}
|
|
removeFromToHandle(cps.getID());
|
|
removeFromToHandle(cps.getID());
|
|
AbstractCpsObject A;
|
|
AbstractCpsObject A;
|
|
AbstractCpsObject B;
|
|
AbstractCpsObject B;
|
|
- for(CpsEdge edge: cps.getConnections()){
|
|
|
|
|
|
+ for (CpsEdge edge : cps.getConnections()) {
|
|
A = edge.getA();
|
|
A = edge.getA();
|
|
B = edge.getB();
|
|
B = edge.getB();
|
|
- if(!(cps instanceof HolonSwitch)){
|
|
|
|
- if(!(sN.getEdges().contains(edge))){
|
|
|
|
|
|
+ if (!(cps instanceof HolonSwitch)) {
|
|
|
|
+ if (!(sN.getEdges().contains(edge))) {
|
|
sN.getEdges().add(edge);
|
|
sN.getEdges().add(edge);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(!visited.contains(A.getID()) && legitState(A, cps)){
|
|
|
|
- sN = buildSubNet(A, visited, sN);
|
|
|
|
|
|
+ if (!visited.contains(A.getID()) && legitState(A, cps)) {
|
|
|
|
+ sN = buildSubNet(A, visited, sN);
|
|
}
|
|
}
|
|
- if(!visited.contains(B.getID()) && legitState(B, cps)){
|
|
|
|
- sN = buildSubNet(B, visited, sN);
|
|
|
|
|
|
+ if (!visited.contains(B.getID()) && legitState(B, cps)) {
|
|
|
|
+ sN = buildSubNet(B, visited, sN);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return sN;
|
|
return sN;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public boolean legitState(AbstractCpsObject neighbor, AbstractCpsObject current){
|
|
|
|
- if(current instanceof HolonSwitch){
|
|
|
|
- if(((HolonSwitch) current).getState(timeStep)){
|
|
|
|
- if(neighbor instanceof HolonSwitch){
|
|
|
|
- if(((HolonSwitch) neighbor).getState(timeStep)){
|
|
|
|
|
|
+
|
|
|
|
+ public boolean legitState(AbstractCpsObject neighbor, AbstractCpsObject current) {
|
|
|
|
+ if (current instanceof HolonSwitch) {
|
|
|
|
+ if (((HolonSwitch) current).getState(timeStep)) {
|
|
|
|
+ if (neighbor instanceof HolonSwitch) {
|
|
|
|
+ if (((HolonSwitch) neighbor).getState(timeStep)) {
|
|
return true;
|
|
return true;
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
return false;
|
|
return false;
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* removes an Object that already has been handled with
|
|
* removes an Object that already has been handled with
|
|
|
|
+ *
|
|
* @param id
|
|
* @param id
|
|
*/
|
|
*/
|
|
- public void removeFromToHandle(int id){
|
|
|
|
- for(int i = 0; i < objectsToHandle.size(); i++){
|
|
|
|
- if(objectsToHandle.get(i).getID() == id){
|
|
|
|
|
|
+ public void removeFromToHandle(int id) {
|
|
|
|
+ for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
|
|
+ if (objectsToHandle.get(i).getID() == id) {
|
|
objectsToHandle.remove(i);
|
|
objectsToHandle.remove(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* ensures that objectsToHandle only contains HolonObjects
|
|
* ensures that objectsToHandle only contains HolonObjects
|
|
*/
|
|
*/
|
|
- public void cleanObjectsToHandle(){
|
|
|
|
- for(int i = 0; i < objectsToHandle.size(); i++){
|
|
|
|
- if(!(objectsToHandle.get(i) instanceof HolonObject)){
|
|
|
|
|
|
+ public void cleanObjectsToHandle() {
|
|
|
|
+ for (int i = 0; i < objectsToHandle.size(); i++) {
|
|
|
|
+ if (!(objectsToHandle.get(i) instanceof HolonObject)) {
|
|
objectsToHandle.remove(i);
|
|
objectsToHandle.remove(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* copies the data of an array of Objects
|
|
* copies the data of an array of Objects
|
|
|
|
+ *
|
|
* @param toCopy
|
|
* @param toCopy
|
|
*/
|
|
*/
|
|
- public void copyObjects(ArrayList<AbstractCpsObject> toCopy){
|
|
|
|
|
|
+ public void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
|
|
objectsToHandle = new ArrayList<AbstractCpsObject>();
|
|
objectsToHandle = new ArrayList<AbstractCpsObject>();
|
|
- for(AbstractCpsObject cps: toCopy){
|
|
|
|
|
|
+ for (AbstractCpsObject cps : toCopy) {
|
|
objectsToHandle.add(cps);
|
|
objectsToHandle.add(cps);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Prints the Components auf all subnets
|
|
* Prints the Components auf all subnets
|
|
*/
|
|
*/
|
|
- public void printNet(){
|
|
|
|
- for(int i = 0; i < subNets.size(); i++){
|
|
|
|
|
|
+ public void printNet() {
|
|
|
|
+ for (int i = 0; i < subNets.size(); i++) {
|
|
System.out.println("SUBNET NR:" + i);
|
|
System.out.println("SUBNET NR:" + i);
|
|
System.out.println(" Objects:");
|
|
System.out.println(" Objects:");
|
|
- for(int j = 0; j < subNets.get(i).getObjects().size(); j++){
|
|
|
|
|
|
+ for (int j = 0; j < subNets.get(i).getObjects().size(); j++) {
|
|
HolonObject hl = subNets.get(i).getObjects().get(j);
|
|
HolonObject hl = subNets.get(i).getObjects().get(j);
|
|
System.out.println(" " + hl.getName() + " " + hl.getID());
|
|
System.out.println(" " + hl.getName() + " " + hl.getID());
|
|
}
|
|
}
|
|
System.out.println(" Edges:");
|
|
System.out.println(" Edges:");
|
|
- for(int j = 0; j < subNets.get(i).getEdges().size(); j++){
|
|
|
|
|
|
+ for (int j = 0; j < subNets.get(i).getEdges().size(); j++) {
|
|
CpsEdge edge = subNets.get(i).getEdges().get(j);
|
|
CpsEdge edge = subNets.get(i).getEdges().get(j);
|
|
System.out.println(" " + edge.getA().getName() + " connected To " + edge.getB().getName());
|
|
System.out.println(" " + edge.getA().getName() + " connected To " + edge.getB().getName());
|
|
}
|
|
}
|
|
System.out.println(" Switches:");
|
|
System.out.println(" Switches:");
|
|
- for(int j = 0; j < subNets.get(i).getSwitches().size(); j++){
|
|
|
|
|
|
+ for (int j = 0; j < subNets.get(i).getSwitches().size(); j++) {
|
|
HolonSwitch sw = subNets.get(i).getSwitches().get(j);
|
|
HolonSwitch sw = subNets.get(i).getSwitches().get(j);
|
|
System.out.println(" " + sw.getName() + " " + sw.getID() + " State:" + sw.getActiveAt()[timeStep]);
|
|
System.out.println(" " + sw.getName() + " " + sw.getID() + " State:" + sw.getActiveAt()[timeStep]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setCanvas(MyCanvas can){
|
|
|
|
|
|
+
|
|
|
|
+ public void setCanvas(MyCanvas can) {
|
|
canvas = can;
|
|
canvas = can;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void reset(){
|
|
|
|
|
|
+
|
|
|
|
+ public void reset() {
|
|
copyObjects(model.getObjectsOnCanvas());
|
|
copyObjects(model.getObjectsOnCanvas());
|
|
}
|
|
}
|
|
-
|
|
|
|
- public ArrayList<subNet> getSubNets(){
|
|
|
|
|
|
+
|
|
|
|
+ public ArrayList<subNet> getSubNets() {
|
|
return subNets;
|
|
return subNets;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|