Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/******** Graph.cpp *******/
#include"Modular_Obs_Graph.h"
//#include<conio.h>
bdd * Temp;//tableau intermdiaire pour calculer la taille (nb bdd) du graphe
/********* setInitialState *****/
void Modular_Obs_Graph::setInitialState(Modular_Class_Of_State *c)
{
currentstate=initialstate=c;
}
/*----------------------find()----------------*/
Modular_Class_Of_State * Modular_Obs_Graph::find(Modular_Class_Of_State* c)
{
bool arret;
for(Modular_Obs_Graph_Nodes::const_iterator i=GONodes.begin();!(i==GONodes.end());i++)
{
//if((c->blocage!=(*i)->blocage)||(c->boucle!=(*i)->boucle))
//{
arret=false;
for(unsigned int k=0;((k<(c->State).size())&&(!arret));k++)
if(!(c->State[k]==(*i)->State[k]))
arret=true;
if(!arret)
return *i;
//}
}
return NULL;
}
/*----------------------find2()----------------*/
//version modulaire on vrifie la projection
Modular_Class_Of_State * Modular_Obs_Graph::find2(Modular_Class_Of_State* c, Set SRConcernes)
{
bool arret;
for(Modular_Obs_Graph_Nodes::const_iterator i=GONodes.begin();!(i==GONodes.end());i++)
{
//if((c->blocage!=(*i)->blocage)||(c->boucle!=(*i)->boucle))
//{
arret=false;
for(unsigned int k=0;((k<(c->State).size())&&(!arret));k++)
if(!(SRConcernes.find(k)==SRConcernes.end()))
if(!(c->State[k]==(*i)->State[k]))
arret=true;
if(!arret&&(c->blocage==(*i)->blocage)&&(c->boucle==(*i)->boucle))
return *i;
//}
}
return NULL;
}
/*-----------------------AddARc2----------------*/
void Modular_Obs_Graph::addArc(Modular_Class_Of_State* Pred,Modular_Class_Of_State* Suc,const char* t)
{
//cout<<"ici addArc entre "<<*Pred<<" et "<<*Suc<<endl;
Modular_Edge arc=Modular_Edge(Suc,t);
Modular_Edge cra=Modular_Edge(Pred,t);
if(Pred->Successors.find(arc)==Pred->Successors.end())
{
//cout<<"OK \n";
Pred->Successors.insert(Pred->Successors.begin(),arc);
Suc->Predecessors.insert(Suc->Predecessors.begin(),cra);
nbArcs++;
}
//else
// cout<<"KO \n";
//int toto;cin>>toto;
}
/*----------------------insert() ------------*/
void Modular_Obs_Graph::insert(Modular_Class_Of_State *c)
{
c->Visited=false;
this->GONodes.push_back(c);
nbStates++;
}
/*----------------------InitVisit()------------------------*/
void Modular_Obs_Graph::InitVisit(Modular_Class_Of_State * S,size_t nb)
{
//cout<<"____________ nb = __________________ "<<nb<<endl;
//cout<<"____________ nbStates = __________________ "<<nbStates<<endl;
if(nb<=nbStates)
{
// cout<<"nb < = nbStates\n";
S->Visited=false;
for(Modular_Edges::const_iterator i=S->Successors.begin();!(i==S->Successors.end());i++)
{
if((*i).first->Visited==true)
{
nb++;
InitVisit((*i).first,nb);
}
}
}
}
/*----------------------NbBddNod()------------------------*/
void Modular_Obs_Graph::TAB_BDDNODES(Modular_Class_Of_State * S, size_t &nb)
{
if(S->Visited==false)
{
//cout<<"ETAT NON VISITE : ";
//cout<<*S<<endl;
//int tt;cin>>tt;
for(unsigned int k=0;k<S->State.size();k++,nb++)
Temp[nb-1]=S->State[k];
nb--;
S->Visited=true;
//int bddnode=0;
//for(k=0;k<S->State.size();k++)
// bddnode+=bdd_nodecount(S->State[k]);
//int size_succ=0;
for(Modular_Edges::const_iterator i=S->Successors.begin();!(i==S->Successors.end());i++)
{
if((*i).first->Visited==false)
{
nb++;
TAB_BDDNODES((*i).first,nb);
}
}
}
}
/*------------------------------------------Affichage du graphe -------------*/
void Modular_Obs_Graph::printCompleteInformation(int nbsubnets)
{
cout << "\n\nGRAPH SIZE : \n";
cout<< "\n\tNB MARKING : "<< nbMarking;
cout<< "\n\tNB NODES : "<< nbStates;
cout<<"\n\tNB ARCS : " <<nbArcs<<endl;
cout<<" \n\nCOMPLETE INFORMATION ?(y/n)\n";
char c;
cin>>c;
//InitVisit(initialstate,n);
Temp=new bdd[nbStates*nbsubnets];
size_t n=1;
//cout<<"NB BDD NODE : "<<NbBddNode(initialstate,n)<<endl;
TAB_BDDNODES(initialstate,n);
cout<<"NB BDD NODE : "<<bdd_anodecount(Temp,nbStates*nbsubnets)<<endl;
//cout<<"Shared Nodes : "<<bdd_anodecount(Tab,nbStates)<<endl;
InitVisit(initialstate,1);
if(c=='y'||c=='Y')
{
size_t n=1;
printGraph(initialstate,n);
}
}
/********* printGraph *****/
void Modular_Obs_Graph::printGraph(Modular_Class_Of_State *s,size_t &nb)
{
//cout<<"Print Graph \n";
//int toto;cin>>toto;
if(nb<=nbStates)
{
cout<<"\nSTATE NUMBER "<<nb<<" : \n";
s->Visited=true;
printsuccessors(s);
getchar();
printpredecessors(s);
getchar();
Modular_Edges::const_iterator i;
for(i=s->Successors.begin();!(i==s->Successors.end());i++)
{
if((*i).first->Visited==false)
{
nb++;
printGraph((*i).first, nb);
}
}
}
}
/*-------------------------Reset()----------------------------*/
void Modular_Obs_Graph::Reset()
{
currentstate=NULL;
nbArcs=nbMarking=nbStates=0;
}
/*---------void print_successors_class(Class_Of_State *)------------*/
void Modular_Obs_Graph::printsuccessors(Modular_Class_Of_State *s)
{
Modular_Edges::const_iterator i;
cout<<*s<<endl;
if(s->boucle)
cout<<"\n\tON BOUCLE DESSUS AVEC EPSILON\n";
if(s->blocage)
cout<<"\n\tEXISTENCE D'UN ETAT BLOCANT\n";
cout<<"\n\tSES SUCCESSEURS SONT ( "<<s->Successors.size()<<" ) :\n\n";
getchar();
for(i =s->Successors.begin();!(i==s->Successors.end());i++)
{
cout<<" \t---"<<(*i).second<<" -->";
cout<<*((*i).first)<<endl;
getchar();
}
}
/*---------void printpredescessors(Class_Of_State *)------------*/
void Modular_Obs_Graph::printpredecessors(Modular_Class_Of_State *s)
{
Modular_Edges::const_iterator i;
cout<<"\n\tSES PREDESCESSEURS SONT ( "<<s->Predecessors.size()<<" ) :\n\n";
getchar();
for(i =s->Predecessors.begin();!(i==s->Predecessors.end());i++)
{
cout<<" \t---"<<(*i).second<<" -->";
cout<<*(*i).first<<endl;
getchar();
}
}