Example #1
0
        private static void Main(string[] args)
        {
            RenderLicense();

            Graph<Node> g = GraphGenerator.GetGraph(Shape.Large).Map(v => new Node { Label = v, Filled = false });
            Graph<Node> d = g.GetDominatingSet();

            RenderGraph(g);
            RenderGraph(g.Map(n => new Node { Color = n.Color, Label = n.Label, Filled = d.Vertices.Contains(n) }));

            g = new Graph<Node>();
            Random r = new Random();
            var nodes = Enumerable.Range(0, r.Next(26)).ToDictionary(_ => _, _ => new Node {Label = ('A' + _).ToString(), Filled = false});
            foreach (var n in nodes.Values) {
                g.Add(n);
            }
            for (int i = 0; i < nodes.Count; i++) {
                for (int j = i + 1; j < nodes.Count; j++) {
                    if (r.NextDouble() < 0.16) {
                        g.Add(new Edge<Node>(nodes[i], nodes[j]));
                    }
                }
            }
            RenderGraph(g);
            d = g.GetDominatingSet();
            RenderGraph(g.Map(n => new Node { Color = n.Color, Label = n.Label, Filled = d.Vertices.Contains(n) }));
        }
Example #2
0
        public void DSet_K1_AllNeighborsOfD_InG()
        {
            Graph<Node> g = new Graph<Node>();
            g.Add(new Node { Label = "A", Filled = false });
            Graph<Node> d = g.GetDominatingSet();

            List<Node> actual = new List<Node>();
            foreach (var n in d.Vertices) {
                actual.Add(n);
                actual.AddRange(g.NeighborsOf(n));
                actual = actual.Distinct().ToList();
            }

            CollectionAssert.AreEquivalent(g.Vertices.ToList(), actual);
        }