示例#1
0
        public void parse(List <object[]> nodesData, List <string[]> edgesData, List <List <double[]> > nodesInfo, List <List <double[]> > edgesInfo, DictionaryJ <string, GraphDataConfiguration> graphDataConfigs)
        {
            try
            {
                DictionaryJ <String, object[]> nodesMap = new DictionaryJ <String, object[]>();
                foreach (Edge edge in Graph.Edges)
                {
                    String sourceNodeId = edge.SourceNode.LabelText;
                    String targetNodeId = edge.TargetNode.LabelText;

                    object[] sourceNodeData; // length=4 [1:type, 2:id, 3;label, 4:additionalinfo]
                    if (!string.IsNullOrEmpty(edge.LabelText) && !nodesMap.ContainsKey(sourceNodeId))
                    {
                        EventStepSim userData = edge.SourceNode.UserData as EventStepSim;
                        sourceNodeData    = new object[4];
                        sourceNodeData[0] = "REGULAR";
                        sourceNodeData[1] = sourceNodeId;
                        sourceNodeData[2] = String.Format("[{0}] {1}", sourceNodeId, userData.ToString());
                        PAT.GenericDiff.graph.Graph configGraph = configGraphBuilder.execute(this.side, userData.Config, sourceNodeId);
                        sourceNodeData[3] = configGraph;
                        nodesData.Add(sourceNodeData);

                        nodesInfo.Add(extractNodeInfos(userData.Config.GlobalEnv, configGraph, graphDataConfigs["REGULAR"].elementInfoTemplates));

                        nodesMap.put(sourceNodeId, sourceNodeData);
                    }

                    object[] targetNodeData; // length=4 [1:type, 2:id, 3;label, 4:additionalinfo]
                    if (!nodesMap.ContainsKey(targetNodeId))
                    {
                        EventStepSim userData = edge.TargetNode.UserData as EventStepSim;
                        targetNodeData    = new object[4];
                        targetNodeData[0] = !string.IsNullOrEmpty(edge.LabelText) ? "REGULAR" : "INIT";
                        targetNodeData[1] = targetNodeId;
                        targetNodeData[2] = String.Format("[{0}] {1}", targetNodeId, userData.ToString());
                        PAT.GenericDiff.graph.Graph configGraph = configGraphBuilder.execute(this.side, userData.Config, targetNodeId);
                        targetNodeData[3] = configGraph;
                        nodesData.Add(targetNodeData);

                        nodesInfo.Add(extractNodeInfos(userData.Config.GlobalEnv, configGraph, graphDataConfigs[!string.IsNullOrEmpty(edge.LabelText) ? "REGULAR" : "INIT"].elementInfoTemplates));

                        nodesMap.put(targetNodeId, targetNodeData);
                    }

                    if (!string.IsNullOrEmpty(edge.LabelText))
                    {
                        String[] edgeData = new String[5];
                        edgeData[0] = "TRANSITION";
                        edgeData[1] = edge.LabelText;
                        edgeData[2] = sourceNodeId;
                        edgeData[3] = targetNodeId;
                        edgesData.Add(edgeData);
                        edgesInfo.Add(extractEdgeInfos(edge.LabelText, graphDataConfigs["TRANSITION"].elementInfoTemplates));
                    }
                }
            }
            catch (Exception e)
            {
                //e.printStackTrace();
            }

            if (!compareConfigGraph)
            {
                if (compareParameterizedSystem)
                {
                    adjustNodeInfosForParameterizedSystems(nodesInfo, graphDataConfigs);
                }
                else
                {
                    adjustNodeInfosRegular(nodesInfo, graphDataConfigs);
                }
            }
        }
示例#2
0
        /* todo: xingzc.
         *
         * Need GlobalVar info to initialze nodeInfoTemplates/nodeInfoNone/nodeInfoCalculatorKind
         *
         * Need to know if left/right is parameterized system and cutnumber. This affects initialize() and Parser.
         * For parameterized system, no need to get a subgraph from a Configuration. A counter vector will be ok.
         * Probably we can still obtain a subgraph. But do not need to compare subgraphs. Instead, extract a counter
         * vector from the subgraph and use it to represent the state info.
         */
        public List <PairUpCandidate> execute(Graph left, Graph right, List <string> vars, bool notMaximalBipartite, SpecificationBase leftSpec, SpecificationBase rightSpec, bool eventDetails, bool matchProcessParameters, bool matchStateStructure, bool matchIfGuardCondition)
        {
            if (left.UserData != null)
            {
                this.cutnumber1 = (int)left.UserData;
            }
            if (right.UserData != null)
            {
                this.cutnumber2 = (int)right.UserData;
            }
            this.compareParameterizedSystem = (this.cutnumber1 != -1) && (this.cutnumber2 != -1);

            this.compareConfigGraph = compareConfigGraph && !compareParameterizedSystem;

            this.notMaximalBipartiteMatch = notMaximalBipartite;

            this.matchEventDetails = eventDetails;

            //ly; newly added.
            this.compareConfigGraph = matchStateStructure;
            //todo: matchIfGuardCondition needs to be added.

            List <string> primitiveVariables = new List <string>();

            Valuation leftValuation = leftSpec.GetEnvironment();

            foreach (string varName in vars)
            {
                if (leftValuation != null && leftValuation.Variables != null)
                {
                    ExpressionValue value = leftValuation.Variables.GetContainsKey(varName);
                    if (value is RecordValue)
                    {
                        RecordValue   array = value as RecordValue;
                        List <string> names = new List <string>();
                        for (int i = 0; i < array.Associations.Length; i++)
                        {
                            names.Add(varName);
                        }
                        selectedVariables.Add(names.ToArray());
                        vectorLength.Add(array.Associations.Length); // array length
                    }
                    else if (false)
                    {
                        // todo: xingzc. processing other complex data type
                    }
                    else // primitive types
                    {
                        primitiveVariables.Add(varName);
                    }
                }

                /* now assume variables of left/right graphs are the same and variables of all the nodes are the same
                 * thus, no need to do this
                 */
                /*if (rightValuation != null && rightValuation.Variables != null)
                 * {
                 *  ExpressionValue value = rightValuation.Variables.GetContainsKey(varName);
                 *  if (value is RecordValue)
                 *  {
                 *      selectedVariables.Add(new string[] {varName});
                 *      //vectorsLength.Add((value as RecordValue).Associations.Length); // array length
                 *  }
                 *  else if (false)
                 *  {
                 *      // todo: xingzc. processing other complex data type
                 *  }
                 *  else // primitive types
                 *  {
                 *      primitiveVariables.Add(varName);
                 *  }
                 * }*/
            }

            if (primitiveVariables.Count > 0)
            {
                selectedVariables.Add(primitiveVariables.ToArray());
                vectorLength.Add(primitiveVariables.Count);
            }

            initialize();

            PAT.GenericDiff.diff.GenericDiff diff = new PAT.GenericDiff.diff.GenericDiff(
                diffParameters.compatibleTypes,
                diffParameters.mappingWeights,
                diffParameters.distanceThresholdVectors,
                diffParameters.epsilonEdgesExcluded,
                diffParameters.maxIteration,
                diffParameters.noPairupIdenticalNodesWithOthers,
                diffParameters.stepsOfNeighbors,
                diffParameters.stopGreedySearchThreshold,
                diffParameters.stopPropagationThreshold,
                diffParameters.removeOutliersThreshold,
                diffParameters.considerNodeDistance,
                diffParameters.considerEdgeDistance,
                diffParameters.includeUnmatched,
                diffParameters.includeNeighbors,
                diffParameters.conductCandidatesSearch,
                diffParameters.appendEpsilonPairups,
                diffParameters.doGreedySearch,
                diffParameters.compareAdditionalInfo,
                diffParameters.notMaximalBipartiteMatch,
                diffParameters.searchPotentialCandidatesKind,
                diffParameters.neighborhoodMatchingStrategyKind,
                diffParameters.removeOutliersStrtegyKind,
                diffParameters.matchingStrategyKind,
                null);

            leftSpec.GrabSharedDataLock();
            leftSpec.LockSharedData(true);
            PATModelFileParser modelParser1 = new PATModelFileParser(left, Side.LHS, compareParameterizedSystem, this.compareConfigGraph, matchProcessParameters, infinity, cutnumber1);

            PAT.GenericDiff.graph.Graph graphLeft = createGraph(Side.LHS, modelParser1, leftGraphDataConfigs, "leftgraph");
            leftSpec.UnLockSharedData();

            rightSpec.GrabSharedDataLock();
            rightSpec.LockSharedData(true);
            PATModelFileParser modelParser2 = new PATModelFileParser(right, Side.RHS, compareParameterizedSystem, this.compareConfigGraph, matchProcessParameters, infinity, cutnumber2);

            PAT.GenericDiff.graph.Graph graphRight = createGraph(Side.RHS, modelParser2, rightGraphDataConfigs, "rightgraph");
            rightSpec.UnLockSharedData();

            List <PairUpCandidate> matches = diff.compare(graphLeft, graphRight);

            return(matches);
        }
示例#3
0
        private List <double[]> extractNodeInfos(Valuation globalVars, PAT.GenericDiff.graph.Graph configGraph, String[][] nodeInfoTemplates)
        {
            List <double[]> nodeInfos = new List <double[]>(nodeInfoTemplates.Length);

            for (int i = 0; i < nodeInfoTemplates.Length; i++)
            {
                nodeInfos.Add(null);
            }

            if (globalVars != null)
            {
                if (globalVars.Variables != null)
                {
                    foreach (StringDictionaryEntryWithKey <ExpressionValue> pair in globalVars.Variables._entries)
                    {
                        if (pair != null)
                        {
                            string varName = pair.Key;

                            int i = 0;
                            int j = 0;
                            for (; i < nodeInfoTemplates.Length; i++)
                            {
                                String[] keys = nodeInfoTemplates[i];
                                for (j = 0; j < keys.Length; j++)
                                {
                                    if (keys[j].Equals(varName))
                                    {
                                        break;
                                    }
                                }
                                if (j < keys.Length)
                                {
                                    break;
                                }
                            }

                            if (i < nodeInfoTemplates.Length)
                            {
                                double          value    = Double.NaN;
                                ExpressionValue varValue = pair.Value;
                                if (varValue is RecordValue)
                                {
                                    // todo: xingzc. need to get array length and values in the array
                                    RecordValue       array  = varValue as RecordValue;
                                    ExpressionValue[] values = array.Associations;
                                    nodeInfos[i] = new double[values.Length];
                                    for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
                                    {
                                        if (values[valueIndex] is IntConstant)
                                        {
                                            nodeInfos[i][valueIndex] = (values[valueIndex] as IntConstant).Value;
                                        }
                                        else if (values[valueIndex] is BoolConstant)
                                        {
                                            nodeInfos[i][valueIndex] = (values[valueIndex] as BoolConstant).Value ? 1.0 : 0.0;
                                        }
                                        else
                                        {
                                            // todo: xingzc. process other primitive types
                                        }
                                    }
                                }
                                else if (false)
                                {
                                    // todo: xingzc. process other complex data type
                                }
                                else
                                {
                                    if (varValue is IntConstant)
                                    {
                                        value = (varValue as IntConstant).Value;
                                    }
                                    else if (varValue is BoolConstant)
                                    {
                                        value = (varValue as BoolConstant).Value ? 1.0 : 0.0;
                                    }
                                    else
                                    {
                                        // todo: xingzc. process other primitive types
                                    }

                                    if (nodeInfos[i] == null)
                                    {
                                        nodeInfos[i] = new double[nodeInfoTemplates[i].Length];
                                    }

                                    if (!Double.IsNaN(value))
                                    {
                                        nodeInfos[i][j] = value;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (!compareConfigGraph)
            {
                DictionaryJ <int, int[]> mapLabelindexCount = new DictionaryJ <int, int[]>();
                List <String>            nodeLabels         = configGraph.getNodelabels();
                foreach (String nodeLabel in nodeLabels)
                {
                    int index = CSPConfigurationParser.mapLabelIndex.get(nodeLabel);
                    if (0 != index) // index should not be 0 according to the way to build configGraph
                    {
                        int[] count = mapLabelindexCount.get(index);
                        if (null == count)
                        {
                            count = new int[1];
                            mapLabelindexCount.put(index, count);
                        }
                        int[] labelIndexCount = CSPConfigurationParser.mapLabelIndexCount.get(index); // shold never be null
                        if (labelIndexCount != null)
                        {
                            count[0] = count[0] + labelIndexCount[0];
                        }
                        else
                        {
                            count[0]++;
                        }
                    }
                }

                int      infoIndex       = 0;
                double[] labelindexCount = new double[mapLabelindexCount.Count * 2];
                foreach (int labelindex in mapLabelindexCount.Keys)
                {
                    int[] count = mapLabelindexCount.get(labelindex);
                    if (null != count) // count should not be null
                    {
                        labelindexCount[infoIndex]     = labelindex;
                        labelindexCount[infoIndex + 1] = count[0];
                    }
                    infoIndex = infoIndex + 2;
                }

                nodeInfos[nodeInfoTemplates.Length - 1] = labelindexCount;
            }

            return(nodeInfos);
        }