博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
探寻路径
阅读量:6423 次
发布时间:2019-06-23

本文共 3029 字,大约阅读时间需要 10 分钟。

// Learn more about F# at http://fsharp.net// See the 'F# Tutorial' project for more help.module File1open System.Windows.Formsopen System.Collections.Generictype Loc =    |A|B|C|Dlet path_key a b = if aList.map (fun (a,b,c)->((path_key a b)),c)                    |>Map.ofListpath_Dis_map |> Map.toList |>printfn "%A" //let dict = new Dictionary
()let path_Dis_map2 = new Dictionary< Loc*Loc , int>()//Map.tryFind let path_map_query ls map1= match ls with |head::val1::tail-> if ( Map.containsKey (A,head) map1) then map1.[(A,head)] else System.Int32.MaxValue |_->System.Int32.MaxValuelet rec path_cdis ls= match ls with |head::a::tail-> let dis1 = path_Dis_map.[path_key head a] dis1 + path_cdis(a::tail) |_->0printfn "dis = %d %d" (path_cdis [D;C;B;A]) (path_map_query [D;C;B;A] path_Dis_map)let fileterme crr value= match value with | (a,b,c) when a=crr -> Some(b) | (a,b,c) when b=crr ->Some(a) | _ ->Nonelet findway (ls:Loc list) = List.choose (fileterme ls.Head) pathData |> List.filter (fun x-> not ( List.exists (fun i->i=x) ls))let start1 =[[A]]let rec work2 (start,pathmaps)= let once = List.collect (fun (ls)-> let firstList = ls//List.head start let ways = findway firstList match ways with |[] -> [] |_-> let ends = List.map (fun x ->x::ls) ways ends ) start let map1 = pathmaps let Mapme = once|> List.fold (fun (acc:Map<(Loc*Loc),int>) (ls:Loc list)-> let k=A,ls.Head let v= path_cdis ls match (Map.tryFind k acc) with |Some n-> if v< n then Map.add k v acc else acc |_->Map.add k v acc ) map1 // //Mapme|>printf "Map me %A" List.filter (fun x-> match x with |D::tail -> printfn "Find the way %A = %d" x (path_cdis x) false |_->true ) once |>printfn "%A" //裁剪路径 let once3 = List.filter (fun (ls:Loc list)-> let k=A,ls.Head let v= path_cdis ls match (Map.tryFind k Mapme) with |Some n-> if v <= n then true else false |_->true ) once |> List.filter (fun (x:Loc list)-> not (D = x.Head)) //once3 |> printfn ">>>>Left is %A" once3,Mapmelet rec work1 (start,map) = match start with |[] ->() |_-> let data = work2 (start,map) work1 datawork1 (start1,path_Dis_map) |> printfn ">>>%A"[
]let main argv = printfn "%A" argv 0 // return an integer exit code

  

转载于:https://www.cnblogs.com/lxf120/archive/2013/02/25/2932018.html

你可能感兴趣的文章
Eclipse+kafka集群 实例源码
查看>>
3171. [TJOI2013]循环格【费用流】
查看>>
Vijos 1067Warcraft III 守望者的烦恼
查看>>
SQL语句
查看>>
LinkedList
查看>>
Python number
查看>>
xmpp 环境配置
查看>>
【Lv1-Lesson008】A Guide to Birthdays
查看>>
mysql source 恢复 sql数据time_zone报错 已解决
查看>>
ubuntu 16.04 安装 Matlab R2016b后启动出现的问题
查看>>
MySQL_PHP学习笔记_2015.04.19_PHP连接数据库
查看>>
关于RFC
查看>>
juery 选择器 选择多个元素
查看>>
【新手向】TensorFlow 安装教程:RK3399上运行谷歌人工智能
查看>>
01-学习前说明
查看>>
Oracle Net Configuration(监听程序和网络服务配置)
查看>>
c语言_判断例子
查看>>
ubuntu重启不清除 /tmp 设置
查看>>
面向对象
查看>>
JSON
查看>>