Ejemplo n.º 1
0
            private void strongconnect(Graph.Node v)
            {
                indexs[v]   = index;
                lowlinks[v] = index;
                index++;
                S.Push(v);

                foreach (Graph.Node w in v.nexts.Keys)
                {
                    if (indexs[w] < 0)
                    {
                        strongconnect(w);
                        lowlinks[v] = Math.Min(lowlinks[v], lowlinks[w]);
                    }
                    else if (S.Contains(w))
                    {
                        lowlinks[v] = Math.Min(lowlinks[v], indexs[w]);
                    }
                }

                if (lowlinks[v] == indexs[v])
                {
                    List <Graph.Node> scc = new List <Graph.Node>();
                    Graph.Node        w;
                    do
                    {
                        w = S.Pop();
                        scc.Add(w);
                    } while(v != w);
                    StronglyConnectedComponents.Add(scc);
                }
            }
Ejemplo n.º 2
0
            public static Elem[] BuildMinMax(Graph graph, Graph.Node source, Dictionary <Graph.Edge, double> edge_dist, IList <Graph.Node> targets)
            {
                Func <Graph.Node, bool> IsTarget = delegate(Graph.Node node)
                {
                    return(targets.Contains(node));
                };

                return(BuildMinMax(graph, source, edge_dist, IsTarget));
            }
Ejemplo n.º 3
0
            /// Now we can read the shortest path from source to target by reverse iteration:
            /// 1  S := empty sequence
            /// 2  u := target
            /// 3  while previous[u] is defined:                                   // Construct the shortest path with a stack S
            /// 4      insert u at the beginning of S                              // Push the vertex into the stack
            /// 5      u := previous[u]                                            // Traverse from target to source
            /// 6  end while ;
            public static Graph.Node[] GetPathNode(Elem[] elems, Graph.Node target)
            {
                List <Graph.Node> S = new List <Graph.Node>();
                Elem u = elems[target.id];

                while (u != null)
                {
                    S.Insert(0, u.node);
                    u = (u.prev != null) ? elems[u.prev.id] : null;
                }
                return(S.ToArray());
            }
Ejemplo n.º 4
0
 public Elem(Graph.Node node, double dist, Graph.Node prev, Graph.Edge edge)
 {
     this.node = node;
     this.dist = dist;
     this.prev = prev;
     this.edge = edge;
     if (edge != null)
     {
         HDebug.Assert(edge.nodes.Length == 2);
         HDebug.Assert(edge.nodes.Contains(node));
         HDebug.Assert(edge.nodes.Contains(prev));
     }
 }
Ejemplo n.º 5
0
            public static Elem[] BuildMinMax(Graph graph, Graph.Node source, Dictionary <Graph.Edge, double> edge_dist, Func <Graph.Node, bool> IsTarget /*=null*/)
            {
                /// dist(v2) := min[dist(v2), max[dist(v1), dist(v1-v2)]]
                Func <double, Graph.Node, Graph.Edge, Graph.Node, double> GetAlt = delegate(double u_dist, Graph.Node u_node, Graph.Edge uv_edge, Graph.Node v_node)
                {
                    double alt = Math.Max(u_dist, edge_dist[uv_edge]);
                    return(alt);
                };
                Dictionary <Graph.Node, double> source2initdist = new Dictionary <Graph.Node, double>();

                source2initdist.Add(source, 0);
                return(BuildMinAlt(graph, source2initdist, GetAlt, IsTarget));
            }
Ejemplo n.º 6
0
 public int this[Graph.Node n]
 {
     get { if (cache.ContainsKey(n) == false)
           {
               return(-1);
           }
           return(cache[n]); }
     set { if (cache.ContainsKey(n) == false)
           {
               cache.Add(n, -1);
           }
           cache[n] = value; }
 }
Ejemplo n.º 7
0
            public static Graph.Edge[] GetPathEdge(Elem[] elems, Graph.Node target)
            {
                List <Graph.Edge> S = new List <Graph.Edge>();
                Elem u = elems[target.id];

                while (u != null)
                {
                    if (u.edge != null)
                    {
                        S.Insert(0, u.edge);
                    }
                    else
                    {
                        HDebug.Assert(u.prev == null);
                    }
                    u = (u.prev != null) ? elems[u.prev.id] : null;
                }
                return(S.ToArray());
            }
Ejemplo n.º 8
0
            public static Elem[] BuildMinMax(Graph graph, Graph.Node source, Dictionary <Graph.Edge, double> edge_dist)
            {
                Func <Graph.Node, bool> IsTarget = null;

                return(BuildMinMax(graph, source, edge_dist, IsTarget));
            }
Ejemplo n.º 9
0
 public static Elem[] Build(Graph graph, Graph.Node source, Dictionary <Graph.Edge, double> edge_dist, IList <Graph.Node> targets)
 {
     return(BuildMinSum(graph, source, edge_dist, targets));
 }
Ejemplo n.º 10
0
 public Edge(int id, Graph.Node node1, Graph.Node node2, EDGE value)
     : base(id, node1, node2)
 {
     this.value = value;
 }
Ejemplo n.º 11
0
 public static Edge New(int id, Graph.Node node1, Graph.Node node2, EDGE value)
 {
     return(new Edge(id, node1, node2, value));
 }