Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: #419, Issue: #238, and Issue: #240 #422

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Saj18
Copy link

@Saj18 Saj18 commented Apr 30, 2024

#419
-Implemented the deleteNodeById function in the Graph class to delete a node by its ID.
-Utilized a lambda function with std::find_if to search for the node with the provided ID within the unordered map of nodes.
-If the node is found, it is erased from the map using nodes.erase(it).
-Returns true if the node is successfully deleted and false if the node is not found.

#238

  • Implemented Dinic's algorithm for finding the maximum flow in a flow network.
  • Added necessary methods and data structures to the Graph class.
  • Implemented BFS and DFS helper functions for the algorithm.

#240

  1. Implemented Krager's algorithm for partitioning a graph into two clusters.
  2. Added the kragersAlgorithm method to the Graph class.
  3. Added necessary data structures and utilities to support the algorithm.
  4. Utilized randomization for edge selection within the algorithm.

@Saj18 Saj18 changed the title Issue: #419 and Issue: #238 Issue: #419, Issue: #238, and Issue: #240 Apr 30, 2024
@ZigRazor ZigRazor requested review from ZigRazor, sbaldu and nolankramer and removed request for ZigRazor April 30, 2024 07:12
Copy link
Owner

@ZigRazor ZigRazor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve the comment and we can merge it. Good Work, just some details to adjust!

std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities;
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow;

bool bfs(const CXXGraph::id_t& source, const CXXGraph::id_t& sink, std::unordered_map<CXXGraph::id_t, int>& distance) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding a new bfs implementation? can you use the provided one?

return distance[sink] != -1;
}

int dfs(const CXXGraph::id_t& current, const CXXGraph::id_t& sink, int flow_value, std::unordered_map<CXXGraph::id_t, int>& distance) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding a new dfs implementation? can you use the provided one?

template <typename T>
class Graph {
private:
std::unordered_map<CXXGraph::id_t, Node<T>> nodes;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be a class variable, reduce the scope of the variable to the minimum required

template <typename T>
class Graph {
private:
std::unordered_map<CXXGraph::id_t, Node<T>> nodes;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Graph_decl.h we already have the node set and the adjiacency matrix, you should use them

// Other graph methods...

// Function to add an edge between two nodes
void addEdge(const std::string& from_id, const std::string& to_id) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is a repetition of the already implemented function in Graph_impl.hpp, you should use it

std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities;
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow;

bool bfs(const CXXGraph::id_t& source, const CXXGraph::id_t& sink, std::unordered_map<CXXGraph::id_t, int>& distance) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing bfs and dfs (and Dinic's!).

These actually seem generally useful. Should we consider making them public? (assuming the storage requirement would need to change given the above comment).

Comment on lines +16 to +17
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities;
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this adds more storage to the graph, which makes it a larger object/heavier. Thoughts on this @sbaldu, @ZigRazor? Perhaps the relevant storage of the algorithm should be extracted elsewhere (and possibly the algorithm implementation itself) so that this storage is temporary.

There are other options, such as lazy storage creation on the heap the first time a dfs, bfs, or Dinic's is called. Although the storage for std::unordered_map isn't wild - I do like keeping Graph as lightweight as can possibly be done.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Agree!

Comment on lines +73 to +83
bool deleteNodeById(const std::string &id) {
auto it = std::find_if(nodes.begin(), nodes.end(), [&](const auto &pair) {
return pair.second.getUserId() == id;
});

if (it != nodes.end()) {
nodes.erase(it);
return true; // Node deleted successfully
}
return false; // Node not found
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 🙏

@ZigRazor ZigRazor self-assigned this Apr 30, 2024
@ZigRazor ZigRazor added enhancement New feature or request development Development of new Functionalities core something about core labels Apr 30, 2024
@ZigRazor ZigRazor added this to the Algorithm Implementation milestone Apr 30, 2024
@ZigRazor
Copy link
Owner

Another things, can you add tests for your algorithm implementation and for the node search by ID?
Thank you in advance!

@nolankramer
Copy link
Collaborator

nolankramer commented Apr 30, 2024

My comments largely reflect @ZigRazor's comments, so mine can be ignored.

Comment on lines +73 to +76
bool deleteNodeById(const std::string &id) {
auto it = std::find_if(nodes.begin(), nodes.end(), [&](const auto &pair) {
return pair.second.getUserId() == id;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to include algorithm in order to use std::find_if

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES

Comment on lines +12 to +17
template <typename T>
class Graph {
private:
std::unordered_map<CXXGraph::id_t, Node<T>> nodes;
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities;
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why is he re-declaring the Graph class? Shouldn't he simply add the declaration of the method in Graph_decl.hpp and add a header for the implementation of the single method?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core something about core development Development of new Functionalities enhancement New feature or request
Projects
None yet
5 participants