Skip to content

Instantly share code, notes, and snippets.

@keithwhor
Last active February 19, 2018 17:37
Show Gist options
  • Save keithwhor/15b31f101ff5a2721dfa to your computer and use it in GitHub Desktop.
Save keithwhor/15b31f101ff5a2721dfa to your computer and use it in GitHub Desktop.
UnitGraph example, loading graph and finding closest nodes
let ug = require('ug');
let graph = new ug.Graph();
// load graph from flatfile into RAM
graph.load('/path_to_saved_graph.ugd', function() {
// get the closest 100 'listings' nodes, at a minimum depth (distance) of 3
let results = graph.closest(node, {
compare: function(node) { return node.entity === 'listing'; },
minDepth: 3,
count: 100
});
// results is now an array of Paths, which are each traces from your starting node to your result node...
let resultNodes = result.map(function(path) {
return path.end();
}));
doSomething(resultNodes); // render, whatever you'd like
});
@kostasx
Copy link

kostasx commented May 6, 2016

Shouldn't line #16 read:
let resultNodes = results.map(function(path) {
?

@lekankoku
Copy link

// load graph from flatfile into RAM
graph.load('/path_to_saved_graph.ugd', function()

What is a ugd ?

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