-
Notifications
You must be signed in to change notification settings - Fork 9
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
Implementation of algorithms on cographs #23
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your work - I have a lot of conceptual comments for now (especially since the proper logic seems to be good) and some stylistic measure, please let me know if everything is clear and sound.
benchmark/benchmarkCograph_rec.cpp
Outdated
std::ifstream fin("../../input/cographConnected11.g6"); | ||
//std::ifstream fin("../../input/graph8c.g6"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just provide the name of the file in cin (as in benchmarkPerfectGraphs.cpp)
benchmark/benchmarkCograph_rec.cpp
Outdated
std::string types[] = { | ||
"UNKNOWN", | ||
"COGRAPH", | ||
"IS_NOT_COGRAPH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: "NOT_COGRAPH"
benchmark/benchmarkCograph_rec.cpp
Outdated
if (recognize.cotree->GetMaxIndependetSetSize() != recognize.cotree->BruteForceIndependetSetSize()) { | ||
std::cout << "error1" << std::endl; | ||
} | ||
|
||
if (recognize.cotree->GetMaxCliqueSize() != recognize.cotree->BruteForceCliqueSize()) { | ||
std::cout << "error2" << std::endl; | ||
} | ||
|
||
recognize.cotree->Coloring(); | ||
if (!recognize.cotree->CheckColoring()) { | ||
std::cout << "error3" << std::endl; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually please turn these checks to asserts
benchmark/benchmarkPerfectGraphs.cpp
Outdated
@@ -20,6 +20,7 @@ int main() { | |||
}; | |||
|
|||
while (true) { | |||
std::ifstream fin("../../input/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line
#include "cograph_rec/Cotree.hpp" | ||
|
||
namespace Koala { | ||
long long Cotree::MaxIndependetSetSize(long long n, long long v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go everywhere with NetworKit::count instead of long long unless you have a good reason to enforce this.
include/cograph_rec/Cotree.hpp
Outdated
class Cotree { | ||
public: | ||
NetworKit::Graph *graph; | ||
std::vector<long long> left_son, right_son, parent, type, size, color, number_of_colors; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to create an auxiliary structure CoNode with fields left, right, parent, type and define std::vector here (if it's a vector of structs, they are also allocated as chunks of continuous memory, unlike vector of pointers, so it's fast)
cpp/cograph_rec/CMakeLists.txt
Outdated
@@ -0,0 +1,10 @@ | |||
koala_add_module(cograph_rec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually you should split this across multiple modules: recognition, coloring, independent set. Please look at the PerfectGraphColoring.hpp/cpp for the scheme.
include/cograph_rec/Cotree.hpp
Outdated
|
||
long long MaxIndependetSetSize(long long n, long long v); | ||
|
||
long long GetMaxIndependetSetSize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be CoTree methods, rather separate classes inheriting from NetworKit::Algorithms in their proper places, please check the existing algorithms for the scheme.
cpp/cograph_rec/cograph/Coloring.cpp
Outdated
for (int i = 0; i < 2 * n + 2; i++) { | ||
color.push_back(0); | ||
number_of_colors.push_back(0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, vector.resize is the way
cpp/cograph_rec/cograph/Coloring.cpp
Outdated
return color[i]; | ||
} | ||
|
||
bool Cotree::CheckColoring() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you implement a proper CographColoring class and inherit from VertexColoringAlgorithm class, then you'll get check method for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much, again quite a lot of conceptual changes suggested - please reach me on- or offline for further clarifications, if necessary.
cpp/CMakeLists.txt
Outdated
@@ -8,3 +8,5 @@ add_subdirectory(mst) | |||
add_subdirectory(recognition) | |||
add_subdirectory(set_cover) | |||
add_subdirectory(traversal) | |||
add_subdirectory(max_clique) | |||
add_subdirectory(structures) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1) Please add empty line at the end
(2) Please sort the subdirs alphabetically
|
||
namespace Koala { | ||
void CographVertexColoring::SubtreeColors(NetworKit::count v) { | ||
if (recognition->cotree->nodes[v].left_son != -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please insert as a first line
auto &cotree_v = recognition->cotree->nodes[v];
It would drastically shorten the subsequent code
NetworKit::count CographVertexColoring::GetColor(NetworKit::count i) { | ||
if (recognition->cotree->prepared == false) { | ||
recognition->cotree->BuildTree(); | ||
} | ||
return color[i]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd replace it with getColoring
returning a map (as e.g. in VertexColoring) + this map would be built during run.
} | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix empty line at the end
} | ||
|
||
bool CographVertexColoring::CheckColoring() { | ||
NetworKit::count n = graph->numberOfNodes(), i, j; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use (unsafe) C-style way of defining temporary variables unitinialized and outside of for loop. That's just really bad idiom, unless absolutely necessary.
std::cout << y->num << " "; | ||
} | ||
} | ||
std::cout << " pivot="; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I guess these shouldn't be left here - and in few other places.
if (cotree->prepared == false) { | ||
cotree->BuildTree(); | ||
} | ||
independet_set_size = recurse_run(n, n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you always pass n as the first parameter? If so, why can't you just get it via G.numberOfNodes()
?
cpp/max_clique/MaxClique.cpp
Outdated
#include "recognition/CographAlg.hpp" | ||
|
||
namespace Koala { | ||
NetworKit::count MaxClique::recurse_run(NetworKit::count n, NetworKit::count v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, you never use the first parameter in the method
cpp/pathwidth/Pathwidth.cpp
Outdated
} | ||
|
||
NetworKit::count Pathwidth::pathwidth(NetworKit::count n, NetworKit::count v) { | ||
if (recognition->cotree->nodes[v].type == 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, extracting recognition->cotree->nodes[v]
to an autoref variable would simplify your code a lot.
cpp/pathwidth/Pathwidth.cpp
Outdated
if (recognition->cotree->prepared == false) { | ||
recognition->cotree->BuildTree(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you check if cotree is prepared if you already forced computing it using recognition->run()
?
No description provided.