コード例 #1
0
ファイル: search.c プロジェクト: jovizhu/multiFIP-Xcode
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;
}
コード例 #2
0
ファイル: search.c プロジェクト: dtolpin/probabilistic-ff
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;

}