예제 #1
0
 public static void EnsureIsAnalyzed(LGSPGraph this_)
 {
     if (this_.statistics.vstructs == null || this_.changesCounterAtLastAnalyze != this_.ChangesCounter)
     {
         this_.AnalyzeGraph();
     }
 }
예제 #2
0
 /// <summary>
 /// Copy and extend constructor, creates a named graph from a normal graph.
 /// Initializes the name maps with the names provided in a given attribute each graph element must have
 /// </summary>
 /// <param name="graph">The graph to be used named</param>
 /// <param name="nameAttributeName">The name of the attribute to be used for naming</param>
 /// <param name="oldToNewMap">A map of the old elements to the new elements after cloning</param>
 public LGSPNamedGraph(LGSPGraph graph, String nameAttributeName, out IDictionary <IGraphElement, IGraphElement> oldToNewMap)
     : base(graph, graph.Name, out oldToNewMap)
 {
     NameToElem = new Dictionary <String, IGraphElement>(graph.NumNodes + graph.NumEdges);
     ElemToName = new Dictionary <IGraphElement, String>(graph.NumNodes + graph.NumEdges);
     DoName(nameAttributeName);
 }
 public LGSPGraphProcessingEnvironment(LGSPGraph graph, LGSPActions actions)
     : base(graph, actions)
 {
     transactionManager = new LGSPTransactionManager(this);
     sequencesManager   = new LGSPDeferredSequencesManager();
     SetClearVariables(true);
 }
예제 #4
0
        public static Edge_slowway CreateEdge(LGSPGraph graph, LGSPNode source, LGSPNode target)
        {
            Edge_slowway edge = new Edge_slowway(source, target);

            graph.AddEdge(edge);
            return(edge);
        }
예제 #5
0
        void DoIt()
        {
            graph   = new LGSPGraph(new ProgramGraphsOriginalGraphModel());
            actions = new ProgramGraphsOriginalActions(graph);
            procEnv = new LGSPGraphProcessingEnvironment(graph, actions);

            // use new exact 2.5 interface
            IClass      cls     = null;
            IMethodBody mb      = null;
            bool        success = actions.createProgramGraphPullUp.Apply(procEnv, ref cls, ref mb);
            IMatchesExact <Rule_pullUpMethod.IMatch_pullUpMethod> matchesExact =
                actions.pullUpMethod.Match(procEnv, 0, cls, mb);

            Console.WriteLine(matchesExact.Count + " matches found.");
            Console.WriteLine(matchesExact.FirstExact.node_m5.ToString());

            graph.Clear();

            // and again with old inexact interface
            IMatches matchesInexact;

            object[] returns;

            Action_createProgramGraphPullUp createProgramGraph = Action_createProgramGraphPullUp.Instance;

            matchesInexact = createProgramGraph.Match(procEnv, 0);
            returns        = createProgramGraph.Modify(procEnv, matchesInexact.First);
            IGraphElement[] param = new LGSPNode[2];
            param[0]       = (Class)returns[0];
            param[1]       = (MethodBody)returns[1];
            matchesInexact = actions.GetAction("pullUpMethod").Match(procEnv, 0, param);
            Console.WriteLine(matchesInexact.Count + " matches found.");
            Console.WriteLine(matchesInexact.First.getNodeAt((int)Rule_pullUpMethod.pullUpMethod_NodeNums.m5).ToString());
        }
예제 #6
0
        public LGSPUniquenessEnsurer(LGSPGraph graph)
        {
            if (!graph.Model.GraphElementUniquenessIsEnsured)
            {
                throw new Exception("Internal error, uniqueness ensurer constructed although uniqueness was not requested");
            }

            if (graph.NumNodes > 0 || graph.NumEdges > 0)
            {
                throw new Exception("Graph must be empty!");
            }

            this.graph = graph;

            // global counter for fetching a new unique id
            nextNewId = 0;

            // we use an array organized as heap for storing the "free list" of already allocated but currently not used ids
            heap.Add(-1); // we start at index 1, yields simpler arithmetic

            // subscribe to events we've to listen to ensure unique ids for the graph elements with a minimum amount of gaps
            graph.OnClearingGraph += ClearingGraph;
            graph.OnNodeAdded     += NodeAdded;
            graph.OnEdgeAdded     += EdgeAdded;
            graph.OnRemovingNode  += RemovingNode;
            graph.OnRemovingEdge  += RemovingEdge;
            graph.OnRetypingNode  += RetypingNode;
            graph.OnRetypingEdge  += RetypingEdge;
        }
예제 #7
0
        public static Edge_connection CreateEdge(LGSPGraph graph, LGSPNode source, LGSPNode target)
        {
            Edge_connection edge = new Edge_connection(source, target);

            graph.AddEdge(edge);
            return(edge);
        }
예제 #8
0
        public static Node_Node CreateNode(LGSPGraph graph)
        {
            Node_Node node = new Node_Node();

            graph.AddNode(node);
            return(node);
        }
예제 #9
0
        public static Node_Process CreateNode(LGSPGraph graph)
        {
            Node_Process node = new Node_Process();

            graph.AddNode(node);
            return(node);
        }
예제 #10
0
        public LGSPEdge Retype(LGSPGraph graph, LGSPEdge oldEdge)
        {
            Edge_fluffway newEdge = new Edge_fluffway(oldEdge.source, oldEdge.target);

            switch (oldEdge.Type.TypeID)
            {
            case (int)EdgeTypes.@speedcon:
            case (int)EdgeTypes.@bigspeedcon:
            case (int)EdgeTypes.@connection:
            {
                IEdge_connection old = (IEdge_connection)oldEdge;
                newEdge.bandwidth = old.bandwidth;
                break;
            }

            case (int)EdgeTypes.@Edge:
            {
                break;
            }
            }

            graph.ReplaceEdge(oldEdge, newEdge);

            return(newEdge);
        }
예제 #11
0
        public GraphMatchingState(LGSPGraph graph)
        {
            ++numGraphsComparedAtLeastOnce;

#if LOG_ISOMORPHY_CHECKING
            if (writer == null)
            {
                writer = new StreamWriter("isocheck_log.txt");
            }

            // print out the names of the type ids referenced in the interpretation plan when the first graph is initialized
            if (numGraphsComparedAtLeastOnce == 1)
            {
                foreach (NodeType nodeType in graph.Model.NodeModel.Types)
                {
                    writer.WriteLine(nodeType.TypeID + " is node type " + nodeType.Name);
                }
                foreach (EdgeType edgeType in graph.Model.EdgeModel.Types)
                {
                    writer.WriteLine(edgeType.TypeID + " is edge type " + edgeType.Name);
                }
                writer.Flush();
            }
#endif
        }
예제 #12
0
        private static void BuildInterpretationPlan(LGSPGraph graph)
        {
            graph.matchingState.patternGraph = BuildPatternGraph(graph);
            PlanGraph planGraph = PlanGraphGenerator.GeneratePlanGraph(graph.Model, graph.statistics, graph.matchingState.patternGraph,
                                                                       false, false, false, new Dictionary <PatternElement, SetValueType>());

            PlanGraphGenerator.MarkMinimumSpanningArborescence(planGraph, graph.matchingState.patternGraph.name, false);
            SearchPlanGraph     searchPlanGraph     = SearchPlanGraphGeneratorAndScheduler.GenerateSearchPlanGraph(planGraph);
            ScheduledSearchPlan scheduledSearchPlan = SearchPlanGraphGeneratorAndScheduler.ScheduleSearchPlan(
                searchPlanGraph, graph.matchingState.patternGraph, false, false);
            InterpretationPlanBuilder builder = new InterpretationPlanBuilder(scheduledSearchPlan, searchPlanGraph, graph.Model);

            graph.matchingState.interpretationPlan = builder.BuildInterpretationPlan("ComparisonMatcher_" + graph.GraphId);
            ++GraphMatchingState.numInterpretationPlans;
            graph.matchingState.changesCounterAtInterpretationPlanBuilding = graph.changesCounterAtLastAnalyze;
            Debug.Assert(graph.changesCounterAtLastAnalyze == graph.ChangesCounter);

#if LOG_ISOMORPHY_CHECKING
            SourceBuilder sb = new SourceBuilder();
            graph.matchingState.interpretationPlan.Dump(sb);
            writer.WriteLine();
            writer.WriteLine(sb.ToString());
            writer.WriteLine();
            writer.Flush();
#endif
        }
예제 #13
0
 /// <summary>
 /// Copy and extend constructor, creates a named graph from a normal graph.
 /// Initializes the name maps with anonymous names in the form "$" + GetNextName()
 /// </summary>
 /// <param name="graph">The graph to be used named</param>
 public LGSPNamedGraph(LGSPGraph graph)
     : base(graph, graph.Name, out tmpOldToNewMap)
 {
     NameToElem     = new Dictionary <String, IGraphElement>(graph.NumNodes + graph.NumEdges);
     ElemToName     = new Dictionary <IGraphElement, String>(graph.NumNodes + graph.NumEdges);
     tmpOldToNewMap = null;
     DoName();
 }
 public LGSPActionExecutionEnvironment(LGSPGraph graph, LGSPActions actions)
 {
     // TODO: evt. IGraph + BaseActions und dann hier cast auf LGSP, mal gucken was an Schnittstelle besser paßt
     this.usedGraphs = new Stack <LGSPGraph>();
     this.usedGraphs.Push(graph);
     this.namedGraphOnTop = graph as LGSPNamedGraph;
     this.curActions      = actions;
     InitActionsProfile(actions);
 }
예제 #15
0
        public LGSPUniquenessIndex(LGSPGraph graph)
            : base(graph)
        {
            if (!graph.Model.GraphElementsAreAccessibleByUniqueId)
            {
                throw new Exception("Internal error, uniqueness index constructed although access by unique id was not requested");
            }

            index = new List <IGraphElement>();
        }
예제 #16
0
        /// <summary>
        /// Constructs a new LGSPActions instance.
        /// This constructor is deprecated.
        /// </summary>
        /// <param name="lgspgraph">The associated graph.</param>
        /// <param name="modelAsmName">The name of the model assembly.</param>
        /// <param name="actionsAsmName">The name of the actions assembly.</param>
        public LGSPActions(LGSPGraph lgspgraph, String modelAsmName, String actionsAsmName)
        {
            graph               = lgspgraph;
            modelAssemblyName   = modelAsmName;
            actionsAssemblyName = actionsAsmName;
            matcherGenerator    = new LGSPMatcherGenerator(graph.Model);
#if ASSERT_ALL_UNMAPPED_AFTER_MATCH
            OnMatched += new AfterMatchHandler(AssertAllUnmappedAfterMatch);
#endif
        }
예제 #17
0
        public virtual void FillAsClone(LGSPGraph originalGraph, IDictionary <IGraphElement, IGraphElement> oldToNewMap)
        {
            LGSPUniquenessEnsurer original = originalGraph.uniquenessEnsurer;

            nextNewId = original.nextNewId;

            heap.Clear(); // remove the -1
            heap.Capacity = original.heap.Capacity;
            heap.AddRange(original.heap);
        }
 public LGSPActionExecutionEnvironment(LGSPGraph graph, LGSPActions actions)
 {
     usedGraphs = new Stack <LGSPGraph>();
     usedGraphs.Push(graph);
     namedGraphOnTop = graph as LGSPNamedGraph;
     curActions      = actions;
     InitActionsProfile(actions);
     customCommandsToDescriptions = new Dictionary <string, string>();
     FillCustomCommandDescriptions();
 }
예제 #19
0
 static void PrintResults(int duration, LGSPGraph graph)
 {
     Console.WriteLine("Mutex benchmark: " + duration + " ms");
     Console.WriteLine("Number of nodes: " + graph.NumNodes);
     Console.WriteLine("Number of edges: " + graph.NumEdges);
     Console.WriteLine("Number of Process nodes: " + graph.GetNumExactNodes(Process.TypeInstance));
     Console.WriteLine("Number of Resource nodes: " + graph.GetNumExactNodes(Resource.TypeInstance));
     Console.WriteLine("Number of next edges: " + graph.GetNumExactEdges(next.TypeInstance));
     Console.WriteLine("Number of request edges: " + graph.GetNumExactEdges(request.TypeInstance));
     Console.WriteLine("Number of token edges: " + graph.GetNumExactEdges(token.TypeInstance));
 }
예제 #20
0
        /// <summary>
        /// Creates a new LGSPGraph and LGSPActions instance from the specified specification file.
        /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
        /// A name for the graph is automatically generated.
        /// </summary>
        /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
        /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
        /// <param name="newGraph">Returns the new graph.</param>
        /// <param name="newActions">Returns the new BaseActions object.</param>
        /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
        /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
        public void CreateFromSpec(String grgFilename, String statisticsPath,
                                   out LGSPGraph newGraph, out LGSPActions newActions)
        {
            LGSPGraph   graph;
            LGSPActions actions;

            CreateFromSpec(grgFilename, GetNextGraphName(), statisticsPath, ProcessSpecFlags.UseNoExistingFiles, new List <String>(), false, 0,
                           out graph, out actions);
            newGraph   = graph;
            newActions = actions;
        }
예제 #21
0
        /// <summary>
        /// Constructs a new LGSPActions instance.
        /// </summary>
        /// <param name="lgspgraph">The associated graph.</param>
        public LGSPActions(LGSPGraph lgspgraph)
        {
            graph            = lgspgraph;
            matcherGenerator = new LGSPMatcherGenerator(graph.Model);

            modelAssemblyName   = Assembly.GetAssembly(graph.Model.GetType()).Location;
            actionsAssemblyName = Assembly.GetAssembly(this.GetType()).Location;

#if ASSERT_ALL_UNMAPPED_AFTER_MATCH
            OnMatched += new AfterMatchHandler(AssertAllUnmappedAfterMatch);
#endif
        }
예제 #22
0
        public override IGraphElement[] ModifyNoReuse(LGSPGraph graph, LGSPMatch match)
        {
            LGSPNode node_p2     = match.nodes[(int)NodeNums.@p2 - 1];
            LGSPNode node_p1     = match.nodes[(int)NodeNums.@p1 - 1];
            LGSPEdge edge__edge0 = match.edges[(int)EdgeNums.@_edge0 - 1];
            LGSPNode node__node0 = graph.AddNode(NodeType_Process.typeVar);
            LGSPEdge edge__edge1 = graph.AddEdge(EdgeType_connection.typeVar, node_p1, node__node0);
            LGSPEdge edge__edge2 = graph.AddEdge(EdgeType_connection.typeVar, node__node0, node_p2);

            graph.Remove(edge__edge0);
            return(EmptyReturnElements);
        }
예제 #23
0
        public LGSPNode Retype(LGSPGraph graph, LGSPNode oldNode)
        {
            Node_Process newNode = new Node_Process();

            graph.AddNodeWithoutEvents(newNode, (int)NodeTypes.@Process);
            switch (oldNode.Type.TypeID)
            {
            case (int)NodeTypes.@Process:
            {
                Node_Process old = (Node_Process)oldNode;
                newNode.val  = old.val;
                newNode.name = old.name;
                break;
            }

            case (int)NodeTypes.@Node:
            {
                break;
            }
            }

            // Reassign all outgoing edges
            LGSPEdge outHead = oldNode.outhead;

            if (outHead != null)
            {
                LGSPEdge outCur = outHead;
                do
                {
                    outCur.source = newNode;
                    outCur        = outCur.outNext;
                }while(outCur != outHead);
            }
            newNode.outhead = outHead;

            // Reassign all incoming edges
            LGSPEdge inHead = oldNode.outhead;

            if (inHead != null)
            {
                LGSPEdge inCur = inHead;
                do
                {
                    inCur.target = newNode;
                    inCur        = inCur.inNext;
                }while(inCur != inHead);
            }
            newNode.inhead = inHead;

            return(newNode);
        }
예제 #24
0
 static void PrintResults(int duration, LGSPGraph graph)
 {
     Console.WriteLine("AntWorld benchmark: " + duration + " ms");
     Console.WriteLine("Number of nodes: " + graph.NumNodes);
     Console.WriteLine("Number of edges: " + graph.NumEdges);
     Console.WriteLine("Number of Process nodes: " + graph.GetNumExactNodes(Ant.TypeInstance));
     Console.WriteLine("Number of Resource nodes: " + graph.GetNumExactNodes(GridNode.TypeInstance));
     Console.WriteLine("Number of Process nodes: " + graph.GetNumExactNodes(GridCornerNode.TypeInstance));
     Console.WriteLine("Number of Resource nodes: " + graph.GetNumExactNodes(AntHill.TypeInstance));
     Console.WriteLine("Number of next edges: " + graph.GetNumExactEdges(NextAnt.TypeInstance));
     Console.WriteLine("Number of request edges: " + graph.GetNumExactEdges(GridEdge.TypeInstance));
     Console.WriteLine("Number of token edges: " + graph.GetNumExactEdges(PathToHill.TypeInstance));
     Console.WriteLine("Number of token edges: " + graph.GetNumExactEdges(AntPosition.TypeInstance));
 }
예제 #25
0
        /// <summary>
        /// Constructs a new LGSPActions instance.
        /// This constructor is deprecated.
        /// </summary>
        /// <param name="lgspgraph">The associated graph.</param>
        /// <param name="modelAsmName">The name of the model assembly.</param>
        /// <param name="actionsAsmName">The name of the actions assembly.</param>
        protected LGSPActions(LGSPGraph lgspgraph, String modelAsmName, String actionsAsmName)
        {
            graph               = lgspgraph;
            modelAssemblyName   = modelAsmName;
            actionsAssemblyName = actionsAsmName;
            matcherGenerator    = new LGSPMatcherGenerator(graph.Model);

            customCommandsToDescriptions = new Dictionary <string, string>();
            FillCustomCommandDescriptions();

#if ASSERT_ALL_UNMAPPED_AFTER_MATCH
            OnMatched += new AfterMatchHandler(AssertAllUnmappedAfterMatch);
#endif
        }
예제 #26
0
        public override void FillAsClone(LGSPGraph originalGraph, IDictionary <IGraphElement, IGraphElement> oldToNewMap)
        {
            base.FillAsClone(originalGraph, oldToNewMap);

            LGSPUniquenessIndex original = (LGSPUniquenessIndex)originalGraph.uniquenessEnsurer;

            if (original.index != null)
            {
                index = new List <IGraphElement>(original.index.Capacity);
                for (int i = 0; i < original.index.Count; ++i)
                {
                    index.Add(oldToNewMap[original.index[i]]);
                }
            }
        }
예제 #27
0
        /// <summary>
        /// Constructs a new LGSPActions instance.
        /// </summary>
        /// <param name="lgspgraph">The associated graph.</param>
        protected LGSPActions(LGSPGraph lgspgraph)
        {
            graph            = lgspgraph;
            matcherGenerator = new LGSPMatcherGenerator(graph.Model);

            modelAssemblyName   = Assembly.GetAssembly(graph.Model.GetType()).Location;
            actionsAssemblyName = Assembly.GetAssembly(this.GetType()).Location;

            customCommandsToDescriptions = new Dictionary <string, string>();
            FillCustomCommandDescriptions();

#if ASSERT_ALL_UNMAPPED_AFTER_MATCH
            OnMatched += new AfterMatchHandler(AssertAllUnmappedAfterMatch);
#endif
        }
        public void DoUndo(IGraphProcessingEnvironment procEnv)
        {
            String name;

            if (procEnv.Graph is LGSPNamedGraph && ((LGSPNamedGraph)procEnv.Graph).ElemToName.TryGetValue(_newElem, out name))
            {
                LGSPNamedGraph lgspGraph = (LGSPNamedGraph)procEnv.Graph;
                if (_newElem is INode)
                {
                    LGSPNode newNode = (LGSPNode)_newElem;
                    LGSPNode oldNode = (LGSPNode)_oldElem;
                    lgspGraph.ElemToName[oldNode] = name;
                    lgspGraph.RetypingNode(newNode, oldNode); // this will switch the variables
                    lgspGraph.ReplaceNode(newNode, oldNode);
                    lgspGraph.ElemToName.Remove(newNode);
                    lgspGraph.NameToElem[name] = oldNode;
                }
                else
                {
                    LGSPEdge newEdge = (LGSPEdge)_newElem;
                    LGSPEdge oldEdge = (LGSPEdge)_oldElem;
                    lgspGraph.ElemToName[oldEdge] = name;
                    lgspGraph.RetypingEdge(newEdge, oldEdge); // this will switch the variables
                    lgspGraph.ReplaceEdge(newEdge, oldEdge);
                    lgspGraph.ElemToName.Remove(newEdge);
                    lgspGraph.NameToElem[name] = oldEdge;
                }
            }
            else
            {
                LGSPGraph lgspGraph = (LGSPGraph)procEnv.Graph;
                if (_newElem is INode)
                {
                    LGSPNode newNode = (LGSPNode)_newElem;
                    LGSPNode oldNode = (LGSPNode)_oldElem;
                    lgspGraph.RetypingNode(newNode, oldNode); // this will switch the variables
                    lgspGraph.ReplaceNode(newNode, oldNode);
                }
                else
                {
                    LGSPEdge newEdge = (LGSPEdge)_newElem;
                    LGSPEdge oldEdge = (LGSPEdge)_oldElem;
                    lgspGraph.RetypingEdge(newEdge, oldEdge); // this will switch the variables
                    lgspGraph.ReplaceEdge(newEdge, oldEdge);
                }
            }
        }
예제 #29
0
        void DoIter()
        {
            graph   = new LGSPGraph(new StdGraphModel());
            actions = new spanningTreeActions(graph);
            procEnv = new LGSPGraphProcessingEnvironment(graph, actions);

            IAction_initUndirected init = actions.initUndirected;
            IMatchesExact <Rule_initUndirected.IMatch_initUndirected> matchesInitUndirected = init.Match(procEnv, 0);
            INode root;

            init.Modify(procEnv, matchesInitUndirected.FirstExact, out root);

            IMatchesExact <Rule_spanningTree.IMatch_spanningTree> matchesSpanningTree = actions.spanningTree.Match(procEnv, 0, root);

            actions.spanningTree.Modify(procEnv, matchesSpanningTree.FirstExact);
            Console.WriteLine(matchesSpanningTree.Count + " matches found.");
        }
예제 #30
0
 public LGSPMatches myMatch(LGSPGraph graph, int maxMatches, IGraphElement[] parameters)
 {
     matches.matches.Clear();
     // Lookup(edge__edge0:connection)
     foreach (EdgeType edge_type_edge__edge0 in EdgeType_connection.typeVar.SubOrSameTypes)
     {
         for (LGSPEdge edge_head_edge__edge0 = graph.edgesByTypeHeads[edge_type_edge__edge0.TypeID], edge_cur_edge__edge0 = edge_head_edge__edge0.typeNext; edge_cur_edge__edge0 != edge_head_edge__edge0; edge_cur_edge__edge0 = edge_cur_edge__edge0.typeNext)
         {
             // ImplicitTarget(edge__edge0 -> node_p2:Process)
             LGSPNode node_cur_node_p2 = edge_cur_edge__edge0.target;
             if (!NodeType_Process.isMyType[node_cur_node_p2.type.TypeID])
             {
                 goto contunmap_edge_cur_edge__edge0_2;
             }
             node_cur_node_p2.mappedTo = 1;
             // ImplicitSource(edge__edge0 -> node_p1:Process)
             LGSPNode node_cur_node_p1 = edge_cur_edge__edge0.source;
             if (!NodeType_Process.isMyType[node_cur_node_p1.type.TypeID])
             {
                 goto contunmap_node_cur_node_p2_4;
             }
             if (node_cur_node_p1.mappedTo != 0)
             {
                 goto cont_node_cur_node_p1_7;
             }
             LGSPMatch match = matchesList.GetNewMatch();
             match.nodes[0] = node_cur_node_p2;
             match.nodes[1] = node_cur_node_p1;
             match.edges[0] = edge_cur_edge__edge0;
             matchesList.CommitMatch();
             if (maxMatches > 0 && matchesList.Count >= maxMatches)
             {
                 node_cur_node_p2.mappedTo = 0;
                 graph.MoveHeadAfter(edge_cur_edge__edge0);
                 return(matches);
             }
             cont_node_cur_node_p1_7      :;
             contunmap_node_cur_node_p2_4 :;
             node_cur_node_p2.mappedTo = 0;
             contunmap_edge_cur_edge__edge0_2 :;
             // Tail of Lookup(edge_cur_edge__edge0)
         }
     }
     return(matches);
 }