Example #1
0
Bool state_hashed( State S )

{

    int i, sum, index;
    StateHashEntry *h;

    sum = state_sum( S );
    index = sum & STATE_HASH_BITS;

    h = lstate_hash_entry[index];
    for ( i = 0; i < lnum_state_hash_entry[index]; i++ ) {
        if ( h->sum != sum ) {
            h = h->next;
            continue;
        }
        if ( same_state( &(h->S), &S ) ) {
            return TRUE;
        }
        h = h->next;
    }

    return FALSE;

}
Example #2
0
Bool ehc_state_hashed( State *S )

{

  int i, sum, index;
  EhcHashEntry *h;

  sum = state_sum( S );
  index = sum & EHC_HASH_BITS;

  h = lehc_hash_entry[index];
  for ( i = 0; i < lnum_ehc_hash_entry[index]; i++ ) {
    if ( h->sum != sum ) {
      h = h->next;
      continue;
    }
    if ( same_state( &(h->ehc_node->S), S ) ) {
      return TRUE;
    }
    h = h->next;
  }

  return FALSE;

}
Example #3
0
int state_seen( int num )

{

    int i;

    for ( i = 0; i <= gnum_plan_ops; i++ ) {
        if ( gplan_states_sum[i] != gplan_states_sum[num] ) {
            continue;
        }
        if ( same_state( &gplan_states[i], &gplan_states[num] ) ) {
            return i;
        }
    }

    return -1;

}
Example #4
0
/*add the state S into hash table*/
PlanHashEntry *hash_plan_state( State *S, int step ) {

	int sum, index;
	PlanHashEntry *h, *tmp;

	sum = state_sum( S );
	index = sum & PLAN_HASH_BITS;

	for ( h = lplan_hash_entry[index]; h; h = h->next ) {
		if ( h->sum != sum ) continue;
		if ( same_state( S, &(h->S) ) ) break;
	}

	/*found the same state in the hash table*/
	if ( h ) {
		if ( h->step != -1 ) {
			printf("\n\n[error]:reencountering a state that is already in plan! debug me\n\n");
			exit( 1 );
		}
		h->step = step;
		return h;
	}

	/* not found the same state in hash table*/
	/* h points to the last one*/
	/* jovi: comments by jovi, seems it is not necessary
	 * This is for addding a nes state 
	*/
	for ( h = lplan_hash_entry[index]; h && h->next; h = h->next ) ;
	 	

	tmp = new_PlanHashEntry();
	tmp->sum = sum;
	copy_source_to_dest( &(tmp->S), S );
	tmp->step = step;

	if ( h ) {
		h->next = tmp;
	} else {
		lplan_hash_entry[index] = tmp;
	}
	return tmp;
}
Example #5
0
PlanHashEntry *plan_state_hashed(State *S) {

	int sum, index;
	PlanHashEntry *h;

	sum = state_sum(S);
	index = sum & PLAN_HASH_BITS;

	for (h = lplan_hash_entry[index]; h; h = h->next) {
		if (h->sum != sum)
			continue;
		if (same_state(S, &(h->S)))
			break;
	}

	if (h && h->step != -1) {
		return h;
	}
	return NULL;
}
Example #6
0
PlanHashEntry *hash_plan_state( State *S, int step )

{

  int sum, index;
  PlanHashEntry *h, *tmp;

  sum = state_sum( S );
  index = sum & PLAN_HASH_BITS;

  for ( h = lplan_hash_entry[index]; h; h = h->next ) {
    if ( h->sum != sum ) continue;
    if ( same_state( S, &(h->S) ) ) break;
  }

  if ( h ) {
    if ( h->step != -1 ) {
      printf("\n\nreencountering a state that is already in plan! debug me\n\n");
      exit( 1 );
    }
    h->step = step;
    return h;
  }

  for ( h = lplan_hash_entry[index]; h && h->next; h = h->next );

  tmp = new_PlanHashEntry();
  tmp->sum = sum;
  copy_source_to_dest( &(tmp->S), S );
  tmp->step = step;

  if ( h ) {
    h->next = tmp;
  } else {
    lplan_hash_entry[index] = tmp;
  }

  return tmp;

}
Example #7
0
/* 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_;
}
Example #8
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;
}