Skip to content

Conversation

@PetholzA
Copy link
Contributor

This code originated as bachelors thesis at MACSy, it has been copied without extensive sanity checks, feel free to comment on possible improvements.

@PetholzA PetholzA marked this pull request as draft January 19, 2024 13:07
@PetholzA PetholzA force-pushed the feature/20240119_improve_generators_rmat branch from c9ef083 to fefdbe7 Compare January 22, 2024 11:25
@PetholzA PetholzA force-pushed the feature/20240119_improve_generators_rmat branch from fefdbe7 to f5585ca Compare January 22, 2024 13:18
Copy link
Member

@fabratu fabratu left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of the integration. In addition, please update the Python bindings and add tests (if needed) for the new parameter.

}

// std::priority_queue doesn't support iterating over its elements.
struct PriorityQueue {
Copy link
Member

Choose a reason for hiding this comment

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

Better use Aux::PrioQueue instead.


std::pair<node, node> RmatGenerator::sampleEdge(std::mt19937_64 &urng, uint8_t bits) {
std::pair<node, node> result{0, 0};
while (true) {
Copy link
Member

Choose a reason for hiding this comment

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

As above (while).

entryList[lastOverfullIndex].probability -= delta;
coinFlipReplacement[curUnderfullIndex] = lastOverfullIndex;
coinFlipProbability[curUnderfullIndex] =
(uint32_t)(delta / baseProbability * std::numeric_limits<uint32_t>::max());
Copy link
Member

Choose a reason for hiding this comment

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

As above (casting).

return;
}
int curUnderfullIndex = lastUnderfullIndex;
while (true) {
Copy link
Member

Choose a reason for hiding this comment

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

As above (while).

throw std::runtime_error("Probabilities in Rmat have to sum to 1.");
defaultEdgeWeight = 1.0;

count size = 1 << std::min((count)12, (count)std::round(scale * 5.0 / 8.0) + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Use static_cast instead of C-style casts.

Graph generate() override;

private:
void sample(std::mt19937_64 &urng);
Copy link
Member

Choose a reason for hiding this comment

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

sample is a generic function name. Also, it is only used in sampleEdge and using internal states based on that. Better implement it directly as a lambda function inside sampleEdge.

coinFlipProbability[i] = 0;
coinFlipReplacement[i] = 0;
}
double baseProbability = 1.0 / (double)size;
Copy link
Member

Choose a reason for hiding this comment

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

As above (casting).

double baseProbability = 1.0 / (double)size;
count lastOverfullIndex = 0;
count lastUnderfullIndex = 0;
while (true) {
Copy link
Member

Choose a reason for hiding this comment

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

Avoid using while(true) for both readability and maintainability. Use do {} while(...) instead.


return std::make_pair(u, v);
});
auto drawEdge([&]() { return sampleEdge(Aux::Random::getURNG(), (uint8_t)scale); });
Copy link
Member

Choose a reason for hiding this comment

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

As above (casting). Also use sampleEdge, since drawEdge simply now calls this.

private:
void sample(std::mt19937_64 &urng);

std::pair<node, node> sampleEdge(std::mt19937_64 &urng, uint8_t bits);
Copy link
Member

Choose a reason for hiding this comment

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

Check whether urng can be moved to a member variable. This is what is normally done in other algorithm classes. This would then also remove the need for passing it as a parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants