NFAController.hpp 20.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright (C) 2014-2021 DBIS Group - TU Ilmenau, All Rights Reserved.
 *
 * This file is part of the PipeFabric package.
 *
 * PipeFabric 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.
 *
 * PipeFabric 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 PipeFabric. If not,
 * see <http://www.gnu.org/licenses/>.
 */

aliahmadbutt4's avatar
aliahmadbutt4 committed
18

Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
19
20
21

#ifndef NFAController_hpp_
#define NFAController_hpp_
22

Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
23
24
25
26
27
28
#include "state/NormalState.hpp"
#include "state/StartState.hpp"
#include "state/FinalState.hpp"
#include "state/KleeneState.hpp"
#include "state/NegationState.hpp"
#include "edge/NFAEdge.hpp"
29

Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
30
31
#include <iostream>

32

Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
33
34
35
36
37
namespace pfabric {
/*
 * A controller class to construct the NFA for detecting the complex event, the user
 * should create the states, edges and transitions by calling particular methods
 */
38
template<class TinPtr, class ToutPtr, class TdepPtr>
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
39
40
41
42
43
class NFAController {
private:
	/**
	 * a vector to store all states except final, kleene and negated states and start state
	 */
44
	std::vector<typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr> normalStates;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
45
46
47
	/**
	 * a vector to store all kleene states
	 */
48
	std::vector<typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneStatePtr> kleeneStates;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
49
50
51
	/**
	 * a vector to store all negated states
	 */
52
	std::vector<typename NegationState<TinPtr, ToutPtr, TdepPtr>::NegationStatePtr> negatedStates;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
53
54
55
	/**
	 * the start state
	 */
56
	typename StartState<TinPtr, ToutPtr, TdepPtr>::StartStatePtr start;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
57
58
59
	/**
	 * a vector to store the final states, in any NFA we have multiple states from this kind
	 */
60
	std::vector<typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr> finalStates;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
61
62
63
64
	/**
	 * a vector to store the transitions between the states, each transition must contain an edge which has
	 * a predicate to evaluate
	 */
65
	std::vector<typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr> transitions;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
66
67
68
69
70
71
72
73
74
75
76
77
78
	/**
	 * a state counter to assign a particular id for each state
	 */
	int stateCountID;
	/**
	 * an edge counter to assign a particular id for each edge
	 */
	int edgeCountID;
	/**
	 * get a pointer for a state with a given id
	 * @param id the id of the state
	 * @return as above
	 */
79
	typename NFAState<TinPtr>::StatePtr getState(int id);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
80
81
82
83
84
	/**
	 * get a pointer for an edge  with a given id
	 * @param the id of the edge
	 * @return as above
	 */
85
	typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr getEdge(int id);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
86
87
88


public:
Omran Saleh's avatar
Omran Saleh committed
89
90
91
	typedef std::shared_ptr<NFAController<TinPtr, ToutPtr, TdepPtr>> NFAControllerPtr;
	typedef std::function<TdepPtr()> initDependency;
	typedef std::function<void(const TdepPtr&, int, const TinPtr&  )> updateDependency;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
92
93
94
95
96
97
98
99
100
	/**
	 * controller constructor, nothing to do
	 */
	NFAController() {
		edgeCountID = 0;
		stateCountID = 0;
		init = [&]() {
			return nullptr;
		};
101
		update = [&](const TdepPtr& tp, int id, const TinPtr& event ) {};
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
102
103
104
105
106
107
108
109
110
111
112
	}
	/**
	 * a destructor, nothing to do
	 */
	~NFAController() {
	}
	/**
	 * create the start state for this NFA and assign its name
	 * @param name the name of the start state
	 * @return a pointer to start state
	 */
aliahmadbutt4's avatar
aliahmadbutt4 committed
113
	typename StartState<TinPtr, ToutPtr, TdepPtr>::StartStatePtr createStartState(std::string name) {
114
		start.reset(new StartState<TinPtr, ToutPtr, TdepPtr>(stateCountID++, name));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
115
116
117
118
119
120
121
122
		return start;
	}
	/**
	 * create a normal state for this NFA and assign its name, this state should not
	 * be final state or start state or kleene state
	 * @param name the name of this normal state
	 * @return a pointer to a normal state
	 */
aliahmadbutt4's avatar
aliahmadbutt4 committed
123
	typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr createNormalState(std::string name) {
124
125
		typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr state(
				new NormalState<TinPtr, ToutPtr, TdepPtr>(stateCountID++, name));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
126
127
128
129
130
131
132
133
134
		normalStates.push_back(state);
		return state;
	}
	/**
	 * create a kleene state of this NFA and assign its name and specification (whether kleene star, kleene plus and so on)
	 *
	 * @param spec the specification of this state (whether kleene star, kleene plus and so on)
	 * @return a pointer to a kleene state
	 */
aliahmadbutt4's avatar
aliahmadbutt4 committed
135
	typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneStatePtr createKleeneState(std::string name,
136
137
138
139
			typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneSpecification spec = KleeneState<
					TinPtr, ToutPtr, TdepPtr>::Star) {
		typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneStatePtr state(
				new KleeneState<TinPtr, ToutPtr, TdepPtr>(stateCountID++, name, spec));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
140
141
142
143
144
145
146
147
		kleeneStates.push_back(state);
		return state;
	}
	/**
	 * create a final state for this NFA and assign its name
	 * @param name the name of the final state
	 * @return a pointer to a final state
	 */
aliahmadbutt4's avatar
aliahmadbutt4 committed
148
	typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr createFinalState(std::string name) {
149
150
		typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr final(
				new FinalState<TinPtr, ToutPtr, TdepPtr>(stateCountID++, name));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
151
152
153
154
155
156
157
158
		finalStates.push_back(final);
		return final;
	}
	/**
	 * create a negated state for this NFA and assign its name
	 * @param name the name of the negated state
	 * @return a pointer to a negated state
	 */
159
	typename NegationState<TinPtr, ToutPtr, TdepPtr>::NegationStatePtr createNegationState(
aliahmadbutt4's avatar
aliahmadbutt4 committed
160
            std::string name) {
161
162
		typename NegationState<TinPtr, ToutPtr, TdepPtr>::NegationStatePtr state(
				new NegationState<TinPtr, ToutPtr, TdepPtr>(stateCountID++, name));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
163
164
165
166
167
168
169
170
		negatedStates.push_back(state);
		return state;
	}
	/**
	 * create a forward edge for this NFA for a given predicate
	 * @param predicate the predicate of this edge
	 * @return a pointer to a forward edge
	 */
171
172
173
174
	typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr createForwardEdge(
			typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::EdgePredicate predicate) {
		typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr edge(
				new ForwardEdge<TinPtr, ToutPtr, TdepPtr>(edgeCountID++, predicate));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
175
176
177
178
179
180
181
182
		transitions.push_back(edge);
		return edge;
	}
	/**
	 * create a loop edge for this NFA for a given predicate
	 * @param predicate the predicate of this edge
	 * @return a pointer to a loop edge
	 */
183
184
185
186
	typename LoopEdge<TinPtr, ToutPtr, TdepPtr>::LoopEdgePtr createLoopEdge(
			typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::EdgePredicate predicate) {
		typename LoopEdge<TinPtr, ToutPtr, TdepPtr>::LoopEdgePtr edge(
				new LoopEdge<TinPtr, ToutPtr, TdepPtr>(edgeCountID++, predicate));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
187
188
189
190
191
192
193
194
195
		transitions.push_back(edge);
		return edge;
	}
	/**
	 * create a forward transition for this NFA between two states by an edge
	 * @param src the source state of this transition
	 * @param dest the destination state of this transition
	 * @param edge an edge to connect both the source and destination nodes
	 */
196
197
198
199
200
201
	void createForwardTransition(typename NFAState<TinPtr>::StatePtr src,
			typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr edge,
			typename NFAState<TinPtr>::StatePtr dest) {
		if (edge->getEdgeType() == NFAEdge<TinPtr, ToutPtr, TdepPtr>::Forward) {
			typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr forward =
					std::static_pointer_cast<ForwardEdge<TinPtr, ToutPtr, TdepPtr>>(edge);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
202
			forward->setDestState(dest.get());
203
			std::static_pointer_cast<NormalState<TinPtr, ToutPtr, TdepPtr>>(src)->addEdge(forward);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
		} else
			assert(false);
	}

	/**
	 * create a forward transition for this NFA between two states (given their ids) by an edge (given its ids)
	 * @param src the source state id of this transition
	 * @param dest the destination state id of this transition
	 * @param edge an edge id to connect both the source and destination nodes
	 */
	void createForwardTransition(int src, int edge, int dest) {
		assert(src == dest);
		this->createForwardTransition(getState(src), getEdge(edge),
				getState(dest));
	}
	/**
	 * create a loop transition for this NFA for kleene state (given its id) by a loop edge (given its ids).
	 * this function adds a loop edge predicate to a given state object, this state must be kleene state which has always
	 * @param source the source state id of this transition
	 * @param edge a loop edge id to connect the source with itself
	 */
	void createLoopTransition(int source, int edge) {
		this->createLoopTransition(getState(source), getEdge(edge));
	}
	/**
	 * create a loop transition for this NFA for kleene state  by a loop edge
	 * @param source the source state of this transition
	 * @param edge a loop edge to connect the source with itself
	 */
233
234
	void createLoopTransition(typename NFAState<TinPtr>::StatePtr source,
			typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr edge);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
235
236
237
238
239
240
241
	/**
	 * add a loop edge predicate to a given state id, this state must be kleene state which has always
	 * loop edge
	 * @param state the kleene state id to add a loop edge to it
	 * @param predicate the predicate of the kleene state to be assigned to the loop edge
	 */
	void addLoopEdgeToState(int state,
242
			typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::EdgePredicate predicate);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	/**
	 * get the id of the start state
	 * @return as above
	 */
	int getStartStateID() {
		if (start.get() != NULL)
			return start->getStateID();
		else
			return -1;
	}
	/**
	 * get a pointer to the start state
	 * @return as above
	 */
257
	StartState<TinPtr, ToutPtr, TdepPtr>* getStartState() const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
258
259
260
261
262
263
		return start.get();
	}
	/**
	 * get a vector of final states in the NFA
	 * @return as above
	 */
264
	const std::vector<typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr>& getFinalStates() const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
265
266
267
268
269
270
271
272
		return this->finalStates;
	}

	/**
	 * set the final states for this NFA
	 * @param a vector of final states
	 */
	void setFinalStates(
273
			std::vector<typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr> finalStates) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
274
275
276
277
278
279
280
281
		for (int i = 0; i < finalStates.size(); i++) {
			addFinalState(finalStates[i]);
		}
	}
	/**
	 * add a final state to this NFA
	 * @param a final state to be added to this NFA
	 */
282
	void addFinalState(typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr final);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
283
284
285
286
287
288

	/**
	 * set the kleene states states of this NFA
	 * @param KleeneStates the kleene states to set
	 */
	void setKleeneStates(
289
			std::vector<typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneStatePtr> kleeneStates) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
290
291
292
293
294
295
296
297
		for (int i = 0; i < kleeneStates.size(); i++) {
			addKleeneState(kleeneStates[i]);
		}
	}
	/**
	 * get a vector of kleene states in the NFA
	 * @return as above
	 */
298
	const std::vector<typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneStatePtr>& getKleeneStates() const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
299
300
301
302
303
304
		return this->kleeneStates;
	}
	/**
	 * add a kleene state to this NFA
	 * @param a kleene state to be added to this NFA
	 */
305
	void addKleeneState(typename KleeneState<TinPtr, ToutPtr, TdepPtr>::KleeneStatePtr kleeneState) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
306
307
308
309
310
311
312
313
314
315
316
		if (std::find(kleeneStates.begin(), kleeneStates.end(), kleeneState)
				== kleeneStates.end()) {
			kleeneStates.push_back(kleeneState);
		}
	}

	/**
	 * set the negated states states of this NFA
	 * @param negated_states the negated states to set
	 */
	void setNegatedStates(
317
			std::vector<typename NegationState<TinPtr, ToutPtr, TdepPtr>::NegationStatePtr> negatedStates) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
318
319
320
321
322
323
324
325
		for (int i = 0; i < negatedStates.size(); i++) {
			addNegatedState(negatedStates[i]);
		}
	}
	/**
	 * get a vector of negated states in the NFA
	 * @return as above
	 */
326
	const std::vector<typename NegationState<TinPtr, ToutPtr, TdepPtr>::NegationStatePtr>& getNegatedStates() const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
327
328
329
330
331
332
333
		return negatedStates;
	}
	/**
	 * add a negated state to this NFA
	 * @param a negated state to be added to this NFA
	 */
	void addNegatedState(
334
			typename NegationState<TinPtr, ToutPtr, TdepPtr>::NegationStatePtr negatedState) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
335
336
337
338
339
340
341
342
343
344
345
		if (std::find(negatedStates.begin(), negatedStates.end(), negatedState)
				== negatedStates.end()) {
			negatedStates.push_back(negatedState);
		}
	}

	/**
	 * set the normal states states of this NFA
	 * @param NormalStates the normal states to set
	 */
	void setNormalStates(
346
			std::vector<typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr> normalStates) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
347
348
349
350
351
352
353
354
		for (int i = 0; i < normalStates.size(); i++) {
			addNormalState(normalStates[i]);
		}
	}
	/**
	 * get a vector of normal states in the NFA
	 * @return as above
	 */
355
	const std::vector<typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr>& getNormalStates() const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
356
357
358
359
360
361
		return normalStates;
	}
	/**
	 * add a normal state to this NFA
	 * @param negated_state a negated state to be added to this NFA
	 */
362
	void addNormalState(typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr NormalState);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
363
364
365
366
367

	/**
	 * get a vector of intermediate states including negated, kleene and normal states in the NFA
	 * @return as above
	 */
368
	std::vector<typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr> getInterStates() const;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
369
370
371
372
373
374
375
376

	/**
	 * add forward edges for a particular state, this state can be start, normal, negated and kleene states
	 * each states in our system has multiple forward edges except the final states
	 * @param state a state to assign forward edges to it
	 * @param edges a vector of forward edges to be assigned to a state
	 */

377
378
	void addForwardEdges(typename NFAState<TinPtr>::StatePtr state,
			std::vector<typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr> edges);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
379
380
381
382
383
384
	/**
	 * add a forward edge for a particular state, this state can be start, normal, negated and kleene states
	 * each states in our system has multiple forward edges except the final states
	 * @param state a state to assign this forward edge to it
	 * @param edge an edge to be assigned to a state
	 */
385
386
	void addForwardEdge(typename NFAState<TinPtr>::StatePtr state,
			typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr edge);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
	/**
	 * add forward edges by their ids to a particular state given its id, this state can be start, normal, negated and kleene states
	 * each states in our system has multiple forward edges except the final states
	 * @param state a state id to assign forward edges to it
	 * @param edges a vector of forward edge ids to be assigned to a state
	 */
	void addForwardEdges(int state, std::vector<int> edges);
	/**
	 * add a forward edge by its id for a particular state given its id, this state can be start, normal, negated and kleene states
	 * each states in our system has multiple forward edges except the final states
	 * @param state a state id to assign this forward edge to it
	 * @param edge an edge id to be assigned to a state
	 */
	void addForwardEdge(int state, int edge);

	/**
	 * get a vector of the transitions in the NFA
	 * @return as above
	 */
406
	const std::vector<typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr>& getTransitions() const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
407
408
409
		return transitions;
	}
	/*
410
	 void addDependencyEdges(typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr edgeSource, typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr edgeDepend,
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
	 int attrIdx, StateDependency::OperationDependency op, StateDependency::OperationType type = StateDependency::Double );
	 vector<StateDependencyPtr> getSourceOf() const;
	 void setSourceOf(vector<StateDependencyPtr> sourceOf);*/
	/**
	 * return the number of states which has kleene type
	 * @return as above
	 */
	int getKleeneStatesCount() const {
		return kleeneStates.size();
	}
	/**
	 * return the number of negated states
	 * @return as above
	 */
	int getNegationStatesCount() const {
		return negatedStates.size();
	}

	void setDependency(initDependency init, updateDependency update) {
		this->init = init ;
		this->update = update;

	}
aliahmadbutt4's avatar
aliahmadbutt4 committed
434
	void print (std::ostream& out = std::cout) ;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
435
436
437
438
439
440
441
442
443

	initDependency init ;

	updateDependency update ;
};
} /* namespace pfabric */

namespace pfabric {

444
445
446
template <class TinPtr, class ToutPtr, class TdepPtr>
std::vector<typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr> NFAController<TinPtr, ToutPtr, TdepPtr>::getInterStates() const {
	std::vector<typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr> result;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
447
448
449
450
451
452
	copy(normalStates.begin(), normalStates.end(), back_inserter(result));
	copy(kleeneStates.begin(), kleeneStates.end(), back_inserter(result));
	copy(negatedStates.begin(), negatedStates.end(), back_inserter(result));
	return result;
}

453
454
template <class TinPtr, class ToutPtr, class TdepPtr>
void NFAController<TinPtr, ToutPtr, TdepPtr>::addFinalState(typename FinalState<TinPtr, ToutPtr, TdepPtr>::FinalStatePtr final) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
	if (std::find(finalStates.begin(), finalStates.end(), final)
			== finalStates.end()) {
		finalStates.push_back(final);
	}
}

/*
void NFAController::addDependencyEdges(NFAEdgePtr edgeSource,
		NFAEdgePtr edgeDepend, int attrIdx,
		StateDependency::OperationDependency op,
		StateDependency::OperationType type) {

	StateDependencyPtr dependency(
			new StateDependency(edgeSource, edgeDepend, attrIdx, op, type));
	edgeSource->addStateSource(dependency);
	edgeDepend->addStateDependeny(dependency);
}*/




476
477
478
479
480
template <class TinPtr, class ToutPtr, class TdepPtr>
void NFAController<TinPtr, ToutPtr, TdepPtr>::addForwardEdges(typename NFAState<TinPtr>::StatePtr state,
		std::vector<typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr> edges) {
	if (state->getStateType() == NFAState<TinPtr>::Normal)
		boost::static_pointer_cast<NormalState<TinPtr, ToutPtr, TdepPtr>>(state)->setForwardEdges(
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
481
482
483
484
485
				edges);
	else
		assert(false);
}

486
487
488
489
template <class TinPtr, class ToutPtr, class TdepPtr>
void NFAController<TinPtr, ToutPtr, TdepPtr>::addForwardEdge(typename NFAState<TinPtr>::StatePtr state, typename ForwardEdge<TinPtr, ToutPtr, TdepPtr>::ForwardEdgePtr edge) {
	if (state->getStateType() == NFAState<TinPtr>::Normal)
		boost::static_pointer_cast<NormalState<TinPtr, ToutPtr, TdepPtr>>(state)->addEdge(edge);
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
	else
		assert(false);
}
/*
 void NFAController::add_ForwardEdges(int state, std::vector<int> edges) {
 std::vector<ForwardNFAEdgePtr> f_edges;
 for (int i = 0; i < edges.size(); i++) {
 ForwardNFAEdgePtr e;
 if ((e = getEdge(edges[i])).IsValid())
 f_edges.push_back(e);
 }
 add_ForwardEdges(getState(state), f_edges);
 }
 */
504
505
template <class TinPtr, class ToutPtr, class TdepPtr>
void NFAController<TinPtr, ToutPtr, TdepPtr>::addForwardEdge(int state, int edge) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
506
	addForwardEdge(getState(state),
507
			boost::static_pointer_cast<ForwardEdge<TinPtr, ToutPtr, TdepPtr>>(getEdge(edge)));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
508
509
}

510
511
template <class TinPtr, class ToutPtr, class TdepPtr>
typename NFAState<TinPtr>::StatePtr NFAController<TinPtr, ToutPtr, TdepPtr>::getState(int id) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
	if (start->getStateID() == id)
		return start;
	for (int i = 0; i < negatedStates.size(); i++) {
		if (negatedStates[i]->getStateID() == id) {
			return negatedStates[i];
		}

	}
	for (int i = 0; i < normalStates.size(); i++) {
		if (normalStates[i]->getStateID() == id) {
			return normalStates[i];
		}

	}
	for (int i = 0; i < finalStates.size(); i++) {
		if (finalStates[i]->getStateID() == id) {
			return finalStates[i];
		}
	}
531
	return NFAState<TinPtr>::StatePtr();
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
532
533
}

534
535
template <class TinPtr, class ToutPtr, class TdepPtr>
typename NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr NFAController<TinPtr, ToutPtr, TdepPtr>::getEdge(int id) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
536
537
538
539
540
	for (int i = 0; i < transitions.size(); i++) {
		if (transitions[i]->getID() == id) {
			return transitions[i];
		}
	}
541
	return NFAEdge<TinPtr, ToutPtr, TdepPtr>::NFAEdgePtr();
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
542
543
544
545
}



546
547
template <class TinPtr, class ToutPtr, class TdepPtr>
void NFAController<TinPtr, ToutPtr, TdepPtr>::addNormalState(typename NormalState<TinPtr, ToutPtr, TdepPtr>::NormalStatePtr normalState) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
548
549
550
551
552
553
	if (std::find(normalStates.begin(), normalStates.end(), normalState)
			== normalStates.end()) {
		normalStates.push_back(normalState);
	}
}

554
template <class TinPtr, class ToutPtr, class TdepPtr>
aliahmadbutt4's avatar
aliahmadbutt4 committed
555
void NFAController<TinPtr, ToutPtr, TdepPtr>::print (std::ostream& out) {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
556
557
558
559
560
561
	out << this->start->getStateName() << std::endl;
}


}
#endif /* NFAController_hpp_ */