Пример #1
0
        public void testLength()
        {
            SimpleList <int> tester = new SimpleList <int>();

            Assert.AreEqual(tester.Length(), 0);
            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            Assert.AreEqual(tester.Length(), 3);
        }
Пример #2
0
        public void testDeleteMiddle()
        {
            SimpleList <int> tester = new SimpleList <int>();

            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            tester.Delete(1);
            Assert.AreEqual(tester.GetHead().GetNext().GetValue(), 2);
            Assert.AreEqual(tester.Length(), 2);
        }
Пример #3
0
        public void testAppend()
        {
            SimpleList <int> tester = new SimpleList <int>();

            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            Object appended = tester.GetHead().GetNext().GetNext().GetValue();

            Assert.AreEqual(appended, 2);
        }
Пример #4
0
        public void testEmpty()
        {
            SimpleList <int> tester = new SimpleList <int>();

            Assert.True(tester.IsEmpty());
            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            Assert.False(tester.IsEmpty());
            tester.Clear();
            Assert.True(tester.IsEmpty());
        }
Пример #5
0
        public void testDeleteHead()
        {
            SimpleList <int> tester = new SimpleList <int>();

            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            tester.Delete(0);
            Assert.Null(tester.Search(0));
            Assert.NotNull(tester.GetHead());
            Object newHead = tester.GetHead().GetValue();

            Assert.AreEqual(newHead, 1);
            Assert.AreEqual(tester.Length(), 2);
        }
Пример #6
0
 internal override IEnumerable <Variable> EnumerateFreeVariables(SimpleList <Variable> bound, HashSet <Variable> free)
 {
     foreach (var x in phi.EnumerateFreeVariables(bound.Append(var), free))
     {
         yield return(x);
     }
 }
Пример #7
0
 public static void PutFileInSimpleList(SimpleList sl, string Path)
 {
     try
     {
         StreamReader myFile = new StreamReader(Path);
         int          i      = 0;
         string       line   = myFile.ReadLine();
         while (line != null)
         {
             Console.WriteLine(i);
             line = myFile.ReadLine();
             if (line != null)
             {
                 sl.Append(Convert.ToInt32(line));
             }
             i++;
         }
         myFile.Close();
     }
     catch (System.IO.FileNotFoundException)
     {
         Console.WriteLine("File wurde nicht gefunden");
     }
     catch (Exception ex)
     {
         Console.WriteLine("Unbekannter Fehler: " + ex.Message);
     }
 }
Пример #8
0
        public void testSearch()
        {
            SimpleList <int> tester = new SimpleList <int>();

            Assert.Null(tester.Search(0));
            tester.Append(0);
            tester.Append(1);
            tester.Append(2);
            Object searchedFirst = tester.Search(0).GetValue();

            Assert.AreEqual(searchedFirst, 0);
            Object searchedMiddle = tester.Search(1).GetValue();

            Assert.AreEqual(searchedMiddle, 1);
            Object searchedLast = tester.Search(2).GetValue();

            Assert.AreEqual(searchedLast, 2);
        }
Пример #9
0
        public void testAppendFirst()
        {
            SimpleList <int> tester = new SimpleList <int>();

            Assert.Null(tester.GetHead());
            tester.Append(0);
            Assert.NotNull(tester.GetHead());
            Object appended = tester.GetHead().GetValue();

            Assert.AreEqual(appended, 0);
        }
Пример #10
0
        internal override MSOFormula <T> SubstituteVariables1(Dictionary <string, Variable> subst, SimpleList <string> bound)
        {
            var psi = phi.SubstituteVariables1(subst, bound.Append(var.Name));

            if (psi == phi)
            {
                return(this);
            }
            else
            {
                return(new MSOForall <T>(var, psi));
            }
        }
Пример #11
0
        //TBD: enable singleton-set-semantics
        internal override Automaton <IMonadicPredicate <BDD, T> > GetAutomatonX(SimpleList <Variable> variables, ICartesianAlgebraBDD <T> alg, bool singletonSetSemantics)
        {
            //the existential variable will shadow any previous occurrence with the same name
            //because when looking up the index of var it will be the last occurrence
            var varIndex     = variables.Count;
            var variablesExt = variables.Append(var);
            var autPhi       = phi.GetAutomatonX(variablesExt, alg, singletonSetSemantics);
            Automaton <IMonadicPredicate <BDD, T> > autEx;

            if (this.IsFirstOrder)
            {
                if (singletonSetSemantics)
                {
                    autEx = autPhi.Intersect(BasicAutomata.MkSingleton <T>(varIndex, alg)).Minimize();
                }
                else
                {
                    autEx = autPhi.Intersect(BasicAutomata.MkIsNonempty <T>(varIndex, alg)).Minimize();
                }
            }
            else
            {
                autEx = autPhi;
            }

            //Project away the the existential variable
            var newMoves = new List <Move <IMonadicPredicate <BDD, T> > >();

            foreach (var move in autEx.GetMoves())
            {
                newMoves.Add(new Move <IMonadicPredicate <BDD, T> >(move.SourceState, move.TargetState, alg.Omit(varIndex, move.Label)));
            }

            var aut = Automaton <IMonadicPredicate <BDD, T> > .Create(alg, autEx.InitialState, autEx.GetFinalStates(), newMoves);

            var res = aut.Determinize();

            res = res.Minimize();

            return(res);
        }
Пример #12
0
        internal override Automaton <BDD> getAutomaton(SimpleList <string> variables, CharSetSolver solver)
        {
            //Automaton<BvSet> for formula
            var varCopy = variables.Append(X);
            var autPhi  = phi.getAutomaton(varCopy, solver);

            var newMoves = new List <Move <BDD> >();
            var k        = variables.Count + ((int)solver.Encoding);

            foreach (var move in autPhi.GetMoves())
            {
                var newCond = solver.OmitBit(move.Label, k);
                newMoves.Add(new Move <BDD>(move.SourceState, move.TargetState, newCond));
            }

            var res = Automaton <BDD> .Create(solver, autPhi.InitialState, autPhi.GetFinalStates(), newMoves);

            if (MINIMIZE)
            {
                res = res.Determinize(solver).Minimize(solver);
            }
            return(res);
        }
Пример #13
0
        internal override Automaton <BDD> GetAutomatonBDD(SimpleList <Variable> variables, IBDDAlgebra alg, int nrOfLabelBits)
        {
            //the existential variable will shadow any previous occurrence with the same name
            //because when looking up the index of var it will be the last occurrence
            var varIndex     = variables.Count + nrOfLabelBits;
            var variablesExt = variables.Append(var);
            var autPhi       = phi.GetAutomatonBDD(variablesExt, alg, nrOfLabelBits);

            //Project away the the existential variable
            var newMoves = new List <Move <BDD> >();

            foreach (var move in autPhi.GetMoves())
            {
                newMoves.Add(new Move <BDD>(move.SourceState, move.TargetState, alg.OmitBit(move.Label, varIndex)));
            }

            var aut = Automaton <BDD> .Create(alg, autPhi.InitialState, autPhi.GetFinalStates(), newMoves);

            var res = aut.Determinize(alg);

            res = res.Minimize(alg);

            return(res);
        }
Пример #14
0
        internal override Automaton <IMonadicPredicate <BDD, T> > getAutomaton(SimpleList <Variable> variables, ICartesianAlgebraBDD <T> alg)
        {
            //the existential variable will shadow any previous occurrence with the same name
            //because when looking up the index of var it will be the last occurrence
            var varIndex     = variables.Count;
            var variablesExt = variables.Append(var);
            var autPhi       = phi.getAutomaton(variablesExt, alg);

            //Project away the the existential variable
            var newMoves = new List <Move <IMonadicPredicate <BDD, T> > >();

            foreach (var move in autPhi.GetMoves())
            {
                var newPred = alg.Omit(varIndex, move.Label);
                newMoves.Add(new Move <IMonadicPredicate <BDD, T> >(move.SourceState, move.TargetState, newPred));
            }

            var res = Automaton <IMonadicPredicate <BDD, T> > .Create(alg, autPhi.InitialState, autPhi.GetFinalStates(), newMoves);

            //var res = res.Determinize(alg);
            var res_min = res.Minimize(alg);

            return(res_min);
        }