Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var graph1 = new Graph();

            graph1.InsertNodes(5);
            graph1.InsertEdge(0, 2);
            graph1.InsertEdge(2, 4);
            graph1.InsertEdge(4, 1);
            graph1.InsertEdge(1, 3);
            graph1.InsertEdge(3, 0);

            var graph2 = new Graph();

            graph2.InsertNodes(5);
            graph2.InsertEdge(0, 1);
            graph2.InsertEdge(1, 4);
            graph2.InsertEdge(4, 3);
            graph2.InsertEdge(3, 2);
            graph2.InsertEdge(2, 0);

            var vfs   = new VfState(graph1, graph2, false);
            var match = vfs.FMatch();

            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine(match ? "Графи ізоморфні" : "Графи не ізоморфні");
            if (match)
            {
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine(i + " -> " + vfs.Mapping1To2[i]);
                }
            }
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public double matchPercent(string file1, string file2)
        {
            //MessageBox.Show(String.Concat(file1, "\t", file2));
            Graph graph = new Graph();

            Console.WriteLine("Graph 1 detail ------\n\n");
            graph = readNetlist(file1);

            Console.WriteLine("Graph 2 detail ------\n\n");
            Graph graph2 = new Graph();

            graph2 = readNetlist(file2);

            bool f = graph2.doesEdgeExist(0, 4);

            Console.WriteLine(String.Concat("Does edge exist = ", f.ToString()));
            List <int> neighbors = graph2.GetNeighbors(5);

            for (int i = 0; i < neighbors.Count; i++)
            {
                Console.Write(String.Concat(neighbors[i].ToString(), "\t"));
            }
            Console.WriteLine("");
            neighbors.Clear();
            neighbors = graph2.GetOutNeighbors(7);
            for (int i = 0; i < neighbors.Count; i++)
            {
                Console.Write(String.Concat(neighbors[i].ToString(), "\t"));
            }

            List <string> cliques = graph2.GetCliques();
            int           count   = 0;

            for (int i = 0; i < cliques.Count; i++)
            {
                char[] delims = { ' ', '\t' };
                //Graph gtemp = new Graph();
                Graph gtemp = getGraphFromPath(cliques[i], graph2);

                //Console.WriteLine(gtemp.GetInfo());
                VfState vfs         = new VfState(graph, gtemp, false, true);
                bool    fIsomorphic = vfs.FMatch();
                if (fIsomorphic)
                {
                    count++;
                }
                Console.WriteLine(String.Concat("clique (", i.ToString(), ") value = ",
                                                cliques[i], " Match = ", fIsomorphic.ToString()));
            }

            double percent = ((double)count / cliques.Count) * 100.0;

            //MessageLogWindow mlw = new MessageLogWindow(logtext);
            //mlw.Show();
            //MessageBox.Show(String.Concat("Percent match = ", percent.ToString()));
            return(percent);
            //return 21.3;
        }
Ejemplo n.º 3
0
        public bool IsIsomorphy()
        {
            Graph <String, String> graph1 = new Graph <string, string>();
            Graph <String, String> graph2 = new Graph <string, string>();

            // The first nodes is always ID 0 and the rest
            // follow so we have nodes 0, 1, 2 and 3

            var nodesDictionary1 = new Dictionary <string, int>();
            var nodesDictionary2 = new Dictionary <string, int>();
            int id = 0;

            foreach (NodeModel node in model1.NodesSource)
            {
                graph1.InsertVertex(node.Key);
                nodesDictionary1.Add(node.Key, id++);
            }

            id = 0;
            foreach (NodeModel node in model2.NodesSource)
            {
                graph2.InsertVertex(node.Key);
                nodesDictionary2.Add(node.Key, id++);
            }

            foreach (LinkModel link in model1.LinksSource)
            {
                graph1.AddEdge(nodesDictionary1[link.From], nodesDictionary1[link.To], link.Weight);
            }

            foreach (LinkModel link in model2.LinksSource)
            {
                graph2.AddEdge(nodesDictionary2[link.From], nodesDictionary2[link.To], link.Weight);
            }

            var         vfs         = new VfState <String, String>(graph1, graph2, true, true);
            FullMapping fIsomorphic = vfs.Match();

            if (fIsomorphic == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public double matchPercent(string file1, string file2)
        {
            //MessageBox.Show(String.Concat(file1, "\t", file2));
            Graph graph = new Graph();
            Console.WriteLine("Graph 1 detail ------\n\n");
            graph = readNetlist(file1);

            Console.WriteLine("Graph 2 detail ------\n\n");
            Graph graph2 = new Graph();
            graph2 = readNetlist(file2);

            bool f = graph2.doesEdgeExist(0, 4);
            Console.WriteLine(String.Concat("Does edge exist = ", f.ToString()));
            List<int> neighbors = graph2.GetNeighbors(5);
            for (int i = 0; i < neighbors.Count; i++)
            {
                Console.Write(String.Concat(neighbors[i].ToString(), "\t"));

            }
            Console.WriteLine("");
            neighbors.Clear();
            neighbors = graph2.GetOutNeighbors(7);
            for (int i = 0; i < neighbors.Count; i++)
            {
                Console.Write(String.Concat(neighbors[i].ToString(), "\t"));

            }

            List<string> cliques = graph2.GetCliques();
            int count = 0;
            for (int i = 0; i < cliques.Count; i++)
            {
                char[] delims = { ' ', '\t' };
                //Graph gtemp = new Graph();
                Graph gtemp = getGraphFromPath(cliques[i], graph2);

                //Console.WriteLine(gtemp.GetInfo());
                VfState vfs = new VfState(graph, gtemp, false, true);
                bool fIsomorphic = vfs.FMatch();
                if (fIsomorphic) count++;
                Console.WriteLine(String.Concat("clique (", i.ToString(), ") value = ",
                    cliques[i], " Match = ", fIsomorphic.ToString()));

            }

            double percent = ((double)count / cliques.Count) * 100.0;
            //MessageLogWindow mlw = new MessageLogWindow(logtext);
            //mlw.Show();
            //MessageBox.Show(String.Concat("Percent match = ", percent.ToString()));
            return percent;
            //return 21.3;
        }