0

GraphLab を使用して BFS アルゴリズムを実装しようとしています。私の vertex_data 構造体では、ベクトルを使用して、これまでに通過したパスを保持しています。

struct vertex_data {

    std::vector<int> current_path;
    bool visited;
    int destination;
    vertex_data() {
        destination = -1;
        visited = false;
    }
}

次に、apply() 関数で、現在の頂点 ID をその特定の頂点の current_path にプッシュしようとしています。

class bfs: public graphlab::ivertex_program<graph_type, graphlab::empty,
        vertex_data> {
private:
    vertex_data msg;

public:


 void apply(icontext_type& context, vertex_type& vertex, const gather_type& gather_result) {
        int vid = vertex.id();
        vertex.data().destination = msg.destination;
        vertex.data().visited = true;
        msg.current_path.push_back(vid);
        vertex.data().current_path.push_back(vid);
}
}

また、ドキュメントの data() の定義は次のとおりです。

vertex_data_type &  data ()
    Returns a reference to the data on the vertex.

GraphLab は vertex_data オブジェクトを vertex_data_type としてラップします。実行すると、いくつかの頂点の push_back() 関数で seg fault が発生します。vid を確認しましたが、常に実際の値を持つ整数です。vertex.data().current_path.size() を実行すると、0 が返されます。

ID をプッシュする前に、ローカル ベクトルを作成して vertex.data() のベクトルを置き換え、サイズを変更するなど、いくつかのアプローチを試しました。最初のケースでは、置換しようとするとセグ エラーが発生し、2 番目のケースでは問題なくサイズ変更が実行されますが、プッシュによってセグ エラーが発生し続けます。

何が問題なのか、何か考えはありますか?

ありがとう

4

1 に答える 1

0

Graphlab のクラスはシリアライズ可能である必要があります。そのため、変数が Plain Old Data (POD) でない場合は、独自のロードおよび保存関数を作成する必要があります。

あなたの場合、次のようになります(ロードリストと保存リストは同じ順序にする必要があることに注意してください):

struct vertex_data {

std::vector<int> current_path;
bool visited;
int destination;
vertex_data() {
    destination = -1;
    visited = false;
}
void save(graphlab::oarchive& oarc) const {
    oarc << current_path << visited << destination;
}

void load(graphlab::iarchive& iarc) {
    iarc >> current_path >> visited >> destination;
}

}

于 2015-10-28T21:35:00.967 に答える