tp_tparallel.h
Go to the documentation of this file.
1/** @file tp_tparallel.h Parallel composition for timed automata */
2
3/* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2007 Thomas Moor
6 Exclusive copyright is granted to Klaus Schmidt
7
8*/
9
10
11// TODO: this code needs testing!
12// TODO: use cparallel for contr. attribs
13
14#ifndef FAUDES_TP_TPARALLEL_H
15#define FAUDES_TP_TPARALLEL_H
16
17#include "tp_tgenerator.h"
18
19namespace faudes {
20
21
22// convenience defs for template functions
23#define TEMP template < \
24 class GlobalAttr1, class StateAttr1, class EventAttr1, class TransAttr1, \
25 class GlobalAttr2, class StateAttr2, class EventAttr2, class TransAttr2, \
26 class GlobalAttrR, class StateAttrR, class EventAttrR, class TransAttrR >
27
28#define TGEN1 TtGenerator<GlobalAttr1,StateAttr1,EventAttr1,TransAttr1>
29#define TGEN2 TtGenerator<GlobalAttr2,StateAttr2,EventAttr2,TransAttr2>
30#define TGENR TtGenerator<GlobalAttrR,StateAttrR,EventAttrR,TransAttrR>
31
32
33/**
34 * Parallel composition of timed generators.
35 * Arguments rGen1 and rGen2 are assumed to have disjoind clocksets.
36 * This implementation considers accessible states only.
37 *
38 * Technically, this function is a template, but timed attribute interfaces
39 * are assumed.
40 *
41 * @param rGen1
42 * First generator
43 * @param rGen2
44 * Second generator
45 * @param rResGen
46 * Reference to resulting parallel composition generator
47 *
48 * @ingroup TimedPlugin
49 */
50TEMP void TParallel(const TGEN1& rGen1, const TGEN2& rGen2, TGENR& rResGen);
51
52
53/**
54 * Parallel composition of timed generators.
55 * Arguments rGen1 and rGen2 are assumed to have disjoind clocksets.
56 * This implementation considers accessible states only.
57 *
58 * Technically, this function is a template, but timed attribute interfaces
59 * are assumed. This version fills given reverse composition map with indices.
60 *
61 * @param rGen1
62 * First generator
63 * @param rGen2
64 * Second generator
65 * @param rReverseCompositionMap
66 * Reverse composition map (map< pair<Idx,Idx>, Idx>)
67 * @param rResGen
68 * Reference to resulting parallel composition generator
69 *
70 * @ingroup TimedPlugin
71 * @ingroup TimedPlugin
72 */
73TEMP void TParallel(
74 const TGEN1& rGen1, const TGEN2& rGen2,
75 std::map< std::pair<Idx,Idx>, Idx>& rReverseCompositionMap,
76 TGENR& rResGen);
77
78
79
80/*
81 **************************************************************************************
82 **************************************************************************************
83 implementation
84 **************************************************************************************
85 **************************************************************************************
86 */
87
88
89// TParallel(rGen1, rGen2, res) (wrapper)
90TEMP void TParallel(const TGEN1& rGen1, const TGEN2& rGen2, TGENR& rResGen) {
91 std::map< std::pair<Idx,Idx>, Idx> rcmap;
92 TParallel(rGen1, rGen2, rcmap, rResGen);
93}
94
95
96// TParallel(rGen1, rGen2, rReverseCompositionMap, res)
98 const TGEN1& rGen1, const TGEN2& rGen2,
99 std::map< std::pair<Idx,Idx>, Idx>& rReverseCompositionMap,
100 TGENR& rResGen)
101{
102 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << ")");
103 // todo: exception for non-disjoint clocksets
104 // call untimed parallel composition, incl virtual clear
105 Parallel( rGen1, rGen2, rReverseCompositionMap, rResGen);
106 // 1. union clockset
107 ClockSet clocks12;
108 clocks12.InsertSet(rGen1.Clocks());
109 clocks12.InsertSet(rGen2.Clocks());
110 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): clocks:" << clocks12.ToString());
111 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): clocks:" << rGen1.Clocks().ToString());
112 rResGen.InjectClocks(clocks12);
113 // 2. intersect invariants
114 std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
115 for(rcit=rReverseCompositionMap.begin(); rcit!=rReverseCompositionMap.end(); rcit++) {
116 Idx x1=rcit->first.first;
117 Idx x2=rcit->first.second;
118 Idx x12=rcit->second;
119 if(!rResGen.ExistsState(x12)) continue;
120 TimeConstraint invariant12;
121 invariant12 << rGen1.Invariant(x1);
122 invariant12 << rGen2.Invariant(x2);
123 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): invariant " << x1 << "|" << x2
124 << " :" << invariant12.ToString());
125 rResGen.Invariant(x12,invariant12);
126 }
127 // 3. set up composition map (todo: avoid this)
128 std::map< Idx, std::pair<Idx,Idx> > compositionmap;
129 for(rcit=rReverseCompositionMap.begin(); rcit!=rReverseCompositionMap.end(); rcit++)
130 compositionmap[rcit->second]=rcit->first;
131 // 4. resets and guards
133 for(tit=rResGen.TransRelBegin(); tit!=rResGen.TransRelEnd(); tit++) {
134 // hypothesis: unconstraint guard, no resets
135 TimeConstraint guard;
136 ClockSet resets;
137 // if event is in Gen1, intersect with gurad of Gen1
138 if(rGen1.ExistsEvent(tit->Ev)) {
139 Transition t1;
140 t1.X1=compositionmap[tit->X1].first;
141 t1.Ev=tit->Ev;
142 t1.X2=compositionmap[tit->X2].first;
143 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): guard/resets in Gen1 for " << t1.Str());
144 guard.Insert(rGen1.Guard(t1));
145 resets.InsertSet(rGen1.Resets(t1));
146 }
147 // if event is in Gen2, intersect with gurad of Gen2
148 if(rGen2.ExistsEvent(tit->Ev)) {
149 Transition t2;
150 t2.X1=compositionmap[tit->X1].second;
151 t2.Ev=tit->Ev;
152 t2.X2=compositionmap[tit->X2].second;
153 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): guard/resets in Gen2 for " << t2.Str());
154 guard.Insert(rGen2.Guard(t2));
155 resets.InsertSet(rGen2.Resets(t2));
156 }
157 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): guard " << tit->Str()
158 << " :" << guard.ToString());
159 rResGen.Guard(*tit,guard);
160 FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): resets " << tit->Str()
161 << " :" << resets.ToString());
162 rResGen.Resets(*tit,resets);
163 }
164 FD_DF("TParallel: done ");
165}
166
167
168
169
170#undef TEMP
171#undef GEN1
172#undef GEN2
173#undef GENR
174
175
176} // namespace faudes
177
178#endif
179
#define TEMP
#define FD_DF(message)
virtual void InsertSet(const NameSet &rOtherSet)
std::string ToString(void) const
Iterator Insert(const ElemConstraint &rElemConstr)
std::string Str(void) const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void TParallel(const TGEN1 &rGen1, const TGEN2 &rGen2, TGENR &rResGen)
uint32_t Idx
#define TGEN2
#define TGEN1
#define TGENR

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen