~verifypn-maintainers/verifypn/u3.1

« back to all changes in this revision

Viewing changes to src/PetriEngine/PetriNetBuilder.cpp

  • Committer: Jiri Srba
  • Date: 2020-10-31 18:54:26 UTC
  • mfrom: (226.1.3 show-reduced-net)
  • Revision ID: srba@cs.aau.dk-20201031185426-40zgypcd8b1651tc
merged in lp:~tapaal-contributor/verifypn/show-reduced-net adding x,y positions when exporting reduced net

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    }
39
39
    PetriNetBuilder::PetriNetBuilder(const PetriNetBuilder& other)
40
40
    : _placenames(other._placenames), _transitionnames(other._transitionnames),
 
41
       _placelocations(other._placelocations), _transitionlocations(other._transitionlocations),
41
42
       _transitions(other._transitions), _places(other._places), 
42
43
       initialMarking(other.initialMarking), reducer(this)
43
44
    {
44
45
 
45
46
    }
46
47
 
47
 
    void PetriNetBuilder::addPlace(const string &name, int tokens, double, double) {
 
48
    void PetriNetBuilder::addPlace(const string &name, int tokens, double x, double y) {
48
49
        if(_placenames.count(name) == 0)
49
50
        {
50
51
            uint32_t next = _placenames.size();
51
52
            _places.emplace_back();
52
53
            _placenames[name] = next;
 
54
            _placelocations.push_back(std::tuple<double, double>(x,y));
53
55
        }
54
56
        
55
57
        uint32_t id = _placenames[name];
60
62
    }
61
63
 
62
64
    void PetriNetBuilder::addTransition(const string &name,
63
 
            double, double) {
 
65
            double x, double y) {
64
66
        if(_transitionnames.count(name) == 0)
65
67
        {
66
68
            uint32_t next = _transitionnames.size();
67
69
            _transitions.emplace_back();
68
70
            _transitionnames[name] = next;
 
71
            _transitionlocations.push_back(std::tuple<double, double>(x,y));
69
72
        }
70
73
    }
71
74
 
318
321
            ++free;
319
322
            next = nextPlaceId(place_cons_count, place_prod_count, place_idmap, reorder);
320
323
        }
 
324
 
321
325
        
322
326
        // Reindex for great justice!
323
327
        for(uint32_t i = 0; i < freeinv; i++)
336
340
//                std::cout << place_idmap[i] << " : " << initialMarking[i] << std::endl;
337
341
            }
338
342
        }
 
343
 
 
344
        net->_placelocations = _placelocations;
 
345
        net->_transitionlocations = _transitionlocations;
339
346
        
340
347
        // reindex place-names
341
348
 
343
350
        int rindex = _placenames.size() - 1;
344
351
        for(auto& i : _placenames)
345
352
        {
 
353
            auto& placelocation = _placelocations[i.second];
346
354
            i.second = place_idmap[i.second];
347
355
            if(i.second != std::numeric_limits<uint32_t>::max())
348
356
            {
349
357
                net->_placenames[i.second] = i.first;
350
358
                assert(_placenames[net->_placenames[i.second]] == i.second);
 
359
                net->_placelocations[i.second] = placelocation;
351
360
            }
352
361
            else
353
362
            {
354
363
                net->_placenames[rindex] = i.first;
 
364
                net->_placelocations[rindex] = placelocation;
355
365
                --rindex;
356
366
            }
357
367
        }
360
370
        int trindex = _transitionnames.size() - 1;
361
371
        for(auto& i : _transitionnames)
362
372
        {
 
373
            auto& transitionlocation = _transitionlocations[i.second];
363
374
            i.second = trans_idmap[i.second];
364
375
            if(i.second != std::numeric_limits<uint32_t>::max())
365
376
            {
366
377
                net->_transitionnames[i.second] = i.first;
 
378
                net->_transitionlocations[i.second] = transitionlocation;
367
379
            }
368
380
            else
369
381
            {
370
382
                net->_transitionnames[trindex] = i.first;
 
383
                net->_transitionlocations[trindex] = transitionlocation;
371
384
                --trindex;
372
385
            }
373
386
        }