Cytoscape JS - Different Weights based on Direction for Dijkstra's

449 Views Asked by At

Trying to get Cytoscape JS to behave for me but running into some usability issues that I don't know if it's me or a limitation of the library.

Primary problem is wanting to use different weights based on direction. A to B should have weight 3, but B to A should have weight 6, for example. There's only one edge defined since the docs say source/target are ignored in undirected graphs.

I'm solving this so far by storing the weight on the node itself, and I thought I had it worked out in dijkstra's weight function by examining edge.target() to get the desired weight.

But, I think edge.target() seems to conform only to the one-way relationship defined when I set up the edges despite specifying directed = false to the algorithm. If I'm coming at it from the other direction I seem to get the wrong weight.

So my question is.. how do I properly obtain the node target that dijkstra is finding weight for, inside the weight function where all I have is the edge object? My graph has circular paths so a node can be approached from two directions and a single weight won't work.

1

There are 1 best solutions below

1
On BEST ANSWER

Well I solved this by editing cytoscape.js and modifying Dijkstra's to pass the actual target node into the weight function:

var weight = weightFn.apply( edge, [ edge, v ] );

That allows me to grab the weight that I store on the node itself.

I'd still be interested if there's a property in the edge object that provides the actual target, but the main question has been answered.