Thuật toán LC-BFSLeast Cost -Breadth First Search=tìm kiếm chi phí ít nhất theo chiều Rộng trước tiên bạn phải tạo 1 file input.txt trong ổ đĩa C:/... q.QMax=MaxItems; q.QNumItems=0;
Trang 1Thuật toán LC-BFS(Least Cost -Breadth First Search=tìm kiếm chi phí ít nhất theo chiều Rộng)
trước tiên bạn phải tạo 1 file input.txt trong ổ đĩa C:/
Trang 2q.QMax=MaxItems;
q.QNumItems=0;
q.QFront=q.QRear= -1; //-1 tuc' la` chua co phan tu
nao trong Quenue
int IsQueueFull(const QUEUE &q)//kiem tra hang` doi co'
day` hay chua
int DeQueue(QUEUE &q , int newitem)//lay 1 pt o dau
Queue,co the lam Queue thay doi
Trang 3
int EnQueue(QUEUE &q , int &outitem)//them 1 pt o cuoi
Queue,co the lam Queue thay doi
Trang 6if((g.A[s][i]!=0 && g.Previous[i]==-1) ||
(g.A[s][i]!=0 && k[s] +g.A[s][i]<k[i]))
Trang 8LC BFS là thuật toán nâng cấp cua BFS
tạo 1 file input.txt nhu thaut toan LCBFS
// BFS.cpp : Defines the entry point for the console
Trang 9int InitQueue(QUEUE &q,int MaxItems)
Trang 15printf("\n\n");
}
Thuật Toán UCS
// UCS.cpp : Defines the entry point for the console
typedef struct map DoThi;
//cac ham dc khai bao
//void Doc_Mang(DoThi &d,char *fn,int &start,int &end) ;
//void Khoi_Tao(DoThi &d);
//void ThanhDong_UCS(DoThi &d,int start,int end);
int Path_ThanhDong_UCS(DoThi d,char *fn,int start,int
end);
// -//
//ham void main()
// -//
//ham doc file input.txt
void Doc_Mang(DoThi &d,char *fn,int &start,int &end)
Trang 16//ham khoi tao
void Khoi_Tao(DoThi &d)
//ham thuat toan UCS
void ThanhDong_UCS(DoThi &d,int start,int end)
Trang 17//ham tim tim duong dj tren thuat toan UCS
int Path_ThanhDong_UCS(DoThi d,char*fn,int start,int end)
Trang 19typedef node *pnode;
void createStack(pstack &S);
void insertTop(pstack &S, int x);
void getTop(pstack &S, int &t);
void insert(pnode &H, int x);
void outputMatrix(Graph A);
void output(pnode H);
void readFile(char *path, Graph &A);
int isScalar(Graph A);//1: Yes - 0: No
int calculateOrderTip(Graph A, int o);
int isVisited(pnode C, int t);//1: Yes - 0: No
void findNextDoor(int Tip, Graph A, pnode &H);
void DFS(Graph A);
cout<<"Bac cua dinh la: "<<calculateOrderTip(A,x);
cout<<"\nDuyet Do thi theo DFS: ";
Trang 22int calculateOrderTip(Graph A,int o)
Trang 23findNextDoor(temp,A,H);//Finf all Tip
next-door to the current Tip
Trang 25int nhapfile(dothi &l,char *fn,TT &start,TT &end)
Trang 26int dua_vao_hangdoi(QUEUE &Q,TT &x)