示例#1
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;
        }
示例#2
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;
        }