|
Go to the documentation of this file.
45 std::vector< Polyhedron > Inv;
47 for( int i=0; i< szi; ++i) {
48 for( int j=0; j< szj; ++j) {
49 std::stringstream name;
50 name << "Inv_" << j+1 << "_" << i+1;
53 Bij. At(0, -1* (mesh*j - 2*overlap));
54 Bij. At(1, (mesh*(j+1) + 2*overlap));
55 Bij. At(2, -1* (mesh*i - 2*overlap));
56 Bij. At(3, (mesh*(i+1) + 2*overlap));
59 Invij. Name(name.str());
66 BAll. At(0, -1* (mesh*0 - 2*overlap));
67 BAll. At(1, (mesh*szj + 2*overlap));
68 BAll. At(2, -1* (mesh*0 - 2*overlap));
69 BAll. At(3, (mesh*szi + 2*overlap));
73 std::vector< Polyhedron > Rate;
74 std::vector< std::string > Direction;
75 EventSet::Iterator uit=uevents. Begin();
76 EventSet::Iterator uit_end=uevents. End();
77 for(;uit!=uit_end;++uit) {
81 Direction.push_back( "n");
86 Direction.push_back( "ne");
91 Direction.push_back( "e");
96 Direction.push_back( "se");
101 Direction.push_back( "s");
106 Direction.push_back( "sw");
111 Direction.push_back( "w");
116 Direction.push_back( "nw");
122 Bd. At(0, -1* (F. At(0) - disturbance));
123 Bd. At(1, (F. At(0) + disturbance));
124 Bd. At(2, -1* (F. At(1) - disturbance));
125 Bd. At(3, (F. At(1) + disturbance));
127 Rated. Name(Direction.back());
129 Rate.push_back(Rated);
136 BNone. At(2, -1* (1));
139 RateNone. AB(A42,BNone);
143 for( int j=0; j< szj; ++j) {
144 for( int i=0; i< szi; ++i) {
145 for( int d=0; d<Direction.size(); ++d) {
146 std::stringstream name;
147 name << "q_" << j+1 << "_" << i+1 << "_" << Direction.at(d);
150 harobot. Rate(q,Rate.at(d));
157 for( int j=0; j< szj; ++j) {
158 for( int i=0; i< szi; ++i) {
159 std::stringstream name;
160 name << "q_" << j+1 << "_" << i+1 << "_?";
163 harobot. Rate(q,RateNone);
176 for( int j=0; j< szj; ++j) {
177 for( int i=0; i< szi; ++i) {
178 std::stringstream name1;
179 name1 << "q_" << j+1 << "_" << i+1 << "_?";
182 std::stringstream name2;
184 name2 << "q_" << j+1 << "_" << i+1 << "_n";
190 name2 << "q_" << j+1 << "_" << i+1 << "_ne";
196 name2 << "q_" << j+1 << "_" << i+1 << "_e";
202 name2 << "q_" << j+1 << "_" << i+1 << "_s";
208 name2 << "q_" << j+1 << "_" << i+1 << "_s";
214 name2 << "q_" << j+1 << "_" << i+1 << "_sw";
220 name2 << "q_" << j+1 << "_" << i+1 << "_w";
226 name2 << "q_" << j+1 << "_" << i+1 << "_nw";
234 for( int j=0; j< szj; ++j) {
235 for( int i=0; i< szi; ++i) {
236 std::stringstream nameev;
237 if((j+1==szj) && (i+1 ==szi))
239 else if((j+1==1) && (i+1 ==1))
242 nameev << "y_" << j+1 << "_" << i+1;
256 for( int j=0; j< szj; ++j) {
257 for( int i=0; i< szi; ++i) {
258 for( int d=0; d<Direction.size(); ++d) {
259 std::stringstream name1;
260 name1 << "q_" << j+1 << "_" << i+1 << "_" << Direction.at(d);
263 std::stringstream name2;
264 std::stringstream nameev;
269 name2 << "q_" << j+1 << "_" << i+1+1 << "_?";
273 nameev << "y_" << j+1 << "_" << i+1+1;
277 if((j+1==1) && (i+1+1 ==1)) {
281 if((j+1==szj) && (i+1+1==szi)) {
286 if((q2!=0) && (ev!=0)) {
291 Bgrd. At(0, -1* (mesh*j - 2*overlap));
292 Bgrd. At(1, (mesh*(j+1) + 2*overlap));
293 Bgrd. At(2, -1* (mesh*(i+1) + 1*overlap));
294 Bgrd. At(3, (mesh*(i+1) + 2*overlap));
300 name2 << "q_" << j+1+1 << "_" << i+1 << "_?";
304 nameev << "y_" << j+1+1 << "_" << i+1;
308 if((j+1+1==1) && (i+1==1)) {
312 if((j+1+1==szj) && (i+1==szi)) {
317 if((q2!=0) && (ev!=0)) {
322 Bgrd. At(0, -1* (mesh*(j+1) + 1*overlap));
323 Bgrd. At(1, (mesh*(j+1) + 2*overlap));
324 Bgrd. At(2, -1* (mesh*(i) - 2*overlap));
325 Bgrd. At(3, (mesh*(i+1) + 2*overlap));
331 name2 << "q_" << j+1 << "_" << i+1-1 << "_?";
335 nameev << "y_" << j+1 << "_" << i+1-1;
339 if((j+1==1) && (i+1-1 ==1)) {
343 if((j+1==szj) && (i+1-1==szi)) {
348 if((q2!=0) && (ev!=0)) {
353 Bgrd. At(0, -1* (mesh*j - 2*overlap));
354 Bgrd. At(1, (mesh*(j+1) + 2*overlap));
355 Bgrd. At(2, -1* (mesh*(i) - 2*overlap));
356 Bgrd. At(3, (mesh*(i) - 1*overlap));
362 name2 << "q_" << j+1-1 << "_" << i+1 << "_?";
366 nameev << "y_" << j+1-1 << "_" << i+1;
370 if((j+1-1==1) && (i+1 ==1)) {
374 if((j+1-1==szj) && (i+1==szi)) {
379 if((q2!=0) && (ev!=0)) {
384 Bgrd. At(0, -1* (mesh*(j) - 2*overlap));
385 Bgrd. At(1, (mesh*(j) - 1*overlap));
386 Bgrd. At(2, -1* (mesh*(i) - 2*overlap));
387 Bgrd. At(3, (mesh*(i+1) + 2*overlap));
396 StateSet::Iterator sit_end= harobot. StatesEnd();
397 for(;sit!=sit_end;++sit) {
408 uevents. Insert( "u_northeast");
409 uevents. Insert( "u_southeast");
410 uevents. Insert( "u_southwest");
411 uevents. Insert( "u_northwest");
430 std::vector< Polyhedron > Rate;
431 std::vector< std::string > Direction;
432 EventSet::Iterator uit=uevents. Begin();
433 EventSet::Iterator uit_end=uevents. End();
434 for(;uit!=uit_end;++uit) {
438 Direction.push_back( "n");
443 Direction.push_back( "ne");
448 Direction.push_back( "e");
453 Direction.push_back( "se");
458 Direction.push_back( "s");
463 Direction.push_back( "sw");
468 Direction.push_back( "w");
473 Direction.push_back( "nw");
479 Bd. At(0, -1* (F. At(0) - disturbance));
480 Bd. At(1, (F. At(0) + disturbance));
481 Bd. At(2, -1* (F. At(1) - disturbance));
482 Bd. At(3, (F. At(1) + disturbance));
484 Rated. Name(Direction.back());
486 Rate.push_back(Rated);
493 BNone. At(2, -1* (1));
496 RateNone. AB(A42,BNone);
500 for( int d=0; d<Direction.size(); ++d) {
501 std::stringstream name;
502 name << "q_" << Direction.at(d);
505 hamarine. Rate(q,Rate.at(d));
510 std::string nameqq= "q_?";
512 hamarine. Rate(qq,RateNone);
516 uit_end=uevents. End();
517 for(;uit!=uit_end;++uit) {
530 std::cout << "Setting up model: INTERNAL ERRROR A\n";
540 for( int d=0; d<Direction.size(); ++d) {
541 std::string namen = "q_" + Direction.at(d);
548 if((Direction.at(d)== "ne") || (Direction.at(d)== "nw")) {
554 Bgrd. At(0, -1* (0 ));
555 Bgrd. At(1, (width ));
556 Bgrd. At(2, -1* (height - overlap));
557 Bgrd. At(3, (height ));
562 if((Direction.at(d)== "se") || (Direction.at(d)== "sw")) {
568 Bgrd. At(0, -1* (0 ));
569 Bgrd. At(1, (width ));
570 Bgrd. At(2, -1* (0 ));
571 Bgrd. At(3, (overlap ));
576 if((Direction.at(d)== "nw") || (Direction.at(d)== "sw")) {
582 Bgrd. At(0, -1* (0 ));
583 Bgrd. At(1, (overlap ));
584 Bgrd. At(2, -1* (0 ));
585 Bgrd. At(3, (height ));
590 if((Direction.at(d)== "ne") || (Direction.at(d)== "se")) {
596 Bgrd. At(0, -1* (width-overlap ));
597 Bgrd. At(1, (width ));
598 Bgrd. At(2, -1* (0 ));
599 Bgrd. At(3, (height ));
612 std::map< Idx, HybridStateSet* > sstatespe;
616 std::cout << "################################\n";
617 std::cout << "# current state set \n";
619 std::cout << "################################\n";
622 std::cout << "################################\n";
623 std::cout << "# mode transitions \n";
626 for(;qit!=qit_end;++qit){
629 for(;tit!=tit_end;++tit)
630 std::cout << plant. TStr(*tit) << "\n";
632 std::cout << "################################\n";
636 std::cout << "################################\n";
637 std::cout << "# successor events \n";
638 std::map< Idx, HybridStateSet* >::iterator sit=sstatespe.begin();
639 std::map< Idx, HybridStateSet* >::iterator sit_end=sstatespe.end();
641 for(;sit!=sit_end;++sit) {
642 enabled. Insert(sit->first);
643 std::cout << plant. EStr(sit->first) << " ";
647 std::cout << "\n################################\n";
655 std::cout << "choose event (or 'x' for exit): ";
658 if(choice== "x") return 0;
660 if(enabled. Exists(ev)) break;
662 if(enabled. Exists(ev)) break;
664 sit=sstatespe.find(ev);
667 std::cout << "################################\n";
668 std::cout << "# successor states for " << plant. EStr(sit->first) << "\n";
669 sit->second->DWrite(plant);
670 std::cout << "################################\n";
673 std::cout << "accept ('n' for no, other for yes): ";
676 if(choice!= "n") break;
681 cstates. Assign(*sit->second);
694 robot(3 , 5 , 10 , 1 , 1 , lioha, uevents);
710 for(;qit!=qit_end;++qit){
714 istates. Insert(*qit,poly);
739 std::cout << "################################\n";
740 std::cout << "# compute l-complete approximation, time variant \n";
741 std::cout << "################################\n";
751 std::cout << "################################\n";
752 std::cout << "# compute l-complete approximation, time invariant \n";
753 std::cout << "################################\n";
766 std::cout << "################################\n";
767 std::cout << "# compose abstraction \n";
768 std::cout << "################################\n";
785 std::cout << "################################\n";
786 std::cout << "# target control synthesis \n";
787 std::cout << "# ctrl evs " << uevents. ToString() << "\n";
788 std::cout << "################################\n";
798 sfloop. Erase( "y_target");
845 aProduct(abst,spec,cmap_abst_spec,loop);
849 std::cout << "target control: #" << gsz << " / #" << loop. Size() << "\n";
851 StateSet::Iterator sit_end=loop. StatesEnd();
852 for(;sit!=sit_end;++sit) {
853 if(good. Exists(*sit)) continue;
857 for(;tit!=tit_end;++tit) {
858 if(good. Exists(tit->X2)) {ok= true; continue;}
859 if(uevents. Exists(tit->Ev)) continue;
865 if(good. Size()==gsz) break;
867 std::cout << "target control: #" << good. Size() << " / #" << loop. Size() << "\n";
870 std::cout << "target control: success (init state #" << loop. InitState() << " found to be good)\n";
872 std::cout << "target control: FAIL\n";
881 StateSet::Iterator sit_end=loop. StatesEnd();
882 for(;sit!=sit_end;++sit) {
884 if(good. Exists(*sit)) continue;
894 for(;tit!=tit_end;++tit) {
895 if(good. Exists(tit->X2)) break;
898 for(;tit2!=tit2_end;++tit2) {
899 if(good. Exists(tit2->X2)) break;
901 if(tit2!=tit2_end) break;
903 if(tit==tit_end) continue;
908 std::cout << "################################\n";
909 std::cout << "# diagnosis\n";
910 std::cout << "# tv-leaves to refine #" << tvleaves. Size() << "/" << tvabs. Experiment().Leaves().Size() << "\n";
911 std::cout << "# tiv-leaves to refine #" << tivleaves. Size() << "/" << tivabs. Experiment().Leaves().Size() << "\n";
912 std::cout << "################################\n";
916 std::cout << "################################\n";
917 std::cout << "# refine\n";
918 std::cout << "################################\n";
919 sit=tvleaves. Begin();
920 sit_end=tvleaves. End();
921 for(;sit!=sit_end;++sit) {
924 sit=tivleaves. Begin();
925 sit_end=tivleaves. End();
926 for(;sit!=sit_end;++sit) {
945 robot(3 , 5 , 10 , 1 , 1 , lioha, uevents);
961 for(;qit!=qit_end;++qit){
965 istates. Insert(*qit,poly);
990 std::cout << "################################\n";
991 std::cout << "# compute l-complete approximation, time invariant \n";
992 std::cout << "################################\n";
1008 abst. Name( "overall abstraction");
1012 abst. Write( "tmp_abs2.gen");
1014 std::cout << "################################\n";
1015 std::cout << "# cycle control synthesis \n";
1016 std::cout << "# ctrl evs " << uevents. ToString() << "\n";
1017 std::cout << "################################\n";
1037 EventSet::Iterator eit=other. Begin();
1038 for(;eit!=other. End();++eit) {
1049 aProduct(abst,spec,cmap_abst_spec,loop);
1056 int csz=constraint. Size();
1057 int tsz=target. Size();
1058 std::cout << "target control: constraint #" << csz << " target #" << tsz << "\n";
1062 int wsz=winning. Size();
1063 std::cout << "target control: #" << wsz << " / #" << loop. Size() << "\n";
1066 StateSet::Iterator sit_end=loop. StatesEnd();
1067 for(;sit!=sit_end;++sit) {
1068 if(winning. Exists(*sit)) continue;
1072 for(;tit!=tit_end;++tit) {
1073 if(winning. Exists(tit->X2)) {ok= true; continue;}
1074 if(target. Exists(tit->X2)) {ok= true; continue;}
1075 if(uevents. Exists(tit->Ev)) continue;
1079 if(ok) ctrlreach. Insert(*sit);
1081 if(ctrlreach <= winning) break;
1086 if(csz==constraint. Size()) break;
1089 std::cout << "target control: #" << winning. Size() << " / #" << loop. Size() << "\n";
1092 std::cout << "target control: success (init state #" << loop. InitState() << " found to be winning)\n";
1094 std::cout << "target control: FAIL\n";
1103 StateSet::Iterator sit_end=loop. StatesEnd();
1104 for(;sit!=sit_end;++sit) {
1106 if(winning. Exists(*sit)) continue;
1114 for(;tit!=tit_end;++tit) {
1115 if(winning. Exists(tit->X2)) break;
1118 for(;tit2!=tit2_end;++tit2) {
1119 if(winning. Exists(tit2->X2)) break;
1121 if(tit2!=tit2_end) break;
1123 if(tit==tit_end) continue;
1127 std::cout << "################################\n";
1128 std::cout << "# diagnosis\n";
1129 std::cout << "# tiv-leaves to refine #" << tivleaves. Size() << "/" << tivabs. Experiment().Leaves().Size() << "\n";
1130 std::cout << "################################\n";
1134 std::cout << "################################\n";
1135 std::cout << "# refine\n";
1136 std::cout << "################################\n";
1137 sit=tivleaves. Begin();
1138 sit_end=tivleaves. End();
1139 for(;sit!=sit_end;++sit) {
1158 marine(30 , 10 , 1 , 10 , 1 , lioha, uevents);
1163 std::cout << "################################\n";
1164 std::cout << "# linear hybrid automaton: \n";
1166 std::cout << "################################\n";
1167 std::cout << "# Valid() returns " << lioha. Valid() << "\n";
1168 std::cout << "################################\n";
1174 for(;qit!=qit_end;++qit){
1178 istates. Insert(*qit,poly);
1195 std::cout << "################################\n";
1196 std::cout << "# compute l-complete approximation, time invariant \n";
1197 std::cout << "################################\n";
1215 abst. Name( "overall abstraction");
1219 abst. Write( "tmp_abs2.gen");
1221 std::cout << "################################\n";
1222 std::cout << "# cycle control synthesis \n";
1223 std::cout << "# ctrl evs " << uevents. ToString() << "\n";
1224 std::cout << "################################\n";
1235 sfloop. Erase( "y_w");
1258 EventSet::Iterator eit=uevents. Begin();
1259 EventSet::Iterator eit_end=uevents. End();
1262 for(;eit!=eit_end;++eit)
1265 eit=uevents. Begin();
1266 eit_end=uevents. End();
1267 for(;eit!=eit_end;++eit) {
1269 EventSet::Iterator eit2=uevents. Begin();
1270 EventSet::Iterator eit2_end=uevents. End();
1271 for(;eit2!=eit2_end;++eit2)
1311 aProduct(abst,spec,cmap_abst_spec,loop);
1319 int csz=constraint. Size();
1320 int tsz=target. Size();
1321 std::cout << "target control: constraint #" << csz << " target #" << tsz << "\n";
1325 int wsz=winning. Size();
1326 std::cout << "target control: #" << wsz << " / #" << loop. Size() << "\n";
1329 StateSet::Iterator sit_end=loop. StatesEnd();
1330 for(;sit!=sit_end;++sit) {
1331 if(winning. Exists(*sit)) continue;
1335 for(;tit!=tit_end;++tit) {
1336 if(winning. Exists(tit->X2)) {ok= true; continue;}
1337 if(target. Exists(tit->X2)) {ok= true; continue;}
1338 if(uevents. Exists(tit->Ev)) continue;
1342 if(ok) ctrlreach. Insert(*sit);
1345 if(winning. Size()==wsz) break;
1349 if(csz==constraint. Size()) break;
1352 std::cout << "target control: #" << winning. Size() << " / #" << loop. Size() << "\n";
1355 std::cout << "target control: success (init state #" << loop. InitState() << " found to be winning)\n";
1357 std::cout << "target control: FAIL\n";
1359 std::cout << "target control: preparing ctrl\n";
1361 StateSet::Iterator sit_end=loop. StatesEnd();
1362 for(;sit!=sit_end;++sit) {
1363 if(!winning. Exists(*sit)) continue;
1367 for(;tit!=tit_end;++tit) {
1369 if(winning. Exists(tit->X2)) { continue;}
1370 if(target. Exists(tit->X2)) { continue;}
1371 if(uevents. Exists(tit->Ev)) { tremove. Insert(*tit); continue; }
1372 std::cout << "synthesis: INTERNAL ERROR C";
1375 tit=tremove. Begin();
1376 tit_end=tremove. End();
1377 for(;tit!=tit_end;++tit)
1380 loop. Write( "tmp_sup.gen");
1388 StateSet::Iterator sit_end=loop. StatesEnd();
1389 for(;sit!=sit_end;++sit) {
1391 if(winning. Exists(*sit)) continue;
1399 for(;tit!=tit_end;++tit) {
1400 if(winning. Exists(tit->X2)) break;
1403 for(;tit2!=tit2_end;++tit2) {
1404 if(winning. Exists(tit2->X2)) break;
1406 if(tit2!=tit2_end) break;
1408 if(tit==tit_end) continue;
1409 if(tivabs. Experiment().IsLeave(qtivabs)) tivleaves_goodchance. Insert(qtivabs);
1411 std::cout << "################################\n";
1412 std::cout << "# diagnosis\n";
1413 std::cout << "# tiv-leaves to refine #" << tivleaves. Size() << "/" << tivabs. Experiment().Leaves().Size() << "\n";
1414 std::cout << "# candidates with better chance #" << tivleaves_goodchance. Size() << "/" << tivabs. Experiment().Leaves().Size() << "\n";
1415 std::cout << "################################\n";
1418 std::cout << "################################\n";
1419 std::cout << "# refine\n";
1420 std::cout << "################################\n";
1421 sit=tivleaves_goodchance. Begin();
1422 sit_end=tivleaves_goodchance. End();
1424 for(;sit!=sit_end;++sit) {
1429 sit=tivleaves. Begin();
1430 sit_end=tivleaves. End();
1431 for(;sit!=sit_end;++sit) {
void InitialStates(CompatibleStates *istates)
void DWrite(const LinearHybridAutomaton &lha)
IndexSet::Iterator LocationsBegin(void) const
void Assign(const HybridStateSet &rOther)
IndexSet::Iterator LocationsEnd(void) const
void RefineUniformly(unsigned int depth)
const Generator & TivAbstraction(void)
const Generator & TvAbstraction(void)
void Experiment(faudes::Experiment *exp)
virtual void InitialiseFull()
virtual void InitialiseConstraint()
const Scalar::Type & At(int i, int j) const
void Zero(int rc=-1, int cc=-1)
bool Exists(const Idx &rIndex) const
void SymbolicName(Idx index, const std::string &rName)
bool Insert(const Idx &rIndex)
void EraseSet(const NameSet &rOtherSet)
virtual bool Erase(const Idx &rIndex)
void AB(const Matrix &rA, const Vector &rB)
virtual const std::string & Name(void) const
Idx Arg1State(Idx s12) const
Idx Arg2State(Idx s12) const
Iterator Begin(void) const
bool Insert(const Transition &rTransition)
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
const TaEventSet< EventAttr > & Alphabet(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
virtual bool Valid(void) const
const Polyhedron & Rate(Idx idx) const
const Polyhedron & InitialConstraint(Idx idx) const
const Polyhedron & StateSpace(void) const
const Polyhedron & Guard(const Transition &rTrans) const
const Polyhedron & Invariant(Idx idx) const
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
void Write(const Type *pContext=0) const
void SWrite(TokenWriter &rTw) const
const Scalar::Type & At(int i) const
StateSet::Iterator StatesBegin(void) const
StateSet::Iterator InitStatesBegin(void) const
bool SetTransition(Idx x1, Idx ev, Idx x2)
const StateSet & MarkedStates(void) const
TransSet::Iterator TransRelBegin(void) const
void ClrTransition(Idx x1, Idx ev, Idx x2)
Idx StateIndex(const std::string &rName) const
void InsEvents(const EventSet &events)
Idx EventIndex(const std::string &rName) const
std::string TStr(const Transition &rTrans) const
void Name(const std::string &rName)
StateSet::Iterator StatesEnd(void) const
TransSet::Iterator TransRelEnd(void) const
bool ExistsEvent(Idx index) const
std::string EStr(Idx index) const
Idx InitState(void) const
bool StateNamesEnabled(void) const
StateSet::Iterator InitStatesEnd(void) const
void GraphWrite(const std::string &rFileName, const std::string &rOutFormat="", const std::string &rDotExec="dot") const
const StateSet & States(void) const
void InjectAlphabet(const EventSet &rNewalphabet)
bool Exists(const T &rElem) const
virtual void RestrictSet(const TBaseSet &rOtherSet)
virtual void InsertSet(const TBaseSet &rOtherSet)
Iterator Begin(void) const
void SelfLoop(Generator &rGen, const EventSet &rAlphabet)
void aProduct(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void MarkAllStates(vGenerator &rGen)
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void PolyFinalise(const Polyhedron &fpoly)
void PolyIntersection(const Polyhedron &poly, Polyhedron &res)
int execute(LinearHybridAutomaton &plant, HybridStateSet &cstates)
void robot(int szi, int szj, int mesh, int overlap, int disturbance, LinearHybridAutomaton &harobot, EventSet &uevents)
void marine(int width, int height, int overlap, int velocity, int disturbance, LinearHybridAutomaton &hamarine, EventSet &uevents)
Idx ToIdx(const std::string &rString)
void LhaReach(const LinearHybridAutomaton &lha, const HybridStateSet &states, std::map< Idx, HybridStateSet * > &ostates, int *pCnt)
libFAUDES 2.33a
--- 2025.05.02
--- c++ api documentaion by doxygen
|