Boost logo

Boost Users :

Subject: [Boost-users] Johnson all pair shortest path and output in a C array
From: Paolo Bolzoni (paolo.bolzoni.brown_at_[hidden])
Date: 2015-12-21 22:12:45


Dear list,

I need to get the all pair shortest path in a C array, to pass it to a
java program.
However johnson all pair shortest path[1] requires a BasicMatrix[2] as
output, so a simple array won't do.

At the moment I used few classes (see Matrix and MatrixR[3]) as
wrapper around a std::vector and it works fine, but I was wondering if
I am missing a simpler solution. Is there?

Yours faithfully,
Paolo

[1]http://www.boost.org/doc/libs/release/libs/graph/doc/johnson_all_pairs_shortest.html
[2]http://www.boost.org/doc/libs/release/libs/graph/doc/BasicMatrix.html

[3]
struct Matrix {
    Matrix(std::vector<int64_t>& storage, size_t rows, size_t columns)
      : m_(storage),
        columns_(columns)
    {
        m_.clear();
        m_.resize(rows * columns_, int64_t{0});
    }

    int64_t& get(size_t row, size_t column) {
        return m_[row * columns_ + column];
    }

    std::vector<int64_t>& m_;
    size_t columns_;
};

struct MatrixR;
struct MatrixRR {
    MatrixRR(MatrixR const& m, size_t column)
      : m_(m),
        column_(column)
    {}
    int64_t& operator[] (size_t row) const;

    MatrixR const& m_;
    size_t column_;
};

struct MatrixR {
    MatrixR(Matrix& m)
      : m_(m)
    {}
    MatrixRR operator[] (size_t column) const {
        return MatrixRR(*this, column);
    }

    Matrix& m_;
};

int64_t &
MatrixRR ::
operator[] (size_t row) const {
    return m_.m_.get(row, column_);
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net