当前位置: 首页>>代码示例>>C#>>正文


C# CharSetSolver.MkOr方法代码示例

本文整理汇总了C#中CharSetSolver.MkOr方法的典型用法代码示例。如果您正苦于以下问题:C# CharSetSolver.MkOr方法的具体用法?C# CharSetSolver.MkOr怎么用?C# CharSetSolver.MkOr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CharSetSolver的用法示例。


在下文中一共展示了CharSetSolver.MkOr方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadFromRanges

        /// <summary>
        /// Each transition has the form int[]{fromState, intervalStart, intervalEnd, toState}.
        /// If intervalStart = intervalEnd = -1 then this is an epsilon move.
        /// </summary>
        public static Automaton<BDD> ReadFromRanges(CharSetSolver solver, int initialState, int[] finalStates, IEnumerable<int[]> transitions)
        {
            var moves = new Dictionary<Pair<int, int>, BDD>();
            var allmoves = new List<Move<BDD>>();
            int[] finals = finalStates;
            foreach (var elems in transitions)
            {
                var key = new Pair<int, int>(elems[0], elems[3]);
                if (elems[1] == -1)
                    allmoves.Add(Move<BDD>.Epsilon(elems[0], elems[3]));
                else
                {
                    var pred = solver.MkCharSetFromRange((char)elems[1], (char)elems[2]);
                    if (moves.ContainsKey(key))
                        moves[key] = solver.MkOr(moves[key], pred);
                    else
                        moves[key] = pred;
                }
            }
            foreach (var kv in moves)
                allmoves.Add(Move<BDD>.Create(kv.Key.First, kv.Key.Second, kv.Value));

            var aut = Automaton<BDD>.Create(solver, initialState, finals, allmoves);
            return aut;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:29,代码来源:RegexToRangeAutomatonSerializer.cs

示例2: Read

        public static Automaton<BDD> Read(CharSetSolver solver, string file)
        {
            var lines = System.IO.File.ReadAllLines(file);
            int initialState = int.Parse(lines[0]);
            var moves = new Dictionary<Pair<int, int>,BDD>();
            var allmoves = new List<Move<BDD>>();
            int[] finals = Array.ConvertAll(lines[1].TrimEnd(' ').Split(' '), s => int.Parse(s));
            for (int i = 2; i < lines.Length; i++)
            {
                int[] elems = Array.ConvertAll(lines[i].TrimEnd(' ').Split(' '), s => int.Parse(s));
                var key = new Pair<int, int>(elems[0], elems[3]);
                if (elems[1] == -1)
                    allmoves.Add(Move<BDD>.Epsilon(elems[0],elems[3]));
                else
                {
                    var pred = solver.MkCharSetFromRange((char)elems[1], (char)elems[2]);
                    if (moves.ContainsKey(key))
                        moves[key] = solver.MkOr(moves[key], pred);
                    else
                        moves[key] = pred;
                }
            }
            foreach (var kv in moves)
                allmoves.Add(Move<BDD>.Create(kv.Key.First, kv.Key.Second, kv.Value));

            var aut = Automaton<BDD>.Create(solver, initialState, finals, allmoves);
            return aut;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:28,代码来源:RegexToRangeAutomatonSerializer.cs

示例3: getDFA

        public Automaton<BDD> getDFA(HashSet<char> alphabet, CharSetSolver solver)
        {            
            //Predicate representing the alphabet
            var alphPred = solver.False;
            foreach (var ch in alphabet)
                alphPred = solver.MkOr(solver.MkCharConstraint(false, ch), alphPred);
            
            var dfa1 =  this.Normalize(solver).PushQuantifiers().getDFA(new List<string>(), alphPred, solver);

            var moves = new List<Move<BDD>>();
            foreach (var move in dfa1.GetMoves())
                foreach (var ch in solver.GenerateAllCharacters(solver.MkAnd(move.Label,alphPred),false))                
                    moves.Add(new Move<BDD>(move.SourceState,move.TargetState,solver.MkCharConstraint(false,ch)));

            return Automaton<BDD>.Create(dfa1.InitialState,dfa1.GetFinalStates(),moves,true,true).Determinize(solver).Minimize(solver);
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:16,代码来源:WS1S.cs

示例4: ChooseTest2

        public void ChooseTest2()
        {
            CharSetSolver solver = new CharSetSolver(BitWidth.BV16);

            BDD set1 = solver.MkRangeConstraint('a', 'a', true);
            string set1str = solver.PrettyPrint(set1);
            BDD set2 = solver.MkRangeConstraint('a', 'a');
            string set2str = solver.PrettyPrint(set2);
            BDD set3 = solver.MkRangeConstraint('A', 'A');
            string set3str = solver.PrettyPrint(set3);

            BDD set1a = solver.MkOr(set2, set3);

            Assert.AreEqual<string>("[Aa]", set1str);
            Assert.AreEqual<string>("a", set2str);
            Assert.AreEqual<string>("A", set3str);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:17,代码来源:CharSetSolverTests.cs

示例5: ChooseTest

        public void ChooseTest()
        {
            for (int i = 0; i < 10; i++)
            {
                CharSetSolver solver = new CharSetSolver(BitWidth.BV16);

                BDD set1 = solver.MkRangeConstraint('a', 'c', true);
                string set1str = solver.PrettyPrint(set1);
                BDD set2 = solver.MkRangeConstraint('a', 'c');
                string set2str = solver.PrettyPrint(set2);
                BDD set3 = solver.MkRangeConstraint( 'A', 'C');
                string set3str = solver.PrettyPrint(set3);

                BDD set1a = solver.MkOr(set2, set3);

                Assert.AreEqual<string>("[A-Ca-c]",set1str);
                Assert.AreEqual<string>("[a-c]", set2str);
                Assert.AreEqual<string>("[A-C]", set3str);

                int h1 = set1.GetHashCode();
                int h2 = set1a.GetHashCode();
                bool same = (h1 == h2);
                Assert.AreSame(set1, set1a);
                Assert.IsTrue(same);
                Assert.IsTrue(solver.AreEquivalent(set1, set1a));

                //int seed = solver.Chooser.RandomSeed;
                char choice1 = (char)solver.Choose(set1);
                char choice2 = (char)solver.Choose(set1);
                char choice3 = (char)solver.Choose(set1);
                char choice4 = (char)solver.Choose(set1);

                //solver.Chooser.RandomSeed = seed;
                //char choice1a = solver.Choose(set1a);
                //char choice2a = solver.Choose(set1a);
                //char choice3a = solver.Choose(set1a);
                //char choice4a = solver.Choose(set1a);

                //string s = new String(new char[] { choice1, choice2, choice3, choice4 });
                //string sa = new String(new char[] { choice1a, choice2a, choice3a, choice4a });

                //Assert.AreEqual<string>(s, sa);
            }
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:44,代码来源:CharSetSolverTests.cs

示例6: TestRanges3

        public void TestRanges3()
        {
            CharSetSolver solver = new CharSetSolver(BitWidth.BV16);
            BDD cond = solver.MkCharSetFromRegexCharClass(@"\d");
            int cnt = cond.CountNodes();
            Pair<uint, uint>[] ranges = solver.ToRanges(cond);
            BDD set = solver.MkCharSetFromRanges(ranges);
            int nodes = set.CountNodes();
            var ranges2 = new List<Pair<uint, uint>>(ranges);
            ranges2.Reverse();
            BDD set2 = solver.MkCharSetFromRanges(ranges2);
            int nodes2 = set.CountNodes();
            var ranges3 = solver.ToRanges(set2);
            BDD set3 = solver.MkCharSetFromRanges(ranges3);

            int cnt2 = set2.CountNodes();
            int cnt3 = set3.CountNodes();
            Assert.IsTrue(set2 == set3);

            Assert.AreEqual<int>(nodes, nodes2);
            Assert.AreSame(set,set2);

            set.ToDot("digits.dot");

            //check equivalence
            bool equiv = solver.MkOr(solver.MkAnd(cond, solver.MkNot(set)), solver.MkAnd(set, solver.MkNot(cond))) == solver.False;

            Assert.AreEqual<int>(31, ranges.Length);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:29,代码来源:CharSetTests.cs

示例7: WriteRangeFields

        private static void WriteRangeFields(BitWidth encoding, StreamWriter sw, string field)
        {
            int bits = (int)encoding;
            int maxChar = (1 << bits) - 1;
            var catMap = new Dictionary<UnicodeCategory, Ranges>();
            for (int c = 0; c < 30; c++)
                catMap[(UnicodeCategory)c] = new Ranges();
            Ranges whitespace = new Ranges();
            Ranges wordcharacter = new Ranges();
            for (int i = 0; i <= maxChar; i++)
            {
                char ch = (char)i;
                if (char.IsWhiteSpace(ch))
                    whitespace.Add(i);
                UnicodeCategory cat = char.GetUnicodeCategory(ch);
                catMap[cat].Add(i);
                int catCode = (int)cat;
                //in .NET 3.5
                if (bits == 7)
                    if (catCode == 0 || catCode == 1 || catCode == 2 || catCode == 3 || catCode == 4 || catCode == 5 || catCode == 8 || catCode == 18)
                        wordcharacter.Add(i);
            }
            //generate bdd reprs for each of the category ranges
            BDD[] catBDDs = new BDD[30];
            CharSetSolver bddb = new CharSetSolver(encoding);
            for (int c = 0; c < 30; c++)
                catBDDs[c] = bddb.MkBddForIntRanges(catMap[(UnicodeCategory)c].ranges);

            BDD whitespaceBdd = bddb.MkBddForIntRanges(whitespace.ranges);

            //in .NET 3.5 category 5 was NOT a word character
            //union of categories 0,1,2,3,4,8,18
            BDD wordCharBdd = bddb.MkOr(catBDDs[0],
                              bddb.MkOr(catBDDs[1],
                              bddb.MkOr(catBDDs[2],
                              bddb.MkOr(catBDDs[3],
                              bddb.MkOr(catBDDs[4],
                              bddb.MkOr(catBDDs[5],
                              bddb.MkOr(catBDDs[8], catBDDs[18])))))));
            if (bits == 7)
            {
                sw.WriteLine(@"/// <summary>
            /// Array of 30 UnicodeCategory ranges. Each entry is a pair of integers.
            /// corresponding to the lower and upper bounds of the unicodes of the characters
            /// that have the given UnicodeCategory code (between 0 and 29).
            /// </summary>");
                sw.WriteLine("public static int[][][] " + field + " = new int[][][]{");
                foreach (UnicodeCategory c in catMap.Keys)
                {
                    sw.WriteLine("//{0}({1}):", c, (int)c);
                    if (catMap[c].Count == 0)
                        sw.WriteLine("null,");
                    else
                    {
                        sw.WriteLine("new int[][]{");
                        foreach (int[] range in catMap[c].ranges)
                            sw.WriteLine("    new int[]{" + string.Format("{0},{1}", range[0], range[1]) + "},");
                        sw.WriteLine("},");
                    }
                }
                sw.WriteLine("};");
            }

            sw.WriteLine(@"/// <summary>
            /// Compact BDD encodings of the categories.
            /// </summary>");
            sw.WriteLine("public static int[][] " + field + "Bdd = new int[][]{");
            foreach (UnicodeCategory c in catMap.Keys)
            {
                sw.WriteLine("//{0}({1}):", c, (int)c);
                BDD catBdd = catBDDs[(int)c];
                if (catBdd == null || catBdd.IsEmpty)
                    sw.WriteLine("null, //false");
                else if (catBdd.IsFull)
                    sw.WriteLine("new int[]{0,0}, //true");
                else
                {
                    sw.WriteLine("new int[]{");
                    foreach (var arc in bddb.SerializeCompact(catBdd))
                        sw.WriteLine("{0},", arc);
                    sw.WriteLine("},");
                }
            }
            sw.WriteLine("};");

            if (bits == 7)
            {
                sw.WriteLine(@"/// <summary>
            /// Whitespace character ranges.
            /// </summary>");
                sw.WriteLine("public static int[][] " + field + "Whitespace = new int[][]{");
                foreach (int[] range in whitespace.ranges)
                    sw.WriteLine("    new int[]{" + string.Format("{0},{1}", range[0], range[1]) + "},");
                sw.WriteLine("};");

                sw.WriteLine(@"/// <summary>
            /// Word character ranges.
            /// </summary>");
                sw.WriteLine("public static int[][] " + field + "WordCharacter = new int[][]{");
                foreach (int[] range in wordcharacter.ranges)
//.........这里部分代码省略.........
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:101,代码来源:UnicodeCategoryRangesGenerator.cs

示例8: DensityFeedback

        public DensityFeedback(FeedbackLevel level, HashSet<char> alphabet, Automaton<BDD> dfaGoal, Automaton<BDD> dfaAttempt, double utility, CharSetSolver solver)
            : base(level, alphabet, utility,solver)
        {
            BDD pred = solver.False;
            foreach (var el in alphabet)
                pred=solver.MkOr(pred,solver.MkCharConstraint(false,el));

            var dfaAll = Automaton<BDD>.Create(0,new int[]{0},new Move<BDD>[]{new Move<BDD>(0,0,pred)});
            this.type = FeedbackType.Density;
            this.positiveDifference = dfaGoal.Minus(dfaAttempt, solver).Determinize(solver).Minimize(solver);
            this.negativeDifference = dfaAttempt.Minus(dfaGoal, solver).Determinize(solver).Minimize(solver);
            this.symmetricDifference = dfaAll.Minus(dfaAll.Minus(positiveDifference,solver).Intersect(dfaAll.Minus(negativeDifference,solver),solver),solver).Determinize(solver).Minimize(solver);                
            this.solver = solver;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:14,代码来源:DFAFeedback.cs

示例9: ChooseUnifromlyTest

        public void ChooseUnifromlyTest()
        {
            CharSetSolver solver = new CharSetSolver(BitWidth.BV16);

            BDD set1 = solver.MkRangeConstraint('\0', '\x01', true);
            BDD set2 = solver.MkRangeConstraint( '\u0FFF', '\u0FFF');
            string set2str = solver.PrettyPrint(set2);
            BDD set3 = solver.MkRangeConstraint( '\u00FF', '\u00FF');
            BDD set4 = solver.MkRangeConstraint( '\u000F', '\u000F');

            BDD set = solver.MkOr(new BDD[]{set2, set3, set4, set1});

            string setstr = solver.PrettyPrint(set);

            set.ToDot(@"foo.dot");

            var map = new Dictionary<char, int>();
            map['\0'] = 0;
            map['\x01'] = 0;
            map['\u0FFF'] = 0;
            map['\u00FF'] = 0;
            map['\u000F'] = 0;

            for (int i = 0; i < 50000; i++)
            {
                var c = solver.ChooseUniformly(set);
                map[c] += 1;
            }
            foreach (var kv in map)
                Assert.IsTrue(kv.Value > 9700);
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:31,代码来源:CharSetSolverTests.cs

示例10: BDDOf

 private static BDD BDDOf(IEnumerable<char> alphabet, CharSetSolver solver)
 {
     bool fst = true;
     BDD safeCharCond = null;
     foreach (var c in alphabet)
         if (fst)
         {
             fst = false;
             safeCharCond = solver.MkCharConstraint(false, c);
         }
         else
             safeCharCond = solver.MkOr(safeCharCond, solver.MkCharConstraint(false, c));
     return safeCharCond;
 }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:14,代码来源:NFAEditDistance.cs

示例11: NFACounterexampleFeedback

        // automata come already determinized
        public NFACounterexampleFeedback(
            FeedbackLevel level, HashSet<char> alphabet, 
            Automaton<BDD> solutionDFA, Automaton<BDD> attemptDFA, 
            CharSetSolver solver)
            : base(level, alphabet, solver)
        {
            BDD pred = solver.False;
            foreach (var el in alphabet)
                pred = solver.MkOr(pred, solver.MkCharConstraint(false, el));

            var dfaAll = Automaton<BDD>.Create(0, new int[] { 0 }, new Move<BDD>[] { new Move<BDD>(0, 0, pred) });
            this.positiveDifference = solutionDFA.Minus(attemptDFA, solver).Determinize(solver).Minimize(solver);
            this.negativeDifference = attemptDFA.Minus(solutionDFA, solver).Determinize(solver).Minimize(solver);
            this.solver = solver;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:16,代码来源:NFAFeedback.cs

示例12: computeDFA

        internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2)
        {
            int pos1 = variables.IndexOf(set1);
            int pos2 = variables.IndexOf(set2);

            Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>> dic1;
            if (!hashedDfa.ContainsKey(alphabet))
                hashedDfa[alphabet] = new Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>>();

            dic1 = hashedDfa[alphabet];

            Dictionary<Pair<int, int>, Automaton<BDD>> dic2;
            if (!dic1.ContainsKey(variables.Count))
                dic1[variables.Count] = new Dictionary<Pair<int, int>, Automaton<BDD>>();

            dic2 = dic1[variables.Count];

            var hash = new Pair<int, int>(pos1, pos2);
            if (dic2.ContainsKey(hash))
                return dic2[hash];

            //Create conditions that bit in pos1 is smaller than pos2
            var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1);
            var both1 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitTrue(pos1), solver.MkSetWithBitTrue(pos2) });
            var both0 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitFalse(pos1), solver.MkSetWithBitFalse(pos2) });
            var eqCond = solver.MkOr(new BDD[] { both0, both1 });

            //Create automaton for condition
            var moves = new Move<BDD>[] { new Move<BDD>(0, 0, eqCond) };
            var dfa = Automaton<BDD>.Create(0, new int[] { 0 }, moves).Determinize(solver).Minimize(solver);
            if(hashing)
                dic2[hash] = dfa;
            return dfa;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:34,代码来源:WS1S.cs

示例13: Normalize

 public override WS1SFormula Normalize(CharSetSolver solver)
 {
     var ln = left.Normalize(solver);
     var rn = right.Normalize(solver);
     if (ln is WS1SUnaryPred && rn is WS1SUnaryPred)
     {
         var cln = ln as WS1SUnaryPred;
         var crn = rn as WS1SUnaryPred;
         if (cln.set == crn.set)
             return new WS1SUnaryPred(cln.set, solver.MkOr(cln.pred, crn.pred));
     }
     else{
         if (ln is WS1STrue || rn is WS1STrue)
             return ln;
         if (ln is WS1SFalse)
             return rn;
         if (rn is WS1SFalse)
             return ln;
     }
     return new WS1SOr(ln, rn);
 }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:21,代码来源:WS1S.cs

示例14: normalizeMoves

        /// <summary>
        /// Returns an automaton where transitions between states are collapsed to a single one
        /// </summary>
        /// <param name="automaton"></param>
        /// <param name="solver"></param>
        /// <returns></returns>
        public static Automaton<BDD> normalizeMoves(Automaton<BDD> automaton, CharSetSolver solver)
        {
            List<Move<BDD>> normMoves = new List<Move<BDD>>();
            foreach (var sourceState in automaton.States)
            {
                Dictionary<int, BDD> moveConditions = new Dictionary<int, BDD>();
                foreach (var moveFromSourceState in automaton.GetMovesFrom(sourceState))
                {
                    var target = moveFromSourceState.TargetState;
                    BDD oldCondition = null;
                    if (moveConditions.ContainsKey(target))                    
                        oldCondition = moveConditions[target];                    
                    else
                        oldCondition = solver.False;

                    if (!moveFromSourceState.IsEpsilon)
                        moveConditions[target] = solver.MkOr(oldCondition, moveFromSourceState.Label);
                    else
                        normMoves.Add(moveFromSourceState);
                }

                foreach (var targetState in moveConditions.Keys)             
                    normMoves.Add(new Move<BDD>(sourceState,targetState,moveConditions[targetState]));                
            }

            return Automaton<BDD>.Create(automaton.InitialState, automaton.GetFinalStates(), normMoves);
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:33,代码来源:NFAUtilities.cs


注:本文中的CharSetSolver.MkOr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。