private ArrayList<String> getBiArcPlaces(PipeTransition pipeTransition) { ArrayList<String> placeNames = new ArrayList<String>(); // bidirectional arcs @SuppressWarnings("rawtypes") Iterator inputArcIterator = pipeTransition.getConnectToIterator(); while (inputArcIterator.hasNext()) { Arc inputArc = (Arc) (inputArcIterator.next()); if (inputArc instanceof BidirectionalArc) { placeNames.add(inputArc.getSource().getName()); } } @SuppressWarnings("rawtypes") Iterator outputArcIterator = pipeTransition.getConnectFromIterator(); while (outputArcIterator.hasNext()) { Arc outputArc = (Arc) (outputArcIterator.next()); if (outputArc instanceof BidirectionalArc) { placeNames.add(outputArc.getTarget().getName()); } } /*System.out.println(pipeTransition.getName()+" biarc places: "); for (String place: placeNames) System.out.print(place+" "); */ return placeNames; }
private ArrayList<Predicate> getPostcondition(PipeTransition pipeTransition) throws ParseException { ArrayList<Predicate> postcondition = new ArrayList<Predicate>(); // bidirectional arcs @SuppressWarnings("rawtypes") Iterator inputArcIterator = pipeTransition.getConnectToIterator(); while (inputArcIterator.hasNext()) { Arc inputArc = (Arc) (inputArcIterator.next()); if (inputArc instanceof BidirectionalArc) { String placeName = inputArc.getSource().getName(); for (Predicate predicate : getPredicateListFromArc(placeName, inputArc)) postcondition.add(predicate); } } // directed arcs @SuppressWarnings("rawtypes") Iterator outputArcIterator = pipeTransition.getConnectFromIterator(); while (outputArcIterator.hasNext()) { Arc outputArc = (Arc) (outputArcIterator.next()); String placeName = outputArc.getTarget().getName(); if (isRESETArcLabel(outputArc)) { ArrayList<String> arguments = new ArrayList<String>(); arguments.add(placeName); postcondition.add(new Predicate(MID.RESET, arguments)); } else { for (Predicate predicate : getPredicateListFromArc(placeName, outputArc)) postcondition.add(predicate); } } return postcondition; }
private void checkForOutputPlaces( PrTPanel parentNet, PipeTransition pipeTransition, PrTPanel childNet) throws ParseException { for (String placeNameInParentNet : getOutputPlaces(pipeTransition)) { PipePlace placeInSubNet = pipePlaceInSubNet(placeNameInParentNet, childNet); if (placeInSubNet == null) throw new ParseException( modelNameMessage(parentNet) + LocaleBundle.bundleString("transition") + " " + pipeTransition.getName() + ": " + LocaleBundle.bundleString("place") + " " + placeNameInParentNet + " " + LocaleBundle.bundleString("DOES_NOT_EXIST_IN_THE_SUBMODEL") + " " + modelNameMessage(childNet) + "."); boolean found = false; @SuppressWarnings("rawtypes") Iterator arcIterator = placeInSubNet.getConnectToIterator(); while (arcIterator.hasNext() && !found) { Arc arc = (Arc) (arcIterator.next()); if (!(arc instanceof InhibitorArc)) found = true; } if (!found) { @SuppressWarnings("rawtypes") Iterator biarcIterator = placeInSubNet.getConnectFromIterator(); while (biarcIterator.hasNext() && !found) { Arc arc = (Arc) (biarcIterator.next()); if (arc instanceof BidirectionalArc) found = true; } } if (!found) throw new ParseException( modelNameMessage(parentNet) + LocaleBundle.bundleString("transition") + " " + pipeTransition.getName() + ": " + LocaleBundle.bundleString("place") + " " + placeNameInParentNet + " " + LocaleBundle.bundleString("IS_NOT_AN_OUTPUT_PLACE_IN_THE_SUBMODEL") + " " + modelNameMessage(childNet) + "."); } }
private void parseTransitions(MID mid, PrTPanel prtNet) throws ParseException { ArrayList<Predicate> globalPredicates = parseGlobalPredicates(mid, prtNet); DataLayerInterface net = prtNet.getModel(); PipeTransition[] pipeTransitions = net.getTransitions(); for (int i = 0; i < pipeTransitions.length; i++) { PipeTransition pipeTransition = pipeTransitions[i]; if (pipeTransition.hasValidSubnetFile() && editor.getKernel().getSystemOptions().isNetHierarchyEnabled()) { PrTPanel subModel = editor.findPrTPanelForFile(pipeTransition.getSubnetFileHandler()); if (subModel != null) { // check composition rules, e.g., place names checkForCompositionErrors(prtNet, pipeTransition, subModel); parseTransitions(mid, subModel); } } else parsePipeTransition(mid, prtNet, pipeTransition, globalPredicates); // System.out.println("Transition ID: "+pipeTransitions[i].getId()+" Name: // "+pipeTransitions[i].getName()); } }
private ArrayList<Predicate> getPrecondition(PipeTransition pipeTransition) throws ParseException { ArrayList<Predicate> precondition = new ArrayList<Predicate>(); // bidirectional arcs @SuppressWarnings("rawtypes") Iterator outputArcIterator = pipeTransition.getConnectFromIterator(); while (outputArcIterator.hasNext()) { Arc outputArc = (Arc) (outputArcIterator.next()); if (outputArc instanceof BidirectionalArc) { String placeName = outputArc.getTarget().getName(); for (Predicate predicate : getPredicateListFromArc(placeName, outputArc)) precondition.add(predicate); } } // directed arcs @SuppressWarnings("rawtypes") Iterator inputArcIterator = pipeTransition.getConnectToIterator(); while (inputArcIterator.hasNext()) { Arc inputArc = (Arc) (inputArcIterator.next()); if (!(inputArc instanceof InhibitorArc)) { String placeName = inputArc.getSource().getName(); for (Predicate predicate : getPredicateListFromArc(placeName, inputArc)) precondition.add(predicate); } } // inhibitor arcs @SuppressWarnings("rawtypes") Iterator inhibitorArcIterator = pipeTransition.getConnectToIterator(); while (inhibitorArcIterator.hasNext()) { Arc inhibitorArc = (Arc) (inhibitorArcIterator.next()); if (inhibitorArc instanceof InhibitorArc) { String placeName = inhibitorArc.getSource().getName(); for (Predicate predicate : getPredicateListFromArc(placeName, inhibitorArc)) precondition.add(predicate); } } return precondition; }
private ArrayList<String> getInhibitorPlaces(PipeTransition pipeTransition) { ArrayList<String> placeNames = new ArrayList<String>(); // inhibitor arcs @SuppressWarnings("rawtypes") Iterator inhibitorArcIterator = pipeTransition.getConnectToIterator(); while (inhibitorArcIterator.hasNext()) { Arc inhibitorArc = (Arc) (inhibitorArcIterator.next()); if (inhibitorArc instanceof InhibitorArc) { placeNames.add(inhibitorArc.getSource().getName()); } } /*System.out.println("\n"+pipeTransition.getName()+" inhibitor places: "); for (String place: placeNames) System.out.print(place+" "); */ return placeNames; }
private ArrayList<String> getOutputPlaces(PipeTransition pipeTransition) { ArrayList<String> placeNames = getBiArcPlaces(pipeTransition); // directed arcs @SuppressWarnings("rawtypes") Iterator outputArcIterator = pipeTransition.getConnectFromIterator(); while (outputArcIterator.hasNext()) { Arc outputArc = (Arc) (outputArcIterator.next()); if (outputArc instanceof NormalArc) { placeNames.add(outputArc.getTarget().getName()); } } /*System.out.println("\n"+pipeTransition.getName()+" output places: "); for (String place: placeNames) System.out.print(place+" "); */ return placeNames; }
private void parsePipeTransition( MID mid, PrTPanel prtNet, PipeTransition pipeTransition, ArrayList<Predicate> globalPredicates) throws ParseException { String transitionSignature = pipeTransition.getName(); Transition istaTransition = null; Predicate signaturePredicate = null; try { signaturePredicate = MIDParser.parseTransitionSignatureString(transitionSignature); istaTransition = new Transition(signaturePredicate.getName()); istaTransition.setArguments(signaturePredicate.getArguments()); } catch (Exception e) { throw new ParseException(e.toString()); } ArrayList<Predicate> precondition = getPrecondition(pipeTransition); ArrayList<Predicate> postcondition = getPostcondition(pipeTransition); if (globalPredicates.size() > 0) { for (int index = globalPredicates.size() - 1; index >= 0; index--) { Predicate global = globalPredicates.get(index); precondition.add(0, global); postcondition.add(0, global); } } istaTransition.setPrecondition(precondition); istaTransition.setPostcondition(postcondition); try { String whenString = pipeTransition.getGuard().trim(); if (whenString != null && !whenString.equals("")) { MIDParser.parseWhenCondition(istaTransition, whenString); } } catch (Exception e) { throw new ParseException( modelNameMessage(prtNet) + transitionSignature + " " + LocaleBundle.bundleString("Guard condition") + ":" + e.toString()); } MIDParser.checkTransitionArguments( transitionSignature, signaturePredicate.getArguments(), precondition, istaTransition.getWhenCondition()); MIDParser.checkWhenConditionVariables(precondition, istaTransition.getWhenCondition()); try { String effectString = pipeTransition.getEffect().trim(); ArrayList<Predicate> effect = MIDParser.parseConditionString(effectString); istaTransition.setEffect(effect); } catch (Exception e) { throw new ParseException( modelNameMessage(prtNet) + transitionSignature + " " + LocaleBundle.bundleString("Effect") + ": " + e.toString()); } istaTransition.collectAllVariables(); MIDParser.checkPostconditionVariables(istaTransition); istaTransition.setId(pipeTransition.getId()); mid.addTransition(istaTransition); mid.putPipeTransition(istaTransition, pipeTransition); }