void unify_easy_inertia_conditions( int curr_inertia ) { int p, i, j, af, hh; int args[MAX_VARS]; int affected_params[MAX_VARS]; int num_affected_params = 0; if ( curr_inertia == lnum_inertia_conds ) { multiply_easy_non_constrained_effect_parameters( 0 ); return; } p = le->conditions[linertia_conds[curr_inertia]].predicate; for ( i = 0; i < garity[p]; i++ ) { args[i] = le->conditions[linertia_conds[curr_inertia]].args[i]; if ( args[i] < 0 ) { hh = DECODE_VAR( args[i] ); hh -= lo->num_vars; if ( le->inst_table[hh] != -1 ) { args[i] = le->inst_table[hh]; } else { affected_params[num_affected_params++] = hh; } } } for ( i = 0; i < gnum_initial_predicate[p]; i++ ) { af = 0; for ( j = 0; j < garity[p]; j++ ) { if ( args[j] >= 0 ) { if ( args[j] != ginitial_predicate[p][i].args[j] ) { break; } else { continue; } } le->inst_table[affected_params[af++]] = ginitial_predicate[p][i].args[j]; } if ( j < garity[p] ) { continue; } unify_easy_inertia_conditions( curr_inertia + 1 ); } for ( i = 0; i < num_affected_params; i++ ) { le->inst_table[affected_params[i]] = -1; } }
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; }
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; 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; }