• 大小: 97KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: C#
  • 标签: floyd算法  C#  

资源简介

从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按一个公式,构造出矩阵D(1);又用同样地公式由D(1)构造出D(2);……;最后又用同样的公式由D(n-1)构造出矩阵D(n)。矩阵D(n)的i行j列元素便是i号顶点到j号顶点的最短路径长度,称D(n)为图的距离矩阵,同时还可引入一个后继节点矩阵path来记录两点间的最短路径。   采用的是松弛技术,对在i和j之间的所有其他点进行一次松弛。所以时间复杂度为O(n^3);

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace floyd
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int[] a = new int[5 5];
        int[] b = new int[5 5];
        int[] c = new int[5];
        
        public void run(int i)
        {
            for (int k = 0; k < 5; k++)
            {
                if (a[k i - 1] != 0 && a[k i - 1] != -1)
                {
                    c[k] = i;
                }
            }
            for (int k = 0; k < 5; k++)
            {
               
                for(int l=0;l<5;l++)
                {
                    if (a[i - 1 l] != 0 && a[k i - 1] != 0 && a[i - 1 l] != -1 && a[k i - 1] != -1)
                    {
                        if (a[k l] == -1)
                        {
                            a[k l] = a[i - 1 l] + a[k i - 1];
                            if (c[k] != 0)
                            {
                                b[k l] = c[k];
                            }
                            else
                            {
                                b[k l] = i;
                            }
                        }
                        else if ((a[i - 1 l] + a[k i - 1]) < a[k l])
                        {
                            a[k l] = a[i - 1 l] + a[k i - 1];
                            if (c[k] != 0)
                            {
                                b[k l] = c[k];
                            }
                            else
                            {
                                b[k l] = i;
                            }
                        }
                    }
                }
            }
        }


        public void runtest(int k)
        { 
            
            
                for (int i = 0; i < 5; i++)
                    for (int j = 0; j < 5; j++)
                    {
                        if (a[ik]!=-1&&a[kj]!=-1&&a[ik]!=0&&a[kj]!=0&&a[i k] + a[k j] < a[i j])
                        {
                            a[i j] = a[i k] + a[k j];
                            b[i j] = b[k j];
                        }
                    }
        }



        public void drawa(int i)
        {
            if (i == 1)
            {
                axMSFlexGrid1.Clear();

                //axMSFlexGrid1.set_ColWidth(3 6000);
                //axMSFlexGrid1.set_ColWidth(2 2000);
                axMSFlexGrid1.set_TextMatrix(0 0 ““);
                axMSFlexGrid1.set_TextMatrix(0 1 “1“);
                axMSFlexGrid1.set_TextMatrix(0 2 “2“);
                axMSFlexGrid1.set_TextMatrix(0 3 “3“);
                axMSFlexGrid1.set_TextMatrix(0 4 “4“);
                ax

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      49152  2008-12-14 13:09  floyd\floyd\bin\Debug\AxInterop.MSFlexGridLib.dll

     文件      40960  2009-07-23 20:37  floyd\floyd\bin\Debug\floyd.exe

     文件      50688  2009-07-23 20:37  floyd\floyd\bin\Debug\floyd.pdb

     文件       5632  2005-12-08 14:51  floyd\floyd\bin\Debug\floyd.vshost.exe

     文件      61440  2008-12-14 13:09  floyd\floyd\bin\Debug\Interop.MSFlexGridLib.dll

     文件       4134  2008-12-13 19:23  floyd\floyd\floyd.csproj

     文件      26949  2009-07-23 20:37  floyd\floyd\Form1.cs

     文件      13082  2008-12-14 13:09  floyd\floyd\Form1.Designer.cs

     文件      15441  2008-12-14 13:09  floyd\floyd\Form1.resx

     文件      49152  2008-12-14 13:09  floyd\floyd\obj\Debug\AxInterop.MSFlexGridLib.dll

     文件        842  2009-07-23 20:37  floyd\floyd\obj\Debug\floyd.csproj.GenerateResource.Cache

     文件        544  2008-12-29 22:05  floyd\floyd\obj\Debug\floyd.csproj.ResolveComReference.cache

     文件      40960  2009-07-23 20:37  floyd\floyd\obj\Debug\floyd.exe

     文件       6282  2009-07-23 20:37  floyd\floyd\obj\Debug\floyd.Form1.resources

     文件      50688  2009-07-23 20:37  floyd\floyd\obj\Debug\floyd.pdb

     文件        180  2009-07-23 20:37  floyd\floyd\obj\Debug\floyd.Properties.Resources.resources

     文件      61440  2008-12-14 13:09  floyd\floyd\obj\Debug\Interop.MSFlexGridLib.dll

     文件        456  2009-07-23 20:38  floyd\floyd\obj\floyd.csproj.FileList.txt

     文件        989  2008-12-14 10:53  floyd\floyd\obj\floyd.csproj.FileListAbsolute.txt

     文件        464  2008-12-13 18:49  floyd\floyd\Program.cs

     文件       1180  2008-12-13 18:49  floyd\floyd\Properties\AssemblyInfo.cs

     文件       2866  2008-12-13 18:49  floyd\floyd\Properties\Resources.Designer.cs

     文件       5612  2008-12-13 18:49  floyd\floyd\Properties\Resources.resx

     文件       1090  2008-12-13 18:49  floyd\floyd\Properties\Settings.Designer.cs

     文件        249  2008-12-13 18:49  floyd\floyd\Properties\Settings.settings

     文件        904  2008-12-13 18:49  floyd\floyd.sln

    ..A..H.     20480  2009-07-23 20:38  floyd\floyd.suo

     目录          0  2009-07-27 12:19  floyd\floyd\obj\Debug\TempPE

     目录          0  2009-07-27 12:19  floyd\floyd\bin\Debug

     目录          0  2009-07-27 12:19  floyd\floyd\obj\Debug

............此处省略8个文件信息

评论

共有 条评论