示例#1
0
 public FAGraphVizPrinter(CGraph graph, UOPCore.Options <ThompsonOptions> options,
                          CGraphLabeling <CGraphNode> nodeLabeling = null,
                          CGraphLabeling <CGraphEdge> edgeLabeling = null) : base(graph, nodeLabeling, edgeLabeling)
 {
     m_FAInfo  = new FAGraphQueryInfo(graph, FA.m_FAINFOKEY);
     m_options = options;
 }
示例#2
0
        public void LoadGraph(CGraph graph)
        {
            CGraph oldGraph = ScriptGraph;

            ScriptGraph = graph;
            GraphName   = ScriptGraph.Name;

            Dictionary <CNode, CScriptNodeViewmodel> nodeToViewModel = new Dictionary <CNode, CScriptNodeViewmodel>();
            List <CScriptNodeViewmodel> newNodes = new List <CScriptNodeViewmodel>();

            foreach (CNode graphNode in ScriptGraph.m_nodes)
            {
                CScriptNodeViewmodel viewmodel = new CScriptNodeViewmodel(graphNode, this);
                nodeToViewModel.Add(graphNode, viewmodel);
                newNodes.Add(viewmodel);
            }

            m_selectedNodes.Clear();
            Nodes = new ObservableCollection <CScriptNodeViewmodel>(newNodes);
            Connections.Clear();

            ResolveScriptNodeConnections(ScriptGraph.m_nodes, nodeToViewModel);
            UndoRedoUtility.Purge(null);

            OnGraphChanged?.Invoke(this, oldGraph, ScriptGraph);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argumentType"></param>
        /// <param name="description"></param>
        /// <param name="localKey"></param>
        public Tuple <string, int, CGraph> AddInputArgument(string description, CGraph inputGraph, int globalkey = -1)
        {
            Tuple <string, int, CGraph> newarg = Tuple.Create(description, globalkey, inputGraph);

            m_inputArgumentsRecords.Add(newarg);
            return(newarg);
        }
示例#4
0
        public static void TestCaseBook()
        {
            // 1. Create a graph
            CGraph mgraph = CGraph.CreateGraph();

            CGraphNode u = mgraph.CreateGraphNode <CGraphNode>("u");
            CGraphNode v = mgraph.CreateGraphNode <CGraphNode>("v");
            CGraphNode w = mgraph.CreateGraphNode <CGraphNode>("w");
            CGraphNode x = mgraph.CreateGraphNode <CGraphNode>("x");
            CGraphNode y = mgraph.CreateGraphNode <CGraphNode>("y");
            CGraphNode z = mgraph.CreateGraphNode <CGraphNode>("z");

            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(u, v, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(u, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x, v, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(v, y, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(w, y, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(w, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, z, GraphType.GT_DIRECTED);

            DepthFirstSearch dfs = new DepthFirstSearch(mgraph);

            dfs.Run();

            DepthFirstSearchQueryInfo info = new DepthFirstSearchQueryInfo(mgraph, dfs);
            CIt_GraphNodes            it   = new CIt_GraphNodes(mgraph);

            for (it.Begin(); !it.End(); it.Next())
            {
                Console.WriteLine("Node {0}: arrival ({1}) - departure ({2})",
                                  it.M_CurrentItem.M_Label, info.Arrival(it.M_CurrentItem), info.Departure(it.M_CurrentItem));
            }
        }
示例#5
0
 public BellmanFord(CGraph graph, CGraphNode source, int graphWeightsKey)
 {
     mGraph                 = graph;
     m_source               = source;
     this[m_PATHINFO]       = m_outputShortestPathsInfo = new BellmanFordQueryInfo(graph, this);
     m_inputGraphWeightInfo = new CGraphQueryInfo <object, int, object>(graph, graphWeightsKey);
     m_outputShortestPathsInfo.CreateInfo(m_shortestPaths);
 }
        static public void Dijkstra()
        {
            CGraph cGraph;

            cGraph = new CGraph(input1);
            Console.WriteLine("-------------Input 1 -------------");
            cGraph.PrintGraph();
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argumentType"></param>
        /// <param name="description"></param>
        /// <param name="localKey"></param>
        public Tuple <string, int, CGraph> AddOutputArgument(string description, CGraph outputGraph, int globalkey = -1)
        {
            Tuple <string, int, CGraph> newarg = Tuple.Create(description,
                                                              outputGraph.GetStorageReservationKey(), outputGraph);

            m_outputArgumentsRecords.Add(newarg);
            return(newarg);
        }
 public BreadthFirstSearch(CGraphNode mSource, CGraph mGraph)
 {
     m_source        = mSource;
     m_graph         = mGraph;
     m_BFSData       = new BreadthFirstSearchQueryInfo(mGraph, this);
     m_Q             = new Queue <CGraphNode>();
     m_nodeVisitList = new List <CGraphNode>();
 }
示例#9
0
        public void CreateNewGraph()
        {
            Connections.Clear();
            Nodes.Clear();

            CGraph oldGraph = ScriptGraph;

            ScriptGraph = new CGraph();

            OnGraphChanged?.Invoke(this, oldGraph, ScriptGraph);
        }
 internal ThompsonGraphVizPrinter(CGraph graph, UOPCore.Options <ThompsonOptions> options,
                                  object thompsonkeyinfo,
                                  CGraphLabeling <CGraphNode> nodeLabeling = null,
                                  CGraphLabeling <CGraphEdge> edgeLabeling = null
                                  ) : base(graph, nodeLabeling, edgeLabeling)
 {
     m_options         = options;
     m_thompsonKeyInfo = thompsonkeyinfo;
     m_thompsonInfo    = new ThompsonInfo(graph, m_thompsonKeyInfo);
     m_FAInfo          = new FAGraphQueryInfo(graph, FA.m_FAINFOKEY);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="graph">The given graph</param>
 /// <param name="freeze">This parameter determines if the iteration will happen on the given graph or a clone of it. In case the graph is changing during the iteration and the objective is to iterate on the initial graph then set freeze to true</param>
 public CIt_GraphNodes(CGraph graph, bool freeze = false)
 {
     if (!freeze)
     {
         m_graph = graph;
     }
     else
     {
         // Iteration happens on the clone which can't be changed externally
         m_graph = CGraph.TemporalClone(graph);
         // The graph that is given from externally and can be change
         // during iteration
         m_initialGraph = graph;
     }
 }
示例#12
0
        public static void TestCaseBook()
        {
            // 1. Create a graph
            CGraph mgraph = CGraph.CreateGraph();

            CGraphNode r = mgraph.CreateGraphNode <CGraphNode>("r");
            CGraphNode s = mgraph.CreateGraphNode <CGraphNode>("s");
            CGraphNode t = mgraph.CreateGraphNode <CGraphNode>("t");
            CGraphNode u = mgraph.CreateGraphNode <CGraphNode>("u");
            CGraphNode v = mgraph.CreateGraphNode <CGraphNode>("v");
            CGraphNode w = mgraph.CreateGraphNode <CGraphNode>("w");
            CGraphNode x = mgraph.CreateGraphNode <CGraphNode>("x");
            CGraphNode y = mgraph.CreateGraphNode <CGraphNode>("y");

            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(r, s, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(r, v, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, w, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(w, t, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(w, x, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, x, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, u, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x, u, GraphType.GT_UNDIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x, y, GraphType.GT_UNDIRECTED);

            // 2. Create Algorithm
            BreadthFirstSearch bfs = new BreadthFirstSearch(s, mgraph);

            // 2. Associate weights with the edges of the graph
            CGraphQueryInfo <int, int, int> bfsData = new CGraphQueryInfo <int, int, int>(mgraph, bfs);

            bfs.Run();

            Console.WriteLine("Printing BFS Results with Source Node : {0}", s.M_Label);
            foreach (CGraphNode node in bfs.BFSNodes())
            {
                Console.WriteLine("Node {0} distance: {1}", node.M_Label, bfs.Distance(node));
            }

            // Testing BreadthFirstSearchQueryInfo
            BreadthFirstSearchQueryInfo bfsInfo = new BreadthFirstSearchQueryInfo(mgraph, bfs);

            Console.WriteLine("Printing BFS Results with Source Node : {0}", s.M_Label);
            foreach (CGraphNode node in bfsInfo.BFSNodes())
            {
                Console.WriteLine("Node {0} distance: {1}", node.M_Label, bfs.Distance(node));
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            CTranslationUnit tr = new CTranslationUnit();

            CGraph graph = CGraph.CreateGraph();

            tr.dipole()
            .algorithm()
            .algorithm()
            .connections()
            .connection()
            .GRAPH(graph)
            .GRAPHELEMENTTYPE(GraphElementType.ET_NODE)
            .KEY(graph.GetHashCode())
            .INFOTYPE(typeof(int))
            .end()
            .end();
        }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractGraphQueryInfo"/> class.
 /// </summary>
 /// <param name="graph">The graph.</param>
 public CGraphQueryInfo(CGraph graph, object key)
 {
     m_graph   = graph;
     m_infoKey = key;
 }
 public DepthFirstSearch(CGraph mGraph)
 {
     m_graph = mGraph;
     m_outputDepthFirstSearch = new DepthFirstSearchQueryInfo(mGraph, this);
 }
示例#16
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length > 0)
                {
                    deviceID = int.Parse(args[0]);
                }
                if (args.Length > 2)
                {
                    platformID = int.Parse(args[2]);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, "Device ID parse error", ex);
            }

            try
            {
                if (args.Length > 1)
                {
                    port = int.Parse(args[1]);
                    Comms.ConnectToMaster(port);
                }
                else
                {
                    TEST = true;
                    CGraph.ShowCycles    = true;
                    Logger.CopyToConsole = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, "Master connection error");
            }


            // Gets all available platforms and their corresponding devices, and prints them out in a table
            List <Platform> platforms = null;

            try
            {
                platforms = Platform.GetPlatforms().ToList();
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, "Failed to get OpenCL platform list");
                return;
            }

            if (TEST)
            {
                currentJob = nextJob = new Job()
                {
                    jobID = 0,
                    k0    = 0xf4956dc403730b01L,
                    k1    = 0xe6d45de39c2a5a3eL,
                    k2    = 0xcbf626a8afee35f6L,
                    k3    = 0x4307b94b1a0c9980L,
                    //k0 = 0x10ef16eadd6aa061L,
                    //k1 = 0x563f07e7a3c788b3L,
                    //k2 = 0xe8d7c8db1518f29aL,
                    //k3 = 0xc0ab7d1b4ca1adffL,
                    pre_pow   = TestPrePow,
                    timestamp = DateTime.Now
                };
            }
            else
            {
                currentJob = nextJob = new Job()
                {
                    jobID     = 0,
                    k0        = 0xf4956dc403730b01L,
                    k1        = 0xe6d45de39c2a5a3eL,
                    k2        = 0xcbf626a8afee35f6L,
                    k3        = 0x4307b94b1a0c9980L,
                    pre_pow   = TestPrePow,
                    timestamp = DateTime.Now
                };

                if (!Comms.IsConnected())
                {
                    Console.WriteLine("Master connection failed, aborting");
                    Logger.Log(LogLevel.Error, "No master connection, exitting!");
                    Task.Delay(500).Wait();
                    return;
                }

                if (deviceID < 0)
                {
                    try
                    {
                        //Environment.SetEnvironmentVariable("GPU_FORCE_64BIT_PTR", "1", EnvironmentVariableTarget.Machine);
                        Environment.SetEnvironmentVariable("GPU_MAX_HEAP_SIZE", "100", EnvironmentVariableTarget.User);
                        Environment.SetEnvironmentVariable("GPU_USE_SYNC_OBJECTS", "1", EnvironmentVariableTarget.User);
                        Environment.SetEnvironmentVariable("GPU_MAX_ALLOC_PERCENT", "100", EnvironmentVariableTarget.User);
                        Environment.SetEnvironmentVariable("GPU_SINGLE_ALLOC_PERCENT", "100", EnvironmentVariableTarget.User);
                        Environment.SetEnvironmentVariable("GPU_64BIT_ATOMICS", "1", EnvironmentVariableTarget.User);
                        Environment.SetEnvironmentVariable("GPU_MAX_WORKGROUP_SIZE", "1024", EnvironmentVariableTarget.User);
                        //Environment.SetEnvironmentVariable("AMD_OCL_BUILD_OPTIONS_APPEND", "-cl-std=CL2.0", EnvironmentVariableTarget.Machine);

                        GpuDevicesMessage gpum = new GpuDevicesMessage()
                        {
                            devices = new List <GpuDevice>()
                        };
                        //foreach (Platform platform in platforms)
                        for (int p = 0; p < platforms.Count(); p++)
                        {
                            Platform platform = platforms[p];
                            var      devices  = platform.GetDevices(DeviceType.Gpu).ToList();
                            //foreach (Device device in platform.GetDevices(DeviceType.All))
                            for (int d = 0; d < devices.Count(); d++)
                            {
                                Device device = devices[d];
                                string name   = device.Name;
                                string pName  = platform.Name;
                                //Console.WriteLine(device.Name + " " + platform.Version.VersionString);
                                gpum.devices.Add(new GpuDevice()
                                {
                                    deviceID = d, platformID = p, platformName = pName, name = name, memory = device.GlobalMemorySize
                                });
                            }
                        }
                        Comms.gpuMsg = gpum;
                        Comms.SetEvent();
                        Task.Delay(1000).Wait();
                        Comms.Close();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogLevel.Error, "Unable to enumerate OpenCL devices");
                        Task.Delay(500).Wait();
                        Comms.Close();
                        return;
                    }
                }
            }

            try
            {
                Device chosenDevice = null;
                try
                {
                    chosenDevice = platforms[platformID].GetDevices(DeviceType.Gpu).ToList()[deviceID];
                    Console.WriteLine($"Using OpenCL device: {chosenDevice.Name} ({chosenDevice.Vendor})");
                    Console.WriteLine();
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.Error, $"Unable to select OpenCL device {deviceID} on platform {platformID} ");
                    Task.Delay(500).Wait();
                    Comms.Close();
                    return;
                }

                var assembly       = Assembly.GetEntryAssembly();
                var resourceStream = assembly.GetManifestResourceStream("OclSolver.kernel.cl");
                using (StreamReader reader = new StreamReader(resourceStream))
                {
                    using (Context context = Context.CreateContext(chosenDevice))
                    {
                        /*
                         * Once the program has been created you can use clGetProgramInfo with CL_PROGRAM_BINARY_SIZES and then CL_PROGRAM_BINARIES, storing the resulting binary programs (one for each device of the context) into a buffer you supply. You can then save this binary data to disk for use in later runs.
                         * Not all devices might support binaries, so you will need to check the CL_PROGRAM_BINARY_SIZES result (it returns a zero size for that device if binaries are not supported).
                         */
                        using (OpenCl.DotNetCore.Programs.Program program = context.CreateAndBuildProgramFromString(reader.ReadToEnd()))
                        {
                            using (CommandQueue commandQueue = CommandQueue.CreateCommandQueue(context, chosenDevice))
                            {
                                IntPtr clearPattern = IntPtr.Zero;
                                uint[] edgesCount;
                                int[]  edgesLeft;
                                int    trims = 0;
                                try
                                {
                                    clearPattern = Marshal.AllocHGlobal(4);
                                    Marshal.Copy(new byte[4] {
                                        0, 0, 0, 0
                                    }, 0, clearPattern, 4);

                                    try
                                    {
                                        bufferA1 = context.CreateBuffer <uint>(MemoryFlag.ReadWrite, BUFFER_SIZE_A1);
                                        bufferA2 = context.CreateBuffer <uint>(MemoryFlag.ReadWrite, BUFFER_SIZE_A2);
                                        bufferB  = context.CreateBuffer <uint>(MemoryFlag.ReadWrite, BUFFER_SIZE_B);

                                        bufferI1 = context.CreateBuffer <uint>(MemoryFlag.ReadWrite, INDEX_SIZE);
                                        bufferI2 = context.CreateBuffer <uint>(MemoryFlag.ReadWrite, INDEX_SIZE);

                                        bufferR = context.CreateBuffer <uint>(MemoryFlag.ReadOnly, 42 * 2);
                                    }
                                    catch (Exception ex)
                                    {
                                        Task.Delay(500).Wait();
                                        Logger.Log(LogLevel.Error, "Unable to allocate buffers, out of memory?");
                                        Task.Delay(500).Wait();
                                        Comms.Close();
                                        return;
                                    }

                                    using (Kernel kernelSeedA = program.CreateKernel("FluffySeed2A"))
                                        using (Kernel kernelSeedB1 = program.CreateKernel("FluffySeed2B"))
                                            using (Kernel kernelSeedB2 = program.CreateKernel("FluffySeed2B"))
                                                using (Kernel kernelRound1 = program.CreateKernel("FluffyRound1"))
                                                    using (Kernel kernelRoundO = program.CreateKernel("FluffyRoundNO1"))
                                                        using (Kernel kernelRoundNA = program.CreateKernel("FluffyRoundNON"))
                                                            using (Kernel kernelRoundNB = program.CreateKernel("FluffyRoundNON"))
                                                                using (Kernel kernelTail = program.CreateKernel("FluffyTailO"))
                                                                    using (Kernel kernelRecovery = program.CreateKernel("FluffyRecovery"))
                                                                    {
                                                                        Stopwatch sw = new Stopwatch();

                                                                        kernelSeedA.SetKernelArgumentGeneric(0, currentJob.k0);
                                                                        kernelSeedA.SetKernelArgumentGeneric(1, currentJob.k1);
                                                                        kernelSeedA.SetKernelArgumentGeneric(2, currentJob.k2);
                                                                        kernelSeedA.SetKernelArgumentGeneric(3, currentJob.k3);
                                                                        kernelSeedA.SetKernelArgument(4, bufferB);
                                                                        kernelSeedA.SetKernelArgument(5, bufferA1);
                                                                        kernelSeedA.SetKernelArgument(6, bufferI1);

                                                                        kernelSeedB1.SetKernelArgument(0, bufferA1);
                                                                        kernelSeedB1.SetKernelArgument(1, bufferA1);
                                                                        kernelSeedB1.SetKernelArgument(2, bufferA2);
                                                                        kernelSeedB1.SetKernelArgument(3, bufferI1);
                                                                        kernelSeedB1.SetKernelArgument(4, bufferI2);
                                                                        kernelSeedB1.SetKernelArgumentGeneric(5, (uint)32);

                                                                        kernelSeedB2.SetKernelArgument(0, bufferB);
                                                                        kernelSeedB2.SetKernelArgument(1, bufferA1);
                                                                        kernelSeedB2.SetKernelArgument(2, bufferA2);
                                                                        kernelSeedB2.SetKernelArgument(3, bufferI1);
                                                                        kernelSeedB2.SetKernelArgument(4, bufferI2);
                                                                        kernelSeedB2.SetKernelArgumentGeneric(5, (uint)0);

                                                                        kernelRound1.SetKernelArgument(0, bufferA1);
                                                                        kernelRound1.SetKernelArgument(1, bufferA2);
                                                                        kernelRound1.SetKernelArgument(2, bufferB);
                                                                        kernelRound1.SetKernelArgument(3, bufferI2);
                                                                        kernelRound1.SetKernelArgument(4, bufferI1);
                                                                        kernelRound1.SetKernelArgumentGeneric(5, (uint)DUCK_SIZE_A * 1024);
                                                                        kernelRound1.SetKernelArgumentGeneric(6, (uint)DUCK_SIZE_B * 1024);

                                                                        kernelRoundO.SetKernelArgument(0, bufferB);
                                                                        kernelRoundO.SetKernelArgument(1, bufferA1);
                                                                        kernelRoundO.SetKernelArgument(2, bufferI1);
                                                                        kernelRoundO.SetKernelArgument(3, bufferI2);

                                                                        kernelRoundNA.SetKernelArgument(0, bufferB);
                                                                        kernelRoundNA.SetKernelArgument(1, bufferA1);
                                                                        kernelRoundNA.SetKernelArgument(2, bufferI1);
                                                                        kernelRoundNA.SetKernelArgument(3, bufferI2);

                                                                        kernelRoundNB.SetKernelArgument(0, bufferA1);
                                                                        kernelRoundNB.SetKernelArgument(1, bufferB);
                                                                        kernelRoundNB.SetKernelArgument(2, bufferI2);
                                                                        kernelRoundNB.SetKernelArgument(3, bufferI1);

                                                                        kernelTail.SetKernelArgument(0, bufferB);
                                                                        kernelTail.SetKernelArgument(1, bufferA1);
                                                                        kernelTail.SetKernelArgument(2, bufferI1);
                                                                        kernelTail.SetKernelArgument(3, bufferI2);

                                                                        kernelRecovery.SetKernelArgumentGeneric(0, currentJob.k0);
                                                                        kernelRecovery.SetKernelArgumentGeneric(1, currentJob.k1);
                                                                        kernelRecovery.SetKernelArgumentGeneric(2, currentJob.k2);
                                                                        kernelRecovery.SetKernelArgumentGeneric(3, currentJob.k3);
                                                                        kernelRecovery.SetKernelArgument(4, bufferR);
                                                                        kernelRecovery.SetKernelArgument(5, bufferI2);

                                                                        int loopCnt = 0;
                                                                        //for (int i = 0; i < runs; i++)
                                                                        while (!Comms.IsTerminated)
                                                                        {
                                                                            try
                                                                            {
                                                                                if (!TEST && (Comms.nextJob.pre_pow == null || Comms.nextJob.pre_pow == "" || Comms.nextJob.pre_pow == TestPrePow))
                                                                                {
                                                                                    Logger.Log(LogLevel.Info, string.Format("Waiting for job...."));
                                                                                    Task.Delay(1000).Wait();
                                                                                    continue;
                                                                                }

                                                                                if (!TEST && ((currentJob.pre_pow != Comms.nextJob.pre_pow) || (currentJob.origin != Comms.nextJob.origin)))
                                                                                {
                                                                                    currentJob           = Comms.nextJob;
                                                                                    currentJob.timestamp = DateTime.Now;
                                                                                }

                                                                                if (!TEST && (currentJob.timestamp.AddMinutes(30) < DateTime.Now) && Comms.lastIncoming.AddMinutes(30) < DateTime.Now)
                                                                                {
                                                                                    Logger.Log(LogLevel.Info, string.Format("Job too old..."));
                                                                                    Task.Delay(1000).Wait();
                                                                                    continue;
                                                                                }

                                                                                // test runs only once
                                                                                if (TEST && loopCnt++ > 100000)
                                                                                {
                                                                                    Comms.IsTerminated = true;
                                                                                }

                                                                                Logger.Log(LogLevel.Debug, string.Format("GPU AMD{4}:Trimming #{4}: {0} {1} {2} {3}", currentJob.k0, currentJob.k1, currentJob.k2, currentJob.k3, currentJob.jobID, deviceID));

                                                                                //Stopwatch srw = new Stopwatch();
                                                                                //srw.Start();

                                                                                Solution s;
                                                                                while (graphSolutions.TryDequeue(out s))
                                                                                {
                                                                                    kernelRecovery.SetKernelArgumentGeneric(0, s.job.k0);
                                                                                    kernelRecovery.SetKernelArgumentGeneric(1, s.job.k1);
                                                                                    kernelRecovery.SetKernelArgumentGeneric(2, s.job.k2);
                                                                                    kernelRecovery.SetKernelArgumentGeneric(3, s.job.k3);
                                                                                    commandQueue.EnqueueWriteBufferEdges(bufferR, s.GetLongEdges());
                                                                                    commandQueue.EnqueueClearBuffer(bufferI2, 64 * 64 * 4, clearPattern);
                                                                                    commandQueue.EnqueueNDRangeKernel(kernelRecovery, 1, 2048 * 256, 256, 0);
                                                                                    s.nonces = commandQueue.EnqueueReadBuffer <uint>(bufferI2, 42);
                                                                                    OpenCl.DotNetCore.Interop.CommandQueues.CommandQueuesNativeApi.Finish(commandQueue.Handle);
                                                                                    s.nonces = s.nonces.OrderBy(n => n).ToArray();
                                                                                    Comms.graphSolutionsOut.Enqueue(s);
                                                                                    Comms.SetEvent();
                                                                                }

                                                                                //srw.Stop();
                                                                                //Console.WriteLine("RECOVERY " + srw.ElapsedMilliseconds);

                                                                                currentJob = currentJob.Next();

                                                                                kernelSeedA.SetKernelArgumentGeneric(0, currentJob.k0);
                                                                                kernelSeedA.SetKernelArgumentGeneric(1, currentJob.k1);
                                                                                kernelSeedA.SetKernelArgumentGeneric(2, currentJob.k2);
                                                                                kernelSeedA.SetKernelArgumentGeneric(3, currentJob.k3);

                                                                                sw.Restart();

                                                                                commandQueue.EnqueueClearBuffer(bufferI2, 64 * 64 * 4, clearPattern);
                                                                                commandQueue.EnqueueClearBuffer(bufferI1, 64 * 64 * 4, clearPattern);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelSeedA, 1, 2048 * 128, 128, 0);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelSeedB1, 1, 1024 * 128, 128, 0);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelSeedB2, 1, 1024 * 128, 128, 0);
                                                                                commandQueue.EnqueueClearBuffer(bufferI1, 64 * 64 * 4, clearPattern);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelRound1, 1, 4096 * 1024, 1024, 0);

                                                                                commandQueue.EnqueueClearBuffer(bufferI2, 64 * 64 * 4, clearPattern);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelRoundO, 1, 4096 * 1024, 1024, 0);
                                                                                commandQueue.EnqueueClearBuffer(bufferI1, 64 * 64 * 4, clearPattern);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelRoundNB, 1, 4096 * 1024, 1024, 0);

                                                                                for (int r = 0; r < trimRounds; r++)
                                                                                {
                                                                                    commandQueue.EnqueueClearBuffer(bufferI2, 64 * 64 * 4, clearPattern);
                                                                                    commandQueue.EnqueueNDRangeKernel(kernelRoundNA, 1, 4096 * 1024, 1024, 0);
                                                                                    commandQueue.EnqueueClearBuffer(bufferI1, 64 * 64 * 4, clearPattern);
                                                                                    commandQueue.EnqueueNDRangeKernel(kernelRoundNB, 1, 4096 * 1024, 1024, 0);
                                                                                }

                                                                                commandQueue.EnqueueClearBuffer(bufferI2, 64 * 64 * 4, clearPattern);
                                                                                commandQueue.EnqueueNDRangeKernel(kernelTail, 1, 4096 * 1024, 1024, 0);

                                                                                edgesCount    = commandQueue.EnqueueReadBuffer <uint>(bufferI2, 1);
                                                                                edgesCount[0] = edgesCount[0] > 1000000 ? 1000000 : edgesCount[0];
                                                                                edgesLeft     = commandQueue.EnqueueReadBuffer(bufferA1, (int)edgesCount[0] * 2);

                                                                                OpenCl.DotNetCore.Interop.CommandQueues.CommandQueuesNativeApi.Flush(commandQueue.Handle);
                                                                                OpenCl.DotNetCore.Interop.CommandQueues.CommandQueuesNativeApi.Finish(commandQueue.Handle);

                                                                                sw.Stop();

                                                                                currentJob.trimTime = sw.ElapsedMilliseconds;
                                                                                currentJob.solvedAt = DateTime.Now;

                                                                                Logger.Log(LogLevel.Info, string.Format("GPU AMD{2}:    Trimmed in {0}ms to {1} edges", sw.ElapsedMilliseconds, edgesCount[0], deviceID));

                                                                                CGraph cg = new CGraph();
                                                                                cg.SetEdges(edgesLeft, (int)edgesCount[0]);
                                                                                cg.SetHeader(currentJob);

                                                                                Task.Factory.StartNew(() =>
                                                                                {
                                                                                    if (edgesCount[0] < 200000)
                                                                                    {
                                                                                        try
                                                                                        {
                                                                                            if (findersInFlight++ < 3)
                                                                                            {
                                                                                                Stopwatch cycleTime = new Stopwatch();
                                                                                                cycleTime.Start();
                                                                                                cg.FindSolutions(graphSolutions);
                                                                                                cycleTime.Stop();
                                                                                                AdjustTrims(cycleTime.ElapsedMilliseconds);
                                                                                                if (TEST)
                                                                                                {
                                                                                                    Logger.Log(LogLevel.Info, string.Format("Finder completed in {0}ms on {1} edges with {2} solution(s) and {3} dupes", sw.ElapsedMilliseconds, edgesCount[0], graphSolutions.Count, cg.dupes));

                                                                                                    if (++trims % 50 == 0)
                                                                                                    {
                                                                                                        Console.ForegroundColor = ConsoleColor.Green;
                                                                                                        Console.WriteLine("SOLS: {0}/{1} - RATE: {2:F1}", solutions, trims, (float)trims / solutions);
                                                                                                        Console.ResetColor();
                                                                                                    }
                                                                                                }
                                                                                                if (graphSolutions.Count > 0)
                                                                                                {
                                                                                                    solutions++;
                                                                                                }
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                Logger.Log(LogLevel.Warning, "CPU overloaded!");
                                                                                            }
                                                                                        }
                                                                                        catch (Exception ex)
                                                                                        {
                                                                                            Logger.Log(LogLevel.Error, "Cycle finder crashed " + ex.Message);
                                                                                        }
                                                                                        finally
                                                                                        {
                                                                                            findersInFlight--;
                                                                                        }
                                                                                    }
                                                                                });
                                                                            }
                                                                            catch (Exception ex)
                                                                            {
                                                                                Logger.Log(LogLevel.Error, "Critical error in main ocl loop " + ex.Message);
                                                                                Task.Delay(5000).Wait();
                                                                            }
                                                                        }

                                                                        //uint[] resultArray = commandQueue.EnqueueReadBuffer<uint>(bufferI1, 64 * 64);
                                                                        //uint[] resultArray2 = commandQueue.EnqueueReadBuffer<uint>(bufferI2, 64 * 64);
                                                                        //Console.WriteLine("SeedA: " + resultArray.Sum(e => e) + " in " + sw.ElapsedMilliseconds / runs);
                                                                        //Console.WriteLine("SeedB: " + resultArray2.Sum(e => e) + " in " + sw.ElapsedMilliseconds / runs);
                                                                        //Task.Delay(1000).Wait();
                                                                        //Console.WriteLine("");
                                                                    }
                                }
                                finally
                                {
                                    // clear pattern
                                    if (clearPattern != IntPtr.Zero)
                                    {
                                        Marshal.FreeHGlobal(clearPattern);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, "Critical error in OCL Init " + ex.Message);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
                Task.Delay(500).Wait();
            }
            finally
            {
                Task.Delay(500).Wait();

                try
                {
                    Comms.Close();
                    bufferA1.Dispose();
                    bufferA2.Dispose();
                    bufferB.Dispose();
                    bufferI1.Dispose();
                    bufferI2.Dispose();
                    bufferR.Dispose();

                    if (OpenCl.DotNetCore.CommandQueues.CommandQueue.resultValuePointer != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(OpenCl.DotNetCore.CommandQueues.CommandQueue.resultValuePointer);
                    }
                }
                catch { }
            }

            //Console.ReadKey();
        }
 public CGraphVizPrinter(CGraph graph, CGraphLabeling <CGraphNode> nodeLabeling = null,
                         CGraphLabeling <CGraphEdge> edgeLabeling = null) : base(graph, nodeLabeling, edgeLabeling)
 {
 }
示例#18
0
        public static void TestCase3x3()
        {
            // 1. Create a graph
            CGraph mgraph = CGraph.CreateGraph();

            CGraphNode x1 = mgraph.CreateGraphNode <CGraphNode>("1");
            CGraphNode x2 = mgraph.CreateGraphNode <CGraphNode>("2");
            CGraphNode x3 = mgraph.CreateGraphNode <CGraphNode>("3");
            CGraphNode x4 = mgraph.CreateGraphNode <CGraphNode>("4");
            CGraphNode x5 = mgraph.CreateGraphNode <CGraphNode>("5");
            CGraphNode x6 = mgraph.CreateGraphNode <CGraphNode>("6");
            CGraphNode x7 = mgraph.CreateGraphNode <CGraphNode>("7");
            CGraphNode x8 = mgraph.CreateGraphNode <CGraphNode>("8");
            CGraphNode x9 = mgraph.CreateGraphNode <CGraphNode>("9");

            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x1, x2, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x2, x1, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x1, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x1, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x1, x4, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x4, x1, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x2, x4, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x4, x2, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x2, x3, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x3, x2, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x2, x6, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x6, x2, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x2, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x2, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x3, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x3, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x3, x6, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x6, x3, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x4, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x4, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x4, x7, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x7, x4, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x4, x8, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x8, x4, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x6, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x6, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x7, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x7, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x8, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x8, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x5, x9, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x9, x5, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x6, x8, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x8, x6, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x6, x9, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x9, x6, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x7, x8, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x8, x7, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x8, x9, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x9, x8, GraphType.GT_DIRECTED);


            // 2. Associate weights with the edges of the graph
            CGraphQueryInfo <int, int, int> weights = new CGraphQueryInfo <int, int, int>(mgraph, 255);

            weights.CreateInfo(x1, x2, 1);
            weights.CreateInfo(x2, x1, 1);
            weights.CreateInfo(x1, x5, 1);
            weights.CreateInfo(x5, x1, 1);
            weights.CreateInfo(x1, x4, 1);
            weights.CreateInfo(x4, x1, 1);
            weights.CreateInfo(x2, x4, 3);
            weights.CreateInfo(x4, x2, 3);
            weights.CreateInfo(x2, x3, 1);
            weights.CreateInfo(x3, x2, 1);
            weights.CreateInfo(x2, x6, 3);
            weights.CreateInfo(x6, x2, 3);
            weights.CreateInfo(x2, x5, 1);
            weights.CreateInfo(x5, x2, 1);
            weights.CreateInfo(x3, x5, 3);
            weights.CreateInfo(x5, x3, 3);
            weights.CreateInfo(x3, x6, 1);
            weights.CreateInfo(x6, x3, 1);
            weights.CreateInfo(x4, x5, 1);
            weights.CreateInfo(x5, x4, 1);
            weights.CreateInfo(x4, x7, 1);
            weights.CreateInfo(x7, x4, 1);
            weights.CreateInfo(x4, x8, 3);
            weights.CreateInfo(x8, x4, 3);
            weights.CreateInfo(x5, x6, 1);
            weights.CreateInfo(x6, x5, 1);
            weights.CreateInfo(x5, x7, 3);
            weights.CreateInfo(x7, x5, 3);
            weights.CreateInfo(x5, x8, 1);
            weights.CreateInfo(x8, x5, 1);
            weights.CreateInfo(x5, x9, 3);
            weights.CreateInfo(x9, x5, 3);
            weights.CreateInfo(x6, x8, 3);
            weights.CreateInfo(x8, x6, 3);
            weights.CreateInfo(x6, x9, 1);
            weights.CreateInfo(x9, x6, 1);
            weights.CreateInfo(x7, x8, 1);
            weights.CreateInfo(x8, x7, 1);
            weights.CreateInfo(x8, x9, 1);
            weights.CreateInfo(x9, x8, 1);

            // 3. Run the BellmanFord algorithm
            BellmanFord bl = new BellmanFord(mgraph, x1, 255);

            bl.FindAllPairsShortestPaths();

            // 4. Print Paths
            BellmanFordQueryInfo shortestPath = new BellmanFordQueryInfo(mgraph, bl);
            CIt_GraphNodes       i            = new CIt_GraphNodes(mgraph);
            CIt_GraphNodes       j            = new CIt_GraphNodes(mgraph);
            Dictionary <CGraphNode, Dictionary <CGraphNode, Path> > paths =
                shortestPath.ShortestPaths();

            for (i.Begin(); !i.End(); i.Next())
            {
                Console.WriteLine();
                for (j.Begin(); !j.End(); j.Next())
                {
                    Console.WriteLine();
                    if (i.M_CurrentItem != j.M_CurrentItem)
                    {
                        Console.Write(paths[i.M_CurrentItem][j.M_CurrentItem]);
                    }
                }
            }
        }
示例#19
0
        public static void BookExampleTestcase()
        {
            // 1. Create a graph
            CGraph mgraph = CGraph.CreateGraph();

            CGraphNode x = mgraph.CreateGraphNode <CGraphNode>("x");
            CGraphNode y = mgraph.CreateGraphNode <CGraphNode>("y");
            CGraphNode z = mgraph.CreateGraphNode <CGraphNode>("z");
            CGraphNode t = mgraph.CreateGraphNode <CGraphNode>("t");
            CGraphNode s = mgraph.CreateGraphNode <CGraphNode>("s");

            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, y, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x, t, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, s, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, t, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, y, GraphType.GT_DIRECTED);

            // 2. Associate weights with the edges of the graph
            CGraphQueryInfo <int, int, int> weights = new CGraphQueryInfo <int, int, int>(mgraph, 255);

            weights.CreateInfo(y, x, -3);
            weights.CreateInfo(x, t, -2);
            weights.CreateInfo(t, x, 5);
            weights.CreateInfo(z, x, 7);
            weights.CreateInfo(y, z, 9);
            weights.CreateInfo(t, y, 8);
            weights.CreateInfo(t, z, -4);
            weights.CreateInfo(s, t, 6);
            weights.CreateInfo(s, y, 7);
            weights.CreateInfo(z, s, 2);

            // 3. Run the BellmanFord algorithm
            BellmanFord bl = new BellmanFord(mgraph, s, 255);

            bl.FindAllPairsShortestPaths();

            // 4. Print Paths
            CGraphQueryInfo <int, int, Dictionary <CGraphNode, Dictionary <CGraphNode, Path> > > shortestPath = new CGraphQueryInfo <int, int, Dictionary <CGraphNode, Dictionary <CGraphNode, Path> > >(mgraph, bl);
            CIt_GraphNodes i = new CIt_GraphNodes(mgraph);
            CIt_GraphNodes j = new CIt_GraphNodes(mgraph);
            Dictionary <CGraphNode, Dictionary <CGraphNode, Path> > paths =
                (Dictionary <CGraphNode, Dictionary <CGraphNode, Path> >)(shortestPath.Info());

            for (i.Begin(); !i.End(); i.Next())
            {
                Console.WriteLine();
                for (j.Begin(); !j.End(); j.Next())
                {
                    Console.WriteLine();
                    if (i.M_CurrentItem != j.M_CurrentItem)
                    {
                        Console.Write(paths[i.M_CurrentItem][j.M_CurrentItem]);
                    }
                }
            }
        }
示例#20
0
        static void Main(string[] args)
        {
            // 1. Create a graph
            CGraph mgraph = CGraph.CreateGraph();

            CGraphNode x = mgraph.CreateGraphNode <CGraphNode>("x");
            CGraphNode y = mgraph.CreateGraphNode <CGraphNode>("y");
            CGraphNode z = mgraph.CreateGraphNode <CGraphNode>("z");
            CGraphNode t = mgraph.CreateGraphNode <CGraphNode>("t");
            CGraphNode s = mgraph.CreateGraphNode <CGraphNode>("s");

            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, y, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x, t, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, s, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, t, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, y, GraphType.GT_DIRECTED);

            // 2. Associate weights with the edges of the graph
            CGraphQueryInfo <int, int, int> weights = new CGraphQueryInfo <int, int, int>(mgraph, 255);

            weights.CreateInfo(y, x, -3);
            weights.CreateInfo(x, t, -2);
            weights.CreateInfo(t, x, 5);
            weights.CreateInfo(z, x, 7);
            weights.CreateInfo(y, z, 9);
            weights.CreateInfo(t, y, 8);
            weights.CreateInfo(t, z, -4);
            weights.CreateInfo(s, t, 6);
            weights.CreateInfo(s, y, 7);
            weights.CreateInfo(z, s, 2);

            mgraph.RegisterGraphPrinter(new CGraphVizPrinter(mgraph));
            // The graph uses the registered printers to print the graph to the specified output
            mgraph.Generate(@"D:\MyPrivateWork\MyApps\MyApplications\EDUFLEX\GraphLibrary\TestSerialization\bin\Debug\test.dot", true);

            BinaryFormatter saver    = new BinaryFormatter();
            XmlSerializer   xmlsaver = new XmlSerializer(typeof(CGraph));

            using (Stream stream = new FileStream("graph.g", FileMode.Create, FileAccess.Write)) {
                saver.Serialize(stream, mgraph);
            }

            CGraph deserializedGraph;

            using (Stream stream = new FileStream("graph.g", FileMode.Open, FileAccess.Read)) {
                deserializedGraph = (CGraph)saver.Deserialize(stream);
            }

            deserializedGraph.RegisterGraphPrinter(new CGraphVizPrinter(mgraph));
            // The graph uses the registered printers to print the graph to the specified output
            deserializedGraph.Generate(@"D:\MyPrivateWork\MyApps\MyApplications\EDUFLEX\GraphLibrary\TestSerialization\bin\Debug\regentest.dot", true);

            using (Stream stream = new FileStream("graph.xml", FileMode.Create, FileAccess.Write)) {
                xmlsaver.Serialize(stream, mgraph);
            }
        }
 protected CGraphPrimitive(GraphElementType etype, CGraph owner = null)
 {
     m_algorithmOutput = new Dictionary <object, object>();
     M_ElementType     = etype;
     m_graph           = owner;
 }
示例#22
0
 public CConnection GRAPH(CGraph g)
 {
     m_graph = g;
     return(this);
 }
示例#23
0
        // CONTEXT

        public GAlg_CondensedGraphBuilder(AlgorithmDataRecord input) : base(input)
        {
            m_sourceGraph           = input.GetIArgumentOriginGraph();
            m_condensedNodeContents = m_sourceGraph[input.GetIArgumentGlobalKey()];
        }
 public CGraphLabeling(CGraph graph)
 {
     m_graph = graph;
 }
示例#25
0
 public CAlgIO GRAPH(CGraph graph)
 {
     m_graph = graph;
     return(this);
 }
 /// <summary>
 /// Labels
 /// </summary>
 /// <param name="prefix">The label prefix</param>
 /// <param name="graph">The condensed graph</param>
 public CCondensedGraphVizLabelling(string prefix, CGraph graph) : base(graph)
 {
     m_prefix = prefix;
     LabelElements();
 }
 public DepthFirstSearchQueryInfo(CGraph graph, object key) : base(graph, key)
 {
 }
示例#28
0
 internal DFASerializer(CGraph graph, AbstractGraphLabeling <CGraphNode> nodeLabeller = null, AbstractGraphLabeling <CGraphEdge> edgeLabeller = null) : base(graph, nodeLabeller, edgeLabeller)
 {
 }
示例#29
0
        static void Main(string[] args)
        {
            CGraph graph1    = CGraph.CreateGraph();
            CGraph graph2    = CGraph.CreateGraph();
            CGraph rootGraph = CGraph.CreateGraph();

            // CREATE A GRAPH FROM A CSV FILE
            // We call the CreateGraphFromCSV where the edges are given as comma separated
            // tuples in curly brackets. Sole nodes can be given inside curle brackets. This
            // method assigns node labels as given in the file using the native graph labeller
            CGraph graph3 = CGraph.CreateGraphFromCSV("csvGraph.txt");

            CGraph.CCloneGraphOperation cloner = new CGraph.CCloneGraphOperation();
            CGraph graph3Clone = cloner.CloneGraph(graph3);


            CGraph.CMergeGraphOperation joiner = new CGraph.CMergeGraphOperation();
            joiner.MergeGraph(graph3);

            CGraph mergedGraph = joiner.MergeGraph(graph3Clone);

            Console.WriteLine("{0}", mergedGraph.ToString());
            // The graph can be printed using the specified graph printer which optionally can
            // take a label contructor. If the label contractor is ommited that printer will recieve
            // labels from the native graph labeller. In this case this what it happens
            graph3.RegisterGraphPrinter(new CGraphVizPrinter(graph3));
            graph3Clone.RegisterGraphPrinter(new CGraphVizPrinter(graph3Clone));
            mergedGraph.RegisterGraphPrinter(new CGraphVizPrinter(mergedGraph));
            // The graph uses the registered printers to print the graph to the specified output
            graph3.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\test3.dot", true);
            graph3Clone.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\test3Clone.dot", true);
            mergedGraph.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\MergeTest.dot", true);

            /*
             *          AlgorithmDataRecord ioargs =
             *              GAlg_LeaderFinder_Builder.Create().
             *                  Input_SourceGraph(graph3).
             *              End();
             *
             *          GAlg_LeaderFinder bbFinder = new GAlg_LeaderFinder(ioargs);
             *          bbFinder.Init();
             * /*
             *          GAlg_BasicBlocks bbCreate = new GAlg_BasicBlocks(graph3,bbFinder);
             *          bbCreate.Init();
             *
             *          // We call the CreateGraphFromCSV where the edges are given as comma separated
             *          // tuples in curly brackets. Sole nodes can be given inside curle brackets. This
             *          // method assigns node labels as given in the file using the native graph labeller
             *          CGraph graph4 = CGraph.CreateGraphFromCSV("csvGraph1.txt");
             *
             *          graph4.RegisterGraphPrinter(new CGraphVizPrinter(graph4));
             *          // The graph uses the registered printers to print the graph to the specified output
             *          graph4.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\test4.dot", true);
             *
             *          GAlg_ExtendedBasicBlockFinder ebbFinder = new GAlg_ExtendedBasicBlockFinder(graph4);
             *          ebbFinder.Init();
             *
             *          // We call the CreateGraphFromCSV where the edges are given as comma separated
             *          // tuples in curly brackets. Sole nodes can be given inside curle brackets. This
             *          // method assigns node labels as given in the file using the native graph labeller
             *          CGraph graph5 = CGraph.CreateGraphFromCSV("csvGraph2.txt");
             *
             *          graph5.RegisterGraphPrinter(new CGraphVizPrinter(graph5));
             *          // The graph uses the registered printers to print the graph to the specified output
             *          graph5.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\csvGraph2.dot", true);
             *
             *          GAlg_DFSSpanningTree dfsSpanningTree = new GAlg_DFSSpanningTree(graph5);
             *          dfsSpanningTree.Init();
             *
             *          dfsSpanningTree.m_dfsSpanningTree.RegisterGraphPrinter(new CDFSSpanningTreeGraphvizPrinter(dfsSpanningTree.m_dfsSpanningTree));
             *          dfsSpanningTree.m_dfsSpanningTree.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\ST.dot", true);
             *
             *          // CREATE A GRAPH FROM RANDOM GRAPH GENERATORS
             *          // A random graph with the specified number of nodes and edges can be generated
             *          // using the GenerateGraph_RandomGraph method. The nodes are labelled in the native
             *          // graph labeller using their serial numbers
             *          graph1.GenerateGraph_RandomGraph(10,40,GraphType.GT_UNDIRECTED);
             *          // The graph can be printed using the specified graph printer which optionally can
             *          // take a label contructor. If the label contractor is ommited that printer will recieve
             *          // labels from the native graph labeller. In this case this what it happens
             *          graph1.RegisterGraphPrinter(new CGraphVizPrinter(graph1));
             *          // The graph uses the registered printers to print the graph to the specified output
             *          //graph1.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\graph1.dot", true);
             *
             *          graph2.GenerateGraph_RandomGraph(10,40,GraphType.GT_UNDIRECTED);
             *          graph2.RegisterGraphPrinter(new CGraphVizPrinter(graph2));
             *          //graph2.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\graph2.dot", true);*/
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphVizNodeLabeling"/> class.
 /// </summary>
 /// <param name="graph">The graph.</param>
 public GraphVizNodeLabeling(CGraph graph) : base(graph)
 {
     LabelElements();
 }