Beispiel #1
0
        internal static async Task <BasicGraphToGraphMlMapping> LoadBasicGraphFromUrl(string url, string graphname)
        {
            if (!graphname.Contains(".xml"))
            {
                graphname += ".xml";
            }
            var tmpgraphpath = Path.Combine(_graphdir, "tmp_" + graphname);
            var graphpath    = Path.Combine(_graphdir, graphname);

            using (var client = new WebClient())
            {
                var proxyConfig = VGAppSettings.RemoteRequestProxy;
                if (proxyConfig != "")
                {
                    client.Proxy = new WebProxy(proxyConfig);
                }
                client.DownloadFile(url, tmpgraphpath);
            }
            await IsolateGraphInFile(tmpgraphpath, graphpath);

            var tinkerGraph = await ReadGraphMl(graphpath);

            BasicGraphModel graph = new BasicGraphModel();

            graph.Name = Path.GetFileNameWithoutExtension(graphpath);
            BasicGraphToGraphMlMapping graphToGraphMlMapping = new BasicGraphToGraphMlMapping(tinkerGraph, graph);

            File.Delete(tmpgraphpath);
            return(graphToGraphMlMapping);
        }
Beispiel #2
0
        public override void Invoke(BasicGraphModel g)
        {
            Node node0 = g.Nodes.First(n => n.Id == (string)Parameters[typeof(string)][0]);
            Node node1 = g.Nodes.First(n => n.Id == (string)Parameters[typeof(string)][1]);

            Action.Invoke(node0, node1, g);
        }
Beispiel #3
0
        internal static Task <bool> WriteToGraphMlFile(BasicGraphModel graph, string filename)
        {
            if (filename == String.Empty)
            {
                return(Task.FromResult(false));
            }
            filename = Path.Combine(_graphdir, filename + ".xml");
            TinkerGrapĥ tinkerGraph = new TinkerGrapĥ();

            foreach (var node in graph.Nodes)
            {
                var vertex = tinkerGraph.AddVertex(node.Id);
                vertex.SetProperty("posx", node.Pos.X);
                vertex.SetProperty("posy", node.Pos.Y);
                vertex.SetProperty("name", node.Name != null?node.Name:" ");
                vertex.SetProperty("vgid", node.Id);
            }
            foreach (var edge in graph.Edges)
            {
                IVertex start = tinkerGraph.GetVertex(edge.StartNode.Id);
                IVertex end   = tinkerGraph.GetVertex(edge.EndNode.Id);
                var     edge_ = tinkerGraph.AddEdge(edge.Id, start, end, $"{edge.Weight}");
                edge_.SetProperty("weight", edge.Weight);
                edge_.SetProperty("vgid", edge.Id);
                edge_.SetProperty("isdirected", graph.IsDirected);
            }
            GraphMlWriter writer = new GraphMlWriter(tinkerGraph);

            using (var fos = File.Open(filename, FileMode.Create))
            {
                writer.OutputGraph(fos);
            }
            return(Task.FromResult(true));
        }
Beispiel #4
0
        public override void Invoke(BasicGraphModel g)
        {
            string n0id   = (string)Parameters[typeof(string)][0];
            string n1id   = (string)Parameters[typeof(string)][1];
            double weight = (double)Parameters[typeof(double)][0];

            Action.Invoke(n0id, n1id, weight, g);
        }
Beispiel #5
0
        public override void Invoke(BasicGraphModel g)
        {
            string n = (string)Parameters[typeof(string)][0];
            double x = (double)Parameters[typeof(double)][0];
            double y = (double)Parameters[typeof(double)][1];

            Action.Invoke(n, x, y, g);
        }
        public override void Invoke(BasicGraphModel g)
        {
            string n0name = Parameters[typeof(string)][0].ToString().Trim();
            string n1name = Parameters[typeof(string)][1].ToString().Trim();

            string n0id   = g.Nodes.First(x => x.Name == n0name).Id;
            string n1id   = g.Nodes.First(x => x.Name == n1name).Id;
            double weight = (double)Parameters[typeof(double)][0];

            Action.Invoke(n0id, n1id, weight, g);
        }
Beispiel #7
0
        public static BasicGraphModel ConvertToBasicGraph(IGraph iGraph)
        {
            var nodeCnt = 0;
            var posxdefault = 0;
            var posydefault = 0;
            var nodes = iGraph.GetVertices().Select(v =>
            {
                var nameProp = v.GetProperty("name");
                var posxProp = v.GetProperty("posx");
                var posyProp = v.GetProperty("posy");
                var idProp = v.GetProperty("vgid");
                if (nameProp == null) nameProp = v.Id;
                if (posxProp == null) posxProp = nodeCnt++ % 3 == 0 ? posxdefault = 0 : posxdefault += 10;
                if (posyProp == null) posyProp = nodeCnt++ % 3 == 0 ? posydefault += 10 : posydefault;

                return new Node
                {
                    Id = v.Id.ToString(),
                    Name = nameProp.ToString(),
                    Pos = new Vector2(Convert.ToSingle(posxProp.ToString()), Convert.ToSingle(posyProp.ToString()))
                };

            }).ToList();
            bool directedGraph = true;
            var edges = iGraph.GetEdges().Select(e =>
            {
                var startnode = nodes.FirstOrDefault(n => e.GetVertex(Direction.Out).Id.ToString() == n.Id);
                var endnode = nodes.FirstOrDefault(n => e.GetVertex(Direction.In).Id.ToString() == n.Id);
                try { directedGraph = Convert.ToBoolean(e.GetProperty("isdirected")); } catch { }
                var edge = new Edge
                {
                    Id = e.Id.ToString(),
                    StartNode = startnode,
                    EndNode = endnode,
                    Weight = Convert.ToDouble(e.GetProperty("weight"))
                };
                startnode.Edges.Add(edge);
                endnode.Edges.Add(edge);
                return edge;
            }).ToList();

            BasicGraphModel graph = new BasicGraphModel()
            {
                Nodes = nodes,
                Edges = edges,
                IsDirected = directedGraph,
            };

            return graph;
        }
Beispiel #8
0
        public static BasicGraphModel CreateRandomGraph(string Graphname, int nodeCount, int edgeCount =  35, double UpperBound = 50, double LowerBound = -50)
        {
            Random random = new Random();
            BasicGraphModel GraphModel = new BasicGraphModel() { Name = Graphname };
            
            for (int i = 0; i < nodeCount; i++)
            {
                GraphModel.Nodes.Add(new Node()
                {
                    Id = i.ToString(),
                    Name = i.ToString(),
                    Pos = new Vector2((float)(random.NextDouble() * (UpperBound - LowerBound) + LowerBound), (float)(random.NextDouble() * (UpperBound - LowerBound) + LowerBound)),
                });
            }
            for (int i = 0; i < edgeCount; i++)
            {
                Node node1,node2;
                node1 = GraphModel.Nodes.FirstOrDefault(x => x.Edges.Count == 0);
                node2 = GraphModel.Nodes.FirstOrDefault(x => x.Edges.Count == 0 && x != node1);
                if(node1 == null)
                {
                   var index = random.Next(0, nodeCount - 1);
                   node1 = GraphModel.Nodes[index];
                }
                if (node2 == null)
                {
                    var index = random.Next(0, nodeCount - 1);
                    node2 = GraphModel.Nodes[index];
                }

                Edge edge = new Edge() { StartNode = node1, EndNode = node2, Id = (i + 1).ToString(), Weight = random.NextDouble() * 10  };
                if(GraphModel.Edges.Any(x=>x.StartNode == node1 && x.EndNode == node2))
                {
                    i--;
                }
                else
                {
                    node1.Edges.Add(edge);
                    node2.Edges.Add(edge);
                    GraphModel.Edges.Add(edge);
                }
                
            }
            return GraphModel;
        }
Beispiel #9
0
        public static BasicGraphModel CreateNewGraphModel()
        {
            var nodes = new System.Collections.Generic.List<Data.Additional.Models.Node>{
                new Data.Additional.Models.Node() {
                    Id = "0",
                    Pos = new System.Numerics.Vector2(-10,10),
                    Name = "Knoten A"
                },
                new Data.Additional.Models.Node() {
                    Id = "1",
                    Pos = new System.Numerics.Vector2(10,-10),
                    Name = "Knoten B"

                }

            };
            var graphmodel = new BasicGraphModel()
            {
                Nodes = nodes,
                Name = "Unbenannter-Graph"
            };
            return graphmodel;
        }
 public override void Invoke(BasicGraphModel g)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 public DijkstraAlgorithm(BasicGraphModel model, string startNodeId = "-1")
 {
     this.Model = model;
     Init(startNodeId);
 }
Beispiel #12
0
 public GraphCommandProcessor(BasicGraphModel model)
 {
     this.model = model;
 }
Beispiel #13
0
 public abstract void Invoke(BasicGraphModel g);