syn_supcmpl.cpp
Go to the documentation of this file.
1/** @file syn_supcmpl.cpp Supremal complete sublanguage for infinite time behaviours */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2010, 2025 Thomas Moor
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
20
21
22//#define FAUDES_DEBUG_FUNCTION
23
24#include "syn_supcmpl.h"
25#include "syn_supcon.h"
26#include "syn_supnorm.h"
27#include "syn_functions.h"
28
29
30namespace faudes {
31
32
33
34/*
35***************************************************************************************
36***************************************************************************************
37 Implementation SupConCmplClosed
38***************************************************************************************
39***************************************************************************************
40*/
41
42
43// supcon complete
45 const Generator& rPlantGen,
46 const EventSet& rCAlph,
47 const Generator& rSpecGen,
48 Generator& rResGen)
49{
50 FD_DF("SupConCmplClosed(" << rPlantGen.Name() << "," << rSpecGen.Name()<< ")");
51
52 // exceptions on invalid parameters, same as std synthesis
53 ControlProblemConsistencyCheck(rPlantGen,rCAlph,rSpecGen);
54
55 // prepare result
56 Generator* pResGen = &rResGen;
57 if(&rResGen== &rPlantGen || &rResGen== &rSpecGen) {
58 pResGen= rResGen.New();
59 }
60 pResGen->Clear();
61 pResGen->Name("SupConCmplClosed("+rPlantGen.Name()+", "+rSpecGen.Name()+")");
62 pResGen->InjectAlphabet(rPlantGen.Alphabet());
63
64 //check for trivial result
65 if(rSpecGen.InitStatesEmpty()){
66 FD_DF("SupConCmplClosed: empty language specification - empty result.");
67 }
68
69
70 // have a reverse composition map
71 std::map< std::pair<Idx,Idx>, Idx> revmap;
72
73 // parallel composition (result is reachable)
74 SupConProduct(rPlantGen, rCAlph, rSpecGen, revmap, *pResGen);
75
76 // make resulting generator complete and controllabel
77 while(true) {
78 Idx state_num = pResGen->Size();
79 if(pResGen->InitStates().Empty()) break;
80 pResGen->Complete();
81 if(pResGen->InitStates().Empty()) break;
82 SupConClosedUnchecked(rPlantGen, rCAlph, *pResGen);
83 if(pResGen->Size() == state_num) break;
84 }
85
86 // convenience state names
87 if(rPlantGen.StateNamesEnabled() && rSpecGen.StateNamesEnabled() && rResGen.StateNamesEnabled())
88 SetComposedStateNames(rPlantGen, rSpecGen, revmap, *pResGen);
89 else
90 pResGen->StateNamesEnabled(false);
91
92 // copy result
93 if(pResGen != &rResGen) {
94 rResGen.Move(*pResGen);
95 delete pResGen;
96 }
97
98}
99
100
101// user wrapper
103 const System& rPlantGen,
104 const Generator& rSpecGen,
105 Generator& rResGen)
106{
107
108 // execute
109 SupConCmplClosed(rPlantGen, rPlantGen.ControllableEvents(),rSpecGen,rResGen);
110
111 // copy all attributes of input alphabet
112 rResGen.EventAttributes(rPlantGen.Alphabet());
113
114}
115
116
117
118
119/*
120***************************************************************************************
121***************************************************************************************
122 Implementation SupConCmpl
123***************************************************************************************
124***************************************************************************************
125*/
126
127
128// supcon complete
130 const Generator& rPlantGen,
131 const EventSet& rCAlph,
132 const Generator& rSpecGen,
133 Generator& rResGen)
134{
135 FD_DF("SupConCmpl(" << rPlantGen.Name() << "," << rSpecGen.Name()<< ")");
136
137 // exceptions on invalid parameters, same as std synthesis
138 ControlProblemConsistencyCheck(rPlantGen,rCAlph,rSpecGen);
139
140 // prepare result
141 Generator* pResGen = &rResGen;
142 if(&rResGen== &rPlantGen || &rResGen== &rSpecGen) {
143 pResGen= rResGen.New();
144 }
145 pResGen->Clear();
146 pResGen->Name("SupConCmpl("+rPlantGen.Name()+", "+rSpecGen.Name()+")");
147 pResGen->InjectAlphabet(rPlantGen.Alphabet());
148
149 //check for trivial result
150 if(rSpecGen.InitStatesEmpty()){
151 FD_DF("SupConCmpl: empty language specification - empty result.");
152 }
153
154
155 // have a reverse composition map
156 std::map< std::pair<Idx,Idx>, Idx> revmap;
157
158 // parallel composition (result is reachable)
159 SupConProduct(rPlantGen, rCAlph, rSpecGen, revmap, *pResGen);
160
161 // make resulting generator complete and controllabel and coaccessible
162 while(true) {
163 Idx state_num = pResGen->Size();
164 if(pResGen->InitStates().Empty()) break;
165 pResGen->Coaccessible();
166 if(pResGen->InitStates().Empty()) break;
167 pResGen->Complete();
168 if(pResGen->InitStates().Empty()) break;
169 SupConClosedUnchecked(rPlantGen, rCAlph, *pResGen);
170 if(pResGen->Size() == state_num) break;
171 }
172
173 // convenience state names
174 if(rPlantGen.StateNamesEnabled() && rSpecGen.StateNamesEnabled() && rResGen.StateNamesEnabled())
175 SetComposedStateNames(rPlantGen, rSpecGen, revmap, *pResGen);
176 else
177 pResGen->StateNamesEnabled(false);
178
179 // copy result
180 if(pResGen != &rResGen) {
181 rResGen.Move(*pResGen);
182 delete pResGen;
183 }
184
185}
186
187
188// user wrapper
190 const System& rPlantGen,
191 const Generator& rSpecGen,
192 Generator& rResGen)
193{
194
195 // execute
196 SupConCmpl(rPlantGen, rPlantGen.ControllableEvents(),rSpecGen,rResGen);
197
198 // copy all attributes of input alphabet
199 rResGen.EventAttributes(rPlantGen.Alphabet());
200
201}
202
203
204
205/*
206***************************************************************************************
207***************************************************************************************
208 Implementation SupConNormCmpl
209***************************************************************************************
210***************************************************************************************
211*/
212
213
214// SupConNormCmpl(rL,rCAlph,rOAlph,rK,rResult)
216 const Generator& rL,
217 const EventSet& rCAlph,
218 const EventSet& rOAlph,
219 const Generator& rK,
220 Generator& rResult)
221{
222 FD_DF("SupConNormCmpl(" << rL.Name() << "," << rK.Name() << ")");
223 // initialize: K0
224 Generator K0;
225 K0.StateNamesEnabled(false);
226 Product(rL,rK,K0);
227 K0.Coaccessible();
228 // initialize: closure(rL)
229 Generator L=rL;
230 L.StateNamesEnabled(false);
231 L.Trim();
232 MarkAllStates(L);
233 // loop
234 Generator Ki=K0;
235 Ki.StateNamesEnabled(false);
236 while(1) {
237 FD_DF("SupConNormCmpl(" << rL.Name() << "," << rK.Name() << "): #" << Ki.Size() << " m#" << Ki.MarkedStatesSize());
238 // keep copy of recent
239 rResult=Ki;
240 // cheep closure (for coreachable generator)
241 Ki.InjectMarkedStates(Ki.States());
242 // synthesise closed
243 SupConNormClosed(L,rCAlph,rOAlph,Ki,Ki);
244 Complete(Ki);
245 // restrict
246 Product(K0,Ki,Ki);
247 Ki.Coaccessible();
248 // test (sequence is decreasing anyway)
249 if(LanguageInclusion(rResult,Ki)) break;
250 }
251 FD_DF("SupConNormCmpl(" << rL.Name() << "," << rK.Name() << "): done");
252}
253
254
255/** rti wrapper */
257 const System& rPlantGen,
258 const Generator& rSpecGen,
259 Generator& rResGen)
260{
261 FD_DF("SupConNormCmpl(" << rPlantGen.Name() << "," << rSpecGen.Name() << "): rti wrapper");
262 // prepare result
263 Generator* pResGen = &rResGen;
264 if(&rResGen== &rPlantGen || &rResGen== &rSpecGen) {
265 pResGen= rResGen.New();
266 }
267 // execute
268 SupConNormCmpl(rPlantGen,rPlantGen.ControllableEvents(),rPlantGen.ObservableEvents(),rSpecGen,*pResGen);
269 // copy all attributes of input alphabet
270 pResGen->EventAttributes(rPlantGen.Alphabet());
271 // copy result
272 if(pResGen != &rResGen) {
273 rResGen.Move(*pResGen);
274 delete pResGen;
275 }
276}
277
278
279
280
281} // name space
#define FD_DF(message)
const std::string & Name(void) const
const TaEventSet< EventAttr > & Alphabet(void) const
EventSet ControllableEvents(void) const
EventSet ObservableEvents(void) const
const EventSet & Alphabet(void) const
bool InitStatesEmpty(void) const
const StateSet & InitStates(void) const
virtual vGenerator & Move(Type &rGen)
virtual vGenerator * New(void) const
void InjectMarkedStates(const StateSet &rNewMarkedStates)
Idx MarkedStatesSize(void) const
virtual void EventAttributes(const EventSet &rEventSet)
bool StateNamesEnabled(void) const
Idx Size(void) const
virtual void Clear(void)
const StateSet & States(void) const
void InjectAlphabet(const EventSet &rNewalphabet)
bool Empty(void) const
void Complete(vGenerator &rGen)
bool LanguageInclusion(const Generator &rGen1, const Generator &rGen2)
void Product(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void MarkAllStates(vGenerator &rGen)
void SupConNormClosed(const Generator &rL, const EventSet &rCAlph, const EventSet &rOAlph, const Generator &rK, Generator &rResult)
void SupConNormCmpl(const Generator &rL, const EventSet &rCAlph, const EventSet &rOAlph, const Generator &rK, Generator &rResult)
void SupConCmplClosed(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSpecGen, Generator &rResGen)
void SupConCmpl(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSpecGen, Generator &rResGen)
uint32_t Idx
void SetComposedStateNames(const Generator &rGen1, const Generator &rGen2, const std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, Generator &rGen12)
void ControlProblemConsistencyCheck(const GeneratorVector &rPlantGenVec, const EventSet &rConAlph, const GeneratorVector &rSpecGenVec)
void SupConClosedUnchecked(const Generator &rPlantGen, const EventSet &rCAlph, Generator &rSupCandGen)
void SupConProduct(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSpecGen, std::map< std::pair< Idx, Idx >, Idx > &rCompositionMap, Generator &rResGen)

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen