Skip to content

Commit 04f2296

Browse files
authored
Export inhibitor arcs for CPNs (TAPAAL#71)
* write inhibitor arcs as well * fix function to write inhibitor arcs * parse inhib weight
1 parent 088177a commit 04f2296

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

include/PetriEngine/Colored/PnmlWriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ namespace PetriEngine::Colored {
9090
void handleOtherColor(const Color *const c);
9191

9292
void handleNumberOf(std::pair<const PetriEngine::Colored::Color *const, uint32_t> numberOff);
93+
94+
void inhibitorArcs();
95+
96+
void writeInhibitorExpressionToPnml(Colored::Arc inhibitor);
9397
};
9498
}
9599

src/PetriEngine/Colored/PnmlWriter.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ namespace PetriEngine {
175175
places();
176176
transitions();
177177
arcs();
178+
inhibitorArcs();
178179
_out << decreaseTabs() << "</page>\n";
179180
}
180181

@@ -366,7 +367,6 @@ namespace PetriEngine {
366367

367368
void PnmlWriter::arcs() {
368369
_out << getTabs() << "<!-- List of arcs -->\n";
369-
uint32_t index = 0;
370370
for (auto &arc: _arcs) {
371371
shared_const_string source;
372372
shared_const_string target;
@@ -377,10 +377,11 @@ namespace PetriEngine {
377377
source = _builder._transitions[arc.transition].name;
378378
target = _builder._places[arc.place].name;
379379
}
380-
_out << getTabs() << "<arc id=\"arc" << index << "\" source=\"" << *source << "\" target=\"" << *target
381-
<< "\">\n";
380+
std::string id = *source + "_to_" + *target;
381+
_out << getTabs() << "<arc id=\"" << id << "\" source=\"" << *source << "\" target=\"" << *target
382+
<< "\" type=\"normal" << "\">\n";
382383
_out << increaseTabs() << "<name>\n";
383-
_out << increaseTabs() << "<text>" << index << "</text>\n";
384+
_out << increaseTabs() << "<text>" << id << "</text>\n";
384385
_out << decreaseTabs() << "</name>\n";
385386
_out << getTabs() << "<hlinscription>\n";
386387
_out << increaseTabs() << "<text>" << to_string(*arc.expr) << "</text>\n";
@@ -389,10 +390,54 @@ namespace PetriEngine {
389390
_out << getTabs() << "</structure>\n";
390391
_out << decreaseTabs() << "</hlinscription>\n";
391392
_out << decreaseTabs() << "</arc>\n";
392-
index++;
393393
}
394394
}
395395

396+
void PnmlWriter::inhibitorArcs() {
397+
_out << getTabs() << "<!-- List of inhibitor arcs -->\n";
398+
for (auto &inhibitor: _builder.inhibitors()) {
399+
Place &place = _builder._places[inhibitor.place];
400+
shared_const_string source = place.name;
401+
shared_const_string target = _builder._transitions[inhibitor.transition].name;
402+
std::string id = *source + "_to_" + *target;
403+
_out << getTabs() << "<arc id=\"" << id << "\" source=\"" << *source << "\" target=\"" << *target
404+
<< "\" type=\"inhibitor" << "\">\n";
405+
_out << increaseTabs() << "<name>\n";
406+
_out << increaseTabs() << "<text>" << id << "</text>\n";
407+
_out << decreaseTabs() << "</name>\n";
408+
_out << getTabs() << "<hlinscription>\n";
409+
410+
_out << increaseTabs() << "<text>" << inhibitor.inhib_weight << "'" << place.type->getName() << ".all"
411+
<< "</text>\n";
412+
_out << getTabs() << "<structure>\n";
413+
writeInhibitorExpressionToPnml(inhibitor);
414+
_out << decreaseTabs() << "</structure>\n";
415+
_out << decreaseTabs() << "</hlinscription>\n";
416+
_out << decreaseTabs() << "</arc>\n";
417+
}
418+
}
419+
420+
void PnmlWriter::writeInhibitorExpressionToPnml(Colored::Arc inhibitor) {
421+
_out << increaseTabs() << "<numberof>\n";
422+
423+
//First subterm with the multiplicity
424+
_out << increaseTabs() << "<subterm>\n";
425+
_out << increaseTabs() << "<numberconstant value=\"" << inhibitor.inhib_weight << "\">\n";
426+
_out << increaseTabs() << "<positive/>\n";
427+
_out << decreaseTabs() << "</numberconstant>\n";
428+
_out << decreaseTabs() << "</subterm>\n";
429+
430+
//Second subterm with the colortype
431+
_out << getTabs() << "<subterm>\n";
432+
_out << increaseTabs() << "<all>\n";
433+
Place &place = _builder._places[inhibitor.place];
434+
_out << increaseTabs() << "<usersort declaration=\"" << place.type->getName() << "\"/>\n";
435+
_out << decreaseTabs() << "</all>\n";
436+
_out << decreaseTabs() << "</subterm>\n";
437+
438+
_out << decreaseTabs() << "</numberof>\n";
439+
}
440+
396441
void PnmlWriter::metaInfoClose() {
397442
_out << decreaseTabs() << "</net>\n"
398443
<< decreaseTabs() << "</pnml>";

src/PetriParse/PNMLParser.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,26 @@ void PNMLParser::parseArc(rapidxml::xml_node<>* element, bool inhibitor) {
669669

670670
bool first = true;
671671
auto weightTag = element->first_attribute("weight");
672-
if(weightTag != nullptr){
672+
if(weightTag != nullptr) {
673673
weight = atoi(weightTag->value());
674674
assert(weight > 0);
675+
} else if (isColored && inhibitor) {
676+
auto hlin = element->first_node("hlinscription");
677+
if (hlin != nullptr) {
678+
auto structure = hlin->first_node("structure");
679+
if (structure != nullptr) {
680+
auto numberOf = structure->first_node("numberof");
681+
if (numberOf != nullptr) {
682+
for (auto subterm = numberOf->first_node("subterm"); subterm; subterm = subterm->next_sibling("subterm")) {
683+
auto numberConstant = subterm->first_node("numberconstant");
684+
if (numberConstant != nullptr) {
685+
auto valueTag = numberConstant->first_attribute("value");
686+
weight = atoi(valueTag->value());
687+
}
688+
}
689+
}
690+
}
691+
}
675692
} else {
676693
for (auto it = element->first_node("inscription"); it; it = it->next_sibling("inscription")) {
677694
std::string text;

0 commit comments

Comments
 (0)