Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- member x.trace(id : string, successp, filterp, stopp) =
- logd ("trace from id: " + id)
- let rec iter (paths : (SectionTraceResult * Vertex list) list) (results : SectionTraceResult list) (*internal_filter*) =
- match stopp results paths with
- | true -> results, paths
- | false ->
- let step =
- paths
- |> List.map
- (fun (path, lpfilters) ->
- match path.stack with
- | (h : Section) :: _ when not(filterp h) -> [],results
- | (h : Section) :: t ->
- let lps =
- path.last_connection_points()
- |> List.filter
- (fun lp ->
- not(lpfilters
- |> List.exists
- (fun lp2 -> vEq lp2 lp)))
- let next_lps =
- lps |> List.collect
- (fun lp ->
- h.outs_on_route lp.Id.OriginalId)
- |> List.filter
- (fun lp ->
- not(lpfilters
- |> List.exists
- (fun lp2 -> vEq lp2 lp)))
- next_lps
- |> List.iter
- (fun lp ->
- logd ("-> " + lp.identifier.ToString()))
- let outs =
- next_lps
- |> List.collect
- (fun lp ->
- x.outSections(lp.Id.OriginalId, h))
- let to_fold, to_result =
- outs
- |> List.fold
- (fun (acc, accr) out_sec ->
- let cmns = out_sec.common_points h
- let success =
- cmns |> List.collect (fun c -> out_sec.trace_wrs c successp)
- |> Helper.Collections.withoutRepeats
- (fun p1 p2 ->
- let intrs = intersection vEq p1.vs p2.vs
- List.length intrs = List.length p1.vs)
- let lpfilters =
- success |>
- List.collect
- (fun p ->
- out_sec.link_points
- |> Seq.filter
- (fun lp ->
- x.parent.parent
- |> haveEdge p.vpCortege.vpOut.v lp)
- |> Seq.toList)
- match success with
- | h :: t -> (out_sec, lpfilters) :: acc, (out_sec, success) :: accr
- | [] -> (out_sec, lpfilters) :: acc, accr)
- ([],[])
- let results =
- to_result
- |> List.collect
- (fun (end_sec, stop_elements) ->
- let stopped = stop_elements |> List.map (fun pp -> pp.vpCortege.vpOut.v)
- stopped
- |> List.map
- (fun stp ->
- let cpath = path.copy()
- cpath.stack_add end_sec
- cpath.stop <- Some(stp)
- cpath))
- let next_processing =
- to_fold
- |> List.map
- (fun (rest_sec, filters) ->
- let cpath = path.copy()
- cpath.stack_add rest_sec
- cpath, filters)
- next_processing, results
- | [] -> [], [])
- |> List.filter
- (fun state ->
- match state with
- | [], [] -> false
- | _ -> true)
- let flat_step =
- step
- |> List.fold
- (fun (acc1, acc2) (next, results) -> (next @ acc1), (results @ acc2))
- ([],[])
- match flat_step with
- | [], step_results -> (results @ step_results), []
- | next_processing, step_results -> iter next_processing (results @ step_results)
- let start_v = x.vertices |> List.find (fun el -> el.Id.OriginalId = id)
- let sections =
- x.sections
- |> List.filter (fun s -> s.have_element (fun el -> el.Id.OriginalId = id))
- |> List.filter
- (fun s ->
- let el = s.outermostElement start_v
- GraphExtensions.in_one_coursep start_v el)
- let initial_stacks =
- sections
- |> List.map
- (fun head_of_search_stack ->
- SectionTraceResult([head_of_search_stack], start_v), [])
- let results, paths =
- iter initial_stacks []
- results, (iter paths)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement