Commit 8b1c5c06 authored by Cocophotos's avatar Cocophotos
Browse files

Merge branch 'release/1.5.5'

No related merge requests found
Showing with 105 additions and 63 deletions
+105 -63
......@@ -585,7 +585,6 @@ public:
}
}
bool isProjective()
{
//If the graph is not planar or is not a graph, it always means that
......@@ -594,9 +593,86 @@ public:
return false;
}
//First is projective_edges and second non_projectives_edges
std::pair<unsigned, unsigned> projectivity_count = testProjectivity(true);
//There is at least one non projective edges
if(projectivity_count.second > 0)
return false;
else
return true;
}
std::pair<unsigned, unsigned> testProjectivity()
{
return testProjectivity(false);
}
////////////////////////////////////////
//-------------------
// Helper functions
//-------------------
bool existsNode(unsigned id) const
{
if(nodesMap.find(id) != nodesMap.end())
return true;
else
return false;
}
bool existsEdge(unsigned id) const
{
if(edgesMap.find(id) != edgesMap.end())
return true;
else
return false;
}
////////////////////////////////////////
protected:
const Node& nodeById(unsigned id) const
{
typename map<unsigned, Node>::const_iterator node_it = nodesMap.find(id);
if(node_it != nodesMap.end())
return node_it->second;
throw out_of_range("The requested node does not exist");
}
const Edge& edgeById(unsigned id) const
{
typename map<unsigned, Edge>::const_iterator edge_it = edgesMap.find(id);
if(edge_it != edgesMap.end())
return edge_it->second;
throw out_of_range("The requested edge does not exist");
}
Node& nodeById(unsigned id)
{
typename map<unsigned, Node>::iterator node_it = nodesMap.find(id);
if(node_it != nodesMap.end())
return node_it->second;
throw out_of_range("The requested node does not exist");
}
Edge& edgeById(unsigned id)
{
typename map<unsigned, Edge>::iterator edge_it = edgesMap.find(id);
if(edge_it != edgesMap.end())
return edge_it->second;
throw out_of_range("The requested edge does not exist");
}
std::pair<unsigned, unsigned> testProjectivity(bool stopWhenSure)
{
std::set<unsigned> needAVisit;
std::set<unsigned> visited;
unsigned non_projective_edges = 0, projective_edges = 0;
const_ordered_node_iter begin, end;
for(boost::tie(begin, end) = constOrderedNodes(); begin != end; ++begin){
......@@ -639,8 +715,8 @@ public:
//Nodes are adjacent, and will not give any hint of projectivity.
//We spare time by not doing the DFS.
if(needAVisit.size() == 2)
continue;
//if(needAVisit.size() == 2)
// continue;
//We are doing a DFS from the sourceId to see if the yield of
......@@ -656,69 +732,19 @@ public:
//It's not the case, so we are sure that the tree is not projective
if(diff.size() > 0)
return false;
//Otherwise we continue to check the tree.
{
non_projective_edges += 1;
if(stopWhenSure)
{
return std::make_pair(projective_edges, non_projective_edges);
}
}
else
projective_edges += 1;
}
}
return true;
}
////////////////////////////////////////
//-------------------
// Helper functions
//-------------------
bool existsNode(unsigned id) const
{
if(nodesMap.find(id) != nodesMap.end())
return true;
else
return false;
}
bool existsEdge(unsigned id) const
{
if(edgesMap.find(id) != edgesMap.end())
return true;
else
return false;
}
////////////////////////////////////////
protected:
const Node& nodeById(unsigned id) const
{
typename map<unsigned, Node>::const_iterator node_it = nodesMap.find(id);
if(node_it != nodesMap.end())
return node_it->second;
throw out_of_range("The requested node does not exist");
}
const Edge& edgeById(unsigned id) const
{
typename map<unsigned, Edge>::const_iterator edge_it = edgesMap.find(id);
if(edge_it != edgesMap.end())
return edge_it->second;
throw out_of_range("The requested edge does not exist");
}
Node& nodeById(unsigned id)
{
typename map<unsigned, Node>::iterator node_it = nodesMap.find(id);
if(node_it != nodesMap.end())
return node_it->second;
throw out_of_range("The requested node does not exist");
}
Edge& edgeById(unsigned id)
{
typename map<unsigned, Edge>::iterator edge_it = edgesMap.find(id);
if(edge_it != edgesMap.end())
return edge_it->second;
throw out_of_range("The requested edge does not exist");
return std::make_pair(projective_edges, non_projective_edges);
}
protected:
......
......@@ -60,6 +60,10 @@ BOOST_AUTO_TEST_CASE(ProjectiveTreeTest){
BOOST_CHECK_EQUAL(ProjectiveTree.nodesSize(), 7);
BOOST_CHECK_EQUAL(ProjectiveTree.edgesSize(), 6);
BOOST_CHECK_EQUAL(ProjectiveTree.isProjective(), true);
P p = ProjectiveTree.testProjectivity();
BOOST_CHECK_EQUAL(p.first, 6);
BOOST_CHECK_EQUAL(p.second, 0);
}
BOOST_AUTO_TEST_CASE(NonProjectiveTreeTest){
......@@ -78,6 +82,10 @@ BOOST_AUTO_TEST_CASE(NonProjectiveTreeTest){
BOOST_CHECK_EQUAL(NonProjectiveTree.nodesSize(), 9);
BOOST_CHECK_EQUAL(NonProjectiveTree.edgesSize(), 8);
BOOST_CHECK_EQUAL(NonProjectiveTree.isProjective(), false);
P p = NonProjectiveTree.testProjectivity();
BOOST_CHECK_EQUAL(p.first, 6);
BOOST_CHECK_EQUAL(p.second, 2);
}
BOOST_AUTO_TEST_CASE(ProjectiveTreeWithRootTest){
......@@ -96,6 +104,10 @@ BOOST_AUTO_TEST_CASE(ProjectiveTreeWithRootTest){
BOOST_CHECK_EQUAL(ProjectiveTree.nodesSize(), 8);
BOOST_CHECK_EQUAL(ProjectiveTree.edgesSize(), 7);
BOOST_CHECK_EQUAL(ProjectiveTree.isProjective(), true);
P p = ProjectiveTree.testProjectivity();
BOOST_CHECK_EQUAL(p.first, 7);
BOOST_CHECK_EQUAL(p.second, 0);
}
BOOST_AUTO_TEST_CASE(NonProjectiveTreeWithRootTest){
......@@ -115,6 +127,10 @@ BOOST_AUTO_TEST_CASE(NonProjectiveTreeWithRootTest){
BOOST_CHECK_EQUAL(NonProjectiveTree.nodesSize(), 10);
BOOST_CHECK_EQUAL(NonProjectiveTree.edgesSize(), 9);
BOOST_CHECK_EQUAL(NonProjectiveTree.isProjective(), false);
P p = NonProjectiveTree.testProjectivity();
BOOST_CHECK_EQUAL(p.first, 7);
BOOST_CHECK_EQUAL(p.second, 2);
}
BOOST_AUTO_TEST_SUITE_END()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment