I am trying to perform a very simple mincut on an itkGraph. I create an extremely simple graph: 2 nodes with a weight 2 edge between them. The problem is that the cut weight is 0, when I would expect it to be 2. Can anyone see if I have done something wrong with constructing the graph or performing the cut?<br>
<br>#include <iostream><br><br>#include "itkGraph.h"<br>#include "itkBoykovGraphTraits.h"<br>#include "itkBoykovMinCutGraphFilter.h"<br><br>int main( int argc, char * argv[] )<br>{<br> //setup types<br>
typedef itk::BoykovGraphTraits<short, 3> GraphTraitsType;<br> typedef itk::Graph<GraphTraitsType> GraphType;<br> typedef GraphType::NodePointerType NodePointerType;<br>
typedef GraphType::EdgePointerType EdgePointerType;<br><br> //create a new graph<br> GraphType::Pointer graph = GraphType::New();<br> <br> // Create graph nodes<br> NodePointerType Nodes[3];<br> <br>
for( unsigned int i = 0; i < 2; i++ )<br> {<br> Nodes[i] = graph->CreateNewNode();<br> }<br> <br> /*<br> //these lines don't change the behavior<br> Nodes[0]->IsSink = true; //set node 0 to be a sink<br>
Nodes[1]->IsSink = false; //set node 1 to be a source<br> */<br> <br> //create an edge between nodes 0 and 1 with weight 2<br> graph->CreateNewEdge( Nodes[0], Nodes[1], 2);<br> <br> //verify that the graph was created correctly<br>
std::cout << std::endl;<br> std::cout << "Num Nodes: " << graph->GetTotalNumberOfNodes() << std::endl;<br> std::cout << "Num Edges: " << graph->GetTotalNumberOfEdges() << std::endl;<br>
<br> // Set the reverse edges (doesn't change the behavior)<br> //graph->SetAllReverseEdges();<br><br> //perform the cut<br> typedef itk::BoykovMinCutGraphFilter <GraphType> FilterType;<br> FilterType::Pointer CutFilter = FilterType::New();<br>
CutFilter->SetInput(graph);<br> CutFilter->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->GetNodeIdentifier( node );<br>
<br> node = graph->GetNodePointer( Id );<br> <br> if(node->IsSink)<br> {<br> std::cout << "Node Id: " << Id << " is a sink." << std::endl;<br>
}<br> else<br> {<br> std::cout << "Node Id: " << Id << " is a source." << std::endl;<br> }<br> }<br> <br> <br> //get the cut weight (min cut = max flow)<br>
typedef GraphType::NodeWeightType NodeWeightType;<br> NodeWeightType maxflow = CutFilter->GetMaxFlow();<br> std::cout << "Max Flow: " << maxflow << std::endl;<br> <br> return EXIT_SUCCESS;<br>
<br>}<br><br>Thanks!<br><br>Dave<br>