~verifypn-cpn/verifypn/colored

« back to all changes in this revision

Viewing changes to PetriEngine/PetriNet.h

  • Committer: Jonas Finnemann Jensen
  • Date: 2011-09-15 13:30:00 UTC
  • Revision ID: jopsen@gmail.com-20110915133000-wnywm1odf82emiuw
Import of sources from github

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* PeTe - Petri Engine exTremE
 
2
 * Copyright (C) 2011  Jonas Finnemann Jensen <jopsen@gmail.com>,
 
3
 *                     Thomas Søndersø Nielsen <primogens@gmail.com>,
 
4
 *                     Lars Kærlund Østergaard <larsko@gmail.com>,
 
5
 * 
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
#ifndef PETRINET_H
 
20
#define PETRINET_H
 
21
 
 
22
#include <string>
 
23
#include <vector>
 
24
#include <climits>
 
25
 
 
26
namespace PetriEngine{
 
27
 
 
28
namespace PQL{
 
29
        class Condition;
 
30
        class AssignmentExpression;
 
31
}
 
32
 
 
33
namespace Structures{
 
34
        class State;
 
35
}
 
36
 
 
37
class PetriNetBuilder;
 
38
 
 
39
/** Type used for holding markings values */
 
40
typedef int MarkVal;
 
41
/** Type used for holding variable values */
 
42
typedef int VarVal;
 
43
 
 
44
#define MARK_INF                                        INT_MAX
 
45
 
 
46
/** Efficient representation of PetriNet */
 
47
class PetriNet
 
48
{
 
49
        PetriNet(int places, int transitions, int variables);
 
50
public:
 
51
        ~PetriNet();
 
52
        /** Fire transition if possible and store result in result */
 
53
        bool fire(unsigned int transition,
 
54
                          const MarkVal* marking,
 
55
                          const VarVal* assignment,
 
56
                          MarkVal* resultMarking,
 
57
                          VarVal* resultAssignment) const;
 
58
        bool fire(unsigned int transition, const Structures::State* s, Structures::State* ns, int multiplicity = 1, int kbound = 0) const;
 
59
        /** Fire without checkings conditions */
 
60
        void fireWithoutCheck(unsigned int transition,
 
61
                                                  const MarkVal* marking,
 
62
                                                  const VarVal* assignment,
 
63
                                                  MarkVal* resultMarking,
 
64
                                                  VarVal* resultAssignment,
 
65
                                                  int multiplicity = 1) const;
 
66
        /** Fire transition if possible and store result in result (Respect MARK_INF */
 
67
        bool fireWithMarkInf(unsigned int transition,
 
68
                          const MarkVal* marking,
 
69
                          const VarVal* assignment,
 
70
                          MarkVal* resultMarking,
 
71
                          VarVal* resultAssignment) const;
 
72
        unsigned int numberOfTransitions() const {return _nTransitions;}
 
73
        unsigned int numberOfVariables() const {return _nVariables;}
 
74
        unsigned int numberOfPlaces() const {return _nPlaces;}
 
75
        int inArc(unsigned int place, unsigned int transition) const;
 
76
        int outArc(unsigned int transition, unsigned int place) const;
 
77
        /** Get vector place names, don't use this to get the number of places */
 
78
        const std::vector<std::string>& placeNames() const {return _places;}
 
79
        /** Get vector variable names, don't use this to get the number of variable */
 
80
        const std::vector<std::string>& variableNames() const {return _variables;}
 
81
        /** Get vector transition names, don't use this to get the number of variable */
 
82
        const std::vector<std::string>& transitionNames() const {return _transitions;}
 
83
private:
 
84
        std::vector<std::string> _places;
 
85
        std::vector<std::string> _transitions;
 
86
        std::vector<std::string> _variables;
 
87
        /** Number of x variables
 
88
         * @remarks We could also get this from the _places vector, but I don't see any
 
89
         * any complexity garentees for this type.
 
90
         */
 
91
        size_t _nPlaces, _nTransitions, _nVariables;
 
92
        /** Transition matrix, see transition vector */
 
93
        MarkVal* _tm;
 
94
        /** Get a transition vector
 
95
         * @remarks On form [p1-][p2-]...[p1+][p2+]...
 
96
         *                      where p1- is number of tokens to be taken from p1.
 
97
         *                      and p1+ is the number of tokens to given to p1.
 
98
         */
 
99
        const MarkVal* _tv(unsigned int t) const {return _tm + t * _nPlaces * 2;}
 
100
        MarkVal* _tv(unsigned int t) {return _tm + t * _nPlaces * 2;}
 
101
 
 
102
        VarVal* _ranges;
 
103
        PQL::Condition** _conditions;
 
104
        PQL::AssignmentExpression** _assignments;
 
105
        friend class PetriNetBuilder;
 
106
};
 
107
 
 
108
} // PetriEngine
 
109
 
 
110
#endif // PETRINET_H