示例#1
0
        private void adjustNodeInfosRegular(List <List <double[]> > nodesInfo, DictionaryJ <string, GraphDataConfiguration> graphDataConfigs)
        {
            foreach (List <double[]> nodeInfos in nodesInfo)
            {
                double[] counters    = nodeInfos[nodeInfos.Count - 1]; // label info vector always the last one in nodeInfos list
                double[] newcounters = new double[CSPConfigurationParser.mapLabelIndex.Count];
                int      infoIndex   = 0;
                foreach (int labelIndex in CSPConfigurationParser.mapLabelIndex.Values)
                {
                    double value = 0;
                    for (int counterIndex = 0; counterIndex < counters.Length; counterIndex = counterIndex + 2)
                    {
                        if (counters[counterIndex] == labelIndex)
                        {
                            value = counters[counterIndex + 1];
                            break;
                        }
                    }

                    newcounters[infoIndex] = value;
                    infoIndex++;
                }

                nodeInfos[nodeInfos.Count - 1] = newcounters;
            }

            double[] nodeInfoNone = new double[CSPConfigurationParser.mapLabelIndex.Count];

            GraphDataConfiguration dataConfig = graphDataConfigs.get("REGULAR");

            dataConfig.elementInfoNone[dataConfig.elementInfoNone.Length - 1] = nodeInfoNone;

            dataConfig = graphDataConfigs.get("INIT");
            dataConfig.elementInfoNone[dataConfig.elementInfoNone.Length - 1] = nodeInfoNone;
        }
示例#2
0
        public override void initialize()
        {
            // Control what graph elements will be created
            graphCreationParameters.createQualifiedGraphNode      = false;
            graphCreationParameters.containmentRelation           = "";
            graphCreationParameters.encapsulateInMatchedGraphNode = false;

            // GenericDiff parameters according to domain semantics
            diffParameters.compatibleTypes =
                new String[][]
            {
                new String[] { "INIT", "100", "false", null },
                new String[] { "REGULAR", "100", "false", null },
                new String[] { "TRANSITION", "200", "false", "false, true" }       //String.Format("false, {0}", matchEventDetails ? "true" : "false")}};
            };

            diffParameters.mappingWeights =
                new String[][] {
                new String[] { "INIT", "INIT", "1", "true" },
                new String[] { "REGULAR", "REGULAR", "1", "true" },
                new String[] { "INIT", "REGULAR", "1", "true" },
                new String[] { "REGULAR", "INIT", "1", "true" },
                new String[] { "TRANSITION", "TRANSITION", "1", "true" }
            };

            diffParameters.distanceThresholdVectors =
                new String[][] {
                new String[] { "TRANSITION", "TRANSITION", "0", "0" }
            };                                                                    // hamming distance threshold=0 means only same-label transitions can be paired-up

            diffParameters.epsilonEdgesExcluded = new String[0][];

            // GenericDiff execution control parameters
            diffParameters.maxIteration = 100;
            diffParameters.noPairupIdenticalNodesWithOthers = false; //todo: xingzc. only make sense when nodes have meaningful labels
            diffParameters.stepsOfNeighbors          = 1;
            diffParameters.stopGreedySearchThreshold = 0.8;
            diffParameters.stopPropagationThreshold  = 0.00001;
            diffParameters.removeOutliersThreshold   = 2;
            diffParameters.considerNodeDistance      = true;
            diffParameters.considerEdgeDistance      = true;
            diffParameters.includeUnmatched          = false;
            diffParameters.includeNeighbors          = this.matchEventDetails;
            diffParameters.conductCandidatesSearch   = true;
            diffParameters.appendEpsilonPairups      = true;
            diffParameters.doGreedySearch            = true;
            diffParameters.compareAdditionalInfo     = this.compareConfigGraph; // !compareParameterizedSystem; //todo: xingzc. set false if parameterized system
            diffParameters.notMaximalBipartiteMatch  = this.notMaximalBipartiteMatch;

            // Strategy objects
            diffParameters.searchPotentialCandidatesKind    = CandidatesSearchStrategyKind.Sequential;
            diffParameters.neighborhoodMatchingStrategyKind = SelectionStrategyKind.StableMarriage;
            diffParameters.removeOutliersStrtegyKind        = RemoveOutliersStrategyKind.None;
            diffParameters.matchingStrategyKind             = SelectionStrategyKind.StableMarriage;

            // Domain knowledge that controls the parsing and graph creation process
            int numOfVectors = selectedVariables.Count; // todo: xingzc. the number of variable groups.

            if (!this.compareConfigGraph)
            {
                numOfVectors = numOfVectors + 1;
            }

            string[][] nodeInfoTemplates      = new string[numOfVectors][];
            double[][] nodeInfoNone1          = new double[numOfVectors][];
            double[][] nodeInfoNone2          = new double[numOfVectors][];
            string[][] nodeInfoCalculatorKind = new string[numOfVectors][];

            if (!this.compareConfigGraph)
            {
                nodeInfoTemplates[numOfVectors - 1]      = new string[0];
                nodeInfoNone1[numOfVectors - 1]          = new double[0];
                nodeInfoNone2[numOfVectors - 1]          = new double[0];
                nodeInfoCalculatorKind[numOfVectors - 1] = new String[] { "Taxi", "vector" };
            }

            // todo: xingzc. initialize info vectors by selected variables
            for (int varGroupIndex = 0; varGroupIndex < selectedVariables.Count; varGroupIndex++)
            {
                string[] varGroup = selectedVariables[varGroupIndex];

                nodeInfoTemplates[varGroupIndex]      = varGroup;
                nodeInfoNone1[varGroupIndex]          = new double[vectorLength[varGroupIndex]];
                nodeInfoNone2[varGroupIndex]          = new double[vectorLength[varGroupIndex]];
                nodeInfoCalculatorKind[varGroupIndex] = new String[] { "Hamming", "vector" }; // todo: xingzc. may be taxi if int
            }

            /*String[][] nodeInfoTemplates =
             *  new String[][]
             *      {
             *          //new String[] {""}, //todo: xingzc. A counter vector if parameterized system, otherwise no vector
             *          //new String[] {"noOfReading", "writing"} //todo: xingzc. initialze from selected variables
             *      };
             *
             * double[][] nodeInfoNone1 =
             *  new double[][]
             *      {
             *          //new double[] {},// todo: xingzc. A none counter vector if parameterized system, otherwise no vector
             *          //new double[] {0, 0} //todo: xingzc.initialze from selected variables
             *      };
             *
             * double[][] nodeInfoNone2 =
             *  new double[][]
             *      {
             *          //new double[] {},// todo: xingzc. A none counter vector if parameterized system, otherwise no vector
             *          //new double[] {0, 0} //todo: xingzc.initialze from selected variables
             *      };
             *
             * String[][] nodeInfoCalculatorKind =
             *  new String[][]
             *      {
             *          //new String[] {"BagJaccard", "set"}, //todo: xingzc.
             *          //new String[] {"Hamming", "vector"} //todo: xingzc.
             *      };*/

            String[][] edgeInfoTemplates = new String[][]
            {
                new String[] { "" },
                new String[0]
            };

            double[][] edgeInfoNone = new double[][]
            {
                new double[] { 0 },
                new double[0]
            };

            String[][] edgeInfoCalculatorKind = new String[][]
            {
                new String[] { "Hamming", "vector" },
                new String[] { "SeqHamming", "set" }
            };

            leftGraphDataConfigs = new DictionaryJ <String, GraphDataConfiguration>();
            GraphDataConfiguration leftGraphDataConfig = GraphDataConfiguration.create(nodeInfoTemplates, nodeInfoNone1, nodeInfoCalculatorKind, null);

            leftGraphDataConfigs.Add("INIT", leftGraphDataConfig);
            leftGraphDataConfigs.Add("REGULAR", leftGraphDataConfig);

            rightGraphDataConfigs = new DictionaryJ <String, GraphDataConfiguration>();
            GraphDataConfiguration rightGraphDataConfig = GraphDataConfiguration.create(nodeInfoTemplates, nodeInfoNone2, nodeInfoCalculatorKind, null);

            rightGraphDataConfigs.Add("INIT", rightGraphDataConfig);
            rightGraphDataConfigs.Add("REGULAR", rightGraphDataConfig);

            GraphDataConfiguration edgeConfig = GraphDataConfiguration.create(edgeInfoTemplates, edgeInfoNone, edgeInfoCalculatorKind, null);

            leftGraphDataConfigs.Add("TRANSITION", edgeConfig);
            rightGraphDataConfigs.Add("TRANSITION", edgeConfig);
        }
示例#3
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);
                }
            }
        }
示例#4
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);
        }
示例#5
0
        private void adjustNodeInfosForParameterizedSystems(List <List <double[]> > nodesInfo, DictionaryJ <string, GraphDataConfiguration> graphDataConfigs)
        {
            foreach (List <double[]> nodeInfos in nodesInfo)
            {
                double[] counters    = nodeInfos[nodeInfos.Count - 1]; // label info vector always the last one in nodeInfos list
                double[] newcounters = new double[CSPConfigurationParser.mapLabelIndexMinCount.Count];
                int      infoIndex   = 0;
                foreach (int labelIndex in CSPConfigurationParser.mapLabelIndexMinCount.Keys)
                {
                    double value = 0;
                    for (int counterIndex = 0; counterIndex < counters.Length; counterIndex = counterIndex + 2)
                    {
                        if (counters[counterIndex] == labelIndex)
                        {
                            value = counters[counterIndex + 1];
                            break;
                        }
                    }

                    int[] labelIndexFirstCount = CSPConfigurationParser.maplabelIndexFirstCount.get(labelIndex);
                    int[] labelIndexMinCount   = CSPConfigurationParser.mapLabelIndexMinCount.get(labelIndex);

                    if (value == -1)
                    {
                        newcounters[infoIndex] = infinity;
                    }
                    else
                    {
                        if (labelIndexMinCount[0] == -1)
                        {
                            newcounters[infoIndex] = Math.Abs(cutnumber - value);
                        }
                        else if (labelIndexMinCount[0] == 0)
                        {
                            newcounters[infoIndex] = value;
                        }
                        else
                        {
                            throw new Exception(String.Format("Invalid LabelIndex MinCount {0}", labelIndexMinCount[0]));
                        }
                    }

                    infoIndex++;
                }

                nodeInfos[nodeInfos.Count - 1] = newcounters;

                /*for(int index = 0; index < counters.Length; index=index+2)
                 * {
                 *  int[] labelIndexFirstCount = CSPConfigurationParser.maplabelIndexFirstCount.get((int)counters[index]);
                 *  int[] labelIndexMinCount = CSPConfigurationParser.mapLabelIndexMinCount.get((int)counters[index]);
                 *  if (counters[index + 1] == -1)
                 *  {
                 *      counters[index + 1] = infinity;
                 *  }
                 *  else
                 *  {
                 *      if (labelIndexMinCount[0] == -1)
                 *      {
                 *          counters[index + 1] = Math.Abs(cutnumber - counters[index + 1]);
                 *          if (labelIndexFirstCount[0] == -1)
                 *          {
                 *              // do nothing
                 *          }
                 *          else if (labelIndexFirstCount[0] > 0)
                 *          {
                 *              //counters[index + 1] = Math.Abs(cutnumber - counters[index + 1]);
                 *          }
                 *          else
                 *          {
                 *              throw new Exception(String.Format("Invalid LabelIndex FirstCount {0}", labelIndexFirstCount[0]));
                 *          }
                 *      }
                 *      else if (labelIndexMinCount[0] == 0)
                 *      {
                 *          // do nothing
                 *      }
                 *      else
                 *      {
                 *          throw new Exception(String.Format("Invalid LabelIndex MinCount {0}", labelIndexMinCount[0]));
                 *      }
                 *  }
                 * }*/
            }

            double[] nodeInfoNone  = new double[CSPConfigurationParser.mapLabelIndexMinCount.Count];
            int      infoNoneIndex = 0;

            foreach (int index in CSPConfigurationParser.mapLabelIndexMinCount.Keys)
            {
                int[] labelIndexFirstCount = CSPConfigurationParser.maplabelIndexFirstCount.get(index);
                int[] labelIndexMinCount   = CSPConfigurationParser.mapLabelIndexMinCount.get(index);

                //nodeInfoNone[infoNoneIndex] = index;
                if (labelIndexMinCount[0] == -1)
                {
                    if (labelIndexFirstCount[0] == -1)
                    {
                        nodeInfoNone[infoNoneIndex] = infinity;
                    }
                    else if (labelIndexFirstCount[0] > 0)
                    {
                        nodeInfoNone[infoNoneIndex] = cutnumber;
                    }
                    else
                    {
                        throw new Exception(String.Format("Invalid LabelIndex FirstCount {0}", labelIndexFirstCount[0]));
                    }
                }
                else if (labelIndexMinCount[0] == 0)
                {
                    nodeInfoNone[infoNoneIndex] = 0;
                }
                else
                {
                    throw new Exception(String.Format("Invalid LabelIndex MinCount {0}", labelIndexMinCount[0]));
                }
                infoNoneIndex = infoNoneIndex + 1;
            }

            GraphDataConfiguration dataConfig = graphDataConfigs.get("REGULAR");

            dataConfig.elementInfoNone[dataConfig.elementInfoNone.Length - 1] = nodeInfoNone;

            dataConfig = graphDataConfigs.get("INIT");
            dataConfig.elementInfoNone[dataConfig.elementInfoNone.Length - 1] = nodeInfoNone;
        }
        private void initializeParameterizedSystem()
        {
            // Control what graph elements will be created
            graphCreationParameters.createQualifiedGraphNode      = false;
            graphCreationParameters.containmentRelation           = "";
            graphCreationParameters.encapsulateInMatchedGraphNode = false;

            // GenericDiff parameters according to domain semantics
            diffParameters.compatibleTypes =
                new String[][] { new string[] { "NODE", "1000", "false", null },
                                 new String[] { "EDGE", "2000", "false", null } };

            diffParameters.mappingWeights =
                new String[][] { new String[] { "NODE", "NODE", "1", "true" },
                                 new String[] { "EDGE", "EDGE", "1", "true" } };

            diffParameters.distanceThresholdVectors =
                new String[][] {};

            diffParameters.epsilonEdgesExcluded = new String[0][];

            // GenericDiff execution control parameters
            diffParameters.maxIteration = 100;
            diffParameters.noPairupIdenticalNodesWithOthers = false; // value no longer checked in GenericDiff; it is defined for each type and checked insider GraphNode
            diffParameters.stepsOfNeighbors          = 1;
            diffParameters.stopGreedySearchThreshold = 0.8;
            diffParameters.stopPropagationThreshold  = 0.00001;
            diffParameters.removeOutliersThreshold   = 2;
            diffParameters.considerNodeDistance      = false;
            diffParameters.considerEdgeDistance      = false;
            diffParameters.includeUnmatched          = false;
            diffParameters.includeNeighbors          = false;
            diffParameters.conductCandidatesSearch   = false;
            diffParameters.appendEpsilonPairups      = false;
            diffParameters.doGreedySearch            = false;
            diffParameters.compareAdditionalInfo     = false;
            diffParameters.notMaximalBipartiteMatch  = false;

            // Strategy objects
            diffParameters.searchPotentialCandidatesKind    = CandidatesSearchStrategyKind.None;
            diffParameters.neighborhoodMatchingStrategyKind = SelectionStrategyKind.None;
            diffParameters.removeOutliersStrtegyKind        = RemoveOutliersStrategyKind.None;
            diffParameters.matchingStrategyKind             = SelectionStrategyKind.None;

            // Domain knowledge that controls the parsing and graph creation process
            String[][] simpleNodeInfoTemplates = new String[][] {};

            double[][] simpleNodeInfoNone = new double[][] {};

            String[][] simpleNodeInfoCalculatorKind = new String[][] {};

            String[][] edgeInfoTemplates = new String[][] { };

            double[][] edgeInfoNone = new double[][] { };

            String[][] edgeInfoCalculatorKind = new String[][] { };

            graphDataConfigs = new DictionaryJ <String, GraphDataConfiguration>();

            GraphDataConfiguration simpleNodeConfig = GraphDataConfiguration.create(simpleNodeInfoTemplates, simpleNodeInfoNone, simpleNodeInfoCalculatorKind, null);

            graphDataConfigs.Add("NODE", simpleNodeConfig);

            GraphDataConfiguration edgeConfig = GraphDataConfiguration.create(edgeInfoTemplates, edgeInfoNone, edgeInfoCalculatorKind, null);

            graphDataConfigs.Add("EDGE", edgeConfig);
        }
        private void initializeNonParameterizedSystem()
        {
            // Control what graph elements will be created
            graphCreationParameters.createQualifiedGraphNode      = false;
            graphCreationParameters.containmentRelation           = "";
            graphCreationParameters.encapsulateInMatchedGraphNode = false;

            // GenericDiff parameters according to domain semantics
            string channelInOutputValidDistanceElements     = "true, false";                                                                                    // [0] outgoing branch; [1] channelName
            string channelInputGuardedValidDistanceElements = string.Format("true, {0}, false", !compareSameSpec && matchProcessParameters ? "true" : "false"); // [0] outgoing branch; [1] guard expr char array; [2] channelName
            string conditionalChoiceValidDistanceElements   = string.Format("true, {0}", !compareSameSpec && matchProcessParameters ? "true" : "false");        // [0] outgoing branck; [1]
            string dataOpValidDistanceElements = string.Format("true, {0}, {0}, false", !compareSameSpec && matchProcessParameters ? "true" : "false");
            string defRefValidDistanceElements = string.Format("true, {0}, false", matchProcessParameters ? "true" : "false");
            string hidingValidDistanceElements = string.Format("true, {0}", matchProcessParameters ? "true" : "false");

            diffParameters.compatibleTypes =
                new String[][] { new String[] { Constants.ATOMIC_STARTED, "1000", "false", null },
                                 new String[] { Constants.CASE, "1001", "false", null },
                                 new String[] { Constants.GENERAL_CHOICE, "1012", "false", null },
                                 new String[] { Constants.EXTERNAL_CHOICE, "1013", "false", null },
                                 new String[] { Constants.INTERLEAVE, "1014", "false", null },
                                 new String[] { Constants.INTERLEAVE + "a", "1015", "false", null },
                                 new String[] { Constants.INTERNAL_CHOICE, "1016", "false", null },
                                 new String[] { Constants.PARALLEL, "1017", "false", null },
                                 new String[] { Constants.INTERRUPT, "1018", "false", null },
                                 new String[] { Constants.SEQUENTIAL, "1019", "false", null },
                                 new String[] { Constants.SKIP, "1020", "false", null },
                                 new String[] { Constants.STOP, "1021", "false", null },

                                 new String[] { "C!", "1004", "false", channelInOutputValidDistanceElements },      // different node has different label
                                 new String[] { "C?", "1002", "false", channelInOutputValidDistanceElements },      // different node has different label

                                 new String[] { "?[]", "1003", "false", channelInputGuardedValidDistanceElements }, // different node has different label

                                 new String[] { "if", "1005", "false", conditionalChoiceValidDistanceElements },
                                 new String[] { "ifa", "1006", "false", conditionalChoiceValidDistanceElements },
                                 new String[] { "GuardProcess", "1010", "false", conditionalChoiceValidDistanceElements },

                                 new String[] { "DataOpPrefix", "1007", "false", dataOpValidDistanceElements }, // different node has different label

                                 new String[] { "DefRef", "1008", "false", defRefValidDistanceElements },       // different node has different label
                                 new String[] { "EventPrefix", "1009", "false", defRefValidDistanceElements },  // different node has different label

                                 new String[] { Constants.HIDING, "1011", "false", hidingValidDistanceElements },

                                 new String[] { "EDGE", "2000", "false", null } };

            diffParameters.mappingWeights =
                new String[][] { new String[] { Constants.ATOMIC_STARTED, Constants.ATOMIC_STARTED, "1", "true" },
                                 new String[] { Constants.CASE, Constants.CASE, "1", "true" },
                                 new String[] { "C?", "C?", "1", "true" },
                                 new String[] { "?[]", "?[]", "1", "true" },
                                 new String[] { "C!", "C!", "1", "true" },
                                 new String[] { "if", "if", "1", "true" },
                                 new String[] { "ifa", "ifa", "1", "true" },
                                 new String[] { "DataOpPrefix", "DataOpPrefix", "1", "true" },
                                 new String[] { "DefRef", "DefRef", "1", "true" },
                                 new String[] { "EventPrefix", "EventPrefix", "1", "true" },
                                 new String[] { "GuardProcess", "GuardProcess", "1", "true" },
                                 new String[] { Constants.HIDING, Constants.HIDING, "1", "true" },
                                 new String[] { Constants.GENERAL_CHOICE, Constants.GENERAL_CHOICE, "1", "true" },
                                 new String[] { Constants.EXTERNAL_CHOICE, Constants.EXTERNAL_CHOICE, "1", "true" },
                                 new String[] { Constants.INTERLEAVE, Constants.INTERLEAVE, "1", "true" },
                                 new String[] { Constants.INTERLEAVE + "a", Constants.INTERLEAVE + "a", "1", "true" },
                                 new String[] { Constants.INTERNAL_CHOICE, Constants.INTERNAL_CHOICE, "1", "true" },
                                 new String[] { Constants.PARALLEL, Constants.PARALLEL, "1", "true" },
                                 new String[] { Constants.INTERRUPT, Constants.INTERRUPT, "1", "true" },
                                 new String[] { Constants.SEQUENTIAL, Constants.SEQUENTIAL, "1", "true" },
                                 new String[] { Constants.SKIP, Constants.SKIP, "1", "true" },
                                 new String[] { Constants.STOP, Constants.STOP, "1", "true" },
                                 new String[] { "EDGE", "EDGE", "1", "true" } };

            if (compareSameSpec)
            {
                diffParameters.distanceThresholdVectors =
                    new String[][]
                {
                    new String[] { "C!", "C!", "1", "0" },
                    new String[] { "C?", "C?", "1", "0" },

                    new String[] { "?[]", "?[]", "1", "0", "2", "0" },

                    new String[] { "if", "if", "1", "0" },
                    new String[] { "ifa", "ifa", "1", "0" },
                    new String[] { "GuardProcess", "GuardProcess", "1", "0" },

                    new String[] { "DataOpPrefix", "DataOpPrefix", "1", "0", "2", "0", "3", "0" },  // hamming distance threshold=0 means only same-label tree nodes can be paired-up

                    new String[] { "DefRef", "DefRef", "2", "0" },
                    new String[] { "EventPrefix", "EventPrefix", "2", "0" }
                };
            }
            else
            {
                diffParameters.distanceThresholdVectors =
                    new String[][]
                {
                    new String[] { "C!", "C!", "1", "0" },
                    new String[] { "C?", "C?", "1", "0" },

                    new String[] { "?[]", "?[]", "2", "0" },

                    new String[] { "DataOpPrefix", "DataOpPrefix", "3", "0" },   // hamming distance threshold=0 means only same-label tree nodes can be paired-up

                    new String[] { "DefRef", "DefRef", "2", "0" },
                    new String[] { "EventPrefix", "EventPrefix", "2", "0" }
                };
            }

            diffParameters.epsilonEdgesExcluded = new String[0][];

            // GenericDiff execution control parameters
            diffParameters.maxIteration = 100;
            diffParameters.noPairupIdenticalNodesWithOthers = false; // value no longer checked in GenericDiff; it is defined for each type and checked insider GraphNode
            diffParameters.stepsOfNeighbors          = 1;
            diffParameters.stopGreedySearchThreshold = 0.8;
            diffParameters.stopPropagationThreshold  = 0.00001;
            diffParameters.removeOutliersThreshold   = 2;
            diffParameters.considerNodeDistance      = true;
            diffParameters.considerEdgeDistance      = false;
            diffParameters.includeUnmatched          = true;
            diffParameters.includeNeighbors          = false;
            diffParameters.conductCandidatesSearch   = true;
            diffParameters.appendEpsilonPairups      = false;
            diffParameters.doGreedySearch            = false;
            diffParameters.compareAdditionalInfo     = false;
            diffParameters.notMaximalBipartiteMatch  = true;

            // Strategy objects
            diffParameters.searchPotentialCandidatesKind    = CandidatesSearchStrategyKind.Sequential;
            diffParameters.neighborhoodMatchingStrategyKind = SelectionStrategyKind.StableMarriage;
            diffParameters.removeOutliersStrtegyKind        = RemoveOutliersStrategyKind.None;
            diffParameters.matchingStrategyKind             = SelectionStrategyKind.StableMarriage;

            // Domain knowledge that controls the parsing and graph creation process
            String[][] simpleNodeInfoTemplates =
                new String[][] {
                new String[] { "" }                  // number of outgoing branches
            };

            double[][] simpleNodeInfoNone =
                new double[][] {
                new double[] { 0 }
            };

            String[][] simpleNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" }
            };

            String[][] channelInOutNodeInfoTemplates =
                new String[][] {
                new String[] { "" },                 // number of outgoing branches
                new String[] { "" }                  // node label index
            };

            double[][] channelInOutNodeInfoNone =
                new double[][] {
                new double[] { 0 },
                new double[] { 0 }
            };

            String[][] channelInOutNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" },
                new String[] { "Hamming", "vector" }
            };

            String[][] channelInGuardedNodeInfoTemplates =
                new String[][] {
                new String[] { "" },              // number of outgoing branches
                new String[0],                    // char arrray of guard condition
                new String[] { "" }               // node label index
            };

            double[][] channelInGuardedNodeInfoNone =
                new double[][] {
                new double[] { 0 },
                new double[0],
                new double[] { 0 }
            };

            String[][] channelInGuardedNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" },
                new String[] { "SeqLCS", "set" },
                new String[] { "Hamming", "vector" }
            };

            String[][] conditionalChoiceNodeInfoTemplates =
                new String[][] {
                new String[] { "" },              // number of outgoing branches
                new String[0],                    // char arrray of guard condition
            };

            double[][] conditionalChoiceNodeInfoNone =
                new double[][] {
                new double[] { 0 },
                new double[0],
            };

            String[][] conditionalChoiceNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" },
                new String[] { "SeqLCS", "set" },
            };

            String[][] dataOpNodeInfoTemplates =
                new String[][] {
                new String[] { "" },              // number of outgoing branches
                new String[0],                    // event args such as get.0.1
                new String[0],                    // char array for AssignmentExpr
                new String[] { "" }               // node label index
            };

            double[][] dataOpNodeInfoNone =
                new double[][] {
                new double[] { 0 },
                new double[0],
                new double[0],
                new double[] { 0 }
            };

            String[][] dataOpNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" },
                new String[] { "SeqHamming", "set" },
                new String[] { "SeqLCS", "set" },
                new String[] { "Hamming", "vector" }
            };

            String[][] defRefNodeInfoTemplates =
                new String[][] {
                new String[] { "" },              // number of outgoing branches
                new String[0],                    // additional args such as get.0.1
                new String[] { "" }               // node label index
            };

            double[][] defRefNodeInfoNone =
                new double[][] {
                new double[] { 0 },
                new double[0],
                new double[] { 0 }
            };

            String[][] defRefNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" },
                new String[] { "SeqHamming", "set" },
                new String[] { "Hamming", "vector" }
            };

            String[][] hidingNodeInfoTemplates =
                new String[][] {
                new String[] { "" },              // number of outgoing branches
                new String[0],                    // additional args such as get.0.1
            };

            double[][] hidingNodeInfoNone =
                new double[][] {
                new double[] { 0 },
                new double[0],
            };

            String[][] hidingNodeInfoCalculatorKind =
                new String[][] {
                new String[] { "Taxi", "vector" },
                new String[] { "SetJaccard", "set" },
            };

            String[][] edgeInfoTemplates = new String[][] { };

            double[][] edgeInfoNone = new double[][] {};

            String[][] edgeInfoCalculatorKind = new String[][] {};

            graphDataConfigs = new DictionaryJ <String, GraphDataConfiguration>();

            GraphDataConfiguration simpleNodeConfig = GraphDataConfiguration.create(simpleNodeInfoTemplates, simpleNodeInfoNone, simpleNodeInfoCalculatorKind, null);

            graphDataConfigs.Add(Constants.ATOMIC_STARTED, simpleNodeConfig);
            graphDataConfigs.Add(Constants.CASE, simpleNodeConfig);
            graphDataConfigs.Add(Constants.GENERAL_CHOICE, simpleNodeConfig);
            graphDataConfigs.Add(Constants.EXTERNAL_CHOICE, simpleNodeConfig);
            graphDataConfigs.Add(Constants.INTERLEAVE, simpleNodeConfig);
            graphDataConfigs.Add(Constants.INTERLEAVE + "a", simpleNodeConfig);
            graphDataConfigs.Add(Constants.INTERNAL_CHOICE, simpleNodeConfig);
            graphDataConfigs.Add(Constants.PARALLEL, simpleNodeConfig);
            graphDataConfigs.Add(Constants.INTERRUPT, simpleNodeConfig);
            graphDataConfigs.Add(Constants.SEQUENTIAL, simpleNodeConfig);
            graphDataConfigs.Add(Constants.SKIP, simpleNodeConfig);
            graphDataConfigs.Add(Constants.STOP, simpleNodeConfig);

            GraphDataConfiguration channelInOutNodeConfig = GraphDataConfiguration.create(channelInOutNodeInfoTemplates, channelInOutNodeInfoNone, channelInOutNodeInfoCalculatorKind, null);

            graphDataConfigs.Add("C?", channelInOutNodeConfig);
            graphDataConfigs.Add("C!", channelInOutNodeConfig);

            GraphDataConfiguration channelInGuardedNodeConfig = GraphDataConfiguration.create(channelInGuardedNodeInfoTemplates, channelInGuardedNodeInfoNone, channelInGuardedNodeInfoCalculatorKind, null);

            graphDataConfigs.Add("?[]", channelInGuardedNodeConfig);

            GraphDataConfiguration conditionalChoiceNodeConfig = GraphDataConfiguration.create(conditionalChoiceNodeInfoTemplates, conditionalChoiceNodeInfoNone, conditionalChoiceNodeInfoCalculatorKind, null);

            graphDataConfigs.Add("if", conditionalChoiceNodeConfig);
            graphDataConfigs.Add("ifa", conditionalChoiceNodeConfig);
            graphDataConfigs.Add("GuardProcess", conditionalChoiceNodeConfig);

            GraphDataConfiguration dataOpNodeConfig = GraphDataConfiguration.create(dataOpNodeInfoTemplates, dataOpNodeInfoNone, dataOpNodeInfoCalculatorKind, null);

            graphDataConfigs.Add("DataOpPrefix", dataOpNodeConfig);

            GraphDataConfiguration defRefNodeConfig = GraphDataConfiguration.create(defRefNodeInfoTemplates, defRefNodeInfoNone, defRefNodeInfoCalculatorKind, null);

            graphDataConfigs.Add("DefRef", defRefNodeConfig);
            graphDataConfigs.Add("EventPrefix", defRefNodeConfig);

            GraphDataConfiguration hidingNodeConfig = GraphDataConfiguration.create(hidingNodeInfoTemplates, hidingNodeInfoNone, hidingNodeInfoCalculatorKind, null);

            graphDataConfigs.Add(Constants.HIDING, hidingNodeConfig);

            GraphDataConfiguration edgeConfig = GraphDataConfiguration.create(edgeInfoTemplates, edgeInfoNone, edgeInfoCalculatorKind, null);

            graphDataConfigs.Add("EDGE", edgeConfig);
        }
示例#8
0
        protected Graph createGraph(Side side, Parser parser, DictionaryJ <String, GraphDataConfiguration> graphDataConfigs, String graphName)
        {
            Graph graph = new Graph(graphName);

            List <String[]>         nodesData = new List <String[]>();
            List <String[]>         edgesData = new List <String[]>();
            List <List <double[]> > nodesInfo = new List <List <double[]> >();
            List <List <double[]> > edgesInfo = new List <List <double[]> >();

            parser.parse(nodesData, edgesData, nodesInfo, edgesInfo, graphDataConfigs);

            if (nodesData.Count != nodesInfo.Count)
            {
                throw new IncomparableException(nodesData.Count, nodesInfo.Count);
            }

            if (edgesData.Count != edgesInfo.Count)
            {
                throw new IncomparableException(edgesData.Count, edgesInfo.Count);
            }

            DictionaryJ <String, GraphNode> nodes = new DictionaryJ <String, GraphNode>();

            for (int nodeIndex = 0; nodeIndex < nodesData.Count; nodeIndex++)
            {
                String[]  nodeData = nodesData[nodeIndex];
                String    label    = nodeData[2] != null ? nodeData[2] : nodeData[1];
                GraphNode node;
                if (graphCreationParameters.createQualifiedGraphNode)
                {
                    node = new QualifiedGraphNode(label, nodeData[0], side, diffParameters.noPairupIdenticalNodesWithOthers);
                }
                else
                {
                    node = new ConcreteGraphNode(label, nodeData[0], side, diffParameters.noPairupIdenticalNodesWithOthers);
                }
                ((AbstractGraphElement)node).setAdditionalInfo(nodeData[3]);

                List <double[]>        nodeInfos  = nodesInfo[nodeIndex];
                GraphDataConfiguration nodeConfig = graphDataConfigs.get(nodeData[0]);
                if (nodeInfos.Count != nodeConfig.elementInfoTemplates.Length)
                {
                    throw new IncomparableException(nodeInfos.Count, nodeConfig.elementInfoTemplates.Length);
                }

                if (nodeInfos.Count > 0)
                {
                    InfoDescriptor[] descriptors = new InfoDescriptor[nodeInfos.Count];
                    for (int infoIndex = 0; infoIndex < nodeInfos.Count; infoIndex++)
                    {
                        double[] characteristicVector         = nodeInfos[infoIndex];
                        DistanceCalculatorKind calculatorkind = (DistanceCalculatorKind)Enum.Parse(typeof(DistanceCalculatorKind), nodeConfig.elementInfoCalculatorKind[infoIndex][0]);
                        if (nodeConfig.elementInfoCalculatorKind[infoIndex][1].Equals("vector"))  // VectorBasedLeafInfoDescriptor
                        {
                            double[] noneVector = nodeConfig.elementInfoNone[infoIndex];
                            if (characteristicVector.Length != noneVector.Length)
                            {
                                throw new IncomparableException(characteristicVector.Length, noneVector.Length);
                            }
                            descriptors[infoIndex] = VectorBasedLeafInfoDescriptor.create(characteristicVector, noneVector, calculatorkind);
                        }
                        else if (nodeConfig.elementInfoCalculatorKind[infoIndex][1].Equals("set"))    // SetBasedLeafInfoDescriptor
                        {
                            descriptors[infoIndex] = new SetBasedLeafInfoDescriptor(characteristicVector, calculatorkind);
                        }
                        else
                        {
                            descriptors[infoIndex] = null; // should not happen. this column is ignore.
                        }
                    }
                    ((ConcreteGraphNode)node).attachInfoDescriptor(new CompositeInfoDescriptor(descriptors));
                }

                if (graphCreationParameters.encapsulateInMatchedGraphNode)
                {
                    node = new MatchedGraphNode((ConcreteGraphNode)node, diffParameters.noPairupIdenticalNodesWithOthers);
                }

                nodes.put(nodeData[1], node);
            }

            List <GraphEdge> edges = new List <GraphEdge>(edgesData.Count);

            for (int edgeIndex = 0; edgeIndex < edgesData.Count; edgeIndex++)
            {
                String[]  edgeData = edgesData[edgeIndex];
                GraphNode source   = nodes.get(edgeData[2]);
                GraphNode target   = nodes.get(edgeData[3]);
                if (source == null || target == null)
                {
                    continue;
                }

                ConcreteGraphEdge edge = new ConcreteGraphEdge(edgeData[1], edgeData[0], source, target);
                edge.setAdditionalInfo(edgeData[4]);

                List <double[]>        edgeInfos  = edgesInfo[edgeIndex];
                GraphDataConfiguration edgeConfig = graphDataConfigs.get(edgeData[0]);
                if (edgeInfos.Count != edgeConfig.elementInfoTemplates.Length)
                {
                    throw new IncomparableException(edgeInfos.Count, edgeConfig.elementInfoTemplates.Length);
                }
                if (edgeInfos.Count > 0)
                {
                    InfoDescriptor[] descriptors = new InfoDescriptor[edgeInfos.Count];
                    for (int infoIndex = 0; infoIndex < edgeInfos.Count; infoIndex++)
                    {
                        double[] characteristicVector         = edgeInfos[infoIndex];
                        DistanceCalculatorKind calculatorkind = (DistanceCalculatorKind)Enum.Parse(typeof(DistanceCalculatorKind), edgeConfig.elementInfoCalculatorKind[infoIndex][0]);
                        if (edgeConfig.elementInfoCalculatorKind[infoIndex][1].Equals("vector"))  // VectorBasedLeafInfoDescriptor
                        {
                            double[] noneVector = edgeConfig.elementInfoNone[infoIndex];
                            if (characteristicVector.Length != noneVector.Length)
                            {
                                throw new IncomparableException(characteristicVector.Length, noneVector.Length);
                            }
                            descriptors[infoIndex] = VectorBasedLeafInfoDescriptor.create(characteristicVector, noneVector, calculatorkind);
                        }
                        else if (edgeConfig.elementInfoCalculatorKind[infoIndex][1].Equals("set"))
                        { // SetBasedLeafInfoDescriptor
                            descriptors[infoIndex] = new SetBasedLeafInfoDescriptor(characteristicVector, calculatorkind);
                        }
                        else     // should not happen. this InfoDescriptor column is ignored
                        {
                            descriptors[infoIndex] = null;
                        }
                    }
                    edge.attachInfoDescriptor(new CompositeInfoDescriptor(descriptors));
                }

                edges.Add(edge);

                // TODO Should find a better way
                if (graphCreationParameters.createQualifiedGraphNode && graphCreationParameters.containmentRelation.Equals(edgeData[0]))
                {
                    QualifiedGraphNode node;
                    if (graphCreationParameters.encapsulateInMatchedGraphNode)
                    {
                        node = (QualifiedGraphNode)((MatchedGraphNode)target).getNode();
                    }
                    else
                    {
                        node = (QualifiedGraphNode)target;
                    }
                    node.setParent(source);
                }
            }


            //for(Iterator<GraphNode> iter = nodes.values().iterator(); iter.hasNext();) {
            foreach (KeyValuePair <string, GraphNode> pair in nodes)
            {
                graph.addNode(pair.Value);
            }

            foreach (GraphEdge list in edges)
            {
                graph.addEdge(list);
            }


            //for(Iterator<Set<GraphNode>> iter = graph.getNodes().iterator(); iter.hasNext();) {
            foreach (HashSet <GraphNode> nodesSet in graph.getNodes())
            {
                foreach (GraphNode node in nodesSet)
                {
                    if (!node.hasBackwardEdges() && !node.hasForwardEdges())
                    {
                        //todo:liuyang
                        //nodesIter.remove();
                    }
                }


                if (nodesSet.Count == 0)
                {
                    //todo:liuyang
                    //iter.remove();
                }
            }

            return(graph);
        }