当前位置: 首页>>代码示例>>C#>>正文


C# Graph.Add方法代码示例

本文整理汇总了C#中Graph.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.Add方法的具体用法?C# Graph.Add怎么用?C# Graph.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        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) }));
        }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:27,代码来源:Program.cs

示例2: Main

 public static void Main(string[] args)
 {
     System.Console.Out.WriteLine("========= BasicGraph ========");
     Graph g = new Graph();
     g.Add(new Node(1), new Node(2));
     g.Add(new Node(3), new Node(4));
     g.Print();
     System.Console.Out.WriteLine();
 }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:9,代码来源:Graph.cs

示例3: GetDominatingSet

        public static Graph<Node> GetDominatingSet(this Graph<Node> g)
        {
            var d = g.Vertices.ToDictionary(_ => _, _ => false);

            var candidates = d.Select(p => new {Point = p.Key, Neighbors = g.NeighborsOf(p.Key), Determined = p.Value}).ToArray();
            var candidate = candidates.Where(p => !p.Determined).OrderBy(p => p.Neighbors.Count).FirstOrDefault();

            while (candidate != null) {
                bool keep = false;
                foreach (var n in candidate.Neighbors) {
                    if (d.ContainsKey(n)) {
                        continue;
                    } else if (g.NeighborsOf(n).Where(p => p != candidate.Point).Any(p => d.ContainsKey(p))) {
                        continue;
                    } else {
                        keep = true;
                        break;
                    }
                }
                if (candidate.Neighbors.Count > 0 && !keep) {
                    d.Remove(candidate.Point);
                } else {
                    d[candidate.Point] = true;
                }

                candidates = d.Select(p => new { Point = p.Key, Neighbors = g.NeighborsOf(p.Key), Determined = p.Value }).ToArray();
                candidate = candidates.Where(p => !p.Determined).OrderBy(p => p.Neighbors.Count).FirstOrDefault();
            }

            Graph<Node> result = new Graph<Node>();
            foreach (var n in d.Keys) {
                result.Add(n);
            }
            return result;
        }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:35,代码来源:Operations.cs

示例4: Simulation

        public Simulation(ScenarioModel scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException("scenario is null");
            }

            //System.Threading.Timer t = new System.Threading.Timer(new System.Threading.TimerCallback((o) => Step()), null, 0, (long)STEP_TIME_MS);

            _scenario = scenario;
            RoadGraph = new Graph<WayPoint, PathFigure>();
            if (_scenario.RoadGraph != null)
            {
                foreach (var node in _scenario.RoadGraph.Nodes)
                {
                    RoadGraph.Add(node);
                }
                foreach (var edge in _scenario.RoadGraph.Edges)
                {
                    var pathGeom = PathGeometry.CreateFromGeometry(PathGeometry.Parse(edge.Data));
                    RoadGraph.AddEdge(edge.Start, edge.End, pathGeom.Figures.First());
                }
            }

            _analisisCollector = new Analisis.AnalisisCollector();
            _map = _scenario.Map;
            _start = _scenario.StartTime;
            _end = _scenario.EndTime;
            _simulationTime = _scenario.StartTime;
            Init(STEP_TIME_MS);
        }
开发者ID:nomoreserious,项目名称:FlowSimulation,代码行数:31,代码来源:Simulation.cs

示例5: Graph_Map

        public void Graph_Map()
        {
            Graph<TypeA> g = new Graph<TypeA>();
            var a = new TypeA { Label = "A" };
            var b = new TypeA { Label = "B" };
            var c = new TypeA { Label = "C" };
            var edge = new Edge<TypeA>(b, c);
            g.Add(a);
            g.Add(b);
            g.Add(c);
            g.Add(edge);

            Func<TypeA, TypeB> map = _ => new TypeB {Label = _.Label};
            Graph<TypeB> h = g.Map(map);

            Assert.IsTrue(g.Vertices.All(v => h.Vertices.Any(w => w.Label == v.Label)));
            Assert.IsFalse(g.Vertices.Any(v => h.Vertices.All(w => w.Label != v.Label)));
        }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:18,代码来源:MapTests.cs

示例6: AddingNodesAndEdges

    // Building the graph
    public static void AddingNodesAndEdges(Graph town, int allEdges)
    {
        for (int i = 0; i < allEdges; i++)
        {
            var line = Console.ReadLine();
            var temp = line.Split(' ').Select(x => int.Parse(x)).ToArray();

            if (!town.Elements.ContainsKey(temp[0]))
            {
                town.Add(new GraphNode(temp[0], double.PositiveInfinity));
            }

            if (!town.Elements.ContainsKey(temp[1]))
            {
                town.Add(new GraphNode(temp[1], double.PositiveInfinity));
            }

            town.Elements[temp[0]].AddEdge(temp[1], (double)temp[2]);
            town.Elements[temp[1]].AddEdge(temp[0], (double)temp[2]);
        }
    }
开发者ID:NikolovNikolay,项目名称:Telerik-Homeworks,代码行数:22,代码来源:FriendsOfPesho.cs

示例7: SetUp

		public void SetUp()
		{
			graph = new Graph(Center)
			{
				Viewport = Rectangle.One,
				MaximumNumberOfPoints = 10,
				NumberOfPercentiles = 2,
				AxesIsVisible = true,
				PercentilesIsVisible = true,
				PercentileLabelsIsVisible = true
			};
			line = graph.CreateLine("", LineColor);
			graph.Add(line);
		}
开发者ID:whztt07,项目名称:DeltaEngine,代码行数:14,代码来源:RemoveOldestPointsTests.cs

示例8: DSet_K1_AllNeighborsOfD_InG

        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);
        }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:15,代码来源:OperationsTests.cs

示例9: CalculatePaths

        private static IEnumerable<Path> CalculatePaths(Route route, IEnumerable<Schedule> schedules)
        {
            var graph = new Graph();
            foreach (var carrierMovement in schedules.SelectMany(s => s.CarrierMovements))
            {
                graph.Add(carrierMovement);
            }

            var paths = new List<Path>
            {
                new Path(0.0, route.DepartureTime, graph.Nodes[route.OriginLocationId.Value])
            };

            var possiblePaths = new List<Path>();

            while (true)
            {
                if (!paths.Any())
                {
                    return possiblePaths.OrderBy(p => p.Distance);
                }

                var orderedPaths = paths
                    .Where(p => !double.IsPositiveInfinity(p.Distance))
                    .OrderBy(p => p.Distance);
                paths = new List<Path>();

                foreach (var path in orderedPaths)
                {
                    if (path.CurrentNode.Name == route.DestinationLocationId.Value)
                    {
                        possiblePaths.Add(path);
                        continue;
                    }

                    paths.AddRange(path.CurrentNode.Edges.Select(e => CreatePath(route, path, e.CarrierMovement, e.Target)).Where(p => p != null));
                }
            }
        }
开发者ID:joaomajesus,项目名称:EventFlow,代码行数:39,代码来源:RoutingService.cs

示例10: ReadScenario

        internal Scenario ReadScenario()
        {
            Scenario sim = new Scenario();
            try
            {
                using (StreamReader test = new StreamReader(_path + "scenario.scn"))
                {}
            }
            catch (Exception)
            {
                return null;
            }
            try
            {
                using (StreamReader sr = new StreamReader(_path + "map.svg"))
                {
                    sim.StringMap = sr.ReadToEnd();
                    XmlTextReader reader = new XmlTextReader(_path + "map.svg");
                    MapReader mapreader = new MapReader(reader);
                    byte[,] temp = mapreader.GetMap();
                    sim.map = new MapOld(temp);
                    for (int i = 0; i < temp.GetLength(0); i++)
                    {
                        for (int j = 0; j < temp.GetLength(1); j++)
                        {
                            if ((temp[i, j] & 0x80) != 0x80)
                            {
                                sim.MapSquere += MapOld.CellSize * MapOld.CellSize;
                            }
                        }
                    }
                    sim.paintObjectList = mapreader.GetPaintObjectList();
                    sim.Image = mapreader.GetImage();
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                sim.map = new MapOld(600, 300);
                sim.paintObjectList = new List<PaintObject>();
                sim.Image = new System.Windows.Media.Imaging.BitmapImage();
            }

            try
            {
                using (StreamReader reader = new StreamReader(_path + "AgentGroups.xml"))
                {
                    XmlSerializer sw = new XmlSerializer(typeof(AgentsGroup[]));
                    AgentsGroup[] groups = (AgentsGroup[])sw.Deserialize(reader);
                    sim.agentGroups = new List<AgentsGroup>(groups);
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                sim.agentGroups = new List<AgentsGroup>();
            }

            try
            {
                using (StreamReader reader = new StreamReader(_path + "Services.xml"))
                {
                    XmlSerializer sw = new XmlSerializer(typeof(ServiceBase[]), new Type[] { typeof(StopService), typeof(TurnstileService), typeof(QueueService), typeof(System.Windows.Media.LineSegment), typeof(System.Windows.Media.PolyLineSegment), typeof(System.Windows.Media.BezierSegment) });
                    ServiceBase[] services = (ServiceBase[])sw.Deserialize(reader);
                    sim.ServicesList = new List<ServiceBase>(services);
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                sim.ServicesList = new List<ServiceBase>();
            }

            try
            {
                using (StreamReader reader = new StreamReader(_path + "RoadGraph.xml"))
                {
                    XmlSerializer sw = new XmlSerializer(typeof(GraphContainer));
                    GraphContainer graph = (GraphContainer)sw.Deserialize(reader);
                    Graph<WayPoint, System.Windows.Media.PathFigure> roadGraph = new Graph<WayPoint, System.Windows.Media.PathFigure>();
                    for (int i = 0; i < graph.VertecesList.Count; i++)
                    {
                        roadGraph.Add(graph.VertecesList[i]);
                    }
                    for (int i = 0; i < graph.EdgesList.Count; i++)
                    {
                        roadGraph.AddEdge(graph.VertecesList[graph.EdgesList[i].from_id], graph.VertecesList[graph.EdgesList[i].to_id], graph.EdgesList[i].data);
                    }
                    sim.RoadGraph = roadGraph;
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                Console.WriteLine("Can't load Road Graph");
                sim.RoadGraph = new Graph<WayPoint, System.Windows.Media.PathFigure>();
            }

            sim.agentsList = new List<AgentBase>();

            int last_agent_id = 0, last_service_id = 0, last_group_id = 0;
            for (int i = 0; i < sim.agentGroups.Count; i++)
            {
                if (last_group_id < sim.agentGroups[i].ID)
//.........这里部分代码省略.........
开发者ID:nomoreserious,项目名称:FlowSimulation,代码行数:101,代码来源:ScenarioReader.cs

示例11: GetSimple

 private static Graph<string> GetSimple()
 {
     Graph<string> g = new Graph<string>();
     g.Add(new Edge<string>("A", "B"));
     g.Add(new Edge<string>("B", "C"));
     g.Add(new Edge<string>("A", "C"));
     g.Add(new Edge<string>("D", "C"));
     g.Add(new Edge<string>("E", "C"));
     g.Add(new Edge<string>("E", "A"));
     return g;
 }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:11,代码来源:GraphGenerator.Graphs.cs

示例12: Test3

        static void Test3()
        {
            IGraph g = new Graph();
            g.Add(CreatePackage("ef", "1.0.0"));
            g.Add(CreatePackage("ef", "2.0.0"));
            g.Add(CreatePackage("ef", "3.0.0"));
            g.Add(CreatePackage("ef", "4.0.0"));

            IGraph q = new Graph();
            q.Assert(new Variable("package"), new Name("id"), new Variable("id"));
            q.Assert(new Variable("package"), new Name("version"), new Variable("version"));

            IGraph t = new Graph();
            t.Assert(new Variable("registration"), new Name("id"), new Variable("id"));
            t.Assert(new Variable("registration"), new Name("version"), new Variable("version"));

            Func<IDictionary<string, object>, object> func = (scope) =>
            {
                return new Name(string.Format("http://nuget.org/package/{0}", scope["id"]));
            };

            var p = new Dictionary<string, object>
            {
                { "registration", func },
            };

            IGraph r = Query.Construct(g, q, t, p);

            foreach (var entry in r.Match(Triple.Empty))
            {
                Console.WriteLine(entry);
            }
        }
开发者ID:NuGet,项目名称:Entropy,代码行数:33,代码来源:Program.cs

示例13: GetLarge

 private static Graph<string> GetLarge()
 {
     Graph<string> g = new Graph<string>();
     foreach (var v in new[] {"B", "C", "D"}) {
         g.Add(new Edge<string>("A", v));
     }
     foreach (var v in new[] { "C", "E" }) {
         g.Add(new Edge<string>("B", v));
     }
     foreach (var v in new[] { "E", "F" }) {
         g.Add(new Edge<string>("C", v));
     }
     foreach (var v in new[] { "F", "G" }) {
         g.Add(new Edge<string>("D", v));
     }
     foreach (var v in new[] { "H" }) {
         g.Add(new Edge<string>("E", v));
     }
     foreach (var v in new[] { "H", "I", "J", "G" }) {
         g.Add(new Edge<string>("F", v));
     }
     foreach (var v in new[] { "K" }) {
         g.Add(new Edge<string>("G", v));
     }
     foreach (var v in new[] { "O", "L" }) {
         g.Add(new Edge<string>("H", v));
     }
     foreach (var v in new[] { "L", "M", "J" }) {
         g.Add(new Edge<string>("I", v));
     }
     foreach (var v in new[] { "M", "N", "K" }) {
         g.Add(new Edge<string>("J", v));
     }
     foreach (var v in new[] { "N", "R" }) {
         g.Add(new Edge<string>("K", v));
     }
     foreach (var v in new[] { "O", "M" }) {
         g.Add(new Edge<string>("L", v));
     }
     foreach (var v in new[] { "O", "P", "N" }) {
         g.Add(new Edge<string>("M", v));
     }
     foreach (var v in new[] { "Q", "R" }) {
         g.Add(new Edge<string>("N", v));
     }
     foreach (var v in new[] { "S", "P" }) {
         g.Add(new Edge<string>("O", v));
     }
     foreach (var v in new[] { "S", "T", "Q" }) {
         g.Add(new Edge<string>("P", v));
     }
     foreach (var v in new[] { "T", "R" }) {
         g.Add(new Edge<string>("Q", v));
     }
     foreach (var v in new[] { "T" }) {
         g.Add(new Edge<string>("R", v));
     }
     foreach (var v in new[] { "Z" }) {
         g.Add(new Edge<string>("S", v));
     }
     foreach (var v in new[] { "Z" }) {
         g.Add(new Edge<string>("T", v));
     }
     return g;
 }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:65,代码来源:GraphGenerator.Graphs.cs

示例14: RenderLicense

 private static void RenderLicense()
 {
     Graph<Node> l = new Graph<Node>();
     List<Node> list = new List<Node>();
     list.AddRange(new[] {
         new Node { Label = "Please" },
         new Node { Label = "refer" },
         new Node { Label = "to" },
         new Node { Label = "the" },
         new Node { Label = "LICENSE" },
         new Node { Label = "file" },
         new Node { Label = "for" },
         new Node { Label = "license" },
         new Node { Label = "details" }
     });
     for (int i = 1; i < list.Count; i++) {
         l.Add(new Edge<Node>(list[i - 1], list[i]));
     }
     RenderGraph(l);
 }
开发者ID:maxwellb,项目名称:GraphEx,代码行数:20,代码来源:Program.cs

示例15: Save

 private void Save()
 {
     //if (_vertexes.Any(v=>v.InCount == 0 && v.OutCount == 0))
     //{
     //    if (MessageBox.Show("Все точки, не имеющие связей (обозначены серым цветом) будут удалены. Продолжить?", "Внимание", MessageBoxButton.YesNo) == MessageBoxResult.No)
     //    {
     //        return;
     //    }
     //    for (int i = 0; i < _vertexes.Count; i++)
     //    {
     //        if (_vertexes[i].InCount == 0 && _vertexes[i].OutCount == 0)
     //        {
     //            _vertexes.RemoveAt(i);
     //            i--;
     //        }
     //    }
     //}
     if (_vertexes.Any(v => v.Node.IsServicePoint && !v.Node.ServiceId.HasValue))
     {
         MessageBox.Show("Для одной или более точек не указан сервис");
         return;
     }
     //Собираем граф дорожной сети
     RoadGraph = new Graph<WayPoint, PathFigure>();
     foreach (var node in _vertexes.Select(v=>v.Node))
     {
         RoadGraph.Add(node);
     }
     foreach (var edge in _edges)
     {
         RoadGraph.AddEdge(edge.NodeFrom, edge.NodeTo, edge.PathData);
     }
     DialogResult = true;
     CloseView = true;
 }
开发者ID:nomoreserious,项目名称:FlowSimulation,代码行数:35,代码来源:RoadGraphConfigViewModel.cs


注:本文中的Graph.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。