예제 #1
0
        public List Concat(List list1, List list2)
        {
            if (list1 == null && list2 == null)
            {
                return new List();
            }
            else if (list1 == null)
            {
                return (List)list2.GetClone();

            }
            else if (list2 == null)
            {
                return (List)list1.GetClone();
            }
            else
            {
                List newList = new List();
                newList.list.AddRange(new System.Collections.Generic.List<int>(list1.list));
                newList.list.AddRange(new System.Collections.Generic.List<int>(list2.list));
                return newList;

            }
        }
예제 #2
0
        public override String ToString()
        {
            if (TimerArray == null)
            {
                return "";
            }

            StringBuilder sb = new StringBuilder();
            List<int> temp = new List<int>(TimerArray);
            temp.Sort();

            for (int i = 1; i <= temp.Count; i++)
            {
                int timerId = temp[i - 1];
                int j = TimerArray.IndexOf(timerId) + 1;
                sb.AppendLine("clock" + timerId + ":[" + Matrix[0][j]*-1 + "," + (Matrix[j][0] == int.MaxValue ? Constants.INFINITE : Matrix[j][0].ToString()) + "];");
            }

            return sb.ToString();
        }
예제 #3
0
        public DBM KeepTimers(int[] activeTimer)
        {
            Contract.Requires(this.IsCanonicalForm, "Keep Timers Failure");

            List<int> idArray = new List<int>();
            List<List<int>> newMatrix = new List<List<int>>(4);

            List<int> temp = new List<int>();
            temp.Add(0);

            foreach (int timerID in activeTimer)
            {
                int timerIndex = this.TimerArray.IndexOf(timerID) + 1;
                idArray.Add(timerID);
                temp.Add(timerIndex);
            }

            foreach (int i in temp)
            {
                List<int> constantRow = new List<int>(4);
                foreach (int j in temp)
                {
                    constantRow.Add(Matrix[i][j]);
                }
                newMatrix.Add(constantRow);
            }

            return new DBM(idArray, newMatrix, true);
        }
예제 #4
0
 public DBM(List<int> idArray, List<List<int>> matrix, bool isCanonical)
 {
     TimerArray = idArray;
     Matrix = matrix;
     IsCanonicalForm = isCanonical;
 }
예제 #5
0
        /// <summary>
        /// Return the next avaiable TimerID
        /// Old timer ID can be reused if possible
        /// </summary>
        /// <returns></returns>
        public int GetNewTimerID()
        {
            if (TimerArray == null)
            {
                return 1;
            }

            int dimention = TimerArray.Count;

            if (TimedRefinementAssertion)
            {
                for (int k = 1; k <= dimention; k++)
                {
                    if (Matrix[k][0] == 0 && Matrix[0][k] == 0 && TimerArray[k - 1] != 1)
                    {
                        return TimerArray[k - 1];
                    }
                }
            }
            else
            {
                for (int k = 1; k <= dimention; k++)
                {
                    if (Matrix[k][0] == 0 && Matrix[0][k] == 0)
                    {
                        return TimerArray[k - 1];
                    }
                }
            }

            List<int> temp = new List<int>(TimerArray);
            temp.Sort();

            int timerCounter = 1;
            foreach (int i in temp)
            {
                if (i > timerCounter)
                {
                    break;
                }
                timerCounter++;
            }

            Contract.Assert(timerCounter > 0, "Get New Timer ID Failure");

            return timerCounter;
        }
예제 #6
0
        public void Conjunction(DBM myDBM)
        {
            if (myDBM.TimerArray == null)
            {
                return;
            }

            if (TimerArray == null)
            {
                Matrix = myDBM.Matrix;
                TimerArray = myDBM.TimerArray;
                IsCanonicalForm = myDBM.IsCanonicalForm;
            }
            else if (myDBM.TimerArray != null)
            {
                Contract.Assert(TimerArray.Count == myDBM.TimerArray.Count, "//Contract-12");    /* chengbin3 */
                int dimention = TimerArray.Count;
                for (int i = 0; i < dimention; i++)
                {
                    int myith = i + 1;
                    int ith = TimerArray.IndexOf(myDBM.TimerArray[i]) + 1;

                    for (int j = 0; j < dimention; j++)
                    {
                        int myjth = j + 1;
                        int jth = TimerArray.IndexOf(myDBM.TimerArray[j]) + 1;

                        if (Matrix[ith][jth] > myDBM.Matrix[myith][myjth])
                        {
                            Matrix[ith][jth] = myDBM.Matrix[myith][myjth];
                        }
                    }
                }

                for (int i = 0; i < dimention; i++)
                {
                    int myith = i + 1;
                    int ith = TimerArray.IndexOf(myDBM.TimerArray[i]) + 1;

                    if (Matrix[0][ith] > myDBM.Matrix[0][myith])
                    {
                        Matrix[0][ith] = myDBM.Matrix[0][myith];
                    }

                    if (Matrix[ith][0] > myDBM.Matrix[myith][0])
                    {
                        Matrix[ith][0] = myDBM.Matrix[myith][0];
                    }
                }

                IsCanonicalForm = false;
            }
        }
예제 #7
0
        public DBM Clone()
        {
            if (TimerArray == null)
            {
                return new DBM(Ceiling);
            }

            List<List<int>> newMatrix = new List<List<int>>();
            for (int i = 0; i < Matrix.Count; i++)
            {
                List<int> newRow = new List<int>();
                for (int j = 0; j < Matrix.Count; j++)
                {
                    newRow.Add(Matrix[i][j]);
                }
                newMatrix.Add(newRow);
            }

            return new DBM(new List<int>(this.TimerArray), newMatrix, IsCanonicalForm);
        }
예제 #8
0
        /// <summary>
        /// Add a new timer id 
        /// </summary>
        /// <param name="timerID"></param>
        public void AddTimer(int timerID)
        {
            Contract.Ensures(IsCanonicalForm, "Add Timer Failure: DBM is not in Canonical Form!");

            if (TimerArray == null)
            {
                //initialize the system
                TimerArray = new List<int>(4);
                Matrix = new List<List<int>>(4);
                List<int> constantRow = new List<int>(4);
                constantRow.Add(0);
                Matrix.Add(constantRow);
            }
            else
            {
                if (TimerArray.Contains(timerID))
                {
                    if (!this.IsCanonicalForm)
                    {
                        this.GetCanonicalForm();
                    }
                    return;
                }

                /**************************************
                //add the last column to be maxvalue
                Matrix[0].Add(0);
                for (int i = 1; i < Matrix.Count; i++)
                {
                    //Matrix[i].Add(int.MaxValue);
                    Matrix[i].Add(Matrix[i][0]);
                }
                ***************************************/
            }

            if (!this.IsCanonicalForm)
            {
                this.GetCanonicalForm();
            }

            Matrix[0].Add(0);
            for (int i = 1; i < Matrix.Count; i++)
            {
                Matrix[i].Add(Matrix[i][0]);
            }

            TimerArray.Add(timerID);

            List<int> newTimerRow = new List<int>(Matrix[0].Count);
            //the last row are all 0
            //newTimerRow.AddRange(new int[TimerArray.Count + 1]);
            for (int i = 0; i < Matrix[0].Count; i++)
            {
                newTimerRow.Add(Matrix[0][i]);
            }

            //add the last row
            Matrix.Add(newTimerRow);
        }
예제 #9
0
 public PStack(List<FrameStack> ss)
 {
     m_stacks = ss;
 }
예제 #10
0
 public PStack()
 {
     this.m_stacks = new List<FrameStack>();
 }
예제 #11
0
 /// <summary>
 /// Please implement this method to return a deep clone of the current object
 /// </summary>
 /// <returns></returns>
 public override ExpressionValue GetClone()
 {
     List<FrameStack> fsLst = new List<FrameStack>(m_stacks);
     return new PStack(fsLst);
 }
예제 #12
0
        public int[] GetSubsetByIndex(int index)
        {
            SortedList<int, bool> subset = new SortedList<int, bool>();

            int digitNumber = 0;
            while (index >= 1 && digitNumber < this.list.Count)
            {
                bool hasBit = index % 2 == 1;
                index = (int)(index / 2);
                if (hasBit)
                {
                    subset.Add(this.list.Keys[digitNumber], false);
                }
                digitNumber++;
            }

            this.list = subset;
            List<int> result = new List<int>(subset.Keys);
            return result.ToArray();
        }
예제 #13
0
 public Stack(List<int> stack)
 {
     this.stack = stack;
 }
예제 #14
0
 //default constructor
 public Stack()
 {
     this.stack = new List<int>();
 }