修改文章
标题:
内容:
Let me have a try:) First, we should have a data structure so that we could store the actions and states. let's suppose they are from A by Boat to C. So.... DEF. int A[2],B[2],C[2],w number of common people is 1*n, stored in x[0] number of silly is -1*n, in x[1] w=1 means Boat is at A, w=2 means Boat is at C So, we have constraints: 1,x[0]+x[1]>=0 UNLESS x[0]=0 2,abs(B[0])+abs(B[1])
=0 && x[1]<=0 Initial state: A[0]=n A[1]=-n B[0]=B[1]=C[0]=C[1]=0 Goal state: C[0]=n C[1]=-n B[0]=B[1]=A[0]=A[1]=0 Action: 1. Precondition: w=1 A[0]->B[0], A[1]->B[1];B[0]->C[0], B[1]->C[1];w=0 (Constraints..1234) 2. Precondition: w=2 C[0]->B[0], C[1]->B[1];B[0]->A[0], B[1]->A[1];w=0 (Constraints..1234) (NOTE: Action 1,2 in fact contains a lot of possible actions, we just split them into two main sets A1, A2) Algorithm: (In Thinking...) Basical ideas as below: list<-{A,B,C(state)}; while (list!=empty){ //not necessarily being null s<-Head(list); list<-Rest(list); if (s is goal) return; else while (Action!=empty ){ //Action is a set in which there are all the actions could apply on this state act<-Head(Action); Action<-Rest(Action); newstate<-apply(act); list<-prepend(newstate, list); } } return SORRY It's Depth-First algorithm, which could find the answer quickly if there is one, but may go on and on if there is no answer or there is a circle in state graph:) Better algortihms are not understood yet, but I'm trying. /////////////////////////////////////////////////////////////////////////////// Any mistake please be put up once you find............(Kan tie yao hui tie
) (more contents should be put up in several days) To be continued................ [此贴被 月之御者(kert_t8) 在 10月03日03时40分 编辑过]
表情:
返回