protected FAInfo UpdateClosureInformation(FA synth, FA currentFA, CGraph.CMergeGraphOperation mergeOperation) { FAInfo closureOperandInfo = synth.GetFAInfo(); // get access to the closure operand FA FAInfo currentFAInfo = currentFA.GetFAInfo(); // get access to the current FA info foreach (FALoop faLoop in closureOperandInfo.MLoopsInFa.Values) { FALoop newloop = new FALoop(); CGraphNode entry = faLoop.MEntryNode; newloop.MEntryNode = mergeOperation.GetMirrorNode(entry); CGraphNode exit = faLoop.MExitNode; newloop.MExitNode = mergeOperation.GetMirrorNode(exit); foreach (CGraphNode cGraphNode in faLoop.MParticipatingNodes) { newloop.MParticipatingNodes.Add(mergeOperation.GetMirrorNode(cGraphNode)); } FALoop.ClosureType closureType = faLoop.MClosureType; Range <int> clsrng = faLoop.MClosureRange; if (clsrng != null) { newloop.MClosureRange = new Range <int>(clsrng); } newloop.MClosureType = faLoop.MClosureType; newloop.MLoopSerial = faLoop.MLoopSerial; currentFAInfo.AddFALoop(newloop); } return(currentFAInfo); }
internal FA SynthesizeOneOrNone(FA synth) { FA tempFA = new FA(); //2.Merge graph CGraph.CMergeGraphOperation merged = tempFA.Merge(synth, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT); merged.MergeGraphInfo(synth, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); merged.MergeGraphInfo(synth, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); merged.MergeGraphInfo(synth, GraphElementType.ET_NODE, FA.m_FAINFOKEY); CGraphNode il = tempFA.CreateGraphNode <CGraphNode>(); tempFA.AddGraphEdge <CGraphEdge, CGraphNode>(il, merged.GetMirrorNode(synth.M_Initial), GraphType.GT_DIRECTED); CGraphNode fl = tempFA.CreateGraphNode <CGraphNode>(); tempFA.AddGraphEdge <CGraphEdge, CGraphNode>(merged.GetMirrorNode(synth.GetFinalStates()[0]), fl, GraphType.GT_DIRECTED); //4.Create the initial and the final node tempFA.M_Initial = il; tempFA.SetFinalState(fl); tempFA.UpdateAlphabet(); tempFA.AddGraphEdge <CGraphEdge, CGraphNode>(il, fl, GraphType.GT_DIRECTED); //7.Return result return(tempFA); }
internal FA Synthesize(FA l, FA r) { FA tempFA = new FA(); //2.Merge left graph CGraph.CMergeGraphOperation lmerge = tempFA.Merge(l, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT); lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, FA.m_FAINFOKEY); CGraphNode il = lmerge.GetMirrorNode(l.M_Initial); CGraphNode fl = lmerge.GetMirrorNode(l.GetFinalStates()[0]); //3.Merge right graph CGraph.CMergeGraphOperation rmerge = tempFA.Merge(r, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT); rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, FA.m_FAINFOKEY); CGraphNode ir = rmerge.GetMirrorNode(r.M_Initial); CGraphNode fr = rmerge.GetMirrorNode(r.GetFinalStates()[0]); //4.Create the initial and the final node tempFA.M_Initial = il; tempFA.SetFinalState(fr); tempFA.AddGraphEdge <CGraphEdge, CGraphNode>(fl, ir, GraphType.GT_DIRECTED); //7.Return result return(tempFA); }
internal FA Sythesize(FA l, FA r, CGraph.CMergeGraphOperation.MergeOptions options) { //1.Create FA m_currentFA = new FA(); m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey); //2.Merge left graph CGraph.CMergeGraphOperation lmerge = m_currentFA.Merge(l, options); //Console.WriteLine(l.ToString()); lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, m_ThompsonInfoKey); lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, m_ThompsonInfoKey); lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, m_ThompsonInfoKey); CGraphNode il = lmerge.GetMirrorNode(l.M_Initial); CGraphNode fl = lmerge.GetMirrorNode(l.GetFinalStates()[0]); //3.Merge right graph CGraph.CMergeGraphOperation rmerge = m_currentFA.Merge(r, options); rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, m_ThompsonInfoKey); rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, m_ThompsonInfoKey); rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, m_ThompsonInfoKey); CGraphNode ir = rmerge.GetMirrorNode(r.M_Initial); CGraphNode fr = rmerge.GetMirrorNode(r.GetFinalStates()[0]); //4.Create the initial and the final node CGraphNode FAinit = m_currentFA.CreateGraphNode <CGraphNode>(); CGraphNode FAfinal = m_currentFA.CreateGraphNode <CGraphNode>(); m_ThompsonInfo.InitNodeInfo(FAinit, new ThompsonNodeFAInfo()); m_ThompsonInfo.InitNodeInfo(FAfinal, new ThompsonNodeFAInfo()); m_currentFA.M_Initial = FAinit; m_currentFA.SetFinalState(FAfinal); m_currentFA.UpdateAlphabet(); m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(FAinit, il, GraphType.GT_DIRECTED); m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(FAinit, ir, GraphType.GT_DIRECTED); m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(fr, FAfinal, GraphType.GT_DIRECTED); m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(fl, FAfinal, GraphType.GT_DIRECTED); // Update closure information from operand closure // Update closure information from operand closure UpdateClosureInformation(l, m_currentFA, lmerge); UpdateClosureInformation(r, m_currentFA, rmerge); //7.Return result return(m_currentFA); }
internal FA Synthesize(FA l, FA r) { FA m_currentFA = new FA(); m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey); //2.Merge left graph CGraph.CMergeGraphOperation lmerge = m_currentFA.Merge(l, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT); lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, m_ThompsonInfoKey); lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, m_ThompsonInfoKey); lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, m_ThompsonInfoKey); CGraphNode il = lmerge.GetMirrorNode(l.M_Initial); CGraphNode fl = lmerge.GetMirrorNode(l.GetFinalStates()[0]); //3.Merge right graph CGraph.CMergeGraphOperation rmerge = m_currentFA.Merge(r, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT); rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, m_ThompsonInfoKey); rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, m_ThompsonInfoKey); rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, m_ThompsonInfoKey); CGraphNode ir = rmerge.GetMirrorNode(r.M_Initial); CGraphNode fr = rmerge.GetMirrorNode(r.GetFinalStates()[0]); //4.Create the initial and the final node m_currentFA.M_Initial = il; m_currentFA.SetFinalState(fr); m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(fl, ir, GraphType.GT_DIRECTED); // Update closure information from operand closure UpdateClosureInformation(l, m_currentFA, lmerge); UpdateClosureInformation(r, m_currentFA, rmerge); //7.Return result return(m_currentFA); }
internal FA Sythesize(FA l, FA r, CGraph.CMergeGraphOperation.MergeOptions options) { //1.Create FA FA templateFA = new FA(); //2.Merge left graph CGraph.CMergeGraphOperation lmerge = templateFA.Merge(l, options); //Console.WriteLine(l.ToString()); lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, FA.m_FAINFOKEY); CGraphNode il = lmerge.GetMirrorNode(l.M_Initial); CGraphNode fl = lmerge.GetMirrorNode(l.GetFinalStates()[0]); //3.Merge right graph CGraph.CMergeGraphOperation rmerge = templateFA.Merge(r, options); rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY); rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, FA.m_FAINFOKEY); CGraphNode ir = rmerge.GetMirrorNode(r.M_Initial); CGraphNode fr = rmerge.GetMirrorNode(r.GetFinalStates()[0]); //4.Create the initial and the final node CGraphNode FAinit = templateFA.CreateGraphNode <CGraphNode>(); CGraphNode FAfinal = templateFA.CreateGraphNode <CGraphNode>(); templateFA.M_Initial = FAinit; templateFA.SetFinalState(FAfinal); templateFA.UpdateAlphabet(); templateFA.AddGraphEdge <CGraphEdge, CGraphNode>(FAinit, il, GraphType.GT_DIRECTED); templateFA.AddGraphEdge <CGraphEdge, CGraphNode>(FAinit, ir, GraphType.GT_DIRECTED); templateFA.AddGraphEdge <CGraphEdge, CGraphNode>(fr, FAfinal, GraphType.GT_DIRECTED); templateFA.AddGraphEdge <CGraphEdge, CGraphNode>(fl, FAfinal, GraphType.GT_DIRECTED); //7.Return result return(templateFA); }
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);*/ }