Line data Source code
1 : /*******************************************************************************
2 : * *
3 : * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles *
4 : * (S)tochastiques *
5 : * *
6 : * Copyright (C) 2009-2012 LSV & LACL *
7 : * Authors: Benoît Barbot & Paolo Ballarini & Hilal Djafri *
8 : * Website: http://www.lsv.ens-cachan.fr/Software/cosmos *
9 : * *
10 : * This program is free software; you can redistribute it and/or modify *
11 : * it under the terms of the GNU General Public License as published by *
12 : * the Free Software Foundation; either version 3 of the License, or *
13 : * (at your option) any later version. *
14 : * *
15 : * This program is distributed in the hope that it will be useful, *
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 : * GNU General Public License for more details. *
19 : * *
20 : * You should have received a copy of the GNU General Public License along *
21 : * with this program; if not, write to the Free Software Foundation, Inc., *
22 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
23 : * file EventsQueueSet.hpp created by on 31/05/2016 *
24 : *******************************************************************************
25 : */
26 :
27 : //
28 : // EventsQueueSet.hpp
29 : // Cosmos
30 : //
31 : // Created by Benoît Barbot on 31/05/2016.
32 : //
33 : //
34 :
35 : #ifndef EventsQueueSet_hpp
36 : #define EventsQueueSet_hpp
37 :
38 : #include <stdio.h>
39 : #include <vector>
40 : #include <map>
41 :
42 : #include "Event.hpp"
43 : #include "spn.hpp"
44 :
45 : typedef std::vector <int> Tab;
46 : typedef std::vector <Event> EQueue;
47 : typedef std::vector <Event>::iterator EQit;
48 :
49 : class EventsQueueSet {
50 : public:
51 : //EventsQueue(size_t);
52 : EventsQueueSet(const std::vector<size_t> &sizes);
53 :
54 : EventsQueueSet(const EventsQueueSet& orig);
55 : virtual ~EventsQueueSet();
56 :
57 : void insert(const Event &);
58 : void replace(const Event &);
59 : void pause(double,size_t,size_t);
60 : bool restart(double,size_t,size_t);
61 : void remove(size_t);
62 : void remove(size_t,size_t);
63 : bool isScheduled(size_t,size_t)const;
64 : Event& getEvent(size_t tr, size_t b);
65 :
66 :
67 : bool isEmpty()const;
68 : void printSedCmd(const std::vector<std::string> &labels, std::ostream&)const;
69 : void view(const std::vector<std::string> &labels)const;
70 :
71 : void reset();
72 : size_t getSize()const ;
73 :
74 :
75 : const Event& InPosition(size_t)const ;
76 : const std::map<size_t, long int>& getScheduledBinding(size_t tr)const;
77 :
78 : //private:
79 :
80 : /**
81 : * The Events Heap Index vector allow to retrive the index
82 : * of an event in the Events Heap (evtHeap) given its transition
83 : * and binding index in constant time.
84 : * If the return value is -1 the corresponding event is not in the event heap.
85 : * transition -> binding hash-> index in event heap
86 : */
87 : std::vector<std::map< size_t, long int > > evtHeapIndex;
88 :
89 : /**
90 : * This is the vector of events, all the events of every transition
91 : * and every binding must occurs in this vector.
92 : * the first index is allong transition and the second along binding index.
93 : * transition -> binding hash -> Event
94 : */
95 : std::vector<std::map< size_t, Event > > evtTbl;
96 :
97 : /**
98 : * The event heap is a vector of pairs. each pairs are the transition index
99 : * and binding index of an event in the event table.
100 : * This vector is a heap for the relation Event::isPriorer.
101 : * The first element of the heap is the most urgent event.
102 : * event index -> transition*binding hash
103 : */
104 : std::vector< Event* > evtHeap;
105 :
106 : private:
107 20130255 : size_t getLeftChildIndex(size_t nodeIndex)const {
108 20130255 : return 2 * nodeIndex + 1;
109 : }
110 :
111 20130255 : size_t getRightChildIndex(size_t nodeIndex)const {
112 20130255 : return 2 * nodeIndex + 2;
113 : }
114 :
115 3402650 : size_t getParentIndex(size_t nodeIndex)const {
116 3402650 : return (nodeIndex - 1) / 2;
117 : }
118 :
119 : void siftUp(size_t);
120 : void siftDown(size_t);
121 : void swapEvt(size_t,size_t);
122 :
123 : void remove(size_t tr, size_t index,size_t bhash);
124 :
125 : };
126 :
127 :
128 :
129 : #endif /* EventsQueueSet_hpp */
|