Beispiel #1
0
void extract_plan_fragment( State *S )

{

  EhcNode *i;
  int ops[MAX_PLAN_LENGTH], num_ops;
  State_pointer states[MAX_PLAN_LENGTH];
  int j;
  PlanHashEntry *start = NULL, *i_ph;

  num_ops = 0;
  for ( i = lehc_current_start; i; i = i->father ) {
    if ( (start = plan_state_hashed( &(i->S) )) != NULL ) {
      for ( i_ph = start->next_step; i_ph; i_ph = i_ph->next_step ) {
	i_ph->step = -1;
      }
      gnum_plan_ops = start->step;
      break;
    }
    if ( num_ops == MAX_PLAN_LENGTH ) {
      printf("\nincrease MAX_PLAN_LENGTH! currently %d\n\n",
	     MAX_PLAN_LENGTH);
      exit( 1 );
    }
    states[num_ops] = &(i->S);
    ops[num_ops++] = i->op;
  }
  if ( !start ) {
    start = plan_state_hashed( S );
    if ( !start ) {
      printf("\n\ncurrent start state not hashed! debug me!\n\n");
      exit( 1 );
    }
    if ( start->step == -1 ) {
      printf("\n\ncurrent start state marked removed from plan! debug me!\n\n");
      exit( 1 );
    }
  }

  for ( j = num_ops - 1; j > -1; j-- ) {
    if ( gnum_plan_ops == MAX_PLAN_LENGTH ) {
      printf("\nincrease MAX_PLAN_LENGTH! currently %d\n\n",
	     MAX_PLAN_LENGTH);
      exit( 1 );
    }
    start->next_step = hash_plan_state( states[j], gnum_plan_ops + 1 );
    start = start->next_step;
    source_to_dest( &(gplan_states[gnum_plan_ops+1]), states[j] );
    gplan_ops[gnum_plan_ops++] = ops[j];
  }

}
Beispiel #2
0
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;
}