private PetriNetPlace AddPlaceBetweenTransitions(PetriNetDefinition definition, RelationshipMatrix matrix, PetriNetTransition from, PetriNetTransition to) { PetriNetPlace result = null; foreach (var flowFrom in to.From) { var placeFrom = flowFrom.From; var flowOrigin = placeFrom.From[0]; var transOrigin = flowOrigin.From; var relTypeFrom = matrix[Tuple.Create(from.Name, transOrigin.Name)]; if (relTypeFrom == RelationshipType.NotFollow) //(c) XOR-Join pattern: a -> c, b -> c, and a#b { result = placeFrom as PetriNetPlace; definition.AddFlow(null, from, result); return(null); } } var relType = matrix[Tuple.Create(from.Name, to.Name)]; if (relType == RelationshipType.Cause) //(a) Sequence pattern: a -> b { result = definition.AddPlace(null, PetriNetPlaceType.Middle); definition.AddFlow(null, from, result); definition.AddFlow(null, result, to); } return(result); }
static void PrintPetriNetDefinition(PetriNetDefinition definition) { //Places Console.Write("P = {"); var i = 0; foreach (var place in definition.Places.Values) { if (i > 0) { Console.Write(", "); } Console.Write(place.Name); i++; } Console.WriteLine("}"); //Transitions Console.Write("T = {"); i = 0; foreach (var transition in definition.Transitions.Values) { if (i > 0) { Console.Write(", "); } Console.Write(transition.Name); i++; } Console.WriteLine("}"); //Flows Console.Write("F = {"); i = 0; foreach (var flow in definition.Flows.Values) { if (i > 0) { Console.Write(", "); } Console.Write("(" + flow.From.Name + ", " + flow.To.Name + ")"); i++; } Console.WriteLine("}"); }
public PetriNetDefinition Definition() { var result = new PetriNetDefinition(); //Start and End Places var startPlace = result.AddPlace(null, PetriNetPlaceType.Start); var endPlace = result.AddPlace(null, PetriNetPlaceType.End); //Transitions var activities = this._simpleEventLog.Activities(); var actRelationships = this._simpleEventLog.ActivitiesAndRelationships(); var matrixRelationships = this._simpleEventLog.SearchRelationships(); foreach (var activity in activities) { result.AddTransition(activity); } //Places and Flows foreach (var activity in activities) { var rel = actRelationships[activity]; var trans = result.Transitions[activity]; if (rel.Prior.Count == 0) { result.AddFlow(null, startPlace, trans); } if (rel.Next.Count == 0) { result.AddFlow(null, trans, endPlace); } else { var listNext = rel.Next.Values.ToList(); var listPlaces = new List <PetriNetPlace>(); foreach (var nextTrans in listNext) { if (listPlaces.Count == 0) { var newPlace = AddPlaceBetweenTransitions(result, matrixRelationships, trans, result.Transitions[nextTrans.Name]); if (newPlace != null) { listPlaces.Add(newPlace); } } else { foreach (var place in listPlaces) { var placeTo = place.To[0].To.Name; var relType = matrixRelationships[Tuple.Create(nextTrans.Name, placeTo)]; if (relType == RelationshipType.NotFollow) //(b) XOR-Split pattern: a -> b, b -> c, and b#c { result.AddFlow(null, place, result.Transitions[nextTrans.Name]); break; } else if (relType == RelationshipType.ReciprocalFollow) //(d) AND-Split pattern: a -> b, b -> c, and b||c { var newPlace = AddPlaceBetweenTransitions(result, matrixRelationships, trans, result.Transitions[nextTrans.Name]); if (newPlace != null) { listPlaces.Add(newPlace); } break; } } } } } } return(result); }