コード例 #1
0
 //! Clears the connection matrix
 public void clear()
 {
     for (int i = 0; i < connections.Length; i++)
     {
         PoslTools.fill(connections[i], 0);
     }
 }
コード例 #2
0
        //! Constructor: receives the connection matrix

        /*!
         * \param connection_matrix The connection matrix
         */
        public ConnectionMatrix(int[][] connection_matrix)
        {
            int n = connection_matrix.GetLength(0);

            for (int i = 0; i < n; i++)
            {
                if (connection_matrix[i].Length != i)
                {
                    PoslTools.p_throw("not valid connection matrix", "ConnectionMatrix", "CONSTRUCTOR");
                }
            }
            connections = connection_matrix;
        }
コード例 #3
0
        //! Returns the total number of variables that index is connected with (RANKING)

        /*!
         * \param index A 0-based index
         * \return The total number of variables that index is connected with (RANKING)
         */
        public int ranking_cost_of_index(int index)
        {
            int sum = 0;

            for (int i = 0; i < connections[index].Length; i++)
            {
                sum += PoslTools.identity(connections[index][i]);
            }
            for (int i = index + 1; i < connections.Length; i++)
            {
                sum += PoslTools.identity(connections[i][index]);
            }
            return(sum);
        }
コード例 #4
0
        //! Returns whether indexes a and b are connected

        /*!
         * \param a A 1-based index
         * \param b A 1-based index
         * \return True if a and b are connected, false otherwise
         */
        public bool are_connected(int a, int b)
        {
            if (!are_one_base_indexes(a, b))
            {
                PoslTools.p_throw("not valid indexes", "ConnectionMatrix", "are_connected");
            }
            if (a == b)
            {
                return(true);
            }
            int pa = Math.Max(a, b) - 1;
            int pb = Math.Min(a, b) - 1;

            return(connections[pa][pb] > 1);
        }
コード例 #5
0
        //! Inserts a new connection between indexes a and b
        //   -- (see C++ implementation for lost details)

        /*!
         * \param a A 1-based index
         * \param b A 1-based index
         */
        public void add_connection(int a, int b)
        {
            if (!are_one_base_indexes(a, b))
            {
                PoslTools.p_throw("not valid indexes", "ConnectionMatrix", "add_connection");
            }
            if (a == b)
            {
                return;
            }
            int pa = Math.Max(a, b) - 1;
            int pb = Math.Min(a, b) - 1;

            connections[pa][pb]++;
        }