Skip to content

Commit

Permalink
Update for components
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesBremner committed Oct 26, 2023
1 parent 4ffc111 commit f706686
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 27 deletions.
31 changes: 16 additions & 15 deletions src/GraphTheory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,8 @@ namespace raven
return path;
}

void components(
std::vector<path_t> components(
const cGraph &g,
std::string &results,
bool fclique)
{
// working copy on input graph
Expand Down Expand Up @@ -744,19 +743,21 @@ namespace raven
vclique.push_back(clique);
}

// Display results
std::stringstream ss;
std::string comp_clique = "component ";
if( fclique )
comp_clique = "clique ";
for (auto &c : vclique)
{
ss << comp_clique;
for (int n : c)
ss << g.userName(n) << " ";
ss << "\n";
}
results = ss.str();
return vclique;

// // Display results
// std::stringstream ss;
// std::string comp_clique = "component ";
// if( fclique )
// comp_clique = "clique ";
// for (auto &c : vclique)
// {
// ss << comp_clique;
// for (int n : c)
// ss << g.userName(n) << " ";
// ss << "\n";
// }
// results = ss.str();
}

double
Expand Down
6 changes: 3 additions & 3 deletions src/GraphTheory.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ namespace raven

/// @brief find components or cliques
/// @param g
/// @param[out] results
/// @param clique true for cliques, default false
/// @return vector of vectors of vertex indices in each component
///
/// the vertices in a component are all reachable from each other
/// the vertices in a clique are all adjacent

void components(
std::vector<path_t> components(
const cGraph &g,
std::string &results,
bool clique = false);


Expand Down
28 changes: 23 additions & 5 deletions src/cPathFinderGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,34 @@ void cGUI::calcSales()

void cGUI::calcComponents()
{
components(
myGraphData.g,
myResultText);
auto vclique = components(
myGraphData.g);
std::stringstream ss;
std::string comp_clique = "component ";
for (auto &c : vclique)
{
ss << comp_clique;
for (int n : c)
ss << myGraphData.g.userName(n) << " ";
ss << "\n";
}
myResultText = ss.str();
}
void cGUI::calcCliques()
{
components(
auto vclique = components(
myGraphData.g,
myResultText,
true);
std::stringstream ss;
std::string comp_clique = "clique ";
for (auto &c : vclique)
{
ss << comp_clique;
for (int n : c)
ss << myGraphData.g.userName(n) << " ";
ss << "\n";
}
myResultText = ss.str();
}

void cGUI::calcFlows()
Expand Down
21 changes: 17 additions & 4 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,23 @@ TEST(cliques)
raven::graph::sGraphData gd;
gd.fname = "../dat/cliques.txt";
readfile(gd);
std::string results;
cliques(gd.g, results,false);
std::string expected("clique: 1 5 3 7 \nclique: 2 8 6 4 \n");
CHECK_EQUAL(expected, results);
auto vclique = components(gd.g, false);
CHECK_EQUAL(2, vclique.size());
std::vector<std::vector<std::string>> exp{
{"1", "5", "3", "7"},
{"2", "8", "6", "4"}};
auto svclique = gd.g.userName( vclique[0] );
CHECK(std::equal(
exp[0].begin(),
exp[0].end(),
svclique.begin()));
svclique = gd.g.userName( vclique[1] );
CHECK(std::equal(
exp[1].begin(),
exp[1].end(),
svclique.begin()));
// std::string expected("clique: 1 5 3 7 \nclique: 2 8 6 4 \n");
// CHECK_EQUAL(expected, results);
}

// TEST(dfs_allpaths)
Expand Down

0 comments on commit f706686

Please sign in to comment.