3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dfs, mc,
4 "Logging specific to MC DFS algorithm");
7 extern xbt_fifo_t mc_snapshot_stack;
8 mc_pairs_t mc_reached = NULL;
9 xbt_dynar_t initial_pairs = NULL;
11 xbt_dynar_t list_pairs_reached = NULL;
12 extern mc_snapshot_t initial_snapshot;
14 mc_pairs_t new_pair(mc_snapshot_t sn, mc_state_t sg, xbt_state_t st){
16 p = xbt_new0(s_mc_pairs_t, 1);
18 p->automaton_state = st;
27 void set_pair_visited(mc_pairs_t p){
31 int pair_reached(xbt_dynar_t p, int num_pair){
33 unsigned int cursor = 0;
34 xbt_dynar_foreach(p, cursor, n){
41 void MC_dfs_init(xbt_automaton_t a){
43 mc_pairs_t mc_initial_pair = NULL;
44 mc_state_t initial_graph_state = NULL;
45 smx_process_t process;
47 MC_wait_for_requests();
51 initial_snapshot = xbt_new0(s_mc_snapshot_t, 1);
52 MC_take_snapshot(initial_snapshot);
53 initial_graph_state = MC_state_new();
54 xbt_swag_foreach(process, simix_global->process_list){
55 if(MC_process_is_enabled(process)){
56 MC_state_interleave_process(initial_graph_state, process);
60 list_pairs_reached = xbt_dynar_new(sizeof(int), NULL);
65 //regarder dans l'automate toutes les transitions activables grâce à l'état initial du système -> donnera les états initiaux de la propriété consistants avec l'état initial du système
67 unsigned int cursor = 0;
68 xbt_state_t state = NULL;
69 unsigned int cursor2 = 0;
71 xbt_transition_t transition_succ = NULL;
72 xbt_dynar_t elses = xbt_dynar_new(sizeof(xbt_transition_t), NULL);
73 int enabled_transition = 0;
75 xbt_dynar_foreach(a->states, cursor, state){
76 if(state->type == -1){
77 xbt_dynar_foreach(state->out, cursor2, transition_succ){
79 res = MC_automaton_evaluate_label(a, transition_succ->label);
85 mc_initial_pair = new_pair(initial_snapshot, initial_graph_state, transition_succ->dst);
86 xbt_fifo_unshift(mc_snapshot_stack, mc_initial_pair);
87 set_pair_visited(mc_initial_pair);
91 enabled_transition = 1;
93 XBT_DEBUG(" ++++++++++++++++++ new initial pair +++++++++++++++++++");
98 xbt_dynar_push(elses,&transition_succ);
105 if(enabled_transition == 0){
107 xbt_dynar_foreach(elses, cursor, transition_succ){
111 mc_initial_pair = new_pair(initial_snapshot, initial_graph_state, transition_succ->dst);
112 xbt_fifo_unshift(mc_snapshot_stack, mc_initial_pair);
113 set_pair_visited(mc_initial_pair);
123 int MC_automaton_evaluate_label(xbt_automaton_t a, xbt_exp_label_t l){
127 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
128 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
129 return (left_res || right_res);
133 int left_res = MC_automaton_evaluate_label(a, l->u.or_and.left_exp);
134 int right_res = MC_automaton_evaluate_label(a, l->u.or_and.right_exp);
135 return (left_res && right_res);
139 int res = MC_automaton_evaluate_label(a, l->u.exp_not);
144 unsigned int cursor = 0;
145 xbt_propositional_symbol_t p = NULL;
146 xbt_dynar_foreach(a->propositional_symbols, cursor, p){
147 if(strcmp(p->pred, l->u.predicat) == 0){
148 int (*f)() = p->function;
162 /*void MC_dfs(xbt_automaton_t a, int search_cycle){
164 xbt_state_t current_state = (xbt_state_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(stack_automaton_dfs));
165 xbt_transition_t transition_succ = NULL;
166 xbt_state_t successor = NULL;
167 unsigned int cursor = 0;
168 xbt_dynar_t elses = xbt_dynar_new(sizeof(xbt_transition_t), NULL);
171 //printf("++ current state : %s\n", current_state->id);
173 xbt_dynar_foreach(current_state->out, cursor, transition_succ){
174 successor = transition_succ->dst;
175 res = MC_automaton_evaluate_label(a, transition_succ->label);
176 //printf("-- state : %s, transition_label : %d, res = %d\n", successor->id, transition_succ->label->type, res);
178 if(search_cycle == 1 && reached_dfs != NULL){
179 if(strcmp(reached_dfs->id, successor->id) == 0){
180 xbt_dynar_push(state_automaton_visited_dfs, &successor);
181 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
182 printf("Visited states : \n");
183 unsigned int cursor2 = 0;
184 xbt_state_t visited_state = NULL;
185 xbt_dynar_foreach(state_automaton_visited_dfs, cursor2, visited_state){
186 printf("State : %s\n", visited_state->id);
191 if(successor->visited == 0){
192 successor->visited = 1;
193 xbt_fifo_unshift(stack_automaton_dfs, successor);
194 xbt_dynar_push(state_automaton_visited_dfs, &successor);
195 MC_dfs(a, search_cycle);
196 if(search_cycle == 0 && successor->type == 1){
197 reached_dfs = successor;
203 xbt_dynar_push(elses,&transition_succ);
209 xbt_dynar_foreach(elses, cursor, transition_succ){
210 successor = transition_succ->dst;
211 if(search_cycle == 1 && reached_dfs != NULL){
212 if(strcmp(reached_dfs->id, successor->id) == 0){
213 xbt_dynar_push(state_automaton_visited_dfs, &successor);
214 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
215 printf("Visited states : \n");
216 unsigned int cursor2 = 0;
217 xbt_state_t visited_state = NULL;
218 xbt_dynar_foreach(state_automaton_visited_dfs, cursor2, visited_state){
219 printf("State : %s\n", visited_state->id);
224 if(successor->visited == 0){
225 successor->visited = 1;
226 xbt_fifo_unshift(stack_automaton_dfs, successor);
227 xbt_dynar_push(state_automaton_visited_dfs, &successor);
228 MC_dfs(a, search_cycle);
229 if(search_cycle == 0 && successor->type == 1){
230 reached_dfs = successor;
236 xbt_fifo_shift(stack_automaton_dfs);
240 void MC_dfs(xbt_automaton_t a, int search_cycle){
242 smx_process_t process = NULL;
244 mc_state_t state = NULL;
245 mc_state_t next_graph_state = NULL;
246 smx_req_t req = NULL;
249 xbt_transition_t transition_succ = NULL;
250 xbt_state_t successor = NULL;
251 unsigned int cursor = 0;
252 xbt_dynar_t elses = xbt_dynar_new(sizeof(xbt_transition_t), NULL);
254 int enabled_transition = 0;
256 mc_pairs_t next_pair = NULL;
257 mc_snapshot_t next_snapshot = NULL;
260 /* Get current state */
261 mc_pairs_t current_pair = (mc_pairs_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_snapshot_stack));
263 XBT_DEBUG("**************************************************");
264 XBT_DEBUG("State=%p, %u interleave",current_pair->graph_state,MC_state_interleave_size(current_pair->graph_state));
266 /* Update statistics */
267 mc_stats->visited_states++;
269 MC_restore_snapshot(current_pair->system_state);
272 //FIXME : vérifier condition permettant d'avoir tous les successeurs possibles dans le graph
274 while(req = MC_state_get_request(current_pair->graph_state, &value)){
276 /* Debug information */
277 if(XBT_LOG_ISENABLED(mc_dfs, xbt_log_priority_debug)){
278 req_str = MC_request_to_string(req, value);
279 XBT_DEBUG("Execute: %s", req_str);
283 MC_state_set_executed_request(current_pair->graph_state, req, value);
284 mc_stats->executed_transitions++;
286 /* Answer the request */
287 SIMIX_request_pre(req, value);
289 /* Wait for requests (schedules processes) */
290 MC_wait_for_requests();
293 /* Create the new expanded graph_state */
296 next_graph_state = MC_state_new();
298 /* Get an enabled process and insert it in the interleave set of the next graph_state */
299 xbt_swag_foreach(process, simix_global->process_list){
300 if(MC_process_is_enabled(process)){
301 MC_state_interleave_process(next_graph_state, process);
305 next_snapshot = xbt_new0(s_mc_snapshot_t, 1);
306 MC_take_snapshot(next_snapshot);
310 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
311 successor = transition_succ->dst;
312 res = MC_automaton_evaluate_label(a, transition_succ->label);
313 if(res == 1){ // enabled transition
316 next_pair = new_pair(next_snapshot, next_graph_state, successor);
318 if((search_cycle == 1) && (pair_reached(list_pairs_reached, next_pair->num) == 1)){
319 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
320 // afficher chemin menant au cycle d'acceptation
323 if(next_pair->visited == 0){ // FIXME : tester avec search_cycle ?
324 xbt_fifo_unshift(mc_snapshot_stack, next_pair);
325 set_pair_visited(next_pair);
326 MC_dfs(a, search_cycle);
327 if((search_cycle == 0) && (next_pair->automaton_state->type == 1)){
328 xbt_dynar_push(list_pairs_reached, &next_pair->num);
334 enabled_transition = 1;
337 xbt_dynar_push(elses,&transition_succ);
342 if(enabled_transition == 0){
344 xbt_dynar_foreach(elses, cursor, transition_succ){
345 successor = transition_succ->dst;
347 next_pair = new_pair(next_snapshot, next_graph_state, successor);
349 if((search_cycle == 1) && (pair_reached(list_pairs_reached, next_pair->num) == 1)){
350 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
351 // afficher chemin menant au cycle d'acceptation
354 if(next_pair->visited == 0){ // FIXME : tester avec search_cycle ?
355 xbt_fifo_unshift(mc_snapshot_stack, next_pair);
356 set_pair_visited(next_pair);
357 MC_dfs(a, search_cycle);
358 if((search_cycle == 0) && (next_pair->automaton_state->type == 1)){
359 xbt_dynar_push(list_pairs_reached, &next_pair->num);
370 xbt_fifo_shift(mc_snapshot_stack);