2

Boost Graph ライブラリを使用して、yEd で作成された .graphml ファイルからグラフ関連の (カスタム) プロパティを読み取ろうとしています。頂点とエッジ (dynamic_) プロパティの読み取りは機能しますが、グラフのプロパティは常に空です。また、boost::read_graphml でグラフ ドメイン属性を読み取る方法にも遭遇しました。しかし、そのソリューションは空の文字列を生成するだけです (以下のコードにあります)。それとは別に、問題に関する多くの情報を見つけることができませんでした。

短縮されたコードは次のとおりです(完全な動作例test.cppはこちら):

struct VertexProperties { string url, description; };
struct EdgeProperties { string url, description; };
struct GraphProperties { string title; };
// ...
typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperties, GraphProperties> DirectedGraph;
typedef dynamic_properties Properties;
DirectedGraph graph(0);

Properties props(ignore_other_properties);
props.property("url", get(&VertexProperties::url, graph));
props.property("description", get(&VertexProperties::description, graph));
props.property("url", get(&EdgeProperties::url, graph));
props.property("description", get(&EdgeProperties::description, graph));
map<string, string> attribute_name2name;
associative_property_map<map<string, string>> graphname_map(attribute_name2name);
props.property("title", graphname_map);
// ...
read_graphml(validated, graph, props);
graph[graph_bundle].title = get(graphname_map, "title");
cout << "\"" << graph[graph_bundle].title << "\"" << endl;

を使用して完全なコードをコンパイルできますg++ test.cpp --std=c++11 -o test -lboost_graph。で実行すると./test simple_graph.graphml、グラフには

<data key="d1"><![CDATA[foobar]]></data>

として定義されているタグ

<key attr.name="title" attr.type="string" for="graph" id="d1">
  <default/>
</key>

simple_graph.graphml サンプル ファイルアップロードしました(画像や詳細を投稿するには十分な担当者がいません)。

マイナーなフォローアップの質問: yEd でエクスポートされたファイル (コードを参照) を「修正」せずにグラフをロードすることは可能ですか? パーサーは常に次のような行について不平を言います (標準で許可されている GraphML 標準で許可されているかどうかは不明です:「このグループは、2 つのオプションの属性で構成されています - attr.name (データ関数の名前を指定します) - attr.type ((データ関数の値の範囲を宣言します)):

<key for="port" id="d2" yfiles.type="portgraphics"/>

このエラーで:

解析エラー: キーのタイプ "" を認識できません

ヘルプ/アイデアは大歓迎です。どうもありがとうございました!

4

1 に答える 1

0

これを試して:

template<typename MutableGraph>
class mutate_graph_impl_yed : public mutate_graph_impl<MutableGraph>
{
public:
    mutate_graph_impl_yed(MutableGraph& g, dynamic_properties& dp)
        : mutate_graph_impl<MutableGraph>(g,dp) { }

    virtual void
        set_vertex_property(const std::string& name, any vertex, const std::string& value, const std::string& value_type)
    {
        bool type_found = false;
        try
        {
            mpl::for_each<value_types>(put_property<graph_traits<MutableGraph>::vertex_descriptor, value_types>
                (name, m_dp, any_cast<graph_traits<MutableGraph>::vertex_descriptor>(vertex),
                    value, value_type, m_type_names, type_found));
        }
        catch (bad_lexical_cast)
        {
            BOOST_THROW_EXCEPTION(
                parse_error("invalid value \"" + value + "\" for key " +
                    name + " of type " + value_type));
        }
    }

    virtual void
        set_edge_property(const std::string& name, any edge, const std::string& value, const std::string& value_type)
    {
        bool type_found = false;
        try
        {
            mpl::for_each<value_types>(put_property<graph_traits<MutableGraph>::edge_descriptor, value_types>
                (name, m_dp, any_cast<graph_traits<MutableGraph>::edge_descriptor>(edge),
                    value, value_type, m_type_names, type_found));
        }
        catch (bad_lexical_cast)
        {
            BOOST_THROW_EXCEPTION(
                parse_error("invalid value \"" + value + "\" for key " +
                    name + " of type " + value_type));
        }
    }
};

read_graphml の呼び出しを次のように置き換えます。

mutate_graph_impl_yed<Graph> mg(g, dp);
read_graphml(fin, mg, 0);
于 2019-04-23T08:27:16.120 に答える