int get_reward_heuristic(State *S) { int i; int h=0; int th; for(i=0;i<gnum_reward_goals;i++) { if(greward_goals[i].ignore==1) continue; th=get_1P(S,&(greward_goals[i].goal_state)); #ifdef REWARD_DEBUG printf("distance from (goal %d): %d \n", greward_goals[i].reward, th); #endif /*printf("distance to %dth goal:%d",i+1,th); */ if(th==INFINITY) return INFINITY; /*not right- one of the goals is unreachable */ h+= greward_goals[i].reward*th; } return h; }
void add_to_bfs_space( State *S, int op, BfsNode *father ) { static int max_d = 0; BfsNode *tmp, *i; int h, num; /* see if state is already a part of this search space */ if ( op >= 0 ) {/* intial state has op -1 */ if ( gcmd_line.dominating && bfs_state_hashed( S, father, op ) ) { return; } } if ( gcmd_line.A && gcmd_line.debug ) { num = 0; for ( i = father; i; i = i->father ) { num++; } if ( num > max_d ) { max_d = num; printf("\ndepth: %d", num); } } h = get_1P( S, &ggoal_state, NULL, father, op ); if ( h == INFINITY ) { return; } for ( i = lbfs_space_head; i->next; i = i->next ) { if ( gcmd_line.breadth_bfs ) { if ( i->next->h > h ) break;/* stop only when next one is strictly worse */ } else { if ( i->next->h >= h ) break;/* stop already when next one is equally good */ } } tmp = new_BfsNode(); copy_source_to_dest( &(tmp->S), S ); tmp->op = op; tmp->h = h; tmp->father = father; tmp->next = i->next; tmp->prev = i; i->next = tmp; if ( tmp->next ) { tmp->next->prev = tmp; } if ( gcmd_line.dominating ) { hash_bfs_node( tmp ); } }
void analyze_local_lDG( State *s ) { static Bool fc = TRUE; static int *s_on_var; Bool nolm = FALSE; Bool max_ed_bound = FALSE; int ed_bound = -1; int responsible_var0; Bool this_var0_nolm; Bool this_var0_max_ed_bound; int this_var0_ed_bound; int var0, trans0; int new_ed_bound; int var; DTGTransition *t0; int i, j, var1, sval; DTGNode *svalnode; if ( fc ) { s_on_var = ( int * ) calloc(gnum_variables, sizeof( int )); glDG_num_successes = 0; fc = FALSE; } /* set defaults for return values */ gsuccess = FALSE; ged_bound = -1; gdead_end = FALSE; /* this whole thing gives a guarantee only if a relaxed plan * actually exists. */ if ( get_1P( s, &ggoal_state ) == INFINITY ) { gdead_end = TRUE; return; } /* just a helper to be easily able to ask what the value of var x in s is. */ for ( i = 0; i < gnum_variables; i++ ) { s_on_var[i] = -1; } for ( i = 0; i < s->num_F; i++ ) { if ( gft_conn[s->F[i]].notFD ) { continue; } if ( s_on_var[gft_conn[s->F[i]].var] != -1 ) { printf("\ns_on_var[gft_conn[s->F[i]].var] != -1??\n\n"); exit(1); } s_on_var[gft_conn[s->F[i]].var] = gft_conn[s->F[i]].val; } for ( i = 0; i < gnum_variables; i++ ) { if ( s_on_var[i] == -1 ) { /* must be OTHER */ for ( j = 0; j < gvariables[i].num_vals; j++ ) { if ( gvariables[i].vals[j] == -1 ) { break; } } if ( j < gvariables[i].num_vals ) { s_on_var[i] = j; } else { printf("\ndidn't find OTHER value for variable not set by state?\n\n"); exit(1); } } } /* $(V,A)$ contains the single leaf vertex $\var_0$, with $\var_0 * \in \vars_{\goal}$ and $\goal(\var_0) \neq s(\var_0)$; there * exists no successor $\var'$ of $\var_0$ in $\sg$ so that $\var' * \in \vars_{\goal}$ and $\goal(\var') \neq s(\var')$. */ for ( var0 = 0; var0 < gnum_variables; var0++ ) { /* $\var_0 \in \vars_{\goal}$ and $\goal(\var_0) \neq s(\var_0)$? */ if ( !gDTGs[var0].var_is_goal ) { continue; } if ( ggoal_on_var[var0] == -1 ) { printf("\nggoal_on_var[var_0] == -1??\n\n"); exit(1); } if ( ggoal_on_var[var0] == s_on_var[var0] ) { continue; } /* DISABLED! Was runtime critical in some benchmarks and, finally, * is used for NOTHING with the single exception of identifying * non-leaf goal vars for x0 in lDGs... which seems a rather useless * occupation anyhow... */ /* /\* there exists no transitive successor $\var'$ of $\var_0$ in */ /* * $\sg$ so that $\var' \in \vars_{\goal}$ and $\goal(\var') \neq */ /* * s(\var')$? */ /* *\/ */ /* for ( i = 0; i < gnum_variables; i++ ) { */ /* if ( !gSG.trans_adj_matrix[var0][i] ) { */ /* continue; */ /* } */ /* if ( !gDTGs[i].var_is_goal ) { */ /* continue; */ /* } */ /* if ( ggoal_on_var[i] == s_on_var[var1] ) { */ /* continue; */ /* } */ /* break; */ /* } */ /* if ( i < gnum_variables ) { */ /* /\* found a bad successor, cannot use this as var0 for lDG! */ /* *\/ */ /* continue; */ /* } */ /* OLD faulty version, looking only at direct successors! */ /* for ( i = 0; i < gSG.nodes[var0].num_succ; i++ ) { */ /* var1 = gSG.nodes[var0].succ[i]->end->var; */ /* if ( !gDTGs[var1].var_is_goal ) { */ /* continue; */ /* } */ /* if ( ggoal_on_var[var1] == s_on_var[var1] ) { */ /* continue; */ /* } */ /* break; */ /* } */ /* if ( i < gSG.nodes[var0].num_succ ) { */ /* /\* found a bad successor, cannot use this as var0 for lDG! */ /* *\/ */ /* continue; */ /* } */ /* use a much simpler sufficient test... * ... namely, use only x0 that are SG leafs!!!! */ if ( gSG.nodes[var0].num_succ > 0 ) { continue; } /* this is a var0 candidate. let's if all the necessary lDGs are * there and satisfy the prerequisites. */ this_var0_nolm = TRUE; this_var0_max_ed_bound = TRUE; this_var0_ed_bound = 0; /* look at all non-irrelevant transitions leaving the value of * var0 in s. */ sval = s_on_var[var0]; svalnode = &(gDTGs[var0].nodes[sval]); for ( trans0 = 0; trans0 < svalnode->num_out; trans0++ ) { t0 = svalnode->out[trans0]; if ( t0->irrelevant ) { continue; } if ( !construct_lDG( s_on_var, var0, t0 ) ) { /* got a cycle! */ this_var0_nolm = FALSE; this_var0_max_ed_bound = FALSE; break; } if ( !gcmd_line.do_recoverer_only_relevant ) { if ( !t0->self_irrelevant_side_effect_deletes && !(t0->irrelevant_side_effects && t0->recoverable_side_effect_deletes) && !t0->replacable_side_effect_deletes ) { /* t0 does not qualify */ this_var0_nolm = FALSE; this_var0_max_ed_bound = FALSE; break; } } else { if ( !t0->self_irrelevant_side_effect_deletes && !(t0->recoverer_only_relevant_side_effects && t0->recoverable_side_effect_deletes) && !t0->replacable_side_effect_deletes ) { /* t0 does not qualify */ this_var0_nolm = FALSE; this_var0_max_ed_bound = FALSE; break; } } if ( !SG_fullDTGs_INsubgraph_nonleafs_qualifies( var0, t0 ) ) { /* one of the non-leaf vars does not satisfy the prerequisites * of the theorem on each lDG */ this_var0_nolm = FALSE; this_var0_max_ed_bound = FALSE; break; } new_ed_bound = SG_fullDTGs_INsubgraph_Dcost( var0 ); if ( t0->self_irrelevant_side_effect_deletes || t0->replacable_side_effect_deletes) { new_ed_bound--; } if ( this_var0_ed_bound < new_ed_bound ) { this_var0_ed_bound = new_ed_bound; } } /* endfor trans0 over transitions out of s(var0) */ /* did the analysis of this var0 lead to success? * if yes, remember best of successes obtained. */ if ( this_var0_nolm ) { nolm = TRUE; } if ( this_var0_max_ed_bound ) { max_ed_bound = TRUE; if ( ed_bound == -1 || this_var0_ed_bound < ed_bound ) { ed_bound = this_var0_ed_bound; responsible_var0 = var0; } } } /* endfor var0 over variables */ if ( nolm ) { gsuccess = TRUE; glDG_num_successes++; } if ( max_ed_bound ) { ged_bound = ed_bound; } /* if ( !nolm ) { */ /* printf("\nunsuccessful State in lDG: "); */ /* for ( i = 0; i < gnum_variables; i++ ) { */ /* print_Variable(i); */ /* printf(": "); */ /* print_Variable_Value(i, s_on_var[i], FALSE); */ /* printf("\n "); */ /* } */ /* printf("\n... and now in FF version: "); */ /* print_state(*s); */ /* printf("\n"); */ /* printf("\n"); */ /* } */ /* if ( nolm ) { */ /* if ( !max_ed_bound ) { */ /* printf("\n!max_ed_bound??\n\n"); */ /* exit(1); */ /* } */ /* printf("\n\n========================lDG LOCAL ANALYSIS: no lm, ed bound %d.", */ /* ed_bound); */ /* printf("\n Responsible variable: "); */ /* print_Variable( responsible_var0 ); */ /* printf("\nState: "); */ /* for ( i = 0; i < gnum_variables; i++ ) { */ /* print_Variable(i); */ /* printf(": "); */ /* print_Variable_Value(i, s_on_var[i], FALSE); */ /* printf("\n "); */ /* } */ /* printf("\n"); */ /* } */ }