/// <summary> /// Converts the net more or less reliable to a string which can be read as a *.dot-File by Graphviz (http://www.graphviz.org/) /// </summary> /// <returns>Returns said string, which you have to put into a file.</returns> public String ConvertToDot() { StringBuilder content = new StringBuilder(); content.Append("digraph TC {\n"); content.Append("node[shape=circle];\nrankdir=LR\n"); // draw all places with their respective labels and amount of tokens (p0 [label="A (1)"]) for (int index = 0; index <= Places.Count() - 1; index++) { content.Append("p" + index + " [label=\"" + Places[index].Name + " (" + Places[index].Token + ")\"]\n"); } content.Append("node[shape=rect];\n"); // draw all transitions with their respective labels (t0 [label="AtoB"]) for (int index = 0; index <= Transitions.Count() - 1; index++) { content.Append("t" + index + " [label=\"" + Transitions[index].Name + "\"]\n"); // and for each transition draw the incoming (p0 -> t0)... foreach (Place incomingPlace in Transitions[index].IncomingPlaces) { content.Append("p" + Places.IndexOf(incomingPlace) + " -> " + "t" + index + "\n"); } // ... and outgoing (t0 -> p1) connections foreach (Place outgoingPlace in Transitions[index].OutgoingPlaces) { content.Append("t" + index + " -> " + "p" + Places.IndexOf(outgoingPlace) + "\n"); } } content.Append("}"); return(content.ToString()); }
/// <summary> /// Returns the number of transitions that are not AND-Transitions. Note that this method uses a cache for performance. /// </summary> /// <returns></returns> /// <author>Jannik Arndt</author> public int CountTransitionsWithoutANDs() { // Only go through all transitions if the overall number of transitions has changed // This has a HUGE performance impact! if (Transitions.Count() != _transitionsCountCache) { int counter = Transitions.Count(transition => !transition.Name.StartsWith("AND") && !String.IsNullOrEmpty(transition.Name) && !transition.IsANDJoin && !transition.IsANDSplit); _transitionsCountCache = Transitions.Count(); _transitionsWithoutANDCountCache = counter; } return(_transitionsWithoutANDCountCache); }
/// <summary> /// Converts the net more or less reliable to a string which can be read as a *.pnml by (http://woped.dhbw-karlsruhe.de/woped/) /// </summary> /// /// <autor>Naby M. Sow</autor> /// <returns>Returns said string, which you have to put into a file.</returns> public String ConvertToPNML() { const string cID = "cId-0"; StringBuilder content = new StringBuilder(); content.Append("<pnml xmlns=\"http://www.pnml.org/version-2009/grammar/pnml\">\n"); content.Append(" <net id=\"" + cID + "\" type=\"http://www.pnml.org/version-2009/grammar/ptnet\">\n"); content.Append(" <page id=\"page0\">\n"); for (int index = 0; index < Places.Count(); index++) { string placeId = "p" + index; string placeName = Places[index].Name; int positionX = Places[index].PositionX; int positionY = Places[index].PositionY; content.Append(" <place id=\"" + placeId + "\">\n"); content.Append(" <name>\n"); content.Append(" <text>" + placeName + "</text>\n"); content.Append(" <graphics>\n"); content.Append(" <offset x=\"" + (positionX + 6) + "\" y=\"" + (positionY + 6) + " \"/>\n"); content.Append(" </graphics>\n"); content.Append(" </name>\n"); content.Append(" <graphics>\n"); content.Append(" <position x=\"" + positionX + "\" y=\"" + positionY + "\"/>\n"); content.Append(" </graphics>\n"); content.Append(" </place>\n"); } for (int index = 0; index < Transitions.Count(); index++) { string transitionId = "t" + index; string transitionName = Transitions[index].Name; int positionX = Transitions[index].PositionX; int positionY = Transitions[index].PositionY; content.Append(" <transition id=\"" + transitionId + "\">\n"); content.Append(" <name>\n"); content.Append(" <text>" + transitionName + "</text>\n"); content.Append(" <graphics>\n"); content.Append(" <offset x=\"" + (positionX + 9) + "\" y=\"" + (positionY + 9) + "\"/>\n"); content.Append(" </graphics>\n"); content.Append(" </name>\n"); content.Append(" <graphics>\n"); content.Append(" <position x=\"" + positionX + "\" y=\"" + positionY + "\"/>\n"); content.Append(" </graphics>\n"); content.Append(" </transition>\n"); } int sourcePlaceId = 0; foreach (Place sourcePlace in Places) { int targetTransitionId = 0; foreach (Transition targetTransition in sourcePlace.OutgoingTransitions) { string arcId = "p2t" + ((sourcePlaceId + 1) + (sourcePlaceId + 1) * (targetTransitionId + 1)); //calculation for unique id string arcSource = GetPlaceID(sourcePlace); string arcTarget = GetTransitionID(targetTransition); content.Append(" <arc id=\"" + arcId + "\" " + "source=\"" + arcSource + "\" " + "target=\"" + arcTarget + "\">\n"); content.Append(" <graphics/>\n"); content.Append(" </arc>\n"); targetTransitionId++; } sourcePlaceId++; } int sourceTransitionId = 0; foreach (Transition sourceTransition in Transitions) { int targetPlaceId = 0; foreach (Place targetPlace in sourceTransition.OutgoingPlaces) { string arcId = "t2p" + ((sourceTransitionId + 1) + (sourceTransitionId + 1) * (targetPlaceId + 1)); //calculation for unique id string arcSource = GetTransitionID(sourceTransition); string arcTarget = GetPlaceID(targetPlace); content.Append(" <arc id=\"" + arcId + "\" " + "source=\"" + arcSource + "\" " + "target=\"" + arcTarget + "\">\n"); content.Append(" <graphics/>\n"); content.Append(" </arc>\n"); targetPlaceId++; } sourceTransitionId++; } content.Append(" </page>\n"); content.Append(" <name>\n"); content.Append(" <text></text>\n"); content.Append(" </name>\n"); content.Append(" </net>\n"); content.Append("</pnml>\n"); return(content.ToString()); }
/// <summary> /// Counts all Transitions that are marked as a loop (.IsLoop == true) /// </summary> /// <returns></returns> /// <author>Jannik Arndt</author> public int CountLoops() { return(Transitions.Count(transition => transition.IsLoop)); }