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

Migrate FloydWarshall Algorithm #8

Open
clue opened this issue Feb 25, 2015 · 3 comments
Open

Migrate FloydWarshall Algorithm #8

clue opened this issue Feb 25, 2015 · 3 comments

Comments

@clue
Copy link
Member

clue commented Feb 25, 2015

Migrate graphp/graph#71 (refs graphp/graph#119)

@InterLinked1
Copy link

Is this still being 'migrated' from somewhere or is the idea to write something new here?

@clue
Copy link
Member Author

clue commented Sep 17, 2020

I still think that this feature makes perfect sense 👍 However, there are currently no immediate plans to build this from my end (no demand at the moment and more important outstanding issues currently), but I would be really happy to accept PRs 👍

(If you need this for a commercial project and if you want to help sponsor this feature, feel free to reach out and send me an email)

@InterLinked1
Copy link

InterLinked1 commented Sep 17, 2020

@clue

Well, as you may have guessed, I am using some of these awesome libraries, though not commercially. Figured out the use; stuff eventually, but it looks like it's the older code - though it seems to have the features I need for now, so I guess it doesn't matter much.

I'm not really good with Git, and I don't use it myself, but I started trying to approach this earlier today, following the pseudocode on Wikipedia... don't think this was covered back in my Intro Algorithms course... I got as far as this - not sure it's much help, though:

function floydWarshallWithPathReconstruction($g, $n) {
	$dist = array_fill(0, $n, array_fill(0, $n, INF)); # initialize n*n 2D array with positive infinity
	$next = array_fill(0, $n, array_fill(0, $n, null)); # initialize n*n 2D array with null
	foreach ($g->getEdges() as $edge) {
		$vertices = $edge->getVertices();
		$u = null;
		$v = null;
		foreach ($vertices as $vert) {
			if ($u === null) {
				$u = $vert;
			} else {
				$v = $vert;
			}
		}
		$uID = $u->getAttribute('id');
		$vID = $v->getAttribute('id');
		$dist[$uID][$vID] = 1; // weight
		$next[$uID][$vID] = $v;
	}
	foreach ($g->getVertices() as $v) {
		$vID = $v->getAttribute('id');
		$dist[$vID][$vID] = 0;
		$next[$vID][$vID] = $v;
	}
	for ($k = 1; $k <= $n; $k++) {
		for ($i = 1; $i < $n; $i++) {
			// unfinished # https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm#Path_reconstruction
		}
	}
} 

I stopped here because the way $k and $i are defined, it expects them to be sequential, but the IDs as I was using them in my program are database IDs, and not necessarily sequential, and I was out of brainpower at this point to come up with an immediate workaround to this.

As a side note, I found the PageRank.php file in an abandoned pull request and downloaded that for my own project. Works great. Not sure why it says it 'failed' but I haven't had any issues with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants