void remove_identical_preconds_and_effects( Operator *o ) { int i, j, k, l; i = 0; while ( i < o->num_preconds-1 ) { j = i+1; while ( j < o->num_preconds ) { if ( identical_fact( &(o->preconds[i]), &(o->preconds[j]) ) ) { for ( k = j; k < o->num_preconds-1; k++ ) { o->preconds[k].predicate = o->preconds[k+1].predicate; for ( l = 0; l < garity[o->preconds[k].predicate]; l++ ) { o->preconds[k].args[l] = o->preconds[k+1].args[l]; } } o->num_preconds--; } else { j++; } } i++; } i = 0; while ( i < o->num_adds-1 ) { j = i+1; while ( j < o->num_adds ) { if ( identical_fact( &(o->adds[i]), &(o->adds[j]) ) ) { for ( k = j; k < o->num_adds-1; k++ ) { o->adds[k].predicate = o->adds[k+1].predicate; for ( l = 0; l < garity[o->adds[k].predicate]; l++ ) { o->adds[k].args[l] = o->adds[k+1].args[l]; } } o->num_adds--; } else { j++; } } i++; } i = 0; while ( i < o->num_dels-1 ) { j = i+1; while ( j < o->num_dels ) { if ( identical_fact( &(o->dels[i]), &(o->dels[j]) ) ) { for ( k = j; k < o->num_dels-1; k++ ) { o->dels[k].predicate = o->dels[k+1].predicate; for ( l = 0; l < garity[o->dels[k].predicate]; l++ ) { o->dels[k].args[l] = o->dels[k+1].args[l]; } } o->num_dels--; } else { j++; } } i++; } }
void cleanup_easy_domain( void ) { int i, i1, i2, i3, i4, a; NormOperator *o; NormEffect *e; /* most likely ( for sure ? ) we do not need this function call here, * as empty types are recognised in translation already. * * however, who knows .. ? doesn't need any real computation time anyway. * * function DOES make sense after unaries encoding, as artificial types * might well be empty. */ handle_empty_easy_parameters(); /* remove identical preconds and effects; * VERY unlikely that such will get down to here, after all * the formula preprocessing, but possible (?) in principle. * takes no computation time. * * also, remove effect conditions that are contained in the * preconditions. */ for ( i = 0; i < gnum_easy_operators; i++ ) { o = geasy_operators[i]; i1 = 0; while ( i1 < o->num_preconds-1 ) { i2 = i1+1; while ( i2 < o->num_preconds ) { if ( identical_fact( &(o->preconds[i1]), &(o->preconds[i2]) ) ) { for ( i3 = i2; i3 < o->num_preconds-1; i3++ ) { o->preconds[i3].predicate = o->preconds[i3+1].predicate; for ( i4 = 0; i4 < garity[o->preconds[i3].predicate]; i4++ ) { o->preconds[i3].args[i4] = o->preconds[i3+1].args[i4]; } } o->num_preconds--; } else { i2++; } } i1++; } for ( e = o->effects; e; e = e->next ) { i1 = 0; while ( i1 < e->num_conditions-1 ) { i2 = i1+1; while ( i2 < e->num_conditions ) { if ( identical_fact( &(e->conditions[i1]), &(e->conditions[i2]) ) ) { for ( i3 = i2; i3 < e->num_conditions-1; i3++ ) { e->conditions[i3].predicate = e->conditions[i3+1].predicate; /* here, we can still have equalities. nowhere else. */ a = ( e->conditions[i3].predicate < 0 ) ? 2 : garity[e->conditions[i3].predicate]; for ( i4 = 0; i4 < a; i4++ ) { e->conditions[i3].args[i4] = e->conditions[i3+1].args[i4]; } } e->num_conditions--; } else { i2++; } } i1++; } i1 = 0; while ( i1 < e->num_conditions ) { for ( i2 = 0; i2 < o->num_preconds; i2++ ) { if ( identical_fact( &(e->conditions[i1]), &(o->preconds[i2]) ) ) { break; } } if ( i2 == o->num_preconds ) { i1++; continue; } for ( i2 = i1; i2 < e->num_conditions-1; i2++ ) { e->conditions[i2].predicate = e->conditions[i2+1].predicate; for ( i3 = 0; i3 < garity[e->conditions[i2].predicate]; i3++ ) { e->conditions[i2].args[i3] = e->conditions[i2+1].args[i3]; } } e->num_conditions--; } i1 = 0; while ( i1 < e->num_adds-1 ) { i2 = i1+1; while ( i2 < e->num_adds ) { if ( identical_fact( &(e->adds[i1]), &(e->adds[i2]) ) ) { for ( i3 = i2; i3 < e->num_adds-1; i3++ ) { e->adds[i3].predicate = e->adds[i3+1].predicate; for ( i4 = 0; i4 < garity[e->adds[i3].predicate]; i4++ ) { e->adds[i3].args[i4] = e->adds[i3+1].args[i4]; } } e->num_adds--; } else { i2++; } } i1++; } i1 = 0; while ( i1 < e->num_dels-1 ) { i2 = i1+1; while ( i2 < e->num_dels ) { if ( identical_fact( &(e->dels[i1]), &(e->dels[i2]) ) ) { for ( i3 = i2; i3 < e->num_dels-1; i3++ ) { e->dels[i3].predicate = e->dels[i3+1].predicate; for ( i4 = 0; i4 < garity[e->dels[i3].predicate]; i4++ ) { e->dels[i3].args[i4] = e->dels[i3+1].args[i4]; } } e->num_dels--; } else { i2++; } } i1++; } } } }
void cleanup_easy_domain( void ) { int i, i1, sw, i2, i3, i4, a; NormOperator *o; NormEffect *e; /* remove equality constraints in preconditions * (op params are assumed different) */ for ( i = 0; i < gnum_easy_operators; i++ ) { o = geasy_operators[i]; i1 = 0; while ( i1 < o->num_preconds ) { if ( o->preconds[i1].predicate == -1 ) { sw = 0; if ( o->preconds[i1].args[0] < 0 ) { sw++; } if ( o->preconds[i1].args[1] < 0 ) { sw++; } switch ( sw ) { case 2: if ( o->preconds[i1].args[0] == o->preconds[i1].args[1] ) { break; } /* replace higher with lower --> higher gets removed in next cleanup step! */ replace_var_entries( o, o->preconds[i1].args[0], o->preconds[i1].args[1] ); break; case 1: /* replace param with constant */ replace_var_entries( o, o->preconds[i1].args[0], o->preconds[i1].args[1] ); break; case 0: printf("\ntwo constants in equality of easy precond. debug me\n\n"); exit( 1 ); } /* equality precond gets removed anyway. */ for ( i2 = i1; i2 < o->num_preconds-1; i2++ ) { o->preconds[i2].predicate = o->preconds[i2+1].predicate; for ( i3 = 0; i3 < garity[o->preconds[i2].predicate]; i3++ ) { o->preconds[i2].args[i3] = o->preconds[i2+1].args[i3]; } } o->num_preconds--; continue; } if ( o->preconds[i1].predicate == -2 ) { /* non equality precond gets removed. */ for ( i2 = i1; i2 < o->num_preconds-1; i2++ ) { o->preconds[i2].predicate = o->preconds[i2+1].predicate; for ( i3 = 0; i3 < garity[o->preconds[i2].predicate]; i3++ ) { o->preconds[i2].args[i3] = o->preconds[i2+1].args[i3]; } } o->num_preconds--; continue; } i1++; } } /* unused params can result from unary encoding; * that's why we have an extra function here */ remove_unused_easy_parameters(); /* most likely ( for sure ? ) we do not need this function call here, * as empty types are recognised in translation already. * * however, who knows .. ? doesn't need any real computation time anyway. * * function DOES make sense after unaries encoding, as artificial types * might well be empty. */ handle_empty_easy_parameters(); /* remove identical preconds and effects; * VERY unlikely that such will get down to here, after all * the formula preprocessing, but possible (?) in principle. * takes no computation time. * * also, remove effect conditions that are contained in the * preconditions. */ for ( i = 0; i < gnum_easy_operators; i++ ) { o = geasy_operators[i]; i1 = 0; while ( i1 < o->num_preconds-1 ) { i2 = i1+1; while ( i2 < o->num_preconds ) { if ( identical_fact( &(o->preconds[i1]), &(o->preconds[i2]) ) ) { for ( i3 = i2; i3 < o->num_preconds-1; i3++ ) { o->preconds[i3].predicate = o->preconds[i3+1].predicate; for ( i4 = 0; i4 < garity[o->preconds[i3].predicate]; i4++ ) { o->preconds[i3].args[i4] = o->preconds[i3+1].args[i4]; } } o->num_preconds--; } else { i2++; } } i1++; } for ( e = o->effects; e; e = e->next ) { i1 = 0; while ( i1 < e->num_conditions-1 ) { i2 = i1+1; while ( i2 < e->num_conditions ) { if ( identical_fact( &(e->conditions[i1]), &(e->conditions[i2]) ) ) { for ( i3 = i2; i3 < e->num_conditions-1; i3++ ) { e->conditions[i3].predicate = e->conditions[i3+1].predicate; /* here, we can still have equalities. nowhere else. */ a = ( e->conditions[i3].predicate < 0 ) ? 2 : garity[e->conditions[i3].predicate]; for ( i4 = 0; i4 < a; i4++ ) { e->conditions[i3].args[i4] = e->conditions[i3+1].args[i4]; } } e->num_conditions--; } else { i2++; } } i1++; } i1 = 0; while ( i1 < e->num_conditions ) { for ( i2 = 0; i2 < o->num_preconds; i2++ ) { if ( identical_fact( &(e->conditions[i1]), &(o->preconds[i2]) ) ) { break; } } if ( i2 == o->num_preconds ) { i1++; continue; } for ( i2 = i1; i2 < e->num_conditions-1; i1++ ) { e->conditions[i2].predicate = e->conditions[i2+1].predicate; for ( i3 = 0; i3 < garity[e->conditions[i2].predicate]; i3++ ) { e->conditions[i2].args[i3] = e->conditions[i2+1].args[i3]; } } e->num_conditions--; } i1 = 0; while ( i1 < e->num_adds-1 ) { i2 = i1+1; while ( i2 < e->num_adds ) { if ( identical_fact( &(e->adds[i1]), &(e->adds[i2]) ) ) { for ( i3 = i2; i3 < e->num_adds-1; i3++ ) { e->adds[i3].predicate = e->adds[i3+1].predicate; for ( i4 = 0; i4 < garity[e->adds[i3].predicate]; i4++ ) { e->adds[i3].args[i4] = e->adds[i3+1].args[i4]; } } e->num_adds--; } else { i2++; } } i1++; } i1 = 0; while ( i1 < e->num_dels-1 ) { i2 = i1+1; while ( i2 < e->num_dels ) { if ( identical_fact( &(e->dels[i1]), &(e->dels[i2]) ) ) { for ( i3 = i2; i3 < e->num_dels-1; i3++ ) { e->dels[i3].predicate = e->dels[i3+1].predicate; for ( i4 = 0; i4 < garity[e->dels[i3].predicate]; i4++ ) { e->dels[i3].args[i4] = e->dels[i3+1].args[i4]; } } e->num_dels--; } else { i2++; } } i1++; } } } }