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

📄 rifoutils.c

📁 intel ipp4.1性能库的一些例子。
💻 C
字号:
/* (C) Copyright 1997 Albert Ludwigs University Freiburg *     Institute of Computer Science * * All rights reserved. Use of this software is permitted for  * non-commercial research purposes, and it may be copied only  * for that use.  All copies must include this copyright message. * This software is made available AS IS, and neither the authors * nor the  Albert Ludwigs University Freiburg make any warranty * about the software or its performance.  */#include "ipp.h"#include "rifo.h"#include "utilities.h"#include "instantiateIV.h"long memused;/*** utility functions for rifo ***//* FREE, MALLOC & CALLOC are used to keep track of memory usage */void FREE( int size, void * ptr ){  memused -= size;  free( ptr );}void *MALLOC( int size ){  void *new;  char estr[40];  memused += size;  rifo_memory = MAX( memused, rifo_memory );  new = calloc( 1, size );  if ( new == NULL )     {      sprintf( estr, "Could not alloc %d bytes\n", size );      fatal_error( estr );  }  return new;}void *CALLOC( int size1, int size2 ){  void *new;  char estr[40];  memused += size1*size2;  rifo_memory = MAX( memused, rifo_memory );  new = calloc( size1, size2 );  if ( new == NULL ) {    sprintf( estr, "Could not calloc %d bytes\n", size1*size2 );    fatal_error( estr );  }  return new;}BitVector * New_bit_vector(int length){  BitVector * result = (BitVector *) CALLOC(length, sizeof(int));  CHECK_PTR(result);#ifdef MEMORY_INFO  rifo_memory += length;#endif  memset(result, 0, length);  return result;}/********************************************************************* * Creates a new pair of two fact info structures. * * FactInfo * pos: This represents the positive part. * FactInfo * neg: This represents the negaitve part. * * RETURNS a pointer to the new structure. *********************************************************************/FactInfoPair * New_fact_info_pair(FactInfo * pos, FactInfo * neg){  FactInfoPair * result = (FactInfoPair *) MALLOC(sizeof(FactInfoPair));  CHECK_PTR(result);#ifdef MEMORY_INFO  rifo_memory += sizeof(FactInfoPair);#endif    result->positive = pos;  result->negative = neg;  return result;}/********************************************************************* * Creates a new fact info structure with a bit vector with the * correct length. A fact info is a tuple of a bit vector and a list * of integers. The integers are the indices of the set bits in the * vector.  *  * NOTE: indices is initialized to NULL; * * RETURNS a pointer to the new structure. *********************************************************************/FactInfo *New_FactInfo( void ){  FactInfo *tmp = ( FactInfo * ) CALLOC( 1, sizeof( FactInfo ) );  CHECK_PTR( tmp );#ifdef MEMORY_INFO  rifo_memory += sizeof( FactInfo );#endif  tmp->vector = New_bit_vector( gft_vector_length );  tmp->indices = NULL;  return tmp;}/********************************************************************* * Creates a new structure that holds one integer !! *  * NOTE: The index is initialized to -1. * * int i: The value for index. * * RETURNS a pointer to the new structure. *********************************************************************/Integers * New_integers(int i){  Integers * result = (Integers *) MALLOC(sizeof(Integers));  CHECK_PTR(result);#ifdef MEMORY_INFO  rifo_memory += sizeof(Integers);#endif  result->index = i;  result->next = NULL;  return result;}BitOperator *New_BitOperator( char *name ){  BitOperator *tmp = ( BitOperator * ) CALLOC( 1, sizeof( BitOperator ) );  CHECK_PTR( tmp );#ifdef MEMORY_INFO  rifo_memory += sizeof( BitOperator );#endif  tmp->name = copy_string( name );  tmp->p_preconds = NULL;  tmp->n_preconds = NULL;  tmp->unconditional = NULL;  tmp->conditionals = NULL;  tmp->next = NULL;  return tmp;}Effect *New_Effect( void ){  Effect *tmp = ( Effect * ) calloc( 1, sizeof( Effect ) );  CHECK_PTR( tmp );#ifdef MEMORY_INFO  rifo_memory += sizeof( Effect );#endif  tmp->p_conds = New_FactInfo();  tmp->n_conds = New_FactInfo();  tmp->p_effects = New_FactInfo();  tmp->n_effects = New_FactInfo();  tmp->next = NULL;    return tmp;}void Free_integers( Integers *l ){  if ( l != NULL ) {    Free_integers( l->next );    free( l );  }}void Free_bit_vector(BitVector * bvec){  if ( bvec ) {    free(bvec);  }}void Free_fact_info(FactInfo * info){  if ( info != NULL ) {    Free_bit_vector(info->vector);    Free_integers(info->indices);    free( info );  }}void Free_fact_info_pair( FactInfoPair *p ){  if ( p ) {    Free_fact_info( p->positive );    Free_fact_info( p->negative );        free( p );  }}void Free_effect(Effect * effect){  if (NULL != effect)    {      Free_effect(effect->next);      Free_fact_info(effect->p_conds);      Free_fact_info(effect->n_conds);      Free_fact_info(effect->p_effects);      Free_fact_info(effect->n_effects);      free(effect);    }}void Free_BitOperator( BitOperator *op ){  if ( op != NULL ) {    Free_fact_info( op->p_preconds );    Free_fact_info( op->n_preconds );    Free_effect( op->unconditional );    Free_effect( op->conditionals );    free( op );  }}void Free_lookup_table( void ){  int i;  for (i=0; i<2*gnum_relevant_facts; i++)    {      Free_integers( op_lookup_table[i] );    }}/* some utils to copy bitvector-based type variables */void Copy_contents_of_FactInfo( FactInfo **dst, FactInfo *src ){  int i;  for ( i=0; i<gft_vector_length; i++ ) {    (*dst)->vector[i] = src->vector[i];  }      (*dst)->indices = Copy_Integers( src->indices );}Integers *Copy_Integers( Integers *i ){  Integers *r;  if ( !i ) {    return NULL;  }  r = New_integers( i->index );  r->next = Copy_Integers( i->next );  return r;}Effect *Copy_effects( Effect *e ){  Effect *r;  if ( !e ) {    return NULL;  }  r = New_Effect();  r->next = Copy_effects( e->next );  Copy_contents_of_FactInfo( &(r->p_conds), e->p_conds );  Copy_contents_of_FactInfo( &(r->n_conds), e->n_conds );  Copy_contents_of_FactInfo( &(r->p_effects), e->p_effects );  Copy_contents_of_FactInfo( &(r->n_effects), e->n_effects );  return r;}/* stop the program - something seems to be REALLY wrong... */void fatal_error( char *str ){  fprintf( stderr, "%s\n", str );  exit( 1 );}/* calculates the bitwise or of two bit vectors (of length gnum_relevant_facts ) and returns the resulting vector */BitVector * or(BitVector * a, BitVector * b){  register int i;  BitVector * vec;  vec = New_bit_vector(gft_vector_length);  for (i = 0; i < gft_vector_length; i++)    {      vec[i] = a[i] | b[i];    }  return vec;}/* dealing with facts etc */int equal_facts( FactInfoPair* f1, FactInfoPair* f2 ){  int i;  int equal=1;  for ( i=0; i<gnum_relevant_facts; i++ )    {      if (((get_bit(f1->positive->vector, gft_vector_length, i))!=	   (get_bit(f2->positive->vector, gft_vector_length, i)))	 ||((get_bit(f1->negative->vector, gft_vector_length, i))!=	   (get_bit(f2->negative->vector, gft_vector_length, i))))	{	  equal=0;	}    }  return equal;}/* calculate bitwise OR of two FactInfos */FactInfo *merge_FactInfo( FactInfo* facts1, FactInfo* facts2 ){  FactInfo *result;   result = New_FactInfo();     Free_bit_vector( result->vector );  result->vector = or( facts1->vector, facts2->vector );  /* no indices, cause they磖e not needed within rifo */  result->indices = NULL;  return result;}/* no. of instantiated operators in operator_list */int op_list_length( BitOperator* ol ){  register int i = 0;  while ( ol )     {      i++;      ol = ol->next;    }  return i;}/* IO functions for rifo */void print_op( BitOperator* op ){  int i;  fprintf(OUT, "%s", op->name);  for ( i=0; i<op->num_vars; i++ ) {    fprintf(OUT, " %s", gconstants_table[op->inst_table[i]]);  }}  void print_Fact_Info( FactInfoPair *facts ){  int i;  printf( "\n positive :" );  for (i=0; i < gnum_relevant_facts; i++)    { if (get_bit( facts->positive->vector, gft_vector_length, i))        printf("1");      else printf("0");    }  printf( "\n negative :" );  for (i=0; i < gnum_relevant_facts; i++)    { if (get_bit( facts->negative->vector, gft_vector_length, i))        printf("1");      else printf("0");    }  printf ("\n");}void print_one_set( settype *set, char *prefix, int donewline ){  int memnum;  printf( "%s [ ", prefix );  for ( memnum = 0; memnum < MAXSETSIZE; memnum++ )     if ( set_member( memnum, set ) )      printf( "%d ", memnum );  printf( "] " );  if ( donewline ) printf( "\n" );}void print_set_list( set_list sl, char *prefix ){  printf( "%s Set-list ( %d )", prefix, set_list_length( sl ) );  while ( sl )     {      print_one_set( sl->item, "", 0 );      sl = sl->next;    }  printf( "\n" );}/* functions to store and reset states and operators for repeated rifo    filtering when using metastrategy */void save_original_ipp_information(){  BitOperator *temp = gbit_operators;  BitOperator *newop = NULL, *act = 0 ;  short int j;  int count = 0;  FactInfo *pos;  FactInfo *neg;    /* save operators */  save_BitOperators = act= New_BitOperator( "dummy" );  while ( temp )    {      newop = act->next = New_BitOperator( temp->name );      newop->p_preconds = New_FactInfo();      newop->n_preconds = New_FactInfo();      Copy_contents_of_FactInfo( &newop->p_preconds, temp->p_preconds);      Copy_contents_of_FactInfo( &newop->n_preconds, temp->n_preconds);      newop->unconditional = Copy_effects(temp->unconditional);      newop->conditionals = Copy_effects(temp->conditionals);      for (j=0; j < MAX_VARS; j++)	newop->inst_table[j] = temp->inst_table[j];      newop->num_vars = temp->num_vars;      temp = temp->next;      newop = newop->next;      act = act->next;      count++;    }  save_BitOperators = save_BitOperators->next;   /* save initial state */  pos = New_FactInfo();  neg = New_FactInfo();  save_initial_state = New_fact_info_pair( pos, neg );  Copy_contents_of_FactInfo( &save_initial_state->positive, gbit_initial_state->positive );  Copy_contents_of_FactInfo( &save_initial_state->negative, gbit_initial_state->negative );   /* save goal state */  pos = New_FactInfo();  neg = New_FactInfo();  save_goal_state = New_fact_info_pair( pos, neg );  Copy_contents_of_FactInfo( &save_goal_state->positive, gbit_goal_state->positive );  Copy_contents_of_FactInfo( &save_goal_state->negative, gbit_goal_state->negative );          }void reset_original_ipp_information(){  BitOperator *temp;  BitOperator *newop = NULL, *act = NULL;  short int j;  int count = 0;  FactInfo *pos;  FactInfo *neg;  if (rifo_display_info > 3)    printf( "restoring original states and operators\n");  temp = save_BitOperators;  gbit_operators = act = New_BitOperator( "dummy" );  while ( temp )    {      newop = act->next = New_BitOperator( temp->name );      newop->p_preconds = New_FactInfo();      newop->n_preconds = New_FactInfo();      Copy_contents_of_FactInfo( &newop->p_preconds, temp->p_preconds);      Copy_contents_of_FactInfo( &newop->n_preconds, temp->n_preconds);      newop->unconditional = Copy_effects(temp->unconditional);      newop->conditionals = Copy_effects(temp->conditionals);      for (j=0; j < MAX_VARS; j++)	newop->inst_table[j] = temp->inst_table[j];      newop->num_vars = temp->num_vars;      temp = temp->next;      newop = newop->next;      act = act->next;      count++;    }    gbit_operators = gbit_operators->next;    /* reset initial state */  pos = New_FactInfo();  neg = New_FactInfo();  gbit_initial_state = New_fact_info_pair( pos, neg );  Copy_contents_of_FactInfo( &gbit_initial_state->positive, save_initial_state->positive );  Copy_contents_of_FactInfo( &gbit_initial_state->negative, save_initial_state->negative );   /* reset goal state */  pos = New_FactInfo();  neg = New_FactInfo();  gbit_goal_state = New_fact_info_pair( pos, neg );  Copy_contents_of_FactInfo( &gbit_goal_state->positive, save_goal_state->positive );  Copy_contents_of_FactInfo( &gbit_goal_state->negative, save_goal_state->negative );}

⌨️ 快捷键说明

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