Exemple #1
0
 public Model()
 {
     Model.tempVariableCount = 0;
     CUDD.InitialiseCUDD(2048, CUDD.CUDD_UNIQUE_SLOTS, CUDD.CUDD_CACHE_SLOTS, 0.1);
 }
Exemple #2
0
 public ModulesToBDD(Modules modules)
 {
     this.modules = modules;
     CUDD.InitialiseCUDD(2048 * 1024, Math.Pow(10, -15));
 }
Exemple #3
0
        public static double[] Jacobi(double[][] A, double[] b, double[] init)
        {
            CUDD.InitialiseCUDD(2048 * 1024, Math.Pow(10, -15));

            if (!(A.Length == b.Length && b.Length == init.Length & A.Length > 0))
            {
                throw new Exception("Wrong format");
            }

            int rowSize = A.Length;
            int colSize = A[0].Length;

            CUDDVars rowVars          = new CUDDVars();
            CUDDVars colVars          = new CUDDVars();
            int      numverOfBoolVars = 0;

            //Create bits for row index
            int numberOfBitForRow = (int)Math.Ceiling(Math.Log(rowSize, 2));

            for (int i = 0; i < numberOfBitForRow; i++)
            {
                CUDDNode v = CUDD.Var(numverOfBoolVars++);
                rowVars.AddVar(v);
            }

            //Create bits for col index
            int numberOfBitForCol = (int)Math.Ceiling(Math.Log(colSize, 2));

            for (int i = 0; i < numberOfBitForCol; i++)
            {
                CUDDNode v = CUDD.Var(numverOfBoolVars++);
                colVars.AddVar(v);
            }

            //Convert matrix to BDD
            CUDDNode matrixA = CUDD.Constant(0);

            for (int i = 0; i < A.Length; i++)
            {
                for (int j = 0; j < A[i].Length; j++)
                {
                    if (A[i][j] != 0)
                    {
                        CUDD.Matrix.SetMatrixElement(matrixA, rowVars, colVars, i, j, A[i][j]);
                    }
                }
            }

            //Convert vector to BDD
            CUDDNode vectorB = CUDD.Constant(0);

            for (int i = 0; i < b.Length; i++)
            {
                if (b[i] != 0)
                {
                    CUDD.Matrix.SetVectorElement(vectorB, rowVars, i, b[i]);
                }
            }

            //Set reach state
            CUDDNode reach = CUDD.Constant(0);

            for (int i = 0; i < rowSize; i++)
            {
                CUDD.Matrix.SetVectorElement(reach, rowVars, i, 1);
            }

            CUDDNode vectorInit = CUDD.Constant(0);

            for (int i = 0; i < init.Length; i++)
            {
                if (init[i] != 0)
                {
                    CUDD.Matrix.SetVectorElement(vectorInit, rowVars, i, init[i]);
                }
            }

            CUDDNode result = Jacobi(matrixA, vectorB, vectorInit, reach, rowVars, colVars, 1);

            double[] solution = new double[colSize];

            for (int i = 0; i < colSize; i++)
            {
                solution[i] = CUDD.Matrix.GetVectorElement(result, rowVars, i);
            }

            return(solution);
        }