Ejemplo n.º 1
0
        private Dictionary <int, Block> InitializeBlocks(Graph.Graph graph)
        {
            var blocks = new Dictionary <int, Block>();

            for (int i = 0; i < graph.Nodes.Length; i++)
            {
                var column = new HashSet <int>(graph.Nodes[i].connections.Length);

                int min = graph.Nodes[i].connections.Min();
                int indexOfBlockToAppendTo = min < i ? min : i;

                column.Add(i);

                foreach (int connection in graph.Nodes[i].connections)
                {
                    column.Add(connection);
                }

                if (!blocks.ContainsKey(indexOfBlockToAppendTo))
                {
                    blocks[indexOfBlockToAppendTo] = new Block();
                }

                blocks[indexOfBlockToAppendTo].AppendColumn(column);
            }
            return(blocks);
        }
Ejemplo n.º 2
0
        public static IEnumerable <int> Run(Graph.Graph graph)
        {
            var algo   = new DominatingSets(graph);
            var result = algo.Iterate();

            // keep the vertex indices only
            foreach (var solution in result)
            {
                yield return(solution.vertexIndex);
            }
        }
Ejemplo n.º 3
0
        private DominatingSets(Graph.Graph graph)
        {
            this.prevAddedVertices           = new Stack <HashSet <int> >();
            this.prevAddedPotentialSolutions = new Stack <Solution>();

            this.currentOptimalSolution   = new HashSet <Solution>();
            this.potentialOptimalSolution = new HashSet <Solution>();

            this.usedVertices = new HashSet <int>(numVertices);
            this.numVertices  = graph.Nodes.Length;

            // step 1
            this.blocks = InitializeBlocks(graph);
        }