Advertisement
Guest User

Untitled

a guest
Feb 26th, 2013
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 7.29 KB | None | 0 0
  1. member x.trace(id : string, successp, filterp, stopp) =
  2.         logd ("trace from id: " + id)
  3.         let rec iter (paths : (SectionTraceResult * Vertex list) list) (results : SectionTraceResult list) (*internal_filter*) =
  4.             match stopp results paths with
  5.             | true -> results, paths
  6.             | false ->
  7.                 let step =
  8.                     paths
  9.                         |> List.map
  10.                             (fun (path, lpfilters) ->
  11.                                 match path.stack with
  12.                                 | (h : Section) :: _ when not(filterp h) -> [],results
  13.                                 | (h : Section) :: t ->
  14.                                     let lps =
  15.                                         path.last_connection_points()
  16.                                             |> List.filter
  17.                                                 (fun lp ->
  18.                                                     not(lpfilters
  19.                                                         |> List.exists
  20.                                                             (fun lp2 -> vEq lp2 lp)))
  21.                                     let next_lps =
  22.                                         lps |> List.collect
  23.                                                 (fun lp ->
  24.                                                     h.outs_on_route lp.Id.OriginalId)
  25.                                             |> List.filter
  26.                                                 (fun lp ->
  27.                                                     not(lpfilters
  28.                                                         |> List.exists
  29.                                                             (fun lp2 -> vEq lp2 lp)))
  30.                                     next_lps
  31.                                         |> List.iter
  32.                                             (fun lp ->
  33.                                                 logd ("-> " + lp.identifier.ToString()))
  34.                                     let outs =
  35.                                         next_lps
  36.                                             |> List.collect
  37.                                                 (fun lp ->
  38.                                                     x.outSections(lp.Id.OriginalId, h))
  39.                                    
  40.                                     let to_fold, to_result =
  41.                                         outs
  42.                                             |> List.fold
  43.                                                 (fun (acc, accr) out_sec ->
  44.                                                     let cmns = out_sec.common_points h
  45.                                                     let success =
  46.                                                         cmns |> List.collect (fun c -> out_sec.trace_wrs c successp)
  47.                                                             |> Helper.Collections.withoutRepeats
  48.                                                                 (fun p1 p2 ->
  49.                                                                     let intrs = intersection vEq p1.vs p2.vs
  50.                                                                     List.length intrs = List.length p1.vs)
  51.                                                     let lpfilters =
  52.                                                         success |>
  53.                                                             List.collect
  54.                                                                 (fun p ->
  55.                                                                     out_sec.link_points
  56.                                                                         |> Seq.filter
  57.                                                                             (fun lp ->
  58.                                                                                 x.parent.parent
  59.                                                                                     |> haveEdge p.vpCortege.vpOut.v lp)
  60.                                                                         |> Seq.toList)
  61.                                                        
  62.                                                     match success with
  63.                                                     | h :: t -> (out_sec, lpfilters) :: acc, (out_sec, success) :: accr
  64.                                                     | [] -> (out_sec, lpfilters) :: acc, accr)
  65.                                                 ([],[])
  66.                                     let results =
  67.                                         to_result
  68.                                             |> List.collect
  69.                                                 (fun (end_sec, stop_elements) ->
  70.                                                     let stopped = stop_elements |> List.map (fun pp -> pp.vpCortege.vpOut.v)
  71.                                                     stopped
  72.                                                         |> List.map
  73.                                                             (fun stp ->
  74.                                                                 let cpath = path.copy()
  75.                                                                 cpath.stack_add end_sec
  76.                                                                 cpath.stop <- Some(stp)
  77.                                                                 cpath))
  78.                                     let next_processing =
  79.                                         to_fold
  80.                                             |> List.map
  81.                                                 (fun (rest_sec, filters) ->
  82.                                                     let cpath = path.copy()
  83.                                                     cpath.stack_add rest_sec
  84.                                                     cpath, filters)
  85.                                     next_processing, results
  86.                                 | [] -> [], [])
  87.                         |> List.filter
  88.                             (fun state ->
  89.                                 match state with
  90.                                 | [], [] -> false
  91.                                 | _ -> true)
  92.                 let flat_step =
  93.                     step
  94.                         |> List.fold
  95.                             (fun (acc1, acc2) (next, results) -> (next @ acc1), (results @ acc2))
  96.                             ([],[])
  97.                 match flat_step with
  98.                 | [], step_results -> (results @ step_results), []
  99.                 | next_processing, step_results -> iter next_processing (results @ step_results)
  100.        
  101.         let start_v = x.vertices |> List.find (fun el -> el.Id.OriginalId = id)
  102.         let sections =
  103.             x.sections
  104.                 |> List.filter (fun s -> s.have_element (fun el -> el.Id.OriginalId = id))
  105.                 |> List.filter
  106.                     (fun s ->
  107.                         let el = s.outermostElement start_v
  108.                         GraphExtensions.in_one_coursep start_v el)
  109.         let initial_stacks =
  110.             sections
  111.                 |> List.map
  112.                     (fun head_of_search_stack ->
  113.                         SectionTraceResult([head_of_search_stack], start_v), [])
  114.         let results, paths =
  115.             iter initial_stacks []
  116.         results, (iter paths)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement