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

📄 instantiatei.c

📁 intel ipp4.1性能库的一些例子。
💻 C
📖 第 1 页 / 共 3 页
字号:
  value = 1;  for ( i = 0; i < n; i++ ) {    if ( args[i] >= 0 ) {      r += value;    }    value *= 2;  }  return r;}int max_unifying_tuples( int p, ArgArray args ){  int n = garity[p], i, r = 1;  for ( i = 0; i < n; i++ ) {    if ( args[i] < 0 ) {      r *= gtype_size[gpredicates_args_type[p][i]];    }  }  return r;}void free_predicate_tables( void ){  int i;  for ( i = 0; i < gpredicates_table_size; i++ ) {    free( gtuples[i] );  }}/* *  ----------------------- ENCODE UNARY INERTIA IN TYPES -------------------------- */CodeNode *ltmpI;void encode_unary_inertia_in_types( void ){  CodeOperator *o, *o2 = NULL, *o3;  Integers *tmp, *tt;  int i, l;  ArgArray a;  short int unary;  CodeNode *n, *nn, *jj, *next;  encode_unaries_under_CodeNode( &(gcode_goal_state) );  for ( o = gcode_operators; o; o = o->next ) {    encode_unaries_under_CodeNode( &(o->preconds) );    encode_unaries_under_CodeNode( &(o->conditionals) );  }  for ( o = gcode_operators; o; o = o->next ) {    /* normalize prefixes of conditional effects!     *     * these can right now have the form of general binary trees,     * where the inner nodes of grade 2 are AND nodes, while the      * nodes with grade one are ALL nodes; the leaves are all WHENs     */    n = o->conditionals;    if ( !n ) {      continue;    }    nn = n->sons;    while ( nn ) {      collect_all_effect_prefix_paths( nn );      free_CodeNode( nn->sons );      nn->connective = ltmpI->connective;      if ( nn->connective == ALL ) {	nn->var = ltmpI->var;	nn->var_type = ltmpI->var_type;      }      nn->sons = ltmpI->sons;      next = nn->next;      nn->next = ltmpI->next;      for ( jj = nn; jj->next; jj = jj->next );      jj->next = next;      nn = next;      free( ltmpI );    }  }  o = gcode_operators;  while ( o ) {    i = 0;        while( i<o->num_vars ) {      if ( (unary = var_used_in_unary_under( i, o->preconds )) != -1 ) {	o2 = new_CodeOperator();	o2->name = copy_string( o->name );	o2->number_of_real_params = o->number_of_real_params;	o2->num_vars = o->num_vars;	for ( l=0; l<o->num_vars; l++ ) {	  o2->var_types[l] = o->var_types[l];	}	o2->preconds = deep_copy_CodeTree( o->preconds );	o2->conditionals = deep_copy_CodeTree( o->conditionals );	for ( o3 = o; o3->next; o3 = o3->next );	o3->next = o2;		/* set types of var i	 * in o: typ \cap ini(unary)	 * in o2: typ \setminus ini(unary)	 */	if ( gtypes_table_size == MAX_TYPES_TABLE ) {	  printf("\ntoo many types (+inferred types)!increase MAX_TYPES_TABLE (currently %d)\n\n",		 MAX_TYPES_TABLE);	  exit( 1 );	}	gtypes_table[gtypes_table_size].name = gnew_types_name;	gtypes_table[gtypes_table_size].integers = NULL;	for ( tt = gtypes_table[o->var_types[i]].integers; tt; tt = tt->next ) {	  a[0] = tt->index;	  if ( possibly_positive( unary, a ) ) {	    tmp = new_integers( tt->index );	    tmp->next = gtypes_table[gtypes_table_size].integers;	    gtypes_table[gtypes_table_size].integers = tmp;	  }	}	o->var_types[i] = gtypes_table_size;	gtypes_table_size++;	if ( gtypes_table_size == MAX_TYPES_TABLE ) {	  printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",		 MAX_TYPES_TABLE);	  exit( 1 );	}	gtypes_table[gtypes_table_size].name = gnew_types_name;	gtypes_table[gtypes_table_size].integers = NULL;	for ( tt = gtypes_table[o2->var_types[i]].integers; tt; tt = tt->next ) {	  a[0] = tt->index;	  if ( !possibly_positive( unary, a ) ) {	    tmp = new_integers( tt->index );	    tmp->next = gtypes_table[gtypes_table_size].integers;	    gtypes_table[gtypes_table_size].integers = tmp;	  }	}	o2->var_types[i] = gtypes_table_size;	gtypes_table_size++;		/* in o->preconds: unary(i) = TRUE	 * in o2->preconds: unary(i) = FALSE	 */	replace_unary_var_occurences( unary, i, TRU, &(o->preconds) );	replace_unary_var_occurences( unary, i, FAL, &(o2->preconds) );	/* same in conditionals	 */	replace_unary_var_occurences( unary, i, TRU, &(o->conditionals) );	replace_unary_var_occurences( unary, i, FAL, &(o2->conditionals) );	continue;      }      if ( (unary = var_used_in_unary_under( i, o->conditionals )) != -1 ) {	o2 = new_CodeOperator();	o2->name = copy_string( o->name );	o2->number_of_real_params = o->number_of_real_params;	o2->num_vars = o->num_vars;	for ( l=0; l<o->num_vars; l++ ) {	  o2->var_types[l] = o->var_types[l];	  o2->inst_table[l] = o->inst_table[l];	}	o2->preconds = deep_copy_CodeTree( o->preconds );	o2->conditionals = deep_copy_CodeTree( o->conditionals );	for ( o3 = o; o3->next; o3 = o3->next );	o3->next = o2;		if ( gtypes_table_size == MAX_TYPES_TABLE ) {	  printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",		 MAX_TYPES_TABLE);	  exit( 1 );	}	gtypes_table[gtypes_table_size].name = gnew_types_name;	gtypes_table[gtypes_table_size].integers = NULL;	for ( tt = gtypes_table[o->var_types[i]].integers; tt; tt = tt->next ) {	  a[0] = tt->index;	  if ( possibly_positive( unary, a ) ) {	    tmp = new_integers( tt->index );	    tmp->next = gtypes_table[gtypes_table_size].integers;	    gtypes_table[gtypes_table_size].integers = tmp;	  }	}	o->var_types[i] = gtypes_table_size;	gtypes_table_size++;	if ( gtypes_table_size == MAX_TYPES_TABLE ) {	  printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",		 MAX_TYPES_TABLE);	  exit( 1 );	}	gtypes_table[gtypes_table_size].name = gnew_types_name;	gtypes_table[gtypes_table_size].integers = NULL;	for ( tt = gtypes_table[o2->var_types[i]].integers; tt; tt = tt->next ) {	  a[0] = tt->index;	  if ( !possibly_positive( unary, a ) ) {	    tmp = new_integers( tt->index );	    tmp->next = gtypes_table[gtypes_table_size].integers;	    gtypes_table[gtypes_table_size].integers = tmp;	  }	}	o2->var_types[i] = gtypes_table_size;	gtypes_table_size++;		replace_unary_var_occurences( unary, i, TRU, &(o->preconds) );	replace_unary_var_occurences( unary, i, FAL, &(o2->preconds) );	replace_unary_var_occurences( unary, i, TRU, &(o->conditionals) );	replace_unary_var_occurences( unary, i, FAL, &(o2->conditionals) );	continue;      }      i++;    }    o = o->next;  }  if ( gcmd_line.display_info == 101 ) {    printf("\ngoal state with unaries encoded is:\n");    print_CodeNode( gcode_goal_state, 0 );    printf("\noperators with unaries encoded are:");    for ( o = gcode_operators; o; o = o->next ) {      print_CodeOperator( o );    }  }}void encode_unaries_under_CodeNode( CodeNode **n ){  CodeNode *son1, *son2, *tmp;  int old_type;  ArgArray a;  Integers *tt, *ttmp;  short int unary;  if ( !(*n) ) {    return;  }  encode_unaries_under_CodeNode( &((*n)->sons) );  encode_unaries_under_CodeNode( &((*n)->next) );  if ( (*n)->connective == ALL ) {    if ( (unary = var_used_in_unary_under( (*n)->var, (*n)->sons )) != -1 ) {      son1 = new_CodeNode( ALL );      son2 = new_CodeNode( ALL );      tmp = deep_copy_CodeTree( (*n)->sons );      son1->sons = (*n)->sons;      son2->sons = tmp;      son1->var = (*n)->var;      son2->var = (*n)->var;      old_type = (*n)->var_type;      (*n)->connective = AND;      (*n)->var = 0;      (*n)->var_type = 0;      (*n)->sons = son1;      son1->next = son2;      son2->next = NULL;      if ( gtypes_table_size == MAX_TYPES_TABLE ) {	printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",	       MAX_TYPES_TABLE);	exit( 1 );      }      gtypes_table[gtypes_table_size].name = gnew_types_name;      gtypes_table[gtypes_table_size].integers = NULL;      for ( tt = gtypes_table[old_type].integers; tt; tt = tt->next ) {	a[0] = tt->index;	if ( possibly_positive( unary, a ) ) {	  ttmp = new_integers( tt->index );	  ttmp->next = gtypes_table[gtypes_table_size].integers;	  gtypes_table[gtypes_table_size].integers = ttmp;	}      }      son1->var_type = gtypes_table_size;      gtypes_table_size++;            if ( gtypes_table_size == MAX_TYPES_TABLE ) {	printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",	       MAX_TYPES_TABLE);	exit( 1 );      }      gtypes_table[gtypes_table_size].name = gnew_types_name;      gtypes_table[gtypes_table_size].integers = NULL;      for ( tt = gtypes_table[old_type].integers; tt; tt = tt->next ) {	a[0] = tt->index;	if ( !possibly_positive( unary, a ) ) {	  ttmp = new_integers( tt->index );	  ttmp->next = gtypes_table[gtypes_table_size].integers;	  gtypes_table[gtypes_table_size].integers = ttmp;	}      }      son2->var_type = gtypes_table_size;      gtypes_table_size++;      replace_unary_var_occurences( unary, son1->var, TRU, &(son1->sons) );      replace_unary_var_occurences( unary, son2->var, FAL, &(son2->sons) );            encode_unaries_under_CodeNode( &(son1) );      encode_unaries_under_CodeNode( &(son2) );    }  }  if ( (*n)->connective == EX ) {    if ( (unary = var_used_in_unary_under( (*n)->var, (*n)->sons )) != -1 ) {      son1 = new_CodeNode( EX );      son2 = new_CodeNode( EX );      tmp = deep_copy_CodeTree( (*n)->sons );      son1->sons = (*n)->sons;      son2->sons = tmp;      son1->var = (*n)->var;      son2->var = (*n)->var;      old_type = (*n)->var_type;      (*n)->connective = OR;      (*n)->var = 0;      (*n)->var_type = 0;      (*n)->sons = son1;      son1->next = son2;      son2->next = NULL;      if ( gtypes_table_size == MAX_TYPES_TABLE ) {	printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",	       MAX_TYPES_TABLE);	exit( 1 );      }      gtypes_table[gtypes_table_size].name = gnew_types_name;      gtypes_table[gtypes_table_size].integers = NULL;      for ( tt = gtypes_table[old_type].integers; tt; tt = tt->next ) {	a[0] = tt->index;	if ( possibly_positive( unary, a ) ) {	  ttmp = new_integers( tt->index );	  ttmp->next = gtypes_table[gtypes_table_size].integers;	  gtypes_table[gtypes_table_size].integers = ttmp;	}      }      son1->var_type = gtypes_table_size;      gtypes_table_size++;            if ( gtypes_table_size == MAX_TYPES_TABLE ) {	printf("\ntoo many types (+inferred types)! increase MAX_TYPES_TABLE (currently %d)\n\n",	       MAX_TYPES_TABLE);	exit( 1 );      }      gtypes_table[gtypes_table_size].name = gnew_types_name;      gtypes_table[gtypes_table_size].integers = NULL;      for ( tt = gtypes_table[old_type].integers; tt; tt = tt->next ) {	a[0] = tt->index;	if ( !possibly_positive( unary, a ) ) {	  ttmp = new_integers( tt->index );	  ttmp->next = gtypes_table[gtypes_table_size].integers;	  gtypes_table[gtypes_table_size].integers = ttmp;	}      }      son2->var_type = gtypes_table_size;      gtypes_table_size++;      replace_unary_var_occurences( unary, son1->var, TRU, &(son1->sons) );      replace_unary_var_occurences( unary, son2->var, FAL, &(son2->sons) );            encode_unaries_under_CodeNode( &(son1) );      encode_unaries_under_CodeNode( &(son2) );    }  }}int var_used_in_unary_under( int var, CodeNode *n ){  short int unary;  if ( !n ) {    return -1;  }  if ( (unary = var_used_in_unary_under( var, n->next )) != -1 ) {    return unary;  }  if ( (unary = var_used_in_unary_under( var, n->sons )) != -1 ) {    return unary;  }  if ( n->connective != ATOM ||       n->predicate == -1 ) {    return -1;  }  if ( garity[n->predicate] == 1 &&       n->arguments[0] == ((-1)*var)-1 &&       !gis_added[n->predicate] &&       !gis_deleted[n->predicate] ) {    return n->predicate;  } else {    return -1;  }}void replace_unary_var_occurences( short int unary, int var, 				   Connective val, CodeNode **n ){  if ( !(*n) ) {    return;  }  replace_unary_var_occurences( unary, var, val, &((*n)->next) );  replace_unary_var_occurences( unary, var, val, &((*n)->sons) );  if ( (*n)->connective != ATOM ) {    return;  }  if ( (*n)->predicate == unary &&       (*n)->arguments[0] == ((-1)*var)-1 ) {    (*n)->connective = val;    free_CodeNode( (*n)->sons );    (*n)->sons = NULL;  }}void collect_all_effect_prefix_paths( CodeNode *n ){  ltmpI = NULL;  recursive_collect_all_effect_prefix_paths( n, NULL );}void recursive_collect_all_effect_prefix_paths( CodeNode *n, 						CodeNode *history ){  CodeNode *tmp, *nn, *new_history, *new_eff, *new_when;  if ( n->connective == ALL ) {    tmp = new_CodeNode( ALL );    tmp->var = n->var;    tmp->var_type = n->var_type;    /* don't know if that's necessary     *     * doesn't matter, as it's on domain description level     */    new_history = deep_copy_CodeTree( history );    if ( !new_history ) {      new_history = tmp;    } else {      for ( nn = new_history; nn->sons; nn = nn->sons );      nn->sons = tmp;    }    recursive_collect_all_effect_prefix_paths( n->sons, new_history );    free_CodeNode( new_history );    return;  }  if ( n->connective == AND ) {    if ( !(n->sons) ||	 !(n->sons->next) ||	 n->sons->next->next ) {      printf("\neffect prefix AND node not binary ...!?\n\n");      exit( 1 );    }    recursive_collect_all_effect_prefix_paths( n->sons, history );    recursive_collect_all_effect_prefix_paths( n->sons->next, history );    return;  }  if ( n->connective == WHEN ) {    new_history = deep_copy_CodeTree( history );    new_when = new_CodeNode( WHEN );    new_eff = deep_copy_CodeTree( n->sons );    new_when->sons = new_eff;    if ( !new_history ) {      new_history = new_when;    } else {      for ( nn = new_history; nn->sons; nn = nn->sons );      nn->sons = new_when;    }    new_history->next = ltmpI;    ltmpI = new_history;    return;  }  printf("\nnon AND, ALL, WHEN in binary prefix tree ...?!\n\n");  exit( 1 );}

⌨️ 快捷键说明

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