微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何减少一组顶点,直到每个顶点不需要另一个顶点

如何解决如何减少一组顶点,直到每个顶点不需要另一个顶点

假设我有一个顶点为ABCDEFG的图,X,并使用如下所示的传出边缘requires进行连接

A -> X
B -> A
C -> B
D -> C
D -> E
E -> X
F -> G
F -> X
G -> X

graphical view of the graph

是否可以缩小给定的一组顶点,直到该组顶点中的每个顶点都不require。例如:

input          = [ C ]
desired output = [ C ]
input          = [ A,B,C,D ]
desired output = [ A ]
input          = [ A,E ]
desired output = [ A,E ]
input          = [ A,D,E,G,F ]
desired output = [ A,G ]

解决方法

到目前为止,我已尽力而为,忽略了所有项目。可能有人可以帮助我如何在查询本身中过滤结果。

g.V().has('name',within('A','B','C','D')).
  aggregate('N').
  repeat(in().dedup()).
  until(has('name','D'))).
  aggregate('K').
  V().has('name','D')).
  where(without('K')).
  dedup().
  values('name')

您也可以使用问题https://gremlify.com/or7cziqjps

中给出的相同数据进行尝试

更新:添加了Where来过滤结果,但是,试图进一步简化查询以使其更加有效。

要使其他人更容易尝试更好的解决方案,请发布查询以添加数据。

g.addV('node').as('1').
  property(single,'name','A').addV('node').as('2').
  property(single,'B').addV('node').as('3').
  property(single,'C').addV('node').as('4').
  property(single,'D').addV('node').as('5').
  property(single,'E').addV('node').as('6').
  property(single,'F').addV('node').as('7').
  property(single,'G').addV('node').as('8').
  property(single,'X').
  addE('requires').from('1').to('8').
  addE('requires').from('2').to('1').
  addE('requires').from('3').to('2').
  addE('requires').from('4').to('3').
  addE('requires').from('4').to('5').
  addE('requires').from('7').to('8').
  addE('requires').from('6').to('7').
  addE('requires').from('5').to('8')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。