98
102
if (source.isPlace && !target.isPlace) {
100
builder->addInputArc(source.id, target.id, false, arc.weight);
104
builder->addInputArc(source.id, target.id, arc.inhib, arc.weight);
102
builder->addInputArc(source.id, target.id, arc.expr);
106
builder->addInputArc(source.id, target.id, arc.expr, arc.inhib, arc.weight);
105
109
} else if (!source.isPlace && target.isPlace) {
115
119
target.id.c_str());
119
for(Arc& inhibitor : inhibarcs)
121
NodeName source = id2name[inhibitor.source];
122
NodeName target = id2name[inhibitor.target];
123
if (source.isPlace && !target.isPlace) {
124
builder->addInputArc(source.id, target.id, true, inhibitor.weight);
129
"XML Parsing error: Inhibitor from \"%s\" to \"%s\" is not valid!\n",
135
123
//Unset the builder
136
124
this->builder = nullptr;
196
183
void PNMLParser::parseNamedSort(rapidxml::xml_node<>* element) {
197
184
auto type = element->first_node();
198
auto ct = strcmp(type->name(), "productsort") == 0 ?
199
new PetriEngine::Colored::ProductType(std::string(element->first_attribute("id")->value())) :
200
new PetriEngine::Colored::ColorType(std::string(element->first_attribute("id")->value()));
185
const PetriEngine::Colored::ColorType* fct = nullptr;
202
186
if (strcmp(type->name(), "dot") == 0) {
204
} else if (strcmp(type->name(), "productsort") == 0) {
205
bool missingType = false;
206
for (auto it = type->first_node(); it; it = it->next_sibling()) {
207
if (strcmp(it->name(), "usersort") == 0) {
208
auto ctName = it->first_attribute("declaration")->value();
209
if(!missingType && colorTypes.count(ctName)){
210
((PetriEngine::Colored::ProductType*)ct)->addType(colorTypes[ctName]);
213
missingCTs.push_back(std::make_pair(ctName, (PetriEngine::Colored::ProductType*)ct));
217
} else if (strcmp(type->name(), "finiteintrange") == 0) {
218
uint32_t start = (uint32_t)atoll(type->first_attribute("start")->value());
219
uint32_t end = (uint32_t)atoll(type->first_attribute("end")->value());
221
for (uint32_t i = start; i<=end;i++) {
222
ct->addColor(std::to_string(i).c_str());
225
for (auto it = type->first_node(); it; it = it->next_sibling()) {
226
auto id = it->first_attribute("id");
227
assert(id != nullptr);
228
ct->addColor(id->value());
187
fct = Colored::ColorType::dotInstance();
191
if (strcmp(type->name(), "productsort") == 0) {
192
auto ct = new PetriEngine::Colored::ProductType(std::string(element->first_attribute("id")->value()));
193
bool missingType = false;
194
for (auto it = type->first_node(); it; it = it->next_sibling()) {
195
if (strcmp(it->name(), "usersort") == 0) {
196
auto ctName = it->first_attribute("declaration")->value();
197
if(!missingType && colorTypes.count(ctName)){
198
ct->addType(colorTypes[ctName]);
201
missingCTs.push_back(std::make_pair(ctName, ct));
209
auto ct = new PetriEngine::Colored::ColorType(std::string(element->first_attribute("id")->value()));
210
if (strcmp(type->name(), "finiteintrange") == 0) {
212
uint32_t start = (uint32_t)atoll(type->first_attribute("start")->value());
213
uint32_t end = (uint32_t)atoll(type->first_attribute("end")->value());
215
for (uint32_t i = start; i<=end;i++) {
216
ct->addColor(std::to_string(i).c_str());
220
for (auto it = type->first_node(); it; it = it->next_sibling()) {
221
auto id = it->first_attribute("id");
222
assert(id != nullptr);
223
ct->addColor(id->value());
232
230
std::string id = element->first_attribute("id")->value();
234
builder->addColorType(id, ct);
231
colorTypes[id] = fct;
232
builder->addColorType(id, fct);
237
235
PetriEngine::Colored::ArcExpression_ptr PNMLParser::parseArcExpression(rapidxml::xml_node<>* element) {
274
272
PetriEngine::Colored::ArcExpression_ptr PNMLParser::constructAddExpressionFromTupleExpression(rapidxml::xml_node<>* element,std::vector<std::vector<PetriEngine::Colored::ColorExpression_ptr>> collectedColors, uint32_t numberof){
275
auto initCartesianSet = cartesianProduct(collectedColors[0], collectedColors[1]);
276
for(uint32_t i = 2; i < collectedColors.size(); i++){
277
initCartesianSet = cartesianProduct(initCartesianSet, collectedColors[i]);
279
std::vector<PetriEngine::Colored::NumberOfExpression_ptr> numberOfExpressions;
280
for(auto set : initCartesianSet){
281
std::vector<PetriEngine::Colored::ColorExpression_ptr> colors;
282
for (auto color : set) {
283
colors.push_back(color);
285
std::shared_ptr<PetriEngine::Colored::TupleExpression> tupleExpr = std::make_shared<PetriEngine::Colored::TupleExpression>(std::move(colors));
286
tupleExpr->setColorType(tupleExpr->getColorType(colorTypes));
287
std::vector<PetriEngine::Colored::ColorExpression_ptr> placeholderVector;
288
placeholderVector.push_back(tupleExpr);
289
numberOfExpressions.push_back(std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(placeholderVector),numberof));
291
std::vector<PetriEngine::Colored::ArcExpression_ptr> constituents;
292
for (auto expr : numberOfExpressions) {
293
constituents.push_back(expr);
295
return std::make_shared<PetriEngine::Colored::AddExpression>(std::move(constituents));
273
std::vector<PetriEngine::Colored::ArcExpression_ptr> numberOfExpressions;
274
if(collectedColors.size() < 2){
275
for(auto exp : collectedColors[0]){
276
std::vector<PetriEngine::Colored::ColorExpression_ptr> colors;
277
colors.push_back(exp);
278
numberOfExpressions.push_back(std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(colors),numberof));
281
auto initCartesianSet = cartesianProduct(collectedColors[0], collectedColors[1]);
282
for(uint32_t i = 2; i < collectedColors.size(); i++){
283
initCartesianSet = cartesianProduct(initCartesianSet, collectedColors[i]);
285
for(auto set : initCartesianSet){
286
std::vector<PetriEngine::Colored::ColorExpression_ptr> colors;
287
for (auto color : set) {
288
colors.push_back(color);
290
std::shared_ptr<PetriEngine::Colored::TupleExpression> tupleExpr = std::make_shared<PetriEngine::Colored::TupleExpression>(std::move(colors));
291
tupleExpr->setColorType(tupleExpr->getColorType(colorTypes));
292
std::vector<PetriEngine::Colored::ColorExpression_ptr> placeholderVector;
293
placeholderVector.push_back(tupleExpr);
294
numberOfExpressions.push_back(std::make_shared<PetriEngine::Colored::NumberOfExpression>(std::move(placeholderVector),numberof));
297
return std::make_shared<PetriEngine::Colored::AddExpression>(std::move(numberOfExpressions));
298
300
std::vector<std::vector<PetriEngine::Colored::ColorExpression_ptr>> PNMLParser::cartesianProduct(std::vector<PetriEngine::Colored::ColorExpression_ptr> rightSet, std::vector<PetriEngine::Colored::ColorExpression_ptr> leftSet){
565
568
} else if (strcmp(it->name(),"inhibitorArc") == 0) {
566
569
parseArc(it, true);
567
570
} else if (strcmp(it->name(), "variable") == 0) {
568
std::cerr << "variable not supported" << std::endl;
571
std::cerr << "ERROR: variable not supported" << std::endl;
570
573
} else if (strcmp(it->name(),"queries") == 0) {
571
574
parseQueries(it);
572
575
} else if (strcmp(it->name(), "k-bound") == 0) {
573
std::cerr << "k-bound should be given as command line option -k" << std::endl;
576
std::cerr << "ERROR: k-bound should be given as command line option -k" << std::endl;
575
578
} else if (strcmp(it->name(),"query") == 0) {
576
std::cerr << "query tag not supported, please use PQL or XML-style queries instead" << std::endl;
579
std::cerr << "ERROR: query tag not supported, please use PQL or XML-style queries instead" << std::endl;
619
622
std::unordered_map<const PetriEngine::Colored::Variable*, const PetriEngine::Colored::Color*> binding;
620
623
PetriEngine::Colored::EquivalenceVec placePartition;
621
624
PetriEngine::Colored::ExpressionContext context {binding, colorTypes, placePartition};
622
for(auto ct : colorTypes){
624
625
hlinitialMarking = parseArcExpression(it->first_node("structure"))->eval(context);
625
626
} else if (strcmp(it->name(), "type") == 0) {
626
627
type = parseUserSort(it);
670
671
bool first = true;
671
for (auto it = element->first_node("inscription"); it; it = it->next_sibling("inscription")) {
673
parseValue(it, text);
674
weight = atoi(text.c_str());
675
if(std::find_if(text.begin(), text.end(), [](char c) { return !std::isdigit(c) && !std::isblank(c); }) != text.end())
677
std::cerr << "ERROR: Found non-integer-text in inscription-tag (weight) on arc from " << source << " to " << target << " with value \"" << text << "\". An integer was expected." << std::endl;
672
auto weightTag = element->first_attribute("weight");
673
if(weightTag != nullptr){
674
weight = atoi(weightTag->value());
680
675
assert(weight > 0);
683
std::cerr << "ERROR: Multiple inscription tags in xml of a arc from " << source << " to " << target << "." << std::endl;
677
for (auto it = element->first_node("inscription"); it; it = it->next_sibling("inscription")) {
679
parseValue(it, text);
680
weight = atoi(text.c_str());
681
if(std::find_if(text.begin(), text.end(), [](char c) { return !std::isdigit(c) && !std::isblank(c); }) != text.end())
683
std::cerr << "ERROR: Found non-integer-text in inscription-tag (weight) on arc from " << source << " to " << target << " with value \"" << text << "\". An integer was expected." << std::endl;
689
std::cerr << "ERROR: Multiple inscription tags in xml of a arc from " << source << " to " << target << "." << std::endl;
689
696
PetriEngine::Colored::ArcExpression_ptr expr;