📄 pddl.c
字号:
*********************************************************************/voidall_the_quantifiers_top_pl (PlNode * plnode){ PlNode * i_pl , * j_pl,*k_pl,* l_pl ,*new_pl,*m_pl,*dummy_quantifier_list; begin_of_function_pl("All_the_quantifiers_top_pl",plnode); l_pl=new_pl_node(DUMMY); l_pl->next=plnode->sons; plnode->sons=l_pl; j_pl=l_pl; i_pl=l_pl->next; dummy_quantifier_list=new_pl_node(DUMMY); k_pl=dummy_quantifier_list; while (i_pl!=NULL) { nots_down_quantifiers_up_pl(i_pl); switch (i_pl->connective) { case NOT: case ATOM: case AND: case OR:/* will be distributed later */ j_pl=j_pl->next; i_pl=j_pl->next; break; case ALL: k_pl=move_quantifier_pl(j_pl,k_pl); i_pl=j_pl->next; break; case EX: k_pl=move_quantifier_pl(j_pl,k_pl); i_pl=j_pl->next; break; default: spec_error("All_the_quantifiers_top_pl"); } } /* remove dummy 1 */ m_pl=plnode->sons; plnode->sons=m_pl->next; free(m_pl); /* remove dummy 2&3 */ if (NULL!=dummy_quantifier_list->sons) { new_pl=copy_pl_node(plnode); new_pl->sons=plnode->sons; k_pl->sons=new_pl; plnode->sons=dummy_quantifier_list->sons->sons; plnode->connective=dummy_quantifier_list->sons->connective; plnode->atom=dummy_quantifier_list->sons->atom; free(dummy_quantifier_list->sons); free(dummy_quantifier_list); } else { free(dummy_quantifier_list); } end_of_function_pl("All_the_quantifiers_top_pl",plnode);}/******************** pddl_inner ***************************//********************************************************************* * This function steps through next list and appends (real) copies * of to_copy_code after the last element of the son list; * all must have sons ;!j_code is changed, returns last of parents list * INPUT j_code: to all son lists of this node a real copy of * (the tree below/including) to_copy_code * to_copy_code: the node/tree to be copied * OUTPUT codenode: the last element of the parents list * (the next successors of j_code) * USING *********************************************************************/CodeNode *append_following(CodeNode *j_code,CodeNode *to_copy_code){ CodeNode * i_code; do { if (AND!=j_code->connective || NULL==j_code->sons) { spec_error("Append_following"); } for (i_code=j_code->sons ; NULL!=i_code->next ; i_code = i_code->next ) { ; } i_code->next=copy_CodeNode(to_copy_code); i_code->next->next=NULL; i_code->next->sons=deep_copy_CodeTree(to_copy_code->sons); if (NULL!=j_code->next) { j_code=j_code->next; } else { return j_code; } } while (TRUE);}/********************************************************************* * INPUT codenode: AND node, below: ORs, ANDs, Lit * OUTPUT codenode: * [1st layer at the top: OR node if necessary] * [2nd :AND nodes if necessary] * 3rd : Literals * USING *********************************************************************/voiddistribute_ands_ors (CodeNode * codenode){ CodeNode * i_code,*l_code,*m_code;/* Laufvars?l */ CodeNode *tmplist,*tmp; begin_of_function_code("Distribute_ands_ors",codenode); combine_ands_code(codenode); codenode->connective=OR; i_code=codenode->sons; codenode->sons=new_CodeNode(AND); /* dummy */ codenode->sons->sons=new_CodeNode(DUMMY); while (i_code!=NULL) { switch (i_code->connective) { case OR: dnf(i_code); /* ?c gehe zunaechst davon aus, dass oben OR bleibt, spaeter soll auch TRU moeglich sein */ /* ?c muesste egal sein, ob AND oder nicht */ tmplist=new_CodeNode(DUMMY);/* dummy */ m_code=tmplist; for (l_code=i_code->sons;NULL!=l_code;l_code=l_code->next) { if (NULL!=l_code->next) { m_code->next=deep_copy_CodeTree(codenode->sons);/* copylist */ } else { m_code->next=codenode->sons; codenode->sons=tmplist->next; free(tmplist); } m_code=append_following(m_code->next,l_code); } break; case ATOM: case NOT: append_following(codenode->sons,i_code); /* ?c spaeter hier remove p AND not p, im Notfall FAL ergenzen */ break; default: spec_error("Distribute_ands_ors"); } tmp=i_code; i_code=i_code->next; if (NULL!=tmp->sons) { free_CodeNode(tmp->sons); } free(tmp); } for (i_code=codenode->sons;NULL!=i_code;i_code=i_code->next) { tmp=i_code->sons; i_code->sons=i_code->sons->next; free(tmp);/*DUMMY */ combine_ands_code(i_code); } if ((OR==codenode->connective)&&(NULL==codenode->sons->next)) { i_code=codenode->sons; codenode->sons=codenode->sons->sons; codenode->connective=AND; free(i_code); } end_of_function_code("Distribute_ands_ors",codenode);}/********************************************************************* * INPUT codenode: AND node, below: ORs, ANDs, Lit * OUTPUT codenode: * [1st layer at the top: OR node if necessary] * [2nd :AND nodes if necessary] * 3rd : Literals * USING *********************************************************************/voiddistribute_ors_ands (CodeNode * codenode){ CodeNode * i_code,*l_code,*m_code;/* Laufvars?l */ CodeNode *tmplist,*tmp; begin_of_function_code("Distribute_ors_ands",codenode); combine_ands_code(codenode); codenode->connective=AND; i_code=codenode->sons; codenode->sons=new_CodeNode(OR); /* dummy */ codenode->sons->sons=new_CodeNode(DUMMY); while (i_code!=NULL) { switch (i_code->connective) { case AND: dnf(i_code); /* ?c gehe zunaechst davon aus, dass oben OR bleibt, spaeter soll auch TRU moeglich sein */ /* ?c muesste egal sein, ob AND oder nicht */ tmplist=new_CodeNode(DUMMY);/* dummy */ m_code=tmplist; for (l_code=i_code->sons;NULL!=l_code;l_code=l_code->next) { if (NULL!=l_code->next) { m_code->next=deep_copy_CodeTree(codenode->sons);/* copylist */ } else { m_code->next=codenode->sons; codenode->sons=tmplist->next; free(tmplist); } m_code=append_following(m_code->next,l_code); } break; case ATOM: case NOT: append_following(codenode->sons,i_code); break; default: spec_error("Distribute_ors_and"); } tmp=i_code; i_code=i_code->next; if (NULL!=tmp->sons) { free_CodeNode(tmp->sons); } free(tmp); } for (i_code=codenode->sons;NULL!=i_code;i_code=i_code->next) { tmp=i_code->sons; i_code->sons=i_code->sons->next; free(tmp);/*DUMMY */ combine_ands_code(i_code); } if ((AND==codenode->connective)&&(NULL==codenode->sons->next)) { i_code=codenode->sons; codenode->sons=codenode->sons->sons; codenode->connective=OR; free(i_code); } end_of_function_code("Distribute_ors_ands",codenode);}/********************************************************************* * This is the crucial function of the (precondition) pdnf, * it could be called quite often, and should therefore be fast * ( contrary to the other functions of this file ) * INPUT codenode * OUTPUT codenode: max 1 OR, max 1 layer of ands, Literals * USING *********************************************************************/voiddnf (CodeNode * codenode){ CodeNode * i_code; begin_of_function_code("Ands below ors",codenode); switch (codenode->connective) { case AND: distribute_ands_ors(codenode); break; case OR: for (i_code=codenode->sons;NULL!=i_code;i_code=i_code->next) { dnf(i_code); /* ?c spaeter: wegmachen p or not p in tru, if irgendwo tru ret tru */ } combine_ands_code(codenode);/* ors */ break; case ATOM: case NOT: break; default: spec_error("Wrong node in dnf"); printf("\nconnective: %d", codenode->connective); } end_of_function_code("Ands below ors",codenode);}/********************************************************************* * This is the crucial function of the (precondition) pdnf, * it could be called quite often, and should therefore be fast * ( contrary to the other functions of this file ) * INPUT codenode * OUTPUT codenode: max 1 OR, max 1 layer of ands, Literals * USING *********************************************************************/voidcnf (CodeNode * codenode){ CodeNode * i_code; begin_of_function_code("cnf",codenode); switch (codenode->connective) { case AND: distribute_ors_ands(codenode); break; case OR: for (i_code=codenode->sons;NULL!=i_code;i_code=i_code->next) { cnf(i_code); /* ?c spaeter: wegmachen p or not p in tru, if irgendwo tru ret tru */ } combine_ands_code(codenode);/* ands */ break; case ATOM: case NOT: break; default: spec_error("Wrong node in cnf"); printf("\nconnective: %d", codenode->connective); } end_of_function_code("cnf",codenode);} /********************************************************************* * INPUT codenode: AND or OR node * OUTPUT codenode: (same) AND/OR node with all nodes with the same connective * directly below combined to one single AND node * USING *********************************************************************/voidcombine_ands_code ( CodeNode * codenode ){ CodeNode * i_code,*j_code,*this_code; Connective con=codenode->connective; begin_of_function_code("Combine ands",codenode); i_code=new_CodeNode(DUMMY); this_code=codenode->sons; i_code->next=this_code; codenode->sons=i_code; while (this_code !=NULL) { if (this_code->connective==con) { combine_ands_code(this_code); i_code->next=this_code->sons; j_code=this_code->next; free(this_code); this_code=j_code; while (NULL!=i_code->next) { i_code=i_code->next; } } else /* !=AND while */ { i_code->next=this_code; i_code=this_code; this_code=this_code->next; } } /* while */ i_code=codenode->sons->next; free(codenode->sons);/* DUMMY */ codenode->sons=i_code; end_of_function_code("Combine ands",codenode);} /******************** axioms ***************************/Boolsingle_predicate_contained(PlNode * e,PlNode * p)/* searches the first tree e for the predicate p*/{ PlNode * i_pl; switch (e->connective) { case AND: case OR: case WHEN: for (i_pl=e->sons;i_pl!=NULL;i_pl=i_pl->next) { if (single_predicate_contained(i_pl,p)) { return TRUE; } } return FALSE; case ALL: case EX: case NOT: return single_predicate_contained(e->sons,p); case TRU: return FALSE; case ATOM: /* printf("? vergl%s%s\n",e->atom->item,p->atom->item); */ if (SAME == strcmp(e->atom->item,p->atom->item)) { return TRUE; } return FALSE; default: spec_error("single_predicate_contained"); return TRUE; } } Boolany_predicate_contained(PlNode * e,PlNode * p)/* searches the latter tree p for any of the effects in the first tree e */{ PlNode * i_pl; switch (p->connective) { case AND: case OR: case WHEN: for (i_pl=p->sons;i_pl!=NULL;i_pl=i_pl->next) { if (any_predicate_contained(e,i_pl)) { return TRUE; } } return FALSE; case ALL: case EX:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -