コード例 #1
0
ファイル: test.cs プロジェクト: MissisWesker/graph-mapping
 private static graph generate_grid(int n, int m)
 {
     graph.creator gc = new graph.creator(n * m);
     for (int i = 0; i < n; i++)
         for (int j = 0; j < m; j++)
         {
             int num = i * m + j;
             if (j < m - 1) gc.AddEdge(num, num + 1);
             if (i < n - 1) gc.AddEdge(num, num + m);
         }
     return gc.create();
 }
コード例 #2
0
        public solution Reduce()
        {
            int current, next, n = 0, k = 0;
            nodes = new List<int>(sln.source.N);
            for (int i = 0; i < sln.source.N; i++)
                nodes.Add(i);

            do
            {
                int r = rand.Next(nodes.Count);
                current = nodes[r];
                sln.map[current] = n;
                k++;
                nodes.RemoveAt(nodes.IndexOf(current));
                next = GetNeighbour(current);
                if (next != -1)
                {
                    sln.map[next] = n;
                    nodes.RemoveAt(nodes.IndexOf(next));
                    k++;
                }
                n++;
            }
            while (k != sln.source.N);

            int[,] weight = new int[n, n];
            graph.creator gc = new graph.creator(n);
            for (int i = 0; i < sln.source.N; i++)
            {
                foreach (int j in sln.source.Adj(i))
                {
                    if ((sln.map[j] != sln.map[i]) && (j > i))
                    {
                        if (weight[sln.map[i], sln.map[j]] == 0)
                            gc.AddEdge(sln.map[i], sln.map[j]);
                        weight[sln.map[i], sln.map[j]]++;
                        weight[sln.map[j], sln.map[i]]++;
                    }
                }
            }
            sln.result = gc.create();
            return sln;
        }
コード例 #3
0
ファイル: test.cs プロジェクト: MissisWesker/graph-mapping
 private static graph generate_graph()
 {
     graph.creator gc = new graph.creator(9);
     gc.AddEdge(0, 1);
     gc.AddEdge(0, 2);
     gc.AddEdge(1, 3);
     gc.AddEdge(1, 8);
     gc.AddEdge(2, 3);
     gc.AddEdge(2, 4);
     gc.AddEdge(3, 5);
     gc.AddEdge(4, 5);
     gc.AddEdge(4, 6);
     gc.AddEdge(5, 6);
     gc.AddEdge(5, 7);
     gc.AddEdge(5, 8);
     gc.AddEdge(6, 7);
     gc.AddEdge(7, 8);
     graph g = gc.create();
     return g;
 }