Пример #1
0
Bool make_conjunction_of_atoms( PlNode **n )

{

  PlNode *tmp, *i, *p, *m;

  if ( !(*n) ) {
    return TRUE;
  }

  if ( (*n)->connective != AND ) {
    switch ( (*n)->connective ) {
    case ATOM:
      tmp = new_PlNode( ATOM );
      tmp->atom = (*n)->atom;
      (*n)->atom = NULL;
      (*n)->connective = AND;
      (*n)->sons = tmp;
      return TRUE;
    case NOT:
      free_PlNode( *n );
      (*n) = NULL;
      return TRUE; 
    default:
      return FALSE;
    }
  }

  p = NULL;
  i = (*n)->sons;
  while ( i ) {
    switch ( i->connective ) {
    case ATOM:
      p = i;
      i = i->next;
      break;
    case NOT:
      if ( p ) {
	p->next = i->next;
      } else {
	(*n)->sons = i->next;
      }
      m = i->next;
      i->next = NULL;
      free_PlNode( i );
      i = m;
      break;
    default:
      return FALSE;
    }
  }

  return TRUE;

}
Пример #2
0
void free_PlNode( PlNode *node )

{
  
  if ( node ) {
    free_PlNode( node->sons );
    free_PlNode( node->next );
    free_TokenList( node->atom );
    free( node );
  }

}
Пример #3
0
void free_PlOperator( PlOperator *o )

{

  if ( o ) {
    free_PlOperator( o->next );

    if ( o->name ) {
      free( o->name );
    }
    
    free_FactList( o->params );
    free_PlNode( o->preconds );
    free_PlNode( o->effects );

    free( o );
  }

}
Пример #4
0
void create_integer_representation( void )

{

  PlNode *n;
  PlOperator *o;
  Operator *tmp;
  FactList *ff;
  int type_num, i;

  if ( gorig_initial_facts ) {
    for ( n = gorig_initial_facts->sons; n; n = n->next ) {
      if ( gnum_full_initial == MAX_INITIAL ) {
	printf("\ntoo many initial facts! increase MAX_INITIAL (currently %d)\n\n",
	       MAX_INITIAL);
	exit( 1 );
      }
      make_Fact( &(gfull_initial[gnum_full_initial]), n, NULL );
      if ( gfull_initial[gnum_full_initial].predicate == -1 ) {
	printf("\nequality in initial state! check input files.\n\n");
	exit( 1 );
      }
      gnum_full_initial++;
    }
    free_PlNode( gorig_initial_facts );
  }

  if ( gorig_goal_facts ) {
    for ( n = gorig_goal_facts->sons; n; n = n->next ) {
      if ( gnum_goal == MAX_STATE ) {
	printf("\ntoo many goal facts! increase MAX_STATE (currently %d)\n\n",
	       MAX_STATE);
	exit( 1 );
      }
      make_Fact( &(ggoal[gnum_goal]), n, NULL );
      if ( ggoal[gnum_goal].predicate == -1 ) {
	printf("\nequality in goal state! check input files.\n\n");
	exit( 1 );
      }
      gnum_goal++;
    }
    free_PlNode( gorig_goal_facts );
  }

  for ( i = 0; i < MAX_TYPES; i++ ) {
    gpredicate_to_type[i] = -1;
    gnum_intersected_types[i] = -1;
  }

  for ( o = gloaded_ops; o; o = o->next ) {
    tmp = new_Operator( o->name, o->number_of_real_params );

    for ( ff = o->params; ff; ff = ff->next ) {
      if ( (type_num = position_in_types_table( ff->item->next->item )) == -1 ) {
	printf("\nwarning: parameter %s of op %s has unknown or empty type. skipping op",
	       ff->item->item, ff->item->next->item);
	break;
      }
      if ( tmp->num_vars == MAX_VARS ) {
	printf("\ntoo many parameters! increase MAX_VARS (currently %d)\n\n",
	       MAX_VARS);
	exit( 1 );
      }
      tmp->var_names[tmp->num_vars] = ff->item->item; 
      tmp->var_types[tmp->num_vars++] = type_num;
    }
    if ( ff ) {
      free_Operator( tmp );
      continue;
    }

    if ( o->preconds ) {
      for ( n = o->preconds->sons; n; n = n->next ) {
	if ( tmp->num_preconds == MAX_OP_P ) {
	  printf("\ntoo many preconds! increase MAX_OP_P (currently %d)\n\n",
		 MAX_OP_P);
	  exit( 1 );
	}
	make_Fact( &((tmp->preconds)[tmp->num_preconds]), n, tmp );
	tmp->num_preconds++;
      }
    }

    if ( o->effects ) {
      for ( n = o->effects->sons; n; n = n->next ) {
	if ( n->connective == ATOM ) {
	  if ( tmp->num_adds == MAX_OP_A ) {
	    printf("\ntoo many added facts! increase MAX_OP_A (currently %d)\n\n",
		   MAX_OP_A);
	    exit( 1 );
	  }
	  make_Fact( &((tmp->adds)[tmp->num_adds]), n, tmp );
	  if ( (tmp->adds)[tmp->num_adds].predicate == -1 ) {
	    printf("\nequality in effect of op %s! check input files.\n\n",
		   o->name);
	    exit( 1 );
	  }
	  tmp->num_adds++;
	} else {/* n->connective == NOT */
	  if ( tmp->num_dels == MAX_OP_D ) {
	    printf("\ntoo many deleted facts! increase MAX_OP_D (currently %d)\n\n",
		   MAX_OP_D);
	    exit( 1 );
	  }
	  make_Fact( &((tmp->dels)[tmp->num_dels]), n->sons, tmp );
	  if ( (tmp->dels)[tmp->num_dels].predicate == -1 ) {
	    printf("\nequality in effect of op %s! check input files.\n\n",
		   o->name);
	    exit( 1 );
	  }
	  tmp->num_dels++;
	}
      }
    }

    if ( gnum_operators == MAX_OPERATORS ) {
      printf("\ntoo many operators! increase MAX_OPERATORS (currently %d)\n\n",
	     MAX_OPERATORS);
      exit( 1 );
    }
    goperators[gnum_operators++] = tmp;
  }

  free_PlOperator( gloaded_ops );

}