图形描述语言GraphML(4):复杂图形(嵌套,超边,端口)

本文详细介绍了GraphML标准,一种用于描述图形结构的XML格式。涵盖嵌套图、超边及注册点等高级特性,并提供示例代码说明如何表示复杂的图形结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

复杂的图形可能包括嵌套,超边或注册点,这些GraphML也提供了内建的支持。
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8"> <meta name="GENERATOR" content="StarSuite 8 (Linux)"> <meta name="AUTHOR" content="*"> <meta name="CREATED" content="20071029;11490000"> <meta name="CHANGEDBY" content="Seaman Wang"> <meta name="CHANGED" content="20080123;14404900">

嵌套图( Nested Graph

嵌套图表现为图形的子元素本身也可能为图。比如:


用GraphML表示如下:

<?xmlversion="1.0"encoding="UTF-8"?>
<graphmlxmlns="http://graphml.graphdrawing.org/xmlns"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://graphml.graphdrawing.org/xmlnshttp://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graphid="G"edgedefault="undirected">
<nodeid="n0"/>
<nodeid="n1"/>
<nodeid="n2"/>
<nodeid="n3"/>
<nodeid="n4"/>
<nodeid="n5">
<graphid="n5:"edgedefault="undirected">
<nodeid="n5::n0"/>
<nodeid="n5::n1"/>
<nodeid="n5::n2"/>
<edgeid="e0"source="n5::n0"target="n5::n2"/>
<edgeid="e1"source="n5::n1"target="n5::n2"/>
</graph>
</node>
<nodeid="n6">
<graphid="n6:"edgedefault="undirected">
<nodeid="n6::n0">
<graphid="n6::n0:"edgedefault="undirected">
<nodeid="n6::n0::n0"/>
</graph>
</node>
<nodeid="n6::n1"/>
<nodeid="n6::n2"/>
<edgeid="e10"source="n6::n1"target="n6::n0::n0"/>
<edgeid="e11"source="n6::n1"target="n6::n2"/>
</graph>
</node>
<edgeid="e2"source="n5::n2"target="n0"/>
<edgeid="e3"source="n0"target="n2"/>
<edgeid="e4"source="n0"target="n1"/>
<edgeid="e5"source="n1"target="n3"/>
<edgeid="e6"source="n3"target="n2"/>
<edgeid="e7"source="n2"target="n4"/>
<edgeid="e8"source="n3"target="n6::n1"/>
<edgeid="e9"source="n6::n1"target="n4"/>
</graph>
</graphml>
其中,如果边连接的是node中子图内的node,则适用::表示node的层级。如source="n6::n1"

<style type="text/css"> <!-- @page { size: 21cm 29.7cm; margin: 2cm } P { margin-bottom: 0.21cm } H3 { margin-bottom: 0.21cm } H3.western { font-family: "Albany", "Arial", sans-serif } H3.cjk { font-family: "方正黑体"; font-style: normal } H3.ctl { font-family: "Lucidasans" } --></style>

<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8"> <meta name="GENERATOR" content="StarSuite 8 (Linux)"> <meta name="AUTHOR" content="*"> <meta name="CREATED" content="20071029;11490000"> <meta name="CHANGEDBY" content="Seaman Wang"> <meta name="CHANGED" content="20080123;14404900">

超边( Hyperedges

超边是指连接到多个node的边,如图:


在GraphML中用元素 <meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">

<meta name="GENERATOR" content="StarSuite 8 (Linux)"> <meta name="AUTHOR" content="*"> <meta name="CREATED" content="20071029;11490000"> <meta name="CHANGEDBY" content="Seaman Wang"> <meta name="CHANGED" content="20080123;16154100"> <style type="text/css"> <!-- @page { size: 21cm 29.7cm; margin: 2cm } PRE.western { font-family: "Cumberland", "Courier New", monospace } PRE.cjk { font-family: "方正宋体", monospace } PRE.ctl { font-family: "方正宋体", monospace } P { margin-bottom: 0.21cm } --></style> hyperedge表示超边,其子元素为多个endpoint,每个endpoint指向一个node:


<?xmlversion="1.0"encoding="UTF-8"?>
<graphmlxmlns="http://graphml.graphdrawing.org/xmlns"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://graphml.graphdrawing.org/xmlnshttp://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graphid="G"edgedefault="undirected">
<nodeid="n0"/>
<nodeid="n1"/>
<nodeid="n2"/>
<nodeid="n3"/>
<nodeid="n4"/>
<nodeid="n5"/>
<nodeid="n6"/>
<hyperedge>
<endpointnode="n0"/>
<endpointnode="n1"/>
<endpointnode="n2"/>
</hyperedge>
<hyperedge>
<endpointnode="n3"/>
<endpointnode="n4"/>
<endpointnode="n5"/>
<endpointnode="n6"/>
</hyperedge>
<hyperedge>
<endpointnode="n1"/>
<endpointnode="n3"/>
</hyperedge>
<edgesource="n0"target="n4"/>
</graph>
</graphml>



注册点(port)

注册点指边或超边连接到node上的逻辑位置。一个node可以有多个注册点,用port子元素定义:

<?xmlversion="1.0"encoding="UTF-8"?>
<graphmlxmlns="http://graphml.graphdrawing.org/xmlns"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://graphml.graphdrawing.org/xmlnshttp://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graphid="G"edgedefault="directed">
<nodeid="n0">
<portname="North"/>
<portname="South"/>
<portname="East"/>
<portname="West"/>
</node>
<nodeid="n1">
<portname="North"/>
<portname="South"/>
<portname="East"/>
<portname="West"/>
</node>
<nodeid="n2">
<portname="NorthWest"/>
<portname="SouthEast"/>
</node>
<nodeid="n3">
<portname="NorthEast"/>
<portname="SouthWest"/>
</node>
<edgesource="n0"target="n3"sourceport="North"targetport="NorthEast"/>
<hyperedge>
<endpointnode="n0"port="North"/>
<endpointnode="n1"port="East"/>
<endpointnode="n2"port="SouthEast"/>
</hyperedge>
</graph>
</graphml>

至此,GraphML的定义如下图:
<style type="text/css"><!-- @page { size: 21cm 29.7cm; margin: 2cm } P { margin-bottom: 0.21cm } H3 { margin-bottom: 0.21cm } H3.western { font-family: "Albany", "Arial", sans-serif } H3.cjk { font-family: "方正黑体"; font-style: normal } H3.ctl { font-family: "Lucidasans" } --></style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值