state_t *explstate(state *init, rels *rls, state *g){
LACE_ME;
- lurd_t *lrd = NULL;
deque *state_queue = create();
trans_t *t = NULL;
- state_t *tmp_state = NULL;
+ state_t *tmp_state = (state_t *)malloc(sizeof(state_t));
BDD visited = init->bdd;
BDD new;
tmp_state->bdd = init->bdd;
tmp_state->vars = init->vars;
- tmp_state->lrd = lrd;
+ tmp_state->lrd = NULL;
state_queue = enq(tmp_state, state_queue);
- while (isEmpty(state_queue) == 1){
+ while (isEmpty(state_queue) == 0){
tmp_state = get_front(state_queue);
state_queue = deq(state_queue);
+ new = tmp_state->bdd;
t = rls->rell;
- new = sylvan_false;
while (t != NULL){
- new = sylvan_or(new, sylvan_relnext(new, t->bdd, t->varset.varset));
+ new = sylvan_relnext(tmp_state->bdd, t->bdd, t->varset.varset);
+ if (new != sylvan_false && new != tmp_state->bdd) break;
t = t->next_rel;
}
- if (check_visited(new, visited, init->vars.varset) == 0){
- if (check_goal(new, g->bdd, init->vars.varset) == 0){
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'l');
- new_state->lrd = lrd;
- state_queue = enq(new_state, state_queue);
- visited = sylvan_or(new, visited);
- }
- else {
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'l');
- new_state->lrd = lrd;
- return new_state;
+ if (new != sylvan_false && new != tmp_state->bdd){
+ if (check_visited(new, visited, init->vars.varset) == 0){
+ if (check_goal(new, g->bdd, init->vars.varset) == 0){
+ lurd_t *lrd = (lurd_t *)malloc(sizeof(lurd_t));
+ lrd = tmp_state->lrd;
+ state_t *new_state = (state_t *)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'l');
+ new_state->lrd = lrd;
+ state_queue = enq(new_state, state_queue);
+ visited = sylvan_or(new, visited);
+ }
+ else {
+ printf("GOAL\n");
+ lurd_t *lrd = tmp_state->lrd;
+ state_t *new_state = NULL;
+ new_state = (state_t*)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'l');
+ new_state->lrd = lrd;
+ return new_state;
+ }
}
}
t = rls->relu;
- new = sylvan_false;
while (t != NULL){
- new = sylvan_or(new, sylvan_relnext(new, t->bdd, t->varset.varset));
+ new = sylvan_relnext(tmp_state->bdd, t->bdd, t->varset.varset);
+ if (new != sylvan_false && new != tmp_state->bdd) break;
t = t->next_rel;
}
- if (check_visited(new, visited, init->vars.varset) == 0){
- if (check_goal(new, g->bdd, init->vars.varset) == 0){
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'u');
- new_state->lrd = lrd;
- state_queue = enq(new_state, state_queue);
- visited = sylvan_or(new, visited);
- }
- else {
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'u');
- new_state->lrd = lrd;
- return new_state;
+ if (new != sylvan_false && new != tmp_state->bdd){
+ if (check_visited(new, visited, init->vars.varset) == 0){
+ if (check_goal(new, g->bdd, init->vars.varset) == 0){
+ lurd_t *lrd = (lurd_t *)malloc(sizeof(lurd_t));
+ lrd = tmp_state->lrd;
+ state_t *new_state = (state_t *)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'u');
+ new_state->lrd = lrd;
+ state_queue = enq(new_state, state_queue);
+ visited = sylvan_or(new, visited);
+ }
+ else {
+ printf("GOAL\n");
+ lurd_t *lrd = tmp_state->lrd;
+ state_t *new_state = NULL;
+ new_state = (state_t*)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'u');
+ new_state->lrd = lrd;
+ return new_state;
+ }
}
}
t = rls->relr;
- new = sylvan_false;
while (t != NULL){
- new = sylvan_or(new, sylvan_relnext(new, t->bdd, t->varset.varset));
+ new = sylvan_relnext(tmp_state->bdd, t->bdd, t->varset.varset);
+ if (new != sylvan_false && new != tmp_state->bdd) break;
t = t->next_rel;
}
- if (check_visited(new, visited, init->vars.varset) == 0){
- if (check_goal(new, g->bdd, init->vars.varset) == 0){
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'r');
- new_state->lrd = lrd;
- state_queue = enq(new_state, state_queue);
- visited = sylvan_or(new, visited);
- }
- else {
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'r');
- new_state->lrd = lrd;
- return new_state;
+ if (new != sylvan_false && new != tmp_state->bdd){
+ if (check_visited(new, visited, init->vars.varset) == 0){
+ if (check_goal(new, g->bdd, init->vars.varset) == 0){
+ lurd_t *lrd = (lurd_t *)malloc(sizeof(lurd_t));
+ lrd = tmp_state->lrd;
+ state_t *new_state = (state_t *)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'r');
+ new_state->lrd = lrd;
+ state_queue = enq(new_state, state_queue);
+ visited = sylvan_or(new, visited);
+ }
+ else {
+ printf("GOAL\n");
+ lurd_t *lrd = tmp_state->lrd;
+ state_t *new_state = NULL;
+ new_state = (state_t*)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'r');
+ new_state->lrd = lrd;
+ return new_state;
+ }
}
}
+
t = rls->reld;
- new = sylvan_false;
while (t != NULL){
- new = sylvan_or(new, sylvan_relnext(new, t->bdd, t->varset.varset));
+ new = sylvan_relnext(tmp_state->bdd, t->bdd, t->varset.varset);
+ if (new != sylvan_false && new != tmp_state->bdd) break;
t = t->next_rel;
}
- if (check_visited(new, visited, init->vars.varset) == 0){
- if (check_goal(new, g->bdd, init->vars.varset) == 0){
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'd');
- new_state->lrd = lrd;
- state_queue = enq(new_state, state_queue);
- visited = sylvan_or(new, visited);
- }
- else {
- lurd_t *lrd = tmp_state->lrd;
- state_t *new_state = NULL;
- new_state = (state_t*)malloc(sizeof(state_t));
- new_state->bdd = new;
- new_state->vars = init->vars;
- lrd = lappend(lrd, 'd');
- new_state->lrd = lrd;
- return new_state;
+ if (new != sylvan_false && new != tmp_state->bdd){
+ if (check_visited(new, visited, init->vars.varset) == 0){
+ if (check_goal(new, g->bdd, init->vars.varset) == 0){
+ lurd_t *lrd = (lurd_t *)malloc(sizeof(lurd_t));
+ lrd = tmp_state->lrd;
+ state_t *new_state = (state_t *)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'd');
+ new_state->lrd = lrd;
+ state_queue = enq(new_state, state_queue);
+ visited = sylvan_or(new, visited);
+ }
+ else {
+ printf("GOAL\n");
+ lurd_t *lrd = tmp_state->lrd;
+ state_t *new_state = NULL;
+ new_state = (state_t*)malloc(sizeof(state_t));
+ new_state->bdd = new;
+ new_state->vars = init->vars;
+ lrd = lappend(lrd, 'd');
+ new_state->lrd = lrd;
+ return new_state;
+ }
}
}
+
}
return NULL;