示例#1
0
文件: utility.hpp 项目: cmu-sei/gbtl
    void pretty_print_matrix(std::ostream &ostr, MatrixT const &mat)
    {
        IndexType rows, cols;
        mat.get_shape(rows, cols);
        typename MatrixT::ScalarType zero(mat.get_zero());

        for (IndexType row = 0; row < rows; ++row)
        {
            ostr << ((row == 0) ? "[[" : " [");
            if (cols > 0)
            {
                auto val = mat.get_value_at(row, 0);
                if (val == zero)
                    ostr << " ";
                else
                    ostr << val;
            }

            for (IndexType col = 1; col < cols; ++col)
            {
                auto val = mat.get_value_at(row, col);
                if (val == zero)
                    ostr << ",  ";
                else
                    ostr << ", " << val;
            }
            ostr << ((row == rows - 1) ? "]]\n" : "]\n");
        }
    }
示例#2
0
文件: maxflow.hpp 项目: cmu-sei/gbtl
static void discharge(MatrixT const &C,
                      MatrixT       &F,
                      MatrixT       &excess,
                      MatrixT       &height,
                      MatrixT       &seen,
                      graphblas::IndexType u)
{
    graphblas::IndexType num_nodes, cols;
    C.get_shape(num_nodes, cols);

    while (excess.get_value_at(0, u) > 0)
    {
        if (seen.get_value_at(0, u) < num_nodes)
        {
            graphblas::IndexType v = seen.get_value_at(0, u);
            if (((C.get_value_at(u, v) - F.get_value_at(u, v)) > 0) &&
                    (height.get_value_at(0, u) > height.get_value_at(0, v)))
            {
                push(C, F, excess, u, v);
            }
            else
            {
                seen.set_value_at(0, u, seen.get_value_at(0, u) + 1);
            }
        }
        else
        {
            relabel(C, F, height, u);
            seen.set_value_at(0, u, 0);
        }
    }
}
示例#3
0
文件: maxflow.hpp 项目: cmu-sei/gbtl
static void push(MatrixT const &C,
                 MatrixT       &F,
                 MatrixT       &excess,
                 graphblas::IndexType u,
                 graphblas::IndexType v)
{
    using T = typename MatrixT::ScalarType;
    T a = excess.get_value_at(0, u);
    T b = C.get_value_at(u, v) - F.get_value_at(u, v);
    T send = std::min(a, b);

    F.set_value_at(u, v, F.get_value_at(u, v) + send);
    F.set_value_at(v, u, F.get_value_at(v, u) - send);

    excess.set_value_at(0, u, excess.get_value_at(0, u) - send);
    excess.set_value_at(0, v, excess.get_value_at(0, v) + send);
}
示例#4
0
文件: maxflow.hpp 项目: cmu-sei/gbtl
static void relabel(MatrixT const &C,
                    MatrixT const &F,
                    MatrixT       &height,
                    graphblas::IndexType u)
{
    using T = typename MatrixT::ScalarType;
    graphblas::IndexType num_nodes, cols;
    C.get_shape(num_nodes, cols);

    T min_height = std::numeric_limits<T>::max();
    for (graphblas::IndexType v = 0; v < num_nodes; ++v)
    {
        if ((C.get_value_at(u, v) - F.get_value_at(u, v)) > 0)
        {
            T a = height.get_value_at(0, v);
            min_height = std::min(min_height, a);
            height.set_value_at(0, u, min_height + 1);
        }
    }
}
示例#5
0
文件: utility.hpp 项目: cmu-sei/gbtl
    void row_index_of(MatrixT &mat)
    {
        graphblas::IndexType rows, cols;
        mat.get_shape(rows, cols);

        for (IndexType i = 0; i < rows; ++i)
        {
            for (IndexType j = 0; j < cols; ++j)
            {
                auto mat_ij = mat.get_value_at(i, j);
                if (mat_ij != mat.get_zero())
                {
                    mat.set_value_at(i, j, i);
                }
            }
        }
    }