Skip to content

Commit

Permalink
FiringMode parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tand00 committed Aug 19, 2024
1 parent 213e144 commit 84ed7f1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
6 changes: 6 additions & 0 deletions include/Colored/ColoredNetStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ namespace unfoldtacpn {
double param1;
double param2;
};
enum FiringMode {
Oldest,
Youngest,
Random
};
}

struct Arc {
Expand Down Expand Up @@ -68,6 +73,7 @@ namespace unfoldtacpn {
SMC::Distribution distribution;
SMC::DistributionParameters distributionParams;
double weight;
SMC::FiringMode firingMode;
std::vector<Arc> arcs;
std::vector<TransportArc> transport;
};
Expand Down
3 changes: 2 additions & 1 deletion include/Colored/ColoredPetriNetBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace unfoldtacpn {
double y,
Colored::SMC::Distribution distrib = Colored::SMC::Constant,
Colored::SMC::DistributionParameters params = { 0.0, 0.0 },
double weight = 1.0);
double weight = 1.0,
Colored::SMC::FiringMode firingMode = Colored::SMC::Oldest);
void addArc(const std::string& source, const std::string& target,
int weight, bool inhibitor, const unfoldtacpn::Colored::ArcExpression_ptr &expr,
const std::vector<unfoldtacpn::Colored::TimeInterval>& intervals);
Expand Down
2 changes: 1 addition & 1 deletion include/TAPNBuilderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace unfoldtacpn {
// add a time transition with a unique name
virtual void addTransition(const std::string &name, int player, bool urgent,
double, double,
int distrib = 0, double distribParam1 = 1, double distribParam2 = 1, double weight = 1.0) = 0;
int distrib = 0, double distribParam1 = 1, double distribParam2 = 1, double weight = 1.0, int firingMode = 0) = 0;

/* Add timed colored input arc with given arc expression*/
virtual void addInputArc(const std::string &place,
Expand Down
7 changes: 4 additions & 3 deletions src/Colored/ColoredPetriNetBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ namespace unfoldtacpn {
double y,
Colored::SMC::Distribution distrib,
Colored::SMC::DistributionParameters params,
double weight) {
double weight,
Colored::SMC::FiringMode firingMode) {
if (_transitionnames.count(name) == 0) {
uint32_t next = _transitionnames.size();
_transitions.emplace_back(Colored::Transition {name, guard, player, urgent, distrib, params, weight});
_transitions.emplace_back(Colored::Transition {name, guard, player, urgent, distrib, params, weight, firingMode});
_transitionnames[name] = next;
_transitionlocations.push_back(std::tuple<double, double>(x,y));
}
Expand Down Expand Up @@ -318,7 +319,7 @@ namespace unfoldtacpn {
}

builder.addTransition(name, transition.player, transition.urgent, std::get<0>(transitionPos), std::get<1>(transitionPos) + offset,
transition.distribution, transition.distributionParams.param1, transition.distributionParams.param2, transition.weight);
transition.distribution, transition.distributionParams.param1, transition.distributionParams.param2, transition.weight, transition.firingMode);
_pttransitionnames[transition.name].push_back(name);
for (auto& arc : transition.arcs) {
unfoldArc(builder, arc, b, name);
Expand Down
26 changes: 19 additions & 7 deletions src/PetriParse/PNMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ void PNMLParser::parseTransition(rapidxml::xml_node<>* element) {
Colored::SMC::Distribution distrib = Colored::SMC::Constant;
Colored::SMC::DistributionParameters distrib_params = { 1.0, 0.0 };
double weight = 1.0;
Colored::SMC::FiringMode firingMode = Colored::SMC::Oldest;

auto posX = element->first_attribute("positionX");
if (posX != nullptr){
Expand Down Expand Up @@ -808,6 +809,17 @@ void PNMLParser::parseTransition(rapidxml::xml_node<>* element) {
weight = atof(weight_el->value());
}

auto firing_el = element->first_attribute("firingMode");
if(firing_el != nullptr) {
if (strcasecmp(firing_el->value(), "oldest") == 0) {
firingMode = Colored::SMC::Oldest;
} else if (strcasecmp(firing_el->value(), "youngest") == 0) {
firingMode = Colored::SMC::Youngest;
} else if (strcasecmp(firing_el->value(), "random") == 0) {
firingMode = Colored::SMC::Random;
}
}

for (auto it = element->first_node(); it; it = it->next_sibling()) {
if (strcmp(it->name(), "graphics") == 0) {
parsePosition(it, x, y);
Expand All @@ -821,7 +833,7 @@ void PNMLParser::parseTransition(rapidxml::xml_node<>* element) {
exit(ErrorCode);
}
}
_builder->addTransition(name, expr, player, urgent, x, y, distrib, distrib_params, weight);
_builder->addTransition(name, expr, player, urgent, x, y, distrib, distrib_params, weight, firingMode);
}

std::tuple<Colored::SMC::Distribution, Colored::SMC::DistributionParameters> PNMLParser::parseDistribution(rapidxml::xml_node<>* element) {
Expand All @@ -830,25 +842,25 @@ std::tuple<Colored::SMC::Distribution, Colored::SMC::DistributionParameters> PNM
auto distrib_el = element->first_attribute("distribution");
if(distrib_el != nullptr) {
char* distrib_name = distrib_el->value();
if(strcmp(distrib_name, "constant") == 0) {
if(strcasecmp(distrib_name, "constant") == 0) {
distrib = Colored::SMC::Constant;
distrib_params.param1 = atof(element->first_attribute("value")->value());
} else if(strcmp(distrib_name, "uniform") == 0) {
} else if(strcasecmp(distrib_name, "uniform") == 0) {
distrib = Colored::SMC::Uniform;
distrib_params.param1 = atof(element->first_attribute("a")->value());
distrib_params.param2 = atof(element->first_attribute("b")->value());
} else if(strcmp(distrib_name, "exponential") == 0) {
} else if(strcasecmp(distrib_name, "exponential") == 0) {
distrib = Colored::SMC::Exponential;
distrib_params.param1 = atof(element->first_attribute("rate")->value());
} else if(strcmp(distrib_name, "normal") == 0) {
} else if(strcasecmp(distrib_name, "normal") == 0) {
distrib = Colored::SMC::Normal;
distrib_params.param1 = atof(element->first_attribute("mean")->value());
distrib_params.param2 = atof(element->first_attribute("stddev")->value());
} else if(strcmp(distrib_name, "gamma") == 0) {
} else if(strcasecmp(distrib_name, "gamma") == 0) {
distrib = Colored::SMC::Gamma;
distrib_params.param1 = atof(element->first_attribute("shape")->value());
distrib_params.param2 = atof(element->first_attribute("scale")->value());
} else if(strcmp(distrib_name, "discrete uniform") == 0) {
} else if(strcasecmp(distrib_name, "discrete uniform") == 0) {
distrib = Colored::SMC::DiscreteUniform;
distrib_params.param1 = atof(element->first_attribute("a")->value());
distrib_params.param2 = atof(element->first_attribute("b")->value());
Expand Down

0 comments on commit 84ed7f1

Please sign in to comment.