-
Notifications
You must be signed in to change notification settings - Fork 242
cpp: improves RmatGenerator and tests #1164
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
Conversation
c9ef083 to
fefdbe7
Compare
fefdbe7 to
f5585ca
Compare
fabratu
left a comment
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.
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 { |
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.
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) { |
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.
As above (while).
| entryList[lastOverfullIndex].probability -= delta; | ||
| coinFlipReplacement[curUnderfullIndex] = lastOverfullIndex; | ||
| coinFlipProbability[curUnderfullIndex] = | ||
| (uint32_t)(delta / baseProbability * std::numeric_limits<uint32_t>::max()); |
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.
As above (casting).
| return; | ||
| } | ||
| int curUnderfullIndex = lastUnderfullIndex; | ||
| while (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.
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); |
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.
Use static_cast instead of C-style casts.
| Graph generate() override; | ||
|
|
||
| private: | ||
| void sample(std::mt19937_64 &urng); |
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.
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; |
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.
As above (casting).
| double baseProbability = 1.0 / (double)size; | ||
| count lastOverfullIndex = 0; | ||
| count lastUnderfullIndex = 0; | ||
| while (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.
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); }); |
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.
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); |
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.
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.
This code originated as bachelors thesis at MACSy, it has been copied without extensive sanity checks, feel free to comment on possible improvements.