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

Simple, safe float comparisons #128

Merged
merged 7 commits into from
Sep 29, 2023

Conversation

ImogenBits
Copy link
Collaborator

@ImogenBits ImogenBits commented Sep 28, 2023

This adds an easy way to perform safe float comparisons, to fix the problems we mentioned in the meeting last week. I think the way this works is best illustrated with an example:

Let's say the problem instances contain a set of points and the solution contains a circle of some radius that should cover as many of these points as possible. The issue we now run into when naively comparing

distance(center, point) <= size

is that the instance points might be placed in such a way that this calculated distance is bigger than size because of float rounding errors. This can be solved by instead comparing

distance(center, point) <= size + epsilon

But this will now run into issues if the generating team intentionally places points in such a way that the rounding error occur at size + epsilon rather than just size. Another problem case is when the floats involved are being computed with big intermediate values, then the rounding errors might be bigger than the constant epsilon.

This PR lets you easily sidestep both issues by just comparing like this:

distance(center, point) <= LaxComp(size, role)

or alternatively

lax_comp(distance(center, point), "<=", size, role)

depending on your syntax preference. This will automatically perform the comparison including an epsilon that adjusts to the total size of the involved values and doubles this fudge factor for the solving team.

@Benezivas
Copy link
Collaborator

This looks like a good way to handle float rounding imprecisions, thank you

@Benezivas Benezivas merged commit a559a52 into Algorithmic-Battle:4.0.0-rc Sep 29, 2023
@ImogenBits ImogenBits deleted the float_types branch September 30, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants