2011-07-29 5 views
2

나는 BOOST 라이브러리를 사용하여 간단한 GraphML 로더를 작성하려고합니다. 나는 GraphML 파일을 가지고 있고 그것을 boost adjacency list 구조체에 적재하고 싶다. 그래프는 지시되며 저장되는 유일한 정보는 노드의 이름 (0,1,2, ...)과 한 노드에서 다른 노드로의 에지입니다. 내가 한 일은 :부스트 read_graphml 예

void loadHierarchy(){ 
    // ... 
    std::ifstream inFile; 
    inFile.open("ext.gml", std::ifstream::in); 

    typedef boost::adjacency_list<> Graph; 
    Graph g; 

    boost::read_graphml(inFile, g); 
    // ... 
} 

인접성 목록에 전체 그래프 정보를 유지하기 위해 속성을 사용할 필요가 없습니다. 내가 할

오류는 다음과 같습니다 :

error: invalid initialization of reference of type ‘boost::mutate_graph&’ from expression of type ‘loadHierarchy()::Graph’

/usr/include/boost/graph/graphml.hpp:194: error: in passing argument 2 of ‘void boost::read_graphml(std::istream&, boost::mutate_graph&)’

그것은 그렇게 간단해야하지만, 분명히 아니다.

답변

1

설정해야 할 속성이 없어도 read_graphml()의 3 매개 변수 버전을 사용해야한다고 생각합니다. 사용할 두 개의 매개 변수 버전은 라이브러리의 (불행히도 노출 된) 내부 세부 정보입니다.

그래서, 난 당신이 이런 식으로 뭔가를 시도하는 것이 좋습니다 :

boost::dynamic_properties dp; 
boost::read_graphml(inFile, g, dp); 

내가 도움이되기를 바랍니다.

+0

확실히 도움이되었습니다. 감사합니다. – EddieBytes

1

좀 더 철저하게 조사한 결과 실제로 행운이라고 결론을 내 렸습니다. 2 param 버전의 boost :: read_graphml이 노출되었습니다. 3 PARAM 하나는 다음과 같습니다

template<typename MutableGraph> 
void 
read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp) 
{ 
    mutate_graph_impl<MutableGraph> mg(g,dp); 
    read_graphml(in, mg); 
} 

이, 거기에 출력하는 잘못된 GraphML 파일의 종류, 즉 YED 특히 좋은 GraphML 편집기가, 예를 들어, 그것은에

<key for="node" id="d6" yfiles.type="nodegraphics"/> 

같은 태그가 그것. 위의 키에는 attr.type = "string"이 있어야하지만 그렇지 않습니다. 대신 yfd가 사용하고있는 확장 인 것처럼 보이는 yfiles.type이 있습니다 (불행히도). 디폴트 mutate_graph_impl은 이것을 처리 할 수 ​​없습니다. mutate_graph_impl은 여러분에게 상속 될 필요가 있으며, 전달 된 mutate_graph_impl의 구현과 함께 2 버전 read_graphml을 직접 호출해야합니다. 자신의 구현에, 당신은 mutate_graph_impl의

virtual void 
    set_vertex_property(const std::string& name, any vertex, const std::string& value, const std::string& value_type) 

가 지정되지 않은 attr.type와 키를 처리하기 위해 오버라이드 (override) 할 필요가 있습니다.