LoginSignup
8
5

More than 5 years have passed since last update.

GEXFの書き方

Last updated at Posted at 2012-11-26

GEXFはグラフをXMLで表現するフォーマットです.
Gephiなどで読むことができます.

単純な例を以下に示します.

hello.gexf
<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.gexf.net/1.2draft
                          http://www.gexf.net/1.2draft/gexf.xsd"
      version="1.2">
  <graph defaultedgetype="directed">
    <nodes>
      <node id="0" label="Hoge" />
      <node id="1" label="Piyo" />
      <node id="2" label="Fizz" />
      <node id="3" label="Buzz" />
    </nodes>
    <edges>
      <edge id="0" source="0" target="1" />
      <edge id="1" source="1" target="2" />
      <edge id="2" source="1" target="3" />
    </edges>
  </graph>
</gexf>

これは次のグラフを表しています.

要素の説明

graph 要素

グラフを表します.

属性として defaultedgetype を指定することができます.
これは directed, undirected, mutual のいずれかの値をとり,edge のタイプが指定されなかった場合のデフォルト値を表します.

graph 要素は,子要素として nodes と edges と attributes を持つことができます.
attributes は上の例に出てきていないので後で説明します.

nodes 要素, node 要素

nodes はグラフの節点の集合を表します.
node はグラフのひとつの節点を表します.

node は属性として id と label を持ちます.
id は,その節点の識別子を表す文字列で,他の節点と同じ id を持つことはできません.

edges 要素,edge 要素

edges はグラフの辺の集合を表します.
edge はグラフのひとつの辺を表します.

edge は属性として id, type, label, source, target, weight を持ちます.
id は,その辺の識別子を表す文字列で,他の辺と同じ id を持つことはできません.
type は directed, undirected, mutual のいずれかの値をとり,edge の種類を表します.
source と target は,それぞれ辺の始点と終点の id です.
weight は辺の重みを表す float です.

attributes 要素,attribute 要素,attvalues 要素,attvalue 要素

節点や辺には,自由に情報を付加できるようになっています.
どうやって付加するのかは,以下の例をよく見れば大体わかると思います.
この例では,節点に kind という情報を付加し,辺に capacity と flow という情報を付加しています.

attr.gexf
<?xml version="1.0" encoding="UTF-8"?>
<gexf xmlns="http://www.gexf.net/1.2draft"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd"
      version="1.2">
  <graph defaultedgetype="directed">

    <attributes class="node">
      <attribute id="0" title="kind" type="string">
        <options>source|sink|others</options>
      </attribute>
    </attributes>
    <attributes class="edge">
      <attribute id="0" title="capacity" type="float" />
      <attribute id="1" title="flow" type="float" />
    </attributes>

    <nodes>
      <node id="0" label="Hoge">
        <attvalues>
          <attvalue for="0" value="source" />
        </attvalues>
      </node>
      <node id="1" label="Piyo">
        <attvalues>
          <attvalue for="0" value="others" />
        </attvalues>
      </node>
      <node id="2" label="Fizz">
        <attvalues>
          <attvalue for="0" value="others" />
        </attvalues>
      </node>
      <node id="3" label="Buzz">
        <attvalues>
          <attvalue for="0" value="sink" />
        </attvalues>
      </node>
    </nodes>

    <edges>
      <edge id="0" source="0" target="1">
        <attvalues>
          <attvalue for="0" value="2.0" />
          <attvalue for="1" value="1.0" />
        </attvalues>
      </edge>
      <edge id="1" source="1" target="2">
        <attvalues>
          <attvalue for="0" value="1.0" />
          <attvalue for="1" value="0.0" />
        </attvalues>
      </edge>
      <edge id="2" source="1" target="3">
        <attvalues>
          <attvalue for="0" value="1.0" />
          <attvalue for="1" value="1.0" />
        </attvalues>
      </edge>
    </edges>
  </graph>
</gexf>

attributes 要素によって,付加する情報のスキーマを定義し,attvalues 要素で節点や辺に値を付加しています.attribute 要素の type 属性には integer, long, double, float, boolean, liststring, string, anyURI が指定できます.
また,options 要素で取りうる値を制限できます.

参考文献

ここで紹介した以外にもまだいくつか機能があります.興味がある人は以下のPDFを読むとよいと思います.

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5