예제 #1
0
        /*
        public void RecordCounterExamples2File(Tuple<List<Tuple<string, List<Model.Element>>>, List<Tuple<string, List<Model.Element>>>> cex)
        {
            List<Tuple<string, List<Model.Element>>> lhs = cex.Item1;
            List<Tuple<string, List<Model.Element>>> rhs = cex.Item2;

            string ret = "";
            
            if (lhs.Count == 0)
            {
                Debug.Assert(rhs.Count == 1);
                ret += ParseListOfModel(rhs.ElementAt(0).Item2);
                ret += ";accept";
            }
            else if (rhs.Count == 0)
            {
                Debug.Assert(lhs.Count == 1);
                ret += ParseListOfModel(lhs.ElementAt(0).Item2);
                ret += ";reject";
            }
            else
            {
                Debug.Assert(lhs.Count == 1);
                Debug.Assert(rhs.Count == 1);
                ret += ParseListOfModel(lhs.ElementAt(0).Item2);
                ret += ";antecedent\n";
                ret += ParseListOfModel(rhs.ElementAt(0).Item2);
                ret += ";consequent";
            }
            if (!System.IO.File.Exists("samples.txt"))
            {
                // Create a file to write to. 
                using (System.IO.StreamWriter sw = System.IO.File.CreateText("samples.txt"))
                {
                    sw.WriteLine("// x y -- empty line");                    
                }
            }

            // This text is always added, making the file longer over time 
            // if it is not deleted. 
            using (System.IO.StreamWriter sw = System.IO.File.AppendText("samples.txt"))
            {                
                sw.WriteLine(ret);
            }
            return;
        }
         * */

#if C5                
        public void RecordCexForC5(Tuple<List<Tuple<string, List<Model.Element>>>, List<Tuple<string, List<Model.Element>>>> cex, 
                                                                                    bool recordImplications = true)
        {
            List<Tuple<string, List<Model.Element>>> lhs = cex.Item1;
            List<Tuple<string, List<Model.Element>>> rhs = cex.Item2;

            if (lhs.Count == 0)
            {
                Debug.Assert(rhs.Count == 1);
                
                dataPoint argsval = new dataPoint(rhs.ElementAt(0).Item1, rhs.ElementAt(0).Item2);                
                if (this.c5samplePointToIndex.ContainsKey(argsval))
                {
                    Debug.Assert(c5samplePointToClassAttr[argsval] != 2); // should be unknown
                    this.c5samplePointToClassAttr[argsval] = 1;
                    if (CommandLineOptions.Clo.Trace)
                    {
                        Console.WriteLine("Overwrote: " + argsval.print() + ": positive");
                    }
                }
                else
                {
                    c5samplePointToIndex[argsval] = c5DataPointsIndex;
                    c5DataPointsIndex++;
                    c5samplePointToClassAttr[argsval] = 1;
                    if (CommandLineOptions.Clo.Trace)
                    {
                        Console.WriteLine("Added: " + argsval.print() + ": positive");
                    }
                }
            }
            else if (rhs.Count == 0)
            {
                if(lhs.Count > 1)
                {
                    List<Tuple<string, List<Model.Element>>> newlhs = new List<Tuple<string, List<Model.Element>>>();
                    newlhs.Add(lhs.ElementAt(lhs.Count - 1));
                    lhs = newlhs;
                }
                Debug.Assert(lhs.Count == 1);
                
                dataPoint argsval = new dataPoint(lhs.ElementAt(0).Item1, lhs.ElementAt(0).Item2);
                if (c5samplePointToIndex.ContainsKey(argsval))
                {
                    Debug.Assert(c5samplePointToClassAttr[argsval] != 1); // should be unknown
                    c5samplePointToClassAttr[argsval] = 2;
                    if (CommandLineOptions.Clo.Trace)
                    {
                        Console.WriteLine("Overwrote: " + argsval.print() + ": negative");
                    }
                }
                else
                {
                    c5samplePointToIndex[argsval] = c5DataPointsIndex;
                    c5DataPointsIndex++;
                    c5samplePointToClassAttr[argsval] = 2;
                    if (CommandLineOptions.Clo.Trace)
                    {
                        Console.WriteLine("Added: " + argsval.print() + ": negative");
                    }
                }
            }
            else
            {
                if (lhs.Count > 1)
                {
                    List<Tuple<string, List<Model.Element>>> newlhs = new List<Tuple<string, List<Model.Element>>>();
                    newlhs.Add(lhs.ElementAt(lhs.Count - 1));
                    lhs = newlhs;
                }
                Debug.Assert(lhs.Count == 1);
                Debug.Assert(rhs.Count == 1);
                
                int antecedent, consequent;

                dataPoint argsval1 = new dataPoint(lhs.ElementAt(0).Item1, lhs.ElementAt(0).Item2);
                dataPoint argsval2 = new dataPoint(rhs.ElementAt(0).Item1, rhs.ElementAt(0).Item2);

                if (c5samplePointToIndex.ContainsKey(argsval1))
                {
                    //Debug.Assert(C5samplePointToClassAttr[argsval1] == 0); // is unknown
                    antecedent = c5samplePointToIndex[argsval1];                    
                }
                else
                {
                    c5samplePointToIndex[argsval1] = c5DataPointsIndex;
                    antecedent = c5DataPointsIndex;
                    c5DataPointsIndex++;
                    c5samplePointToClassAttr[argsval1] = 0;
                }
                if (c5samplePointToIndex.ContainsKey(argsval2))
                {
                    //Debug.Assert(C5samplePointToClassAttr[argsval2] == 0); // is unknown
                    consequent = c5samplePointToIndex[argsval2];                    
                }
                else
                {
                    c5samplePointToIndex[argsval2] = c5DataPointsIndex;
                    consequent = c5DataPointsIndex;
                    c5DataPointsIndex++;
                    c5samplePointToClassAttr[argsval2] = 0;
                }
                if (recordImplications)
                {
                    Tuple<int, int> t = new Tuple<int, int>(antecedent, consequent);
                    if (CommandLineOptions.Clo.Trace)
                    {
                        Console.WriteLine("Added implication: " + antecedent + "," + consequent);
                    }
                    c5implications.Add(t);
                }
            }
        }
예제 #2
0
        public void RecordCexForC5(Tuple<List<Tuple<string, List<Model.Element>>>, List<Tuple<string, List<Model.Element>>>> cex)
        {
            List<Tuple<string, List<Model.Element>>> lhs = cex.Item1;
            List<Tuple<string, List<Model.Element>>> rhs = cex.Item2;

            if (lhs.Count == 0)
            {
                Debug.Assert(rhs.Count == 1);
                if (C5index == 0)
                {
                    C5FunctionName = rhs.ElementAt(0).Item1;
                }
                else
                {
                    Debug.Assert(C5FunctionName == rhs.ElementAt(0).Item1);
                }

                dataPoint argsval = new dataPoint(rhs.ElementAt(0).Item2);
                if (C5samplePointToIndex.ContainsKey(argsval))
                {
                    Debug.Assert(C5samplePointToClassAttr[argsval] != 2); // should be unknown
                    C5samplePointToClassAttr[argsval] = 1;
                    C5repeatedPoints++;
                }
                else
                {
                    C5samplePointToIndex[argsval] = C5index;
                    C5index++;
                    C5samplePointToClassAttr[argsval] = 1;
                }
            }
            else if (rhs.Count == 0)
            {
                Debug.Assert(lhs.Count == 1);
                if (C5index == 0)
                {
                    C5FunctionName = lhs.ElementAt(0).Item1;
                }
                else
                {
                    Debug.Assert(C5FunctionName == lhs.ElementAt(0).Item1);
                }

                dataPoint argsval = new dataPoint(lhs.ElementAt(0).Item2);
                if (C5samplePointToIndex.ContainsKey(argsval))
                {
                    Debug.Assert(C5samplePointToClassAttr[argsval] != 1); // should be unknown
                    C5samplePointToClassAttr[argsval] = 2;
                    C5repeatedPoints++;
                }
                else
                {
                    C5samplePointToIndex[argsval] = C5index;
                    C5index++;
                    C5samplePointToClassAttr[argsval] = 2;
                }
            }
            else
            {
                Debug.Assert(lhs.Count == 1);
                Debug.Assert(rhs.Count == 1);
                if (C5index == 0)
                {
                    C5FunctionName = rhs.ElementAt(0).Item1;
                }
                else
                {
                    Debug.Assert(C5FunctionName == rhs.ElementAt(0).Item1);
                }
                int antecedent, consequent;

                dataPoint argsval1 = new dataPoint(lhs.ElementAt(0).Item2);
                dataPoint argsval2 = new dataPoint(rhs.ElementAt(0).Item2);

                if (C5samplePointToIndex.ContainsKey(argsval1))
                {
                    //Debug.Assert(C5samplePointToClassAttr[argsval1] == 0); // is unknown
                    antecedent = C5samplePointToIndex[argsval1];
                    C5repeatedPoints++;
                }
                else
                {
                    C5samplePointToIndex[argsval1] = C5index;
                    antecedent = C5index;
                    C5index++;
                    C5samplePointToClassAttr[argsval1] = 0;
                }
                if (C5samplePointToIndex.ContainsKey(argsval2))
                {
                    //Debug.Assert(C5samplePointToClassAttr[argsval2] == 0); // is unknown
                    consequent = C5samplePointToIndex[argsval2];
                    C5repeatedPoints++;
                }
                else
                {
                    C5samplePointToIndex[argsval2] = C5index;
                    consequent = C5index;
                    C5index++;
                    C5samplePointToClassAttr[argsval2] = 0;
                }
                Tuple<int, int> t = new Tuple<int, int>(antecedent, consequent);
                C5implications.Add(t);
            }
        }
예제 #3
0
 public string outputDataPoint(dataPoint p)
 {
     string funcName = p.functionName;
     List<int> attrVals = p.value;
     string ret = funcName;
     foreach (var exFunc in existentialFunctions)
     {
         if (exFunc.Key.Equals(funcName))
         {
             foreach (var x in attrVals)
             {
                 ret += "," + x.ToString();
             }
         }
         else
         {
             foreach (var arg in exFunc.Value.InParams)
             {
                 ret += ",?";
             }
         }
     }
     return ret;
 }