国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

一個簡單圖搜索算法

2019-11-17 02:37:06
字體:
來源:轉載
供稿:網友

一個簡單圖搜索算法

[Serializable]  public class VPoint { public int ID { get; set; } public int X { get; set; } public int Y { get; set; } public bool IsFind { get; set; } public List<int> Dependences { get; set; }//與該點關聯的點ID }PRivate void FindPath()        {            VPoint v1 = new VPoint() { ID = 0, X = 0, Y = 20, Dependences = new List<int>() {2, 1 } };            VPoint v2 = new VPoint() { ID = 1, X = 20, Y = 0, Dependences = new List<int>() { 0, 3, 2 } };            VPoint v3 = new VPoint() { ID = 2, X = 20, Y = 20, Dependences = new List<int>() { 0, 1, 4 } };            VPoint v4 = new VPoint() { ID = 3, X = 40, Y = 0, Dependences = new List<int>() { 1, 4, 5 } };            VPoint v5 = new VPoint() { ID = 4, X = 40, Y = 20, Dependences = new List<int>() { 2, 3, 5 } };            VPoint v6 = new VPoint() { ID = 5, X = 60, Y = 20, Dependences = new List<int>() { 3, 4 } };            List<VPoint> points = new List<VPoint>() { v1, v2, v3, v4, v5, v6 };            VPoint start = v1;            VPoint end = v6;            List<VPoint> resultpoint = new List<VPoint>();            FindPoint(Clone(points), start, end, resultpoint);            foreach (var item in Paths)            {                string path = "";                foreach (var point in item)                {                    path += point.ID +"=>";                }                Console.WriteLine(path);//打印路徑            }            Console.WriteLine(count);        }        int count = 0;        List<IList<VPoint>> Paths = new List<IList<VPoint>>();//全局變量,保存所有的路徑        private void FindPoint(List<VPoint> points, VPoint start, VPoint end, List<VPoint> resultpoint)        {            resultpoint.Add(start);            int index = points.IndexOf(points.Where(p => p.ID == start.ID).ToList()[0]);            points[index].IsFind = true; //標記已經查找過            if (start.Dependences.Contains(end.ID))//如果是終點            {                resultpoint.Add(end);                Paths.Add(resultpoint);                int _index = points.IndexOf(points.Where(p => p.ID == end.ID).ToList()[0]);                points[_index].IsFind = true;            }            else            {                foreach (var item in start.Dependences)                {                    var newstart = points.Where(p => p.ID == item && p.IsFind == false).ToList();                    if (newstart.Count > 0)                    {                        count++;                        List<VPoint> newpoints = Clone(resultpoint);                        FindPoint(Clone(points), newstart[0], end, newpoints);                    }                }            }        }        public static T Clone<T>(T RealObject)//深度拷貝        {            using (Stream objectStream = new MemoryStream())            {                IFormatter formatter = new BinaryFormatter();                formatter.Serialize(objectStream, RealObject);                objectStream.Seek(0, SeekOrigin.Begin);                return (T)formatter.Deserialize(objectStream);            }        }  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涞源县| 比如县| 乐至县| 南开区| 武邑县| 绵阳市| 金堂县| 恩施市| 石河子市| 新巴尔虎左旗| 黔南| 宾川县| 阳谷县| 和平区| 高青县| 林口县| 北安市| 仁寿县| 普格县| 建昌县| 陇南市| 名山县| 呼图壁县| 磴口县| 丰城市| 黑山县| 南溪县| 东莞市| 石河子市| 友谊县| 广西| 伊金霍洛旗| 大埔县| 湘阴县| 炉霍县| 家居| 扶余县| 江源县| 左云县| 新巴尔虎左旗| 高要市|