Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixing one off in the uniform_on_restart bug.#207

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kieronqtran wants to merge2 commits intoGecode:release/6.3.0
base:release/6.3.0
Choose a base branch
Loading
fromkieronqtran:fix_uniform_on_restart

Conversation

@kieronqtran
Copy link

@kieronqtrankieronqtran commentedOct 17, 2025
edited
Loading

This pull request makes a small but important fix to the random value assignment logic in thegecode/flatzinc/flatzinc.cpp file. The change ensures that the generated random integer values can include the upper bound of the specified range, correcting an off-by-one error. This is happened becasueRnd _random input domain is[lower_bound, upper_bound) and+ 1 to correct set to[lower_bound, upper_bound], and it is effect touniform_on_restart constraints.

  • Fixed the calculation of random values for uniform integer ranges to include the upper bound by changing the random range from(range.second - range.first) to(range.second - range.first + 1).

@Dekker1
Copy link
Contributor

This fix looks good to me. As you pointed out, I didn't see that theRnd::operator() gives a value in the range[0,n) instead of[0,n] as I expected.

The same issue actually is also present for floating point, although in a different form:

const FloatVal rndVal = (static_cast<FloatVal>(_random(INT_MAX)) / INT_MAX)*(range.second - range.first) + range.first;

This will never reach the upper bound, as the division will never reach one becauseINT_MAX is excluded. To fix this, we might have to give up some of the granularity in the division and reduce the right-hand side of the division:

const FloatVal rndVal = (static_cast<FloatVal>(_random(INT_MAX)) / (INT_MAX-1))*(range.second - range.first) + range.first;

This seems fine, and I think any other fix would require an inclusive version of the random number generator, which would be more work.

@kieronqtran
Copy link
Author

Updated for uniform_on_researt for float. Thank@Dekker1

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@kieronqtran@Dekker1

[8]ページ先頭

©2009-2025 Movatter.jp