Skip to content

Commit 47df7e9

Browse files
committed
fix: clarify warnings to say distances are rounded, not truncated
1 parent 456fee4 commit 47df7e9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ you want to have it added here, please open an issue.
119119
Technical Notes
120120
-------
121121

122-
**Coordinate scaling:** Concorde computes distances using integer arithmetic.
123-
If your coordinates are small (e.g. in [0, 1]), distances between points will
124-
be rounded to 0, leading to incorrect results or crashes. Scale your
122+
**Coordinate scaling:** Concorde rounds all edge distances to the nearest
123+
integer. If your coordinates are small (e.g. in [0, 1]), distances between
124+
points will round to 0, leading to incorrect results or crashes. Scale your
125125
coordinates up before passing them to the solver — for example, multiply by
126126
1e6. Similarly, very large coordinates (above 1e7) may cause integer overflow.
127127
See `examples/truncation_demo.py` for a demonstration.

concorde/tests/test_concorde_datagroup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_from_data_warns_small_coordinates(self):
3030
ys = [0.2, 0.6, 0.8]
3131
with self.assertWarns(UserWarning) as ctx:
3232
TSPSolver.from_data(xs, ys, "EUC_2D")
33-
self.assertIn("[-1, 1]", str(ctx.warning))
33+
self.assertIn("rounds distances", str(ctx.warning))
3434

3535
def test_from_data_warns_large_coordinates(self):
3636
# Large coordinates risk integer overflow in Concorde

concorde/tsp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ def from_data(cls, xs, ys, norm, name=None):
5252

5353
if max_abs <= 1.0:
5454
warnings.warn(
55-
"All coordinates are in [-1, 1]. Concorde uses integer "
56-
"distances internally, so small coordinates will be "
57-
"truncated to 0. Consider scaling your coordinates "
58-
"(e.g. multiply by 1e6).",
55+
"All coordinates are in [-1, 1]. Concorde rounds "
56+
"distances to the nearest integer, so distances "
57+
"between nearby points will round to 0. Consider "
58+
"scaling your coordinates (e.g. multiply by 1e6).",
5959
UserWarning,
6060
stacklevel=2,
6161
)
6262
if max_abs > 1e7:
6363
warnings.warn(
64-
"Coordinates exceed 1e7. Large values may cause integer "
65-
"overflow in Concorde, leading to incorrect results or "
64+
"Coordinates exceed 1e7. Concorde rounds distances "
65+
"to the nearest integer, and large values may cause "
66+
"integer overflow, leading to incorrect results or "
6667
"crashes. Consider scaling down.",
6768
UserWarning,
6869
stacklevel=2,

0 commit comments

Comments
 (0)