void make_normal_effects()

in grolp/gen/ff_planner/inst_pre.c [3303:3616]


void make_normal_effects( NormOperator **nop, Operator *op )

{

  Effect *e;
  NormEffect *tmp_ef;
  WffNode *w, *ww, *www;
  int j, m, ma, md, mn;
  Literal *l;
  NumericEffect *ll;
  Fact *tmp_ft;
  Fluent *tmp_fl;

  for ( e = op->effects; e; e = e->next ) {
    w = e->conditions;
    switch ( w->connective ) {
    case OR:
      for ( ww = w->sons; ww; ww = ww->next ) {
	tmp_ef = new_NormEffect1( e );
	if ( ww->connective == AND ) {
	  m = 0;
	  mn = 0;
	  for ( www = ww->sons; www; www = www->next ) {
	    if ( www->connective == ATOM ) m++;
	    if ( www->connective == COMP ) mn++;
	  }
	  tmp_ef->conditions = ( Fact * ) calloc( m, sizeof( Fact ) );
	  tmp_ef->numeric_conditions_comp = ( Comparator * ) calloc( mn, sizeof( Comparator ) );
	  tmp_ef->numeric_conditions_lh = ( ExpNode_pointer * ) calloc( mn, sizeof( ExpNode_pointer ) );
	  tmp_ef->numeric_conditions_rh = ( ExpNode_pointer * ) calloc( mn, sizeof( ExpNode_pointer ) );
	  for ( www = ww->sons; www; www = www->next ) {
	    if ( www->connective == ATOM ) {
	      tmp_ft = &(tmp_ef->conditions[tmp_ef->num_conditions]);
	      tmp_ft->predicate = www->fact->predicate;
	      for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
		tmp_ft->args[j] = www->fact->args[j];
	      }
	      tmp_ef->num_conditions++;
	    }
	    if ( www->connective == COMP ) {
	      tmp_ef->numeric_conditions_comp[tmp_ef->num_numeric_conditions] = www->comp;
	      tmp_ef->numeric_conditions_lh[tmp_ef->num_numeric_conditions] = copy_Exp( www->lh );
	      tmp_ef->numeric_conditions_rh[tmp_ef->num_numeric_conditions] = copy_Exp( www->rh );
	      tmp_ef->num_numeric_conditions++;
	    }
	  }
	} else {
	  if ( ww->connective == ATOM ) {
	    tmp_ef->conditions = ( Fact * ) calloc( 1, sizeof( Fact ) );
	    tmp_ft = &(tmp_ef->conditions[0]);
	    tmp_ft->predicate = ww->fact->predicate;
	    for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	      tmp_ft->args[j] = ww->fact->args[j];
	    }
	    tmp_ef->num_conditions = 1;
	  }
	  if ( ww->connective == COMP ) {
	    tmp_ef->numeric_conditions_comp = ( Comparator * ) calloc( 1, sizeof( Comparator ) );
	    tmp_ef->numeric_conditions_lh = ( ExpNode_pointer * ) calloc( 1, sizeof( ExpNode_pointer ) );
	    tmp_ef->numeric_conditions_rh = ( ExpNode_pointer * ) calloc( 1, sizeof( ExpNode_pointer ) );
	    tmp_ef->numeric_conditions_comp[0] = ww->comp;
	    tmp_ef->numeric_conditions_lh[0] = copy_Exp( ww->lh );
	    tmp_ef->numeric_conditions_rh[0] = copy_Exp( ww->rh );
	    tmp_ef->num_numeric_conditions = 1;
	  }
	}
	ma = 0; md = 0;
	for ( l = e->effects; l; l = l->next ) {
	  if ( l->negated ) { md++; } else { ma++; }
	}
	tmp_ef->adds = ( Fact * ) calloc( ma, sizeof( Fact ) );
	tmp_ef->dels = ( Fact * ) calloc( md, sizeof( Fact ) );
	for ( l = e->effects; l; l = l->next ) {
	  if ( l->negated ) {
	    tmp_ft = &(tmp_ef->dels[tmp_ef->num_dels++]);
	  } else {
	    tmp_ft = &(tmp_ef->adds[tmp_ef->num_adds++]);
	  }
	  tmp_ft->predicate = l->fact.predicate;
	  for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	    tmp_ft->args[j] = l->fact.args[j];
	  }
	}
	ma = 0;
	for ( ll = e->numeric_effects; ll; ll = ll->next ) ma++;
	tmp_ef->numeric_effects_neft = ( NumericEffectType * ) calloc( ma, sizeof( NumericEffectType ) );
	tmp_ef->numeric_effects_fluent = ( Fluent * ) calloc( ma, sizeof( Fluent ) );
	tmp_ef->numeric_effects_rh = ( ExpNode_pointer * ) calloc( ma, sizeof( ExpNode_pointer ) );
	for ( ll = e->numeric_effects; ll; ll = ll->next ) {
	  tmp_ef->numeric_effects_neft[tmp_ef->num_numeric_effects] = ll->neft;
	  tmp_fl = &(tmp_ef->numeric_effects_fluent[tmp_ef->num_numeric_effects]);
	  tmp_fl->function = ll->fluent.function;
	  for ( j = 0; j < gf_arity[tmp_fl->function]; j++ ) {
	    tmp_fl->args[j] = ll->fluent.args[j];
	  }
	  tmp_ef->numeric_effects_rh[tmp_ef->num_numeric_effects] = copy_Exp( ll->rh );
	  tmp_ef->num_numeric_effects++;
	}
	tmp_ef->next = (*nop)->effects;
	if ( (*nop)->effects ) {
	  (*nop)->effects->prev = tmp_ef;
	}
	(*nop)->effects = tmp_ef;
      }
      break;
    case AND:
      tmp_ef = new_NormEffect1( e );
      m = 0;
      mn = 0;
      for ( ww = w->sons; ww; ww = ww->next ) {
	if ( ww->connective == ATOM ) m++;
	if ( ww->connective == COMP ) mn++;
      }
      tmp_ef->conditions = ( Fact * ) calloc( m, sizeof( Fact ) );
      tmp_ef->numeric_conditions_comp = ( Comparator * ) calloc( mn, sizeof( Comparator ) );
      tmp_ef->numeric_conditions_lh = ( ExpNode_pointer * ) calloc( mn, sizeof( ExpNode_pointer ) );
      tmp_ef->numeric_conditions_rh = ( ExpNode_pointer * ) calloc( mn, sizeof( ExpNode_pointer ) );
      for ( ww = w->sons; ww; ww = ww->next ) {
	if ( ww->connective == ATOM ) {
	  tmp_ft = &(tmp_ef->conditions[tmp_ef->num_conditions]);
	  tmp_ft->predicate = ww->fact->predicate;
	  for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	    tmp_ft->args[j] = ww->fact->args[j];
	  }
	  tmp_ef->num_conditions++;
	}
	if ( ww->connective == COMP ) {
	  tmp_ef->numeric_conditions_comp[tmp_ef->num_numeric_conditions] = ww->comp;
	  tmp_ef->numeric_conditions_lh[tmp_ef->num_numeric_conditions] = copy_Exp( ww->lh );
	  tmp_ef->numeric_conditions_rh[tmp_ef->num_numeric_conditions] = copy_Exp( ww->rh );
	  tmp_ef->num_numeric_conditions++;
	}
      }
      ma = 0; md = 0;
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) { md++; } else { ma++; }
      }
      tmp_ef->adds = ( Fact * ) calloc( ma, sizeof( Fact ) );
      tmp_ef->dels = ( Fact * ) calloc( md, sizeof( Fact ) );
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) {
	  tmp_ft = &(tmp_ef->dels[tmp_ef->num_dels++]);
	} else {
	  tmp_ft = &(tmp_ef->adds[tmp_ef->num_adds++]);
	}
	tmp_ft->predicate = l->fact.predicate;
	for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	  tmp_ft->args[j] = l->fact.args[j];
	}
      }
      ma = 0;
      for ( ll = e->numeric_effects; ll; ll = ll->next ) ma++;
      tmp_ef->numeric_effects_neft = ( NumericEffectType * ) calloc( ma, sizeof( NumericEffectType ) );
      tmp_ef->numeric_effects_fluent = ( Fluent * ) calloc( ma, sizeof( Fluent ) );
      tmp_ef->numeric_effects_rh = ( ExpNode_pointer * ) calloc( ma, sizeof( ExpNode_pointer ) );
      for ( ll = e->numeric_effects; ll; ll = ll->next ) {
	tmp_ef->numeric_effects_neft[tmp_ef->num_numeric_effects] = ll->neft;
	tmp_fl = &(tmp_ef->numeric_effects_fluent[tmp_ef->num_numeric_effects]);
	tmp_fl->function = ll->fluent.function;
	for ( j = 0; j < gf_arity[tmp_fl->function]; j++ ) {
	  tmp_fl->args[j] = ll->fluent.args[j];
	}
	tmp_ef->numeric_effects_rh[tmp_ef->num_numeric_effects] = copy_Exp( ll->rh );
	tmp_ef->num_numeric_effects++;
      }
      tmp_ef->next = (*nop)->effects;
      if ( (*nop)->effects ) {
	(*nop)->effects->prev = tmp_ef;
      }
      (*nop)->effects = tmp_ef;
      break;
    case ATOM:
      tmp_ef = new_NormEffect1( e );
      tmp_ef->conditions = ( Fact * ) calloc( 1, sizeof( Fact ) );
      tmp_ft = &(tmp_ef->conditions[0]);
      tmp_ft->predicate = w->fact->predicate;
      for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	tmp_ft->args[j] = w->fact->args[j];
      }
      tmp_ef->num_conditions = 1;
      ma = 0; md = 0;
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) { md++; } else { ma++; }
      }
      tmp_ef->adds = ( Fact * ) calloc( ma, sizeof( Fact ) );
      tmp_ef->dels = ( Fact * ) calloc( md, sizeof( Fact ) );
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) {
	  tmp_ft = &(tmp_ef->dels[tmp_ef->num_dels++]);
	} else {
	  tmp_ft = &(tmp_ef->adds[tmp_ef->num_adds++]);
	}
	tmp_ft->predicate = l->fact.predicate;
	for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	  tmp_ft->args[j] = l->fact.args[j];
	}
      }
      ma = 0;
      for ( ll = e->numeric_effects; ll; ll = ll->next ) ma++;
      tmp_ef->numeric_effects_neft = ( NumericEffectType * ) calloc( ma, sizeof( NumericEffectType ) );
      tmp_ef->numeric_effects_fluent = ( Fluent * ) calloc( ma, sizeof( Fluent ) );
      tmp_ef->numeric_effects_rh = ( ExpNode_pointer * ) calloc( ma, sizeof( ExpNode_pointer ) );
      for ( ll = e->numeric_effects; ll; ll = ll->next ) {
	tmp_ef->numeric_effects_neft[tmp_ef->num_numeric_effects] = ll->neft;
	tmp_fl = &(tmp_ef->numeric_effects_fluent[tmp_ef->num_numeric_effects]);
	tmp_fl->function = ll->fluent.function;
	for ( j = 0; j < gf_arity[tmp_fl->function]; j++ ) {
	  tmp_fl->args[j] = ll->fluent.args[j];
	}
	tmp_ef->numeric_effects_rh[tmp_ef->num_numeric_effects] = copy_Exp( ll->rh );
	tmp_ef->num_numeric_effects++;
      }
      tmp_ef->next = (*nop)->effects;
      if ( (*nop)->effects ) {
	(*nop)->effects->prev = tmp_ef;
      }
      (*nop)->effects = tmp_ef;
      break;     
    case COMP:
      tmp_ef = new_NormEffect1( e );
      tmp_ef->numeric_conditions_comp = ( Comparator * ) calloc( 1, sizeof( Comparator ) );
      tmp_ef->numeric_conditions_lh = ( ExpNode_pointer * ) calloc( 1, sizeof( ExpNode_pointer ) );
      tmp_ef->numeric_conditions_rh = ( ExpNode_pointer * ) calloc( 1, sizeof( ExpNode_pointer ) );
      tmp_ef->numeric_conditions_comp[0] = w->comp;
      tmp_ef->numeric_conditions_lh[0] = copy_Exp( w->lh );
      tmp_ef->numeric_conditions_rh[0] = copy_Exp( w->rh );
      tmp_ef->num_numeric_conditions = 1;
      ma = 0; md = 0;
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) { md++; } else { ma++; }
      }
      tmp_ef->adds = ( Fact * ) calloc( ma, sizeof( Fact ) );
      tmp_ef->dels = ( Fact * ) calloc( md, sizeof( Fact ) );
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) {
	  tmp_ft = &(tmp_ef->dels[tmp_ef->num_dels++]);
	} else {
	  tmp_ft = &(tmp_ef->adds[tmp_ef->num_adds++]);
	}
	tmp_ft->predicate = l->fact.predicate;
	for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	  tmp_ft->args[j] = l->fact.args[j];
	}
      }
      ma = 0;
      for ( ll = e->numeric_effects; ll; ll = ll->next ) ma++;
      tmp_ef->numeric_effects_neft = ( NumericEffectType * ) calloc( ma, sizeof( NumericEffectType ) );
      tmp_ef->numeric_effects_fluent = ( Fluent * ) calloc( ma, sizeof( Fluent ) );
      tmp_ef->numeric_effects_rh = ( ExpNode_pointer * ) calloc( ma, sizeof( ExpNode_pointer ) );
      for ( ll = e->numeric_effects; ll; ll = ll->next ) {
	tmp_ef->numeric_effects_neft[tmp_ef->num_numeric_effects] = ll->neft;
	tmp_fl = &(tmp_ef->numeric_effects_fluent[tmp_ef->num_numeric_effects]);
	tmp_fl->function = ll->fluent.function;
	for ( j = 0; j < gf_arity[tmp_fl->function]; j++ ) {
	  tmp_fl->args[j] = ll->fluent.args[j];
	}
	tmp_ef->numeric_effects_rh[tmp_ef->num_numeric_effects] = copy_Exp( ll->rh );
	tmp_ef->num_numeric_effects++;
      }
      tmp_ef->next = (*nop)->effects;
      if ( (*nop)->effects ) {
	(*nop)->effects->prev = tmp_ef;
      }
      (*nop)->effects = tmp_ef;
      break;
    case TRU:
      tmp_ef = new_NormEffect1( e );
      ma = 0; md = 0;
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) { md++; } else { ma++; }
      }
      tmp_ef->adds = ( Fact * ) calloc( ma, sizeof( Fact ) );
      tmp_ef->dels = ( Fact * ) calloc( md, sizeof( Fact ) );
      for ( l = e->effects; l; l = l->next ) {
	if ( l->negated ) {
	  tmp_ft = &(tmp_ef->dels[tmp_ef->num_dels++]);
	} else {
	  tmp_ft = &(tmp_ef->adds[tmp_ef->num_adds++]);
	}
	tmp_ft->predicate = l->fact.predicate;
	for ( j = 0; j < garity[tmp_ft->predicate]; j++ ) {
	  tmp_ft->args[j] = l->fact.args[j];
	}
      }
      ma = 0;
      for ( ll = e->numeric_effects; ll; ll = ll->next ) ma++;
      tmp_ef->numeric_effects_neft = ( NumericEffectType * ) calloc( ma, sizeof( NumericEffectType ) );
      tmp_ef->numeric_effects_fluent = ( Fluent * ) calloc( ma, sizeof( Fluent ) );
      tmp_ef->numeric_effects_rh = ( ExpNode_pointer * ) calloc( ma, sizeof( ExpNode_pointer ) );
      for ( ll = e->numeric_effects; ll; ll = ll->next ) {
	tmp_ef->numeric_effects_neft[tmp_ef->num_numeric_effects] = ll->neft;
	tmp_fl = &(tmp_ef->numeric_effects_fluent[tmp_ef->num_numeric_effects]);
	tmp_fl->function = ll->fluent.function;
	for ( j = 0; j < gf_arity[tmp_fl->function]; j++ ) {
	  tmp_fl->args[j] = ll->fluent.args[j];
	}
	tmp_ef->numeric_effects_rh[tmp_ef->num_numeric_effects] = copy_Exp( ll->rh );
	tmp_ef->num_numeric_effects++;
      }
      tmp_ef->next = (*nop)->effects;
      if ( (*nop)->effects ) {
	(*nop)->effects->prev = tmp_ef;
      }
      (*nop)->effects = tmp_ef;
      break;
    case FAL:
      break;
    default:
      printf("\nwon't get here: non OR, AND, ATOM, TRUE, FALSE in dnf. debug me\n\n");
      exit( 1 );
    }
  }

}