Esempio n. 1
0
        public void TestGraphWithLayerAndRelation()
        {
            Graph locationGraph = new Graph("Location Graph");

            // Add Nodes
            Entity orgrimmar = new Entity("Orgrimmar", locationGraph);
            Entity undercity = new Entity("Undercity", locationGraph);
            Entity gromGol   = new Entity("Grom'Gol", locationGraph);
            Entity stormwind = new Entity("Stormwind", locationGraph);

            locationGraph.Entities.AddRange(new Entity[] { orgrimmar, undercity, gromGol, stormwind });

            // Add Zeppelin Layer
            Layer zeppelinLayer = new Layer("Zeppelin Layer");

            locationGraph.AddLayer(zeppelinLayer);

            zeppelinLayer.AddRelation(orgrimmar, gromGol);
            zeppelinLayer.AddRelation(orgrimmar, undercity);
            zeppelinLayer.AddRelation(undercity, gromGol);

            Console.WriteLine(locationGraph.ID.ToString());
            Assert.AreEqual(4, locationGraph.Entities.Count, "Expected 4 nodes (og, uc, gg, sw).");
            Assert.AreEqual(1, locationGraph.GetLayers().Count, "Expected exactly one Layer (zeppelin).");
            Assert.AreEqual(3, zeppelinLayer.Relations.Count, "Expected 3 relations (og-uc, og-gg, uc-gg).");
        }
Esempio n. 2
0
        public override void AddToGraph(Graph graph, Layer layer, Entity parent)
        {
            var n1      = new Entity("CrossingT Area 1", graph);
            var n2      = new Entity("CrossingT Area 2", graph);
            var n3      = new Entity("CrossingT Area 3", graph);
            var nCenter = new Entity("CrossingT Area Center", graph);

            parent.Children.AddRange(new List <Entity>()
            {
                n1, n2, n3, nCenter
            });

            layer.AddRelation(n1, nCenter, "1 to Center");
            layer.AddRelation(n2, nCenter, "2 to Center");
            layer.AddRelation(n3, nCenter, "3 to Center");
        }
Esempio n. 3
0
        private void InstantiateTemplate(Model.Graph templateGraph, Entity targetEntity)
        {
            Dictionary <Entity, Entity> templateToInstanceMapping = new();

            // instantiate all entities from template and remember mapping
            foreach (var templateEntity in templateGraph.Entities)
            {
                var templateInstance = templateEntity.CreateDuplicate(_graph, targetEntity);
                templateToInstanceMapping.Add(templateEntity, templateInstance);
                targetEntity.AddChild(templateInstance);
            }

            // add internal relations between instantiated entities
            foreach (var templateLayer in templateGraph.GetLayers())
            {
                Layer layer = _graph.GetOrAddLayer(templateLayer.Name);

                foreach (var templateRelation in templateLayer.Relations)
                {
                    var from = templateToInstanceMapping[templateRelation.Entities[0]];
                    var to   = templateToInstanceMapping[templateRelation.Entities[1]];
                    layer.AddRelation(from, to, templateRelation.Name);
                }
            }
        }
        private void ConnectChildren(Relation parentRelation, Layer childLayer)
        {
            var np0 = parentRelation.Entities[0];
            var np1 = parentRelation.Entities[1];

            var cp0 = FindRandomUnconnectedChildNode(np0, childLayer);
            var cp1 = FindRandomUnconnectedChildNode(np1, childLayer);

            childLayer.AddRelation(cp0, cp1, $"InterCon: {np0.Name} to {np1.Name}");
        }
Esempio n. 5
0
        public void TestParentChildNodes()
        {
            Graph locationGraph = new Graph("Location Graph");

            // Add Nodes
            Entity orgrimmar    = new Entity("Orgrimmar", locationGraph);
            Entity thunderbluff = new Entity("Thunderbluff", locationGraph);

            Entity undercity = new Entity("Undercity", locationGraph);
            Entity gromGol   = new Entity("Grom'Gol", locationGraph);
            Entity stormwind = new Entity("Stormwind", locationGraph);

            Entity easternKingdoms = new Entity("Eastern Kingdoms", locationGraph);

            easternKingdoms.AddChildren(new Entity[] { undercity, gromGol, stormwind });

            Entity kalimdor = new Entity("Kalimdor", locationGraph);

            kalimdor.AddChildren(new Entity[] { orgrimmar, thunderbluff });

            locationGraph.Entities.AddRange(new Entity[] { easternKingdoms, kalimdor });

            // Add Zeppelin Layer
            Layer zeppelinLayer = new Layer("Zeppelin Layer");

            locationGraph.AddLayer(zeppelinLayer);

            zeppelinLayer.AddRelation(orgrimmar, gromGol);
            zeppelinLayer.AddRelation(orgrimmar, undercity);
            zeppelinLayer.AddRelation(orgrimmar, thunderbluff);
            zeppelinLayer.AddRelation(undercity, gromGol);

            Assert.AreEqual(2, locationGraph.Entities.Count, "Expected 2 nodes (kalimdor, eastern kingdoms).");
            Assert.AreEqual(1, locationGraph.GetLayers().Count, "Expected exactly one Layer (zeppelin).");
            Assert.AreEqual(4, zeppelinLayer.Relations.Count, "Expected 4 relations (og-uc, og-gg, uc-gg, og-tb).");
            Entity orgrimmarParent;

            Assert.IsTrue(orgrimmar.Parent.TryGetTarget(out orgrimmarParent), "Orgrimmar should have a parent");
            Assert.AreEqual("Kalimdor", orgrimmarParent.Name, "Orgrimmar should have Kalimdor as a parent");
        }
Esempio n. 6
0
        public override void AddToGraph(Graph graph, Layer layer, Entity parent)
        {
            var previousNode = new Entity("Chain Area 1", graph);

            parent.Children.Add(previousNode);

            for (int i = 2; i <= _chainLength; i++)
            {
                var currentNode = new Entity($"Chain Area {i}", graph);
                parent.Children.Add(currentNode);
                layer.AddRelation(previousNode, currentNode, $"Chain {i-1} to {i}");

                previousNode = currentNode;
            }
        }
Esempio n. 7
0
        public Graph ExecuteStep(Graph graph)
        {
            var points       = _pointSupplier.Invoke();
            var fortuneSites = points.Select(point => new FortuneSite(point.X, point.Y)).ToList();

            FortunesAlgorithm.Run(fortuneSites, _generationMin.X, _generationMin.Y, _generationMax.X, _generationMax.Y);

            // add entities to graph
            Dictionary <FortuneSite, Entity> siteToEntityMapping = new ();

            foreach (var cell in fortuneSites)
            {
                var             areaEntity    = new Entity(_cellNameSupplier.Invoke(cell.X, cell.Y), graph);
                EntityComponent areaComponent = new ("AreaComponent");
                areaComponent.SetProperty("cell", cell);
                areaEntity.Components.Add(areaComponent);

                ComponentUtility.AddPosition2D(areaEntity, (float)cell.X, (float)cell.Y);

                if (_parent == null)
                {
                    graph.Entities.Add(areaEntity);
                }
                else
                {
                    _parent.AddChild(areaEntity);
                }

                siteToEntityMapping.Add(cell, areaEntity);
            }

            // add relations to graph
            Layer layer = graph.GetOrAddLayer(_layerName);

            foreach (var cell in fortuneSites)
            {
                foreach (var cellNeighbor in cell.Neighbors)
                {
                    layer.AddRelation(siteToEntityMapping[cell], siteToEntityMapping[cellNeighbor]);
                }
            }

            return(graph);
        }