|
@@ -6,6 +6,7 @@ import classes.CpsEdge;
|
|
import classes.CpsNode;
|
|
import classes.CpsNode;
|
|
import classes.CpsObject;
|
|
import classes.CpsObject;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
|
|
+import classes.HolonSwitch;
|
|
import classes.subNet;
|
|
import classes.subNet;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
import ui.view.MyCanvas;
|
|
import ui.view.MyCanvas;
|
|
@@ -15,6 +16,7 @@ public class SimulationManager {
|
|
private ArrayList<CpsObject> objectsToHandle;
|
|
private ArrayList<CpsObject> objectsToHandle;
|
|
private ArrayList<subNet> subNets;
|
|
private ArrayList<subNet> subNets;
|
|
private MyCanvas canvas;
|
|
private MyCanvas canvas;
|
|
|
|
+ private int timeStep;
|
|
|
|
|
|
public SimulationManager(Model m){
|
|
public SimulationManager(Model m){
|
|
canvas = null;
|
|
canvas = null;
|
|
@@ -28,6 +30,7 @@ public class SimulationManager {
|
|
* @param x
|
|
* @param x
|
|
*/
|
|
*/
|
|
public void calculateStateForTimeStep(int x){
|
|
public void calculateStateForTimeStep(int x){
|
|
|
|
+ timeStep = x;
|
|
searchForSubNets();
|
|
searchForSubNets();
|
|
for(subNet singleSubNet: subNets){
|
|
for(subNet singleSubNet: subNets){
|
|
float production = calculateEnergy("prod", singleSubNet, x);
|
|
float production = calculateEnergy("prod", singleSubNet, x);
|
|
@@ -54,6 +57,7 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //printNet();
|
|
canvas.repaint();
|
|
canvas.repaint();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -96,7 +100,7 @@ public class SimulationManager {
|
|
if(objectsToHandle.size() > 0){
|
|
if(objectsToHandle.size() > 0){
|
|
while(!end){
|
|
while(!end){
|
|
cps = objectsToHandle.get(i);
|
|
cps = objectsToHandle.get(i);
|
|
- subNet singleSubNet = new subNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>());
|
|
|
|
|
|
+ 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);
|
|
@@ -106,7 +110,6 @@ public class SimulationManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //printNet();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -121,21 +124,47 @@ public class SimulationManager {
|
|
if(cps instanceof HolonObject){
|
|
if(cps instanceof HolonObject){
|
|
sN.getObjects().add((HolonObject) cps);
|
|
sN.getObjects().add((HolonObject) cps);
|
|
}
|
|
}
|
|
|
|
+ if(cps instanceof HolonSwitch){
|
|
|
|
+ sN.getSwitches().add((HolonSwitch) cps);
|
|
|
|
+ }
|
|
removeFromToHandle(cps.getID());
|
|
removeFromToHandle(cps.getID());
|
|
|
|
+ CpsObject A;
|
|
|
|
+ CpsObject B;
|
|
for(CpsEdge edge: cps.getConnections()){
|
|
for(CpsEdge edge: cps.getConnections()){
|
|
- if(!(sN.getEdges().contains(edge))){
|
|
|
|
- sN.getEdges().add(edge);
|
|
|
|
|
|
+ A = edge.getA();
|
|
|
|
+ B = edge.getB();
|
|
|
|
+ if(!(cps instanceof HolonSwitch)){
|
|
|
|
+ if(!(sN.getEdges().contains(edge))){
|
|
|
|
+ sN.getEdges().add(edge);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if(!visited.contains(edge.getA().getID())){
|
|
|
|
- sN = buildSubNet(edge.getA(), visited, sN);
|
|
|
|
|
|
+ if(!visited.contains(A.getID()) && legitState(A, cps)){
|
|
|
|
+ sN = buildSubNet(A, visited, sN);
|
|
}
|
|
}
|
|
- if(!visited.contains(edge.getB().getID())){
|
|
|
|
- sN = buildSubNet(edge.getB(), visited, sN);
|
|
|
|
|
|
+ if(!visited.contains(B.getID()) && legitState(B, cps)){
|
|
|
|
+ sN = buildSubNet(B, visited, sN);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return sN;
|
|
return sN;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean legitState(CpsObject neighbor, CpsObject current){
|
|
|
|
+ if(current instanceof HolonSwitch){
|
|
|
|
+ if(((HolonSwitch) current).getActiveAt()[timeStep]){
|
|
|
|
+ if(neighbor instanceof HolonSwitch){
|
|
|
|
+ if(((HolonSwitch) neighbor).getActiveAt()[timeStep]){
|
|
|
|
+ return true;
|
|
|
|
+ }else{
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* removes an Object that already has been handled with
|
|
* removes an Object that already has been handled with
|
|
* @param id
|
|
* @param id
|
|
@@ -179,14 +208,18 @@ public class SimulationManager {
|
|
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:");
|
|
|
|
+ for(int j = 0; j < subNets.get(i).getSwitches().size(); j++){
|
|
|
|
+ HolonSwitch sw = subNets.get(i).getSwitches().get(j);
|
|
|
|
+ System.out.println(" " + sw.getName() + " " + sw.getID() + " State:" + sw.getActiveAt()[timeStep]);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|