Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed activator arc conflict issues

  • Loading branch information...
commit 5b35872e0cd6913ee6f570245fa7c9b15b26576a 1 parent 319951a
@Thulinma authored
Showing with 14 additions and 5 deletions.
  1. +8 −4 petricalc.cpp
  2. +6 −1 petricalc.h
View
12 petricalc.cpp
@@ -147,9 +147,9 @@ void PetriNet::parseEdges(TiXmlNode * N){
d = 0;
while ((d = c->IterateChildren(d))){addEdge(d, EDGE_READ);}
}
- fprintf(stderr, "Loaded %u edges\n", (unsigned int)edges.size());
//other types not supported yet
}
+ fprintf(stderr, "Loaded %u edges\n", (unsigned int)edges.size());
}
void PetriNet::addEdge(TiXmlNode * N, edgeType E){
@@ -306,15 +306,16 @@ bool PetriNet::CalculateStep(){
}
//all conflicting transitions consume their input in random order, one time
+ //calculations are done as "midstep" type to prevent activator arcs from disabling already enabled edges
while (conflict.size() > 0){
std::random_shuffle(conflict.begin(), conflict.end());
- unsigned int cnt = isEnabled(conflict[0]);
+ unsigned int cnt = isEnabled(conflict[0], CALC_MIDSTEP);
if (cnt < 1){
conflict.erase(conflict.begin());
}else{
counter[conflict[0]] += 1;//mark transition
doInput(conflict[0], 1);
- if (isEnabled(conflict[0]) < 1){conflict.erase(conflict.begin());}
+ if (isEnabled(conflict[0], CALC_MIDSTEP) < 1){conflict.erase(conflict.begin());}
}
}
@@ -398,7 +399,7 @@ bool PetriNet::findInput(unsigned int src, std::string expression, std::map<std:
}
/// Returns how many times this expression can fire currently
-unsigned int PetriNet::isEnabled(unsigned int T){
+unsigned int PetriNet::isEnabled(unsigned int T, calcType C){
std::map<std::string, std::string> vars;
std::set<unsigned int>::iterator edgeit;
unsigned int fire_count = 0xFFFFFFFF; //start with maximum possible
@@ -406,6 +407,9 @@ unsigned int PetriNet::isEnabled(unsigned int T){
return 0;/// \todo guard support
}else{
for (edgeit = transitions[T].inputs.begin(); edgeit != transitions[T].inputs.end(); edgeit++){
+ //skip read edges if calculation type is midstep
+ if ((C == CALC_MIDSTEP) && (edges[*edgeit].etype == EDGE_READ)){continue;}
+
if (edges[*edgeit].multiplicity > 0){
//no expression, just a number
if (places[edges[*edgeit].source].iMarking >= edges[*edgeit].multiplicity){
View
7 petricalc.h
@@ -32,6 +32,11 @@ enum edgeType{
EDGE_READ
};
+enum calcType{
+ CALC_FULL,
+ CALC_MIDSTEP
+};
+
/// A PetriNet Edge - holds a single edge's state information.
class PetriEdge{
public:
@@ -62,7 +67,7 @@ class PetriNet{
void PrintState();///< Prints the current net state, seperated by tabs, followed by a newline.
void PrintStateHeader(std::map<std::string, unsigned int> & cellnames);
void PrintState(std::map<std::string, unsigned int> & cellnames);
- unsigned int isEnabled(unsigned int T);///< Returns how many times this transition is enabled.
+ unsigned int isEnabled(unsigned int T, calcType C = CALC_FULL);///< Returns how many times this transition is enabled.
std::map<unsigned int, PetriPlace> places;
std::map<unsigned int, PetriTrans> transitions;
std::map<unsigned int, PetriEdge> edges;
Please sign in to comment.
Something went wrong with that request. Please try again.