/* PeTe - Petri Engine exTremE * Copyright (C) 2011 Jonas Finnemann Jensen , * Thomas Søndersø Nielsen , * Lars Kærlund Østergaard , * Peter Gjøl Jensen * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef PETRINET_H #define PETRINET_H #include #include #include #include #include namespace PetriEngine { namespace PQL { class Condition; } namespace Structures { class State; } class PetriNetBuilder; class SuccessorGenerator; struct TransPtr { uint32_t inputs; uint32_t outputs; }; struct Invariant { uint32_t place; uint32_t tokens; bool inhibitor; // we can pack things here, but might give slowdown } /*__attribute__((packed))*/; /** Type used for holding markings values */ typedef uint32_t MarkVal; /** Efficient representation of PetriNet */ class PetriNet { PetriNet(uint32_t transitions, uint32_t invariants, uint32_t places); public: ~PetriNet(); MarkVal* makeInitialMarking(); /** Fire transition if possible and store result in result */ bool deadlocked(const MarkVal* marking) const; bool fireable(const MarkVal* marking, int transitionIndex); uint32_t numberOfTransitions() const { return _ntransitions; } uint32_t numberOfPlaces() const { return _nplaces; } int inArc(uint32_t place, uint32_t transition) const; int outArc(uint32_t transition, uint32_t place) const; const std::vector& transitionNames() const { return _transitionnames; } const std::vector& placeNames() const { return _placenames; } private: void print(MarkVal const * const val) const { for(size_t i = 0; i < _nplaces; ++i) { if(val[i] != 0) { std::cout << i << " -> " << val[i] << std::endl; } } } /** Number of x variables * @remarks We could also get this from the _places vector, but I don't see any * any complexity garentees for this type. */ uint32_t _ninvariants, _ntransitions, _nplaces; std::vector _transitions; std::vector _invariants; std::vector _placeToPtrs; MarkVal* _initialMarking; std::vector _transitionnames; std::vector _placenames; friend class PetriNetBuilder; friend class Reducer; friend class SuccessorGenerator; }; } // PetriEngine #endif // PETRINET_H