<div class="gmail_quote">On Tue, Sep 1, 2009 at 11:50 PM, Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com">ntustison@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="word-wrap: break-word;">Hi David,<div><br></div><div>Okay, it&#39;s been quite awhile since I&#39;ve looked at the code but I think I can provide you with a little bit of direction.  If you look in the Initialize() function (the lines in question are 198-205 in my copy), you&#39;ll see that Boykov&#39;s min-cut algorithm adds 2 edges to the output graph, i.e. the &quot;terminal edge&quot; and the &quot;orphan edge&quot;. Also, if I remember correctly, what you do is iterate through the nodes in the graph and inspect  the boolean variable &quot;IsSink&quot; which will be either true (sink node) or false (source node).  Also, the class variable m_MaxFlow should hold the weight of the min cut.  Simply call GetMaxFlow().</div>
<div><br></div><div>Nick   </div><div></div></div></blockquote><div><br>Nick,<br><br>Thanks for the help so far - however, it doesn&#39;t seem to be working as expected.<br><br>IsSink is returning false for both nodes.<br>
GetMaxFlow() is returning 0.<br><br>I added this:<br>  this-&gt;m_MaxFlow += bottleneck;<br>std::cout &lt;&lt; &quot;added &quot; &lt;&lt; bottleneck &lt;&lt; &quot; to maxflow.&quot; &lt;&lt; std::endl;<br><br>to line 394 of itkBoykovMinCutGraphFilter.txx and nothing is ever output.. so it follows that GetMaxFlow() would return 0 - but why would it never be incremented? Is this too degenerate of a graph for the algorithm to work properly? I wasn&#39;t sure if multiple edges were allowed between nodes - so I now only have one edge of weight 2. I also wasn&#39;t sure about the behavior of directed graphs, so I removed the call to SetAllReverseEdges.   Here is the code:<br>
#include &lt;iostream&gt;<br><br>#include &quot;itkGraph.h&quot;<br>#include &quot;itkBoykovGraphTraits.h&quot;<br>#include &quot;itkBoykovMinCutGraphFilter.h&quot;<br><br>int main( int argc, char * argv[] )<br>{<br>    typedef itk::BoykovGraphTraits&lt;short, 3&gt; GraphTraitsType;<br>
<br>    typedef itk::Graph&lt;GraphTraitsType&gt;           GraphType;<br>    GraphType::Pointer graph = GraphType::New();<br><br>    typedef GraphType::NodePointerType      NodePointerType;<br>    typedef GraphType::EdgePointerType      EdgePointerType;<br>
 <br>      // Create graph nodes<br>    NodePointerType Nodes[2];<br>  <br>    for( unsigned int i = 0; i &lt; 2; i++ )<br>    {<br>        graph-&gt;CreateNewNode( 2 );<br>    }<br>    <br>    //get pointers to the newly created nodes<br>
    for( unsigned int i = 0; i &lt; 2; i++ )<br>    {<br>        Nodes[i] = graph-&gt;GetNodePointer( i );<br>    }<br><br>     //create three edges between nodes 0 and 1, each with weight 2<br>    graph-&gt;CreateNewEdge( Nodes[0], Nodes[1], 2 );<br>
    //graph-&gt;CreateNewEdge( Nodes[0], Nodes[1], 2 );<br>    //graph-&gt;CreateNewEdge( Nodes[0], Nodes[1], 2 );<br><br>    // Set the reverse edges<br>    //graph-&gt;SetAllReverseEdges();<br><br>    //perform the cut<br>
    typedef itk::BoykovMinCutGraphFilter  &lt;GraphType&gt; FilterType;<br>    FilterType::Pointer filter = FilterType::New();<br>    filter-&gt;SetInput(graph);<br>    filter-&gt;Update();<br><br>    //see which nodes are sinks<br>
    typedef GraphType::NodeIterator         NodeIteratorType;<br>    typedef GraphType::NodeIdentifierType   NodeIdentifierType;<br>    NodeIteratorType nit( graph );<br>    for( nit.GoToBegin(); !nit.IsAtEnd(); ++nit )<br>
    {<br>        NodePointerType node = nit.GetPointer();<br>        NodeIdentifierType Id = graph-&gt;GetNodeIdentifier( node );<br>        node = graph-&gt;GetNodePointer( Id );<br>        bool IsSink = node-&gt;IsSink;<br>
        <br>        if(IsSink)<br>        {<br>            std::cout &lt;&lt; &quot;Node Id: &quot; &lt;&lt; Id &lt;&lt; &quot; is in group 1.&quot; &lt;&lt; std::endl;<br>        }<br>        else<br>        {<br>            std::cout &lt;&lt; &quot;Node Id: &quot; &lt;&lt; Id &lt;&lt; &quot; is in group 0.&quot; &lt;&lt; std::endl;<br>
        }<br>    }<br>        <br>    //get the cut weight (min cut = max flow)<br>    typedef GraphType::NodeWeightType       NodeWeightType;<br>    NodeWeightType maxflow = filter-&gt;GetMaxFlow();<br>    std::cout &lt;&lt; &quot;Max Flow: &quot; &lt;&lt; maxflow &lt;&lt; std::endl;<br>
    <br>    return EXIT_SUCCESS;<br>    <br>}<br><br>The output is:<br>Node Id: 0 is in group 0.<br>Node Id: 1 is in group 0.<br>Max Flow: 0<br><br>The expected output is: (group 1 and 0 could possibly be switched)<br>Node Id: 0 is in group 0.<br>

Node Id: 1 is in group 1.<br>
Max Flow: 2<br>
<br>Any more suggestions?<br><br clear="all">Thanks,<br><br>David<br></div></div>