Skip to main content
added 11 characters in body
Source Link
Ash
  • 31
  • 2

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include or exclude a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from f',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from f',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include or exclude a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from f',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 
Tweeted twitter.com/StackGIS/status/1037264329303830528
deleted 3 characters in body
Source Link
Ash
  • 31
  • 2

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from express1_path'f',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from express1_path',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from f',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 
added 25 characters in body
Source Link
geozelot
  • 30.9k
  • 4
  • 34
  • 57

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation FROM pgr_ksp('Select id, source, target, airmiles as cost from express1_path', source, target, 2) AS d INNER JOIN f ON d.edge= f.id ORDER BY aggregation, path_id, path_seq;

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from express1_path',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation FROM pgr_ksp('Select id, source, target, airmiles as cost from express1_path', source, target, 2) AS d INNER JOIN f ON d.edge= f.id ORDER BY aggregation, path_id, path_seq;

I am using pgr_ksp algorithm to find out the shortest path between a startnode and endnode by creating a network topology between all the nodes. Pgr_ksp algorithm very well gives me all the shortest paths taking the cost in consideration. But now, I also want to add a constraint that the path its giving between startnode and endnode must include a particular node or link. Below code works perfect. But how and where can I add a constraint such that the path will include a node for example 'nodeA'?

SELECT d.*, f.linkname ,SUM(cost) OVER (PARTITION BY path_id) AS aggregation
FROM pgr_ksp('Select id, source, target, airmiles as cost from express1_path',
source,
target,
 2) AS d
INNER JOIN f ON d.edge= f.id
ORDER BY aggregation, path_id, path_seq; 
added 392 characters in body
Source Link
Ash
  • 31
  • 2
Loading
Source Link
Ash
  • 31
  • 2
Loading