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

Random std::bad_alloc when using pgr_TSP on OSM data #1206

Open
amasciotta opened this issue May 24, 2019 · 2 comments
Open

Random std::bad_alloc when using pgr_TSP on OSM data #1206

amasciotta opened this issue May 24, 2019 · 2 comments

Comments

@amasciotta
Copy link

I'm experiencing random std::bad_alloc when calling pgr_TSP.
My query is

SELECT * FROM pgr_TSP(
    $$
	SELECT * FROM pgr_withPointsCostMatrix(
        'SELECT id, source, target, cost, reverse_cost FROM osm.ways ORDER BY id',
        'SELECT pid, edge_id, fraction from osm.TSPpoints',
        array[-1, -2, -3, -4], directed := false);
    $$,
    randomize := false
);

The error that I see on the output is

ERROR:  std::bad_alloc
HINT:  pgr_eucledianTSP Processing Information 
Initializing tsp class ---> tsp.greedyInitial --->
SQL state: XX000

The error doesn't happen every time but only randomly, once every 3-5 tries. When there is no error, the query returns successfully and the output is correct.

I'm using this dataset (the zip file contains an .osm file, downloaded from the OSM site) that I have imported with osm2pgrouting utility (the Windows version, that I found available in my local PostgreSQL installation path) : the osm.ways table contains 2188 rows. Morevoer, the osm.TSPpoints table contains 4 rows: its content can be found in this csv file.

I never get the error when running with the sample data available from the pgrouting documentation (I've tried running the query 20-30 times).

I'm using

PostgreSQL 11.3, compiled by Visual C++ build 1914, 64-bit

POSTGIS="2.5.2 r17328" [EXTENSION] PGSQL="110" GEOS="3.7.0-CAPI-1.11.0 3.7.1" SFCGAL="1.3.2" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.4, released 2018/03/19" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" TOPOLOGY RASTER

(2.6.2,v2.6.2,b14f4d56b,master,1.59.0)

@cvvergara
Copy link
Member

I wonder if you have the same problem when using the current master branch?

@uzmaansari23
Copy link

The pgr_eucledianTSP function is used to solve the Travelling Salesman Problem (TSP) for a set of points using an Euclidean distance matrix. One possible reason for this error is that the function is trying to allocate too much memory for the distance matrix, either because there are too many points or because the coordinates of the points are very large.

To fix this issue, you may try the following solutions:

  1. Reduce the number of points: If the number of points is large, try reducing it. Depending on the application, you may be able to get away with only visiting a subset of the points.

2.Check the coordinate system: Ensure that the coordinate system is appropriate for the location of the points. If the points are in a large geographic area, consider using a geographic coordinate system rather than a projected one.

3.Optimize the memory usage: Check the memory usage of the system and try to optimize it. You can reduce the memory usage of the program by running it on a machine with more memory or reducing the size of other running programs.

4.Use another algorithm: If the problem persists, try using another algorithm that is better suited for your data. For example, the pgr_TSP function can solve the TSP using a variety of algorithms, and some may be more memory-efficient than others.

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

No branches or pull requests

3 participants