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;
164 /*void MC_dfs(xbt_automaton_t a, int search_cycle){
166 xbt_state_t current_state = (xbt_state_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(stack_automaton_dfs));
167 xbt_transition_t transition_succ = NULL;
168 xbt_state_t successor = NULL;
169 unsigned int cursor = 0;
170 xbt_dynar_t elses = xbt_dynar_new(sizeof(xbt_transition_t), NULL);
173 //printf("++ current state : %s\n", current_state->id);
175 xbt_dynar_foreach(current_state->out, cursor, transition_succ){
176 successor = transition_succ->dst;
177 res = MC_automaton_evaluate_label(a, transition_succ->label);
178 //printf("-- state : %s, transition_label : %d, res = %d\n", successor->id, transition_succ->label->type, res);
180 if(search_cycle == 1 && reached_dfs != NULL){
181 if(strcmp(reached_dfs->id, successor->id) == 0){
182 xbt_dynar_push(state_automaton_visited_dfs, &successor);
183 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
184 printf("Visited states : \n");
185 unsigned int cursor2 = 0;
186 xbt_state_t visited_state = NULL;
187 xbt_dynar_foreach(state_automaton_visited_dfs, cursor2, visited_state){
188 printf("State : %s\n", visited_state->id);
193 if(successor->visited == 0){
194 successor->visited = 1;
195 xbt_fifo_unshift(stack_automaton_dfs, successor);
196 xbt_dynar_push(state_automaton_visited_dfs, &successor);
197 MC_dfs(a, search_cycle);
198 if(search_cycle == 0 && successor->type == 1){
199 reached_dfs = successor;
205 xbt_dynar_push(elses,&transition_succ);
211 xbt_dynar_foreach(elses, cursor, transition_succ){
212 successor = transition_succ->dst;
213 if(search_cycle == 1 && reached_dfs != NULL){
214 if(strcmp(reached_dfs->id, successor->id) == 0){
215 xbt_dynar_push(state_automaton_visited_dfs, &successor);
216 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
217 printf("Visited states : \n");
218 unsigned int cursor2 = 0;
219 xbt_state_t visited_state = NULL;
220 xbt_dynar_foreach(state_automaton_visited_dfs, cursor2, visited_state){
221 printf("State : %s\n", visited_state->id);
226 if(successor->visited == 0){
227 successor->visited = 1;
228 xbt_fifo_unshift(stack_automaton_dfs, successor);
229 xbt_dynar_push(state_automaton_visited_dfs, &successor);
230 MC_dfs(a, search_cycle);
231 if(search_cycle == 0 && successor->type == 1){
232 reached_dfs = successor;
238 xbt_fifo_shift(stack_automaton_dfs);
242 void MC_dfs(xbt_automaton_t a, int search_cycle){
244 smx_process_t process = NULL;
246 mc_state_t next_graph_state = NULL;
247 smx_req_t req = NULL;
250 xbt_transition_t transition_succ = NULL;
251 xbt_state_t successor = NULL;
252 unsigned int cursor = 0;
253 xbt_dynar_t elses = xbt_dynar_new(sizeof(xbt_transition_t), NULL);
255 int enabled_transition = 0;
257 mc_pairs_t next_pair = NULL;
258 mc_snapshot_t next_snapshot = NULL;
261 /* Get current state */
262 mc_pairs_t current_pair = (mc_pairs_t)xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_snapshot_stack));
264 XBT_DEBUG("**************************************************");
265 XBT_DEBUG("State=%p, %u interleave",current_pair->graph_state,MC_state_interleave_size(current_pair->graph_state));
267 /* Update statistics */
268 mc_stats->visited_states++;
270 MC_restore_snapshot(current_pair->system_state);
273 //FIXME : vérifier condition permettant d'avoir tous les successeurs possibles dans le graph
275 while((req = MC_state_get_request(current_pair->graph_state, &value)) != NULL){
277 /* Debug information */
278 if(XBT_LOG_ISENABLED(mc_dfs, xbt_log_priority_debug)){
279 req_str = MC_request_to_string(req, value);
280 XBT_DEBUG("Execute: %s", req_str);
284 MC_state_set_executed_request(current_pair->graph_state, req, value);
285 mc_stats->executed_transitions++;
287 /* Answer the request */
288 SIMIX_request_pre(req, value);
290 /* Wait for requests (schedules processes) */
291 MC_wait_for_requests();
294 /* Create the new expanded graph_state */
297 next_graph_state = MC_state_new();
299 /* Get an enabled process and insert it in the interleave set of the next graph_state */
300 xbt_swag_foreach(process, simix_global->process_list){
301 if(MC_process_is_enabled(process)){
302 MC_state_interleave_process(next_graph_state, process);
306 next_snapshot = xbt_new0(s_mc_snapshot_t, 1);
307 MC_take_snapshot(next_snapshot);
311 xbt_dynar_foreach(current_pair->automaton_state->out, cursor, transition_succ){
312 successor = transition_succ->dst;
313 res = MC_automaton_evaluate_label(a, transition_succ->label);
314 if(res == 1){ // enabled transition
317 next_pair = new_pair(next_snapshot, next_graph_state, successor);
319 if((search_cycle == 1) && (pair_reached(list_pairs_reached, next_pair->num) == 1)){
320 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
321 // afficher chemin menant au cycle d'acceptation
324 if(next_pair->visited == 0){ // FIXME : tester avec search_cycle ?
325 xbt_fifo_unshift(mc_snapshot_stack, next_pair);
326 set_pair_visited(next_pair);
327 MC_dfs(a, search_cycle);
328 if((search_cycle == 0) && (next_pair->automaton_state->type == 1)){
329 xbt_dynar_push(list_pairs_reached, &next_pair->num);
335 enabled_transition = 1;
338 xbt_dynar_push(elses,&transition_succ);
343 if(enabled_transition == 0){
345 xbt_dynar_foreach(elses, cursor, transition_succ){
346 successor = transition_succ->dst;
348 next_pair = new_pair(next_snapshot, next_graph_state, successor);
350 if((search_cycle == 1) && (pair_reached(list_pairs_reached, next_pair->num) == 1)){
351 printf("\n-*-*-*-*-*-*- ACCEPTANCE CYCLE -*-*-*-*-*-*-\n");
352 // afficher chemin menant au cycle d'acceptation
355 if(next_pair->visited == 0){ // FIXME : tester avec search_cycle ?
356 xbt_fifo_unshift(mc_snapshot_stack, next_pair);
357 set_pair_visited(next_pair);
358 MC_dfs(a, search_cycle);
359 if((search_cycle == 0) && (next_pair->automaton_state->type == 1)){
360 xbt_dynar_push(list_pairs_reached, &next_pair->num);
371 xbt_fifo_shift(mc_snapshot_stack);