Пример #1
0
        private bool lasso_finding_test(HashSet <Arc> g, HashSet <Arc> h, int init)
        {
            if (!Head.ContainsKey(g.ToString()))
            {
                HashSet <int> H = new HashSet <int>();

                foreach (Arc arc_g in g)
                {
                    if (arc_g.From == init)
                    {
                        H.Add(arc_g.To);
                    }
                }
                Head.Add(g.ToString(), H);
            }

            if (!Tail.ContainsKey(h.ToString()))
            {
                FiniteAutomaton fa = new FiniteAutomaton();
                OneToOneTreeMap <int, FAState> st = new OneToOneTreeMap <int, FAState>();

                foreach (Arc arc_h in h)
                {
                    if (!st.containsKey(arc_h.From))
                    {
                        st.put(arc_h.From, fa.createState());
                    }
                    if (!st.containsKey(arc_h.To))
                    {
                        st.put(arc_h.To, fa.createState());
                    }
                    fa.addTransition(st.getValue(arc_h.From), st.getValue(arc_h.To), arc_h.Label ? "1" : "0");
                }

                SCC           s = new SCC(fa);
                HashSet <int> T = new HashSet <int>();

                foreach (FAState state in s.getResult())
                {
                    T.Add(st.getKey(state));
                }

                int TailSize = 0;

                HashSet <Arc> isolatedArcs = h;

                while (TailSize != T.Count)
                {
                    TailSize = T.Count;

                    HashSet <Arc> isolatedArcsTemp = new HashSet <Arc>();
                    foreach (Arc arc in isolatedArcs)
                    {
                        if (!T.Contains(arc.To))
                        {
                            isolatedArcsTemp.Add(arc);
                        }
                        else
                        {
                            T.Add(arc.From);
                        }
                    }
                    isolatedArcs = isolatedArcsTemp;
                }
                Tail.Add(h.ToString(), T);
            }
            HashSet <int> intersection = new HashSet <int>(Head[g.ToString()]);

            //intersection.retainAll(Tail[h.ToString()]);
            intersection.IntersectWith(Tail[h.ToString()]);

            //if(debug){
            //    if(intersection.isEmpty()){
            //        //debug("g_graph:"+g+", Head: "+Head.get(g.ToString()));
            //        //debug("h_graph:"+h+", Tail: "+Tail.get(h.ToString()));
            //    }
            //}

            return(intersection.Count > 0);
        }
Пример #2
0
	private bool lasso_finding_test(HashSet<Arc> g, HashSet<Arc> h, int init){
		if(!Head.ContainsKey(g.ToString())){
			HashSet<int> H=new HashSet<int>();

		    foreach (Arc arc_g in g)
		    {
		        if(arc_g.From==init){
					H.Add(arc_g.To);
				}
			}
			Head.Add(g.ToString(), H);
		}
		if(!Tail.ContainsKey(h.ToString())){
			FiniteAutomaton fa=new FiniteAutomaton();
			OneToOneTreeMap<int,FAState> st=new OneToOneTreeMap<int,FAState>();
		    foreach (Arc arc_h in h)
		    {
		        if(!st.containsKey(arc_h.From))
					st.put(arc_h.From, fa.createState());
				if(!st.containsKey(arc_h.To))
					st.put(arc_h.To, fa.createState());
				fa.addTransition(st.getValue(arc_h.From), st.getValue(arc_h.To), arc_h.Label?"1":"0");
			}
			SCC s=new SCC(fa);
			HashSet<int> T=new HashSet<int>();
            foreach (FAState state in s.getResult())
		    {
		        T.Add(st.getKey(state));
			}

			int TailSize=0;
			HashSet<Arc> isolatedArcs=h;
			while(TailSize!=T.Count){
                TailSize = T.Count;

				HashSet<Arc> isolatedArcsTemp=new HashSet<Arc>();

			    foreach (Arc arc in isolatedArcs)
			    {
			        if(!T.Contains(arc.To)){
						isolatedArcsTemp.Add(arc);
					}else{
						T.Add(arc.From);
					}
				}
				isolatedArcs=isolatedArcsTemp;
			}
			Tail.Add(h.ToString(), T);
		}
        HashSet<int> intersection = new HashSet<int>(Head[g.ToString()]);
		//intersection.retainAll(Tail[h.ToString()]);

        intersection.IntersectWith(Tail[h.ToString()]);
		
        //if(debug){
        //    if(intersection.isEmpty()){
        //        //debug("g_graph:"+g+", Head: "+Head.get(g.ToString()));
        //        //debug("h_graph:"+h+", Tail: "+Tail.get(h.ToString()));
        //    }
        //}
		
		return intersection.Count > 0;
	}