Ejemplo n.º 1
0
void free_NormOperator( NormOperator *o )

{

  int i;

  if ( o ) {

    if ( o->preconds ) {
      free( o->preconds );
    }
    if ( o->numeric_preconds_comp ) {
      free( o->numeric_preconds_comp );
    }
    for ( i = 0; i < o->num_numeric_preconds; i++ ) {
      free_ExpNode( o->numeric_preconds_lh[i] );
      free_ExpNode( o->numeric_preconds_rh[i] );
    }
    if ( o->numeric_preconds_lh ) {
      free( o->numeric_preconds_lh );
    }
    if ( o->numeric_preconds_rh ) {
      free( o->numeric_preconds_rh );
    }
    free_NormEffect( o->effects );

    free( o );
  }

}
Ejemplo n.º 2
0
void free_NormEffect( NormEffect *e )

{

  int i;

  if ( e ) {
    free_NormEffect( e->next );

    if ( e->conditions ) {
      free( e->conditions );
    }
    if ( e->adds ) {
      free( e->adds );
    }
    if ( e->dels ) {
      free( e->dels );
    }

    if ( e->numeric_conditions_comp ) {
      free( e->numeric_conditions_comp );
    }
    for ( i = 0; i < e->num_numeric_conditions; i++ ) {
      free_ExpNode( e->numeric_conditions_lh[i] );
      free_ExpNode( e->numeric_conditions_rh[i] );
    }
    if ( e->numeric_conditions_lh ) {
      free( e->numeric_conditions_lh );
    }
    if ( e->numeric_conditions_rh ) {
      free( e->numeric_conditions_rh );
    }

    if ( e->numeric_effects_neft ) {
      free( e->numeric_effects_neft );
    }
    if ( e->numeric_effects_fluent ) {
      free( e->numeric_effects_fluent );
    }
    for ( i = 0; i < e->num_numeric_effects; i++ ) {
      free_ExpNode( e->numeric_effects_rh[i] );
    }
    if ( e->numeric_effects_rh ) {
      free( e->numeric_effects_rh );
    }

    free( e );
  }

}
Ejemplo n.º 3
0
void free_NormOperator( NormOperator *o )

{

  if ( o ) {

    if ( o->preconds ) {
      free( o->preconds );
    }

    free_NormEffect( o->effects );

    free( o );
  }

}
Ejemplo n.º 4
0
void free_NormEffect( NormEffect *e )

{

  if ( e ) {
    free_NormEffect( e->next );

    if ( e->conditions ) {
      free( e->conditions );
    }
    if ( e->adds ) {
      free( e->adds );
    }
    if ( e->dels ) {
      free( e->dels );
    }

    free( e );
  }

}
Ejemplo n.º 5
0
void multiply_easy_non_constrained_effect_parameters( int curr_parameter )

{

  int t, n, i, j, k, p, par;
  NormEffect *tmp;
  Bool rem;

  if ( curr_parameter == lnum_multiply_parameters ) {
    /* create new effect, adjusting conds to inst, and
     * partially instantiating effects;
     *
     * add result to  lres
     */
    tmp = new_NormEffect2( le );

    /* instantiate param occurences
     */
    for ( i = 0; i < le->num_vars; i++ ) {
      par = lo->num_vars + i;

      /* numerical part
       */
      for ( j = 0; j < tmp->num_numeric_conditions; j++ ) {
	replace_var_with_const_in_exp( &(tmp->numeric_conditions_lh[j]), 
				       par, le->inst_table[i] );
      }
      for ( j = 0; j < tmp->num_numeric_conditions; j++ ) {
	replace_var_with_const_in_exp( &(tmp->numeric_conditions_rh[j]), 
				       par, le->inst_table[i] );
      }
      /* was that already enough to get numbers? if yes,
       * see whether comparison holds or not.
       */
      j = 0;
      while ( j < tmp->num_numeric_conditions ) {
	if ( tmp->numeric_conditions_lh[j]->connective == NUMBER &&
	     tmp->numeric_conditions_rh[j]->connective == NUMBER ) {
	  if ( number_comparison_holds( tmp->numeric_conditions_comp[j],
					tmp->numeric_conditions_lh[j]->value,
					tmp->numeric_conditions_rh[j]->value ) ) {
	    free_ExpNode( tmp->numeric_conditions_lh[j] );
	    free_ExpNode( tmp->numeric_conditions_rh[j] );
	    for ( k = j; k < tmp->num_numeric_conditions-1; k++ ) {
	      tmp->numeric_conditions_comp[k] = tmp->numeric_conditions_comp[k+1];
	      tmp->numeric_conditions_lh[k] = tmp->numeric_conditions_lh[k+1];
	      tmp->numeric_conditions_rh[k] = tmp->numeric_conditions_rh[k+1];
	    }
	    tmp->num_numeric_conditions--;
	  } else {
	    free_NormEffect( tmp );
	    return;
	  }
	} else {
	  j++;
	}
      }
      for ( j = 0; j < tmp->num_numeric_effects; j++ ) {
	for ( k = 0; k < gf_arity[tmp->numeric_effects_fluent[j].function]; k++ ) {
	  if ( tmp->numeric_effects_fluent[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->numeric_effects_fluent[j].args[k] = le->inst_table[i];
	  }
	}
      }
      for ( j = 0; j < tmp->num_numeric_effects; j++ ) {
	replace_var_with_const_in_exp( &(tmp->numeric_effects_rh[j]), 
				       par, le->inst_table[i] );
      }

      /* logical part
       */
      for ( j = 0; j < tmp->num_conditions; j++ ) {
	for ( k = 0; k < garity[tmp->conditions[j].predicate]; k++ ) {
	  if ( tmp->conditions[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->conditions[j].args[k] = le->inst_table[i];
	  }
	}
      }
      for ( j = 0; j < tmp->num_adds; j++ ) {
	for ( k = 0; k < garity[tmp->adds[j].predicate]; k++ ) {
	  if ( tmp->adds[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->adds[j].args[k] = le->inst_table[i];
	  }
	}
      }
      for ( j = 0; j < tmp->num_dels; j++ ) {
	for ( k = 0; k < garity[tmp->dels[j].predicate]; k++ ) {
	  if ( tmp->dels[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->dels[j].args[k] = le->inst_table[i];
	  }
	}
      }
    }
    /* adjust conditions
     */
    i = 0;
    while ( i < tmp->num_conditions ) {
      rem = FALSE;
      p = tmp->conditions[i].predicate;
      if ( !gis_added[p] &&
	   !gis_deleted[p] ) {
	for ( j = 0; j < garity[p]; j++ ) {
	  if ( tmp->conditions[i].args[j] < 0 &&
	       DECODE_VAR( tmp->conditions[i].args[j] < lo->num_vars ) ) {
	    break;
	  }
	}
	if ( j == garity[p] ) {
	  /* inertia that constrain only effect params have been unified,
	   * are therefore TRUE
	   */
	  rem = TRUE;
	}
      }
      if ( rem ) {
	for ( j = i; j < tmp->num_conditions - 1; j++ ) {
	  tmp->conditions[j].predicate = tmp->conditions[j+1].predicate;
	  for ( k = 0; k < garity[tmp->conditions[j+1].predicate]; k++ ) {
	    tmp->conditions[j].args[k] = tmp->conditions[j+1].args[k];
	  }
	}
	tmp->num_conditions--;
      } else {
	i++;
      }
    }
    /* add result to lres
     */
    if ( lres ) {
      lres->prev = tmp;
    }
    tmp->next = lres;
    lres = tmp;
    return;
  }

  t = le->var_types[lmultiply_parameters[curr_parameter]];
  n = gtype_size[t];

  for ( i = 0; i < n; i++ ) {
    le->inst_table[lmultiply_parameters[curr_parameter]] = gtype_consts[t][i];
    multiply_easy_non_constrained_effect_parameters( curr_parameter + 1 );
  }

  le->inst_table[lmultiply_parameters[curr_parameter]] = -1;

}
Ejemplo n.º 6
0
void multiply_easy_effect_parameters( void )

{

  int i, j, k, l, p, par;
  NormEffect *e;

  for ( i = 0; i < gnum_easy_operators; i++ ) {
    lo = geasy_operators[i];

    lres = NULL;
    for ( e = lo->effects; e; e = e->next ) {
      le = e;

      lnum_inertia_conds = 0;
      for ( j = 0; j < e->num_conditions; j++ ) {
	for ( k = 0; k < garity[e->conditions[j].predicate]; k++ ) {
	  if ( e->conditions[j].args[k] < 0 &&
	       DECODE_VAR( e->conditions[j].args[k] ) < lo->num_vars ) {
	    break;
	  }
	}
	if ( k < garity[e->conditions[j].predicate] ) {
	  /* only consider inertia constraining effect parameters
	   */
	  continue;
	}
	if ( !gis_added[e->conditions[j].predicate] &&
	     !gis_deleted[e->conditions[j].predicate] ) {
	  linertia_conds[lnum_inertia_conds++] = j;
	}
      }

      lnum_multiply_parameters = 0;
      for ( j = 0; j < e->num_vars; j++ ) {
	par = lo->num_vars + j;
	for ( k = 0; k < lnum_inertia_conds; k++ ) {
	  p = e->conditions[linertia_conds[k]].predicate;
	  for ( l = 0; l < garity[p]; l++ ) {
	    if ( e->conditions[linertia_conds[k]].args[l] ==
		 ENCODE_VAR( par ) ) {
	      break;
	    }
	  }
	  if ( l < garity[p] ) {
	    break;
	  }
	}
	if ( k < lnum_inertia_conds ) {
	  continue;
	}
	lmultiply_parameters[lnum_multiply_parameters++] = j;
      }

      unify_easy_inertia_conditions( 0 );
    }
    free_NormEffect( lo->effects );
    lo->effects = lres;
  }

}
Ejemplo n.º 7
0
void multiply_easy_non_constrained_effect_parameters( int curr_parameter )

{

  int t, n, i, j, k, p, par, a;
  NormEffect *tmp;
  Bool rem;

  if ( curr_parameter == lnum_multiply_parameters ) {
    /* create new effect, adjusting conds to inst, and
     * partially instantiating effects;
     *
     * add result to  lres
     */
    tmp = new_NormEffect2( le );
    /* instantiate param occurences
     */
    for ( i = 0; i < le->num_vars; i++ ) {
      par = lo->num_vars + i;
      for ( j = 0; j < tmp->num_conditions; j++ ) {
	a = ( tmp->conditions[j].predicate < 0 ) ? 
	  2 : garity[tmp->conditions[j].predicate];
	for ( k = 0; k < a; k++ ) {
	  if ( tmp->conditions[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->conditions[j].args[k] = le->inst_table[i];
	  }
	}
      }
      for ( j = 0; j < tmp->num_adds; j++ ) {
	for ( k = 0; k < garity[tmp->adds[j].predicate]; k++ ) {
	  if ( tmp->adds[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->adds[j].args[k] = le->inst_table[i];
	  }
	}
      }
      for ( j = 0; j < tmp->num_dels; j++ ) {
	for ( k = 0; k < garity[tmp->dels[j].predicate]; k++ ) {
	  if ( tmp->dels[j].args[k] == ENCODE_VAR( par ) ) {
	    tmp->dels[j].args[k] = le->inst_table[i];
	  }
	}
      }
    }
    /* adjust conditions
     */
    i = 0;
    while ( i < tmp->num_conditions ) {
      rem = FALSE;
      p = tmp->conditions[i].predicate;
      if ( p == -1 &&
	   tmp->conditions[i].args[0] > 0 &&
	   tmp->conditions[i].args[1] > 0 ) {
	if ( tmp->conditions[i].args[0] !=
	     tmp->conditions[i].args[1] ) {
	  free_NormEffect( tmp );
	  return;
	} else {
	  rem = TRUE;
	}
      }
      if ( p == -2 &&
	   tmp->conditions[i].args[0] > 0 &&
	   tmp->conditions[i].args[1] > 0 ) {
	if ( tmp->conditions[i].args[0] ==
	     tmp->conditions[i].args[1] ) {
	  free_NormEffect( tmp );
	  return;
	} else {
	  rem = TRUE;
	}
      }
      if ( p > 0 ) {
	if ( !gis_added[p] &&
	     !gis_deleted[p] ) {
	  for ( j = 0; j < garity[p]; j++ ) {
	    if ( tmp->conditions[i].args[j] < 0 &&
		 DECODE_VAR( tmp->conditions[i].args[j] < lo->num_vars ) ) {
	      break;
	    }
	  }
	  if ( j == garity[p] ) {
	    /* inertia that constrain only effect params have been unified,
	     * are therefore TRUE
	     */
	    rem = TRUE;
	  }
	}
      }
      if ( rem ) {
	for ( j = i; j < tmp->num_conditions - 1; j++ ) {
	  tmp->conditions[j].predicate = tmp->conditions[j+1].predicate;
	  a = ( tmp->conditions[j+1].predicate < 0 ) ? 
	    2 : garity[tmp->conditions[j+1].predicate];
	  for ( k = 0; k < a; k++ ) {
	    tmp->conditions[j].args[k] = tmp->conditions[j+1].args[k];
	  }
	}
	tmp->num_conditions--;
      } else {
	i++;
      }
    }
    /* add result to lres
     */
    if ( lres ) {
      lres->prev = tmp;
    }
    tmp->next = lres;
    lres = tmp;
    return;
  }

  t = le->var_types[lmultiply_parameters[curr_parameter]];
  n = gtype_size[t];

  for ( i = 0; i < n; i++ ) {
    le->inst_table[lmultiply_parameters[curr_parameter]] = gtype_consts[t][i];
    multiply_easy_non_constrained_effect_parameters( curr_parameter + 1 );
  }

  lo->inst_table[lmultiply_parameters[curr_parameter]] = -1;

}