neo4j logic gate simulation, how to?

China☆狼群 提交于 2019-12-11 03:14:39

问题


I would like to create a bunch of "and" and "or" and "not" gates in a directed graph. And then traverse from the inputs to see what they results are.

I assume there is a ready made traversal that would do that but I don't see it. I don't know what the name of such a traversal would be.

Certainly breadth first will not do the job. I need to get ALL the leaves, and go up toward the root. In other words

A = (B & (C & Z))

I need to resolve C @ Z first.

I need to put this type of thing in a graph and to traverse up.


回答1:


You would probably create each of the operations as a node which has N incoming and one outgoing connection. You can of course also have more complex operations encapsuled as a node.

With Neo4j 2.0 I would use Labels for the 3 types of operations.

I assume your leaves would then be boolean values? Actually I think you have many roots and just a single leaf (the result expression)

(input1)-->(:AND {id:1})-->(:OR {id:2})-->(output)
(input2)-->(:AND {id:1})
(input3)------------------>(:OR {id:2})

Then you can use CASE when for decisions on the label type and use the collection predicates (ALL, ANY) for the computation

See: http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html

Predicates: http://docs.neo4j.org/chunked/milestone/query-function.html

Labels: http://docs.neo4j.org/chunked/milestone/query-match.html#match-get-all-nodes-with-a-label



来源:https://stackoverflow.com/questions/16679184/neo4j-logic-gate-simulation-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!