输入: 城市坐标文件,需导航两个城市编号
输出:路径序列就路径长度
2.1 试采用最短路径算法实现,分析其存在的主要问题;
2.2 设计适当的启发式策略,采用A算法实现
最短路径:
#include <cstdio>//with this method,we can find all the shortest ways from the start point to any other points.
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <set>
#include <cstring>
using namespace std;//the problem of this shortest-path method is that you must find the best way of every other point.Tihs will be very complex when the amount of points increase.
#define N 13
#define BG 1100000000
double pmap[N][N];//point map
char sp,tp;
int sn,tn;
struct point{
int num;
double dist;
int pnum;
bool operator < (const point &a)const
{
return a.dist>dist;//order the set by dist
}
};
multiset<point>qo;//balace tree~,every time we should find the point wihch is closest to the start point quickly.
multiset<point>qc;//to find the whole
multiset<point>::iterator it;
point inp,outp;
double d[N];
int p[N];//p[N] stores the best parent of every point
void input()//the format of the first 8 lines is"cityname x y",and the following lines are the cities which are connected.
{
cin>>sp>>tp;
ifstream OpenFile("/Users/liuyuhan/Desktop/Blue_Home/MyTest/AMusic/LineLandMail/CityPoints.txt");
string ch;
int cityx[N],cityy[N];
int i;
while(!OpenFile.eof