转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
最短路径(校园导游)的简单算法         ★★★★

最短路径(校园导游)的简单算法

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3078 更新时间:2009/4/23 18:26:31
begin
if ((flag[w]=false) and (dist[w]<min)) then
begin
min:=dist[w];
v:=w;
end;//if dist[w]<min
end;//for w
min:=100;
if dist[v]=100 then
showmessage(''''dist[v]=100!!'''')
else
begin//////
flag[v]:=true;
for k:=1 to 7 do
begin
if ((flag[k]=false) and(dist[v]+map[v][k]<dist[k]))then
begin
dist[k]:=dist[v]+map[v][k];
road[k,8]:=road[k,8]+1;
for l:=1 to road[v,8] do
road[k,l]:=road[v,l];
road[k,road[k,8]+1]:=v;

end;//if ((flag[k]=false) and(dist[v]+map[v][k]<dist[k])then
end;//for k
end;//////esle

end;//for j:=1 to 7 do  over
//for i:=1 to 7 do

//listbox1.Items.Add(floattostr(dist[i]));

end;//procedure over

procedure TForm2.FormCreate(Sender: TObject);
begin
//request:=4;
map[1,1]:=0;
map[1,2]:=2.5;
map[1,3]:=100;
map[1,4]:=8;
map[1,5]:=4;
map[1,6]:=100;
map[1,7]:=100;
//
map[2,1]:=2.5;
map[2,2]:=0;
map[2,3]:=1.5;
map[2,4]:=6;
map[2,5]:=2;
map[2,6]:=100;
map[2,7]:=100;
//
map[3,1]:=100;
map[3,2]:=1.5;
map[3,3]:=0;
map[3,4]:=5;
map[3,5]:=100;
map[3,6]:=100;
map[3,7]:=100;
//
map[4,1]:=8;
map[4,2]:=8;
map[4,3]:=5;
map[4,4]:=0;
map[4,5]:=4.2;
map[4,6]:=100;
map[4,7]:=100;
//
map[5,1]:=4;
map[5,2]:=2;
map[5,3]:=100;
map[5,4]:=4.2;
map[5,5]:=0;
map[5,6]:=1.5;
map[5,7]:=2;
//
map[6,1]:=100;
map[6,2]:=100;
map[6,3]:=100;
map[6,4]:=100;
map[6,5]:=1.5;
map[6,6]:=0;
map[6,7]:=1;
//
map[7,1]:=100;
map[7,2]:=100;
map[7,3]:=100;
map[7,4]:=100;
map[7,5]:=2;
map[7,6]:=1;
map[7,7]:=0;
end;


procedure TForm2.bsSkinButton2Click(Sender: TObject);
//var
//i:integer;
begin

form5.Show;
end;


procedure TForm2.bsSkinButton1Click(Sender: TObject);
begin
form3.l1.Caption:=floattostr(dist[1])+''''m   '''';
form3.l2.Caption:=floattostr(dist[2])+''''m   '''';
form3.l3.Caption:=floattostr(dist[3])+''''m   '''';

form3.l5.Caption:=floattostr(dist[4])+''''m   '''';
form3.l6.Caption:=floattostr(dist[5])+''''m   '''';
form3.l7.Caption:=floattostr(dist[6])+''''m   '''';
form3.l8.Caption:=floattostr(dist[7])+''''m   '''';
form3.Show;
end;

end.


unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, bsSkinData, BusinessSkinForm, StdCtrls, bsSkinCtrls, jpeg,
  ExtCtrls;

type
  TForm3 = class(TForm)
    bsBusinessSkinForm1: TbsBusinessSkinForm;
    bsSkinData1: TbsSkinData;
    bsCompressedStoredSkin1: TbsCompressedStoredSkin;
    bsSkinStdLabel1: TbsSkinStdLabel;
    bsSkinStdLabel2: TbsSkinStdLabel;
    bsSkinStdLabel3: TbsSkinStdLabel;
    bsSkinStdLabel4: TbsSkinStdLabel;
    bsSkinStdLabel5: TbsSkinStdLabel;
    bsSkinStdLabel6: TbsSkinStdLabel;
    bsSkinStdLabel7: TbsSkinStdLabel;
    bsSkinStdLabel8: TbsSkinStdLabel;
    damen: TImage;
    lanqiou: TImage;
    ydc: TImage;
    jxl: TImage;
    gongyu: TImage;
    st: TImage;
    xyf: TImage;
    l1: TbsSkinStdLabel;
    l2: TbsSkinStdLabel;
    l3: TbsSkinStdLabel;
    l5: TbsSkinStdLabel;
    l6: TbsSkinStdLabel;
    l7: TbsSkinStdLabel;
    l8: TbsSkinStdLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

end.
unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, bsSkinData, BusinessSkinForm, StdCtrls, bsSkinCtrls, CheckLst;

type
  TForm5 = class(TForm)
    bsSkinStdLabel1: TbsSkinStdLabel;
    bsBusinessSkinForm1: TbsBusinessSkinForm;
    bsSkinData1: TbsSkinData;
    bsCompressedStoredSkin1: TbsCompressedStoredSkin;
    rg: TbsSkinRadioGroup;
    word: TbsSkinLabel;
    lab: TCheckListBox;
    procedure rgChecked(Sender: TObject);
    procedure rgClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
  request2:integer;
    { Public declarations }
  end;
mapinfo=array[1..7,1..7]of real;
roadinfo=array[1..7,1..8]of integer;
flagarray=array[1..7]of bool;
distinfo=array[1..7]of real;

var
Form5: TForm5;
request:integer;
map:mapinfo;
road:roadinfo;
flag:flagarray;
dist:distinfo;
implementation

uses Unit2;

{$R *.dfm}

procedure TForm5.rgChecked(Sender: TObject);
var
m,n:integer;
v,i,j,w,k,l:integer;
min: real;
begin
for m:=0 to rg.ComponentCount-1 do
if (rg.Controls[m]as tbsSkinCheckRadioBox).Checked then
n:=m;

//form3.Show;

form5.lab.Items.clear;

for i:=1 to road[n+1,8] do
begin
//大门运动场 教学大楼 公寓 洗浴中心
case road[n+1,i] of
1:form5.lab.Items.Add(''''南校区大门 '''') ;
2:form5.lab.Items.Add(''''篮球场 '''') ;
3:form5.lab.Items.Add(''''运动场 '''') ;
4:form5.lab.Items.Add(''''教学大楼   '''') ;
5:form5.lab.Items.Add(''''公寓 '''') ;
6:form5.lab.Items.Add(''''食堂 '''') ;
7:form5.lab.Items.Add(''''洗浴中心 '''') ;
end;


end;//for i

//listbox1.Items.Add(floattostr(dist[i]));

end;//procedure over

procedure TForm5.rgClick(Sender: TObject);
var
m,n:integer;
v,i,j,w,k,l:integer;
min: real;
begin
for m:=0 to rg.ComponentCount-1 do
if (rg.Controls[m]as tbsSkinCheckRadioBox).Checked then
begin
n:=m;
//form5.Caption:=inttostr(n);


end;
//form3.Show;

form5.lab.Items.clear;

for i:=1 to 7 do
begin
//师大南校区大门安师大南校区大门运动场 教学大楼 公寓 洗浴中心
case road[n+1,i] of
1:form5.lab.Items.Add(''''师大南校区大门 '''') ;
2:form5.lab.Items.Add(''''篮球场 '''') ;
3:form5.lab.Items.Add(''''运动场 '''') ;
4:form5.lab.Items.Add(''''教学大楼   '''') ;
5:form5.lab.Items.Add(''''公寓 '''') ;
6:form5.lab.Items.Add(''''食堂 '''') ;
7:form5.lab.Items.Add(''''洗浴中心 '''') ;
end;

end;//for i
//lab.Items.IndexOf()
case n+1 of
1:
begin
if lab.Items.IndexOf(''''师大南校区大门 '''')=-1 then
form5.lab.Items.Add(''''安师大南校区大门 '''') ;
end;
2:
begin
if lab.Items.IndexOf(''''篮球场 '''')=-1 then
form5.lab.Items.Add(''''篮球场 '''') ;
end;
3:
begin
if lab.Items.IndexOf(''''运动场 '''')=-1 then

form5.lab.Items.Add(''''运动场 '''') ;
end;
4:
begin
if lab.Items.IndexOf(''''教学大楼   '''')=-1 then
form5.lab.Items.Add(''''教学大楼   '''') ;
end;
5:
begin
if lab.Items.IndexOf(''''公寓 '''')=-1 then
form5.lab.Items.Add(''''公寓 '''') ;
end;
6:
begin
if lab.Items.IndexOf(''''食堂 '''')=-1 then
form5.lab.Items.Add(''''食堂 '''') ;
end;
7:
begin
if lab.Items.IndexOf(''''洗浴中心 '''')=-1 then
form5.lab.Items.Add(''''洗浴中心 '''') ;
end;
end;


//listbox1.Items.Add(floattostr(dist[i]));

end;//procedure over


procedure TForm5.FormCreate(Sender: TObject);
begin
//request:=form2.request;

map[1,1]:=0;
map[1,2]:=2.5;
map[1,3]:=100;
map[1,4]:=8;
map[1,5]:=4;
map[1,6]:=100;
map[1,7]:=100;
//
map[2,1]:=2.5;
map[2,2]:=0;
map[2,3]:=1.5;
map[2,4]:=6;
map[2,5]:=2;
map[2,6]:=100;
map[2,7]:=100;
//
map[3,1]:=100;
map[3,2]:=1.5;
map[3,3]:=0;
map[3,4]:=5;
map[3,5]:=100;
map[3,6]:=100;
map[3,7]:=100;
//
map[4,1]:=8;
map[4,2]:=8;
map[4,3]:=5;
map[4,4]:=0;
map[4,5]:=4.2;
map[4,6]:=100;
map[4,7]:=100;
//
map[5,1]:=4;
map[5,2]:=2;
map[5,3]:=100;
map[5,4]:=4.2;
map[5,5]:=0;
map[5,6]:=1.5;
map[5,7]:=2;
//
map[6,1]:=100;
map[6,2]:=100;
map[6,3]:=100;
map[6,4]:=100;
map[6,5]:=1.5;
map[6,6]:=0;
map[6,7]:

上一页  [1] [2] [3]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台