704
503
* Removes the specified object from the appropriate ArrayList of objects.
705
504
* All observers are notified of this change.
706
* @param pnObject The PetriNetObject to be removed.
507
* The PetriNetObject to be removed.
708
public void removePetriNetObject(PetriNetObject pnObject){
509
public void removePetriNetObject(PetriNetObject pnObject) {
709
510
boolean didSomething = false;
710
511
ArrayList<?> attachedArcs = null;
713
514
if (setPetriNetObjectArrayList(pnObject)) {
714
515
didSomething = changeArrayList.remove(pnObject);
715
516
// we want to remove all attached arcs also
716
517
if (pnObject instanceof PlaceTransitionObject) {
717
if(pnObject instanceof ColoredTimedPlace){
718
((ColoredTimedPlace)pnObject).showAgeOfTokens(false);
721
if ( arcsMap.get(pnObject) != null) {
723
// get the list of attached arcs for the object we are removing
518
if (arcsMap.get(pnObject) != null) {
520
// get the list of attached arcs for the object we are
724
522
attachedArcs = arcsMap.get(pnObject);
726
524
// iterate over all the attached arcs, removing them all
727
525
// Pere: in inverse order!
728
//for (int i=0; i < attachedArcs.size(); i++){
729
for (int i = attachedArcs.size() - 1; i >= 0; i--){
526
// for (int i=0; i < attachedArcs.size(); i++){
527
for (int i = attachedArcs.size() - 1; i >= 0; i--) {
731
((Arc)attachedArcs.get(i)).delete();
529
((Arc) attachedArcs.get(i)).delete();
732
530
} catch (IndexOutOfBoundsException e) {
733
531
// XXX - this is a hack
734
// This is OK, it just means that the transport arc
532
// This is OK, it just means that the transport
735
534
// already has been removed
741
539
arcsMap.remove(pnObject);
744
if ( inhibitorsMap.get(pnObject) != null) {
542
if (inhibitorsMap.get(pnObject) != null) {
746
// get the list of attached arcs for the object we are removing
544
// get the list of attached arcs for the object we are
747
546
attachedArcs = inhibitorsMap.get(pnObject);
749
548
// iterate over all the attached arcs, removing them all
750
549
// Pere: in inverse order!
751
//for (int i=0; i < attachedArcs.size(); i++){
752
for (int i = attachedArcs.size() - 1; i >= 0; i--){
753
((Arc)attachedArcs.get(i)).delete();
550
// for (int i=0; i < attachedArcs.size(); i++){
551
for (int i = attachedArcs.size() - 1; i >= 0; i--) {
552
((Arc) attachedArcs.get(i)).delete();
755
554
inhibitorsMap.remove(pnObject);
757
if ( tapnInhibitorsMap.get(pnObject) != null) {
556
if (tapnInhibitorsMap.get(pnObject) != null) {
759
// get the list of attached arcs for the object we are removing
558
// get the list of attached arcs for the object we are
760
560
attachedArcs = tapnInhibitorsMap.get(pnObject);
762
562
// iterate over all the attached arcs, removing them all
763
563
// Pere: in inverse order!
764
//for (int i=0; i < attachedArcs.size(); i++){
765
for (int i = attachedArcs.size() - 1; i >= 0; i--){
766
((Arc)attachedArcs.get(i)).delete();
564
// for (int i=0; i < attachedArcs.size(); i++){
565
for (int i = attachedArcs.size() - 1; i >= 0; i--) {
566
((Arc) attachedArcs.get(i)).delete();
768
568
tapnInhibitorsMap.remove(pnObject);
770
} else if (pnObject instanceof NormalArc) {
772
// get source and target of the arc
773
PlaceTransitionObject attached = ((Arc)pnObject).getSource();
775
if (attached != null) {
776
ArrayList<NormalArc> a = arcsMap.get(attached);
781
attached.removeFromArc((Arc)pnObject);
782
if (attached instanceof Transition){
783
((Transition)attached).removeArcCompareObject((Arc)pnObject);
570
} else if (pnObject instanceof TimedInhibitorArcComponent) {
572
// get source and target of the arc
573
PlaceTransitionObject attached = ((Arc) pnObject).getSource();
575
if (attached != null) {
576
ArrayList<TimedInhibitorArcComponent> a = tapnInhibitorsMap.get(attached);
581
attached.removeFromArc((Arc) pnObject);
582
if (attached instanceof Transition) {
583
((Transition) attached).removeArcCompareObject((Arc) pnObject);
585
// attached.updateConnected(); //causing null pointer
589
attached = ((Arc) pnObject).getTarget();
591
if (attached != null) {
592
if (tapnInhibitorsMap.get(attached) != null) { // causing
597
tapnInhibitorsMap.get(attached).remove(pnObject);
600
attached.removeToArc((Arc) pnObject);
601
if (attached instanceof Transition) {
602
((Transition) attached)
603
.removeArcCompareObject((Arc) pnObject);
605
// attached.updateConnected(); //causing null pointer
608
} else if (pnObject instanceof TimedOutputArcComponent) {
610
// get source and target of the arc
611
PlaceTransitionObject attached = ((Arc) pnObject).getSource();
613
if (attached != null) {
614
ArrayList<TimedOutputArcComponent> a = arcsMap.get(attached);
619
attached.removeFromArc((Arc) pnObject);
620
if (attached instanceof Transition) {
621
((Transition) attached).removeArcCompareObject((Arc) pnObject);
784
622
attached.updateConnected();
786
//attached.updateConnected(); //causing null pointer exceptions (?)
624
// attached.updateConnected(); //causing null pointer
789
attached = ((Arc)pnObject).getTarget();
628
attached = ((Arc) pnObject).getTarget();
790
629
if (attached != null) {
791
if (arcsMap.get(attached) != null) { //causing null pointer exceptions (!)
630
if (arcsMap.get(attached) != null) { // causing null
792
634
arcsMap.get(attached).remove(pnObject);
795
attached.removeToArc((Arc)pnObject);
637
attached.removeToArc((Arc) pnObject);
796
638
if (attached instanceof Transition) {
797
((Transition)attached).removeArcCompareObject((Arc)pnObject);
639
((Transition) attached).removeArcCompareObject((Arc) pnObject);
798
640
attached.updateConnected();
800
// attached.updateConnected(); //causing null pointer exceptions (?)
642
// attached.updateConnected(); //causing null pointer
802
645
} else if (pnObject instanceof InhibitorArc) {
804
647
// get source and target of the arc
805
PlaceTransitionObject attached = ((Arc)pnObject).getSource();
648
PlaceTransitionObject attached = ((Arc) pnObject)
807
651
if (attached != null) {
808
ArrayList<InhibitorArc> a=inhibitorsMap.get(attached);
652
ArrayList<InhibitorArc> a = inhibitorsMap.get(attached);
810
654
a.remove(pnObject);
813
attached.removeFromArc((Arc)pnObject);
814
if (attached instanceof Transition){
815
((Transition)attached).removeArcCompareObject((Arc)pnObject);
657
attached.removeFromArc((Arc) pnObject);
658
if (attached instanceof Transition) {
659
((Transition) attached)
660
.removeArcCompareObject((Arc) pnObject);
817
//attached.updateConnected(); //causing null pointer exceptions (?)
662
// attached.updateConnected(); //causing null pointer
821
attached = ((Arc)pnObject).getTarget();
666
attached = ((Arc) pnObject).getTarget();
823
668
if (attached != null) {
824
if (inhibitorsMap.get(attached) != null) { //causing null pointer exceptions (!)
669
if (inhibitorsMap.get(attached) != null) { // causing
825
674
inhibitorsMap.get(attached).remove(pnObject);
828
attached.removeToArc((Arc)pnObject);
829
if (attached instanceof Transition) {
830
((Transition)attached).removeArcCompareObject((Arc)pnObject);
832
// attached.updateConnected(); //causing null pointer exceptions (?)
834
}else if (pnObject instanceof TAPNInhibitorArc) {
836
// get source and target of the arc
837
PlaceTransitionObject attached = ((Arc)pnObject).getSource();
839
if (attached != null) {
840
ArrayList<TAPNInhibitorArc> a=tapnInhibitorsMap.get(attached);
845
attached.removeFromArc((Arc)pnObject);
846
if (attached instanceof Transition){
847
((Transition)attached).removeArcCompareObject((Arc)pnObject);
849
//attached.updateConnected(); //causing null pointer exceptions (?)
853
attached = ((Arc)pnObject).getTarget();
855
if (attached != null) {
856
if (tapnInhibitorsMap.get(attached) != null) { //causing null pointer exceptions (!)
857
tapnInhibitorsMap.get(attached).remove(pnObject);
860
attached.removeToArc((Arc)pnObject);
861
if (attached instanceof Transition) {
862
((Transition)attached).removeArcCompareObject((Arc)pnObject);
864
// attached.updateConnected(); //causing null pointer exceptions (?)
677
attached.removeToArc((Arc) pnObject);
678
if (attached instanceof Transition) {
679
((Transition) attached)
680
.removeArcCompareObject((Arc) pnObject);
682
// attached.updateConnected(); //causing null pointer
904
722
if (pnObject instanceof Transition) {
905
723
changeArrayList = transitionsArray;
907
} else if (pnObject instanceof Place){
725
} else if (pnObject instanceof Place) {
908
726
changeArrayList = placesArray;
911
else if (pnObject instanceof TAPNInhibitorArc) {
728
} else if (pnObject instanceof TimedInhibitorArcComponent) {
912
729
changeArrayList = arcsArray;
915
else if (pnObject instanceof NormalArc) {
731
} else if (pnObject instanceof TimedOutputArcComponent) {
916
732
changeArrayList = arcsArray;
918
734
} else if (pnObject instanceof InhibitorArc) {
919
735
changeArrayList = inhibitorsArray;
922
else if(pnObject instanceof AnnotationNote) {
737
} else if (pnObject instanceof AnnotationNote) {
923
738
changeArrayList = labelsArray;
931
* Returns an iterator of all PetriNetObjects - the order of these cannot be guaranteed.
745
* Returns an iterator of all PetriNetObjects - the order of these cannot be
932
748
* @return An iterator of all PetriNetObjects
934
public Iterator<PetriNetObject> getPetriNetObjects(){
750
public Iterable<PetriNetObject> getPetriNetObjects() {
935
751
ArrayList<PetriNetObject> all = new ArrayList<PetriNetObject>(placesArray);
936
752
all.addAll(transitionsArray);
937
753
all.addAll(arcsArray);
938
754
all.addAll(labelsArray);
940
return all.iterator();
944
public boolean hasPlaceTransitionObjects(){
945
return (placesArray.size() + transitionsArray.size()) > 0;
950
* Creates a Label object from a Label DOM Element
951
* @param inputLabelElement Input Label DOM Element
952
* @return Label Object
954
private AnnotationNote createAnnotation (Element inputLabelElement) {
955
int positionXInput = 0;
956
int positionYInput = 0;
960
boolean borderInput = true;
962
String positionXTempStorage = inputLabelElement.getAttribute("xPosition");
963
String positionYTempStorage = inputLabelElement.getAttribute("yPosition");
964
String widthTemp = inputLabelElement.getAttribute("w");
965
String heightTemp = inputLabelElement.getAttribute("h");
966
String textTempStorage = inputLabelElement.getAttribute("txt");
967
String borderTemp = inputLabelElement.getAttribute("border");
969
if (positionXTempStorage.length() > 0) {
970
positionXInput = Integer.valueOf(positionXTempStorage).intValue() + 1;
973
if (positionYTempStorage.length() > 0){
974
positionYInput = Integer.valueOf(positionYTempStorage).intValue() + 1;
977
if (widthTemp.length() > 0) {
978
widthInput = Integer.valueOf(widthTemp).intValue() + 1;
981
if (heightTemp.length() > 0) {
982
heightInput = Integer.valueOf(heightTemp).intValue() + 1;
985
if (borderTemp.length()>0) {
986
borderInput = Boolean.valueOf(borderTemp).booleanValue();
991
if (textTempStorage.length() > 0) {
992
text = textTempStorage;
997
return new AnnotationNote(text, positionXInput, positionYInput,
998
widthInput, heightInput, borderInput);
1004
* Creates a Transition object from a Transition DOM Element
1005
* @param inputTransitionElement Input Transition DOM Element
1006
* @return Transition Object
1008
private Transition createTransition(Element element){
1009
double positionXInput = 0;
1010
double positionYInput = 0;
1011
String idInput = null;
1012
String nameInput = null;
1013
double nameOffsetYInput = 0;
1014
double nameOffsetXInput = 0;
1015
boolean timedTransition;
1016
boolean infiniteServer;
1019
String positionXTempStorage = element.getAttribute("positionX");
1020
String positionYTempStorage = element.getAttribute("positionY");
1021
String idTempStorage = element.getAttribute("id");
1022
String nameTempStorage = element.getAttribute("name");
1023
String nameOffsetXTempStorage = element.getAttribute("nameOffsetX");
1024
String nameOffsetYTempStorage = element.getAttribute("nameOffsetY");
1025
String nameTimed = element.getAttribute("timed");
1026
String nameInfiniteServer = element.getAttribute("infiniteServer");
1027
String nameAngle = element.getAttribute("angle");
1028
String namePriority = element.getAttribute("priority");
1030
if (nameTimed.length() == 0) {
1031
timedTransition = false;
1032
} else if (nameTimed.length()== 5) {
1033
timedTransition = false;
1035
timedTransition = true;
1038
infiniteServer = !(nameInfiniteServer.length() == 0 ||
1039
nameInfiniteServer.length() == 5);
1041
if (positionXTempStorage.length() > 0) {
1042
positionXInput = Double.valueOf(positionXTempStorage).doubleValue() *
1046
if (positionYTempStorage.length() > 0) {
1047
positionYInput = Double.valueOf(positionYTempStorage).doubleValue() *
1052
positionXInput = Grid.getModifiedX(positionXInput);
1053
positionYInput = Grid.getModifiedY(positionYInput);
1055
if (idTempStorage.length() > 0) {
1056
idInput = idTempStorage;
1057
} else if (nameTempStorage.length() > 0) {
1058
idInput = nameTempStorage;
1061
if (nameTempStorage.length() > 0) {
1062
nameInput = nameTempStorage;
1063
} else if (idTempStorage.length() > 0) {
1064
nameInput = idTempStorage;
1067
if (nameOffsetXTempStorage.length() > 0) {
1068
nameOffsetXInput = Double.valueOf(nameOffsetXTempStorage).doubleValue();
1071
if (nameOffsetYTempStorage.length() > 0) {
1072
nameOffsetYInput = Double.valueOf(nameOffsetYTempStorage).doubleValue();
1075
if (nameAngle.length() > 0) {
1076
angle = Integer.valueOf(nameAngle).intValue();
1079
if (namePriority.length() > 0) {
1080
priority = Integer.valueOf(namePriority).intValue();
1083
Transition transition = null;
1086
new TAPNTransition(positionXInput, positionYInput,
1089
nameOffsetXInput, nameOffsetYInput,
1100
private Place createPlace(Element element){
1101
double positionXInput = 0;
1102
double positionYInput = 0;
1103
String idInput = null;
1104
String nameInput = null;
1105
double nameOffsetYInput = 0;
1106
double nameOffsetXInput = 0;
1107
int initialMarkingInput = 0;
1108
double markingOffsetXInput = 0;
1109
double markingOffsetYInput = 0;
1110
int capacityInput = 0;
1112
String positionXTempStorage = element.getAttribute("positionX");
1113
String positionYTempStorage = element.getAttribute("positionY");
1114
String idTempStorage = element.getAttribute("id");
1115
String nameTempStorage = element.getAttribute("name");
1116
String nameOffsetXTempStorage = element.getAttribute("nameOffsetX");
1117
String nameOffsetYTempStorage = element.getAttribute("nameOffsetY");
1118
String initialMarkingTempStorage = element.getAttribute("initialMarking");
1119
String markingOffsetXTempStorage = element.getAttribute("markingOffsetX");
1120
String markingOffsetYTempStorage = element.getAttribute("markingOffsetY");
1121
String capacityTempStorage = element.getAttribute("capacity");
1122
String invariantTempStorage = element.getAttribute("invariant");
1125
if (positionXTempStorage.length() > 0) {
1126
positionXInput = Double.valueOf(positionXTempStorage).doubleValue() + 1;
1128
if (positionYTempStorage.length() > 0) {
1129
positionYInput = Double.valueOf(positionYTempStorage).doubleValue() + 1;
1131
positionXInput = Grid.getModifiedX(positionXInput);
1132
positionYInput = Grid.getModifiedY(positionYInput);
1134
if (idTempStorage.length() > 0) {
1135
idInput = idTempStorage;
1136
} else if (nameTempStorage.length() > 0) {
1137
idInput = nameTempStorage;
1140
if (nameTempStorage.length() > 0) {
1141
nameInput = nameTempStorage;
1142
} else if (idTempStorage.length() > 0) {
1143
nameInput = idTempStorage;
1146
if (nameOffsetYTempStorage.length() > 0) {
1147
nameOffsetXInput = Double.valueOf(nameOffsetXTempStorage).doubleValue();
1149
if (nameOffsetXTempStorage.length() > 0) {
1150
nameOffsetYInput = Double.valueOf(nameOffsetYTempStorage).doubleValue();
1153
if (initialMarkingTempStorage.length() > 0) {
1154
initialMarkingInput = Integer.valueOf(initialMarkingTempStorage).intValue();
1156
if (markingOffsetXTempStorage.length() > 0) {
1157
markingOffsetXInput = Double.valueOf(markingOffsetXTempStorage).doubleValue();
1159
if (markingOffsetYTempStorage.length() > 0) {
1160
markingOffsetYInput = Double.valueOf(markingOffsetYTempStorage).doubleValue();
1163
if (capacityTempStorage.length() > 0) {
1164
capacityInput = Integer.valueOf(capacityTempStorage).intValue();
1169
if (invariantTempStorage == null || invariantTempStorage == ""){
1170
place = new Place(positionXInput, positionYInput,
1173
nameOffsetXInput, nameOffsetYInput,
1174
initialMarkingInput,
1175
markingOffsetXInput, markingOffsetYInput,
1180
place = new TimedPlace(positionXInput, positionYInput,
1183
nameOffsetXInput, nameOffsetYInput,
1184
initialMarkingInput,
1185
markingOffsetXInput, markingOffsetYInput,
1186
capacityInput, invariantTempStorage);
1194
* Creates a Arc object from a Arc DOM Element
1195
* @param inputArcElement Input Arc DOM Element
1196
* @return Arc Object
1198
private Arc createArc(Element inputArcElement){
1199
String idInput = null;
1200
String sourceInput = null;
1201
String targetInput = null;
1206
sourceInput = inputArcElement.getAttribute("source");
1207
targetInput = inputArcElement.getAttribute("target");
1208
String idTempStorage = inputArcElement.getAttribute("id");
1209
String sourceTempStorage = inputArcElement.getAttribute("source");
1210
String targetTempStorage = inputArcElement.getAttribute("target");
1211
String inscriptionTempStorage = inputArcElement.getAttribute("inscription");
1213
String taggedTempStorage = inputArcElement.getAttribute("tagged");
1214
// String inscriptionOffsetXTempStorage = inputArcElement.getAttribute("inscriptionOffsetX");
1215
// String inscriptionOffsetYTempStorage = inputArcElement.getAttribute("inscriptionOffsetY");
1217
taggedArc = !(taggedTempStorage.length() == 0 ||
1218
taggedTempStorage.length() == 5);
1220
if (idTempStorage.length() > 0) {
1221
idInput = idTempStorage;
1223
if (sourceTempStorage.length() > 0) {
1224
sourceInput = sourceTempStorage;
1226
if (targetTempStorage.length() > 0) {
1227
targetInput = targetTempStorage;
1231
if (sourceInput.length() > 0) {
1232
if (getPlaceTransitionObject(sourceInput) != null) {
1233
// System.out.println("PNMLDATA: sourceInput is not null");
1234
startX = getPlaceTransitionObject(sourceInput).getPositionX();
1235
startX += getPlaceTransitionObject(sourceInput).centreOffsetLeft();
1236
startY = getPlaceTransitionObject(sourceInput).getPositionY();
1237
startY += getPlaceTransitionObject(sourceInput).centreOffsetTop();
1240
if (targetInput.length() > 0) {
1241
if (getPlaceTransitionObject(targetInput) != null) {
1242
getPlaceTransitionObject(targetInput).getPositionX();
1243
getPlaceTransitionObject(targetInput).getPositionY();
1247
PlaceTransitionObject sourceIn = getPlaceTransitionObject(sourceInput);
1248
PlaceTransitionObject targetIn = getPlaceTransitionObject(targetInput);
1250
// add the insets and offset
1251
int aStartx = sourceIn.getX() + sourceIn.centreOffsetLeft();
1252
int aStarty = sourceIn.getY() + sourceIn.centreOffsetTop();
1254
int aEndx = targetIn.getX() + targetIn.centreOffsetLeft();
1255
int aEndy = targetIn.getY() + targetIn.centreOffsetTop();
1258
double _startx = aStartx;
1259
double _starty = aStarty;
1260
double _endx = aEndx;
1261
double _endy = aEndy;
1268
String type = "normal"; // default value
1269
NodeList nl = inputArcElement.getElementsByTagName("type");
1270
if (nl.getLength()>0) {
1271
type = ((Element)(nl.item(0))).getAttribute("type");
1275
if (type.equals("inhibitor")) {
1276
tempArc = new InhibitorArc(_startx, _starty,
1280
/*CB Joakim Byg - inscribtion is inserted as the arcs weight*/
1281
Integer.valueOf(inscriptionTempStorage),
1284
} else if (type.equals("tapnInhibitor")){
1285
tempArc = new TAPNInhibitorArc(new TimedArc(new NormalArc(_startx, _starty, _endx, _endy, sourceIn, targetIn, 1, idInput, taggedArc)), (inscriptionTempStorage!=null ? inscriptionTempStorage : ""));
1290
//XXX - cant check for if arc is timed, check pn-type instead
1291
if (type.equals("timed")){
1292
tempArc = new TimedArc(new NormalArc (_startx, _starty,
1298
taggedArc), (inscriptionTempStorage!=null ? inscriptionTempStorage : ""));
1299
}else if (type.equals("transport")){
1300
String[] inscriptionSplit = {};
1301
if (inscriptionTempStorage.contains(":")){
1302
inscriptionSplit = inscriptionTempStorage.split(":");
1304
boolean isInPreSet = false;
1305
if ( sourceIn instanceof Place ) {
1308
tempArc = new TransportArc( new TimedArc( new NormalArc(_startx, _starty,
1314
taggedArc), inscriptionSplit[0]), Integer.parseInt(inscriptionSplit[1]), isInPreSet );
1316
tempArc = new NormalArc( _startx, _starty,
1320
//inscribtion is inserted as the arcs weight
1321
Integer.valueOf(inscriptionTempStorage),
1328
getPlaceTransitionObject(sourceInput).addConnectFrom(tempArc);
1329
getPlaceTransitionObject(targetInput).addConnectTo(tempArc);
1331
// **********************************************************************************
1332
// The following section attempts to load and display arcpath details****************
1334
//NodeList nodelist = inputArcElement.getChildNodes();
1335
NodeList nodelist = inputArcElement.getElementsByTagName("arcpath");
1336
if (nodelist.getLength()>0) {
1337
tempArc.getArcPath().purgePathPoints();
1338
for (int i = 0; i < nodelist.getLength(); i++) {
1339
Node node = nodelist.item(i);
1340
if(node instanceof Element) {
1341
Element element = (Element)node;
1342
if ("arcpath".equals(element.getNodeName())){
1343
String arcTempX = element.getAttribute("x");
1344
String arcTempY = element.getAttribute("y");
1345
String arcTempType = element.getAttribute("arcPointType");
1346
float arcPointX = Float.valueOf(arcTempX).floatValue();
1347
float arcPointY = Float.valueOf(arcTempY).floatValue();
1348
arcPointX += Pipe.ARC_CONTROL_POINT_CONSTANT + 1;
1349
arcPointY += Pipe.ARC_CONTROL_POINT_CONSTANT + 1;
1350
boolean arcPointType =
1351
Boolean.valueOf(arcTempType).booleanValue();
1352
tempArc.getArcPath().addPoint(arcPointX,arcPointY,arcPointType);
1358
// Arc path creation ends here***************************************************************
1359
// ******************************************************************************************
1365
* Stores Current Marking
1367
public void storeState(){
1368
boolean isTAPN = true;
1370
if(!isUsingColors()){
1371
placeMarkingStorageMap = new HashMap<TimedPlace, ArrayList<BigDecimal>>();
1372
for (Place p : getPlaces()){
1373
placeMarkingStorageMap.put( (TimedPlace)p, (ArrayList<BigDecimal>)((TimedPlace)p).getTokens().clone() );
1376
coloredPlaceMarkingStorageMap = new HashMap<ColoredTimedPlace, List<ColoredToken>>();
1377
for(Place p : getPlaces()){
1378
ColoredTimedPlace ctp = (ColoredTimedPlace)p;
1379
coloredPlaceMarkingStorageMap.put(ctp, copyListOfColoredTokens(ctp.getColoredTokens()));
1383
int placeSize = placesArray.size();
1384
markingVectorAnimationStorage = new int[placeSize];
1385
for (int placeNo = 0; placeNo < placeSize; placeNo++) {
1386
markingVectorAnimationStorage[placeNo] =
1387
((Place)placesArray.get(placeNo)).getCurrentMarking();
1392
private List<ColoredToken> copyListOfColoredTokens(
1393
List<ColoredToken> coloredTokens) {
1394
ArrayList<ColoredToken> list = new ArrayList<ColoredToken>(coloredTokens.size());
1395
for(ColoredToken token : coloredTokens){
1396
list.add(new ColoredToken(token));
1402
public HashMap<TimedPlace, ArrayList<BigDecimal>> getCurrentMarking(){
1403
boolean isTAPN = true;
1405
HashMap<TimedPlace, ArrayList<BigDecimal>> toReturn = new HashMap<TimedPlace, ArrayList<BigDecimal>>();
1407
for (Place p : getPlaces()){
1408
toReturn.put( (TimedPlace)p, (ArrayList<BigDecimal>)((TimedPlace)p).getTokens().clone() );
1416
* Restores To previous Stored Marking
1418
public void restoreState(){
1419
boolean isTAPN = true;
1421
if(!isUsingColors()){
1422
if (placeMarkingStorageMap!=null){
1423
for (Place p : getPlaces()){
1424
ArrayList<BigDecimal> markingOfP = placeMarkingStorageMap.get((TimedPlace)p);
1425
p.setCurrentMarking( markingOfP.size() );
1426
((TimedPlace)p).setAgeOfTokens(markingOfP);
1433
if(coloredPlaceMarkingStorageMap != null){
1434
for(Place p : getPlaces()){
1435
ColoredTimedPlace ctp = (ColoredTimedPlace)p;
1436
ctp.setColoredTokens(coloredPlaceMarkingStorageMap.get(ctp));
1444
if(markingVectorAnimationStorage != null) {
1445
int placeSize = placesArray.size();
1446
for (int placeNo = 0; placeNo < placeSize; placeNo++) {
1447
Place place = ((Place)placesArray.get(placeNo));
1448
if (place != null) {
1449
place.setCurrentMarking(markingVectorAnimationStorage[placeNo]);
1451
notifyObservers(place);
1461
* Fire a specified transition, no affect if transtions not enabled
1462
* @param transition Reference of specifiec Transition
1464
* @author Kenneth Yrke Joergensen <kenneth@yrke.dk> Changed to handeling
1465
* firing modes when working with TAPN.
1467
public FiringAction fireTransition(Transition transition) {
1468
FiringAction toReturn = null;
1471
if (Pipe.drawingmode == Pipe.drawmodes.TIMEDARCPETRINET){
1472
if(!isUsingColors()){
1473
toReturn = fireTransitionInNonColoredTAPN(transition);
1475
toReturn = fireTransitionInColoredTAPN(transition);
1483
private FiringAction fireTransitionInColoredTAPN(
1484
Transition transition) {
1485
ColoredDiscreteFiringAction firingAction = new ColoredDiscreteFiringAction((TAPNTransition)transition);
1487
setEnabledTransitions();
1488
if(transition.isEnabled()){
1489
HashMap<Integer, ColoredToken> tokensConsumedByTransportArcs = new HashMap<Integer, ColoredToken>();
1491
for(Arc arc : transition.getPreset()){
1492
if(arc instanceof ColoredTransportArc){
1493
ColoredTransportArc tarc = (ColoredTransportArc)arc;
1494
ArrayList<ColoredToken> possibleTokens = new ArrayList<ColoredToken>();
1495
ColoredTimedPlace source = (ColoredTimedPlace)arc.getSource();
1496
ColoredTimedPlace target = (ColoredTimedPlace)tarc.getConnectedTo().getTarget();
1498
for(ColoredToken token : source.getColoredTokens()){
1499
if(tarc.satisfiesGuard(token) && target.satisfiesInvariant(token)){
1500
possibleTokens.add(token);
1504
ColoredToken usedToken = CreateGui.getAnimator().firingmode.fire(possibleTokens);
1505
firingAction.addConsumedToken(source, usedToken);
1506
tokensConsumedByTransportArcs.put(tarc.getGroupNr(), usedToken);
1507
source.removeColoredToken(usedToken);
1508
}else if(arc instanceof ColoredInputArc){
1509
ColoredInputArc inputArc = (ColoredInputArc)arc;
1510
ArrayList<ColoredToken> possibleTokens = new ArrayList<ColoredToken>();
1511
ColoredTimedPlace source = (ColoredTimedPlace)arc.getSource();
1513
for(ColoredToken token : source.getColoredTokens()){
1514
if(inputArc.satisfiesGuard(token)){
1515
possibleTokens.add(token);
1519
ColoredToken usedToken = CreateGui.getAnimator().firingmode.fire(possibleTokens);
1520
firingAction.addConsumedToken(source, usedToken);
1521
source.removeColoredToken(usedToken);
1525
for(Arc arc : transition.getPostset()){
1526
if(arc instanceof ColoredTransportArc){
1527
ColoredTransportArc tarc = (ColoredTransportArc)arc;
1528
ColoredToken consumed = tokensConsumedByTransportArcs.get(tarc.getGroupNr());
1529
ColoredToken newToken = tarc.generateOutputToken(consumed);
1531
ColoredTimedPlace target = (ColoredTimedPlace)tarc.getTarget();
1532
firingAction.addProducedToken(target, newToken);
1533
target.addColoredToken(newToken);
1534
}else if(arc instanceof ColoredOutputArc){
1535
ColoredOutputArc outputArc = (ColoredOutputArc)arc;
1536
ColoredToken token = outputArc.generateOutputToken();
1537
ColoredTimedPlace target = (ColoredTimedPlace)outputArc.getTarget();
1539
firingAction.addProducedToken(target, token);
1540
target.addColoredToken(token);
1545
return firingAction;
1549
private FiringAction fireTransitionInNonColoredTAPN(Transition transition) {
1550
DiscreetFiringAction toReturn = new DiscreetFiringAction(transition);
1551
if (transition != null){
1552
setEnabledTransitions();
1555
// Check transition is enables
1556
//Find the tokens valid to fire (check guard)
1557
// - If transportarc check if invariant is ok
1558
// Select the tokens to consume, based on firing stradegy
1559
// Consume the tokens and create the tokens
1561
if (transition.isEnabled()){
1562
HashMap<Integer, BigDecimal> tokensConsumedByTransportArcs = new HashMap<Integer, BigDecimal>();
1564
for (Arc a : (LinkedList<Arc>)transition.getPreset() ){
1568
if (a instanceof TransportArc){
1569
ArrayList<BigDecimal> eligableToken = new ArrayList<BigDecimal>();
1572
TimedPlace p = (TimedPlace)a.getSource();
1574
ArrayList<BigDecimal> tokensOfPlace = p.getTokens();
1576
TimedPlace targetPlace = (TimedPlace)((TransportArc)a).getConnectedTo().getTarget();
1578
for (int i=0; i< tokensOfPlace.size(); i++){
1579
if ( ((TimedArc)a).satisfiesGuard(tokensOfPlace.get(i)) && targetPlace.satisfiesInvariant(tokensOfPlace.get(i))) {
1580
eligableToken.add(tokensOfPlace.get(i));
1583
BigDecimal tokenToRemove = CreateGui.getAnimator().firingmode.fire(eligableToken);
1585
// XXX - This will break if two tokens from the same place is consumed
1586
toReturn.addConsumedToken(p, tokenToRemove);
1588
tokensConsumedByTransportArcs.put(((TransportArc) a).getGroupNr(), tokenToRemove);
1592
p.removeTokenofAge(tokenToRemove);
1594
// if arc is an inhibitor arc then do nothing.
1595
else if(a instanceof TAPNInhibitorArc)
1599
else if (a instanceof TimedArc){
1600
ArrayList<BigDecimal> eligableToken = new ArrayList<BigDecimal>();
1601
//int indexOfOldestEligebleToken = 0;
1603
TimedPlace p = (TimedPlace)a.getSource();
1605
ArrayList<BigDecimal> tokensOfPlace = p.getTokens();
1606
for (int i=0; i< tokensOfPlace.size(); i++){
1607
if ( ((TimedArc)a).satisfiesGuard(tokensOfPlace.get(i))){
1608
eligableToken.add(tokensOfPlace.get(i));
1612
//Select torken to remove based on firing mode
1613
BigDecimal tokenToRemove = CreateGui.getAnimator().firingmode.fire(eligableToken);
1615
// XXX - This will break if two tokens from the same place is consumed
1616
toReturn.addConsumedToken(p, tokenToRemove);
1618
p.removeTokenofAge(tokenToRemove);
1624
//Should not be possible
1630
for (Arc a : (LinkedList<Arc>)transition.getPostset() ){
1631
if (a instanceof TransportArc){
1632
TimedPlace p = (TimedPlace)a.getTarget();
1633
int newNumberOfTokens = p.getTokens().size()+1;
1634
p.setCurrentMarking(newNumberOfTokens);
1635
ArrayList<BigDecimal> markingToBeSet = p.getTokens();
1636
BigDecimal ageOfTokenToSet = tokensConsumedByTransportArcs.get( ((TransportArc) a).getGroupNr() );
1637
markingToBeSet.set(markingToBeSet.size()-1,ageOfTokenToSet);
1639
p.setAgeOfTokens(markingToBeSet);
1642
TimedPlace p = (TimedPlace)a.getTarget();
1643
int newNumberOfTokens = p.getTokens().size()+1;
1644
p.setCurrentMarking(newNumberOfTokens);
1657
* Fire a specified transition and specific tokens, no affect if transtions not enabled
1658
* @param transition Reference of specifiec Transition
1660
* @author Kenneth Yrke Joergensen <kenneth@yrke.dk> Changed to handeling
1661
* firing modes when working with TAPN.
1663
public void fireTransition(Transition transition, HashMap<Place, ArrayList<BigDecimal>> consumedTokens) {
1667
if (Pipe.drawingmode == Pipe.drawmodes.TIMEDARCPETRINET){
1669
if (transition != null){
1670
setEnabledTransitions();
1673
// Check transition is enables
1674
//Find the tokens valid to fire (check guard)
1675
// - If transportarc check if invariant is ok
1676
// Select the tokens to consume, based on firing stradegy
1677
// Consume the tokens and create the tokens
1679
if (transition.isEnabled()){
1680
HashMap<Integer, BigDecimal> tokensConsumedByTransportArcs = new HashMap<Integer, BigDecimal>();
1682
for ( Arc a : (LinkedList<Arc>)transition.getPreset() ){
1683
TimedPlace p = (TimedPlace)a.getSource();
1685
if (a instanceof TransportArc){
1686
BigDecimal tokenToRemove = consumedTokens.get(p).get(0);
1688
//XXX - This will break if two tokens from the same place is consumed
1690
tokensConsumedByTransportArcs.put(((TransportArc) a).getGroupNr(), tokenToRemove);
1692
p.removeTokenofAge(tokenToRemove);
1695
else if (a instanceof TimedArc && !(a instanceof TAPNInhibitorArc)){
1696
//Select torken to remove based on firing mode
1697
BigDecimal tokenToRemove = consumedTokens.get(p).get(0);
1699
//XXX - This will break if two tokens from the same place is consumed
1701
p.removeTokenofAge(tokenToRemove);
1708
for (Arc a : (LinkedList<Arc>)transition.getPostset() ){
1709
if (a instanceof TransportArc){
1710
TimedPlace p = (TimedPlace)a.getTarget();
1711
int newNumberOfTokens = p.getTokens().size()+1;
1712
p.setCurrentMarking(newNumberOfTokens);
1713
ArrayList<BigDecimal> markingToBeSet = p.getTokens();
1714
BigDecimal ageOfTokenToSet = tokensConsumedByTransportArcs.get( ((TransportArc) a).getGroupNr() );
1715
markingToBeSet.set(markingToBeSet.size()-1,ageOfTokenToSet);
1717
p.setAgeOfTokens(markingToBeSet);
1720
TimedPlace p = (TimedPlace)a.getTarget();
1721
int newNumberOfTokens = p.getTokens().size()+1;
1722
p.setCurrentMarking(newNumberOfTokens);
1736
* Fire a random transition, takes rate (probability) of Transitions into account
1738
public Transition fireRandomTransition() {
1740
setEnabledTransitions();
1741
// All the enabled transitions are of the same type:
1742
// a) all are immediate transitions; or
1743
// b) all are timed transitions.
1745
ArrayList<Transition> enabledTransitions = new ArrayList<Transition>();
1747
for (int i = 0; i < transitionsArray.size(); i++) {
1748
Transition transition = (Transition)transitionsArray.get(i);
1749
if (transition.isEnabled()) {
1750
enabledTransitions.add(transition);
1754
// if there is only one enabled transition, return this transition
1755
if (enabledTransitions.size() == 1) {
1756
return enabledTransitions.get(0);
1759
int random = randomNumber.nextInt(enabledTransitions.size());
1761
// no enabled transition found, so no transition can be fired
1762
return enabledTransitions.get(random);
1766
public void fireTimedTransitionBackwards(HashMap<TimedPlace, ArrayList<BigDecimal>> presetMarking,
1767
HashMap<TimedPlace, ArrayList<BigDecimal>> postsetMarking,
1768
TAPNTransition transition){
1769
for (Arc a : (LinkedList<Arc>)transition.getPreset()){
1770
if (! presetMarking.containsKey(a.getSource()) )
1771
throw new IllegalArgumentException("Incorrect Preset for transition argument!");
1773
for (Arc a : (LinkedList<Arc>)transition.getPostset()){
1774
if (! postsetMarking.containsKey(a.getTarget()) )
1775
throw new IllegalArgumentException("Incorrect Postset for transition argument!");
1779
for (Arc a : (LinkedList<Arc>)transition.getPreset()){
1780
TimedPlace place = (TimedPlace)a.getSource();
1781
//place.setCurrentMarking( (presetMarking.get(place)).size() );
1782
//place.setAgeOfTokens(presetMarking.get(place));
1784
// XXX - kyrke Hav now idea on why the two above functions do net do the work,
1785
// But the dont... So we will just use this function for now instead
1786
place.setTokensAndAgeOfTokens(presetMarking.get(place));
1788
for (Arc a : (LinkedList<Arc>)transition.getPostset()){
1789
TimedPlace place = (TimedPlace)a.getTarget();
1790
//place.setCurrentMarking( ((ArrayList<Float>)postsetMarking.get(place)).size() );
1791
//place.setAgeOfTokens(postsetMarking.get(place));
1793
// XXX - kyrke Hav now idea on why the two above functions do net do the work,
1794
// But the dont... So we will just use this function for now instead
1795
place.setTokensAndAgeOfTokens(postsetMarking.get(place));
1802
public void resetEnabledTransitions() {
1803
for (int i = 0; i < transitionsArray.size(); i++) {
1804
Transition transition = (Transition)transitionsArray.get(i);
1805
transition.setEnabled(false);
1807
notifyObservers(transition);
1815
public void setEnabledTransitions(){
1816
for ( Transition t : getTransitions() ){
1817
boolean isEnabled = false;
1819
if(!isUsingColors()){
1820
isEnabled = isTransitionEnabledNonColored(t);
1822
isEnabled = isTransitionEnabledColored(t);
1824
t.setEnabled(isEnabled);
1831
private boolean isTransitionEnabledColored(Transition t) {
1832
boolean enabled = true;
1833
for(Arc arc : t.getPreset()){
1834
boolean arcEnabled = false;
1835
ColoredTimedPlace inputPlace = (ColoredTimedPlace)arc.getSource();
1837
for(ColoredToken token : inputPlace.getColoredTokens()){
1838
if(arc instanceof ColoredInputArc){
1839
arcEnabled = arcEnabled || ((ColoredInputArc)arc).satisfiesGuard(token);
1840
}else if(arc instanceof ColoredTransportArc){
1841
boolean guardSatisfied = ((ColoredTransportArc)arc).satisfiesGuard(token);
1842
boolean targetInvariantSatisfied = ((ColoredTransportArc)arc).satisfiesTargetInvariant(token);
1844
arcEnabled = arcEnabled || (guardSatisfied && targetInvariantSatisfied);
1845
}else if(arc instanceof ColoredInhibitorArc){
1846
arcEnabled = arcEnabled || ((ColoredInhibitorArc)arc).satisfiesGuard(token);
1854
enabled = enabled && arcEnabled;
1857
for(Arc arc : t.getPostset()){
1858
if(arc instanceof ColoredOutputArc){
1859
int value = ((ColoredOutputArc)arc).getOutputValue().getValue();
1860
ColorSet colorInvariant = ((ColoredTimedPlace)arc.getTarget()).getColorInvariant();
1861
enabled = enabled && colorInvariant.contains(value);
1870
private boolean isTransitionEnabledNonColored(Transition t) {
1871
boolean isEnabled = true;
1873
Collection<Arc> presetArcs = t.getPreset();
1874
for ( Arc a : presetArcs ){
1876
Place p = (Place)a.getSource();
1877
if (p instanceof TimedPlace){
1879
boolean ageIsSatisfied;
1881
if(a instanceof TAPNInhibitorArc)
1882
ageIsSatisfied = true;
1884
ageIsSatisfied = false;
1887
if (p.currentMarking > 0){
1889
for ( BigDecimal token : ((TimedPlace)p).getTokens() ){
1890
if(a instanceof TAPNInhibitorArc)
1892
if(!((TimedArc)a).satisfiesGuard(token))
1894
ageIsSatisfied = false;
1902
if ( ((TimedArc)a).satisfiesGuard(token) ){
1904
//make sure no invariants are violated
1905
if (a instanceof TransportArc){
1906
for ( Arc postsetArc : (LinkedList<Arc>)t.getPostset() ){
1907
if (postsetArc instanceof TransportArc){
1908
if ( ((TransportArc) postsetArc).getGroupNr() == ((TransportArc)a).getGroupNr()){
1909
if ( ((TimedPlace)postsetArc.getTarget()).satisfiesInvariant(token) ){
1910
ageIsSatisfied = true;
1916
//invariants are not violated, if it is not a transport arc
1918
ageIsSatisfied = true;
1926
isEnabled = ageIsSatisfied;
1933
//p should always be a TimedPlace unless we have introduced hybrid nets
1942
* Empty all attributes, turn into empty Petri-Net
1944
private void emptyPNML() {
1947
transitionsArray = null;
1950
changeArrayList = null;
1952
initializeMatrices();
1956
760
* Get a List of all the Place objects in the Petri-Net
1957
762
* @return A List of all the Place objects
1959
764
public Place[] getPlaces() {
1960
765
Place[] returnArray = new Place[placesArray.size()];
1962
for (int i = 0; i < placesArray.size(); i++){
1963
returnArray[i] = (Place)placesArray.get(i);
767
for (int i = 0; i < placesArray.size(); i++) {
768
returnArray[i] = placesArray.get(i);
1965
770
return returnArray;
1969
public int getPlacesCount(){
1970
if (placesArray == null) {
1973
return placesArray.size();
1978
/* wjk added 03/10/2007 */
1980
* Get the current marking of the Petri net
1982
* @return The current marking of the Petri net
1984
public int[] getMarking() {
1985
int [] result = new int[placesArray.size()];
1987
for (int i=0; i < placesArray.size(); i++) {
1988
result[i] = ((Place) placesArray.get(i)).getCurrentMarking();
1995
774
* Get a List of all the net-level NameLabel objects in the Petri-Net
1996
* @return A List of all the net-level (as opposed to element-specific) label objects
776
* @return A List of all the net-level (as opposed to element-specific)
1998
779
public AnnotationNote[] getLabels() {
1999
780
AnnotationNote[] returnArray = new AnnotationNote[labelsArray.size()];
2001
for (int i = 0; i < labelsArray.size(); i++){
2002
returnArray[i] = (AnnotationNote)labelsArray.get(i);
782
for (int i = 0; i < labelsArray.size(); i++) {
783
returnArray[i] = labelsArray.get(i);
2004
785
return returnArray;
2008
789
* Get an List of all the Transition objects in the Petri-Net
2009
791
* @return An List of all the Transition objects
2011
793
public Transition[] getTransitions() {
2012
794
Transition[] returnArray = new Transition[transitionsArray.size()];
2014
for (int i = 0; i < transitionsArray.size(); i++){
2015
returnArray[i] = (Transition)transitionsArray.get(i);
796
for (int i = 0; i < transitionsArray.size(); i++) {
797
returnArray[i] = transitionsArray.get(i);
2017
799
return returnArray;
2021
public int getTransitionsCount() {
2022
if (transitionsArray == null) {
2025
return transitionsArray.size();
2030
803
* Get an List of all the Arcs objects in the Petri-Net
2031
805
* @return An List of all the Arc objects
2033
807
public Arc[] getArcs() {
2034
808
Arc[] returnArray = new Arc[arcsArray.size()];
2036
for (int i = 0; i < arcsArray.size(); i++){
2037
returnArray[i] = (Arc)arcsArray.get(i);
810
for (int i = 0; i < arcsArray.size(); i++) {
811
returnArray[i] = arcsArray.get(i);
2039
813
return returnArray;
2044
817
* Get an List of all the InhibitorArc objects in the Petri-Net
2045
819
* @return An List of all the InhibitorArc objects
2047
821
public InhibitorArc[] getInhibitors() {
2048
822
InhibitorArc[] returnArray = new InhibitorArc[inhibitorsArray.size()];
2050
for (int i = 0; i < inhibitorsArray.size(); i++){
2051
returnArray[i] = (InhibitorArc)inhibitorsArray.get(i);
824
for (int i = 0; i < inhibitorsArray.size(); i++) {
825
returnArray[i] = inhibitorsArray.get(i);
2053
827
return returnArray;
2056
public TAPNInhibitorArc[] getTAPNInhibitors() {
2057
int numInhibArcs = 0;
2058
for (int i = 0; i < arcsArray.size(); i++){
2059
if(arcsArray.get(i) instanceof TAPNInhibitorArc)
2063
TAPNInhibitorArc[] returnArray = new TAPNInhibitorArc[numInhibArcs];
2065
for(int i = 0; i < numInhibArcs; i++)
2067
for (int j = 0; j < arcsArray.size(); j++)
2069
if(arcsArray.get(j) instanceof TAPNInhibitorArc)
2070
returnArray[i] = (TAPNInhibitorArc)arcsArray.get(j);
2079
831
* Return the Transition called transitionName from the Petri-Net
2080
* @param transitionID ID of Transition object to return
2081
* @return The first Transition object found with a name equal to transitionName
833
* @param transitionID
834
* ID of Transition object to return
835
* @return The first Transition object found with a name equal to
2083
838
public Transition getTransitionById(String transitionID) {
2084
839
Transition returnTransition = null;
2086
841
if (transitionsArray != null) {
2087
842
if (transitionID != null) {
2088
for (int i = 0 ; i < transitionsArray.size(); i++) {
2089
if (transitionID.equalsIgnoreCase(
2090
((Transition)transitionsArray.get(i)).getId())) {
2091
returnTransition = (Transition)transitionsArray.get(i);
843
for (int i = 0; i < transitionsArray.size(); i++) {
844
if (transitionID.equalsIgnoreCase((transitionsArray.get(i))
846
returnTransition = transitionsArray.get(i);
2096
851
return returnTransition;
2101
855
* Return the Transition called transitionName from the Petri-Net
2102
* @param transitionName Name of Transition object to return
2103
* @return The first Transition object found with a name equal to transitionName
857
* @param transitionName
858
* Name of Transition object to return
859
* @return The first Transition object found with a name equal to
2105
862
public Transition getTransitionByName(String transitionName) {
2106
863
Transition returnTransition = null;
2256
* Create model from TAPN model
2257
* @author Kenneth Yrke Jørgensen <kyrke@cs.aau.dk>
2260
public void createFromTAPN(TAPN model) {
2262
// double xcord = 10;
2263
// double ycord = 10;
2265
// List<dk.aau.cs.petrinet.TAPNPlace> places = model.getPlaces();
2266
// List<dk.aau.cs.petrinet.TAPNTransition> transitions = model.getTransitions();
2267
// List<dk.aau.cs.petrinet.Arc> arcs = model.getArcs();
2270
// for (dk.aau.cs.petrinet.TAPNPlace p : places){
2271
// Place tmp = new Place(xcord, ycord, ""+p.getID(), p.getName(), 10.0, 10.0, 0, 0, 0, 0);
2272
// TimedPlace tp = new TimedPlace(tmp, p.getInvariant());
2276
// xcord = xcord + 10;
2277
// ycord = ycord + 10;
2280
// // Add transitions
2281
// for (dk.aau.cs.petrinet.TAPNTransition t : transitions){
2282
// Transition trans = new Transition(xcord, ycord, ""+t.getID(), t.getName(), 10.0, 10.0, 10.0, false, false, 1, 1);
2283
// addTransition(new TAPNTransition(trans));
2284
// xcord = xcord + 10;
2285
// ycord = ycord + 10;
2289
// for (dk.aau.cs.petrinet.Arc a : arcs){
2293
// if (CreateGui.getApp()!=null) {
2294
// CreateGui.getApp().restoreMode();
2301
* Create model from transformed PNML file
2302
* @author Ben Kirby, 10 Feb 2007
2303
* @param filename URI location of PNML
2305
* @author Edwin Chung
2306
* This code is modified so that dataLayer objects can be created
2309
public void createFromPNML(Document PNMLDoc){
2310
createFromPNML(PNMLDoc, NetType.TAPN);
2313
public void createFromPNML(Document PNMLDoc, NetType type) {
2314
// XXX - kyrke debug
2316
this.setNetType(type);
2318
NodeList nodeList = null;
2321
if (CreateGui.getApp()!=null) {
2322
// Notifies used to indicate new instances.
2323
CreateGui.getApp().setMode(Pipe.CREATING);
2326
if(type.equals(NetType.COLORED)){
2327
NodeList places = PNMLDoc.getElementsByTagName("net").item(0).getChildNodes();
2328
for(int i = 0; i < places.getLength(); i++){
2329
this.parseColoredElement(places.item(i));
2332
nodeList = PNMLDoc.getDocumentElement().getChildNodes();
2333
for(int i = 0 ; i < nodeList.getLength() ; i++) {
2334
node = nodeList.item(i);
2339
if (CreateGui.getApp()!=null) {
2340
CreateGui.getApp().restoreMode();
2345
} catch (Exception e) {
2346
System.out.println("runtime except");
2347
throw new RuntimeException(e);
2351
private void parseColoredElement(Node node) {
2353
if(node instanceof Element) {
2354
element = (Element)node;
2355
if ("labels".equals(element.getNodeName())){
2356
addAnnotation(createAnnotation(element));
2357
} else if("place".equals(element.getNodeName())){
2358
addPlace(createColoredPlace(element));
2359
} else if ("transition".equals(element.getNodeName())){
2360
addTransition(createTransition(element));
2361
} else if ("arc".equals(element.getNodeName())) {
2362
Arc newArc = createColoredArc(element);
2363
if (newArc instanceof InhibitorArc) {
2364
addArc((InhibitorArc) newArc);
2365
} else if (newArc instanceof TAPNInhibitorArc) {
2366
addArc((TAPNInhibitorArc) newArc);
2368
addArc((NormalArc) newArc);
2369
checkForInverseArc((NormalArc) newArc);
2371
} else if( "queries".equals(element.getNodeName()) ){
2372
TAPNQuery query = createQuery(element);
2375
} else if ("constant".equals(element.getNodeName())){
2376
String name = element.getAttribute("name");
2377
int value = Integer.parseInt(element.getAttribute("value"));
2378
if(!name.isEmpty() && value >= 0)
2379
addConstant(name, value);
2381
System.out.println("!" + element.getNodeName());
2388
private Arc createColoredArc(Element inputArcElement) {
2389
String idInput = null;
2390
String sourceInput = null;
2391
String targetInput = null;
2396
sourceInput = inputArcElement.getAttribute("source");
2397
targetInput = inputArcElement.getAttribute("target");
2398
idInput = inputArcElement.getAttribute("id");
2400
String taggedTempStorage = inputArcElement.getAttribute("tagged");
2401
// String inscriptionOffsetXTempStorage = inputArcElement.getAttribute("inscriptionOffsetX");
2402
// String inscriptionOffsetYTempStorage = inputArcElement.getAttribute("inscriptionOffsetY");
2404
taggedArc = !(taggedTempStorage.length() == 0 ||
2405
taggedTempStorage.length() == 5);
2407
if (sourceInput.length() > 0) {
2408
if (getPlaceTransitionObject(sourceInput) != null) {
2409
// System.out.println("PNMLDATA: sourceInput is not null");
2410
startX = getPlaceTransitionObject(sourceInput).getPositionX();
2411
startX += getPlaceTransitionObject(sourceInput).centreOffsetLeft();
2412
startY = getPlaceTransitionObject(sourceInput).getPositionY();
2413
startY += getPlaceTransitionObject(sourceInput).centreOffsetTop();
2416
if (targetInput.length() > 0) {
2417
if (getPlaceTransitionObject(targetInput) != null) {
2421
PlaceTransitionObject sourceIn = getPlaceTransitionObject(sourceInput);
2422
PlaceTransitionObject targetIn = getPlaceTransitionObject(targetInput);
2424
// add the insets and offset
2425
int aStartx = sourceIn.getX() + sourceIn.centreOffsetLeft();
2426
int aStarty = sourceIn.getY() + sourceIn.centreOffsetTop();
2428
int aEndx = targetIn.getX() + targetIn.centreOffsetLeft();
2429
int aEndy = targetIn.getY() + targetIn.centreOffsetTop();
2432
double _startx = aStartx;
2433
double _starty = aStarty;
2434
double _endx = aEndx;
2435
double _endy = aEndy;
2437
String type = inputArcElement.getAttribute("type");
2441
if(type.equals("ColoredInputArc")){
2442
ColoredInputArc cia = new ColoredInputArc(new NormalArc(_startx, _starty, _endx, _endy, sourceIn, targetIn,1,idInput, taggedArc));
2443
ColoredInterval timeGuard = new ColoredInterval(inputArcElement.getAttribute("timeGuard"));
2444
cia.setTimeGuard(timeGuard);
2446
ColorSet colorGuard = new ColorSet(inputArcElement.getAttribute("colorGuard"));
2447
cia.setColorGuard(colorGuard);
2450
}else if(type.equals("ColoredOutputArc")){
2451
ColoredOutputArc coa = new ColoredOutputArc(_startx, _starty, _endx, _endy, sourceIn, targetIn,1,idInput, taggedArc);
2452
coa.setOutputValue(new IntOrConstant(inputArcElement.getAttribute("outputValue")));
2455
}else if(type.equals("ColoredInhibitorArc")){
2456
ColoredInhibitorArc cia = new ColoredInhibitorArc(new NormalArc(_startx, _starty, _endx, _endy, sourceIn, targetIn,1,idInput, taggedArc));
2457
ColoredInterval timeGuard = new ColoredInterval(inputArcElement.getAttribute("timeGuard"));
2458
cia.setTimeGuard(timeGuard);
2460
ColorSet colorGuard = new ColorSet(inputArcElement.getAttribute("colorGuard"));
2461
cia.setColorGuard(colorGuard);
2465
}else if(type.equals("ColoredTransportArc")){
2466
ColoredTransportArc cta = new ColoredTransportArc(
2467
new TimedArc( new NormalArc(_startx, _starty,
2475
Integer.parseInt(inputArcElement.getAttribute("groupNo")),
2476
sourceIn instanceof Place);
2478
ColoredInterval timeGuard = new ColoredInterval(inputArcElement.getAttribute("timeGuard"));
2479
cta.setTimeGuard(timeGuard);
2481
ColorSet colorGuard = new ColorSet(inputArcElement.getAttribute("colorGuard"));
2482
cta.setColorGuard(colorGuard);
2484
Preserve preservation = Preserve.valueOf(inputArcElement.getAttribute("preservation"));
2485
cta.setPreservation(preservation);
2487
IntOrConstant outputValue = new IntOrConstant(inputArcElement.getAttribute("outputValue"));
2488
cta.setOutputValue(outputValue);
2493
getPlaceTransitionObject(sourceInput).addConnectFrom(arc);
2494
getPlaceTransitionObject(targetInput).addConnectTo(arc);
2496
// **********************************************************************************
2497
// The following section attempts to load and display arcpath details****************
2499
//NodeList nodelist = inputArcElement.getChildNodes();
2500
NodeList nodelist = inputArcElement.getElementsByTagName("arcpath");
2501
if (nodelist.getLength()>0) {
2502
arc.getArcPath().purgePathPoints();
2503
for (int i = 0; i < nodelist.getLength(); i++) {
2504
Node node = nodelist.item(i);
2505
if(node instanceof Element) {
2506
Element element = (Element)node;
2507
if ("arcpath".equals(element.getNodeName())){
2508
String arcTempX = element.getAttribute("xCoord");
2509
String arcTempY = element.getAttribute("yCoord");
2510
String arcTempType = element.getAttribute("arcPointType");
2511
float arcPointX = Float.valueOf(arcTempX).floatValue();
2512
float arcPointY = Float.valueOf(arcTempY).floatValue();
2513
arcPointX += Pipe.ARC_CONTROL_POINT_CONSTANT + 1;
2514
arcPointY += Pipe.ARC_CONTROL_POINT_CONSTANT + 1;
2515
boolean arcPointType =
2516
Boolean.valueOf(arcTempType).booleanValue();
2517
arc.getArcPath().addPoint(arcPointX,arcPointY,arcPointType);
2523
// Arc path creation ends here***************************************************************
2524
// ******************************************************************************************
2529
private Place createColoredPlace(Element element) {
2530
double positionXInput = 0;
2531
double positionYInput = 0;
2532
String idInput = element.getAttribute("id");
2533
String nameInput = element.getAttribute("name");
2534
double nameOffsetYInput = 0;
2535
double nameOffsetXInput = 0;
2536
double markingOffsetXInput = 0;
2537
double markingOffsetYInput = 0;
2538
int capacityInput = 0;
2540
String positionXTempStorage = element.getAttribute("positionX");
2541
String positionYTempStorage = element.getAttribute("positionY");
2542
String nameOffsetXTempStorage = element.getAttribute("nameOffsetX");
2543
String nameOffsetYTempStorage = element.getAttribute("nameOffsetY");
2544
String initialMarkingTempStorage = element.getAttribute("initialMarking");
2545
String markingOffsetXTempStorage = element.getAttribute("markingOffsetX");
2546
String markingOffsetYTempStorage = element.getAttribute("markingOffsetY");
2547
String capacityTempStorage = element.getAttribute("capacity");
2549
if (positionXTempStorage.length() > 0) {
2550
positionXInput = Double.valueOf(positionXTempStorage).doubleValue() + 1;
2552
if (positionYTempStorage.length() > 0) {
2553
positionYInput = Double.valueOf(positionYTempStorage).doubleValue() + 1;
2556
positionXInput = Grid.getModifiedX(positionXInput);
2557
positionYInput = Grid.getModifiedY(positionYInput);
2559
if (nameOffsetYTempStorage.length() > 0) {
2560
nameOffsetXInput = Double.valueOf(nameOffsetXTempStorage).doubleValue();
2562
if (nameOffsetXTempStorage.length() > 0) {
2563
nameOffsetYInput = Double.valueOf(nameOffsetYTempStorage).doubleValue();
2566
if (initialMarkingTempStorage.length() > 0) {
2568
if (markingOffsetXTempStorage.length() > 0) {
2569
markingOffsetXInput = Double.valueOf(markingOffsetXTempStorage).doubleValue();
2571
if (markingOffsetYTempStorage.length() > 0) {
2572
markingOffsetYInput = Double.valueOf(markingOffsetYTempStorage).doubleValue();
2575
if (capacityTempStorage.length() > 0) {
2576
capacityInput = Integer.valueOf(capacityTempStorage).intValue();
2579
ColoredTimeInvariant timeInvariant = new ColoredTimeInvariant(element.getAttribute("timeInvariant"));
2580
ColorSet colorInvariant = new ColorSet(element.getAttribute("colorInvariant"));
2582
ColoredTimedPlace place = new ColoredTimedPlace(positionXInput,positionYInput, idInput, nameInput,nameOffsetXInput, nameOffsetYInput, 0, markingOffsetXInput, markingOffsetYInput, capacityInput, "");
2583
place.setTimeInvariant(timeInvariant);
2584
place.setColorInvariant(colorInvariant);
2586
NodeList tokenNodes = element.getElementsByTagName("colored-token");
2587
List<ColoredToken> tokens = parseTokens(tokenNodes);
2588
place.setColoredTokens(tokens);
2595
private List<ColoredToken> parseTokens(NodeList tokenNodes) {
2596
ArrayList<ColoredToken> list = new ArrayList<ColoredToken>();
2598
for(int i = 0; i < tokenNodes.getLength(); i++){
2599
Element element = (Element)tokenNodes.item(i);
2601
IntOrConstant value = new IntOrConstant(element.getAttribute("value"));
2602
list.add(new ColoredToken(value));
2608
private void parseElement(Node node) {
2610
if(node instanceof Element) {
2611
element = (Element)node;
2612
if ("labels".equals(element.getNodeName())){
2613
addAnnotation(createAnnotation(element));
2614
} else if("place".equals(element.getNodeName())){
2615
addPlace(createPlace(element));
2616
} else if ("transition".equals(element.getNodeName())){
2617
addTransition(createTransition(element));
2618
} else if ("arc".equals(element.getNodeName())) {
2619
Arc newArc = createArc(element);
2620
if (newArc instanceof InhibitorArc) {
2621
addArc((InhibitorArc) newArc);
2622
} else if (newArc instanceof TAPNInhibitorArc) {
2623
addArc((TAPNInhibitorArc) newArc);
2625
addArc((NormalArc) newArc);
2626
checkForInverseArc((NormalArc) newArc);
2628
} else if( "queries".equals(element.getNodeName()) ){
2629
TAPNQuery query = createQuery(element);
2632
} else if ("constant".equals(element.getNodeName())){
2633
String name = element.getAttribute("name");
2634
int value = Integer.parseInt(element.getAttribute("value"));
2635
if(!name.isEmpty() && value >= 0)
2636
addConstant(name, value);
2638
System.out.println("!" + element.getNodeName());
2645
* This method creates a new datalayer based on a datalayer,
2646
* this can be used for drawing a datalayer after having modyfied it
2647
* by some external code.
2649
* This method is used for drawing a datalayer after it has been
2650
* transformed by dk.aau.cs.TAPN.transformer
2652
* @author Kenneth Yrke Joergensen (kyrke@cs.aau.dk) **/
2654
public void createFromDataLayer(DataLayer m){
2655
if (CreateGui.getApp()!=null) {
2656
// Notifies used to indicate new instances.
2657
CreateGui.getApp().setMode(Pipe.CREATING);
2660
for (Transition t : m.getTransitions()){
2661
addTransition(new Transition(t));
2664
for (Place p : m.getPlaces()){
2665
addPlace(p.clone());
2669
for (Arc a:m.getArcs()){
2670
NormalArc tmp = (NormalArc)a.clone();
2672
PlaceTransitionObject source = getPlaceTransitionObject(tmp.getSource().getName());
2673
PlaceTransitionObject target = getPlaceTransitionObject(tmp.getTarget().getName());
2675
target.addConnectTo(tmp);
2676
source.addConnectFrom(tmp);
2682
if (getPlaceTransitionObject(sourceInput) != null) {
2683
// System.out.println("PNMLDATA: sourceInput is not null");
2684
startX = getPlaceTransitionObject(sourceInput).getPositionX();
2685
startX += getPlaceTransitionObject(sourceInput).centreOffsetLeft();
2686
startY = getPlaceTransitionObject(sourceInput).getPositionY();
2687
startY += getPlaceTransitionObject(sourceInput).centreOffsetTop();
2690
if (getPlaceTransitionObject(targetInput) != null) {
2691
// System.out.println("PNMLDATA: targetInput is not null");
2692
endX = getPlaceTransitionObject(targetInput).getPositionX();
2693
endY = getPlaceTransitionObject(targetInput).getPositionY();
2697
PlaceTransitionObject sourceIn = getPlaceTransitionObject(sourceInput);
2698
PlaceTransitionObject targetIn = getPlaceTransitionObject(targetInput);
2700
// add the insets and offset
2701
int aStartx = sourceIn.getX() + sourceIn.centreOffsetLeft();
2702
int aStarty = sourceIn.getY() + sourceIn.centreOffsetTop();
2704
int aEndx = targetIn.getX() + targetIn.centreOffsetLeft();
2705
int aEndy = targetIn.getY() + targetIn.centreOffsetTop();
2708
double _startx = aStartx;
2709
double _starty = aStarty;
2710
double _endx = aEndx;
2711
double _endy = aEndy; */
2718
if (CreateGui.getApp()!=null) {
2719
CreateGui.getApp().restoreMode();
2725
private TAPNQuery createQuery(Element queryElement) {
2729
comment = queryElement.getAttribute("name");
2730
}catch (Exception e) {
2731
comment = "No comment specified";
2734
TraceOption traceOption;
2736
traceOption = TraceOption.valueOf(queryElement.getAttribute("traceOption"));
2737
}catch (Exception e) {
2738
traceOption = TraceOption.NONE;
2741
SearchOption searchOption;
2743
searchOption = SearchOption.valueOf(queryElement.getAttribute("searchOption"));
2744
}catch (Exception e) {
2745
searchOption = SearchOption.BFS;
2748
HashTableSize hashTableSize;
2750
hashTableSize = HashTableSize.valueOf(queryElement.getAttribute("hashTableSize"));
2751
}catch (Exception e) {
2752
hashTableSize = HashTableSize.MB_16;
2755
ExtrapolationOption extrapolationOption;
2757
extrapolationOption = ExtrapolationOption.valueOf(queryElement.getAttribute("extrapolationOption"));
2758
}catch (Exception e) {
2759
extrapolationOption = ExtrapolationOption.AUTOMATIC;
2762
ReductionOption reductionOption;
2764
reductionOption = ReductionOption.valueOf(queryElement.getAttribute("reductionOption"));
2765
}catch (Exception e) {
2766
reductionOption = ReductionOption.STANDARD;
2771
capacity = queryElement.getAttribute("capacity");
2772
}catch (Exception e) {
2775
TAPAALQueryParser queryParser = new TAPAALQueryParser();
2776
TCTLAbstractProperty query;
2778
query = queryParser.parse(queryElement.getAttribute("query"));
2780
return new TAPNQuery(comment, Integer.parseInt(capacity), query, traceOption, searchOption, reductionOption, hashTableSize, extrapolationOption);
2783
}catch (Exception e) {
2784
JOptionPane.showMessageDialog(CreateGui.getApp(), "TAPAAL encountered an error trying to parse the queries in the model.\n\nThe queries that could not be parsed will not show up in the query list.", "Error Parsing Query", JOptionPane.ERROR_MESSAGE);
2785
System.err.println("No query was specified: " + e.getStackTrace());
2794
* Return a URI for the PNML file for the Petri-Net
2795
* @return A DOM for the Petri-Net
2797
public String getURI() {
2802
/** prints out a brief representation of the dataLayer object */
2803
public void print() {
2804
System.out.println("No of Places = " + placesArray.size() + "\"");
2805
System.out.println("No of Transitions = " + transitionsArray.size() + "\"");
2806
System.out.println("No of Arcs = " + arcsArray.size() + "\"");
2807
System.out.println("No of Labels = " + labelsArray.size() +
2808
"\" (Model View Controller Design Pattern)");
2814
* See if the supplied net has any timed transitions.
2819
public boolean hasTimedTransitions(){
2820
Transition[] transitions = this.getTransitions();
2821
int transCount = transitions.length;
2823
for (int i = 0; i< transCount; i++) {
2824
if (transitions[i].isTimed() == true) {
2833
* See if the net has any timed transitions.
2837
public boolean hasImmediateTransitions(){
2838
Transition[] transitions = this.getTransitions();
2839
int transCount = transitions.length;
2841
for (int i = 0; i< transCount; i++) {
2842
if (transitions[i].isTimed() == false) {
2852
private void checkForInverseArc(NormalArc newArc) {
2853
Iterator<Arc> iterator = newArc.getSource().getConnectToIterator();
2856
while (iterator.hasNext()){
2857
anArc = iterator.next();
2858
if (anArc.getTarget() == newArc.getSource() &&
2859
anArc.getSource() == newArc.getTarget()) {
2860
if (anArc.getClass() == NormalArc.class) {
2861
if (!newArc.hasInverse()) {
2862
((NormalArc)anArc).setInverse(newArc, Pipe.JOIN_ARCS);
2870
public String getTransitionName(int i) {
2871
return ((Transition)transitionsArray.get(i)).getName();
2875
public HashMap<Transition, HashMap<TransportArc, TransportArc> > getTransportArcMap() {
2876
return transportArcMap;
2879
public void letTimePass(BigDecimal timeToPass) throws InvariantViolatedAnimationException{
2880
if(!canTimePass(timeToPass)){
2881
throw new InvariantViolatedAnimationException();
2885
for (Place p : getPlaces()){
2886
if(isUsingColors()){
2887
ColoredTimedPlace place = (ColoredTimedPlace)p;
2888
for(ColoredToken token : place.getColoredTokens()){
2889
token.doTimeDelay(timeToPass);
2892
if (p instanceof TimedPlace){
2893
TimedPlace place = (TimedPlace)p;
2894
int sizeOfArray = place.getTokens().size();
2896
for (int i = 0; i< sizeOfArray; i++){
2897
BigDecimal token = place.getTokens().get(i);
2898
place.getTokens().set(i, token.add(timeToPass));
2908
setEnabledTransitions();
2912
public boolean canTimePass(BigDecimal timeToPass) throws InvariantViolatedAnimationException{
2913
// Can we do time delay
2914
for (Place p : getPlaces()){
2915
if(isUsingColors()){
2916
ColoredTimedPlace ctp = (ColoredTimedPlace)p;
2918
for(ColoredToken token : ctp.getColoredTokens()){
2919
ColoredToken newToken = new ColoredToken(token.getAge().add(timeToPass), token.getColor());
2920
if(!ctp.satisfiesInvariant(newToken)){
2925
if (p instanceof TimedPlace){
2926
TimedPlace timedPlace = (TimedPlace)p;
2928
for (BigDecimal token : timedPlace.getTokens()){
2929
if (!timedPlace.satisfiesInvariant(token.add(timeToPass))){
2939
public void setQueries(ArrayList<TAPNQuery> queries) {
2940
this.queries = queries;
2943
public ArrayList<TAPNQuery> getQueries(){
2947
public Collection<Constant> getConstants()
2949
return constants.getConstants();
2952
public UndoableEdit updateConstant(String oldName, Constant constant)
2954
UndoableEdit edit = constants.updateConstant(oldName, constant, this);
2956
correctGuards(oldName, constant.getName());
2962
public void correctGuards(String oldName, String newName) {
2963
updateArcGuards(oldName, newName);
2964
for(Place p : placesArray){
2965
if(!isUsingColors()){
2966
if(p instanceof TimedPlace){
2967
TimedPlace tp = (TimedPlace)p;
2968
String inv = tp.getInvariant();
2970
String operator = inv.contains("<=") ? "<=" : "<";
2971
String first = inv.substring(operator.length());
2973
if(first.equals(oldName)){
2977
tp.setInvariant(operator + first);
2980
((ColoredTimedPlace)p).updateConstantName(oldName, newName);
2987
private void updateArcGuards(String oldName, String newName) {
2988
for(Arc arc : arcsArray){
2989
if(!isUsingColors()){
2990
if(arc instanceof TimedArc || arc instanceof TransportArc){
2991
TimedArc tarc = (TimedArc)arc;
2992
String guard = tarc.getGuard();
2993
String leftDelim = guard.substring(0,1);
2994
String rightDelim = guard.substring(guard.length()-1, guard.length());
2995
String first = guard.substring(1, guard.indexOf(","));
2996
String second = guard.substring(guard.indexOf(",")+1, guard.length()-1);
2998
if(first.equals(oldName)){
3001
if(second.equals(oldName)){
3005
tarc.setGuard(leftDelim + first + "," + second + rightDelim);
3008
if(arc instanceof ColoredTransportArc){
3009
ColoredTransportArc cta = (ColoredTransportArc)arc;
3010
cta.updateConstantName(oldName, newName);
3011
}else if(arc instanceof ColoredInhibitorArc){
3012
((ColoredInhibitorArc)arc).updateConstantName(oldName, newName);
3013
}else if(arc instanceof ColoredInputArc){
3014
((ColoredInputArc)arc).updateConstantName(oldName, newName);
3015
}else if(arc instanceof ColoredOutputArc){
3016
((ColoredOutputArc)arc).updateConstantName(oldName, newName);
3023
public UndoableEdit addConstant(String name, int value) {
3024
return constants.addConstant(name, value);
3027
public UndoableEdit removeConstant(String name){
3028
return constants.removeConstant(name);
3031
public void addQuery(TAPNQuery query) {
3037
public Set<String> getConstantNames() {
3038
return constants.getConstantNames();
3043
public int getConstantValue(String constantName) {
3044
return constants.getConstant(constantName).getValue();
3048
public int getLargestConstantValue() {
3049
return constants.getLargestConstantValue();
3053
public void buildConstraints() {
3054
constants.buildConstraints(placesArray,arcsArray, isUsingColors());
3057
public boolean hasTAPNInhibitorArcs(){ // TODO: Fix this to make it faster
3058
for(Arc arc : arcsArray){
3059
if(arc instanceof TAPNInhibitorArc){
3066
public boolean isUsingColors() {
3067
return type.equals(NetType.COLORED);
3070
public NetType netType(){
980
public boolean hasTAPNInhibitorArcs() { // TODO: Fix this to make it faster
981
for (Arc arc : arcsArray) {
982
if (arc instanceof TimedInhibitorArcComponent) {
989
public boolean hasTransportArcs() {
990
for(Arc arc : arcsArray) {
991
if(arc instanceof TransportArcComponent) {
998
public boolean hasInvariants() {
999
for(Place p : placesArray) {
1000
if(!((TimedPlaceComponent)p).underlyingPlace().invariant().equals(TimeInvariant.LESS_THAN_INFINITY))
1006
public NetType netType() {
3074
1010
public void setNetType(NetType type) {
3075
1011
this.type = type;
3079
public void fireColoredTransitionBackwards(
3080
ColoredDiscreteFiringAction action) {
3081
for(Entry<ColoredTimedPlace, ColoredToken> entry : action.getConsumedTokens().entrySet()){
3082
entry.getKey().addColoredToken(entry.getValue());
3085
for(Entry<ColoredTimedPlace, ColoredToken> entry : action.getProducedTokens().entrySet()){
3086
entry.getKey().removeColoredToken(entry.getValue());
3089
//fireTransitionBackwards(action.getTransition());
3093
public void fireTransition(ColoredDiscreteFiringAction action) {
3095
for(Entry<ColoredTimedPlace, ColoredToken> entry : action.getConsumedTokens().entrySet()){
3096
ColoredTimedPlace place = entry.getKey();
3097
ColoredToken token = entry.getValue();
3099
place.removeColoredToken(token);
3102
for(Entry<ColoredTimedPlace, ColoredToken> entry : action.getProducedTokens().entrySet()){
3103
entry.getKey().addColoredToken(entry.getValue());
3107
public boolean isDegree2(){
3108
boolean isDegree2=true;
3110
for (Transition t : getTransitions()){
3112
if (t.getPostset().size() > 2 || t.getPreset().size() > 2){
3124
1014
public void redrawVisibleTokenLists() {
3125
1015
for (Place place : placesArray) {
3126
if(place instanceof TimedPlace){
3127
TimedPlace tp = (TimedPlace)place;
3128
if(tp.isAgeOfTokensShown()){
1016
if (place instanceof TimedPlaceComponent) {
1017
TimedPlaceComponent tp = (TimedPlaceComponent) place;
1018
if (tp.isAgeOfTokensShown()) {
3129
1019
tp.showAgeOfTokens(true);
1025
public void repaintPlaces() {
1026
for (Place p : placesArray) {
1031
public void repaintPlaces(boolean displayConstantNames) {
1032
for (Place p : placesArray) {
1033
p.update(displayConstantNames);
1038
public void repaintAll(boolean displayConstantNames) {
1039
repaintPlaces(displayConstantNames);
1041
for (Transition t : transitionsArray) {
1045
for (Arc arc : arcsArray) {
1046
arc.updateWeightLabel(displayConstantNames);
1050
for (InhibitorArc arc : inhibitorsArray) {
1051
arc.updateWeightLabel(displayConstantNames);
1057
public DataLayer copy(TimedArcPetriNet tapn) {
1058
DataLayer guiModel = new DataLayer();
1059
Hashtable<PlaceTransitionObject, PlaceTransitionObject> oldToNewMapping = new Hashtable<PlaceTransitionObject, PlaceTransitionObject>();
1061
for(Place p : placesArray) {
1062
if(p instanceof TimedPlaceComponent) {
1063
TimedPlaceComponent place = ((TimedPlaceComponent)p).copy(tapn, guiModel);
1064
oldToNewMapping.put(p, place);
1065
guiModel.addPetriNetObject(place);
1069
for(Transition t : transitionsArray) {
1070
if(t instanceof TimedTransitionComponent) {
1071
TimedTransitionComponent trans = ((TimedTransitionComponent)t).copy(tapn, guiModel);
1072
oldToNewMapping.put(t, trans);
1073
guiModel.addPetriNetObject(trans);
1077
for(Arc arc : arcsArray) {
1078
if(arc instanceof TransportArcComponent) {
1079
TransportArcComponent transArc = ((TransportArcComponent)arc).copy(tapn, guiModel, oldToNewMapping);
1080
guiModel.addPetriNetObject(transArc);
1082
else if(arc instanceof TimedInhibitorArcComponent) {
1083
TimedInhibitorArcComponent inhibArc = ((TimedInhibitorArcComponent)arc).copy(tapn, guiModel, oldToNewMapping);
1084
guiModel.addPetriNetObject(inhibArc);
1086
else if(arc instanceof TimedInputArcComponent) {
1087
TimedInputArcComponent inputArc = ((TimedInputArcComponent)arc).copy(tapn, guiModel, oldToNewMapping);
1088
guiModel.addPetriNetObject(inputArc);
1090
else if(arc instanceof TimedOutputArcComponent) {
1091
TimedOutputArcComponent outputArc = ((TimedOutputArcComponent)arc).copy(tapn, guiModel, oldToNewMapping);
1092
guiModel.addPetriNetObject(outputArc);
1095
throw new RuntimeException("Arc was unknown type");
1099
for(AnnotationNote note : labelsArray) {
1100
AnnotationNote annotation = note.copy();
1101
annotation.setGuiModel(guiModel);
1102
guiModel.addPetriNetObject(annotation);