一.介绍
平衡三角算法被用来估计图的结构稳定性
平衡三元组是一种计算节点所属的平衡和不平衡三元组数目的算法,他使用带符号标志的图模型利用权重符号来区分正负关系。
其中+ + + 和- + - 表示为平衡状态
- + +和 - - - 表示为不平衡状态
二.neo4j算法调用:
CALL algo.balancedTriads.stream(label:String, relationship:String, {concurrency:4})
YIELD nodeId, balanced, unbalanced
三.实例:
MERGE (a:Person {name:'Anna'})
MERGE (b:Person {name:'Dolores'})
MERGE (c:Person {name:'Matt'})
MERGE (d:Person {name:'Larry'})
MERGE (e:Person {name:'Stefan'})
MERGE (f:Person {name:'Sophia'})
MERGE (g:Person {name:'Robin'})
MERGE (a)-[:TYPE {weight:1.0}]->(b)
MERGE (a)-[:TYPE {weight:-1.0}]->(c)
MERGE (a)-[:TYPE {weight:1.0}]->(d)`在这里插入代码片`
MERGE (a)-[:TYPE {weight:-1.0}]->(e)
MERGE (a)-[:TYPE {weight:1.0}]->(f)
MERGE (a)-[:TYPE {weight:-1.0}]->(g)
MERGE (b)-[:TYPE {weight:-1.0}]->(c)
MERGE (c)-[:TYPE {weight:1.0}]->(d)
MERGE (d)-[:TYPE {weight:-1.0}]->(e)
MERGE (e)-[:TYPE {weight:1.0}]->(f)
MERGE (f)-[:TYPE {weight:-1.0}]->(g)
MERGE (g)-[:TYPE {weight:1.0}]->(b);
call algo.balancedTriads.stream('Person','TYPE',{weightProperty:'weight'})
yield nodeId,balanced,unbalanced
return algo.getNodeById(nodeId).name as person,balanced,unbalanced
order by balanced+unbalanced desc