How to implement a triggering based on multi events?

Hi,
I have a event A, which happens only when event B, and C occur at the same time. This is a common situation in the fault tree analysis.
Is there any neat way I can implement this logic?
Thank you!
Br
Haofeng

Can I build a small graph to implement AND gate?

Interesting question. I used to design digital circuits years ago. In one job I used some modeling software to define and simulate my designs. It was software, but it differed from traditional software, since I could have the variables all change state on an event, like the rising edge of a clock. This allowed me to model sequential digital circuits. It was only for steady-state analysis.

Are you looking to model only combinational circuits and just steady state response? Sequential circuit analysis will be even more challenging.

I guess you could model a combinational circuit with a set of nodes and relationships. Even so, I don't see evaluating the logic with cypher to be easy or efficient for anything but the simplest circuit. I think if you want to evaluate the logic or perform some fault tolerant analysis on a circuit, you will need to implement each algorithm in custom procedures. These are procedures that run on the server itself, which are developed using Neo4j's Java API. They will allow you to traverse the graph and perform calculations along the way.

I am not sure this is the platform for what you are trying to achieve. There are no existing solutions for this?

Hi Gary,
Thank you very much for your kind reply!
I have been trying neo4j for about 1 week for my application, which is somewhat close to what you describe. I need to handle many nodes and the visualization becomes tricky. There are indeed other platform but I need to do some tricks to get things working. I was lazy and looking for some ready-to-use tools. Now I realize maybe neo4j is not the perfect tool for me due to the lack of easy implementation of AND logic.
Appreciate the suggestions very much!
Br
Haofeng

You are very welcome. Very cool problem to work on.

The cypher query language is a great tool for finding paths based on patterns. The result of a query is a set of rows.

For your application, you will need to evaluate logical expressions as you traverse your
collections of nodes. This can be done writing code in Java that uses the Neo4j API. The API allows you to access nodes and their relationship so you can traverse a collection of nodes. Your code implementing custom procedures and functions is bundled in a jar and deployed on the server, which becomes available in cypher.

I have used the api to build the evaluation of a decision tree in neo4j. I used a recursive algorithm to traverse the tree and accumulate any outcome at each node.

Your problem is more difficult since a circuit can have N inputs and M outputs. Unlike the decision tree, a node in your circuit will have multiple inputs (besides an inverter). This makes evaluation with a recursive algorithm more challenging than my decision tree as you have to worry about the order of the calculations, because you can’t evaluate a node if all it’s inputs have not been determined. I have developed an algorithm in Java for an application that did just this where I had any number of inputs and needed to evaluate functions of any combination of each, but I could had inputs to any function that included results from and calculated function. As such, I had N inputs of values and M outputs to calculate, where there was interdependencies between the calculations. This is the same as evaluating a combinational circuits with simple Boolean expressions to calculate instead of numeric functions. I also used a recursive algorithm to evaluate the functions, but this time I needed to consider it a node had all its inputs computed when evaluating a node. If not, the algorithm would move on and automatically try again later. The algorithm would always converge with all the values calculated as long as the the network didn’t contain lops, which makes sense.

Anyways, you could do something similar in your case.

Hi Gary,
Thank you for sharing your experience! That sounds really cool.

I am new to cypher. Do you mean that the server will determine some states so in cypher there is no need to do the logic operation? That is smart. I have no experience in Java but I do my daily work with Matlab. Maybe it can be done with Matlab.
As the tree is dynamically built with the help of server, I think it will be only possible to see the whole tree once all calculation has been done on the server. That's reasonable.
Thank you again for the inspiring answer.
Br
Haofeng

As I see it, cypher looks for paths using pattern matching. It doesn’t have the capabilities to execute algorithms over the results as well, which again is a collection of paths.

For your application, you need to execute an algorithm over a collection of interconnected nodes. Neo4j exposes their Java API that you can use to traverse any collection of nodes, allowing you to calculate whatever you need for that collection of connected nodes. This code runs on the server. You develop procedures and functions to implement your logic. The code you write is packaged in a ‘jar’ file and deployed to the server by placing it in the ‘plugin’ folder associated with your database. The procedures and functions are then available in cypher. In your case you could do something like query for the input nodes of your circuit and call your procedure with these nodes as input parameters. That would cause your code on the server to execute, which could update the steady state output of each node and maybe return the state of each node representing an output of your circuit. This is just a thought how it could be used.