⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pddl-types.c

📁 intel ipp4.1性能库的一些例子。
💻 C
📖 第 1 页 / 共 2 页
字号:
   */  for ( i = 0; i < lnum_types; i++ ) {    lnum_either_ty[i] = 0;  }  for ( tyl = gparse_types; tyl; tyl = tyl->next ) {    make_either_ty( tyl );  }  for ( tyl = gparse_constants; tyl; tyl = tyl->next ) {    make_either_ty( tyl );  }  for ( tyl = gparse_objects; tyl; tyl = tyl->next ) {    make_either_ty( tyl );  }  for ( tyll = gparse_predicates; tyll; tyll = tyll->next ) {    for ( tyl = tyll->args; tyl; tyl = tyl->next ) {      make_either_ty( tyl );    }  }  make_either_ty_in_pl( gorig_goal_facts );  for ( po = gloaded_ops; po; po = po->next ) {    make_either_ty_in_pl( po->preconds );    make_either_ty_in_pl( po->effects );    for ( tyl = po->parse_params; tyl; tyl = tyl->next ) {      make_either_ty( tyl );    }  }  /* now, compute the transitive closure of all type inclusions.   * first initialize the matrix.   */  for ( i = 0; i < lnum_types; i++ ) {    for ( j = 0; j < lnum_types; j++ ) {      m[i][j] = ( i == j ? TRUE : FALSE );    }  }  std = -1;  for ( i = 0; i < lnum_types; i++ ) {    if ( strcmp( ltype_names[i], STANDARD_TYPE ) == SAME ) {      std = i;      break;    }  }  for ( i = 0; i < lnum_types; i++ ) {    m[i][std] = TRUE;/* all types are subtypes of OBJECT */  }  for ( tyl = gparse_types; tyl; tyl = tyl->next ) {    /* all inclusions as are defined in domain file     */    m[my_get_type( tyl->name )][tyl->n] = TRUE;  }  /* compute transitive closure on inclusions matrix   */  for ( j = 0; j < lnum_types; j++ ) {    for ( i = 0; i < lnum_types; i++ ) {      if ( m[i][j] ) {	for ( k = 0; k < lnum_types; k++ ) {	  if ( m[j][k] ) {	    m[i][k] = TRUE;	  }	}      }    }  }  /* union types are subsets of all those types that contain all   * their components, and    * all component types are subsets of the either type !   */  for ( i = 0; i < lnum_types; i++ ) {    if ( lnum_either_ty[i] < 2 ) continue;    for ( j = 0; j < lnum_types; j++ ) {      if ( j == i ) continue;      /* get supertypes of all component types       */      for ( k = 0; k < lnum_either_ty[i]; k++ ) {	if ( !m[leither_ty[i][k]][j] ) break;      }      if ( k < lnum_either_ty[i] ) continue;      m[i][j] = TRUE;      /* make components subtypes of either type       */      for ( k = 0; k < lnum_either_ty[i]; k++ ) {	m[leither_ty[i][k]][i] = TRUE;      }    }  }  /* and again, compute transitive closure on inclusions matrix.   * I guess, this won't change anything (?), but it also won't need   * any remarkable computation time, so why should one think about it ?   */  for ( j = 0; j < lnum_types; j++ ) {    for ( i = 0; i < lnum_types; i++ ) {      if ( m[i][j] ) {	for ( k = 0; k < lnum_types; k++ ) {	  if ( m[j][k] ) {	    m[i][k] = TRUE;	  }	}      }    }  }    /* now build FactList of ALL  constant -> type   pairs.   * for each constant / object, let it appear separately   * for each type it is a member of; compute type   * membership based on propagating constants / objects   * through inclusions matrix.   *   * this might make the same pair appear doubly, if an object   * is declared in type T as well as in some supertype T'.   * such cases will be filtered out in string collection.   */  for ( tyl = gparse_constants; tyl; tyl = tyl->next ) {    fl = new_fact_list();    fl->item = new_token_list();    fl->item->next = new_token_list();    fl->item->item = copy_Token( tyl->name );    if ( tyl->type->next ) {      fl->item->next->item = new_token( MAX_LENGTH );      strcpy( fl->item->next->item, EITHER_STR );      for ( tl = tyl->type; tl; tl = tl->next ) {	strcat( fl->item->next->item, CONNECTOR );	strcat( fl->item->next->item, tl->item );      }    } else {      fl->item->next->item = copy_Token( tyl->type->item );    }    fl->next = gorig_constant_list;    gorig_constant_list = fl;    /* now add constant to all supertypes     */    n = my_get_type( fl->item->next->item );    for ( i = 0; i < lnum_types; i++ ) {      if ( i == n ||	   !m[n][i] ) continue;      fl = new_fact_list();      fl->item = new_token_list();      fl->item->next = new_token_list();      fl->item->item = copy_Token( tyl->name );      fl->item->next->item = copy_Token( ltype_names[i] );      fl->next = gorig_constant_list;      gorig_constant_list = fl;    }  }  for ( tyl = gparse_objects; tyl; tyl = tyl->next ) {    fl = new_fact_list();    fl->item = new_token_list();    fl->item->next = new_token_list();    fl->item->item = copy_Token( tyl->name );    if ( tyl->type->next ) {      fl->item->next->item = new_token( MAX_LENGTH );      strcpy( fl->item->next->item, EITHER_STR );      for ( tl = tyl->type; tl; tl = tl->next ) {	strcat( fl->item->next->item, CONNECTOR );	strcat( fl->item->next->item, tl->item );      }    } else {      fl->item->next->item = copy_Token( tyl->type->item );    }    fl->next = gorig_constant_list;    gorig_constant_list = fl;    /* now add constant to all supertypes     */    n = my_get_type( fl->item->next->item );    for ( i = 0; i < lnum_types; i++ ) {      if ( i == n ||	   !m[n][i] ) continue;      fl = new_fact_list();      fl->item = new_token_list();      fl->item->next = new_token_list();      fl->item->item = copy_Token( tyl->name );      fl->item->next->item = copy_Token( ltype_names[i] );      fl->next = gorig_constant_list;      gorig_constant_list = fl;    }  }  /* now, normalize all typed-list-of  s in domain and problem def,   * i.e., in all PlNode quantifiers and in op parameters   *   * at the same time, remove typed-listof structures in these defs   */  normalize_tyl_in_pl( &gorig_goal_facts );  for ( po = gloaded_ops; po; po = po->next ) {    normalize_tyl_in_pl( &po->preconds );    normalize_tyl_in_pl( &po->effects );    /* be careful to maintain parameter ordering !     */    if ( !po->parse_params ) {      continue;/* no params at all */    }    fl = new_fact_list();    fl->item = new_token_list();    fl->item->next = new_token_list();    fl->item->item = copy_Token( po->parse_params->name );    if ( po->parse_params->type->next ) {      fl->item->next->item = new_token( MAX_LENGTH );      strcpy( fl->item->next->item, EITHER_STR );      for ( tl = po->parse_params->type; tl; tl = tl->next ) {	strcat( fl->item->next->item, CONNECTOR );	strcat( fl->item->next->item, tl->item );      }    } else {      fl->item->next->item = copy_Token( po->parse_params->type->item );    }    po->params = fl;    p_fl = fl;    for ( tyl = po->parse_params->next; tyl; tyl = tyl->next ) {      fl = new_fact_list();      fl->item = new_token_list();      fl->item->next = new_token_list();      fl->item->item = copy_Token( tyl->name );      if ( tyl->type->next ) {	fl->item->next->item = new_token( MAX_LENGTH );	strcpy( fl->item->next->item, EITHER_STR );	for ( tl = tyl->type; tl; tl = tl->next ) {	  strcat( fl->item->next->item, CONNECTOR );	  strcat( fl->item->next->item, tl->item );	}      } else {	fl->item->next->item = copy_Token( tyl->type->item );      }      p_fl->next = fl;      p_fl = fl;    }    free_TypedList( po->parse_params );    po->parse_params = NULL;  }  /* finally, build  gpredicates_and_types  by chaining predicate names    * together with the names of their args' types.   */  for ( tyll = gparse_predicates; tyll; tyll = tyll->next ) {    fl = new_fact_list();    fl->item = new_token_list();    fl->item->item = copy_Token( tyll->predicate );    fl->next = gpredicates_and_types;    gpredicates_and_types = fl;    if ( !tyll->args ) continue;    /* add arg types; MAINTAIN ORDERING !     */    fl->item->next = new_token_list();    if ( tyll->args->type->next ) {      fl->item->next->item = new_token( MAX_LENGTH );      strcpy( fl->item->next->item, EITHER_STR );      for ( tl = tyll->args->type; tl; tl = tl->next ) {	strcat( fl->item->next->item, CONNECTOR );	strcat( fl->item->next->item, tl->item );      }    } else {      fl->item->next->item = copy_Token( tyll->args->type->item );    }    p_tl = fl->item->next;    for ( tyl = tyll->args->next; tyl; tyl = tyl->next ) {      tmp_tl = new_token_list();      if ( tyl->type->next ) {	tmp_tl->item = new_token( MAX_LENGTH );	strcpy( tmp_tl->item, EITHER_STR );	for ( tl = tyl->type; tl; tl = tl->next ) {	  strcat( tmp_tl->item, CONNECTOR );	  strcat( tmp_tl->item, tl->item );	}      } else {	tmp_tl->item = copy_Token( tyl->type->item );      }      p_tl->next = tmp_tl;      p_tl = tmp_tl;    }  }  /* now get rid of remaining typed-list-of parsing structures   */  free_TypedList( gparse_types );  gparse_types = NULL;  free_TypedList( gparse_constants );  gparse_constants = NULL;  free_TypedList( gparse_objects );  gparse_objects = NULL;  free_TypedListList( gparse_predicates );  gparse_predicates = NULL;}void collect_type_names_in_pl( PlNode *n ){  PlNode *i;  TypedList *tyl;  TokenList *tl;  char *tmp = NULL;  int nn;  if ( !n ) {    return;  }  switch( n->connective ) {  case ALL:  case EX:    for ( tyl = n->parse_vars; tyl; tyl = tyl->next ) {      if ( tyl->type->next ) {	tmp = new_token( MAX_LENGTH );	strcpy( tmp, EITHER_STR );	for ( tl = tyl->type; tl; tl = tl->next ) {	  strcat( tmp, CONNECTOR );	  strcat( tmp, tl->item );	}      } else {	tmp = copy_Token( tyl->type->item );      }      if ( (nn = my_get_type( tmp )) == -1 ) {	tyl->n = lnum_types;	ltype_names[lnum_types++] = copy_Token( tmp );      } else {	tyl->n = nn;      }      free( tmp );      tmp = NULL;    }    collect_type_names_in_pl( n->sons );    break;  case AND:  case OR:    for ( i = n->sons; i; i = i->next ) {      collect_type_names_in_pl( i );    }    break;  case NOT:    collect_type_names_in_pl( n->sons );    break;  case ATOM:  case TRU:  case FAL:    break;  case WHEN:    collect_type_names_in_pl( n->sons );    collect_type_names_in_pl( n->sons->next );    break;  default:    break;  }}int my_get_type( char *str ){  int i;  for ( i = 0; i < lnum_types; i++ ) {    if ( strcmp( str, ltype_names[i] ) == SAME ) return i;  }  return -1;}void make_either_ty( TypedList *tyl ){  TokenList *i;  if ( lnum_either_ty[tyl->n] > 0 ) {    return;  }  for ( i = tyl->type; i; i = i->next ) {    leither_ty[tyl->n][lnum_either_ty[tyl->n]++] = my_get_type( i->item );  }}void make_either_ty_in_pl( PlNode *n ){  PlNode *i;  TypedList *tyl;  if ( !n ) {    return;  }  switch( n->connective ) {  case ALL:  case EX:    for ( tyl = n->parse_vars; tyl; tyl = tyl->next ) {      make_either_ty( tyl );    }    make_either_ty_in_pl( n->sons );    break;  case AND:  case OR:    for ( i = n->sons; i; i = i->next ) {      make_either_ty_in_pl( i );    }    break;  case NOT:    make_either_ty_in_pl( n->sons );    break;  case ATOM:  case TRU:  case FAL:    break;  case WHEN:    make_either_ty_in_pl( n->sons );    make_either_ty_in_pl( n->sons->next );    break;  default:    break;  }}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_token_list();    tmp_tl->next = new_token_list();    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_token_list();      tmp_tl->next = new_token_list();      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_pl_node( (*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;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -