tp_tparallel.h

Go to the documentation of this file.
00001 /** @file tp_tparallel.h  Parallel composition for timed automata */
00002 
00003 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2007  Thomas Moor
00006    Exclusive copyright is granted to Klaus Schmidt
00007 
00008 */
00009 
00010 
00011 // TODO: this code needs testing!
00012 // TODO: use cparallel for contr. attribs
00013 
00014 #ifndef FAUDES_TP_TPARALLEL_H
00015 #define FAUDES_TP_TPARALLEL_H
00016 
00017 #include "tp_tgenerator.h"
00018 
00019 namespace faudes {
00020 
00021 
00022 // convenience defs for template functions
00023 #define TEMP template < \
00024   class GlobalAttr1, class StateAttr1, class EventAttr1, class TransAttr1, \
00025   class GlobalAttr2, class StateAttr2, class EventAttr2, class TransAttr2, \
00026   class GlobalAttrR, class StateAttrR, class EventAttrR, class TransAttrR >
00027 
00028 #define TGEN1 TtGenerator<GlobalAttr1,StateAttr1,EventAttr1,TransAttr1>
00029 #define TGEN2 TtGenerator<GlobalAttr2,StateAttr2,EventAttr2,TransAttr2>
00030 #define TGENR TtGenerator<GlobalAttrR,StateAttrR,EventAttrR,TransAttrR>
00031 
00032 
00033 /**
00034  * Parallel composition of timed generators. 
00035  * Arguments rGen1 and rGen2 are assumed to have disjoind clocksets.
00036  * This implementation considers accessible states only. 
00037  *
00038  * Technically, this function is a template, but timed attribute interfaces
00039  * are assumed.
00040  *
00041  * @param rGen1
00042  *   First generator
00043  * @param rGen2
00044  *   Second generator
00045  * @param rResGen
00046  *   Reference to resulting parallel composition generator
00047  *
00048  * @ingroup TimedPlugin
00049  */
00050 TEMP void TParallel(const TGEN1& rGen1, const TGEN2& rGen2, TGENR& rResGen);
00051 
00052 
00053 /**
00054  * Parallel composition of timed generators. 
00055  * Arguments rGen1 and rGen2 are assumed to have disjoind clocksets.
00056  * This implementation considers accessible states only. 
00057  *
00058  * Technically, this function is a template, but timed attribute interfaces
00059  * are assumed.  This version fills given reverse composition map with indices. 
00060  *
00061  * @param rGen1
00062  *   First generator
00063  * @param rGen2
00064  *   Second generator
00065  * @param rReverseCompositionMap
00066  *   Reverse composition map (map< pair<Idx,Idx>, Idx>)
00067  * @param rResGen
00068  *   Reference to resulting parallel composition generator
00069  *
00070  * @ingroup TimedPlugin
00071  * @ingroup TimedPlugin
00072  */
00073 TEMP void TParallel(
00074     const TGEN1& rGen1, const TGEN2& rGen2,
00075     std::map< std::pair<Idx,Idx>, Idx>& rReverseCompositionMap, 
00076     TGENR& rResGen);
00077 
00078 
00079 
00080 /*
00081  **************************************************************************************
00082  **************************************************************************************
00083  implementation
00084  **************************************************************************************
00085  **************************************************************************************
00086  */
00087 
00088 
00089 // TParallel(rGen1, rGen2, res) (wrapper)
00090 TEMP void TParallel(const TGEN1& rGen1, const TGEN2& rGen2, TGENR& rResGen) {
00091   std::map< std::pair<Idx,Idx>, Idx> rcmap;
00092   TParallel(rGen1, rGen2, rcmap, rResGen);
00093 }
00094  
00095 
00096 // TParallel(rGen1, rGen2, rReverseCompositionMap, res)
00097 TEMP void TParallel(
00098   const TGEN1& rGen1, const TGEN2& rGen2, 
00099   std::map< std::pair<Idx,Idx>, Idx>& rReverseCompositionMap, 
00100   TGENR& rResGen)
00101 {
00102   FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << ")");
00103   // todo: exception for non-disjoint clocksets
00104   // call untimed parallel composition, incl virtual clear
00105   Parallel( rGen1, rGen2, rReverseCompositionMap, rResGen);
00106   // 1. union clockset
00107   ClockSet clocks12;
00108   clocks12.InsertSet(rGen1.Clocks());
00109   clocks12.InsertSet(rGen2.Clocks());
00110   FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): clocks:" << clocks12.ToString());
00111   FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): clocks:" << rGen1.Clocks().ToString());
00112   rResGen.InjectClocks(clocks12);
00113   // 2. intersect invariants
00114   std::map< std::pair<Idx,Idx>, Idx>::const_iterator rcit;
00115   for(rcit=rReverseCompositionMap.begin(); rcit!=rReverseCompositionMap.end(); rcit++) {
00116     Idx x1=rcit->first.first;
00117     Idx x2=rcit->first.second;
00118     Idx x12=rcit->second;
00119     if(!rResGen.ExistsState(x12)) continue;
00120     TimeConstraint invariant12;
00121     invariant12 << rGen1.Invariant(x1);
00122     invariant12 <<  rGen2.Invariant(x2);
00123     FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): invariant " << x1 << "|" << x2 
00124        << " :" << invariant12.ToString());
00125     rResGen.Invariant(x12,invariant12);
00126   }
00127   // 3. set up composition map (todo: avoid this)
00128   std::map< Idx, std::pair<Idx,Idx> > compositionmap; 
00129   for(rcit=rReverseCompositionMap.begin(); rcit!=rReverseCompositionMap.end(); rcit++) 
00130     compositionmap[rcit->second]=rcit->first;
00131   // 4. resets and guards
00132   TransSet::Iterator tit;
00133   for(tit=rResGen.TransRelBegin(); tit!=rResGen.TransRelEnd(); tit++) {
00134     // hypothesis: unconstraint guard, no resets
00135     TimeConstraint guard;
00136     ClockSet resets;
00137     // if event is in Gen1, intersect with gurad of Gen1
00138     if(rGen1.ExistsEvent(tit->Ev)) {
00139        Transition t1;
00140        t1.X1=compositionmap[tit->X1].first;
00141        t1.Ev=tit->Ev;
00142        t1.X2=compositionmap[tit->X2].first;
00143        FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): guard/resets in Gen1 for " << t1.Str());  
00144        guard.Insert(rGen1.Guard(t1));
00145        resets.InsertSet(rGen1.Resets(t1));
00146     }
00147     // if event is in Gen2, intersect with gurad of Gen2
00148     if(rGen2.ExistsEvent(tit->Ev)) {
00149        Transition t2;
00150        t2.X1=compositionmap[tit->X1].second;
00151        t2.Ev=tit->Ev;
00152        t2.X2=compositionmap[tit->X2].second;
00153        FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): guard/resets in Gen2 for " << t2.Str());  
00154        guard.Insert(rGen2.Guard(t2));
00155        resets.InsertSet(rGen2.Resets(t2));
00156     }
00157     FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): guard " << tit->Str()  
00158        << " :" << guard.ToString());
00159     rResGen.Guard(*tit,guard);
00160     FD_DF("TParallel(" << &rGen1 << "," << &rGen2 << "): resets " << tit->Str()  
00161        << " :" << resets.ToString());
00162     rResGen.Resets(*tit,resets);
00163   }
00164   FD_DF("TParallel: done ");
00165 }
00166 
00167 
00168 
00169 
00170 #undef TEMP
00171 #undef GEN1
00172 #undef GEN2
00173 #undef GENR
00174 
00175 
00176 } // namespace faudes
00177 
00178 #endif 
00179 

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen