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

2.2.4: change(pivot2pgr): do not use clean_graph() procedure #75

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## x.y.z

## 2.2.4

CHANGED:
- Pivot to pgr: Not using clean_grpah method anymore, but a SQL query

## 2.2.3

CHANGED:
Expand Down
2 changes: 1 addition & 1 deletion r2gg/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
__uri_tracker__ = f"{__uri_repository__}issues/"
__uri__ = __uri_repository__

__version__ = "2.2.3"
__version__ = "2.2.4"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
Expand Down
34 changes: 32 additions & 2 deletions r2gg/_pivot_to_pgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,43 @@ def pivot_to_pgr(source, cost_calculation_file_path, connection_work, connection

for profile_name in profile_names:
logger.info("Cleaning isolated edges for profile {}...".format(profile_name))
clean_graph_query = "SELECT {0}.clean_graph('{1}')".format(schema, profile_name)
clean_graph_query = """
WITH connected_components AS (
SELECT * FROM pgr_connectedComponents(
'SELECT id, source, target, cost_s_{1} as cost, reverse_cost_s_{1} as reverse_cost FROM {0}.ways'
)
),
remove_nodes AS (
SELECT node
FROM
connected_components
WHERE
component = ANY(
SELECT DISTINCT component
FROM
(
SELECT component, count(*) AS nb
FROM
connected_components
GROUP BY component
)
AS components
WHERE nb <= 10
)
)
UPDATE {0}.ways
SET cost_s_{1} = -1,
reverse_cost_s_{1} = -1,
cost_m_{1} = -1,
reverse_cost_m_{1} = -1
WHERE {0}.ways.target = ANY(SELECT * from remove_nodes) OR {0}.ways.source = ANY(SELECT * from remove_nodes);
""".format(schema, profile_name)
logger.info("SQL: {}".format(clean_graph_query))
cursor_isolated.execute(clean_graph_query)
connection_out.commit()

et_execute = time.time()
logger.info("Execution ended. Elapsed time : %s seconds." %(et_execute - st_execute))
connection_out.commit()
cursor_isolated.close()

end_time = time.time()
Expand Down
Loading