Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use c++ to write code cor the functions. size_t CountGroups () const: Return the number of connected components in the graph (i.e. the number of

Use c++ to write code cor the functions.

size_t CountGroups () const: Return the number of connected components in the graph (i.e. the number of groups who are connected by ANY activity).

size_t CountGroups(const std::string& relationship) const: Return the number of connected components in the graph after edges in the graph are filtered: only consider edges relationship.

size_t CountGroups(const std::vector& relationships) const: Return the number of connected components in the graph after edges in the graph are filtered: only consider edges in relationships.

Exist code:
class Graph {
public:
Constractor(const std::string &people_fpath, const std::string &relations_fpath);
size_t CountGroups () const;

size_t CountGroups(const std::string& relationship) const;

size_t CountGroups(const std::vector& relationships) const

void AddVertex(const std::string& vertex);
void AddEdge(const std::string& v1, const std::string& v2);
private:
bool VertexInGraph(const std::string vertex);
std::vector relation;
std::map> graph_;
};

bool Graph::VertexInGraph(const std::string vertex) {
return static_cast(graph_.count(vertex));
}
void Graph::AddEdge(const std::string& v1, const std::string& v2) {
if (!VertexInGraph(v1) || !VertexInGraph(v2)) {
throw std::runtime_error("invalid argument");
}
graph_.at(v1).push_back(v2);
graph_.at(v2).push_back(v1);
}
void Graph::AddVertex(const std::string& vertex) {
if (VertexInGraph(vertex))
throw std::runtime_error("vertex already in graph.");
graph_.insert({vertex, std::list()});
}
Graph::Constractor(const std::string &people_fpath, const std::string &relations_fpath) {
std::ifstream ifs{people_fpath};
for (std::string line; std::getline(ifs, line); line = "") {
AddVertex(line);
}
std::ifstream ifp{relations_fpath};
for (std::string line; std::getline(ifp, line); line = "") {
std::vector one;
one = utilities::Split(line, ',');
AddEdge(one[0], one[1]);
relation.push_back(one[2]);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

Calculate the number of neutrons of 239Pu.

Answered: 1 week ago