AI-路径导航(最短路径算法 and A算法)

该博客探讨了AI路径导航问题,通过实现最短路径算法并分析其局限性,然后提出使用A*算法进行改进,以找到更优路径。内容涉及城市坐标文件处理,从两个城市编号出发,输出路径序列及路径长度。
摘要由CSDN通过智能技术生成

输入: 城市坐标文件,需导航两个城市编号

输出:路径序列就路径长度

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值