示例#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, 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 );

}
示例#2
0
void print_fixpoint_result( void )

{

  int time, i;
  Bool hit, hit_F, hit_E;

  time = 0;
  while ( 1 ) {
    hit = FALSE;
    hit_F = FALSE;
    hit_E = FALSE;
    for ( i = 0; i < gnum_ft_conn; i++ ) {
      if ( gft_conn[i].level == time ) {
	hit = TRUE;
	hit_F = TRUE;
	break;
      }
    }
    for ( i = 0; i < gnum_ef_conn; i++ ) {
      if ( gef_conn[i].level == time ) {
	hit = TRUE;
	hit_E = TRUE;
	break;
      }
    }
    if ( !hit ) {
      break;
    }
 
    printf("\n\nLEVEL %d:", time);
    if ( hit_F ) {
      printf("\n\nFACTS:");
      for ( i = 0; i < gnum_ft_conn; i++ ) {
	if ( gft_conn[i].level == time ) {
	  printf("\n");
	  print_ft_name( i );
	}
      }
    }
    if ( hit_E ) {
      printf("\n\nEFS:");
      for ( i = 0; i < gnum_ef_conn; i++ ) {
	if ( gef_conn[i].level == time ) {
	  printf("\neffect %d to ", i);
	  print_op_name( gef_conn[i].op );
	}
      }
    }

    time++;
  }
  fflush( stdout );

}
示例#3
0
void print_plan( void )

{  

  int i;

  printf("\n\nff: found legal plan as follows");
  printf("\n\nstep ");
  for ( i = 0; i < gnum_plan_ops; i++ ) {
    printf("%4d: ", i);
    print_op_name( gplan_ops[i] );
    printf("\n     ");
  }

}
示例#4
0
void print_plan( void )

{  

  int i;
  float cost = 0.0;

  printf("\n\nff: found legal plan (steps: %d) as follows", gnum_plan_ops);
  printf("\n\nstep ");
  for ( i = 0; i < gnum_plan_ops; i++ ) {
    printf("%4d: ", i);
    print_op_name( gplan_ops[i] );
    if(gop_conn[gplan_ops[i]].num_E != 1) {
      printf(" -- MULTI-EFFECT OP! -- ");
    }
    else {
      cost += get_cost(gop_conn[gplan_ops[i]].E[0]);
      printf(" (%f) ", get_cost(gop_conn[gplan_ops[i]].E[0]) );
      if(artificial_gtt) {
	printf("(+1 artificial)");
      }
      /*
      switch( get_action_type(gplan_ops[i]) ) {

      case SG_AT_COLLECT_REWARD:
	printf( " - reward");
	break;
      case SG_AT_FOREGO_REWARD:
	printf( " - forego");
	break;
      case SG_AT_OTHER:
	printf( " - other");
	break;
      }
      */
    }
    printf("\n     ");
  }
  printf( "\n\tTotal cost of plan: %f ", cost);
}
示例#5
0
void print_plan( void )

{  

  int i;
  float cost = 0;

  printf("\n\nff: found legal plan as follows");
  printf("\nstep ");
  for ( i = 0; i < gnum_plan_ops; i++ ) {
    printf("%4d: ", i);
    print_op_name( gplan_ops[i] );
    if ( i < gnum_plan_ops-1 ) {
      printf("\n     ");
    }
    if ( goptimization_established ) {
      cost += gop_conn[gplan_ops[i]].cost;
    }
  }
  if ( goptimization_established ) {
    printf("\nplan cost: %f", cost);
  }

}
示例#6
0
void collect_H_info( void )

{

  static Bool first_call = TRUE;
  static int *H, num_H, *D;
  int i, j, k, ft, ef, op, d;

  if ( first_call ) {
    gH = ( int * ) calloc( gnum_op_conn, sizeof( int ) );
    H = ( int * ) calloc( gnum_op_conn, sizeof( int ) );
    D = ( int * ) calloc( gnum_op_conn, sizeof( int ) );
    gnum_H = 0;
    num_H = 0;
    first_call = FALSE;
  }

  for ( i = 0; i < gnum_H; i++ ) {
    gop_conn[gH[i]].is_in_H = FALSE;
  }

  num_H = 0;
  for ( i = 0; i < lnum_goals_at[1]; i++ ) {
    ft = lgoals_at[1][i];

    for ( j = 0; j < gft_conn[ft].num_A; j++ ) {
      ef = gft_conn[ft].A[j];
      if ( gef_conn[ef].level != 0 ) {
	continue;
      }
      op = gef_conn[ef].op;

      if ( gop_conn[op].is_in_H ) {
	continue;
      }
      gop_conn[op].is_in_H = TRUE;
      H[num_H++] = op;
    }
  }

  /* H collected; now order it
   * here: count number of goal- and subgoal facts that
   *       op deletes (with level 0 effects). order less deletes
   *       before more deletes.
   *       start from back of H, to prefer down under
   *       goals to upper goals.
   */
  gnum_H = 0;
  for ( i = num_H - 1; i > -1; i-- ) {
    d = 0;
    for ( j = 0; j < gop_conn[H[i]].num_E; j++ ) {
      ef = gop_conn[H[i]].E[j];
      if ( gef_conn[ef].level != 0 ) continue;
      for ( k = 0; k < gef_conn[ef].num_D; k++ ) {
	if ( gft_conn[gef_conn[ef].D[k]].is_goal ) d++;
      }
    }
    for ( j = 0; j < gnum_H; j++ ) {
      if ( D[j] > d ) break;
    }
    for ( k = gnum_H; k > j; k-- ) {
      gH[k] = gH[k-1];
      D[k] = D[k-1];
    }
    gH[j] = H[i];
    D[j] = d;
    gnum_H++;
  }
  if ( gcmd_line.display_info == 124 ) {
    printf("\ncollected H: ");
    for ( i = 0; i < gnum_H; i++ ) {
      print_op_name( gH[i] );
      printf("\n              ");
    }
  }

}
示例#7
0
void achieve_goals( int time )

{

  int i, j, k, ft, min_p, min_e, ef, p, op;

  if ( gcmd_line.display_info == 123 ) {
    printf("\nselecting at step %3d: ", time-1);
  }

  for ( i = 0; i < lnum_goals_at[time]; i++ ) {
    ft = lgoals_at[time][i];

    if ( gft_conn[ft].is_true == time ) {
      /* fact already added by prev now selected op
       */
      continue;
    }

    min_p = INFINITY;
    min_e = -1;
    for ( j = 0; j < gft_conn[ft].num_A; j++ ) {
      ef = gft_conn[ft].A[j];
      if ( gef_conn[ef].level != time - 1 ) continue; 
      p = 0;
      for ( k = 0; k < gef_conn[ef].num_PC; k++ ) {
	p += gft_conn[gef_conn[ef].PC[k]].level;
      }
      if ( LESS( p, min_p ) ) {
	min_p = p;
	min_e = ef;
      }
    }
    ef = min_e;
    if ( !gef_conn[ef].in_plan ) {
      gef_conn[ef].in_plan = TRUE;
      gin_plan_E[gnum_in_plan_E++] = ef;
    }

    op = gef_conn[ef].op;
    if ( gop_conn[op].is_used != time ) {
      gop_conn[op].is_used = time;
      lused_O[lnum_used_O++] = op;
      if ( gcmd_line.display_info == 123 ) {
	print_op_name( op );
	printf("\n                       ");
      }
    }

    for ( j = 0; j < gef_conn[ef].num_PC; j++ ) {
      ft = gef_conn[ef].PC[j];
      if ( gft_conn[ft].is_true == time ) {
	/* a prev at this level selected op accidently adds this precond, 
	 * so we can order that op before this one and get the precond added for free.
	 */
	continue;
      }
      if ( gft_conn[ft].is_goal ) {
	/* this fact already is a goal
	 */
	continue;
      }
      lgoals_at[gft_conn[ft].level][lnum_goals_at[gft_conn[ft].level]++] = ft;
      gft_conn[ft].is_goal = TRUE;
      if ( !gft_conn[ft].ch ) {
	lch_F[lnum_ch_F++] = ft;
	gft_conn[ft].ch = TRUE;
      }
    }

    for ( j = 0; j < gef_conn[ef].num_A; j++ ) {
      ft = gef_conn[ef].A[j];
      gft_conn[ft].is_true = time;
      if ( !gft_conn[ft].ch ) {
	lch_F[lnum_ch_F++] = ft;
	gft_conn[ft].ch = TRUE;
      }
    }
    for ( j = 0; j < gef_conn[ef].num_I; j++ ) {
      for ( k = 0; k < gef_conn[gef_conn[ef].I[j]].num_A; k++ ) {
	ft = gef_conn[gef_conn[ef].I[j]].A[k];
	gft_conn[ft].is_true = time;
	if ( !gft_conn[ft].ch ) {
	  lch_F[lnum_ch_F++] = ft;
	  gft_conn[ft].ch = TRUE;
	}
      }
    }
  }

}
示例#8
0
void build_connectivity_graph( void )

{

  int i, j, k, l, n_op, n_ef, m, na, nd;
  Action *a;
  int *same_effects, sn;
  Bool *had_effects;
  ActionEffect *e, *e_;


/*
 * DEA - University of Brescia
 */
  //  struct timeb tp;

  int tmpnum;
  int sizeofgop, sizeofgef, sizeofgft;

  sizeofgop = 0;
  sizeofgef = 0;
  sizeofgft = 0;

  //  ftime( &tp );
  //  srandom( tp.millitm );

  srandom(seed);

/*
 * End of DEA
 */


  gnum_ft_conn = gnum_relevant_facts;
/*
 * DEA - University of Brescia
 */
  gnum_ft_block = gnum_ft_conn / 32 + 1;
/*
 * End of DEA
 */
  gnum_op_conn = gnum_actions;
  gft_conn = ( FtConn * ) calloc( gnum_ft_conn, sizeof( FtConn ) );
  gop_conn = ( OpConn * ) calloc( gnum_op_conn, sizeof( OpConn ) );
  gef_conn = ( EfConn * ) calloc( lnum_effects, sizeof( EfConn ) );
  gnum_ef_conn = 0;

  same_effects = ( int * ) calloc( lnum_effects, sizeof( int ) );
  had_effects = ( Bool * ) calloc( lnum_effects, sizeof( Bool ) );

  for ( i = 0; i < gnum_ft_conn; i++ ) {
    gft_conn[i].num_PC = 0;
    gft_conn[i].num_A = 0;
    gft_conn[i].num_D = 0;

/*
 * DEA - University of Brescia
 */
    // gft_conn[i].rand = random () % BIG_INT;
   gft_conn[i].rand = MY_RANDOM % BIG_INT;
/*
 * End of DEA
 */
  }

  for ( i = 0; i < gnum_op_conn; i++ ) {
    gop_conn[i].num_E = 0;
  }

  for ( i = 0; i < gnum_ef_conn; i++ ) {
    gef_conn[i].num_PC = 0;
    gef_conn[i].num_A = 0;
    gef_conn[i].num_D = 0;
    gef_conn[i].num_I = 0;
  }


  n_op = 0;
  n_ef = 0;
  for ( a = gactions; a; a = a->next ) {

    gop_conn[n_op].action = a;

    gop_conn[n_op].E = ( int * ) calloc( a->num_effects, sizeof( int ) );
    for ( i = 0; i < a->num_effects; i++ ) {
      had_effects[i] = FALSE;
    }
    for ( i = 0; i < a->num_effects; i++ ) {
      if ( had_effects[i] ) {
	continue;
      }
      had_effects[i] = TRUE;
      e = &(a->effects[i]);
      gop_conn[n_op].E[gop_conn[n_op].num_E++] = n_ef;
      gef_conn[n_ef].op = n_op;

      sn = 0;
      for ( j = i + 1; j < a->num_effects; j++ ) {
	if ( had_effects[j] ) {
	  continue;
	}
	e_ = &(a->effects[j]);
	/* check conditions
	 */
	for ( k = 0; k < e_->num_conditions; k++ ) {
	  for ( l = 0; l < e->num_conditions; l++ ) {
	    if ( e_->conditions[k] == e->conditions[l] ) {
	      break;
	    }
	  }
	  if ( l == e->num_conditions ) {
	    break;
	  }
	}
	if ( k < e_->num_conditions ) {
	  continue;
	}
	if ( e->num_conditions == e_->num_conditions ) {
	  same_effects[sn++] = j;
	}
      }

      na = e->num_adds;
      nd = e->num_dels;
      for ( j = 0; j < sn; j++ ) {
	na += a->effects[same_effects[j]].num_adds;
	nd += a->effects[same_effects[j]].num_dels;
      }
/*
 * DEA - University of Brescia
 */
      tmpnum = get_num_of_effects_of (n_ef, AT_END_TIME, 1);
      //      gef_conn[n_ef].A = (int *) calloc (na, sizeof (int));
      gef_conn[n_ef].A = ( int * ) calloc( na + tmpnum, sizeof( int ) );

      tmpnum = get_num_of_effects_of (n_ef, AT_START_TIME, 1);
      if (tmpnum)
	gef_conn[n_ef].sf->A_start = (int *) calloc (tmpnum, sizeof (int));
      /*cancellanti */
      tmpnum = get_num_of_effects_of (n_ef, AT_START_TIME, 0);
      if (tmpnum)
	gef_conn[n_ef].sf->D_start =(int *) calloc (tmpnum, sizeof (int));
/*
 * End of DEA
 */
      gef_conn[n_ef].D = ( int * ) calloc( nd, sizeof( int ) );
      for ( j = 0; j < e->num_adds; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_A; k++ ) {
	  if ( gef_conn[n_ef].A[k] == e->adds[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_A ) continue;
	gef_conn[n_ef].A[gef_conn[n_ef].num_A++] = e->adds[j];
      }
      for ( j = 0; j < e->num_dels; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_D; k++ ) {
	  if ( gef_conn[n_ef].D[k] == e->dels[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_D ) continue;
	gef_conn[n_ef].D[gef_conn[n_ef].num_D++] = e->dels[j];
      }
      for ( j = 0; j < sn; j++ ) {
	e_ = &(a->effects[same_effects[j]]);
	for ( l = 0; l < e_->num_adds; l++ ) {
	  for ( k = 0; k < gef_conn[n_ef].num_A; k++ ) {
	    if ( gef_conn[n_ef].A[k] == e_->adds[l] ) break;
	  }
	  if ( k < gef_conn[n_ef].num_A ) continue;
	  gef_conn[n_ef].A[gef_conn[n_ef].num_A++] = e_->adds[l];
	}
	for ( l = 0; l < e_->num_dels; l++ ) {
	  for ( k = 0; k < gef_conn[n_ef].num_D; k++ ) {
	    if ( gef_conn[n_ef].D[k] == e_->dels[l] ) break;
	  }
	  if ( k < gef_conn[n_ef].num_D ) continue;
	  gef_conn[n_ef].D[gef_conn[n_ef].num_D++] = e_->dels[l];
	}
      }
      a->effects[i].ef_conn_pos = n_ef;
      for ( j = 0; j < sn; j++ ) {
	had_effects[same_effects[j]] = TRUE;
	a->effects[same_effects[j]].ef_conn_pos = n_ef;
      }

/*
 * DEA - University of Brescia
 */
      tmpnum = get_num_of_preconds_of(n_ef,AT_START_TIME);

      // gef_conn[n_ef].PC = (int *) calloc (e->num_conditions + a->num_preconds, sizeof (int));
      gef_conn[n_ef].PC = ( int * ) calloc( e->num_conditions + a->num_preconds + tmpnum, sizeof( int ) );

      /*alloco lo spazio anche per le condizioni overall */
      tmpnum = get_num_of_preconds_of (n_ef, OVER_ALL_TIME);
      if (tmpnum)
	gef_conn[n_ef].sf->PC_overall = (int *) calloc (tmpnum, sizeof (int));
      /*alloco lo spazio anche per le condizioni at end */
      tmpnum = get_num_of_preconds_of (n_ef, AT_END_TIME);
      if (tmpnum)
	gef_conn[n_ef].sf->PC_end = (int *) calloc (tmpnum, sizeof (int));
/*
 * End of DEA
 */
      for ( j = 0; j < a->num_preconds; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_PC; k++ ) {
	  if ( gef_conn[n_ef].PC[k] == a->preconds[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_PC ) continue;
	gef_conn[n_ef].PC[gef_conn[n_ef].num_PC++] = a->preconds[j];
      }
      for ( j = 0; j < e->num_conditions; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_PC; k++ ) {
	  if ( gef_conn[n_ef].PC[k] == e->conditions[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_PC ) continue;
	gef_conn[n_ef].PC[gef_conn[n_ef].num_PC++] = e->conditions[j];
      }
      
      n_ef++;
      gnum_ef_conn++;
    }/* ende all a->effects */


    /* setup implied effects info
     */
    if ( a->num_effects > 1 ) {
      m = 0;
      for ( i = a->effects[0].ef_conn_pos; i < n_ef - 1; i++ ) {
	for ( j = i+1; j < n_ef; j++ ) {
	  /* i ==> j ? */
	  for ( k = 0; k < gef_conn[j].num_PC; k++ ) {
	    for ( l = 0; l < gef_conn[i].num_PC; l++ ) {
	      if ( gef_conn[i].PC[l] == gef_conn[j].PC[k] ) break;
	    }
	    if ( l == gef_conn[i].num_PC ) break;
	  }
	  if ( k == gef_conn[j].num_PC ) {
	    gef_conn[i].num_I++;
	  }
	  /* j ==> i ? */
	  for ( k = 0; k < gef_conn[i].num_PC; k++ ) {
	    for ( l = 0; l < gef_conn[j].num_PC; l++ ) {
	      if ( gef_conn[j].PC[l] == gef_conn[i].PC[k] ) break;
	    }
	    if ( l == gef_conn[j].num_PC ) break;
	  }
	  if ( k == gef_conn[i].num_PC ) {
	    gef_conn[j].num_I++;
	  }
	}
      }
      for ( i = a->effects[0].ef_conn_pos; i < n_ef; i++ ) {
	gef_conn[i].I = ( int * ) calloc( gef_conn[i].num_I, sizeof( int ) );
	gef_conn[i].num_I = 0;
      }    
      for ( i = a->effects[0].ef_conn_pos; i < n_ef - 1; i++ ) {
	for ( j = i+1; j < n_ef; j++ ) {
	  /* i ==> j ? */
	  for ( k = 0; k < gef_conn[j].num_PC; k++ ) {
	    for ( l = 0; l < gef_conn[i].num_PC; l++ ) {
	      if ( gef_conn[i].PC[l] == gef_conn[j].PC[k] ) break;
	    }
	    if ( l == gef_conn[i].num_PC ) break;
	  }
	  if ( k == gef_conn[j].num_PC ) {
	    gef_conn[i].I[gef_conn[i].num_I++] = j;
	  }
	  /* j ==> i ? */
	  for ( k = 0; k < gef_conn[i].num_PC; k++ ) {
	    for ( l = 0; l < gef_conn[j].num_PC; l++ ) {
	      if ( gef_conn[j].PC[l] == gef_conn[i].PC[k] ) break;
	    }
	    if ( l == gef_conn[j].num_PC ) break;
	  }
	  if ( k == gef_conn[i].num_PC ) {
	    gef_conn[j].I[gef_conn[j].num_I++] = i;
	  }
	}
      }
    }

    /* first sweep: only count the space we need for the fact arrays !
     */
    if ( a->num_effects > 0 ) {
      for ( i = a->effects[0].ef_conn_pos; i < n_ef; i++ ) {
	for ( j = 0; j < gef_conn[i].num_PC; j++ ) {
	  gft_conn[gef_conn[i].PC[j]].num_PC++;
	}
 	for ( j = 0; j < gef_conn[i].num_A; j++ ) {
	  gft_conn[gef_conn[i].A[j]].num_A++;
	}
	for ( j = 0; j < gef_conn[i].num_D; j++ ) {
	  gft_conn[gef_conn[i].D[j]].num_D++;
	}
      }
    }

    n_op++;
  }

  for ( i = 0; i < gnum_ft_conn; i++ ) {
    gft_conn[i].PC = ( int * ) calloc( gft_conn[i].num_PC, sizeof( int ) );
    gft_conn[i].num_PC = 0;
    gft_conn[i].A = ( int * ) calloc( gft_conn[i].num_A, sizeof( int ) );
    gft_conn[i].num_A = 0;
    gft_conn[i].D = ( int * ) calloc( gft_conn[i].num_D, sizeof( int ) );
    gft_conn[i].num_D = 0;

    gft_conn[i].is_global_goal = FALSE;
  }

  for ( i = 0; i < ggoal_state.num_F; i++ ) {
    gft_conn[ggoal_state.F[i]].is_global_goal = TRUE;
  }

  for ( i = 0; i < gnum_ef_conn; i++ ) {
    for ( j = 0; j < gef_conn[i].num_PC; j++ ) {
      gft_conn[gef_conn[i].PC[j]].PC[gft_conn[gef_conn[i].PC[j]].num_PC++] = i;
    }
    for ( j = 0; j < gef_conn[i].num_A; j++ ) {
      gft_conn[gef_conn[i].A[j]].A[gft_conn[gef_conn[i].A[j]].num_A++] = i;
    }
    for ( j = 0; j < gef_conn[i].num_D; j++ ) {
      gft_conn[gef_conn[i].D[j]].D[gft_conn[gef_conn[i].D[j]].num_D++] = i;
    }
  }

  free( same_effects );
  free( had_effects );

  if ( gcmd_line.display_info == 121) {
    printf("\n\ncreated connectivity graph as follows:");

    printf("\n\n------------------OP ARRAY:-----------------------");
    for ( i = 0; i < gnum_op_conn; i++ ) {
/*
 * DEA - University of Brescia
 */
      sizeofgop += sizeof (gop_conn[i]) + sizeof (int) * (gop_conn[i].num_E - 1);
/*
 * End of DEA
 */
      printf("\n\nOP: ");
      print_op_name( i );
      printf("\n----------EFFS:");
      for ( j = 0; j < gop_conn[i].num_E; j++ ) {
	printf("\neffect %d", gop_conn[i].E[j]);
      }
/*
 * DEA - University of Brescia
 */
	  printf ("\nSIZE = %d", sizeof (gop_conn[i]) + sizeof (int) * (gop_conn[i].num_E - 1));
/*
 * End of DEA
 */
    }
    
    printf("\n\n-------------------EFFECT ARRAY:----------------------");
    for ( i = 0; i < gnum_ef_conn; i++ ) {
/*
 * DEA - University of Brescia
 */
      sizeofgef += sizeof (gef_conn[i]) + sizeof (int) * (gef_conn[i].num_PC - 1) +
	sizeof (int) * (gef_conn[i].num_A - 1) + sizeof (int) * (gef_conn[i].num_D - 1);
/*
 * End of DEA
 */
      printf("\n\neffect %d of op %d: ", i, gef_conn[i].op);
      print_op_name( gef_conn[i].op );
      printf("\n----------PCS:");
      for ( j = 0; j < gef_conn[i].num_PC; j++ ) {
	printf("\n");
	print_ft_name( gef_conn[i].PC[j] );
      }
      printf("\n----------ADDS:");
      for ( j = 0; j < gef_conn[i].num_A; j++ ) {
	printf("\n");
	print_ft_name( gef_conn[i].A[j] );
      }
      printf("\n----------DELS:");
      for ( j = 0; j < gef_conn[i].num_D; j++ ) {
	printf("\n");
	print_ft_name( gef_conn[i].D[j] );
      }
      printf("\n----------IMPLIEDS:");
      for ( j = 0; j < gef_conn[i].num_I; j++ ) {
	printf("\nimplied effect %d of op %d: ", 
	       gef_conn[i].I[j], gef_conn[gef_conn[i].I[j]].op);
	print_op_name( gef_conn[gef_conn[i].I[j]].op );
      }
    }
    
    printf("\n\n----------------------FT ARRAY:-----------------------------");
    for ( i = 0; i < gnum_ft_conn; i++ ) {
/*
 * DEA - University of Brescia
 */
      sizeofgft += sizeof (gft_conn[i]) + sizeof (int) * (gft_conn[i].num_PC - 1) +
	sizeof (int) * (gft_conn[i].num_A - 1) + sizeof (int) * (gft_conn[i].num_D - 1);
      //      printf("\n\nFT: ");
      printf ("\n ----------------- \n\n %d FT: ", i);
/*
 * End of DEA
 */
      print_ft_name( i );
      printf(" rand: %d", gft_conn[i].rand);
      printf("\n----------PRE COND OF:");
      for ( j = 0; j < gft_conn[i].num_PC; j++ ) {
	printf("\neffect %d", gft_conn[i].PC[j]);
      }
      printf("\n----------ADD BY:");
      for ( j = 0; j < gft_conn[i].num_A; j++ ) {
	printf("\neffect %d", gft_conn[i].A[j]);
      }
      printf("\n----------DEL BY:");
      for ( j = 0; j < gft_conn[i].num_D; j++ ) {
	printf("\neffect %d", gft_conn[i].D[j]);
      }
/*
 * DEA - University of Brescia
 */
      printf ("\nSIZE= %d", sizeof (gft_conn[i]) + sizeof (int) * (gft_conn[i].num_PC - 1) +
	      sizeof (int) * (gft_conn[i].num_A - 1) + sizeof (int) * (gft_conn[i].num_D - 1));
/*
 * End of DEA
 */
    }
  }
/*
 * DEA - University of Brescia
 */
  gnum_ef_block = gnum_ef_conn / 32 + 1;
  
  for (i = 0; i < gnum_ft_conn; i++)
    gft_conn[i].position = i;

  for (i = 0; i < gnum_ef_conn; i++)
    gef_conn[i].position = i;
  
  
  if (DEBUG0)
    {
      
    //  printf ("Number of actions   : %7d", gnum_ef_conn);
    //  printf ("\nNumber of facts     : %7d", gnum_ft_conn);
   //   fflush(stdout);
    }
  
  if (gcmd_line.display_info == 121)
    {
      printf ("\nDim. azioni    (gop_conn): %7d", sizeofgop);
      printf ("\nDim. 'effetti' (gef_conn): %7d", sizeofgef);
      printf ("\nDim. fatti     (gft_conn): %7d", sizeofgft);
    }
 /*
 * End of DEA
 */
   
}
示例#9
0
void build_connectivity_graph( void )

{

  int i, j, n;
  Action *a;

  struct timeb tp;

  ftime( &tp );
  srandom( tp.millitm );

  gnum_ft_conn = gnum_relevant_facts;
  gnum_op_conn = gnum_actions;
  gft_conn = ( FtConn * ) calloc( gnum_ft_conn, sizeof( FtConn ) );
  gop_conn = ( OpConn * ) calloc( gnum_op_conn, sizeof( OpConn ) );

  for ( i = 0; i < gnum_ft_conn; i++ ) {
    gft_conn[i].num_P = 0;
    gft_conn[i].num_A = 0;
    gft_conn[i].num_D = 0;

    gft_conn[i].rand = random() % STATE_HASH_SIZE;
  }

  for ( i = 0; i < gnum_op_conn; i++ ) {
    gop_conn[i].num_P = 0;
    gop_conn[i].num_A = 0;
    gop_conn[i].num_D = 0;
  }

  n = 0;
  for ( a = gactions; a; a = a->next ) {

    /* ops are simply copied over. a waste of time and memory,
     * but, usually there are not so many actions after
     * the fixpoint. can speed that up for optimization, but
     * keep it the clean and tidy way for the time being.
     */
    gop_conn[n].op = a->op;
    for ( i = 0; i < goperators[a->op]->num_vars; i++ ) {
      gop_conn[n].inst_table[i] = a->inst_table[i];
    }

    gop_conn[n].P = ( int * ) calloc( a->num_preconds, sizeof( int ) );
    for ( i = 0; i < a->num_preconds; i++ ) {
      gop_conn[n].P[i] = a->preconds[i];
    }
    gop_conn[n].num_P = a->num_preconds;

    gop_conn[n].A = ( int * ) calloc( a->num_adds, sizeof( int ) );
    for ( i = 0; i < a->num_adds; i++ ) {
      gop_conn[n].A[i] = a->adds[i];
    }
    gop_conn[n].num_A = a->num_adds;

    gop_conn[n].D = ( int * ) calloc( a->num_dels, sizeof( int ) );
    for ( i = 0; i < a->num_dels; i++ ) {
      gop_conn[n].D[i] = a->dels[i];
    }
    gop_conn[n].num_D = a->num_dels;


    /* first sweep: only count the space we need for the fact arrays !
     */
    for ( i = 0; i < a->num_preconds; i++ ) {
      gft_conn[a->preconds[i]].num_P++;
    }
    for ( i = 0; i < a->num_adds; i++ ) {
      gft_conn[a->adds[i]].num_A++;
    }
    for ( i = 0; i < a->num_dels; i++ ) {
      gft_conn[a->dels[i]].num_D++;
    }

    n++;
  }

  for ( i = 0; i < gnum_ft_conn; i++ ) {
    gft_conn[i].P = ( int * ) calloc( gft_conn[i].num_P, sizeof( int ) );
    gft_conn[i].num_P = 0;
    gft_conn[i].A = ( int * ) calloc( gft_conn[i].num_A, sizeof( int ) );
    gft_conn[i].num_A = 0;
    gft_conn[i].D = ( int * ) calloc( gft_conn[i].num_D, sizeof( int ) );
    gft_conn[i].num_D = 0;
  }

  n = 0;
  for ( a = gactions; a; a = a->next ) {
    /* second sweep: now put the op numbers into the arrays
     */
    for ( i = 0; i < a->num_preconds; i++ ) {
      gft_conn[a->preconds[i]].P[gft_conn[a->preconds[i]].num_P++] = n;
    }
    for ( i = 0; i < a->num_adds; i++ ) {
      gft_conn[a->adds[i]].A[gft_conn[a->adds[i]].num_A++] = n;
    }
    for ( i = 0; i < a->num_dels; i++ ) {
      gft_conn[a->dels[i]].D[gft_conn[a->dels[i]].num_D++] = n;
    }
    n++;
  }


  if ( gcmd_line.display_info == 111 ) {
    printf("\n\ncreated connectivity graph as follows:");

    printf("\n\nOP ARRAY:");
    for ( i = 0; i < gnum_op_conn; i++ ) {
      printf("\n\nOP: ");
      print_op_name( i );
      printf("\n----------PRES:");
      for ( j = 0; j < gop_conn[i].num_P; j++ ) {
	printf("\n");
	print_ft_name( gop_conn[i].P[j] );
      }
      printf("\n----------ADDS:");
      for ( j = 0; j < gop_conn[i].num_A; j++ ) {
	printf("\n");
	print_ft_name( gop_conn[i].A[j] );
      }
      printf("\n----------DELS:");
      for ( j = 0; j < gop_conn[i].num_D; j++ ) {
	printf("\n");
	print_ft_name( gop_conn[i].D[j] );
      }
    }
    
    printf("\n\nFT ARRAY:");
    for ( i = 0; i < gnum_ft_conn; i++ ) {
      printf("\n\nFT: ");
      print_ft_name( i );
      printf("\n----------PRE OF:");
      for ( j = 0; j < gft_conn[i].num_P; j++ ) {
	printf("\n");
	print_op_name( gft_conn[i].P[j] );
      }
      printf("\n----------ADD BY:");
      for ( j = 0; j < gft_conn[i].num_A; j++ ) {
	printf("\n");
	print_op_name( gft_conn[i].A[j] );
      }
      printf("\n----------DEL BY:");
      for ( j = 0; j < gft_conn[i].num_D; j++ ) {
	printf("\n");
	print_op_name( gft_conn[i].D[j] );
      }
    }
  }
    
}
示例#10
0
void manual_control( void )

{

  static Bool fc = TRUE;
  static State S;

  int i, j, h, choice;
  BfsNode *tmp, *curr;

  if ( fc ) {
    make_state( &S, gnum_ft_conn );
    fc = FALSE;
  }

  tmp = new_BfsNode();
  copy_source_to_dest( &(tmp->S), &ginitial_state );
  tmp->op = -1;
  curr = tmp;
  if ( gcmd_line.dominating ) {
    hash_bfs_node( curr );
  }

  while ( TRUE ) {
    if ( !curr ) break;
    h = get_1P_and_H( &(curr->S), &ggoal_state, NULL, curr->father, curr->op );
    get_A( &(curr->S) );

    while ( TRUE ) {
      printf("\n\n\n-------------state h = %d", h);
      if ( h > 0 ) printf(" (resp. %d actions)", h - 1);
      printf(", info level %d, %d applicable actions", gcmd_line.debug, gnum_A);
      if ( gcmd_line.debug >= 1 ) {
	print_state( curr->S );
      }
      if ( 0 ) {
	printf("\nH:"); 
	for ( i = 0; i < gnum_H; i++ ) {
	  printf(" ");
	  print_op_name( gH[i] );
	}
      }
      printf("\n"); 
      for ( i = 0; i < gnum_A; i++ ) {
	printf("\n%3d ", i); 
	for ( j = 0; j < gnum_H; j++ ) {
	  if ( gA[i] == gH[j] ) break;
	}
	if ( j < gnum_H ) {
	  printf("H: ");
	} else {
	  printf(" : ");
	}
	print_op_name( gA[i] );
      }
      printf("\n\n -1: retract last choice");
      printf("\n -2: set info level");
      printf("\n\nchoice: "); scanf("%d", &choice);
      if ( choice >= -2 && choice < gnum_A ) break;
    }
    
    if ( choice >= 0 ) {
      if ( !result_to_dest( &S, NULL, curr, gA[choice] ) ) {
	printf("\naction not applicable!");
	continue;
      }
      
      if ( gcmd_line.dominating && bfs_state_hashed( &S, curr, gA[choice] ) ) {
	printf("\nthis state is dominated!\n\n");
      }
      
      tmp = new_BfsNode();
      copy_source_to_dest( &(tmp->S), &S );
      tmp->father = curr;
      tmp->op = gA[choice];
      curr = tmp;
      
      if ( gcmd_line.dominating ) {
	hash_bfs_node( curr );
      }
      
      continue;
    }
    if ( choice == -1 ) {
      curr = curr->father;
      continue;
    }
    printf("\nlevel : "); scanf("%d", &gcmd_line.debug);
  }

}
示例#11
0
int
init_act_vect (FILE * fp, PlanAction ** plan_actions, int start_level)
{
  float start_time;
  char Str[MAX_LENGTH];
  char opname[MAX_LENGTH];
  char operands[MAX_ARITY][MAX_LENGTH];
  float duration;
  int num_operands = 0;
  int act_pos;
  int index_of_arg[MAX_ARITY];
  char *cStr, *ptchr;
  int i;
  int level = 0;
  Bool no_dur;

  printf ("\n Load input plan:\n");


  while (!feof (fp))
    {
      cStr = Str;
      fgets (cStr, MAX_LENGTH, fp);
      for (i = 0; i < MAX_LENGTH; i++)
	cStr[i] = toupper (cStr[i]);
      if ((cStr[0] == ';') || (cStr[0] == '\n') || (cStr[0] == '\0'))
	continue;
      num_operands = 0;

      start_time = extract_level (cStr);
      cStr = strchr (cStr, ':');

      if (cStr == NULL)
	continue;
      cStr++;


      while (TRUE)
	{
	  if ((cStr[0] == '(') || (cStr[0] == ' '))
	    {
	      cStr++;
	      continue;
	    }
	  if (cStr[0] == '\0')
	    {
	      printf ("init_act_vect: opname not found (not even '(' )\n");
	      exit (1);
	    }
	  break;
	}

      sscanf (cStr, "%s", opname);
      if (strlen (opname) == 0)
	{
	  printf ("init_act_vect: opname not found\n");
	  exit (1);
	}
      cStr += strlen (opname);

      while (TRUE)
	{
	  if (cStr[0] == ' ')
	    {
	      cStr++;
	      continue;
	    }
	  break;
	}

      while (TRUE)
	{
	  sscanf (cStr, "%s", operands[num_operands]);

	  for (i = 0; i < strlen (operands[num_operands]); i++)
	    if (operands[num_operands][i] == ')')
	      {
		operands[num_operands][i] = '\0';
		break;
	      }
	  if (strlen (operands[num_operands]) == 0)
	    {
	      printf ("init_act_vect: ')' not found\n");
	      exit (1);
	    }
	  index_of_arg[num_operands] =
	    get_index_of_constant (operands[num_operands]);
	  if (index_of_arg[num_operands] == -1)
	    {
	      printf ("\n\nArg not found in constants table!\n\n");
	      exit (1);
	    }
	  cStr += strlen (operands[num_operands]);
	  num_operands++;

	  while (TRUE)
	    {
	      if (cStr[0] == ' ')
		{
		  cStr++;
		  continue;
		}
	      break;
	    }
	  if (cStr[0] == ')')
	    break;
	}

      no_dur = FALSE;
      while (TRUE)
	{
	  if (cStr[0] == '\0')
	    {
	      no_dur = TRUE;
	      break;
	    }
	  if (cStr[0] != '[')
	    {
	      cStr++;
	      continue;
	    }
	  break;
	}
      cStr++;
      for (ptchr = cStr;; ptchr++)
	{
	  if (ptchr[0] == ']')
	    {
	      ptchr[0] = '\0';
	      break;
	    }
	  if (ptchr[0] == '\0')
	    {
	      no_dur = TRUE;
	      break;
	    }
	}
      if (no_dur == TRUE)
	duration = 1;
      else
	duration = atof (cStr);

      act_pos = get_action_index (opname, index_of_arg);
      if (act_pos == -1)
	{
	  printf ("\n\naction not found in gef_conns\n\n");
	}
      if (act_pos != -1)
	{
	  store_action_vect (plan_actions, act_pos, start_time, duration);
	  level++;
	}
    }


  {
    PlanAction *p;
    printf ("\n");
    for (p = *plan_actions; p; p = p->next)
      {
	printf ("\n");
	printf ("%5.2f: (", p->start_time);
	print_op_name (p->act_pos);
	printf (") [%5.2f ]", p->duration);
      }
    printf ("\n\n");
  }

  return level;
}
示例#12
0
void build_connectivity_graph( void )

{

  int i, j, k, l, n_op, n_ef, na, nd, ef, ef_, m, l_;
  Action *a;
  int *same_effects, sn;
  Bool *had_effects;
  ActionEffect *e, *e_, *e__;

  struct timeb tp;

  ftime( &tp );
  srandom( tp.millitm );

  gnum_ft_conn = gnum_relevant_facts;
  gnum_op_conn = gnum_actions;
  gft_conn = ( FtConn * ) calloc( gnum_ft_conn, sizeof( FtConn ) );
  gop_conn = ( OpConn * ) calloc( gnum_op_conn, sizeof( OpConn ) );
  gef_conn = ( EfConn * ) calloc( lnum_effects, sizeof( EfConn ) );
  gnum_ef_conn = 0;

  same_effects = ( int * ) calloc( lnum_effects, sizeof( int ) );
  had_effects = ( Bool * ) calloc( lnum_effects, sizeof( Bool ) );

  for ( i = 0; i < gnum_ft_conn; i++ ) {
    gft_conn[i].num_PC = 0;
    gft_conn[i].num_A = 0;
    gft_conn[i].num_D = 0;

    gft_conn[i].rand = random() % BIG_INT;
  }

  for ( i = 0; i < gnum_op_conn; i++ ) {
    gop_conn[i].num_E = 0;
  }

  for ( i = 0; i < lnum_effects; i++ ) {
    gef_conn[i].num_PC = 0;
    gef_conn[i].num_A = 0;
    gef_conn[i].num_D = 0;
    gef_conn[i].num_I = 0;

    gef_conn[i].removed = FALSE;
  }


  n_op = 0;
  n_ef = 0;
  for ( a = gactions; a; a = a->next ) {

    gop_conn[n_op].action = a;

    gop_conn[n_op].E = ( int * ) calloc( a->num_effects, sizeof( int ) );
    for ( i = 0; i < a->num_effects; i++ ) {
      had_effects[i] = FALSE;
    }
    for ( i = 0; i < a->num_effects; i++ ) {
      if ( had_effects[i] ) {
	continue;
      }
      had_effects[i] = TRUE;
      e = &(a->effects[i]);
      gop_conn[n_op].E[gop_conn[n_op].num_E++] = n_ef;
      gef_conn[n_ef].op = n_op;

      gef_conn[n_ef].PC = ( int * ) 
	calloc( e->num_conditions + a->num_preconds, sizeof( int ) );
      for ( j = 0; j < a->num_preconds; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_PC; k++ ) {
	  if ( gef_conn[n_ef].PC[k] == a->preconds[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_PC ) continue;
	gef_conn[n_ef].PC[gef_conn[n_ef].num_PC++] = a->preconds[j];
      }
      for ( j = 0; j < e->num_conditions; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_PC; k++ ) {
	  if ( gef_conn[n_ef].PC[k] == e->conditions[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_PC ) continue;
	gef_conn[n_ef].PC[gef_conn[n_ef].num_PC++] = e->conditions[j];
      }

      sn = 0;
      for ( j = i + 1; j < a->num_effects; j++ ) {
	if ( had_effects[j] ) {
	  continue;
	}
	e_ = &(a->effects[j]);
	/* check conditions
	 */
	for ( k = 0; k < e_->num_conditions; k++ ) {
	  for ( l = 0; l < e->num_conditions; l++ ) {
	    if ( e_->conditions[k] == e->conditions[l] ) {
	      break;
	    }
	  }
	  if ( l == e->num_conditions ) {
	    break;
	  }
	}
	if ( k < e_->num_conditions ) {
	  continue;
	}
	if ( e->num_conditions == e_->num_conditions ) {
	  same_effects[sn++] = j;
	}
      }

      na = e->num_adds;
      nd = e->num_dels;
      for ( j = 0; j < sn; j++ ) {
	na += a->effects[same_effects[j]].num_adds;
	nd += a->effects[same_effects[j]].num_dels;
      }
      gef_conn[n_ef].A = ( int * ) calloc( na, sizeof( int ) );
      gef_conn[n_ef].D = ( int * ) calloc( nd, sizeof( int ) );
      for ( j = 0; j < e->num_adds; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_A; k++ ) {
	  if ( gef_conn[n_ef].A[k] == e->adds[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_A ) continue;
	/* exclude already true adds
	 */
	for ( k = 0; k < gef_conn[n_ef].num_PC; k++ ) {
	  if ( gef_conn[n_ef].PC[k] == e->adds[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_PC ) continue;
	gef_conn[n_ef].A[gef_conn[n_ef].num_A++] = e->adds[j];
      }
      for ( j = 0; j < e->num_dels; j++ ) {
	for ( k = 0; k < gef_conn[n_ef].num_D; k++ ) {
	  if ( gef_conn[n_ef].D[k] == e->dels[j] ) break;
	}
	if ( k < gef_conn[n_ef].num_D ) continue;
	/* exclude re-added dels; check against *all*
	 * adds to be integrated.
	 */
	for ( k = 0; k < e->num_adds; k++ ) {
	  if ( e->adds[k] == e->dels[j] ) break;
	}
	if ( k < e->num_adds ) continue;
	for ( l = 0; l < sn; l++ ) {
	  e_ = &(a->effects[same_effects[l]]);
	  for ( k = 0; k < e_->num_adds; k++ ) {
	    if ( e_->adds[k] == e->dels[j] ) break;
	  }
	  if ( k < e_->num_adds ) break;
	}
	if ( l < sn ) continue;
	gef_conn[n_ef].D[gef_conn[n_ef].num_D++] = e->dels[j];
      }
      for ( j = 0; j < sn; j++ ) {
	e_ = &(a->effects[same_effects[j]]);
	for ( l = 0; l < e_->num_adds; l++ ) {
	  for ( k = 0; k < gef_conn[n_ef].num_A; k++ ) {
	    if ( gef_conn[n_ef].A[k] == e_->adds[l] ) break;
	  }
	  if ( k < gef_conn[n_ef].num_A ) continue;
	  for ( k = 0; k < gef_conn[n_ef].num_PC; k++ ) {
	    if ( gef_conn[n_ef].PC[k] == e_->adds[l] ) break;
	  }
	  if ( k < gef_conn[n_ef].num_PC ) continue;
	  gef_conn[n_ef].A[gef_conn[n_ef].num_A++] = e_->adds[l];
	}
	for ( l = 0; l < e_->num_dels; l++ ) {
	  for ( k = 0; k < gef_conn[n_ef].num_D; k++ ) {
	    if ( gef_conn[n_ef].D[k] == e_->dels[l] ) break;
	  }
	  if ( k < gef_conn[n_ef].num_D ) continue;
	  /* exclude re-added dels; check against *all*
	   * adds to be integrated.
	   */
	  for ( k = 0; k < e->num_adds; k++ ) {
	    if ( e->adds[k] == e_->dels[l] ) break;
	  }
	  if ( k < e->num_adds ) continue;
	  for ( l_ = 0; l_ < sn; l_++ ) {
	    e__ = &(a->effects[same_effects[l_]]);
	    for ( k = 0; k < e__->num_adds; k++ ) {
	      if ( e__->adds[k] == e_->dels[l] ) break;
	    }
	    if ( k < e__->num_adds ) break;
	  }
	  if ( l_ < sn ) continue;
	  gef_conn[n_ef].D[gef_conn[n_ef].num_D++] = e_->dels[l];
	}
      }
      for ( j = 0; j < sn; j++ ) {
	had_effects[same_effects[j]] = TRUE;
      }
      
      n_ef++;
      gnum_ef_conn++;
    }/* ende all a->effects */


    if ( gop_conn[n_op].num_E >= 1 ) {
      /* CHECK EMPTY EFFECTS!
       *
       * two step process --- first, remove all effects that are entirely empty.
       *                      second, check if all remaining effects are illegal
       *                      or only delete:
       *                      in that case, the op will never do any good so we 
       *                      remove all its effects.
       */
      i = 0;
      while ( i < gop_conn[n_op].num_E ) {
	if ( gef_conn[gop_conn[n_op].E[i]].num_A != 0 ||
	     gef_conn[gop_conn[n_op].E[i]].num_D != 0 ) {
	  i++;
	  continue;
	}
	/* we keep it in the gef_conn (seems easier), 
	 * but mark it as removed, which will exclude it from everything.
	 */
	gef_conn[gop_conn[n_op].E[i]].removed = TRUE;
	for ( j = i; j < gop_conn[n_op].num_E - 1; j++ ) {
	  gop_conn[n_op].E[j] = gop_conn[n_op].E[j+1];
	}
	gop_conn[n_op].num_E--;
      }

      m = 0;
      for ( i = 0; i < gop_conn[n_op].num_E; i++ ) {
	if ( gef_conn[gop_conn[n_op].E[i]].num_A == 0 ) {
	  m++;
	}
      }
      if ( m == gop_conn[n_op].num_E ) {
	/* all remaining effects solely-deleters.
	 */
	for ( i = 0; i < gop_conn[n_op].num_E; i++ ) {
	  gef_conn[gop_conn[n_op].E[i]].removed = TRUE;
	}
	gop_conn[n_op].num_E = 0;
      }
    }

    /* setup implied effects info
     */
    if ( gop_conn[n_op].num_E > 1 ) {
      for ( i = 0; i < gop_conn[n_op].num_E; i++ ) {
	ef = gop_conn[n_op].E[i];
	gef_conn[ef].I = ( int * ) calloc( gop_conn[n_op].num_E, sizeof( int ) );
	gef_conn[ef].num_I = 0;
      }    
      for ( i = 0; i < gop_conn[n_op].num_E - 1; i++ ) {
	ef = gop_conn[n_op].E[i];
	for ( j = i+1; j < gop_conn[n_op].num_E; j++ ) {
	  ef_ = gop_conn[n_op].E[j];
	  /* ef ==> ef_ ? */
	  for ( k = 0; k < gef_conn[ef_].num_PC; k++ ) {
	    for ( l = 0; l < gef_conn[ef].num_PC; l++ ) {
	      if ( gef_conn[ef].PC[l] == gef_conn[ef_].PC[k] ) break;
	    }
	    if ( l == gef_conn[ef].num_PC ) break;
	  }
	  if ( k == gef_conn[ef_].num_PC ) {
	    gef_conn[ef].I[gef_conn[ef].num_I++] = ef_;
	  }
	  /* j ==> i ? */
	  for ( k = 0; k < gef_conn[ef].num_PC; k++ ) {
	    for ( l = 0; l < gef_conn[ef_].num_PC; l++ ) {
	      if ( gef_conn[ef_].PC[l] == gef_conn[ef].PC[k] ) break;
	    }
	    if ( l == gef_conn[ef_].num_PC ) break;
	  }
	  if ( k == gef_conn[ef].num_PC ) {
	    gef_conn[ef_].I[gef_conn[ef_].num_I++] = ef;
	  }
	}
      }
    }

    /* first sweep: only count the space we need for the fact arrays !
     */
    if ( gop_conn[n_op].num_E > 0 ) {
      for ( i = 0; i < gop_conn[n_op].num_E; i++ ) {
	ef = gop_conn[n_op].E[i];
	for ( j = 0; j < gef_conn[ef].num_PC; j++ ) {
	  gft_conn[gef_conn[ef].PC[j]].num_PC++;
	}
 	for ( j = 0; j < gef_conn[ef].num_A; j++ ) {
	  gft_conn[gef_conn[ef].A[j]].num_A++;
	}
	for ( j = 0; j < gef_conn[ef].num_D; j++ ) {
	  gft_conn[gef_conn[ef].D[j]].num_D++;
	}
      }
    }

    n_op++;
  }

  for ( i = 0; i < gnum_ft_conn; i++ ) {
    if ( gft_conn[i].num_PC > 0 ) {
      gft_conn[i].PC = ( int * ) calloc( gft_conn[i].num_PC, sizeof( int ) );
    }
    gft_conn[i].num_PC = 0;
    if ( gft_conn[i].num_A > 0 ) {
      gft_conn[i].A = ( int * ) calloc( gft_conn[i].num_A, sizeof( int ) );
    }
    gft_conn[i].num_A = 0;
    if ( gft_conn[i].num_D > 0 ) {
      gft_conn[i].D = ( int * ) calloc( gft_conn[i].num_D, sizeof( int ) );
    }
    gft_conn[i].num_D = 0;

    gft_conn[i].is_global_goal = FALSE;
  }
  for ( i = 0; i < ggoal_state.num_F; i++ ) {
    gft_conn[ggoal_state.F[i]].is_global_goal = TRUE;
  }

  for ( i = 0; i < gnum_ef_conn; i++ ) {
    if ( gef_conn[i].removed ) continue;
    for ( j = 0; j < gef_conn[i].num_PC; j++ ) {
      gft_conn[gef_conn[i].PC[j]].PC[gft_conn[gef_conn[i].PC[j]].num_PC++] = i;
    }
    for ( j = 0; j < gef_conn[i].num_A; j++ ) {
      gft_conn[gef_conn[i].A[j]].A[gft_conn[gef_conn[i].A[j]].num_A++] = i;
    }
    for ( j = 0; j < gef_conn[i].num_D; j++ ) {
      gft_conn[gef_conn[i].D[j]].D[gft_conn[gef_conn[i].D[j]].num_D++] = i;
    }
  }

  free( same_effects );
  free( had_effects );

  if ( gcmd_line.display_info == 121 ) {
    printf("\n\ncreated connectivity graph as follows:");

    printf("\n\n------------------OP ARRAY:-----------------------");
    for ( i = 0; i < gnum_op_conn; i++ ) {
      printf("\n\nOP: ");
      print_op_name( i );
      printf("\n----------EFFS:");
      for ( j = 0; j < gop_conn[i].num_E; j++ ) {
	printf("\neffect %d", gop_conn[i].E[j]);
      }
    }
    
    printf("\n\n-------------------EFFECT ARRAY:----------------------");
    for ( i = 0; i < gnum_ef_conn; i++ ) {
      printf("\n\neffect %d of op %d: ", i, gef_conn[i].op);
      print_op_name( gef_conn[i].op );
      if ( gef_conn[i].removed ) {
	printf(" --- REMOVED ");
	continue;
      }
      printf("\n----------PCS:");
      for ( j = 0; j < gef_conn[i].num_PC; j++ ) {
	printf("\n");
	print_ft_name( gef_conn[i].PC[j] );
      }
      printf("\n----------ADDS:");
      for ( j = 0; j < gef_conn[i].num_A; j++ ) {
	printf("\n");
	print_ft_name( gef_conn[i].A[j] );
      }
      printf("\n----------DELS:");
      for ( j = 0; j < gef_conn[i].num_D; j++ ) {
	printf("\n");
	print_ft_name( gef_conn[i].D[j] );
      }
      printf("\n----------IMPLIEDS:");
      for ( j = 0; j < gef_conn[i].num_I; j++ ) {
	printf("\nimplied effect %d of op %d: ", 
	       gef_conn[i].I[j], gef_conn[gef_conn[i].I[j]].op);
	print_op_name( gef_conn[gef_conn[i].I[j]].op );
      }
    }
    
    printf("\n\n----------------------FT ARRAY:-----------------------------");
    for ( i = 0; i < gnum_ft_conn; i++ ) {
      printf("\n\nFT: ");
      print_ft_name( i );
      printf(" rand: %d", gft_conn[i].rand);
      printf("\n----------PRE COND OF:");
      for ( j = 0; j < gft_conn[i].num_PC; j++ ) {
	printf("\neffect %d", gft_conn[i].PC[j]);
      }
      printf("\n----------ADD BY:");
      for ( j = 0; j < gft_conn[i].num_A; j++ ) {
	printf("\neffect %d", gft_conn[i].A[j]);
      }
      printf("\n----------DEL BY:");
      for ( j = 0; j < gft_conn[i].num_D; j++ ) {
	printf("\neffect %d", gft_conn[i].D[j]);
      }
    }
  }
    
}
示例#13
0
void achieve_goals( int time ) {
    
    int i, j, k, ft, min_p, min_e, ef, p, op;
    
    if ( gcmd_line.display_info == 123 ) {
        printf("\nselecting at step %3d: ", time-1);
    }
    
    for ( i = 0; i < lnum_goals_at[time]; i++ ) {
        ft = lgoals_at[time][i];
        
        if ( gft_conn[ft].is_true == time ) {
            /* fact already added by prev now selected op
             */
            continue;
        }
        
        min_p = INFINITY;
        min_e = -1;
        /* fact not been added by prev*/
        /* for each fact, get the minimal level of precondtion*/
        for ( j = 0; j < gft_conn[ft].num_A; j++ ) {
            ef = gft_conn[ft].A[j];
            if ( gef_conn[ef].level != time - 1 ) continue;
            p = 0;
            for ( k = 0; k < gef_conn[ef].num_PC; k++ ) {
                p += gft_conn[gef_conn[ef].PC[k]].level;
            }
            if ( LESS( p, min_p ) ) {
                min_p = p;
                min_e = ef;
            }
        }
        ef = min_e;
        if ( !gef_conn[ef].in_plan ) {
            gef_conn[ef].in_plan = TRUE;
            gin_plan_E[gnum_in_plan_E++] = ef;
        }
        
        op = gef_conn[ef].op;
        if ( gop_conn[op].is_used != time ) {
            if ( gop_conn[op].is_used == INFINITY ) {
                lused_O[lnum_used_O++] = op;
            }
            gop_conn[op].is_used = time;
            lh++;
            if ( gcmd_line.display_info == 123 ) {
                print_op_name( op );
                printf("\n                       ");
            }
        }
        
        for ( j = 0; j < gef_conn[ef].num_PC; j++ ) {
            ft = gef_conn[ef].PC[j];
            if ( gft_conn[ft].is_true == time ) {
                /* a prev at this level selected op accidently adds this precond,
                 * so we can order that op before this one and get the precond added for free.
                 */
                continue;
            }
            if ( gft_conn[ft].is_goal ) {
                /* this fact already is a goal
                 */
                continue;
            }
            lgoals_at[gft_conn[ft].level][lnum_goals_at[gft_conn[ft].level]++] = ft;
            gft_conn[ft].is_goal = TRUE;
            if ( !gft_conn[ft].ch ) {
                lch_F[lnum_ch_F++] = ft;
                gft_conn[ft].ch = TRUE;
            }
        }
        
        for ( j = 0; j < gef_conn[ef].num_A; j++ ) {
            ft = gef_conn[ef].A[j];
            gft_conn[ft].is_true = time;
            /* NOTE: one level below a goal will only be skipped if it's true value is time-1,
             * so subgoals introduced by prev selected ops are not excluded here.
             *
             * --- neither those of the at this level prev selected oned - which we want -
             * nor those of at prev levels selected ops - which we would want to be skipped.
             *
             * --- so the ordering consraints assumed are valid but don't explore
             * the full potential.
             */
            if ( !gft_conn[ft].ch ) {
                lch_F[lnum_ch_F++] = ft;
                gft_conn[ft].ch = TRUE;
            }
        }
        for ( j = 0; j < gef_conn[ef].num_I; j++ ) {
            for ( k = 0; k < gef_conn[gef_conn[ef].I[j]].num_A; k++ ) {
                ft = gef_conn[gef_conn[ef].I[j]].A[k];
                gft_conn[ft].is_true = time;
                if ( !gft_conn[ft].ch ) {
                    lch_F[lnum_ch_F++] = ft;
                    gft_conn[ft].ch = TRUE;
                }
            }
        }
    }
}
示例#14
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);
}