Пример #1
0
        /** Negation of a constraint.
         * Swap indices i,j, negate value, and toggle the strictness.
         * @param c: constraint to negate.
         * @return negated constraint.
         */
        public static DBMConstraint dbm_negConstraint(DBMConstraint c)
        {
            byte tmp = c.i;

            c.i     = c.j;
            c.j     = tmp;
            c.value = dbm_negRaw(c.value);
            return(c);
        }
Пример #2
0
        /// <summary>
        /// Update the FullDBM with a new constraint
        /// </summary>
        /// <param name="timerID">which timer the constraint is on</param>
        /// <param name="op">0 for equal; 1 for >=; -1 for <=</param>
        /// <param name="constant"></param>
        public void AddConstraint(byte timer, TimerOperationType op, int constant)
        {
            Debug.Assert(timer > 0);
            int boundt0 = DBMConstraint.dbm_raw2bound(Matrix[timer * dimention + 0]);
            int bound0t = DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + timer]);

            switch (op)
            {
            case TimerOperationType.Equals:
                if (boundt0 > constant)
                {
                    Matrix[timer * dimention + 0] = DBMConstraint.dbm_bound2raw(constant, dbm_WEAK);
                }

                if (bound0t > -1 * constant)
                {
                    Matrix[0 * dimention + timer] = DBMConstraint.dbm_bound2raw(-1 * constant, dbm_WEAK);
                }

                break;

            case TimerOperationType.GreaterThanOrEqualTo:
                if (bound0t > -1 * constant)
                {
                    Matrix[0 * dimention + timer] = DBMConstraint.dbm_bound2raw(-1 * constant, dbm_WEAK);
                }
                break;

            case TimerOperationType.LessThanOrEqualTo:
                if (boundt0 > constant)
                {
                    Matrix[timer * dimention + 0] = DBMConstraint.dbm_bound2raw(constant, dbm_WEAK);
                }
                break;

            case TimerOperationType.GreaterThan:
                if (bound0t > -1 * constant)
                {
                    Matrix[0 * dimention + timer] = DBMConstraint.dbm_bound2raw(-1 * constant, dbm_STRICT);
                    //MatrixStrictness[0 * dimention + timer] = true;
                }
                //ClockLowerValues[timer - 1] = Math.Max(constant, ClockLowerValues[timer - 1]);
                break;

            case TimerOperationType.LessThan:
                if (boundt0 > constant)
                {
                    Matrix[timer * dimention + 0] = DBMConstraint.dbm_bound2raw(constant, dbm_STRICT);
                }
                break;
            }

            IsCanonicalForm = false;
        }
Пример #3
0
        public string GetID()
        {
            if (IsEmpty)
            {
                return("");
            }

            string toReturn = "";

            for (int i = 1; i < dimention; i++)
            {
                toReturn += (DBMConstraint.dbm_rawIsStrict(Matrix[0 * dimention + i]) ? "(" : "[") + DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + i] * -1) + "," + DBMConstraint.dbm_raw2bound(Matrix[i * dimention + 0]) + (DBMConstraint.dbm_rawIsStrict(Matrix[i * dimention + 0]) ? ")" : "]");
            }

            return(toReturn);
        }
Пример #4
0
        public override String ToString()
        {
            if (IsEmpty)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 1; i < dimention; i++)
            {
                sb.AppendLine("clock" + i + (DBMConstraint.dbm_rawIsStrict(Matrix[0 * dimention + i]) ? ":(" : ":[") + (DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + i]) == int.MaxValue ? "-" + Constants.INFINITE : (Matrix[0 * dimention + i] * -1).ToString()) + "," + (Matrix[i * dimention + 0] == int.MaxValue ? Constants.INFINITE : Matrix[i * dimention + 0].ToString()) + (DBMConstraint.dbm_rawIsStrict(Matrix[i * dimention + 0]) ? ");" : "];"));
            }

            return(sb.ToString());
        }
Пример #5
0
        public String ToString(Dictionary <string, byte> clockMapping)
        {
            if (IsEmpty)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, byte> pair in clockMapping)
            {
                sb.AppendLine(pair.Key + (DBMConstraint.dbm_rawIsStrict(Matrix[0 * dimention + pair.Value]) ? ":(" : ":[") +
                              (Matrix[0 * dimention + pair.Value] == int.MaxValue ? "-" + Constants.INFINITE : (DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + pair.Value] * -1)).ToString()) +
                              "," + (Matrix[pair.Value * dimention + 0] == int.MaxValue ? Constants.INFINITE : DBMConstraint.dbm_raw2bound(Matrix[pair.Value * dimention + 0]).ToString()) +
                              (DBMConstraint.dbm_rawIsStrict(Matrix[pair.Value * dimention + 0]) ? ");" : "];"));
            }


            return(sb.ToString());
        }
Пример #6
0
 public DBMConstraint(DBMConstraint c) : this(c.i, c.j, c.value)
 {
 }
Пример #7
0
 /** Equality of constraints.
  * @param c1, c2: constraints.
  * @return TRUE if c1 == c2.
  */
 public static bool dbm_areConstraintsEqual(DBMConstraint c1, DBMConstraint c2)
 {
     return(c1.i == c2.i && c1.j == c2.j && c1.value == c2.value);
 }
Пример #8
0
        private void GetCanonicalForm()
        {
            //int dimention = Matrix.Count;
            for (int k = 0; k < dimention; k++)
            {
                for (int i = 0; i < dimention; i++)
                {
                    if (i != k)
                    {
                        for (int j = 0; j < dimention; j++)
                        {
                            //check for the overflow problem
                            if (Matrix[i * dimention + k] != dbm_LS_INFINITY && Matrix[k * dimention + j] != dbm_LS_INFINITY)
                            {
                                //Attension, Matrix[i* dimention + k] + Matrix[k* dimention + j] is bigger than int.MaxValue, there is a possbility of overflow.
                                //Matrix[i* dimention + j] = Math.Min(Matrix[i* dimention + j], Matrix[i* dimention + k] + Matrix[k* dimention + j]);

                                int dbm_ikkj = dbm_addFiniteFinite(Matrix[i * dimention + k], Matrix[k * dimention + j]);

                                if (Matrix[i * dimention + j] > dbm_ikkj)
                                {
                                    Matrix[i * dimention + j] = dbm_ikkj;
                                }

                                //if (Matrix[i * dimention + j] > Matrix[i * dimention + k] + Matrix[k * dimention + j])
                                //{
                                //    Matrix[i * dimention + j] = Matrix[i * dimention + k] + Matrix[k * dimention + j];
                                //    MatrixStrictness[i * dimention + j] = MatrixStrictness[i * dimention + k] || MatrixStrictness[k * dimention + j];
                                //}
                                //else if (Matrix[i * dimention + j] == Matrix[i * dimention + k] + Matrix[k * dimention + j])
                                //{
                                //    MatrixStrictness[i * dimention + j] = MatrixStrictness[i * dimention + j] || (MatrixStrictness[i * dimention + k] || MatrixStrictness[k * dimention + j]);
                                //}
                            }
                        }

                        if (Matrix[i * dimention + i] < dbm_LE_ZERO)
                        {
                            IsCanonicalForm           = true;
                            Matrix[0 * dimention + 0] = -1;
                            return;
                        }
                    }
                }
            }

            if (!SpecificationBase.IsSimulation && Matrix[0 * dimention + 0] >= 0)
            {
                for (int i = 0; i < dimention; i++)
                {
                    int boundi = DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + i]);
                    for (int j = 0; j < dimention; j++)
                    {
                        int boundij = DBMConstraint.dbm_raw2bound(Matrix[i * dimention + j]);
                        int boundj  = DBMConstraint.dbm_raw2bound(Matrix[0 * dimention + j]);
                        //=======================classic extrapolation======================
                        if (i > 0 && ClockMaxValues[i] > 0 && boundij > ClockMaxValues[i])
                        {
                            //Debug.Assert(Matrix[i* dimention + j] <= ClockMaxValues[i - 1]);

                            Matrix[i * dimention + j] = dbm_LS_INFINITY; // int.MaxValue;
                        }

                        if (j > 0 && ClockMaxValues[j] > 0 && -1 * boundij > ClockMaxValues[j])
                        {
                            //Debug.Assert(-1*Matrix[i* dimention + j] <= ClockMaxValues[j - 1]);

                            Matrix[i * dimention + j] = DBMConstraint.dbm_bound2raw(-1 * ClockMaxValues[j], dbm_STRICT);
                            //MatrixStrictness[i * dimention + j] = true;
                        }
                        //=======================classic extrapolation======================


                        ////=======================diaganol extrapolation======================
                        if (i > 0 && ClockMaxValues[i] > 0 && -1 * boundi > ClockMaxValues[i])
                        {
                            //Debug.Assert(-1 * Matrix[0* dimention + i] <= ClockMaxValues[i - 1]);
                            Matrix[i * dimention + j] = dbm_LS_INFINITY;
                        }

                        if (j > 0 && ClockMaxValues[j] > 0 && i != 0 && -1 * boundj > ClockMaxValues[j])
                        {
                            //Debug.Assert(-1 * Matrix[0* dimention + j] <= ClockMaxValues[j - 1]);
                            Matrix[i * dimention + j] = dbm_LS_INFINITY;
                        }

                        if (j > 0 && ClockMaxValues[j] > 0 && i == 0 && -1 * boundi > ClockMaxValues[j])
                        {
                            //Debug.Assert(-1 * Matrix[i* dimention + j] <= ClockMaxValues[j - 1]);
                            Matrix[i * dimention + j] = DBMConstraint.dbm_bound2raw(-1 * ClockMaxValues[i], dbm_STRICT);
                            //MatrixStrictness[i * dimention + j] = true;
                        }
                        ////=======================diaganol extrapolation======================


                        ////=======================L/U extrapolation======================
                        if (i > 0 && ClockLowerValues[i] > 0 && boundij > ClockLowerValues[i])
                        {
                            //Debug.Assert(Matrix[i* dimention + j] <= ClockLowerValues[i - 1]);
                            Matrix[i * dimention + j] = dbm_LS_INFINITY;
                        }


                        if (j > 0 && ClockUpperValues[j] > 0 && -1 * Matrix[i * dimention + j] > ClockUpperValues[j])
                        {
                            //Debug.Assert(-1*Matrix[i* dimention + j] <= ClockUpperValues[j - 1]);
                            Matrix[i * dimention + j] = DBMConstraint.dbm_bound2raw(-1 * ClockUpperValues[j], dbm_STRICT);
                            //MatrixStrictness[i * dimention + j] = true;
                        }
                        ////=======================L/U extrapolation======================


                        ////=======================diaganol L/U extrapolation======================
                        if (i > 0 && ClockLowerValues[i] > 0 && -1 * Matrix[0 * dimention + i] > ClockLowerValues[i])
                        {
                            //Debug.Assert(-1 * Matrix[0* dimention + i] <= ClockLowerValues[i - 1]);
                            Matrix[i * dimention + j] = dbm_LS_INFINITY;
                        }


                        if (j > 0 && ClockUpperValues[j] > 0 && i != 0 && -1 * boundj > ClockUpperValues[j])
                        {
                            //Debug.Assert(-1 * Matrix[0* dimention + j] <= ClockUpperValues[j - 1]);
                            Matrix[i * dimention + j] = dbm_LS_INFINITY;
                        }

                        if (j > 0 && ClockUpperValues[j] > 0 && i == 0 && -1 * boundi > ClockUpperValues[j])
                        {
                            //Debug.Assert(-1 * Matrix[i* dimention + j] <= ClockUpperValues[j - 1]);
                            Matrix[i * dimention + j] = DBMConstraint.dbm_bound2raw(-1 * ClockUpperValues[j], dbm_STRICT);
                            //MatrixStrictness[i * dimention + j] = true;
                        }

                        ////=======================diaganol L/U extrapolation======================
                    }
                }
            }

            IsCanonicalForm = true;
        }
Пример #9
0
 public DBMConstraint(DBMConstraint c)
     : this(c.i, c.j, c.value)
 {
 }
Пример #10
0
 /** Negation of a constraint.
 * Swap indices i,j, negate value, and toggle the strictness.
 * @param c: constraint to negate.
 * @return negated constraint.
 */
 public static DBMConstraint dbm_negConstraint(DBMConstraint c)
 {
     byte tmp = c.i;
     c.i = c.j;
     c.j = tmp;
     c.value = dbm_negRaw(c.value);
     return c;
 }
Пример #11
0
 /** Equality of constraints.
 * @param c1, c2: constraints.
 * @return TRUE if c1 == c2.
 */
 public static bool dbm_areConstraintsEqual(DBMConstraint c1, DBMConstraint c2)
 {
     return (c1.i == c2.i && c1.j == c2.j && c1.value == c2.value);
 }