Example #1
0
        void CreateEdgeThreadProc(object par)
        {
            EdgeCreationThreadObject p = (EdgeCreationThreadObject)par;
            long start;
            long end;

            if (p.threadCount - 1 == p.threadIndex)
            {
                start = 0;
                end   = edgeCount / (p.threadCount) + edgeCount % (p.threadCount);
            }
            else
            {
                start = 0;
                end   = edgeCount / p.threadCount;
            }
            long times = (long)Math.Log(nodeCount, 2);

            for (long i = start; i < end; i++)
            {
                long   x1          = 0;
                long   x2          = 0;
                long   y1          = nodeCount;
                long   y2          = nodeCount;
                double probability = 0;
                for (int timesIndex = 0; timesIndex < times; timesIndex++)
                {
                    probability = randomArray[p.threadIndex].NextDouble();
                    if (probability <= 0.4)
                    {
                        y1 = y1 - (y1 - x1) / 2;
                        y2 = y2 - (y2 - x2) / 2;
                    }
                    else if (probability < 0.55 && probability > 0.4)
                    {
                        x1 = x1 + (y1 - x1) / 2;
                        y2 = y2 - (y2 - x2) / 2;
                    }
                    else if (probability > 0.55 && probability <= 0.75)
                    {
                        x2 = x2 + (y2 - x2) / 2;
                        y1 = y1 - (y1 - x1) / 2;
                    }
                    else if (probability > 0.75)
                    {
                        x1 = x1 + (y1 - x1) / 2;
                        x2 = x2 + (y2 - x2) / 2;
                    }
                }
                using (var node = Global.LocalStorage.UseGraphNode(y2))
                {
                    if (!node.Edges.Contains(y1))
                    {
                        if (node.EdgeCount < node.Edges.Count)
                        {
                            node.Edges[node.EdgeCount++] = y1;
                        }
                        else
                        {
                            int         reserveNum    = avgDegree;
                            List <long> reserved_list = new List <long>();
                            reserved_list.AddRange(Enumerable.Range(-avgDegree, reserveNum).Select(x => (long)x));
                            node.Edges.AddRange(reserved_list);
                            node.Edges[node.EdgeCount++] = y1;
                        }
                    }
                }
            }
        }
Example #2
0
        public void CreatGraph()
        {
            int threadCount = Environment.ProcessorCount;

            Thread[] threadNum = new Thread[threadCount];
            ////////////////////////////////PHASE 1///////////////////////////////
            Console.WriteLine("Generating ID values");
            Stopwatch s = new Stopwatch();

            s.Start();
            TrinityConfig.CurrentRunningMode = RunningMode.Embedded;
            TrinityConfig.DefragInterval     = 2500;
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
            {
                NodeCreationThreadObject p = new NodeCreationThreadObject(threadCount, threadIndex);
                threadNum[threadIndex] = new Thread(CreateGraphNodeThreadProc);
                threadNum[threadIndex].Start(p);
            }
            for (int inde = 0; inde < threadCount; inde++)
            {
                threadNum[inde].Join();
            }
            s.Stop();
            Console.WriteLine("add idValue cost time:{0}", s.ElapsedMilliseconds);
            ////////////////////////////////PHASE 2///////////////////////////////
            Console.WriteLine("add edges");
            Stopwatch ss = new Stopwatch();

            ss.Start();
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
            {
                EdgeCreationThreadObject p = new EdgeCreationThreadObject(threadCount, threadIndex);
                threadNum[threadIndex] = new Thread(CreateEdgeThreadProc);
                threadNum[threadIndex].Start(p);
            }
            for (int inde = 0; inde < threadCount; inde++)
            {
                threadNum[inde].Join();
            }
            ss.Stop();
            Console.WriteLine("add outlinks cost time:{0}", ss.ElapsedMilliseconds);

            ///////////////Remove dirty outlinks//////////////
            Stopwatch watch = new Stopwatch();

            watch.Start();
            for (int threadIndex = 0; threadIndex < threadCount; threadIndex++)
            {
                CellCleaningThreadObject p = new CellCleaningThreadObject(threadCount, threadIndex, nodeCount);
                threadNum[threadIndex] = new Thread(CellCleaningThreadProc);
                threadNum[threadIndex].Start(p);
            }
            for (int inde = 0; inde < threadCount; inde++)
            {
                threadNum[inde].Join();
            }
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
            TrinityConfig.DefragInterval = 100;
            ///////////////////////////////////////////////
            Stopwatch sss = new Stopwatch();

            sss.Start();
            Global.LocalStorage.SaveStorage();
            sss.Stop();
            Console.WriteLine("saveStorage cost time:{0}", sss.ElapsedMilliseconds);
            //foreach (var node in Global.LocalStorage.GraphNode_Selector())
            //{
            //    Console.WriteLine(node);
            //}
            //var results = from node in Global.LocalStorage.GraphNode_Accessor_Selector()
            //              select node;
            //Console.WriteLine(results.Distinct());
        }