Esempio n. 1
0
Bool search_A_for_better_state( State S, int h, State *S_, int *h_ )

{

    int i, h__;
    State S__;

    lspace_start = 0;
    lspace_end = 0;
    lspace_size = 0;

    hash_state( S );

    for ( i = 0; i < gnum_A; i++ ) {
        result_to_dest( &S__, S, gA[i] );
        add_to_search_space( S__, gA[i], -1 );
    }

    while ( TRUE ) {
        if ( lspace_start == lspace_end ) {
            return FALSE;
        }
        h__ = expand_A_first_node( h );
        if ( LESS( h__, h ) ) {
            break;
        }
    }

    reset_hash_entrys();

    extract_plan_fragment();

    source_to_dest( S_, lsearch_space[lspace_start].S );
    *h_ = h__;

    if ( lsearch_space[lspace_start].depth > gmax_search_depth ) {
        gmax_search_depth = lsearch_space[lspace_start].depth;
    }

    if ( lspace_size > gmax_search_size ) {
        gmax_search_size = lspace_size;
    }

    return TRUE;

}
Esempio n. 2
0
Bool search_for_better_state( State *S, int h, State *S_, int *h_ )

{

  static Bool first_call = TRUE;
  static State S__;

  int i, h__, depth = 0;
  EhcNode *tmp;

  if ( first_call ) {
    make_state( &S__, gnum_ft_conn );
    first_call = FALSE;
  }

  /* don't hash states, but search nodes.
   * this way, don't need to keep states twice in memory
   */
  tmp = new_EhcNode();
  copy_source_to_dest( &(tmp->S), S);
  hash_ehc_node( tmp );

  lehc_current_end = lehc_space_head->next;
  for ( i = 0; i < gnum_H; i++ ) {
      /* see result-to-dest params explanation at fn header
       */
    if ( !result_to_dest( &S__, tmp, NULL, gH[i] ) ) continue;
    add_to_ehc_space( &S__, gH[i], tmp );
  }
  lehc_current_start = lehc_space_head->next;

  while ( TRUE ) {  
    if ( lehc_current_start == lehc_current_end ) {
      reset_ehc_hash_entrys();
      free( tmp );
      return FALSE;
    }
    if ( lehc_current_start->depth > depth ) {
      depth = lehc_current_start->depth;
      if ( depth > gmax_search_depth ) {
	gmax_search_depth = depth;
      }
      printf("[%d]", depth);
      fflush( stdout );
      /* HACK: if this is going to more than 15, then most likely this is just a stupid
       * effect of helpful actions pruning, and we won't get anywhere anyway.
       */
      if ( depth > 15 ) {
	reset_ehc_hash_entrys();
	free( tmp );
	return FALSE; 
      }     
    }
    h__ = expand_first_node( h );
    if ( LESS( h__, h ) ) {
      break;
    }
  }

  reset_ehc_hash_entrys();
  free( tmp );

  extract_plan_fragment( S );

  source_to_dest( S_, &(lehc_current_start->S) );
  *h_ = h__;

  return TRUE;

}
Esempio n. 3
0
/*************************************************
 * FUNCTIONS FOR BREADTH FIRST SEARCH IN H SPACE *
 *************************************************/
Bool search_for_better_state_for_multiple_purpose ( State *S, int h, State *S_, int *h_ ) {
    
	static Bool first_call_for_multiple_purpose = TRUE;
	static State S__;
    
	int i, h__, depth = 0, g;
	EhcNode *tmp;
    
	if ( first_call_for_multiple_purpose ) {
		make_state( &S__, gnum_ft_conn );
		S__.max_F = gnum_ft_conn;
		first_call_for_multiple_purpose = FALSE;
	}
    
	/* don't hash states, but search nodes.
     * this way, don't need to keep states twice in memory */
	tmp = new_EhcNode();
	copy_source_to_dest( &(tmp->S), S);
	hash_ehc_node( tmp );
    
	lehc_current_end = lehc_space_head->next;
	
	for ( i = 0; i < gnum_H; i++ ) {
		int k;
		Bool found = FALSE;
		for(k = 0; k < gnum_IV; k++){
			if(same_state(&gInvActs[k].state, 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__, S, gH[i] );
		add_to_ehc_space( &S__, gH[i], NULL, g );
	}
    
	for ( i = 0; i < gnum_H; i++ ) {
		int k;
		Bool found = FALSE;
		for(k = 0; k < gnum_IV; k++){
			if(same_state(&gInvActs[k].state, S) && gH[i] == gInvActs[k].act){
				found = TRUE;
				break;
			}
		}
		if(found) continue;
        
		if(!is_D_action(gop_conn[gH[i]].action->name)) continue;
		
        /* D_cation, not in the gH */
		g = result_to_dest( &S__, S, gH[i] );
		add_to_ehc_space( &S__, gH[i], NULL, g );
	}
    
	lehc_current_start = lehc_space_head->next;
    
	while ( TRUE ) {
		if ( lehc_current_start == lehc_current_end ) {
			reset_ehc_hash_entrys();
			free( tmp );
			return FALSE;
		}
		
		if ( lehc_current_start->depth > depth ) {
			depth = lehc_current_start->depth;
			if ( depth > gmax_search_depth ) {
				gmax_search_depth = depth;
			}
			printf("[%d]", depth);
			fflush( stdout );
		}
        
		h__ = expand_first_node( h );
		if ( LESS( h__, h ) ) {
			break;
		}
	}
    
	reset_ehc_hash_entrys();
	free( tmp );
    
	extract_plan_fragment( S );
    
	source_to_dest( S_, &(lehc_current_start->S) );
	*h_ = h__;
    
	return TRUE;
}
Esempio n. 4
0
Bool search_for_better_state( State *S, int h, State *S_, int *h_ )

{

  static Bool first_call = TRUE;
  static State S__;

  int i, h__, depth = 0, g;
  EhcNode *tmp;

  if ( first_call ) {
    make_state( &S__, gnum_ft_conn );
    S__.max_F = gnum_ft_conn;
    first_call = FALSE;
  }

  /* don't hash states, but search nodes.
   * this way, don't need to keep states twice in memory
   */
  tmp = new_EhcNode();
  copy_source_to_dest( &(tmp->S), S);
  hash_ehc_node( tmp );

  lehc_current_end = lehc_space_head->next;
  for ( i = 0; i < gnum_H; i++ ) {
    g = result_to_dest( &S__, S, gH[i] );
    add_to_ehc_space( &S__, gH[i], NULL, g );
  }
  lehc_current_start = lehc_space_head->next;

  while ( TRUE ) {  
    if ( lehc_current_start == lehc_current_end ) {
      reset_ehc_hash_entrys();
      free( tmp );
      return FALSE;
    }
    if ( lehc_current_start->depth > depth ) {
      depth = lehc_current_start->depth;
      if ( depth > gmax_search_depth ) {
	gmax_search_depth = depth;
      }
      printf("[%d]", depth);
      fflush( stdout );
    }
    h__ = expand_first_node( h );
    if ( LESS( h__, h ) ) {
      break;
    }
  }

  reset_ehc_hash_entrys();
  free( tmp );

  extract_plan_fragment( S );

  source_to_dest( S_, &(lehc_current_start->S) );
  *h_ = h__;

  return TRUE;

}