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

Improved return type for Kosaraju's algoritm + tests #260

Merged
merged 4 commits into from
Feb 9, 2023

Conversation

dvd2000
Copy link
Contributor

@dvd2000 dvd2000 commented Feb 7, 2023

I implemented the changes discussed in #251 concerning the return type of Kosaraju's algorithm (I hope this correspond to what you had in mind) and written a few tests for it (#221).

For the return type, I introduced a SCCResult type (Strongly Connected Components Result), similar to what has been done for other algorithms in the library. Let me know if I can improve my PR in some way.

@github-actions github-actions bot added core something about core repo something about repo test Something about test labels Feb 7, 2023
@ghost
Copy link

ghost commented Feb 7, 2023

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@dvd2000
Copy link
Contributor Author

dvd2000 commented Feb 7, 2023

I think I made some mistakes when merging to keep my fork updated, sorry
I'll fix that tomorrow

EDIT: Should be fixed now

@ZigRazor
Copy link
Owner

ZigRazor commented Feb 9, 2023

Good Work @dvd2000 !

@dvd2000
Copy link
Contributor Author

dvd2000 commented Feb 9, 2023

Glad I could contribute.

I'm still not completely convinced about the return type though. Specifically:

  • Wouldn't it be better if the returned connected components contained pointers to the vertex in the graph, instead of (subgraph) copies? I mean, if one wants to check which component a given vertex of the graph belongs to, I think it would make more sense to refer to vertices in the original graph than to vertices in a graph isomorphic/identical to the original. But this question applies to other algorithms in the library too (e.g. BFS, DFS). In some cases (e.g. Max flow, MST algorithms) we return vectors of pairs of strings for the edges, why don't we return vectors of pointers to edges instead? I general, I feel that the interface is a bit too heterogeneous concerning algorithms returns type.

  • With this choice of data structure (i.e. std::vector) it is kind of hard to get the strongly connected component for a given vertex (linear time search). Maybe doing something like what has been done for DialResult (i.e. unordered_map) could simplify this. And providing hashing for single vertices is not really a problem since they already have an id attribute.

@ZigRazor
Copy link
Owner

ZigRazor commented Feb 9, 2023

I think we can close this PR, and then rework it in a secondary issue.

  • Wouldn't it be better if the returned connected components contained pointers to the vertex in the graph, instead of (subgraph) copies? I mean, if one wants to check which component a given vertex of the graph belongs to, I think it would make more sense to refer to vertices in the original graph than to vertices in a graph isomorphic/identical to the original. But this question applies to other algorithms in the library too (e.g. BFS, DFS). In some cases (e.g. Max flow, MST algorithms) we return vectors of pairs of strings for the edges, why don't we return vectors of pointers to edges instead? I general, I feel that the interface is a bit too heterogeneous concerning algorithms returns type.

On the fact that we can return the pointer, i'm not sure is the correct way, the result can be modified and should not impact the original graph.

  • With this choice of data structure (i.e. std::vector) it is kind of hard to get the strongly connected component for a given vertex (linear time search). Maybe doing something like what has been done for DialResult (i.e. unordered_map) could simplify this. And providing hashing for single vertices is not really a problem since they already have an id attribute.

This second opportuniy can be evalueted in a new issue, maybe an unordered_map can be a good solution.

@ZigRazor ZigRazor merged commit 8f28627 into ZigRazor:master Feb 9, 2023
@ZigRazor ZigRazor self-assigned this Feb 9, 2023
This was linked to issues Feb 9, 2023
ZigRazor added a commit that referenced this pull request Mar 21, 2023
* introduce topological sort for graph (#247)

* implement topological sort based on dfs
* add benchmark for topological sort
* add basic test for topological sort

Co-authored-by: suncanghuai <suncanghuai@gmail.com>

* Fix typo in link specification (#248)

This PR removes an additional space character between link text and link URL, which caused faulty formatting of the README.md file.

* introduce WeightBalancedLibra algorithm(vertex-cut graph partition) (#249)

* implement WeightBalancedLibra algorithm based on paper pseudocode
* add weight-related apis for class CoordinatedPartitionState
* adjust set operations of class CoordinatedRecord
* append a testcase in PartitionTest.cpp for WB-Libra

Co-authored-by: suncanghuai <suncanghuai@hesaitech.com>

* Update README.md

* Update README.md

* Install the CodeSee workflow. Learn more at https://docs.codesee.io (#250)

Co-authored-by: codesee-maps[bot] <86324825+codesee-maps[bot]@users.noreply.github.com>

* * implement multi-thread bfs (#252)

* add testcases for multi-thread bfs(in BFSTest.cpp)
* add benchmark for multi-thread bfs(in BFS_BM.cpp)

Co-authored-by: suncanghuai <suncanghuai@gmail.com>

* Update Readme Roadmap

* Implement best first search (#254)

* first implementation and tests

* add docs and minor changes

* minor change

* minor change

* Update README.md

* Update README.md

* Include best first search test (#258)

* Update README for best first search algorithm (#257)

* Update README for best first search algorithm

* minor change

* minor change

* minor review changes

* Implement kahn's algorithm for topological sorting (#259)

* Improved return type for Kosaraju's algoritm + tests (#260)

* custom return type for kosaraju()

* Tests for Kosaraju's algorithm

* fixed minor issues

* fixed merge issue

* Update Road Map

* Update README.md

* Reworked Cmake

Signed-off-by: GitHub <noreply@github.com>

* Add partition Example ( HDRF )

Signed-off-by: GitHub <noreply@github.com>

* Corrected Partition Class
Fix #263

Signed-off-by: GitHub <noreply@github.com>

* Update Readme for Roadmap

Signed-off-by: GitHub <noreply@github.com>

* Corrected Cmake for old Example

Signed-off-by: GitHub <noreply@github.com>

* Update cmake.yml

* Update benchmark_pr.yml

* Update benchmark.yml

* Update Code_Coverage.yml

* Correction for Graph.hpp

Signed-off-by: GitHub <noreply@github.com>

* Update Code_Coverage.yml

Parallel compilation

* Update benchmark.yml

parallel compilation

* Update benchmark_pr.yml

parallel compilation

* Update cmake.yml

parallel compilation

* Update codeql-analysis.yml

remove useless steps:
- manually installed google test and benchmark

* Create .github/workflows/super-linter.yml

Added Super-Linter

* Update super-linter.yml

* Create .clang-format

* Reformatted Files
with clang-format with syle "Google"

Signed-off-by: GitHub <noreply@github.com>

* Delete super-linter.yml

* Create .github/workflows/codeql.yml

* Delete codeql-analysis.yml

* Update README.md

* Create .github/workflows/codacy.yml

* Create .github/workflows/snyk-security.yml

* Update snyk-security.yml

* Delete snyk-security.yml

---------

Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: ARockHammer <37604654+SunCangHuai@users.noreply.github.com>
Co-authored-by: suncanghuai <suncanghuai@gmail.com>
Co-authored-by: David Chocholatý <chocholaty.david@protonmail.com>
Co-authored-by: suncanghuai <suncanghuai@hesaitech.com>
Co-authored-by: codesee-maps[bot] <86324825+codesee-maps[bot]@users.noreply.github.com>
Co-authored-by: Pradeep Krishnamurthy <pradkrish84@gmail.com>
Co-authored-by: David Sapienza <david.sapienza@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core something about core repo something about repo test Something about test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return type of Kosaraju Add Tests for Kosaraju Algorithm
2 participants