Example #1
0
Bool make_conjunction_of_literals( PlNode **n )

{

  PlNode *tmp, *i;

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

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

  for ( i = (*n)->sons; i; i = i->next ) {
    if ( i->connective == NOT ) {
      if ( !(i->sons) ||
	   i->sons->connective != ATOM ) {
	return FALSE;
      }
      continue;
    }
    if ( i->connective != ATOM ) {
      return FALSE;
    }
  }

  return TRUE;

}
Example #2
0
Bool make_conjunction_of_atoms( PlNode **n )

{

  PlNode *tmp, *i;

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

  if ( (*n)->connective != AND ) {
    if ( (*n)->connective != ATOM ) {
      return FALSE;
    }
    tmp = new_PlNode( ATOM );
    tmp->atom = (*n)->atom;
    (*n)->atom = NULL;
    (*n)->connective = AND;
    (*n)->sons = tmp;
    return TRUE;
  }

  for ( i = (*n)->sons; i; i = i->next ) {
    if ( i->connective != ATOM ) {
      return FALSE;
    }
  }

  return TRUE;

}
Example #3
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;

}
Example #4
0
Bool make_initial_conjunction( PlNode **n )

{

  PlNode *tmp, *i, *result, *nn;
  int orcount = 0, oneofcount = 0, multicount = 0;

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

  /* if single entry, for simplicity turn that into AND
   */
  if ( (*n)->connective != AND ) {
    tmp = new_PlNode( AND );
    tmp->sons = (*n);
  }

  /* check through, and count nr of implications
   */
  for ( i = (*n)->sons; i; i = i->next ) {
    switch ( i->connective ) {
    case ATOM:
    case UNKNOWN:
      break;
    case OR:
      orcount++;
      break;
    case ONEOF:
      oneofcount++;
      break;
    case MULTI:
      multicount++;
      break;
    default:
      return FALSE;
    }
  }

  gorig_initial_ors = ( PlNode_pointer * ) calloc( orcount, sizeof( PlNode_pointer ) );
  gorig_initial_oneofs = ( PlNode_pointer * ) calloc( oneofcount, sizeof( PlNode_pointer ) );
  gorig_initial_multis = ( PlNode_pointer * ) calloc( multicount, sizeof( PlNode_pointer ) );

  /* now split the list up.
   */
  result = new_PlNode( AND );
  i = (*n)->sons;
  orcount = 0;
  oneofcount = 0;
  multicount = 0;
  while ( i ) {
    switch ( i->connective ) {
    case ATOM:
    case UNKNOWN:
      nn = i->next;
      i->next = result->sons;
      result->sons = i;
      i = nn;
      break;
    case OR:
      nn = i->next;
      gorig_initial_ors[orcount++] = i;
      i->next = NULL;
      i = nn;
      break;
    case ONEOF:
      nn = i->next;
      gorig_initial_oneofs[oneofcount++] = i;
      i->next = NULL;
      i = nn;
      break;
    case MULTI:
      nn = i->next;
      gorig_initial_multis[multicount++] = i;
      i->next = NULL;
      i = nn;
      break;
    default:
      return FALSE;
    }
  }

  *n = result;
  gnum_orig_initial_ors = orcount;
  gnum_orig_initial_oneofs = oneofcount;
  gnum_orig_initial_multis = multicount;

  return TRUE;

}
Example #5
0
Bool make_adl_domain( void )

{

  PlOperator *i;
  FactList *ff;
  int j;

  if ( gcmd_line.display_info == 101 ) {
    printf("\noriginal problem parsing is:\n");
    printf("\nobjects:");
    for ( ff = gorig_constant_list; ff; ff = ff->next ) {
      printf("\n%s : %s", ff->item->item, ff->item->next->item);
    }
    printf("\n\ninitial state:\n");
    print_PlNode( gorig_initial_facts, 0 );
    printf("\n\ngoal state:\n");
    print_PlNode( gorig_goal_facts, 0 );
    printf("\n\nops:");
    print_plops( gloaded_ops );
  }

  if ( !make_initial_conjunction( &gorig_initial_facts ) ) {
    printf("\nillegal initial state");
    return FALSE;
  } else {
    if ( gcmd_line.display_info == 101 ) {
      printf("\n\norig parse split up initial state, facts:\n");
      print_PlNode( gorig_initial_facts, 0 );
      printf("\n\norig parse split up initial state, ors:\n");
      for ( j = 0; j < gnum_orig_initial_ors; j++ ) {
	print_PlNode( gorig_initial_ors[j], 0 );
      }
      printf("\n\norig parse split up initial state, oneofs:\n");
      for ( j = 0; j < gnum_orig_initial_oneofs; j++ ) {
	print_PlNode( gorig_initial_oneofs[j], 0 );
      }
      printf("\n\norig parse split up initial state, multis:\n");
      for ( j = 0; j < gnum_orig_initial_multis; j++ ) {
	print_PlNode( gorig_initial_multis[j], 0 );
      }
    }
  }

  if ( !gorig_goal_facts ) {
    gorig_goal_facts = new_PlNode( TRU );
  }

  if ( !is_wff( gorig_goal_facts ) ) {
    printf("\nillegal goal formula");
    print_PlNode( gorig_goal_facts, 0 );
    return FALSE;
  }

  for ( i = gloaded_ops; i; i = i->next ) {
    if ( !i->preconds ) {
      i->preconds = new_PlNode( TRU );
    }
    if ( !is_wff( i->preconds ) ) {
      printf("\nop %s has illegal precondition", i->name);
      return FALSE;
    }
    if ( !make_effects( &(i->effects) ) ) {
      printf("\nop %s has illegal effects", i->name);
      return FALSE;
    }
  }

  if ( gcmd_line.display_info == 102 ) {
    printf("\nfinal ADL representation is:\n");
    printf("\nobjects:");
    for ( ff = gorig_constant_list; ff; ff = ff->next ) {
      printf("\n%s : %s", ff->item->item, ff->item->next->item);
    }
    printf("\n\ninitial state:\n");
    print_PlNode( gorig_initial_facts, 0 );
    printf("\ninitial state, ors:\n");
    for ( j = 0; j < gnum_orig_initial_ors; j++ ) {
      print_PlNode( gorig_initial_ors[j], 0 );
    }
    printf("\ninitial state, oneofs:\n");
    for ( j = 0; j < gnum_orig_initial_oneofs; j++ ) {
      print_PlNode( gorig_initial_oneofs[j], 0 );
    }
    printf("\ninitial state, multis:\n");
    for ( j = 0; j < gnum_orig_initial_multis; j++ ) {
      print_PlNode( gorig_initial_multis[j], 0 );
    }
    printf("\n\ngoal formula:\n");
    print_PlNode( gorig_goal_facts, 0 );
    printf("\n\nops:");
    print_plops( gloaded_ops );
  }

  return TRUE;
      
}
Example #6
0
void normalize_tyl_in_pl( PlNode **n )

{

  PlNode *i;
  TypedList *tyl;
  PlNode *tmp_pl = NULL, *sons, *p_pl;
  TokenList *tmp_tl, *tl;


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

  switch( (*n)->connective ) {
  case ALL:
  case EX:
    /* we need to make a sequence of quantifiers ( ->sons ...)
     * out of the given sequence of TypedList  elements,
     * with connected type names, var - name in TokenList
     * and KEEPING THE SAME ORDERING !!
     */
    if ( !(*n)->parse_vars ) {
      printf("\n\nquantifier without argument !! check input files.\n\n");
      exit( 1 );
    }
    tmp_tl = new_TokenList();
    tmp_tl->next = new_TokenList();
    tmp_tl->item = copy_Token( (*n)->parse_vars->name );
    if ( (*n)->parse_vars->type->next ) {
      tmp_tl->next->item = new_Token( MAX_LENGTH );
      strcpy( tmp_tl->next->item, EITHER_STR );
      for ( tl = (*n)->parse_vars->type; tl; tl = tl->next ) {
	strcat( tmp_tl->next->item, CONNECTOR );
	strcat( tmp_tl->next->item, tl->item );
      }
    } else {
      tmp_tl->next->item = copy_Token( (*n)->parse_vars->type->item );
    }
    (*n)->atom = tmp_tl;
    /* now add list of sons
     */
    sons = (*n)->sons;
    p_pl = *n;
    for ( tyl = (*n)->parse_vars->next; tyl; tyl = tyl->next ) {
      tmp_tl = new_TokenList();
      tmp_tl->next = new_TokenList();
      tmp_tl->item = copy_Token( tyl->name );
      if ( tyl->type->next ) {
	tmp_tl->next->item = new_Token( MAX_LENGTH );
	strcpy( tmp_tl->next->item, EITHER_STR );
	for ( tl = tyl->type; tl; tl = tl->next ) {
	  strcat( tmp_tl->next->item, CONNECTOR );
	  strcat( tmp_tl->next->item, tl->item );
	}
      } else {
	tmp_tl->next->item = copy_Token( tyl->type->item );
      }
      tmp_pl = new_PlNode( (*n)->connective );
      tmp_pl->atom = tmp_tl;
      p_pl->sons = tmp_pl;
      p_pl = tmp_pl;
    }
    /* remove typed-list-of info
     */
    free_TypedList( (*n)->parse_vars );
    (*n)->parse_vars = NULL;
    /* the last son in list takes over ->sons
     */
    p_pl->sons = sons;
    /* normalize this sons and get out
     */
    normalize_tyl_in_pl( &(p_pl->sons) );
    break;
  case AND:
  case OR:
    for ( i = (*n)->sons; i; i = i->next ) {
      normalize_tyl_in_pl( &i );
    }
    break;
  case NOT:
    normalize_tyl_in_pl( &((*n)->sons) );
    break;
  case ATOM:
  case TRU:
  case FAL:
    break;
  case WHEN:
    normalize_tyl_in_pl( &((*n)->sons) );
    normalize_tyl_in_pl( &((*n)->sons->next) );
    break;
  default:
    break;
  }

}
Example #7
0
Bool make_effects( PlNode **n )

{

  PlNode *tmp, *i, *literals, *j, *k, *next;
  int m = 0;

  if ( (*n)->connective != AND ) {
    if ( !is_eff_literal( *n ) &&
	 (*n)->connective != ALL &&
	 (*n)->connective != WHEN ) {
      return FALSE;
    }
    tmp = new_PlNode( (*n)->connective );
    tmp->atom = (*n)->atom;
    tmp->sons = (*n)->sons;
    /* july06
     */
    if ( (*n)->connective == WHEN ) {
      tmp->eff_p = (*n)->eff_p;
      (*n)->eff_p = -1;/* unnecessary, just for consistency */
    }
    (*n)->connective = AND;
    (*n)->sons = tmp;
  }

  for ( i = (*n)->sons; i; i = i->next ) {
    if ( is_eff_literal( i ) ) {
      m++;
      continue;
    }
    if ( i->connective == AND ) {
      for ( j = i->sons; j; j = j->next ) {
	if ( !is_eff_literal( j ) ) {
	  return FALSE;
	}
	m++;
      }
      continue;
    }
    if ( i->connective == ALL ) {
      for ( j = i->sons; j && j->connective == ALL; j = j->sons ) {
	if ( !j->atom ||
	     !j->atom->next ||
	     j->atom->next->next != NULL ) {
	  return FALSE;
	}
      }
      if ( !j ) {
	return FALSE;
      }
      if ( is_eff_literal( j ) ) {
	tmp = new_PlNode( AND );
	for ( k = i; k->sons->connective == ALL; k = k->sons );
	k->sons = tmp;
	tmp->sons = j;
	j = tmp;
      }
      if ( j->connective == AND ) {
	for ( k = j->sons; k; k = k->next ) {
	  if ( !is_eff_literal( k ) ) {
	    return FALSE;
	  }
	}
	tmp = new_PlNode( WHEN );
	tmp->eff_p = 1.0;
	for ( k = i; k->sons->connective == ALL; k = k->sons );
	k->sons = tmp;
	tmp->sons = new_PlNode( TRU );
	tmp->sons->next = j;
	continue;
      }
      if ( j->connective != WHEN ) {
	return FALSE;
      }
      if ( !(j->sons) ) {
	j->sons = new_PlNode( TRU );
      }
      if ( !is_wff( j->sons ) ) {
	return FALSE;
      }
      if ( !make_conjunction_of_literals( &(j->sons->next) ) ) {
	return FALSE;
      }
      continue;
    }
    if ( i->connective != WHEN ) {
      return FALSE;
    }
    if ( !(i->sons) ) {
      i->sons = new_PlNode( TRU );
    }
    if ( !is_wff( i->sons ) ) {
      return FALSE;
    }
    if ( !make_conjunction_of_literals( &(i->sons->next) ) ) {
      return FALSE;
    }
  }

  if ( m == 0 ) {
    return TRUE;
  }

  tmp = new_PlNode( WHEN );
  tmp->eff_p = 1.0;
  tmp->sons = new_PlNode( TRU );
  literals = new_PlNode( AND );
  tmp->sons->next = literals;
  tmp->next = (*n)->sons;
  (*n)->sons = tmp;
  i = (*n)->sons;
  while ( i->next ) {
    if ( is_eff_literal( i->next ) ) {
      next = i->next->next;
      i->next->next = literals->sons;
      literals->sons = i->next;
      i->next = next;
      continue;
    }
    if ( i->next->connective == AND ) {
      next = i->next->next;
      for ( j = i->next->sons; j && j->next; j = j->next );
      if ( j ) {
	j->next = literals->sons;
	literals->sons = i->next->sons;
      }
      i->next = next;
      continue;
    }
    i = i->next;
  }
  return TRUE;

}