/// <summary> /// Compiles the given AST <code>ast</code> into a oWFN petri net /// </summary> /// <exception cref="System.NullReferenceException">Thrown when the AST <c>ast</c> is null</exception> /// <returns>An equivalent <c>PetriNet</c> representation</returns> public PetriNet Compile() { if (this.ast == null) { throw new NullReferenceException("AST cannot be null"); } // Phylum net = new PetriNet(); String prefix = net.ActivityCount + ".internal."; Place p1 = net.NewPlace(prefix + "initialized"); Place p2 = net.NewPlace(prefix + "closed"); // Initial Marking p1.Tokens = 1; // Final Marking HashSet <Place> final = new HashSet <Place>(); final.Add(p2); net.AddFinalSet(final); // Compile inner activities int newID = ++net.ActivityCount; net = ast.Compile(net); // Merge final net net.Merge(p1, newID + ".internal.initialized"); net.Merge(p2, newID + ".internal.closed"); return(net); }
public PetriNet Compile(PetriNet phylum) { String prefix = phylum.ActivityCount + ".internal."; Place p1 = phylum.NewPlace(prefix + "initialized"); Place p2 = phylum.NewPlace(prefix + "closed"); // Inner Petri Net Place condition = phylum.NewPlace(prefix + "condition"); Transition evalCondition = phylum.NewTransition(prefix + "evalcondition"); Transition init = phylum.NewTransition(prefix + "initactivity"); Transition end = phylum.NewTransition(prefix + "endwhile"); phylum.NewArc(p1, evalCondition); phylum.NewArc(evalCondition, condition); phylum.NewArc(condition, init); phylum.NewArc(condition, end); phylum.NewArc(end, p2); int currentID = 0; // Inner Activity if (innerActivity != null) { // New Activity phylum.ActivityCount += 1; currentID = phylum.ActivityCount; // Compile innerActivity.Compile(phylum); // Connect phylum.NewArc(init, currentID + ".internal.initialized"); // Merge phylum.Merge(p1, currentID + ".internal.closed"); } else { // Empty phylum.NewArc(init, p1); } return(phylum); }
public PetriNet Compile(PetriNet phylum) { String prefix = phylum.ActivityCount + ".internal."; Place p1 = phylum.NewPlace(prefix + "initialized"); Place p2 = phylum.NewPlace(prefix + "closed"); // Inner Petri Net Place condition = phylum.NewPlace(prefix + "condition"); Transition evalCondition = phylum.NewTransition(prefix + "evalcondition"); phylum.NewArc(p1, evalCondition); phylum.NewArc(evalCondition, condition); // Empty if (innerThen == null && innerElse == null) { Transition finish = phylum.NewTransition(prefix + "finish"); phylum.NewArc(condition, finish); phylum.NewArc(finish, p2); return(phylum); } Transition initThen = phylum.NewTransition(prefix + "initthen"); Transition initElse = phylum.NewTransition(prefix + "inittelse"); phylum.NewArc(condition, initThen); phylum.NewArc(condition, initElse); // Then if (innerThen != null) { // New Activity phylum.ActivityCount += 1; int thenID = phylum.ActivityCount; // Compile innerThen.Compile(phylum); // Connect phylum.NewArc(initThen, thenID + ".internal.initialized"); // Merge phylum.Merge(p2, thenID + ".internal.closed"); } else { // Empty phylum.NewArc(initThen, p2); } // Else if (innerElse != null) { // New Activity phylum.ActivityCount += 1; int elseID = phylum.ActivityCount; // Compile innerElse.Compile(phylum); // Connect phylum.NewArc(initElse, elseID + ".internal.initialized"); // Merge phylum.Merge(p2, elseID + ".internal.closed"); } else { // Empty phylum.NewArc(initElse, p2); } return(phylum); }
public PetriNet Compile(PetriNet phylum) { String prefix = phylum.ActivityCount + ".internal."; Place p1 = phylum.NewPlace(prefix + "initialized"); Place p2 = phylum.NewPlace(prefix + "closed"); // Inner Petri Net Place lastState = p1; IList <int> mergeIds = new List <int>(); for (int i = 1; i <= caseActivities.Count + 1; i++) { if (i <= caseActivities.Count) { Place state = phylum.NewPlace(prefix + "case" + i); Transition evalCase = phylum.NewTransition(prefix + "evalcase" + i); Transition initCase = phylum.NewTransition(prefix + "initcase" + i); phylum.NewArc(lastState, evalCase); phylum.NewArc(evalCase, state); phylum.NewArc(state, initCase); // Activity phylum.ActivityCount += 1; int currentID = phylum.ActivityCount; caseActivities[i - 1].Compile(phylum); // Connect phylum.NewArc(initCase, currentID + ".internal.initialized"); // LastState lastState = state; // Merge ID mergeIds.Add(currentID); } else { Transition initDefault = phylum.NewTransition(prefix + "initdefault"); phylum.NewArc(lastState, initDefault); if (defaultActivity != null) { // Activity phylum.ActivityCount += 1; int currentID = phylum.ActivityCount; defaultActivity.Compile(phylum); // Connect phylum.NewArc(initDefault, currentID + ".internal.initialized"); // Merge ID mergeIds.Add(currentID); } else { // Empty Connect phylum.NewArc(initDefault, p2); } } } // Merge foreach (int id in mergeIds) { phylum.Merge(p2, id + ".internal.closed"); } return(phylum); }