void dnf (int argc, char** argv) { if (freopen ("tests/in", "r", stdin) == NULL) { printf ("Error: read the file tests/in!\n"); exit (0); } if (argc == 1) { puts ("please input the formula:"); if (fgets (in, MAXN, stdin) == NULL) { printf ("Error: read input!\n"); exit (0); } } else { strcpy (in, argv[1]); } dnf_formula dnf (in); printf ("%s\n", dnf.to_string ().c_str ()); }
void create_hard_pseudo_effects( PseudoAction *a, Effect *e, int curr_var ) { int par, t, i, m; WffNode *tmp1, *w, *ww; PseudoActionEffect *tmp2; if ( curr_var < e->num_vars ) { par = a->operator->num_vars + curr_var; t = e->var_types[curr_var]; for ( i = 0; i < gtype_size[t]; i++ ) { linst_table[par] = gtype_consts[t][i]; create_hard_pseudo_effects( a, e, curr_var + 1 ); linst_table[par] = -1; } return; } tmp1 = instantiate_wff( e->conditions ); if ( tmp1->connective == FAL ) { free_WffNode( tmp1 ); return; } dnf( &tmp1 ); cleanup_wff( &tmp1 ); /* only debugging, REMOVE LATER */ if ( is_dnf( tmp1 ) == -1 ) { printf("\n\nILLEGAL DNF %s AFTER INSTANTIATION\n\n", a->operator->name); print_Wff( tmp1, 0 ); exit( 1 ); } switch ( tmp1->connective ) { case OR: for ( w = tmp1->sons; w; w = w->next ) { tmp2 = new_PseudoActionEffect(); if ( w->connective == AND ) { m = 0; for ( ww = w->sons; ww; ww = ww->next ) m++; tmp2->conditions = ( Fact * ) calloc( m, sizeof( Fact ) ); tmp2->num_conditions = m; m = 0; for ( ww = w->sons; ww; ww = ww->next ) { tmp2->conditions[m].predicate = ww->fact->predicate; for ( i = 0; i < garity[ww->fact->predicate]; i++ ) { tmp2->conditions[m].args[i] = ww->fact->args[i]; } m++; } } else { tmp2->conditions = ( Fact * ) calloc( 1, sizeof( Fact ) ); tmp2->num_conditions = 1; tmp2->conditions[0].predicate = w->fact->predicate; for ( i = 0; i < garity[w->fact->predicate]; i++ ) { tmp2->conditions[0].args[i] = w->fact->args[i]; } } make_instantiate_literals( tmp2, e->effects ); tmp2->next = a->effects; a->effects = tmp2; a->num_effects++; } break; case AND: tmp2 = new_PseudoActionEffect(); m = 0; for ( w = tmp1->sons; w; w = w->next ) m++; tmp2->conditions = ( Fact * ) calloc( m, sizeof( Fact ) ); tmp2->num_conditions = m; m = 0; for ( w = tmp1->sons; w; w = w->next ) { tmp2->conditions[m].predicate = w->fact->predicate; for ( i = 0; i < garity[w->fact->predicate]; i++ ) { tmp2->conditions[m].args[i] = w->fact->args[i]; } m++; } make_instantiate_literals( tmp2, e->effects ); tmp2->next = a->effects; a->effects = tmp2; a->num_effects++; break; case ATOM: tmp2 = new_PseudoActionEffect(); tmp2->conditions = ( Fact * ) calloc( 1, sizeof( Fact ) ); tmp2->num_conditions = 1; tmp2->conditions[0].predicate = tmp1->fact->predicate; for ( i = 0; i < garity[tmp1->fact->predicate]; i++ ) { tmp2->conditions[0].args[i] = tmp1->fact->args[i]; } make_instantiate_literals( tmp2, e->effects ); tmp2->next = a->effects; a->effects = tmp2; a->num_effects++; break; case TRU: tmp2 = new_PseudoActionEffect(); make_instantiate_literals( tmp2, e->effects ); tmp2->next = a->effects; a->effects = tmp2; a->num_effects++; break; default: printf("\n\nillegal connective %d in parsing DNF precond.\n\n", tmp1->connective); exit( 1 ); } free_WffNode( tmp1 ); }
void create_hard_mixed_operators( Operator *o, int curr_var ) { int t, i, m; WffNode *tmp1, *w, *ww; MixedOperator *tmp2; if ( curr_var < o->num_vars ) { if ( o->removed[curr_var] ) { /* param doesn't matter -- select any appropriate type constant * at least one there; otherwise, op would not have been translated. */ linst_table[curr_var] = gtype_consts[o->var_types[curr_var]][0]; create_hard_mixed_operators( o, curr_var + 1 ); linst_table[curr_var] = -1; return; } t = o->var_types[curr_var]; for ( i = 0; i < gtype_size[t]; i++ ) { linst_table[curr_var] = gtype_consts[t][i]; create_hard_mixed_operators( o, curr_var + 1 ); linst_table[curr_var] = -1; } return; } tmp1 = instantiate_wff( o->preconds ); if ( tmp1->connective == FAL ) { free_WffNode( tmp1 ); return; } dnf( &tmp1 ); cleanup_wff( &tmp1 ); if ( tmp1->connective == FAL ) { free_WffNode( tmp1 ); return; } /* only debugging, REMOVE LATER */ if ( is_dnf( tmp1 ) == -1 ) { printf("\n\nILLEGAL DNF %s AFTER INSTANTIATION\n\n", o->name); print_Wff( tmp1, 0 ); exit( 1 ); } switch ( tmp1->connective ) { case OR: for ( w = tmp1->sons; w; w = w->next ) { tmp2 = new_MixedOperator( o ); for ( i = 0; i < o->num_vars; i++ ) { tmp2->inst_table[i] = linst_table[i]; } if ( w->connective == AND ) { m = 0; for ( ww = w->sons; ww; ww = ww->next ) m++; tmp2->preconds = ( Fact * ) calloc( m, sizeof( Fact ) ); tmp2->num_preconds = m; m = 0; for ( ww = w->sons; ww; ww = ww->next ) { tmp2->preconds[m].predicate = ww->fact->predicate; for ( i = 0; i < garity[ww->fact->predicate]; i++ ) { tmp2->preconds[m].args[i] = ww->fact->args[i]; } m++; } } else { tmp2->preconds = ( Fact * ) calloc( 1, sizeof( Fact ) ); tmp2->num_preconds = 1; tmp2->preconds[0].predicate = w->fact->predicate; for ( i = 0; i < garity[w->fact->predicate]; i++ ) { tmp2->preconds[0].args[i] = w->fact->args[i]; } } tmp2->effects = instantiate_Effect( o->effects ); tmp2->next = ghard_mixed_operators; ghard_mixed_operators = tmp2; gnum_hard_mixed_operators++; } break; case AND: tmp2 = new_MixedOperator( o ); for ( i = 0; i < o->num_vars; i++ ) { tmp2->inst_table[i] = linst_table[i]; } m = 0; for ( w = tmp1->sons; w; w = w->next ) m++; tmp2->preconds = ( Fact * ) calloc( m, sizeof( Fact ) ); tmp2->num_preconds = m; m = 0; for ( w = tmp1->sons; w; w = w->next ) { tmp2->preconds[m].predicate = w->fact->predicate; for ( i = 0; i < garity[w->fact->predicate]; i++ ) { tmp2->preconds[m].args[i] = w->fact->args[i]; } m++; } tmp2->effects = instantiate_Effect( o->effects ); tmp2->next = ghard_mixed_operators; ghard_mixed_operators = tmp2; gnum_hard_mixed_operators++; break; case ATOM: tmp2 = new_MixedOperator( o ); for ( i = 0; i < o->num_vars; i++ ) { tmp2->inst_table[i] = linst_table[i]; } tmp2->preconds = ( Fact * ) calloc( 1, sizeof( Fact ) ); tmp2->num_preconds = 1; tmp2->preconds[0].predicate = tmp1->fact->predicate; for ( i = 0; i < garity[tmp1->fact->predicate]; i++ ) { tmp2->preconds[0].args[i] = tmp1->fact->args[i]; } tmp2->effects = instantiate_Effect( o->effects ); tmp2->next = ghard_mixed_operators; ghard_mixed_operators = tmp2; gnum_hard_mixed_operators++; break; case TRU: tmp2 = new_MixedOperator( o ); for ( i = 0; i < o->num_vars; i++ ) { tmp2->inst_table[i] = linst_table[i]; } tmp2->effects = instantiate_Effect( o->effects ); tmp2->next = ghard_mixed_operators; ghard_mixed_operators = tmp2; gnum_hard_mixed_operators++; break; default: printf("\n\nillegal connective %d in parsing DNF precond.\n\n", tmp1->connective); exit( 1 ); } free_WffNode( tmp1 ); }