コード例 #1
0
ファイル: Program.cs プロジェクト: mrbiglari/automation
        public TreeNode <string> BackTrack_Chronological(UnSatCore unSATCore, Grammar grammar, TreeNode <string> currentNode, TreeNode <string> root)
        {
            currentNode.Parent.holes.Push(currentNode.Parent.holesBackTrack.Pop());
            currentNode.MakeHole();

            return(root);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: mrbiglari/automation
        public TreeNode <string> ExtractUnSATProgram(UnSatCore unSATCore, Grammar grammarGround, Context context)
        {
            var minIndex  = unSATCore.Min(x => x.index.ToInt());
            var rootCores = unSATCore.Where(x => x.index.ToInt() == minIndex).ToList();

            if (rootCores.Count(x => !x.exprInterVars.Args.First().ToString().Contains(Symbols.outputArg)) != 0)
            {
                return(null);
            }
            var result = unSATCore.GroupBy(x => x.index).Select(grp => grp.First()).OrderBy(x => x.index.ToInt()).ToList();

            var rule = grammarGround.productions.Where(x => x.component == rootCores.First().name).First();

            var rootOfUnSATCoreProgram = new TreeNode <string>();

            rootOfUnSATCoreProgram.FillHole(rule.component, rule, context, grammarGround, minIndex);

            foreach (var node in result.Skip(1))
            {
                rule = grammarGround.productions.Where(x => x.component == node.name).First();
                var temp = grammarGround.DFS(rootOfUnSATCoreProgram, x => x.index == node.index.ToInt()).Pop();
                temp.FillHole(rule.component, rule, context, grammarGround);
            }

            return(rootOfUnSATCoreProgram);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: mrbiglari/automation
        public Lemma AnalyzeConflict(UnSatCore unSATCore, List <Z3ComponentSpecs> z3ComponentsSpecs, Context context, TreeNode <string> root, Grammar grammar)
        {
            var lemma = new Lemma();

            foreach (var clause in unSATCore)
            {
                //var rule = programRoot.GetAtIndex(Int32.Parse(clause.index)).rule;
                var rule = grammar.DFS(root, (x) => x.index == Int32.Parse(clause.index)).Pop().rule;
                var componentsToCheck = grammar.productions.Where(x => x.leftHandSide == rule.leftHandSide)
                                        .Select(x => x.rightHandSide.First()).ToList();

                var lemmaClause = new LemmaClause();

                lemmaClause.Add(context.MkNot(clause.expression));

                if (clause.spec != null && z3ComponentsSpecs.Any(x => x.key == clause.name && x.type != ComponentType.Parameter))
                {
                    foreach (var component in componentsToCheck)
                    {
                        var componentSpec = z3ComponentsSpecs.Where(x => x.key == component).FirstOrDefault();
                        if (componentSpec != null)
                        {
                            var z3ComponentSpec = context.MkAnd(ComponentSpecsBuilder.GetComponentSpec(componentSpec));

                            var check         = context.MkNot(context.MkImplies(z3ComponentSpec, clause.spec));
                            var lightEncoding = unSATCore.Where(x => x != clause);
                            if (SMTSolver.CheckIfUnSAT(context, check))
                            {
                                lemmaClause.Add(context.MkNot(context.MkBoolConst($"C_{clause.index}_{component}")));
                            }
                        }
                    }
                }
                //lemma.lemmaLength = unSATCores.SelectMany(x => x).Max(x => x.index).ToInt();
                lemma.Add(lemmaClause);
            }
            return(lemma);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: mrbiglari/automation
        public TreeNode <string> BackTrack_Non_Chronological(UnSatCore unSATCore, Grammar grammar, TreeNode <string> currentNode, TreeNode <string> root)
        {
            int index = 0;

            while (unSATCore.First().index.ToInt() != currentNode.index)
            {
                if (!grammar.RuleResultsInLeaf(grammar, currentNode.rule))
                {
                    grammar.productions.Add(currentNode.rule);
                }
                currentNode = currentNode.Parent;
            }

            if (currentNode.Parent != null)
            {
                if (!grammar.RuleResultsInLeaf(grammar, currentNode.rule))
                {
                    grammar.productions.Add(currentNode.rule);
                }
                index       = currentNode.Parent.Children.IndexOf(currentNode);
                currentNode = currentNode.Parent;

                //currentNode.holes.Push(grammar.productions.Where(x => x.component == currentNode.Children[index].Data).First().leftHandSide);
                currentNode.holes.Push(currentNode.holesBackTrack.Pop());
                currentNode.Children[index].MakeHole();
            }
            else
            {
                if (!grammar.RuleResultsInLeaf(grammar, currentNode.rule))
                {
                    grammar.productions.Add(currentNode.rule);
                }
                root        = new TreeNode <string>();
                currentNode = root;
            }

            return(root);
        }