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

Implementation of algorithms on cographs #23

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

Conversation

aSmallTyphoon
Copy link

No description provided.

Copy link
Owner

@krzysztof-turowski krzysztof-turowski left a 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.

Comment on lines 14 to 15
std::ifstream fin("../../input/cographConnected11.g6");
//std::ifstream fin("../../input/graph8c.g6");

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)

std::string types[] = {
"UNKNOWN",
"COGRAPH",
"IS_NOT_COGRAPH"

Choose a reason for hiding this comment

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

Suggestion: "NOT_COGRAPH"

Comment on lines 30 to 41
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;
}

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

@@ -20,6 +20,7 @@ int main() {
};

while (true) {
std::ifstream fin("../../input/");

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) {

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.

class Cotree {
public:
NetworKit::Graph *graph;
std::vector<long long> left_son, right_son, parent, type, size, color, number_of_colors;

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)

@@ -0,0 +1,10 @@
koala_add_module(cograph_rec

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.


long long MaxIndependetSetSize(long long n, long long v);

long long GetMaxIndependetSetSize();

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.

Comment on lines 57 to 60
for (int i = 0; i < 2 * n + 2; i++) {
color.push_back(0);
number_of_colors.push_back(0);
}

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

return color[i];
}

bool Cotree::CheckColoring() {

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.

Copy link
Owner

@krzysztof-turowski krzysztof-turowski left a 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.

@@ -8,3 +8,5 @@ add_subdirectory(mst)
add_subdirectory(recognition)
add_subdirectory(set_cover)
add_subdirectory(traversal)
add_subdirectory(max_clique)
add_subdirectory(structures)

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) {

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

Comment on lines 68 to 73
NetworKit::count CographVertexColoring::GetColor(NetworKit::count i) {
if (recognition->cotree->prepared == false) {
recognition->cotree->BuildTree();
}
return color[i];
}

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;
}
}

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;

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=";

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);

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()?

#include "recognition/CographAlg.hpp"

namespace Koala {
NetworKit::count MaxClique::recurse_run(NetworKit::count n, NetworKit::count v) {

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

}

NetworKit::count Pathwidth::pathwidth(NetworKit::count n, NetworKit::count v) {
if (recognition->cotree->nodes[v].type == 2) {

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.

Comment on lines 57 to 59
if (recognition->cotree->prepared == false) {
recognition->cotree->BuildTree();
}

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()?

@aSmallTyphoon aSmallTyphoon changed the title first version Implementation of algorithms on cographs Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
algorithms New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants