int expand_first_node( int h ) { static Bool fc = TRUE; static State S_; int h_, i, g; if ( fc ) { make_state( &S_, gnum_ft_conn ); S_.max_F = gnum_ft_conn; fc = FALSE; } h_ = get_1P_and_H( &(lehc_current_start->S), &lcurrent_goals ); if ( h_ == INFINITY ) { lehc_current_start = lehc_current_start->next; return h_; } if ( lehc_current_start->new_goal != -1 && new_goal_gets_deleted( lehc_current_start ) ) { lehc_current_start = lehc_current_start->next; return INFINITY; } if ( h_ < h ) { return h_; } for ( i = 0; i < gnum_H; i++ ) { g = result_to_dest( &S_, &(lehc_current_start->S), gH[i] ); add_to_ehc_space( &S_, gH[i], lehc_current_start, g ); } lehc_current_start = lehc_current_start->next; return h_; }
int expand_first_node( int h ) { static Bool fc = TRUE; static State S_; int h_, i; if ( fc ) { make_state( &S_, gnum_ft_conn ); fc = FALSE; } h_ = get_1P_and_H( &(lehc_current_start->S), &lscurrent_goals, lehc_current_start->father, NULL, lehc_current_start->op ); if ( h_ == INFINITY ) { lehc_current_start = lehc_current_start->next; return h_; } if ( h_ < h ) { return h_; } for ( i = 0; i < gnum_H; i++ ) { if ( !result_to_dest( &S_, lehc_current_start, NULL, gH[i] ) ) continue; add_to_ehc_space( &S_, gH[i], lehc_current_start ); } lehc_current_start = lehc_current_start->next; return h_; }
/* breath first search */ int expand_first_node( int h ) { static Bool fc = TRUE; static State S_; int h_, i, g; if ( fc ) { make_state( &S_, gnum_ft_conn ); S_.max_F = gnum_ft_conn; fc = FALSE; } h_ = get_1P_and_H( &(lehc_current_start->S), &lcurrent_goals ); if ( h_ == INFINITY ) { lehc_current_start = lehc_current_start->next; return h_; } if ( lehc_current_start->new_goal != -1 && new_goal_gets_deleted( lehc_current_start ) ) { lehc_current_start = lehc_current_start->next; return INFINITY; } if ( h_ < h ) { return h_; } for ( i = 0; i < gnum_H; i++ ) { /*JC: dismiss invalid actions*/ int k; Bool found = FALSE; for(k = 0; k < gnum_IV; k++){ if(same_state(&gInvActs[k].state, &(lehc_current_start->S)) && gH[i] == gInvActs[k].act){ found = TRUE; break; } } if(found) continue; if(is_D_action(gop_conn[gH[i]].action->name)) continue; g = result_to_dest( &S_, &(lehc_current_start->S), gH[i] ); add_to_ehc_space( &S_, gH[i], lehc_current_start, g ); } for ( i = 0; i < gnum_H; i++ ) { /*JC: dismiss invalid actions*/ int k; Bool found = FALSE; for(k = 0; k < gnum_IV; k++){ if(same_state(&gInvActs[k].state, &(lehc_current_start->S)) && gH[i] == gInvActs[k].act){ found = TRUE; break; } } if(found) continue; if(!is_D_action(gop_conn[gH[i]].action->name)) continue; g = result_to_dest( &S_, &(lehc_current_start->S), gH[i] ); add_to_ehc_space( &S_, gH[i], lehc_current_start, g ); } lehc_current_start = lehc_current_start->next; return h_; }
Bool do_enforced_hill_climbing( State *start, State *end ) { static Bool first_call = TRUE; static State S, S_; int i, h, h_; if ( first_call ) { /* on first call, initialize plan hash table, search space, search hash table */ for ( i = 0; i < PLAN_HASH_SIZE; i++ ) { lplan_hash_entry[i] = NULL; } /* on subsequent calls, the start is already hashed, as it's the end of the previous calls */ hash_plan_state( start, 0 ); lehc_space_head = new_EhcNode(); lehc_space_end = lehc_space_head; for ( i = 0; i < EHC_HASH_SIZE; i++ ) { lehc_hash_entry[i] = NULL; lnum_ehc_hash_entry[i] = 0; lchanged_ehc_entry[i] = FALSE; } lnum_changed_ehc_entrys = 0; make_state( &S, gnum_ft_conn ); S.max_F = gnum_ft_conn; make_state( &S_, gnum_ft_conn ); S_.max_F = gnum_ft_conn; make_state( &lcurrent_goals, gnum_ft_conn ); lcurrent_goals.max_F = gnum_ft_conn; first_call = FALSE; } /* start enforced Hill-climbing */ source_to_dest( &lcurrent_goals, end ); source_to_dest( &S, start ); /*seems get a heuristic*/ h = get_1P_and_H( &S, &lcurrent_goals ); if ( h == INFINITY ) { return FALSE; } if ( h == 0 ) { return TRUE; } printf("\n\nCueing down from goal distance: %4d into depth", h); while ( h != 0 ) { if ( !search_for_better_state( &S, h, &S_, &h_ ) ) { return FALSE; } /* * modified by Jason Huang: return ealier */ if(is_solved_state( &S_ )) { printf("\nstate have seen. h = %d. return\n", h); return TRUE; } source_to_dest( &S, &S_ ); h = h_; printf("\n %4d ", h); } return TRUE; }
void manual_control( void ) { static Bool fc = TRUE; static State S; int i, j, h, choice; BfsNode *tmp, *curr; if ( fc ) { make_state( &S, gnum_ft_conn ); fc = FALSE; } tmp = new_BfsNode(); copy_source_to_dest( &(tmp->S), &ginitial_state ); tmp->op = -1; curr = tmp; if ( gcmd_line.dominating ) { hash_bfs_node( curr ); } while ( TRUE ) { if ( !curr ) break; h = get_1P_and_H( &(curr->S), &ggoal_state, NULL, curr->father, curr->op ); get_A( &(curr->S) ); while ( TRUE ) { printf("\n\n\n-------------state h = %d", h); if ( h > 0 ) printf(" (resp. %d actions)", h - 1); printf(", info level %d, %d applicable actions", gcmd_line.debug, gnum_A); if ( gcmd_line.debug >= 1 ) { print_state( curr->S ); } if ( 0 ) { printf("\nH:"); for ( i = 0; i < gnum_H; i++ ) { printf(" "); print_op_name( gH[i] ); } } printf("\n"); for ( i = 0; i < gnum_A; i++ ) { printf("\n%3d ", i); for ( j = 0; j < gnum_H; j++ ) { if ( gA[i] == gH[j] ) break; } if ( j < gnum_H ) { printf("H: "); } else { printf(" : "); } print_op_name( gA[i] ); } printf("\n\n -1: retract last choice"); printf("\n -2: set info level"); printf("\n\nchoice: "); scanf("%d", &choice); if ( choice >= -2 && choice < gnum_A ) break; } if ( choice >= 0 ) { if ( !result_to_dest( &S, NULL, curr, gA[choice] ) ) { printf("\naction not applicable!"); continue; } if ( gcmd_line.dominating && bfs_state_hashed( &S, curr, gA[choice] ) ) { printf("\nthis state is dominated!\n\n"); } tmp = new_BfsNode(); copy_source_to_dest( &(tmp->S), &S ); tmp->father = curr; tmp->op = gA[choice]; curr = tmp; if ( gcmd_line.dominating ) { hash_bfs_node( curr ); } continue; } if ( choice == -1 ) { curr = curr->father; continue; } printf("\nlevel : "); scanf("%d", &gcmd_line.debug); } }
Bool do_enforced_hill_climbing( State *start, State *end ) { static Bool first_call = TRUE; static State S, S_; int i, h, h_; if ( first_call ) { /* on first call, initialize plan hash table, search space, search hash table */ for ( i = 0; i < PLAN_HASH_SIZE; i++ ) { lplan_hash_entry[i] = NULL; } lehc_space_head = new_EhcNode(); lehc_space_end = lehc_space_head; make_state( &S, gnum_ft_conn ); make_state( &S_, gnum_ft_conn ); make_state( &lscurrent_goals, gnum_ft_conn ); first_call = FALSE; } /* start enforced Hill-climbing */ source_to_dest( &lscurrent_goals, end ); source_to_dest( &S, start ); h = get_1P_and_H( &S, &lscurrent_goals, NULL, NULL, -1 ); if ( h == INFINITY ) { return FALSE; } if ( h == 0 ) { return TRUE; } printf("\n\nCueing down from goal distance: %4d into depth ", h); fflush(stdout); while ( h != 0 ) { if ( !search_for_better_state( &S, h, &S_, &h_ ) ) { /* printf("\nswitch to no H %4d ", h); */ /* get_A(&S); */ /* for ( i = 0; i < gnum_H; i++ ) { */ /* gop_conn[gH[i]].is_in_H = FALSE; */ /* } */ /* for ( i = 0; i < gnum_A; i++ ) { */ /* gH[i] = gA[i]; */ /* gop_conn[gH[i]].is_in_H = TRUE; */ /* } */ /* gnum_H = gnum_A; */ /* gcmd_line.help = FALSE; */ /* if ( !search_for_better_state( &S, h, &S_, &h_ ) ) { */ for ( i = 0; i < gnum_clauses; i++ ) { gclause_length[i] = 0; } gnum_fixed_clauses = 0; gnum_clauses = 0; for ( i = 1; i <= gnum_fixed_c; i++ ) { gcodes[gct[i]][gcf[i]] = -1; } gnum_fixed_c = 0; extend_fixed_clauses_base( 0, 0 ); extend_fixed_clauses_base_encoding( 0 ); return FALSE; /* } else { */ /* gcmd_line.help = TRUE; */ /* } */ } source_to_dest( &S, &S_ ); h = h_; printf("\n %4d ", h); fflush(stdout); } return TRUE; }