?? instantiateiv.c
字號:
free_CodeOperator( j ); }}void generate_ini_goal_bitmap_representation( void ){ FactInfo *tpos = new_FactInfo(); FactInfo *tneg = new_FactInfo(); CodeNode *i, *l; int j; RelevantFact *tmp; BitOperator *tmpop; /* goal state is non trivial, otherwise we would have stopped already. */ dnf( gcode_goal_state ); if ( gcode_goal_state->connective != OR ) { if ( gcode_goal_state->connective != AND ) { if ( gcode_goal_state->connective == NOT ) { make_entry_in_FactInfo( &tneg, gcode_goal_state->sons->var ); } else { make_entry_in_FactInfo( &tpos, gcode_goal_state->var ); } } else { for ( i = gcode_goal_state->sons; i; i = i->next ) { if ( i->connective == NOT ) { make_entry_in_FactInfo( &tneg, i->sons->var ); } else { make_entry_in_FactInfo( &tpos, i->var ); } } } } else { /* disjunctive goals! introduce new GOAL-REACHED fact */ if ( gpredicates_table_size == MAX_PREDICATES_TABLE ) { printf("\ntoo many predicates! increase MAX_PREDICATES_TABLE (currently %d)\n\n", MAX_PREDICATES_TABLE); exit( 1 ); } gpredicates_table[gpredicates_table_size] = ggoal_reached_name; garity[gpredicates_table_size] = 0; gpredicates_table_size++; if ( gnum_relevant_facts == MAX_RELEVANT_FACTS ) { printf("\nincrease MAX_RELEVANT_FACTS! (current value: %d)\n\n", MAX_RELEVANT_FACTS); exit( 1 ); } tmp = new_RelevantFact( NULL ); tmp->predicate = gpredicates_table_size - 1; grelevant_facts[gnum_relevant_facts++] = tmp; /* adjust the vector length to additional fact */ gft_vector_length = ( ( int ) gnum_relevant_facts / gcword_size ); if ( ( gnum_relevant_facts % gcword_size ) > 0 ) gft_vector_length++; /* now make an operator for each disjunkt */ for ( i = gcode_goal_state->sons; i; i = i->next ) { tmpop = new_BitOperator( ggoal_reached_name ); tmpop->num_vars = 0; if ( i->connective != AND ) { if ( i->connective == NOT ) { make_entry_in_FactInfo( &(tmpop->n_preconds), i->sons->var ); } else { make_entry_in_FactInfo( &(tmpop->p_preconds), i->var ); } } else { for ( l = i->sons; l; l = l->next ) { if ( l->connective == NOT ) { make_entry_in_FactInfo( &(tmpop->n_preconds), l->sons->var ); } else { make_entry_in_FactInfo( &(tmpop->p_preconds), l->var ); } } } tmpop->unconditional = new_effect(); make_entry_in_FactInfo( &(tmpop->unconditional->p_effects), gnum_relevant_facts-1 ); tmpop->next = gbit_operators; gbit_operators = tmpop; gnum_bit_operators++; if ( gcmd_line.display_info == 103 ) { printf("\ngoal disjunct operator reads as follows:"); print_BitOperator( gbit_operators ); } } /* finally, we make sure that our only goal is to achieve * the new GOAL-REACHED fact */ make_entry_in_FactInfo( &tpos, gnum_relevant_facts-1 ); } gbit_goal_state = new_fact_info_pair( tpos, tneg ); tpos = new_FactInfo(); tneg = new_FactInfo(); /* initial state can be empty, or simplified to TRU */ if ( gcode_initial_state && gcode_initial_state->connective != TRU ) { if ( gcode_initial_state->connective != AND ) { make_entry_in_FactInfo( &tpos, gcode_initial_state->var ); } else { for ( i = gcode_initial_state->sons; i; i = i->next ) { make_entry_in_FactInfo( &tpos, i->var ); } } } for ( j = 0; j<gnum_relevant_facts; j++ ) { if ( !get_bit( tpos->vector, gft_vector_length, j ) ) { make_entry_in_FactInfo( &tneg, j ); } } gbit_initial_state = new_fact_info_pair( tpos, tneg ); if ( gcmd_line.display_info == 103 ) { printf("\nbit coded initial state reads:"); printf("\npositive"); print_FactInfo( gbit_initial_state->positive ); printf("\nnegative"); print_FactInfo( gbit_initial_state->negative ); printf("\nbit coded goal state reads:"); printf("\npositive"); print_FactInfo( gbit_goal_state->positive ); printf("\nnegative"); print_FactInfo( gbit_goal_state->negative ); }}int get_bit( BitVector *vec, int vec_len, int pos ){ return (vec[pos / gcword_size] & (1 << (pos % gcword_size)));}void generate_BitOperators( CodeOperator *op ){ int i, mm; BitOperator *tmp, *tmp2; CodeNode *n, *j, *k, *l; Effect *tef, *ttt; tmp = new_BitOperator( op->name ); tmp->num_vars = op->num_vars; for ( i=0; i<MAX_VARS; i++ ) { tmp->inst_table[i] = op->inst_table[i]; } if ( op->conditionals ) { for ( j = op->conditionals->sons; j; j = j->next ) { if ( !(j->sons) || j->sons->connective == TRU ) { if ( !(tmp->unconditional) ) { tmp->unconditional = new_Effect(); } make_effect_entries( &(tmp->unconditional), j->sons->next ); continue; } dnf( j->sons ); if ( j->sons->connective != OR ) { tef = new_Effect(); if ( j->sons->connective != AND ) { if ( j->sons->connective == NOT ) { make_entry_in_FactInfo( &(tef->n_conds), j->sons->sons->var ); } else { make_entry_in_FactInfo( &(tef->p_conds), j->sons->var ); } } else { for ( k = j->sons->sons; k; k = k->next ) { if ( k->connective == NOT ) { make_entry_in_FactInfo( &(tef->n_conds), k->sons->var ); } else { make_entry_in_FactInfo( &(tef->p_conds), k->var ); } } } /* conditions finished; see wether we got that already */ for ( ttt = tmp->conditionals; ttt; ttt = ttt->next ) { for ( mm = 0; mm < gft_vector_length; mm++ ) { if ( ttt->p_conds->vector[mm] != tef->p_conds->vector[mm] ) { break; } } if ( mm < gft_vector_length ) { continue; } for ( mm = 0; mm < gft_vector_length; mm++ ) { if ( ttt->n_conds->vector[mm] != tef->n_conds->vector[mm] ) { break; } } if ( mm < gft_vector_length ) { continue; } free_effect( tef ); make_effect_entries( &ttt, j->sons->next ); break; } if ( ttt ) { continue; } make_effect_entries( &tef, j->sons->next ); tef->next = tmp->conditionals; tmp->conditionals = tef; continue;/* finished with effect whose conds where != OR */ } for ( k = j->sons->sons; k; k = k->next ) { tef = new_Effect(); if ( k->connective != AND ) { if ( k->connective == NOT ) { make_entry_in_FactInfo( &(tef->n_conds), k->sons->var ); } else { make_entry_in_FactInfo( &(tef->p_conds), k->var ); } } else { for ( l = k->sons; l; l = l->next ) { if ( l->connective == NOT ) { make_entry_in_FactInfo( &(tef->n_conds), l->sons->var ); } else { make_entry_in_FactInfo( &(tef->p_conds), l->var ); } } } /* conditions finished; see wether we got that already */ for ( ttt = tmp->conditionals; ttt; ttt = ttt->next ) { for ( mm = 0; mm < gft_vector_length; mm++ ) { if ( ttt->p_conds->vector[mm] != tef->p_conds->vector[mm] ) { break; } } if ( mm < gft_vector_length ) { continue; } for ( mm = 0; mm < gft_vector_length; mm++ ) { if ( ttt->n_conds->vector[mm] != tef->n_conds->vector[mm] ) { break; } } if ( mm < gft_vector_length ) { continue; } free_effect( tef ); make_effect_entries( &ttt, j->sons->next ); break; } if ( ttt ) { continue; } /* a bit INEFFICIENT... could also do effect entries only one time * and then copy that for each disjunct */ make_effect_entries( &tef, j->sons->next ); tef->next = tmp->conditionals; tmp->conditionals = tef; } } /* identical effects are now completely merged */ } /* check if the overall merged unconditional effects are contradictory */ if ( tmp->unconditional ) { for ( i = 0; i < gft_vector_length; i++ ) { if ( tmp->unconditional->p_effects->vector[i] & tmp->unconditional->n_effects->vector[i] ) { return; } } } if ( !op->preconds || op->preconds->connective == TRU ) { tmp->next = gbit_operators; gbit_operators = tmp; gnum_bit_operators++; if ( gcmd_line.display_info == 103 ) { printf("\nbit mapped operator reads as follows:"); print_BitOperator( gbit_operators ); } return; } dnf( op->preconds ); n = op->preconds; if ( n->connective != OR ) { if ( n->connective != AND ) { if ( n->connective == NOT ) { make_entry_in_FactInfo( &(tmp->n_preconds), n->sons->var ); } else { make_entry_in_FactInfo( &(tmp->p_preconds), n->var ); } } else { for ( k = n->sons; k; k = k->next ) { if ( k->connective == NOT ) { make_entry_in_FactInfo( &(tmp->n_preconds), k->sons->var ); } else { make_entry_in_FactInfo( &(tmp->p_preconds), k->var ); } } } tmp->next = gbit_operators; gbit_operators = tmp; gnum_bit_operators++; if ( gcmd_line.display_info == 103 ) { printf("\nbit mapped operator reads as follows:"); print_BitOperator( gbit_operators ); } return; } for ( k = n->sons; k; k = k->next ) { tmp2 = new_BitOperator( op->name ); tmp2->num_vars = op->num_vars; for ( i=0; i<MAX_VARS; i++ ) { tmp2->inst_table[i] = op->inst_table[i]; } tmp2->unconditional = copy_effects( tmp->unconditional ); tmp2->conditionals = copy_effects( tmp->conditionals ); if ( k->connective != AND ) { if ( k->connective == NOT ) { make_entry_in_FactInfo( &(tmp2->n_preconds), k->sons->var ); } else { make_entry_in_FactInfo( &(tmp2->p_preconds), k->var ); } } else { for ( l = k->sons; l; l = l->next ) { if ( l->connective == NOT ) { make_entry_in_FactInfo( &(tmp2->n_preconds), l->sons->var ); } else { make_entry_in_FactInfo( &(tmp2->p_preconds), l->var ); } } } tmp2->next = gbit_operators; gbit_operators = tmp2; gnum_bit_operators++; if ( gcmd_line.display_info == 103 ) { printf("\nbit mapped operator reads as follows:"); print_BitOperator( gbit_operators ); } } free_BitOperator( tmp );}void make_entry_in_FactInfo( FactInfo **f, int index ){ int uid_block; unsigned int uid_mask; Integers *i; if ( index < 0 ) { /* can happen in effects: facts that are deleted, but not contained * in the initial state and never added. */ return; } uid_block = index / gcword_size; uid_mask = 1 << ( index % gcword_size ); i = new_integers( index ); (*f)->vector[uid_block] |= uid_mask; i->next = (*f)->indices; (*f)->indices = i;}void make_effect_entries( Effect **e, CodeNode *n ){ CodeNode *j; if ( n->connective != AND ) { if ( n->connective == NOT ) { make_entry_in_FactInfo( &((*e)->n_effects), n->sons->var ); } else { make_entry_in_FactInfo( &((*e)->p_effects), n->var ); } } else { for ( j=n->sons; j; j = j->next ) { if ( j->connective == NOT ) { make_entry_in_FactInfo( &((*e)->n_effects), j->sons->var ); } else { make_entry_in_FactInfo( &((*e)->p_effects), j->var ); } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -