title: How to check if the Directed Acyclic Graph (DAG) restraint is broken for a simple Bayesian Network
body: <p>DISCLAIMER:  I'm new to bayesian Networks and Adjacency Matrix</p>
  
  <p>hey guys,</p>
  
  <p>So I'm making this very simple Bayesian network and I am trying to represent it using an Adjacency Matrix. <a href="https://i.stack.imgur.com/TdkbS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TdkbS.png" alt="enter image description here"></a>. So above is a graphical representation of the problem. We see that we have a cycle between node A, B, and C. And I want to prevent that. Now here is how I am trying to represent my graph in code (using an Adjacency Matrix or double loop).</p>
  
  <p><a href="https://i.stack.imgur.com/bFVaX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bFVaX.png" alt="enter image description here"></a></p>
  
  <p>I'm writing this method called checkDag(int[][] AdjacencyMatrixInput)</p>
  
  <p>it takes an AM and check if the DAG constraint is violated or not. i've started some code but keep getting stuck. Really would appreciate the help! (pseudocode or actual code would be great).</p>
  
  <pre><code>public void checkDag(Node[][] AM)
      {
          for(int i = 0; i &lt; AM.length; i++)
          {
              for(int j = 0; j &lt; AM[i].length; j++)
              {
                  if(AM[i][i].value == 1)
                  {
                      //getting stuck on how to check parents.
                  }
              }
          }
      }
  </code></pre>