Exemple #1
0
Bool do_greedy_heuristic_improvement( void )

{

    State S, S_;
    int h, h_;

    source_to_dest( &S, ginitial_state );

    h = get_1P_and_AH( S );

    if ( h == INFINITY ) {
        printf("\n\nGoals can't be reached -- problem proved unsolvable!\n\n");
        exit( 1 );
    }

    source_to_dest( &(gplan_states[0]), ginitial_state );
    gplan_states_sum[0] = state_sum( ginitial_state );

    printf("\n\nCueing down from goal distance: %4d", h);

    while ( h != 0 ) {
        if ( !search_H_for_better_state( S, h, &S_, &h_ ) ) {
            /* H space got empty, switch to complete space
             */
            if ( gcmd_line.display_info ) {
                printf("\n\nH search space got empty !");
                printf("\nswitching to complete search space now.\n");
                fflush( stdout );
            }
            get_1P_and_AH( S );
            reset_hash_entrys();
            if ( !search_A_for_better_state( S, h, &S_, &h_ ) ) {
                if ( gcmd_line.display_info ) {
                    printf("\n\nsearch space got empty !");
                    printf("\neither - problem is not invertible or");
                    printf("\n       - problem is unsolvable\n\n");
                }
                return FALSE;
            }
        }
        source_to_dest( &S, S_ );
        h = h_;
        printf("\n                                %4d", h);
    }

    return TRUE;

}
Exemple #2
0
void add_to_search_space( State S, int op, int father )

{

    /* see if state is already a part of this search space
     */
    if ( state_hashed( S ) ) {
        return;
    }

    source_to_dest( &(lsearch_space[lspace_end].S), S );
    lsearch_space[lspace_end].op = op;
    lsearch_space[lspace_end].father = father;
    if ( father == -1 ) {
        lsearch_space[lspace_end].depth = 1;
    } else {
        lsearch_space[lspace_end].depth = lsearch_space[father].depth + 1;
    }

    lspace_end++;
    if ( lspace_end == MAX_SPACE ) {
        printf("\nsearch space size too small! currently %d\n\n", MAX_SPACE);
        exit( 1 );
    }

    lspace_size++;

    hash_state( S );

}
Exemple #3
0
int get_1P( State *S, State *current_goals ) {
    
    int h, max;
    
    source_to_dest( &lcurrent_goals, current_goals );
    
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: in function get_1P.\n the lcurrent_goals is: \n");
        print_state(lcurrent_goals);
    }

    gevaluated_states++;
    
    max = build_fixpoint( S );
    h = extract_1P( max, FALSE );
    
    if ( gcmd_line.display_info == 122 ) {
        print_fixpoint_result();
    }
    
    reset_fixpoint();
    
    return h;
    
}
Exemple #4
0
int get_1P_and_H( State *S, State *current_goals, int new_goal )

{

  int h, max;

  source_to_dest( &lgoals, current_goals );  
  if ( new_goal != -1 ) {
    lnew_goal = TRUE;
  } else {
    lnew_goal = FALSE;
  }
  
  gevaluated_states++;

  max = build_fixpoint( S );
  h = extract_1P( max, TRUE );

  if ( gcmd_line.display_info == 122 ) {
    print_fixpoint_result();
  }

  reset_fixpoint();

  return h;

}
Exemple #5
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];
  }

}
Exemple #6
0
void extract_plan_fragment( State *S )

{

  EhcNode *i;
  int ops[MAX_PLAN_LENGTH], num_ops;
  State_pointer states[MAX_PLAN_LENGTH];
  int j, mem, prev;

  num_ops = 0;
  for ( i = lehc_current_start; i->father; i = i->father ) {
    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;
  }

  mem = gnum_plan_ops;
  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 );
    }
    source_to_dest( &(gplan_states[gnum_plan_ops+1]), states[j] );
    gplan_ops[gnum_plan_ops++] = ops[j];
    if ( gcmd_line.A && gcmd_line.debug ) {
      printf("\n------------EHC SELECTING: ");
      print_op_name( ops[j] );
    }
  }

  if ( gcmd_line.A && gcmd_line.debug ) {
    printf("\n\nnew op path is:");
    for ( j = 0; j < gnum_plan_ops; j++ ) {
      printf("\n");print_op_name( gplan_ops[j] );
    }
  }

  prev = gnum_fixed_clauses;
  extend_fixed_clauses_base( mem, gnum_plan_ops );
  extend_fixed_clauses_base_encoding( prev );

}
Exemple #7
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;

}
Exemple #8
0
/*get he heuristic data*/
int get_1P_and_H( State *S, State *current_goals ) {
    
    int h, max;
    
    source_to_dest( &lcurrent_goals, current_goals );
    
    gevaluated_states++;
    
    max = build_fixpoint( S );
    h = extract_1P( max, TRUE );
    
    if ( gcmd_line.display_info == 122 ) {
        print_fixpoint_result();
    }
    
    reset_fixpoint();
    
    return h;
}
Exemple #9
0
/*get he heuristic data*/
int get_1P_and_H_for_multiple_purpose ( State *S, State *current_goals ) {

    int h, max;

    source_to_dest( &lcurrent_goals, current_goals );

    gevaluated_states++;

    max = build_fixpoint( S );
    h = extract_1P_for_multiple_purpose ( max, TRUE );

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: extract_1P_for_multiple_purpose get heuristic: %4d\n", h);
    }

    if ( gcmd_line.display_info == 122 ) {
        print_fixpoint_result();
    }

    reset_fixpoint();

    return h;
}
Exemple #10
0
int main( int argc, char *argv[] )

{

  /* resulting name for ops file
   */
  char ops_file[MAX_LENGTH] = "";
  /* same for fct file 
   */
  char fct_file[MAX_LENGTH] = "";
  
  struct tms start, end;

  State current_start, current_end;
  int i, j;
  Bool found_plan;


  times ( &lstart );


  /* command line treatment
   */
  if ( argc == 1 || ( argc == 2 && *++argv[0] == '?' ) ) {
    ff_usage();
    exit( 1 );
  }
  if ( !process_command_line( argc, argv ) ) {
    ff_usage();
    exit( 1 );
  }


  /* make file names
   */

  /* one input name missing
   */
  if ( !gcmd_line.ops_file_name || 
       !gcmd_line.fct_file_name ) {
    fprintf(stdout, "\nff: two input files needed\n\n");
    ff_usage();      
    exit( 1 );
  }
  /* add path info, complete file names will be stored in
   * ops_file and fct_file 
   */
  sprintf(ops_file, "%s%s", gcmd_line.path, gcmd_line.ops_file_name);
  sprintf(fct_file, "%s%s", gcmd_line.path, gcmd_line.fct_file_name);


  /* parse the input files
   */

  /* start parse & instantiation timing
   */
  times( &start );
  /* domain file (ops)
   */
  if ( gcmd_line.display_info >= 1 ) {
    printf("\nff: parsing domain file");
  } 
  /* it is important for the pddl language to define the domain before 
   * reading the problem 
   */
  load_ops_file( ops_file );
  /* problem file (facts)
   */  
  if ( gcmd_line.display_info >= 1 ) {
    printf(" ... done.\nff: parsing problem file"); 
  }
  load_fct_file( fct_file );
  if ( gcmd_line.display_info >= 1 ) {
    printf(" ... done.\n\n");
  }

  /* This is needed to get all types.
   */
  build_orig_constant_list();

  /* last step of parsing: see if it's an ADL domain!
   */
  if ( !make_adl_domain() ) {
    printf("\nff: this is not an ADL problem!");
    printf("\n    can't be handled by this version.\n\n");
    exit( 1 );
  }


  /* now instantiate operators;
   */


  /**************************
   * first do PREPROCESSING * 
   **************************/


  /* start by collecting all strings and thereby encoding 
   * the domain in integers.
   */
  encode_domain_in_integers();

  /* inertia preprocessing, first step:
   *   - collect inertia information
   *   - split initial state into
   *        _ arrays for individual predicates
   *        - arrays for all static relations
   *        - array containing non - static relations
   */
  do_inertia_preprocessing_step_1();

  /* normalize all PL1 formulae in domain description:
   * (goal, preconds and effect conditions)
   *   - simplify formula
   *   - expand quantifiers
   *   - NOTs down
   */
  normalize_all_wffs();

  /* translate negative preconds: introduce symmetric new predicate
   * NOT-p(..) (e.g., not-in(?ob) in briefcaseworld)
   */
  translate_negative_preconds();

  /* split domain in easy (disjunction of conjunctive preconds)
   * and hard (non DNF preconds) part, to apply 
   * different instantiation algorithms
   */
  split_domain();


  /***********************************************
   * PREPROCESSING FINISHED                      *
   *                                             *
   * NOW MULTIPLY PARAMETERS IN EFFECTIVE MANNER *
   ***********************************************/

  build_easy_action_templates();
  build_hard_action_templates();

  times( &end );
  TIME( gtempl_time );

  times( &start );

  /* perform reachability analysis in terms of relaxed 
   * fixpoint
   */
  perform_reachability_analysis();

  times( &end );
  TIME( greach_time );

  times( &start );

  /* collect the relevant facts and build final domain
   * and problem representations.
   */
  collect_relevant_facts();

  times( &end );
  TIME( grelev_time );

  times( &start );

  /* now build globally accessable connectivity graph
   */
  build_connectivity_graph();

  times( &end );
  TIME( gconn_time );
  

  /***********************************************************
   * we are finally through with preprocessing and can worry *
   * bout finding a plan instead.                            *
   ***********************************************************/

  times( &start );

  /* another quick preprocess: approximate goal orderings and split
   * goal set into sequence of smaller sets, the goal agenda
   */
  compute_goal_agenda();

  /* make space in plan states info, and relax
   */
  for ( i = 0; i < MAX_PLAN_LENGTH + 1; i++ ) {
    make_state( &(gplan_states[i]), gnum_ft_conn );
    gplan_states[i].max_F = gnum_ft_conn;
  }
  make_state( &current_start, gnum_ft_conn );
  current_start.max_F = gnum_ft_conn;
  make_state( &current_end, gnum_ft_conn );
  current_end.max_F = gnum_ft_conn;
  initialize_relax();


  source_to_dest( &(gplan_states[0]), &ginitial_state );

  source_to_dest( &current_start, &ginitial_state );
  source_to_dest( &current_end, &(ggoal_agenda[0]) );

  for ( i = 0; i < gnum_goal_agenda; i++ ) {
    if ( !do_enforced_hill_climbing( &current_start, &current_end ) ) {
      break;
    }
    source_to_dest( &current_start, &(gplan_states[gnum_plan_ops]) );
    if ( i < gnum_goal_agenda - 1 ) {
      for ( j = 0; j < ggoal_agenda[i+1].num_F; j++ ) {
	current_end.F[current_end.num_F++] = ggoal_agenda[i+1].F[j];
      }
    }
  }
  found_plan = ( i == gnum_goal_agenda ) ? TRUE : FALSE;

  if ( !found_plan ) {
    printf("\n\nEnforced Hill-climbing failed !");
    printf("\nswitching to Best-first Search now.\n");
    found_plan = do_best_first_search();
  }

  times( &end );
  TIME( gsearch_time );

  if ( found_plan ) {
    print_plan();
  }

  output_planner_info();

  printf("\n\n");
  exit( 0 );

}
Exemple #11
0
int extract_1P( int max, Bool H_info )

{

  static Bool first_call = TRUE;
  int i, max_goal_level, time, r;

  if ( first_call ) {
    for ( i = 0; i < gnum_ft_conn; i++ ) {
      gft_conn[i].is_true = INFINITY;
      gft_conn[i].is_goal = FALSE;
      gft_conn[i].ch = FALSE;
    }
    for ( i = 0; i < gnum_op_conn; i++ ) {
      gop_conn[i].is_used = INFINITY;
    }
    for ( i = 0; i < gnum_ef_conn; i++ ) {
      gef_conn[i].in_plan = FALSE;
    }
    lch_F = ( int * ) calloc( gnum_ft_conn, sizeof( int ) );
    lnum_ch_F = 0;
    lused_O = ( int * ) calloc( gnum_op_conn, sizeof( int ) );
    lnum_used_O = 0;
    gin_plan_E = ( int * ) calloc( gnum_ef_conn, sizeof( int ) );
    gnum_in_plan_E = 0;
    first_call = FALSE;
  }

  reset_search_info();

  if ( (max_goal_level = initialize_goals( max )) == INFINITY ) {
    return INFINITY;
  }

  //new from Y. Chen
  for(i=0; i<known_iga_list.num_F; i++) {
    if(gft_conn[known_iga_list.F[i]].level == INFINITY) { 
        //printf("known_iga blocking\n");
        return INFINITY;
    }
  }             
  //----------------
  
  for ( time = max_goal_level; time > 0; time-- ) {
    achieve_goals( time );
  }
  if ( H_info ) {
    collect_H_info();
  }
  r = lnum_used_O;

  if ( lnew_goal ) {
    reset_search_info();
    source_to_dest( &lgoals, &ggoal_state );  
    if ( (max_goal_level = initialize_goals( max )) == INFINITY ) {
      return INFINITY;
    }
    for ( time = max_goal_level; time > 0; time-- ) {
      achieve_goals( time );
    }
  }

  return r;

}
Exemple #12
0
/* jovi: add for multiple purpose */
Bool do_enforced_hill_climbing_for_multiple_purpose ( State *start, State *end ) {

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: do_enforced_hill_climbing_for_multiple_purpose \n");
        printf("start:");
        print_state(*start);
        printf("\n\nend:");
        print_state(*end);
    }

	static Bool first_call_for_multiple_purpose  = TRUE;
	static State S, S_;
	int i, h, h_;

	if ( first_call_for_multiple_purpose ) {

		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_for_multiple_purpose  = FALSE;
	}

	/* start enforced Hill-climbing */
	source_to_dest( &lcurrent_goals, end );  
	source_to_dest( &S, start );
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: in function do_enforced_hill_climbing_for_multiple_purpose() \n");
        printf("lcurrent_goals is:");
        print_state(lcurrent_goals);
    }
	/*seems get a heuristic*/
	h = get_1P_and_H_for_multiple_purpose ( &S, &lcurrent_goals );
    
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: get_1P_and_H_for_multiple_purpose get heuristic: %4d\n", h);
    }
    
    if ( gcmd_line.display_info >= 1 ) {
    	printf("\nDebugInfo: Current goal is ");
    	print_state(lcurrent_goals);
    	printf("\n");
    }



	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_for_multiple_purpose( &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;
}
Exemple #13
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;
}
Exemple #14
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;
}
Exemple #15
0
int main (int argc, char *argv[])
{

  /* resulting name for ops file */
  char ops_file[MAX_LENGTH] = "";
  /* same for fct file */
  char fct_file[MAX_LENGTH] = "";

  char sol_file[MAX_LENGTH] = "";

  struct tms start, end;

  struct timeval tv;
  struct timezone tz;

  State current_start, current_end;
  int i, j, k;
  Bool found_plan=0;


#ifdef __EFENCE__
  extern int EF_ALLOW_MALLOC_0;
  EF_ALLOW_MALLOC_0 = 1;
#endif

printf("#\n");
printf("# (C) Copyright 2008, University of Illinois, Urbana-Champaign\n");
printf("#\n");
printf("# All rights reserved. Use of this software is permitted ONLY for\n");
printf("# non-commercial research purposes, and it may be copied only\n");
printf("# for that use only. All copies must include this copyright message.\n");
printf("# This software is made available AS IS, and neither the authors\n");
printf("# nor the University of Illinois, make any warranty about the\n");
printf("# software or its performance.\n");
printf("#\n");

  dis_gcmd_line.display_info = 1;
  dis_gcmd_line.debug = 0;
  dis_gcmd_line.ehc = dis_TRUE;
  dis_gcmd_line.optimize = dis_FALSE;
  dis_gcmd_line.g_weight = 1;
  dis_gcmd_line.h_weight = 1;
  SymmLagrangian = 0;     
  SymmLagrange = 0;     
  GpG.subsolver = 0;
  //dis_processdis__command_line(argc, argv); 
  /*
  printf("dis_gcmd_line.g_weight = %d\n", dis_gcmd_line.g_weight );
  printf("dis_gcmd_line.h_weight = %d\n", dis_gcmd_line.h_weight );
  printf("dis_gcmd_line.ehc = %d\n", dis_gcmd_line.ehc );
  printf("dis_gcmd_line.optimize = %d\n", dis_gcmd_line.optimize );
  printf("dis_gcmd_line.display_info = %d\n", dis_gcmd_line.display_info );
  printf("dis_gcmd_line.debug = %d\n", dis_gcmd_line.debug );
    */        
  
  //-------
  
  so_signal_management();

  strcpy (gcomm_line, "");
  for (i = 0; i < argc; i++)
    {
      strcat (gcomm_line, argv[i]);
      strcat (gcomm_line, " ");
    }
  get_path (*argv, glpg_path);
  initialize_preset_values ();


#ifdef __STATISTIC_LM__
  init_statistic();
#endif 

  /*Reset  hash-table
   */ 
  reset_cvar_hash_table();

  /* Initialize random seed
   */
  gettimeofday (&tv, &tz);
  seed = ((tv.tv_sec & 0177) * 1000000) + tv.tv_usec;


  /* command line treatment
   */
  if (argc == 1 || (argc == 2 && *++argv[0] == '?'))
    {
      lpg_usage ();
      exit (1);
    }
    gcmd_line.out_file_name[0] = 0;
  if (!process_command_line (argc, argv))
    {
      lpg_usage ();
      exit (1);
    }

  /* make file names
   */

  /* one input name missing
   */
  if (!gcmd_line.ops_file_name || !gcmd_line.fct_file_name)
    {
      fprintf (stdout, "\n%s: two input files needed\n\n", NAMEPRG);
      lpg_usage ();
      exit (1);
    }
  /* add path info, complete file names will be stored in
   * ops_file and fct_file 
   */
  sprintf (ops_file, "%s%s", gcmd_line.path, gcmd_line.ops_file_name);
  sprintf (fct_file, "%s%s", gcmd_line.path, gcmd_line.fct_file_name);

  strcpy (gops_file, ops_file);
  strcpy (gfct_file, fct_file);
  sprintf (sol_file, "%s%s", gcmd_line.path, gcmd_line.sol_file_name);


  /* parse the input files
   */

  /* start parse & instantiation timing
   */
  times (&glob_start_time);
  times (&start);

  /*
  //GpG.feed_MFF_LPG = TRUE;
  GpG.feed_MFF_LPG = FALSE;
  if(GpG.feed_MFF_LPG) {
        dis_MFF_main(ops_file, fct_file);
        mff_to_lpg();    
  }
  else 
  // START OF PARSING
  {*/

  /* domain file (ops)
   */

  // ADL?
  GpG.gis_ADL = ADL_ops_file(ops_file);
  i = get_requirements(ops_file);
  if((!GpG.is_deripred || i == 1 || !GpG.gis_ADL) && !GpG.is_goal_utilities && !GpG.is_action_costs) {
  if(!i || !GpG.gis_ADL) {   
   printf ("\nParsing domain file\n");
	fflush(stdout);

    /* it is important for the pddl language to define the domain before 
    * reading the problem 
    */
    load_ops_file (ops_file);
    // Y. Chen
    if(gloaded_dps) {
       // printf("\nSGPlan: Contains derived predicates\n");
      GpG.is_deripred = TRUE;
    }
    else {
      //  printf("\nSGPlan: No derived predicates\n");
      GpG.is_deripred = FALSE;
    }                 
  }
  else
  {
    gdomain_name = dis_copy_dis_Token("PSR");
    GpG.is_deripred = TRUE;
  }
  }

  /* =============  Search Modal =======================
   * Y. Chen 
   * Decide which parser to use here 
   */
                                
  search_ops_modal(); 
  //fprintf(stderr, "\nSearchModal = %d %d\n", GpG.SearchModal, GpG.SecondaryModal);
                                           
  // MFF_parser
  if((GpG.SearchModal == 5) || (GpG.SearchModal == 7) 
     || (GpG.SearchModal == 6) || (GpG.SearchModal == 100)
     || (GpG.SearchModal == 104) || (GpG.SearchModal == 106)
     || (GpG.SearchModal == 107)
     || (GpG.SearchModal == -1) || (GpG.SearchModal <= -1000)) {
	/* 
	Settlers 5
	Sattelite 6 Sattelite TIME_TIMEWINDOWS_COMPILED 106
	UMTS 7
	Psr large 100 Psr middle-compiled 104
	Promela OPTICAL_TELEGRAPH_FLUENTS PHILOSOPHERS_FLUENTS 107
	*/
        GpG.MFF_parser = TRUE;        
  } else {
        GpG.MFF_parser = FALSE;
  }
 
  // ComputeMutex       
  if(((GpG.SearchModal == 0)||(GpG.SearchModal == 105))
  || (GpG.SearchModal == 3 && GpG.is_til )
         ) {
	/*
	Airport 0 Airport TEMPORAL_TIMEWINDOWS_COMPILED 105
	Pipesworld NOTANKAGE_TEMPORAL_DEADLINES 3
	*/
	GpG.lowmemory = FALSE;
        ComputeMutex = TRUE;        
  } else {
        ComputeMutex = FALSE;
  }
  if(GpG.is_deripred) {
      ComputeMutex = FALSE;
  }
    
    
  /* ==================================================*/
 
  if(GpG.MFF_parser) {
    mffDistributedSearch(ops_file, fct_file);  
    exit(0);
  }
  
  /* ===================================================
    */
  
  transfer_PlDP_PlOperator();
        
  /*dirty trick to get another copy of gloaded_ops */
  	if (GpG.is_til)
		load_fct_file (fct_file);  
  gloaded_pl2ops = gloaded_ops;
  gloaded_ops = NULL;
  /* derived predicates */
  gloaded_dps = NULL;
  /* timed initial literals */
  gnum_tils = 0;
  g_tils = gtils = NULL;
  gdomain_name = NULL;
  gorig_initial_facts = NULL;
  gorig_goal_facts = NULL;
  gmetric_exp = NULL;
  gloaded_axioms = NULL;
  gparse_types = NULL;
  gparse_constants = NULL;
  gparse_predicates = NULL;
  gparse_functions = NULL;
  gparse_objects = NULL;
  gorig_constant_list = NULL;
  gpredicates_and_types = NULL;
  gfunctions_and_types = NULL;
  gloaded_constraints = NULL;
  gloaded_preferences = NULL;
  load_ops_file (ops_file);
  
  // Y. Chen
  transfer_PlDP_PlOperator();

  /*add dummy effect to operators without boolean effects */
  add_dummy_effects (gloaded_ops);
  add_dummy_effects (gloaded_pl2ops);
  /*counts numeric preconds and effects */
  count_num_preconds_and_effects ();
  GpG.gplan_actions = NULL;


  /* problem file (facts)
   */
  if (gcmd_line.display_info >= 1)
    {
      printf ("\nParsing problem file\n");
	fflush(stdout);
    }

  load_fct_file (fct_file);
  if (gcmd_line.display_info >= 1)
    printf ("\n\n");

  allocate_after_parser();

  /* now we have PlOperators and PlNodes */
  reduce_pddl2_to_pddl1 ();

  /* This is needed to get all types.
   */
  build_orig_constant_list ();

  /* last step of parsing: see if it's an ADL domain!
   */

  if (!make_adl_domain ())
    {
      printf ("\n%s: this is  an ADL problem!", NAMEPRG);
      printf ("\n    can't be handled by this version.\n\n");
      exit (1);
    }


  /* now instantiate operators;
   */


  /**************************
   * first do PREPROCESSING * 
   **************************/


  /* start by collecting all strings and thereby encoding 
   * the domain in integers.
   */
  encode_domain_in_integers ();

  /* inertia preprocessing, first step:
   *   - collect inertia information
   *   - split initial state into
   *        _ arrays for individual predicates
   *        - arrays for all static relations
   *        - array containing non - static relations
   */
  do_inertia_preprocessing_step_1 ();

  /* normalize all PL1 formulae in domain description:
   * (goal, preconds and effect conditions)
   *   - simplify formula
   *   - expand quantifiers
   *   - NOTs down
   */
  normalize_all_wffs ();

  /* translate negative preconds: introduce symmetric new predicate
   * NOT-p(..) (e.g., not-in(?ob) in briefcaseworld)
   */
  translate_negative_preconds ();

  /* split domain in easy (disjunction of conjunctive preconds)
   * and hard (non DNF preconds) part, to apply 
   * different instantiation algorithms
   */
  split_domain ();


  /***********************************************
   * PREPROCESSING FINISHED                      *
   *                                             *
   * NOW MULTIPLY PARAMETERS IN EFFECTIVE MANNER *
   ***********************************************/

  build_easy_action_templates ();

  build_hard_action_templates ();

  times (&end);
  TIME (gtempl_time);
  times (&start);


  check_time_and_length (0);

  // Y.Chen
  seed = 2004;
  srandom(seed);

#ifdef __MY_OUTPUT__
  printf ("\n Seed %d  \n", seed);
#endif


  /* perform reachability analysis in terms of relaxed 
   * fixpoint
   */

  perform_reachability_analysis ();

  times (&end);
  TIME (greach_time);
  times (&start);

  check_time_and_length (0);


  /* collect the relevant facts and build final domain
   * and problem representations.
   */

  collect_relevant_facts ();

  times (&end);
  TIME (grelev_time);
  times (&start);

  check_time_and_length (0);


  /* now build globally accessable connectivity graph
   */
  build_connectivity_graph ();
 
 /* 
  }// END PARSING
 */

  // Y. Chen
  set_DPop_flag();
 
  if(GpG.SearchModal != 3 && GpG.SearchModal != -2) { 
    if(!ComputeMutex) {       
        DistributeSearch(&ginitial_state, &ggoal_state, &subplan_actions);
        exit(0);
    }
  }
  
  times (&end);
  TIME (gconn_time);
  times (&start);

  check_time_and_length (0);

  /* association to gef_conn[i] a corresponding complet ploperator */
  associate_PlOperator_with_EfConn ();


  /* adding composed numeric quantities */
  add_composite_vars ();

  make_numgoal_state(GpG.numeric_goal_PlNode);

  /* make false the comparison between uninitialized numeric quantities */
  make_false_all_checks_on_not_init ();

  /* Semplification for inertial vars
   */
  propagate_inertias ();

if (GpG.SearchModal == -2)
{
	mffDistributedSearch(ops_file, fct_file);
	exit(0);
}
  if(GpG.SearchModal == 3) { 
    if(!ComputeMutex) {       
        DistributeSearch(&ginitial_state, &ggoal_state, &subplan_actions);
        exit(0);
    }
  }

  if (DEBUG0)
    if (GpG.non_strips_domain)
      {
          /*
	    if (GpG.variable_duration)
	        printf ("\n\nAction durations have been computed\n");
	    else
	     printf ("\n\nThere is no action duration to compute\n");*/
      }

  /* Set vars orig_weight_cost and orig_weight_time according with plan evaluation metric
   */
  if (goptimization_exp != -1)
    set_cost_and_time_coeffs ();

  /*
  if (DEBUG0)
    printf("\nEvaluation function weights:\n     Action duration %.2f; Action cost %.2f", GpG.orig_weight_time, GpG.orig_weight_cost);

  if (DEBUG0)
    printf ("\n\nTemporal flag: %s\n", GpG.temporal_plan ? "ON" : "OFF");
 */
    
  /* Make numeric effects structure
   */
  create_descnumeff_of_efconns ();

  /* Sets flag is_numeric for each action (efconn)
   */
  set_numeric_flag ();

  assert (gnum_comp_var < MAX_NUM_VALUE);

  /* Copy initial state in  initial_state
   */
  for (i = 0; i < gnum_comp_var; i++)
    ginitial_state.V[i] = GCOMP_VAR_VALUE(i);


  times (&end);
  TIME (gnum_time);
  times (&start);

  /* Print information about action istantiation 
   */
  print_parser_info_for_debug();
  //print_real_state(ginitial_state); 

  
    if(ComputeMutex) {
        
  //if (GpG.numrun > 0 && GpG.numtry > 0) {
  if (1) {

    if (DEBUG0 && !DEBUG1) {
   //   printf ("\nComputing mutex... ");
   //   fflush (stdout);
    }
    if (DEBUG1)
      printf ("\n\n--- COMPUTE MUTEX BETWEEN FACTS ---\n");
    
    if (GpG.accurate_cost >= 1)
      allocate_reachability_information_data();
	
    /* Comute mutex between facts    
    */
    calc_mutex (&ginitial_state);
    
    if (!are_goal_reachable_and_non_mutex ()) {
      printf ("\nThe problem is unsolvable since at the fixpoint level the goals are mutex or not reachable\n\n");
      exit (0);
    }
  }
  

  times (&end);
  TIME (gmutex_ft_time);

  if (DEBUG2)
    printf ("\n");
  if (DEBUG1)
    printf ("\n   --> Compute mutex between facts TOTAL TIME: %12.2f",gmutex_ft_time);

  times (&start);
  //if (GpG.numrun > 0 && GpG.numtry > 0) {
  if(1){  
   if (DEBUG1)
      printf ("\n\n--- COMPUTE MUTEX BETWEEN ACTIONS ---\n");
    /*Compute action-action, action_fact, fact-action mutex
     */
    calc_mutex_ops ();
  }


  times (&end);
  TIME (gmutex_ops_time);

  if (DEBUG1)
    printf ("\n   --> Compute mutex between actions TOTAL TIME: %12.2f\n",gmutex_ops_time);


  
  times (&start);

  
  //if (GpG.numrun > 0 && GpG.numtry > 0) {
  if(1){
      if (DEBUG1)
      printf ("\n\n--- COMPUTE MUTEX BETWEEN NUMERIC FACTS ---\n");
    /* Compute mutex between action with numeric effects
     */  
    if (!GpG.lowmemory)
      calc_mutex_num_efs ();
  }
  
  times (&end);
  TIME (gmutex_num_time);

  if (DEBUG1)
    printf("\n   --> Compute mutex between numeric facts TOTAL TIME: %12.2f\n",gmutex_num_time);
  if (DEBUG2)
    print_mutex_result ();
  if (DEBUG0 && !DEBUG1) {
   // printf ("done");
   // fflush (stdout);
  }

  times (&start);

  //if (DEBUG6 && !GpG.lowmemory)
    print_matrs ();
  gmutex_total_time = gmutex_ft_time + gmutex_ops_time + gmutex_num_time;
 }

  if (strlen (gcmd_line.sol_file_name) > 0)
    load_pddl2_plan (sol_file, &GpG.gplan_actions, 0);
	if (GpG.SearchModal == 3)
		ComputeMutex = FALSE;


  GpG.max_num_actions = gnum_ef_conn;
  GpG.max_num_facts = gnum_ft_conn;
  GpG.max_num_ft_block = gnum_ft_block;



  /***********************************************************
   * we are finally through with preprocessing and can worry *
   * about finding a plan instead.                            *
   ***********************************************************/


  /* another quick preprocess: approximate goal orderings and split
   * goal set into sequence of smaller sets, the goal agenda
   */
   
	// Yixin
 if(ComputeMutex) { 
    modify_ft_ef_mutex(); 
    compute_goal_agenda();
 }
  // printf ("******************\n");

  /*
   source_to_dest( &(gplan_states[0]), &ginitial_state );
   source_to_dest( &current_start, &ginitial_state );
   source_to_dest( &current_end, &(ggoal_agenda[0]) );
          
   for ( i = 0; i < gnum_goal_agenda; i++ ) {
	if ( !do_enforced_hill_climbing( &current_start, &current_end ) ) {
	       break;
       }
       source_to_dest( &current_start, &(gplan_states[gnum_plan_ops]) );
      if ( i < gnum_goal_agenda - 1 ) {
         for ( j = 0; j < ggoal_agenda[i+1].num_F; j++ ) {
	       current_end.F[current_end.num_F++] = ggoal_agenda[i+1].F[j];
         }
      }
    }
    found_plan = ( i == gnum_goal_agenda ) ? TRUE : FALSE;
  */
    

  source_to_dest (&(gplan_states[0]), &ginitial_state);
  source_to_dest (&current_start, &ginitial_state);
  source_to_dest (&current_end, &ggoal_state);

  remove_unappliable_actions ();

  if ((GpG.search_type == LOCAL && GpG.numrun > 0 && GpG.numtry > 0) ||
      GpG.search_type == DIS_SEARCH )
     {
      k = MAX (GpG.input_plan_lenght, gmutex_level);
      for (i = 0; i < k; i++)
	{
	  if (i < gmutex_level)
	    create_vectlevel (0);
	  else
	    create_vectlevel (1);
	}
      allocate_data_for_local_search();
      create_all_min_array ();

      GpG.fixpoint_plan_length = GpG.max_plan_length - 1;
      GpG.saved_fixpoint_plan_length = GpG.fixpoint_plan_length ;
      GpG.curr_goal_state =  &current_end;

    }


  if (DEBUG1) {
    printf ("\n\nTime spent for preprocessing:");
    printf ("\n Instantiating:     %7.2f seconds", gtempl_time + greach_time + grelev_time + gconn_time + gsearch_time);
    printf ("\n Mutex relations:   %7.2f seconds", gmutex_total_time);
    printf ("\n Numeric relations: %7.2f seconds", gnum_time);
  }
  if (DEBUG0) {   
    times (&glob_end_time);
    gtotal_time = (float) ((glob_end_time.tms_utime - glob_start_time.tms_utime + glob_end_time.tms_stime - glob_start_time.tms_stime) / 100.0);
  //  printf ("\nPreprocessing total time: %.2f seconds",gtotal_time);
  }
  

  /*
  printf ("\n\ninitial state is:\n\n");
  for (i = 0; i < ginitial_state.num_F; i++)
    {
      print_ft_name (current_start.F[i]);
      printf ("\n");
    }
  printf ("\n\ngoal state is:\n\n");
  for (i = 0; i < current_end.num_F; i++)
    {
      print_ft_name (current_end.F[i]);
      printf ("\n");
    }
  printf("GpG.fixpoint_plan_length = ",
          GpG.fixpoint_plan_length);
*/
#ifdef __TEST__
  for (i = 0; i < gnum_op_conn; i++)
  {
    print_op_name(i);
    printf(" -- %f \n", get_action_cost (i));
  }
#endif


  if (GpG.do_best_first == TRUE && GpG.numrun==0)  
    GpG.search_type=BEST_FIRST;
  /* Search untill it is not reached termination condition (given by the function 'is_term_condition_reached')
   */
  while(!is_terminated)
    {
      /* Different types of local search 
       */      
      switch(GpG.search_type)
	{
	  /* Local Search usually used in LPG
	   */

     case DIS_SEARCH:
         DistributeSearch(&current_start, &current_end, &subplan_actions);
         GpG.gplan_actions = subplan_actions;
         subplan_actions = NULL;
         is_terminated=TRUE;
         break;       
         
     case LOCAL:
	  /* Do Local Search
	   */
	   
        LocalSearch (&current_start, &current_end, &subplan_actions);
	  /* Store plan in GpG.gplan_actions
	   */
	  GpG.gplan_actions = subplan_actions;	 
	  subplan_actions = NULL;
	  /* Control if the termination condition is reached
	   */
	  is_terminated=TRUE;
      //is_terminated= is_term_condition_reached();
	  break;
	 
	  /* Best First Search implemented by J. Hoffmann (FF-v2.3)
	   */
	case BEST_FIRST:

      //  strips_gef_conn();
       // load_ff_gef_conn();
	  
        if (DEBUG0)
	    printf("\n\nSwitching to Best-first Search ( code from J. Hoffmann's package FF-v2.3 ) \n");
	  check_time_and_length (0);	/* con zero non controlla la lunghezza */
	  /* Return solution if reached, FALSE otherwise
	   */
	  found_plan = do_best_first_search ();
	  printf("do_best_first_search");
      
	  //if (do_enforced_hill_climbing (&current_start, &current_end))
	  //printf("do_hill");
	  
      times (&end);
	  TIME (gsearch_time);
	  
	  times (&end);
	  times (&glob_end_time);
	  gtotal_time = (float) ((glob_end_time.tms_utime - glob_start_time.tms_utime + glob_end_time.tms_stime - glob_start_time.tms_stime) / 100.0);
	  /* If a solution was found in best first search print solution
	   */
	  if (found_plan)
	    {
	      
#ifdef __MY_OUTPUT__
	      printf ("\nFFGGHH::%.2f::%d\n", gtotal_time, gnum_plan_ops);
#endif
	      store_adapted_temporal_plan_ff (gcmd_line.fct_file_name);
	      
	      
	      printf ("\nTotal time:      %.2f\nSearch time:     %.2f\nActions:         %d\nExecution cost:  %.2f\nDuration:        %.3f\nPlan quality:    %.3f", gtotal_time, gsearch_time, GpG.num_actions, GpG.total_cost, GpG.total_time,GpG.total_cost * GpG.orig_weight_cost + GpG.total_time * GpG.orig_weight_time);

	      printf ("\n     Plan file:");
	      printf ("       plan_bestfirst_%s.SOL", gcmd_line.fct_file_name);
	  
	    }
	  
	  if (DEBUG1)
	    output_planner_info ();
	  /* Control if the termination condition is reached
	   */
	  is_terminated= is_term_condition_reached();
	  break;
	  
	  /* Hill Climbing Search
	   */
	case   HILL_CLIMBING:
	  
	  if (do_enforced_hill_climbing (&current_start, &current_end))
	    source_to_dest (&current_start, &(gplan_states[gnum_plan_ops]));
	  
      printf("do_hill");
	  /* Control if the termination condition is reached
	   */
	  is_terminated= is_term_condition_reached();
	  break;
	  
	default:
	  /* Control if the termination condition is reached
	   */
	  is_terminated= is_term_condition_reached();
	  break;

	}  

	  
      if (DEBUG2)
	{
	  printf ("\n\nInitial state is:\n\n");
	  for (j = 0; j < ginitial_state.num_F; j++)
	    {
	      print_ft_name (current_start.F[j]);
	      printf ("\n");
	    }
	  printf ("\n\nGoal state is:\n\n");
	  for (j = 0; j < current_end.num_F; j++)
	    {
	      print_ft_name (current_end.F[j]);
	      printf ("\n");
	    }
	}
    }
    
  printf ("\n\n");

	      printf ("\nTotal time:      %.3f\n", gtotal_time);
  exit (0);
}
Exemple #16
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;

}
Exemple #17
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;

}
Exemple #18
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;
    }
    
    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;

}
Exemple #19
0
void hash_state( State S )

{

    static Bool first_call = TRUE;

    int i, sum, index;
    StateHashEntry *h, *prev = NULL;

    if ( first_call ) {
        for ( i = 0; i < STATE_HASH_SIZE; i++ ) {
            lstate_hash_entry[i] = NULL;
            lnum_state_hash_entry[i] = 0;
            lchanged_entry[i] = FALSE;
        }
        lnum_changed_entrys = 0;
        first_call = FALSE;
    }

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

    h = lstate_hash_entry[index];
    if ( !h ) {
        h = new_StateHashEntry();
        source_to_dest( &(h->S), S );
        h->sum = sum;
        lstate_hash_entry[index] = h;
        lnum_state_hash_entry[index]++;
        if ( !lchanged_entry[index] ) {
            lchanged_entrys[lnum_changed_entrys++] = index;
            lchanged_entry[index] = TRUE;
        }
        return;
    }
    i = 0;
    while ( h ) {
        if ( i == lnum_state_hash_entry[index] ) {
            break;
        }
        i++;
        prev = h;
        h = h->next;
    }

    if ( h ) {
        /* current list end is still in allocated list of hash entrys
         */
        source_to_dest( &(h->S), S );
        h->sum = sum;
        lnum_state_hash_entry[index]++;
        if ( !lchanged_entry[index] ) {
            lchanged_entrys[lnum_changed_entrys++] = index;
            lchanged_entry[index] = TRUE;
        }
        return;
    }
    /* allocated list ended; connect a new hash entry to it.
     */
    h = new_StateHashEntry();
    source_to_dest( &(h->S), S );
    h->sum = sum;
    prev->next = h;
    lnum_state_hash_entry[index]++;
    if ( !lchanged_entry[index] ) {
        lchanged_entrys[lnum_changed_entrys++] = index;
        lchanged_entry[index] = TRUE;
    }
    return;

}
Exemple #20
0
int main( int argc, char *argv[] ) {
    /* resulting name for ops file
     */
    char ops_file[MAX_LENGTH] = "";

    /* same for fct file
     */
    char fct_file[MAX_LENGTH] = "";

    /* name for additional goal file
     */
    char mul_file[MAX_LENGTH] = "";

    struct timeb start, end;

    State current_start, current_end;
    int i, j;
    Bool found_plan;

    Bool found_plan_for_multiple_purpose;

    /*times ( &lstart );*/
    ftime(&lstart);

    /* command line treatment*/
    if ( argc == 1 || ( argc == 2 && *++argv[0] == '?' ) ) {
        ff_usage();
        exit( 1 );
    }
    if ( !process_command_line( argc, argv ) ) {
        ff_usage();
        exit( 1 );
    }

    /* make file names
     */

    /* one input name missing
     */
    if ( !gcmd_line.ops_file_name ||
            !gcmd_line.fct_file_name ||
            !gcmd_line.mul_file_name ) {

        fprintf(stdout, "\nmul-fip : three input files needed\n");
        ff_usage();
        exit( 1 );
    }
    /* add path info, complete file names will be stored in
     * ops_file and fct_file
     */
    sprintf(ops_file, "%s%s", gcmd_line.path, gcmd_line.ops_file_name);
    sprintf(fct_file, "%s%s", gcmd_line.path, gcmd_line.fct_file_name);
    sprintf(mul_file, "%s%s", gcmd_line.path, gcmd_line.mul_file_name);

    /* parse the input files
     */
    /* start parse & instantiation timing*/
    /*times( &start );*/
    ftime(&start);
    /* domain file (ops)
     */

    /* it is important for the pddl language to define the domain before
     * reading the problem  */
    load_ops_file( ops_file );
    /* problem file (facts) */
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: parsing problem file.\n");
    }

    load_fct_file( fct_file );

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: original purpose fact file done.\n");
    }

    load_mul_file( mul_file );

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: multiple purpose fact file done.\n");
    }

    /* This is needed to get all types.*/
    /* modified by jovi: adding supprot for addtional constant */
    build_orig_constant_list();

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: build_orig_constant_list() done.\n");
    }

    /* last step of parsing: see if it's an ADL domain!
     */
    if ( !make_adl_domain() ) {
        printf("\nmul-fip: this is not an ADL problem!");
        printf("\n\tcan't be handled by this version.\n\n");
        exit( 1 );
    }
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: make_adl_domain() done.\n");
    }

    /* now instantiate operators;
     */
    /*JC: initialize the array*/
    gInvActs = (StateActionPair*)calloc(MAX_INVALID_ACTIONS, sizeof(StateActionPair));

    /**************************
     * first do PREPROCESSING *
     **************************/

    /* start by collecting all strings and thereby encoding
     * the domain in integers.
     */
    encode_domain_in_integers();

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: encode_domain_in_integers() done.\n");
    }
    /* inertia preprocessing, first step:
     *   - collect inertia information
     *   - split initial state into
     *        _ arrays for individual predicates
     *        - arrays for all static relations
     *        - array containing non - static relations
     */
    do_inertia_preprocessing_step_1();
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: do_inertia_preprocessing_step_1() done.\n");
    }

    /* normalize all PL1 formulae in domain description:
     * (goal, preconds and effect conditions)
     *   - simplify formula
     *   - expand quantifiers
     *   - NOTs down
     */
    normalize_all_wffs();

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: normalize_all_wffs() done.\n");
    }

    /* translate negative preconds: introduce symmetric new predicate
     * NOT-p(..) (e.g., not-in(?ob) in briefcaseworld)
     */
    translate_negative_preconds();
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: translate_negative_preconds() done.\n");
    }

    /* split domain in easy (disjunction of conjunctive preconds)
     * and hard (non DNF preconds) part, to apply
     * different instantiation algorithms
     */
    split_domain();
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: split_domain() done.\n");
    }

    /***********************************************
     * PREPROCESSING FINISHED                      *
     *                                             *
     * NOW MULTIPLY PARAMETERS IN EFFECTIVE MANNER *
     ***********************************************/

    /*jovi: updated for multiple purpose */
    build_easy_action_templates();
    build_hard_action_templates();

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: build_easy_action_template() done.\n");
    }

    /*times( &end );*/
    ftime(&end);
    TIME( gtempl_time );

    /*times( &start );*/
    ftime(&start);

    /* perform reachability analysis in terms of relaxed  fixpoint */
    perform_reachability_analysis();

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: perform_reachability_analysis() done.\n");
    }

    /*times( &end );*/
    ftime(&end);
    TIME( greach_time );

    /*times( &start );*/
    ftime(&start);

    /* collect the relevant facts and build final domain
     * and problem representations.*/
    collect_relevant_facts();
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: collect_relevant_facts.\n");
    }
    /*times( &end );*/
    ftime(&end);
    TIME( grelev_time );

    /*times( &start );*/
    ftime(&start);

    /* now build globally accessable connectivity graph */
    build_connectivity_graph();
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: build_connectivity_graph().\n");
    }

    /*times( &end );*/
    ftime(&end);
    TIME( gconn_time );


    /***********************************************************
     * we are finally through with preprocessing and can worry *
     * bout finding a plan instead.                            *
     ***********************************************************/
    ftime(&mystart);
    /*times( &start );*/
    ftime(&start);

    /* another quick preprocess: approximate goal orderings and split
     * goal set into sequence of smaller sets, the goal agenda
     */
    compute_goal_agenda();
    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: compute_goal_agenda().\n");
    }
    /*debugit(&ginitial_state);*/
    /* make space in plan states info, and relax
     * make sapce is initialize the space for gplan_states and
     * initialzie the variable
     */
    for ( i = 0; i < MAX_PLAN_LENGTH + 1; i++ ) {
        make_state( &(gplan_states[i]), gnum_ft_conn );
        gplan_states[i].max_F = gnum_ft_conn;
    }

    make_state( &current_start, gnum_ft_conn );
    current_start.max_F = gnum_ft_conn;
    make_state( &current_end, gnum_ft_conn );
    current_end.max_F = gnum_ft_conn;
    initialize_relax();

    /* need to read the agenda paper */
    source_to_dest( &(gplan_states[0]), &ginitial_state );
    source_to_dest( &current_start, &ginitial_state );
    source_to_dest( &current_end, &(ggoal_agenda[0]) );

    for ( i = 0; i < gnum_goal_agenda; i++ ) {
        /* JC add a hashtable creating in do_enforced_hill_climbling*/
        if (!do_enforced_hill_climbing(&current_start, &current_end)) {
            if (gcmd_line.display_info >= 1) {
                printf("\nDebugInfo: do_enforced_hill_climbling() exit .\n");
            }
            break;
        }
        source_to_dest( &current_start, &(gplan_states[gnum_plan_ops]) );
        if ( i < gnum_goal_agenda - 1 ) {
            for ( j = 0; j < ggoal_agenda[i+1].num_F; j++ ) {
                current_end.F[current_end.num_F++] = ggoal_agenda[i+1].F[j];
            }
        }
    }

    found_plan = ( i == gnum_goal_agenda ) ? TRUE : FALSE;

    if ( !found_plan ) {
        printf("\nDebugInfo: switching to Best-first Search now.\n");
        reset_ff_states();
        found_plan = do_best_first_search();
    }


    if ( gcmd_line.display_info >= 1 ) {
        printf("\n************************************************\n");
        printf("\n*  mul-fip: fip plan finished for single goal. *\n");
        printf("\n************************************************\n");
    }
    print_plan();

    if ( !found_plan ) {
        /*print_plan();*/
        /* D action add to group */
        build_action_group();

        gfipPlan.num_sons = 0;
        gfipPlan.action = -1;

        print_plan();

        /*put the ultimate goal to the solved set*/
        StateActionPair *g = new_StateActionPair();
        make_state(&g->state, gnum_ft_conn);
        g->state.max_F = gnum_ft_conn;
        source_to_dest(&g->state, &ggoal_state);
        g->state.num_L = 1;
        g->state.L[0] = 10000000; /*make it the biggest*/
        add_solved_state(g);
        /*ugly, but work*/

        convert_ff_plan_to_fip_plan( &gfipPlan );

        solve_unsolved_states();

        if(!gsolved_states) {
            printf("No solutions are found! The problem is unsolvable.\n");
            exit(0);
        } else if(g_is_strong) {
            StateActionPair *ptr = gsolved_states;
            Bool valid = FALSE;
            while(ptr) {
                if(ptr->state.num_L == 1 && ptr->state.L[0] == 1) {
                    valid = TRUE;
                    break;
                }
                ptr = ptr->next;
            }
            if(!valid) {
                printf("The initial state is a dead-end! The problem is unsolvable.\n");
                exit(0);
            }
        }

        printf("##########################################\n");
        printf("#####   PROCEDURE-LIKE CODE   ############\n");
        printf("##########################################\n");
        /* print_fip_plan_1( is_solved_state(&ginitial_state) , &gfipPlan, 1); */

        /* times( &end ); */
        ftime(&end);
        TIME( gsearch_time );

        /* myend = clock(); */
        ftime(&myend);

        /* printf("my cac is %7.3f\n", 1.0*(myend.millitm - mystart.millitm)/1000.0); */
        print_fip_plan_2();

        if(to_print_state)
            print_all_states();
        /* print_fip_plan_3( &gfipPlan, 0 ); */
    }
    printf("The total searching time is %7.3f\n", (myend.time - mystart.time) + (myend.millitm - mystart.millitm)/1000.0);

    output_planner_info();




    /********************************************
     * Multiple Purpose Planning                *
     ********************************************/

    if ( gcmd_line.display_info >= 1 ) {
        printf("\n************************************************\n");
        printf("\n*  mul-fip: multiple purpose planning          *\n");
        printf("\n************************************************\n");
    }

    set_global_variables_for_multiple_purpose();

    ftime(&start);
    update_reachability_analysis_for_multiple_purpose ();
    ftime(&end);
    TIME( gadd_reach_time );

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: update_reachability_analysis_for_multiple_purpose() finished\n");
    }

    ftime(&start);
    update_relevant_facts_for_multiple_purpose ();
    ftime(&end);
    TIME( gadd_relev_time );

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: update_relevant_facts_for_multiple_purpose() finished\n");
    }

    ftime(&start);
    update_connectivity_graph_for_multiple_purpose();
    ftime(&end);
    TIME( gadd_conn_time );

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: update_connectivity_graph_for_multiple_purpose() finished\n");
    }

    compute_goal_agenda_for_multiple_purpose ();

    if ( gcmd_line.display_info >= 1 ) {
        printf("\nDebugInfo: compute_goal_agenda_for_multiple_purpose() finished\n");
    }

    for ( i = 0; i < MAX_PLAN_LENGTH + 1; i++ ) {
        make_state( &(gadd_plan_states[i]), gnum_ft_conn );
        gadd_plan_states[i].max_F = gnum_ft_conn;
    }

    source_to_dest( &current_end, &(gadd_goal_agenda[0]) );

    for ( i = 0; i < gadd_num_goal_agenda; i++ ) {
        /* JC add a hashtable creating in do_enforced_hill_climbling*/
        if ( !do_enforced_hill_climbing_for_multiple_purpose ( &current_start, &current_end ) ) {
            break;
        }
        source_to_dest( &current_start, &(gplan_states[gnum_plan_ops]) );
        if ( i < gnum_goal_agenda - 1 ) {
            for ( j = 0; j < ggoal_agenda[i+1].num_F; j++ ) {
                current_end.F[current_end.num_F++] = ggoal_agenda[i+1].F[j];
            }
        }
    }

    found_plan_for_multiple_purpose = ( i == gadd_num_goal_agenda ) ? TRUE : FALSE;



    if ( !found_plan_for_multiple_purpose ) {
        printf("\n\nEnforced Hill-climbing failed !");
        printf("\nswitching to Best-first Search now.\n");
        reset_ff_states_for_multiple_purpose();
        found_plan_for_multiple_purpose = do_best_first_search_for_multiple_purpose();
    }

    if ( gcmd_line.display_info >= 1 ) {
        printf("\n************************************************\n");
        printf("\n*  mul-fip: fip plan finished for multiple goal. *\n");
        printf("\n************************************************\n");
    }

    print_plan();

    if ( !found_plan_for_multiple_purpose ) {
        /*print_plan();*/
        /* D action add to group */
        build_action_group();

        gfipPlan.num_sons = 0;
        gfipPlan.action = -1;

        print_plan();

        /*put the ultimate goal to the solved set*/
        StateActionPair *g = new_StateActionPair();
        make_state(&g->state, gnum_ft_conn);
        g->state.max_F = gnum_ft_conn;
        source_to_dest(&g->state, &ggoal_state);
        g->state.num_L = 1;
        g->state.L[0] = 10000000; /*make it the biggest*/
        add_solved_state(g);
        /*ugly, but work*/

        convert_ff_plan_to_fip_plan( &gfipPlan );

        solve_unsolved_states();

        if(!gsolved_states) {
            printf("No solutions are found! The problem is unsolvable.\n");
            exit(0);
        } else if(g_is_strong) {
            StateActionPair *ptr = gsolved_states;
            Bool valid = FALSE;
            while(ptr) {
                if(ptr->state.num_L == 1 && ptr->state.L[0] == 1) {
                    valid = TRUE;
                    break;
                }
                ptr = ptr->next;
            }
            if(!valid) {
                printf("The initial state is a dead-end! The problem is unsolvable.\n");
                exit(0);
            }
        }

        printf("##########################################\n");
        printf("#####   PROCEDURE-LIKE CODE   ############\n");
        printf("##########################################\n");
        /* print_fip_plan_1( is_solved_state(&ginitial_state) , &gfipPlan, 1); */

        /* times( &end ); */
        ftime(&end);
        TIME( gsearch_time );

        /* myend = clock(); */
        ftime(&myend);

        /* printf("my cac is %7.3f\n", 1.0*(myend.millitm - mystart.millitm)/1000.0); */
        print_fip_plan_2();

        if(to_print_state)
            print_all_states();
        /* print_fip_plan_3( &gfipPlan, 0 ); */
    }
    /*****************************************************************************************/

    output_planner_info();

    printf("\n\n");
    exit( 0 );

}