




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
程序代码程序代码 include include include include include include include define MAX 100 define maxD 99999 class CFixedMap struct Coordinate int x int y int num 记录点的结构体 struct combp int x1 y1 int x2 y2 连通点坐标 struct Combname int num1 int num2 连通点名 public int mVexNum 顶点数 int mEdgNum 边数 double mMatrix MAX MAX 邻接矩阵 Combname comb MAX 连通点名 combp cp MAX 连通点坐标 Coordinate mVexs MAX 顶点集合 int getx int n1 int gety int n2 void Input 以文件方式输入地图信息 void ShowMap easyx 显示地图 int CFixedMap getx int n1 int x 0 for int i 0 i mVexNum i if n1 mVexs i num x mVexs i x return x int CFixedMap gety int n2 int y 0 for int i 0 i mVexNum i if n2 mVexs i num y mVexs i y return y void CFixedMap Input int panju char fname 10 map2 txt cout panju if panju 2 cout fname ifstream file fname char use1 100 char use2 100 char use3 100 char use4 100 use 数组用来储存提示信息 file use1 file mVexNum 端点个数 file use2 file mEdgNum 边数 file use3 for int i 0 i mVexs i num mVexs i x mVexs i y file use4 for i 0 i comb i num1 comb i num2 file close easyx 显示地图 void CFixedMap ShowMap initgraph 800 600 SHOWCONSOLE NOCLOSE 初始化绘图环境 setbkcolor WHITE 设置背景色 cleardevice 用背景色清空屏幕 setfillcolor BLACK 设置填充色 画顶点 for int i 0 i mVexNum i fillcircle mVexs i x mVexs i y 5 settextcolor BLACK char s MAX sprintf s d i 1 outtextxy mVexs i x 10 mVexs i y 20 s 给实际连通的顶点连线 setlinecolor RGB 0 0 0 setlinestyle PS SOLID 6 NULL 0 for i 0 i mEdgNum i cp i x1 getx comb i num1 cp i y1 gety comb i num1 cp i x2 getx comb i num2 cp i y2 gety comb i num2 line cp i x1 cp i y1 cp i x2 cp i y2 class CPathPlan public CFixedMap public int path MAX 存放最后一个点 double dist MAX 存放路径距离 int v0 起始点 int route 40 路径 int rnum 路径顶点数 Coordinate rpoints MAX 路径点集 void MaptoGraph void Dijstra void Putpath void CPathPlan MaptoGraph rnum 0 int a b x y for int i 0 i mVexNum i for int j 0 j mVexNum j if i j mMatrix i j 0 else mMatrix i j maxD for i 0 i mEdgNum i if comb i num1 a comb i num1 1 b comb i num2 1 x mVexs a x mVexs b x y mVexs a y mVexs b y mMatrix a b sqrt x x y y mMatrix b a sqrt x x y y void CPathPlan Dijstra cout v0 v0 int s MAX int v int i int j int w double min for v 0 v mVexNum v 初始化 S dist path s v 0 0 表示未求出最短路径 dist v mMatrix v0 v 开始时假定为最短路径 if dist v maxD 直达情况 else path v 1 无直达路径 dist v0 0 初始时 v0 属于 s 集 v0 到 v0 路径最短 s v0 1 for i 1 i mVexNum i 假设由一个中转点到达会近些 验证 再假设由两个中转点 到达会近些 验证 穷举 min maxD for w 0 w mVexNum w 找一个最近到的点 下标装入 v if s w 0 经点 w 中转 min dist w s v 1 将 v 并入 S 由 v0 到达 v 点最短距离为 min 假设由 v0 到 v 再由 v 到其余各点 更新当前最后一个点及距离 for j 0 j mVexNum j if s j 0 path j v 点的序号 void CPathPlan Putpath int opp 20 int z int i 0 cout z z int next ofstream file2 fops txt if dist z maxD 终点 next path z 第一个点 while next v0 opp i mVexs next num next path next 下一个点 opp i mVexs v0 num file2 路径长度为 dist z n 起点 v0 和最短路径 else if z v0 无路径 file2 mVexs z num mVexs v0 num no path n for int j 0 j i 1 j route j opp i j file2 路径为 for j 0 j i j file2 route j rnum i 1 file2 route i file2 close for i 0 i rnum i rpoints i x getx route i rpoints i y gety route i rpoints i num route i class CAGV int speed AGV 速度 int width AGV 宽度 int length AGV 长度 public CAGV int getl int getw int gets CAGV CAGV int panju cout panju speed 8 width 6 length 6 if panju 2 cout length cout width cout speed int CAGV getl return length int CAGV getw return width int CAGV gets return speed class CAGVShow public CPathPlan public CAGV public define k abs y2 y1 abs x1 x2 int a b c d int x1 x2 y1 y2 int i j int l w s void show void CAGVShow show l getl w getw s 11 gets for int o 0 ox1j x2 x1 j a x1 j l b y1 j k w c x1 j l d y1 j k w setfillcolor RGB 0 0 0 rectangle a b c d clearrectangle a 1 b k c d k setlinecolor RED line x1 j y1 j k x2 y2 setlinecolor GREEN line x1 y1 x1 j y1 j k if j 2 0 setfillcolor RGB 255 255 0 circle x2 y2 5 Sleep s if x2 x1j x1 x2 j a x1 j l b y1 j k w c x1 j l d y1 j k w setfillcolor RGB 0 0 0 rectangle a b c d clearrectangle a 1 b k c d k setlinecolor RED line x1 j y1 j k x2 y2 setlinecolor GREEN line x1 y1 x1 j y1 j k if j 2 0 setfillcolor RGB 255 255 0 circle x2 y2 5 Sleep s if x2y1 for j 1 jx1jx1 for j 1 j x2 x1 j setfillcolor RGB 0 0 0 rectangle x1 j l y1 w x1 j l y1 w clearrectangle x1 j l 1 y1 w x1 j l 1 y1 w setlinecolor RED line x1 j y1 x2 y2 setlinecolor GREEN line x1 y1 x1 j y1 if j 2 0 setfillcolor RGB 255 0 255 circle x2 y2 5 Sleep s if x2 x1 for j 1 jy1 for j 1 j y2 y1 j setfillcolor BLUE rectangle x1 l y1 j w x1 l y1 j w setfillcolor WHITE rectangle x1 y1 j w 1 x1 1 y1 j 1 w clearrectangle x1 l 1 y1 j 1 w x1 l 1 y1 j 1 w setlinecolor RED line x1 y1 j x2 y2 setlinecolor GREEN line x1 y1 x1 y1 j if j 2 0 setfillcolor RGB 255 255 0 circle x2 y2 5 Sleep s if y2 y1 for j 1 j y1 y2 j setfillcolor BLUE rectangle x1 l y1 j w x1 l y1 j w setfillcolor WHITE rectangle x1 y1 j w 1 x1 1 y1 j 1 w clearrectangle x1 l 1 y1 j 1 w x1 l 1 y1 j 1 w setlinecolor RED line x1 y1 j x2 y2 setlinecolor GREEN line x1 y1 x1 y1 j if j 2 0 setfillcolor RGB 255 255 0 circle x2 y2 5 Sleep s cout 成功显示 n getch 按任意键继续 closegraph 关闭图形界面 void main CAGVShow a int panju a Input cout panju if panju 1 for int i 0 i 20 i a ShowMap a MaptoGraph a Dijstra a Putpath a show panju 0 cout panju if panju 1 break else a ShowMap a MaptoGraph a Dijstra a Putpath a show 相关文件 map2 txt 点的个数 输入所有数据前请换行 16 连线条数 26 依次输入所有点的编号 x y 坐标 用空格隔开 1 50 50 2 250 50 3 550
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025养老护理院面试题及答案
- 2025年生活垃圾分类知识测试题及答案
- 2025年通信技术笔试模拟题及答案
- 2025年无人机操控员试题及答案
- 2025年汽车维修技术认证考试题库及备考策略
- 2025-2030中国药用安瓿瓶市场供给平衡性分析及投资效益报告
- 2025年炼钢工艺初级面试题及答案集合
- 2025年心理咨询师初级考试题库及参考答案
- 2025年初中音乐特岗教师教学设计与实施能力测试模拟题集详解
- 2025年无人机高级维修师笔试模拟题及答案
- 2025企业单位网络与信息安全事件应急预案
- 2025-2026学年人教版(2024)小学数学三年级上册教学计划及进度表
- 2025年人工流产试题及答案
- 2025年文物保护工程从业资格考试(责任工程师·近现代重要史迹及代表性建筑)历年参考题库含答案详解(5套)
- 社保补助协议书范本
- 2025年调度持证上岗证考试题库
- 小区物业薪酬制度方案(3篇)
- 2025年计算机一级考试题库操作题及答案
- 高血压防治指南
- 2026届潍坊市达标名校中考联考语文试卷含解析
- (新教材)2025年秋期部编人教版二年级上册小学语文全册教案(教学设计)(新课标核心素养教案)
评论
0/150
提交评论