예제 #1
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            var _NumberOfVertices        = 100000;
            var _NumberOfConcurrentTasks = 8;


            // Create a new simple property graph
            var _graph = GraphFactory.CreateGenericPropertyGraph(1);

            var _Task = new Task[_NumberOfConcurrentTasks];

            var Stopwatch = new Stopwatch();

            Stopwatch.Restart();

            for (var i = 0; i < _NumberOfConcurrentTasks; i++)
            {
                _Task[i] = Task.Factory.StartNew((iCopy) => { for (var j = 0; j < _NumberOfVertices / _NumberOfConcurrentTasks; j++)
                                                              {
                                                                  _graph.AddVertex(v => v.SetProperty("Task", iCopy).SetProperty("Number", j));
                                                              }
                                                 }, i, new CancellationToken())
                           .ContinueWith(task => Console.WriteLine("Task: {0} Completed.", task.GetHashCode()));
            }

            Task.WaitAll(_Task);

            Stopwatch.Stop();
            Console.WriteLine("All tasks completed.");
            Console.WriteLine("Added " + _NumberOfVertices + " in " + Stopwatch.Elapsed.TotalSeconds + "s using " + _NumberOfConcurrentTasks + " tasks (" + Math.Round(_NumberOfVertices / Stopwatch.Elapsed.TotalSeconds) + " vertices/s).");

            Console.WriteLine("Number of total vertices within the graph: " + _graph.NumberOfVertices());

            Console.WriteLine("TaskIds / NumberOfVertices: ");
            _graph.Vertices().
            P("Task").
            DuplicateFilter().
            ForEach(TaskId => {
                if (TaskId != null)
                {
                    Console.WriteLine("Task '" + TaskId + "' added " +
                                      //_graph.NumberOfVertices(v => v.Contains("Task", TaskId)) +
                                      " vertices."
                                      );
                }
            }
                    );
            Console.WriteLine("");


            while (true)
            {
                Thread.Sleep(10);
            }
        }
예제 #2
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            var Graph1 = GraphFactory.CreateGenericPropertyGraph(1);
            var Graph2 = GraphFactory.CreateGenericPropertyGraph(2);
            var Graph3 = GraphFactory.CreateGenericPropertyGraph(3);
            var Graph4 = GraphFactory.CreateGenericPropertyGraph(4);
            var Graph5 = GraphFactory.CreateGenericPropertyGraph(5);

            var PartitionGraph1 = GraphFactory.CreatePartitionGraph(23UL, "Stack of graphs 1-5", Graph1, Graph2, Graph3, Graph4, Graph5);
            var PartitionGraph2 = Graph1.CreatePartitionGraph(42UL, "Stack of graphs 1-3", Graph2, Graph3);

            Graph2.OnVertexAddition.OnNotification          += (graph, vertex) => Console.WriteLine("Vertex #" + vertex.Id + " had been added to graph #" + graph.Id);
            PartitionGraph1.OnVertexAddition.OnNotification += (graph, vertex) => Console.WriteLine("Vertex #" + vertex.Id + " had been added to the partition graph");
            PartitionGraph1.OnVertexAddition.OnVoting       += (graph, vertex, vote) => { if (vertex.Id == 7)
                                                                                          {
                                                                                              Console.WriteLine("The vertex id '7' is not allowed!"); vote.Deny();
                                                                                          }
            };

            Graph1.AddVertex(1, "vertex", v => v.SetProperty("GraphId", 1));
            Graph2.AddVertex(2, "vertex", v => v.SetProperty("GraphId", 2));
            Graph3.AddVertex(3, "vertex", v => v.SetProperty("GraphId", 3));
            Graph4.AddVertex(4, "vertex", v => v.SetProperty("GraphId", 4));
            Graph5.AddVertex(5, "vertex", v => v.SetProperty("GraphId", 5));

            PartitionGraph1.AddVertex(6, "vertex", v => v.SetProperty("GraphId", 6));
            PartitionGraph1.AddVertex(7, "vertex", v => v.SetProperty("GraphId", 7));

            Console.WriteLine(PartitionGraph1.NumberOfVertices());
            Console.WriteLine(PartitionGraph1.NumberOfVertices(v => v.Id != 3));

            var v1a = PartitionGraph1.VertexById(1);    // valid
            var v2a = PartitionGraph1.VertexById(2);    // valid
            var v3a = PartitionGraph1.VertexById(3);    // valid
            var v4a = PartitionGraph1.VertexById(4);    // valid
            var v5a = PartitionGraph1.VertexById(5);    // valid
            var v6a = PartitionGraph1.VertexById(6);    // valid
            var v7x = Graph1.VertexById(7);             // null
            var v7a = PartitionGraph1.VertexById(7);    // null

            var v1b = PartitionGraph2.VertexById(1);    // valid
            var v2b = PartitionGraph2.VertexById(2);    // valid
            var v3b = PartitionGraph2.VertexById(3);    // valid
            var v4b = PartitionGraph2.VertexById(4);    // null
            var v5b = PartitionGraph2.VertexById(5);    // null
            var v6b = PartitionGraph2.VertexById(6);    // valid
            var v7b = PartitionGraph2.VertexById(7);    // null
        }
예제 #3
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            // graph1 -> *SerializerArrow -> UDPMulticastSenderArrow ==[IP MULTICAST]=> UDPMulticastReceiverArrow -> -> graph2

            // Create two independend graphs
            var graph1 = GraphFactory.CreateGenericPropertyGraph(1);
            var graph2 = GraphFactory.CreateGenericPropertyGraph(2);


            // Create an arrow sending all messages to UDP multicast
            var UDPMulticastSenderArrow = new UDPMulticastSenderArrow <String>("224.100.0.1", IPPort.Parse(9001));

            var GraphSerializer       = graph1.NewGraphMLSerializer(IncludePropertyTypes: true);
            var VertexSerializerArrow = GraphSerializer.NewVertexSerializerArrow(UDPMulticastSenderArrow);
            var EdgeSerializerArrow   = GraphSerializer.NewEdgeSerializerArrow(UDPMulticastSenderArrow);
            var GraphSerializerArrow  = GraphSerializer.NewGraphSerializerArrow(UDPMulticastSenderArrow);


            // Connect the graph1 vertex/edge added events to the serializers
            //graph1.OnVertexAdded += VertexSerializerArrow.ReceiveMessage;
            //graph1.OnEdgeAdded   +=   EdgeSerializerArrow.ReceiveMessage;


            // Create an arrow receiving messages from UDP multicast
            var UDPMulticastReceiverArrow = new UDPMulticastReceiverArrow <String>("224.100.0.1", IPPort.Parse(9001));

            UDPMulticastReceiverArrow.OnMessageAvailable += (Sender, Message) => Console.WriteLine(Sender.Address + ":" + Sender.Port + " => " + Message);


            // Populate the graph
            var v1 = graph1.AddVertex(v => v.SetProperty("graph", 1));
            var v2 = graph1.AddVertex(v => v.SetProperty("graph", 1));
            var v3 = graph1.AddVertex(v => v.SetProperty("graph", "1"));
            var v4 = graph1.AddVertex(v => v.SetProperty("graph", "2"));

            var e1 = graph1.AddEdge(v1, "links", v2, e => e.SetProperty("weight", 0.34));
            var e2 = graph1.AddEdge(v2, "links", v3);

            GraphSerializerArrow.ReceiveMessage(graph1);

            while (true)
            {
                Thread.Sleep(100);
            }
        }
예제 #4
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            // Create a new simple property graph
            var graph = GraphFactory.CreateGenericPropertyGraph(1);

            var v0 = graph.AddVertex("person", v => v.SetProperty("name", "Alice"));
            var v1 = graph.AddVertex("person", v => v.SetProperty("name", "Bob"));
            var v2 = graph.AddVertex("person", v => v.SetProperty("name", "Carol"));

            var s1 = graph.ToString();
            var s2 = v0.ToString();

            var e0 = graph.AddEdge(v0, v1);
            var e1 = graph.AddEdge(v1, v2);
            var e2 = graph.AddEdge(v2, v0);

            using (var transaction = graph.BeginTransaction())
            {
                //ToDo: Add delegates denying all modifications of the underlying graph!

                var txgraph = transaction.TXObject;

                var v0_ = txgraph.VertexById(0);
                var v1_ = txgraph.VertexById(1);
                var nv_ = txgraph.NumberOfVertices();

                var v3 = txgraph.AddVertex("person", v => v.SetProperty("name", "Dave"));
                var v4 = txgraph.AddVertex("person", v => v.SetProperty("name", "Eve"));
                var v5 = txgraph.AddVertex("thing", v => v.SetProperty("type", "car"));

                var e3 = txgraph.AddEdge(v0, v3);
                var e4 = txgraph.AddEdge(v1, v4);

                transaction.Commit(); //ToDo: Add delegates denying all modifications of the tx graph!
            } // If the transaction was not committed -> Rollback()

            while (true)
            {
                Thread.Sleep(100);
            }
        }
예제 #5
0
        /// <summary>
        /// Main routine!
        /// </summary>
        /// <param name="myArgs">The command line arguments.</param>
        public SocialGraphDemo(String[] myArgs)
        {
            //var _Graph = new SimplePropertyGraph();
            //var _Vertex1 = _Graph.AddVertex(5, v => v.SetProperty("key1", "value1").
            //                                          SetProperty("key2", 42));
            //var _Vertex2 = _Graph.AddVertex(23);

            //var b = _Vertex1.CompareTo(_Vertex2);

            //var x = _Vertex1.AsDynamic().key1;

            //_Vertex.GetProperty(

            //var aa = new List<Double>() { 1, 3 };
            //var bb = aa.Sum(_ => _ * _);


            //var _g      = TinkerGraphFactory.CreateTinkerGraph();
            //var _graph  = DemoGraphFactory.CreateDemoGraph();

            //var _index1 = _graph.CreateVerticesIndex("IdxNames",
            //                                         "DictionaryIndex",
            //                                         e => e["name"].ToString().ToLower() +
            //                                              e["age"].ToString(),
            //                                         e => Indexing.HasKeys(e, "name", "age"));

            //var _index2 = _graph.CreateVerticesIndex<Int32>("IdxAges",
            //                                                "DictionaryIndex",
            //                                                e => (Int32) e["age"],
            //                                                e => Indexing.HasKeys(e, "age"));

            //var _Idx = _graph.VerticesIndices().First();
            //_Idx.Insert(_graph.Vertices());
            //_index2.Insert(_graph.Vertices());

            ////var x = _Idx.As();
            //var y = _Idx.Equals("alice18").ToList();
            //var z = _Idx.Equals(18).ToList();


            ////_Idx.GetType().ContainsGenericParameters

            //var m = _index2.Equals(18).First();
            //var n = _index2.LargerThan(20).ToList();
            //foreach (var nn in n)
            //    if (((Int32) nn.GetProperty("age")) <= 20)
            //        throw new Exception("Mist!");

            //var n2 = _index1.LargerThan(20).ToList();

            // Create SocialGraph, if not existant!
            if (!File.Exists(_FileName))
            {
                GenerateSocialGraph();
            }


            // Create an in-memory graph using reflection
            //IPropertyGraph _SocialGraph = null;
            //var _AD = new AutoDiscovery<IPropertyGraph>(true);
            //if (!_AD.TryActivate("InMemoryPropertyGraph", out _SocialGraph))
            //{
            //    Console.WriteLine("Could not find the 'InMemoryGraph' implementation!");
            //    Environment.Exit(1);
            //}
            var _SocialGraph = GraphFactory.CreateGenericPropertyGraph(1);


            // Import vertices and edges
            ImportVertices(_SocialGraph);
            ImportEdges(_SocialGraph);


            var all1 = _SocialGraph.NumberOfVertices();
            var all2 = _SocialGraph.Vertices(v => v.Id > 10).Count();

            Console.ReadLine();
        }
예제 #6
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            var Stopwatch = new Stopwatch();
            var PRNG      = new Random();

            // Create a new simple property graph
            var _Graph = GraphFactory.CreateGenericPropertyGraph(1);

            var NumberOfUsers      = 20000UL;
            var NumberOfIterations = 30;
            var MinNumberOfEdges   = 15;
            var MaxNumberOfEdges   = 25;

            var CountedNumberOfEdges = 0UL;


            var d = new Dictionary <UInt64, UInt64>();

            for (var i = 0UL; i < NumberOfUsers; i++)
            {
                d.Add(i, i);
            }

            Stopwatch.Restart();
            foreach (var INT in d)
            {
                CountedNumberOfEdges += INT.Value;
            }
            Stopwatch.Stop();
            Console.WriteLine(Stopwatch.Elapsed.TotalMilliseconds + "ms");

            Stopwatch.Restart();
            var b = new UInt64[NumberOfUsers];

            foreach (var INT in b)
            {
                CountedNumberOfEdges += INT;
            }
            Stopwatch.Stop();
            Console.WriteLine(Stopwatch.Elapsed.TotalMilliseconds + "ms");


            IReadOnlyGenericPropertyVertex <UInt64, Int64, String, String, Object,
                                            UInt64, Int64, String, String, Object,
                                            UInt64, Int64, String, String, Object,
                                            UInt64, Int64, String, String, Object> ActualVertex = null;

            var Vertices = new IReadOnlyGenericPropertyVertex <UInt64, Int64, String, String, Object,
                                                               UInt64, Int64, String, String, Object,
                                                               UInt64, Int64, String, String, Object,
                                                               UInt64, Int64, String, String, Object> [NumberOfUsers + 1];

            var Measurements = new Double[NumberOfIterations];

            Stopwatch.Start();

            Vertices[0] = _Graph.AddVertex(1 - 1, "default");

            for (var VertexId = 2UL - 1; VertexId < NumberOfUsers; VertexId++)
            {
                ActualVertex = _Graph.AddVertex(VertexId, "default", v => v.SetProperty("Name", "User" + VertexId)
                                                .SetProperty("Age", PRNG.Next(0, 150)));
                Vertices[VertexId - 1] = ActualVertex;
                _Graph.AddEdge(ActualVertex, Vertices[PRNG.Next(0, (Int32)VertexId - 1)]);

                var NumberOfAdditionalEdges = (UInt64)PRNG.Next(MinNumberOfEdges, MaxNumberOfEdges);

                do
                {
                    _Graph.AddEdge(ActualVertex, Vertices[PRNG.Next(0, (Int32)VertexId - 1)]);
                } while (ActualVertex.OutDegree() < NumberOfAdditionalEdges);

                if (VertexId % 10000UL == 0)
                {
                    Console.WriteLine(VertexId);
                }
            }

            Stopwatch.Stop();
            Console.WriteLine("Creation Time: " + Stopwatch.Elapsed.TotalMilliseconds + "ms");
            Console.WriteLine();

            //var _ROGraph = new SimpleReadOnlyPropertyGraph(2, _Graph,
            //                                               SyncedVertexIds:  true,
            //                                               SyncedEdgeIds:    true
            //                                               );

            for (var Iteration = 0; Iteration < NumberOfIterations; Iteration++)
            {
                CountedNumberOfEdges = 0;

                Stopwatch.Restart();

                foreach (var _Vertex in _Graph.Vertices())
                {
                    CountedNumberOfEdges += (UInt64)_Vertex.OutDegree();
                }

                Stopwatch.Stop();
                Measurements[Iteration] = Stopwatch.Elapsed.TotalMilliseconds;
                Console.WriteLine(CountedNumberOfEdges + " edges in " + Stopwatch.Elapsed.TotalMilliseconds + "ms");
            }

            //var AverageAndStdDev = Measurements.AverageAndStdDev();
            //Console.WriteLine("Mean: " + AverageAndStdDev.Item1 + ", stddev: " + AverageAndStdDev.Item2);
            //Console.ReadLine();
        }
예제 #7
0
        /// <summary>
        /// Run the tutorial.
        /// </summary>
        public void Run()
        {
            var _Stopwatch               = new Stopwatch();
            var _Random                  = new Random();
            var _NumberOfVertices        = 10000;
            var _NumberOfEdges           = 600000;
            var _NumberOfConcurrentTasks = 10;


            // Create a new simple property graph
            var _graph = GraphFactory.CreateGenericPropertyGraph(1);

            _Stopwatch.Start();

            // Add vertices
            _NumberOfVertices.Loop(() => _graph.AddVertex());
            Console.WriteLine(_Stopwatch.Elapsed.TotalSeconds + "s : " + _NumberOfVertices + " vertices added.");


            // Add Edges
            _NumberOfEdges.Loop(() => _graph.AddEdge(_graph.VertexById((UInt64)_Random.Next(_NumberOfVertices) + 1),
                                                     "knows",
                                                     _graph.VertexById((UInt64)_Random.Next(_NumberOfVertices) + 1)));

            Console.WriteLine(_Stopwatch.Elapsed.TotalSeconds + "s : " + _NumberOfEdges + " vertices added.");

            //var Workload = _graph.Vertices().
            //               ToPartitions((UInt64) Math.Round((Double) _NumberOfVertices / (Double) _NumberOfConcurrentTasks));

            Double TimeStamp1, TimeStamp2;

            TimeStamp1 = _Stopwatch.Elapsed.TotalSeconds;
            var TraversalGraph = _graph.ToAdjacencyMatrixGraph <int>();

            TimeStamp2 = _Stopwatch.Elapsed.TotalSeconds;

            Console.WriteLine(Math.Round(TimeStamp2 - TimeStamp1, 6) + " secs to create the TraversalGraph.");

            #region Vertices.Out()

            //Console.WriteLine(Environment.NewLine + "Traversing all Vertices.Out()");

            TimeStamp1 = _Stopwatch.Elapsed.TotalSeconds;

            _graph.Vertices().Out().ForEach(x => { });

            TimeStamp2 = _Stopwatch.Elapsed.TotalSeconds;

            //Parallel.ForEach(_graph.Vertices(), x => x.Out().ForEach(y => { }));
            ////_graph.Vertices().AsParallel().Out().ForEach(x => { });

            //var TimeStamp3 = _Stopwatch.Elapsed.TotalSeconds;

            Console.WriteLine(Math.Round(TimeStamp2 - TimeStamp1, 6) + " secs (single threaded)");
            Console.WriteLine(Math.Round(_NumberOfEdges / (TimeStamp2 - TimeStamp1)) + " traversals per second (single threaded)");
            //Console.WriteLine(Math.Round(_NumberOfEdges / (TimeStamp3 - TimeStamp2)) + " traversals per second (multi threaded)");


            TimeStamp1 = _Stopwatch.Elapsed.TotalSeconds;

            _graph.Vertices().Out().ForEach(x => { });

            TimeStamp2 = _Stopwatch.Elapsed.TotalSeconds;

            Console.WriteLine(Math.Round(TimeStamp2 - TimeStamp1, 6) + " secs (single threaded)");
            Console.WriteLine(Math.Round(_NumberOfEdges / (TimeStamp2 - TimeStamp1)) + " traversals per second (single threaded)");


            #endregion

            #region Vertices.Out().Out()

            //Console.WriteLine(Environment.NewLine + "Traversing all Vertices.Out().Out()");

            //var TimeStamp4 = _Stopwatch.Elapsed.TotalSeconds;

            //_graph.Vertices().Out().Out().ForEach(x => { });

            //var TimeStamp5 = _Stopwatch.Elapsed.TotalSeconds;

            //Parallel.ForEach(_graph.Vertices(), x => x.Out().Out().ForEach(y => { }));

            ////_graph.Vertices().ForEach(x => x.OutDegree());

            ////var a = from v
            ////        in _graph.Vertices()//.AsParallel()
            ////        select v.OutDegree();


            //var TimeStamp6 = _Stopwatch.Elapsed.TotalSeconds;

            //Console.WriteLine(Math.Round((_NumberOfEdges^2) / (TimeStamp5 - TimeStamp4)) + " traversals per second (single threaded)");
            //Console.WriteLine(Math.Round((_NumberOfEdges^2) / (TimeStamp6 - TimeStamp5)) + " traversals per second (multi threaded)");

            #endregion

            while (true)
            {
                Thread.Sleep(100);
            }
        }