Graph Functions

This chapter describes various functions on a graph.A lot of these accept a vertex (or edge) example as parameter as defined in the next section.

Examples will explain the API on the the city graph:

Social Example Graph

Definition of examples

For many of the following functions examples can be passed in as a parameter.Examples are used to filter the result set for objects that match the conditions.These examples can have the following values:

  • null, there is no matching executed all found results are valid.
  • A string, only results are returned, which _id equal the value of the string
  • An example object, defining a set of attributes. Only results having these attributes are matched.
  • A list containing example objects and/or strings. All results matching at least one of the elements in the list are returned.

Get vertices from edges.

Get vertex from of an edge

Get the source vertex of an edge

graph._fromVertex(edgeId)

Returns the vertex defined with the attribute from of the edge with _edgeId as its id_.

Parameters

  • edgeId (required) _id attribute of the edge

Examples

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("social");
  3. arangosh> var any = require("@arangodb").db.relation.any();
  4. arangosh> graph._fromVertex("relation/" + any._key);

Show execution results

Hide execution results

  1. {
  2. "_key" : "alice",
  3. "_id" : "female/alice",
  4. "_rev" : "_Z2KDQUG---",
  5. "name" : "Alice"
  6. }

Get vertex to of an edge

Get the target vertex of an edge

graph._toVertex(edgeId)

Returns the vertex defined with the attribute to of the edge with _edgeId as its id_.

Parameters

  • edgeId (required) _id attribute of the edge

Examples

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("social");
  3. arangosh> var any = require("@arangodb").db.relation.any();
  4. arangosh> graph._toVertex("relation/" + any._key);

Show execution results

Hide execution results

  1. {
  2. "_key" : "charly",
  3. "_id" : "male/charly",
  4. "_rev" : "_Z2KDQVG---",
  5. "name" : "Charly"
  6. }

_neighbors

Get all neighbors of the vertices defined by the example

graph._neighbors(vertexExample, options)

The function accepts an id, an example, a list of examples or even an emptyexample as parameter for vertexExample.The complexity of this method is O(n*m^x) with n being the vertices defined by theparameter vertexExamplex, m the average amount of neighbors and x the maximal depths.Hence the default call would have a complexity of O(n*m);

Parameters

  • vertexExample (optional) See Definition of examples
  • options (optional) An object defining further options. Can have the following values:
    • direction: The direction of the edges. Possible values are outbound, inbound and any (default).
    • edgeExamples: Filter the edges, see Definition of examples
    • neighborExamples: Filter the neighbor vertices, see Definition of examples
    • edgeCollectionRestriction : One or a list of edge-collection names that should beconsidered to be on the path.
    • vertexCollectionRestriction : One or a list of vertex-collection names that should beconsidered on the intermediate vertex steps.
    • minDepth: Defines the minimal number of intermediate steps to neighbors (default is 1).
    • maxDepth: Defines the maximal number of intermediate steps to neighbors (default is 1).

Examples

A route planner example, all neighbors of capitals.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._neighbors({isCapital : true});

Show execution results

Hide execution results

  1. [
  2. "frenchCity/Lyon",
  3. "germanCity/Berlin",
  4. "germanCity/Hamburg",
  5. "germanCity/Cologne",
  6. "frenchCity/Paris"
  7. ]

A route planner example, all outbound neighbors of Hamburg.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._neighbors('germanCity/Hamburg', {direction : 'outbound', maxDepth : 2});

Show execution results

Hide execution results

  1. [
  2. "germanCity/Cologne",
  3. "frenchCity/Paris",
  4. "frenchCity/Lyon"
  5. ]

_commonNeighbors

Get all common neighbors of the vertices defined by the examples.

graph._commonNeighbors(vertex1Example, vertex2Examples, optionsVertex1, optionsVertex2)

This function returns the intersection of graph_module._neighbors(vertex1Example, optionsVertex1)_and _graph_module._neighbors(vertex2Example, optionsVertex2).For parameter documentation see _neighbors.

The complexity of this method is O(n*m^x) with n being the maximal amount of verticesdefined by the parameters vertexExamples, m the average amount of neighbors and x themaximal depths.Hence the default call would have a complexity of O(n*m);

Examples

A route planner example, all common neighbors of capitals.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._commonNeighbors({isCapital : true}, {isCapital : true});

Show execution results

Hide execution results

  1. [
  2. {
  3. "left" : "frenchCity/Paris",
  4. "right" : "germanCity/Berlin",
  5. "neighbors" : [
  6. "germanCity/Cologne",
  7. "germanCity/Hamburg",
  8. "frenchCity/Lyon"
  9. ]
  10. },
  11. {
  12. "left" : "germanCity/Berlin",
  13. "right" : "frenchCity/Paris",
  14. "neighbors" : [
  15. "frenchCity/Lyon",
  16. "germanCity/Hamburg",
  17. "germanCity/Cologne"
  18. ]
  19. }
  20. ]

A route planner example, all common outbound neighbors of Hamburg with any other locationwhich have a maximal depth of 2 :

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._commonNeighbors(
  4. ........> 'germanCity/Hamburg',
  5. ........> {},
  6. ........> {direction : 'outbound', maxDepth : 2},
  7. ........> {direction : 'outbound', maxDepth : 2});

Show execution results

Hide execution results

  1. [
  2. {
  3. "left" : "germanCity/Hamburg",
  4. "right" : "frenchCity/Paris",
  5. "neighbors" : [
  6. "frenchCity/Lyon"
  7. ]
  8. },
  9. {
  10. "left" : "germanCity/Hamburg",
  11. "right" : "germanCity/Berlin",
  12. "neighbors" : [
  13. "frenchCity/Lyon",
  14. "frenchCity/Paris",
  15. "germanCity/Cologne"
  16. ]
  17. },
  18. {
  19. "left" : "germanCity/Hamburg",
  20. "right" : "germanCity/Cologne",
  21. "neighbors" : [
  22. "frenchCity/Lyon",
  23. "frenchCity/Paris"
  24. ]
  25. }
  26. ]

_countCommonNeighbors

Get the amount of common neighbors of the vertices defined by the examples.

graph._countCommonNeighbors(vertex1Example, vertex2Examples, optionsVertex1, optionsVertex2)

Similar to _commonNeighbors but returns count instead of the elements.

Examples

A route planner example, all common neighbors of capitals.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> var example = { isCapital: true };
  4. arangosh> var options = { includeData: true };
  5. arangosh> graph._countCommonNeighbors(example, example, options, options);

Show execution results

Hide execution results

  1. [
  2. {
  3. "frenchCity/Paris" : [
  4. {
  5. "germanCity/Berlin" : 3
  6. }
  7. ]
  8. },
  9. {
  10. "germanCity/Berlin" : [
  11. {
  12. "frenchCity/Paris" : 3
  13. }
  14. ]
  15. }
  16. ]

A route planner example, all common outbound neighbors of Hamburg with any other locationwhich have a maximal depth of 2 :

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> var options = { direction: 'outbound', maxDepth: 2, includeData: true };
  4. arangosh> graph._countCommonNeighbors('germanCity/Hamburg', {}, options, options);

Show execution results

Hide execution results

  1. [
  2. {
  3. "germanCity/Hamburg" : [
  4. {
  5. "frenchCity/Paris" : 1
  6. },
  7. {
  8. "germanCity/Berlin" : 3
  9. },
  10. {
  11. "germanCity/Cologne" : 2
  12. }
  13. ]
  14. }
  15. ]

_commonProperties

Get the vertices of the graph that share common properties.

graph._commonProperties(vertex1Example, vertex2Examples, options)

The function accepts an id, an example, a list of examples or even an emptyexample as parameter for vertex1Example and vertex2Example.

The complexity of this method is O(n) with n being the maximal amount of verticesdefined by the parameters vertexExamples.

Parameters

  • vertex1Examples (optional) Filter the set of source vertices, see Definition of examples

  • vertex2Examples (optional) Filter the set of vertices compared to, see Definition of examples

  • options (optional) An object defining further options. Can have the following values:
    • vertex1CollectionRestriction : One or a list of vertex-collection names that should besearched for source vertices.
    • vertex2CollectionRestriction : One or a list of vertex-collection names that should besearched for compare vertices.
    • ignoreProperties : One or a list of attribute names of a document that should be ignored.

Examples

A route planner example, all locations with the same properties:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._commonProperties({}, {});

Show execution results

Hide execution results

  1. [
  2. {
  3. "frenchCity/Lyon" : [
  4. {
  5. "_id" : "germanCity/Cologne",
  6. "isCapital" : false
  7. },
  8. {
  9. "_id" : "germanCity/Hamburg",
  10. "isCapital" : false
  11. }
  12. ]
  13. },
  14. {
  15. "frenchCity/Paris" : [
  16. {
  17. "_id" : "germanCity/Berlin",
  18. "isCapital" : true
  19. }
  20. ]
  21. },
  22. {
  23. "germanCity/Berlin" : [
  24. {
  25. "_id" : "frenchCity/Paris",
  26. "isCapital" : true
  27. }
  28. ]
  29. },
  30. {
  31. "germanCity/Cologne" : [
  32. {
  33. "_id" : "frenchCity/Lyon",
  34. "isCapital" : false
  35. },
  36. {
  37. "_id" : "germanCity/Hamburg",
  38. "isCapital" : false,
  39. "population" : 1000000
  40. }
  41. ]
  42. },
  43. {
  44. "germanCity/Hamburg" : [
  45. {
  46. "_id" : "frenchCity/Lyon",
  47. "isCapital" : false
  48. },
  49. {
  50. "_id" : "germanCity/Cologne",
  51. "isCapital" : false,
  52. "population" : 1000000
  53. }
  54. ]
  55. }
  56. ]

A route planner example, all cities which share same properties except for population.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._commonProperties({}, {}, {ignoreProperties: 'population'});

Show execution results

Hide execution results

  1. [
  2. {
  3. "frenchCity/Lyon" : [
  4. {
  5. "_id" : "germanCity/Cologne",
  6. "isCapital" : false
  7. },
  8. {
  9. "_id" : "germanCity/Hamburg",
  10. "isCapital" : false
  11. }
  12. ]
  13. },
  14. {
  15. "frenchCity/Paris" : [
  16. {
  17. "_id" : "germanCity/Berlin",
  18. "isCapital" : true
  19. }
  20. ]
  21. },
  22. {
  23. "germanCity/Berlin" : [
  24. {
  25. "_id" : "frenchCity/Paris",
  26. "isCapital" : true
  27. }
  28. ]
  29. },
  30. {
  31. "germanCity/Cologne" : [
  32. {
  33. "_id" : "frenchCity/Lyon",
  34. "isCapital" : false
  35. },
  36. {
  37. "_id" : "germanCity/Hamburg",
  38. "isCapital" : false
  39. }
  40. ]
  41. },
  42. {
  43. "germanCity/Hamburg" : [
  44. {
  45. "_id" : "frenchCity/Lyon",
  46. "isCapital" : false
  47. },
  48. {
  49. "_id" : "germanCity/Cologne",
  50. "isCapital" : false
  51. }
  52. ]
  53. }
  54. ]

_countCommonProperties

Get the amount of vertices of the graph that share common properties.

graph._countCommonProperties(vertex1Example, vertex2Examples, options)

Similar to _commonProperties but returns count instead ofthe objects.

Examples

A route planner example, all locations with the same properties:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._countCommonProperties({}, {});

Show execution results

Hide execution results

  1. [
  2. {
  3. "frenchCity/Lyon" : 2
  4. },
  5. {
  6. "frenchCity/Paris" : 1
  7. },
  8. {
  9. "germanCity/Berlin" : 1
  10. },
  11. {
  12. "germanCity/Cologne" : 2
  13. },
  14. {
  15. "germanCity/Hamburg" : 2
  16. }
  17. ]

A route planner example, all German cities which share same properties except for population.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._countCommonProperties({}, {}, {vertex1CollectionRestriction : 'germanCity',
  4. ........> vertex2CollectionRestriction : 'germanCity' ,ignoreProperties: 'population'});

Show execution results

Hide execution results

  1. [
  2. {
  3. "frenchCity/Lyon" : 2
  4. },
  5. {
  6. "frenchCity/Paris" : 1
  7. },
  8. {
  9. "germanCity/Berlin" : 1
  10. },
  11. {
  12. "germanCity/Cologne" : 2
  13. },
  14. {
  15. "germanCity/Hamburg" : 2
  16. }
  17. ]

_paths

The _paths function returns all paths of a graph.

graph._paths(options)

This function determines all available paths in a graph.

The complexity of this method is O(nnm) with n being the amount of vertices inthe graph and m the average amount of connected edges;

Parameters

  • options (optional) An object containing options, see below:
    • direction: The direction of the edges. Possible values are any,inbound and outbound (default).
    • followCycles (optional): If set to true the query follows cycles in the graph,default is false.
    • minLength (optional): Defines the minimal length a path musthave to be returned (default is 0).
    • maxLength (optional): Defines the maximal length a path must have to be returned (default is 10).

Examples

Return all paths of the graph “social”:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var g = examples.loadGraph("social");
  3. arangosh> g._paths();

Show execution results

Hide execution results

  1. [
  2. {
  3. "source" : {
  4. "_key" : "alice",
  5. "_id" : "female/alice",
  6. "_rev" : "_Z2KDRF6---",
  7. "name" : "Alice"
  8. },
  9. "destination" : {
  10. "_key" : "alice",
  11. "_id" : "female/alice",
  12. "_rev" : "_Z2KDRF6---",
  13. "name" : "Alice"
  14. },
  15. "edges" : [ ],
  16. "vertice" : [
  17. {
  18. "_key" : "alice",
  19. "_id" : "female/alice",
  20. "_rev" : "_Z2KDRF6---",
  21. "name" : "Alice"
  22. }
  23. ]
  24. },
  25. {
  26. "source" : {
  27. "_key" : "alice",
  28. "_id" : "female/alice",
  29. "_rev" : "_Z2KDRF6---",
  30. "name" : "Alice"
  31. },
  32. "destination" : {
  33. "_key" : "bob",
  34. "_id" : "male/bob",
  35. "_rev" : "_Z2KDRG----",
  36. "name" : "Bob"
  37. },
  38. "edges" : [
  39. {
  40. "_key" : "77883",
  41. "_id" : "relation/77883",
  42. "_from" : "female/alice",
  43. "_to" : "male/bob",
  44. "_rev" : "_Z2KDRGC---",
  45. "type" : "married",
  46. "vertex" : "alice"
  47. }
  48. ],
  49. "vertice" : [
  50. {
  51. "_key" : "alice",
  52. "_id" : "female/alice",
  53. "_rev" : "_Z2KDRF6---",
  54. "name" : "Alice"
  55. },
  56. {
  57. "_key" : "bob",
  58. "_id" : "male/bob",
  59. "_rev" : "_Z2KDRG----",
  60. "name" : "Bob"
  61. }
  62. ]
  63. },
  64. {
  65. "source" : {
  66. "_key" : "alice",
  67. "_id" : "female/alice",
  68. "_rev" : "_Z2KDRF6---",
  69. "name" : "Alice"
  70. },
  71. "destination" : {
  72. "_key" : "diana",
  73. "_id" : "female/diana",
  74. "_rev" : "_Z2KDRG---C",
  75. "name" : "Diana"
  76. },
  77. "edges" : [
  78. {
  79. "_key" : "77883",
  80. "_id" : "relation/77883",
  81. "_from" : "female/alice",
  82. "_to" : "male/bob",
  83. "_rev" : "_Z2KDRGC---",
  84. "type" : "married",
  85. "vertex" : "alice"
  86. },
  87. {
  88. "_key" : "77889",
  89. "_id" : "relation/77889",
  90. "_from" : "male/bob",
  91. "_to" : "female/diana",
  92. "_rev" : "_Z2KDRGG--A",
  93. "type" : "friend",
  94. "vertex" : "bob"
  95. }
  96. ],
  97. "vertice" : [
  98. {
  99. "_key" : "alice",
  100. "_id" : "female/alice",
  101. "_rev" : "_Z2KDRF6---",
  102. "name" : "Alice"
  103. },
  104. {
  105. "_key" : "bob",
  106. "_id" : "male/bob",
  107. "_rev" : "_Z2KDRG----",
  108. "name" : "Bob"
  109. },
  110. {
  111. "_key" : "diana",
  112. "_id" : "female/diana",
  113. "_rev" : "_Z2KDRG---C",
  114. "name" : "Diana"
  115. }
  116. ]
  117. },
  118. {
  119. "source" : {
  120. "_key" : "alice",
  121. "_id" : "female/alice",
  122. "_rev" : "_Z2KDRF6---",
  123. "name" : "Alice"
  124. },
  125. "destination" : {
  126. "_key" : "charly",
  127. "_id" : "male/charly",
  128. "_rev" : "_Z2KDRG---A",
  129. "name" : "Charly"
  130. },
  131. "edges" : [
  132. {
  133. "_key" : "77885",
  134. "_id" : "relation/77885",
  135. "_from" : "female/alice",
  136. "_to" : "male/charly",
  137. "_rev" : "_Z2KDRGC--A",
  138. "type" : "friend",
  139. "vertex" : "alice"
  140. }
  141. ],
  142. "vertice" : [
  143. {
  144. "_key" : "alice",
  145. "_id" : "female/alice",
  146. "_rev" : "_Z2KDRF6---",
  147. "name" : "Alice"
  148. },
  149. {
  150. "_key" : "charly",
  151. "_id" : "male/charly",
  152. "_rev" : "_Z2KDRG---A",
  153. "name" : "Charly"
  154. }
  155. ]
  156. },
  157. {
  158. "source" : {
  159. "_key" : "alice",
  160. "_id" : "female/alice",
  161. "_rev" : "_Z2KDRF6---",
  162. "name" : "Alice"
  163. },
  164. "destination" : {
  165. "_key" : "diana",
  166. "_id" : "female/diana",
  167. "_rev" : "_Z2KDRG---C",
  168. "name" : "Diana"
  169. },
  170. "edges" : [
  171. {
  172. "_key" : "77885",
  173. "_id" : "relation/77885",
  174. "_from" : "female/alice",
  175. "_to" : "male/charly",
  176. "_rev" : "_Z2KDRGC--A",
  177. "type" : "friend",
  178. "vertex" : "alice"
  179. },
  180. {
  181. "_key" : "77887",
  182. "_id" : "relation/77887",
  183. "_from" : "male/charly",
  184. "_to" : "female/diana",
  185. "_rev" : "_Z2KDRGG---",
  186. "type" : "married",
  187. "vertex" : "charly"
  188. }
  189. ],
  190. "vertice" : [
  191. {
  192. "_key" : "alice",
  193. "_id" : "female/alice",
  194. "_rev" : "_Z2KDRF6---",
  195. "name" : "Alice"
  196. },
  197. {
  198. "_key" : "charly",
  199. "_id" : "male/charly",
  200. "_rev" : "_Z2KDRG---A",
  201. "name" : "Charly"
  202. },
  203. {
  204. "_key" : "diana",
  205. "_id" : "female/diana",
  206. "_rev" : "_Z2KDRG---C",
  207. "name" : "Diana"
  208. }
  209. ]
  210. },
  211. {
  212. "source" : {
  213. "_key" : "diana",
  214. "_id" : "female/diana",
  215. "_rev" : "_Z2KDRG---C",
  216. "name" : "Diana"
  217. },
  218. "destination" : {
  219. "_key" : "diana",
  220. "_id" : "female/diana",
  221. "_rev" : "_Z2KDRG---C",
  222. "name" : "Diana"
  223. },
  224. "edges" : [ ],
  225. "vertice" : [
  226. {
  227. "_key" : "diana",
  228. "_id" : "female/diana",
  229. "_rev" : "_Z2KDRG---C",
  230. "name" : "Diana"
  231. }
  232. ]
  233. },
  234. {
  235. "source" : {
  236. "_key" : "bob",
  237. "_id" : "male/bob",
  238. "_rev" : "_Z2KDRG----",
  239. "name" : "Bob"
  240. },
  241. "destination" : {
  242. "_key" : "bob",
  243. "_id" : "male/bob",
  244. "_rev" : "_Z2KDRG----",
  245. "name" : "Bob"
  246. },
  247. "edges" : [ ],
  248. "vertice" : [
  249. {
  250. "_key" : "bob",
  251. "_id" : "male/bob",
  252. "_rev" : "_Z2KDRG----",
  253. "name" : "Bob"
  254. }
  255. ]
  256. },
  257. {
  258. "source" : {
  259. "_key" : "bob",
  260. "_id" : "male/bob",
  261. "_rev" : "_Z2KDRG----",
  262. "name" : "Bob"
  263. },
  264. "destination" : {
  265. "_key" : "diana",
  266. "_id" : "female/diana",
  267. "_rev" : "_Z2KDRG---C",
  268. "name" : "Diana"
  269. },
  270. "edges" : [
  271. {
  272. "_key" : "77889",
  273. "_id" : "relation/77889",
  274. "_from" : "male/bob",
  275. "_to" : "female/diana",
  276. "_rev" : "_Z2KDRGG--A",
  277. "type" : "friend",
  278. "vertex" : "bob"
  279. }
  280. ],
  281. "vertice" : [
  282. {
  283. "_key" : "bob",
  284. "_id" : "male/bob",
  285. "_rev" : "_Z2KDRG----",
  286. "name" : "Bob"
  287. },
  288. {
  289. "_key" : "diana",
  290. "_id" : "female/diana",
  291. "_rev" : "_Z2KDRG---C",
  292. "name" : "Diana"
  293. }
  294. ]
  295. },
  296. {
  297. "source" : {
  298. "_key" : "charly",
  299. "_id" : "male/charly",
  300. "_rev" : "_Z2KDRG---A",
  301. "name" : "Charly"
  302. },
  303. "destination" : {
  304. "_key" : "charly",
  305. "_id" : "male/charly",
  306. "_rev" : "_Z2KDRG---A",
  307. "name" : "Charly"
  308. },
  309. "edges" : [ ],
  310. "vertice" : [
  311. {
  312. "_key" : "charly",
  313. "_id" : "male/charly",
  314. "_rev" : "_Z2KDRG---A",
  315. "name" : "Charly"
  316. }
  317. ]
  318. },
  319. {
  320. "source" : {
  321. "_key" : "charly",
  322. "_id" : "male/charly",
  323. "_rev" : "_Z2KDRG---A",
  324. "name" : "Charly"
  325. },
  326. "destination" : {
  327. "_key" : "diana",
  328. "_id" : "female/diana",
  329. "_rev" : "_Z2KDRG---C",
  330. "name" : "Diana"
  331. },
  332. "edges" : [
  333. {
  334. "_key" : "77887",
  335. "_id" : "relation/77887",
  336. "_from" : "male/charly",
  337. "_to" : "female/diana",
  338. "_rev" : "_Z2KDRGG---",
  339. "type" : "married",
  340. "vertex" : "charly"
  341. }
  342. ],
  343. "vertice" : [
  344. {
  345. "_key" : "charly",
  346. "_id" : "male/charly",
  347. "_rev" : "_Z2KDRG---A",
  348. "name" : "Charly"
  349. },
  350. {
  351. "_key" : "diana",
  352. "_id" : "female/diana",
  353. "_rev" : "_Z2KDRG---C",
  354. "name" : "Diana"
  355. }
  356. ]
  357. }
  358. ]

Return all inbound paths of the graph “social” with a maximallength of 1 and a minimal length of 2:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var g = examples.loadGraph("social");
  3. arangosh> g._paths({direction : 'inbound', minLength : 1, maxLength : 2});

Show execution results

Hide execution results

  1. [
  2. {
  3. "source" : {
  4. "_key" : "diana",
  5. "_id" : "female/diana",
  6. "_rev" : "_Z2KDRH6---",
  7. "name" : "Diana"
  8. },
  9. "destination" : {
  10. "_key" : "charly",
  11. "_id" : "male/charly",
  12. "_rev" : "_Z2KDRH2--A",
  13. "name" : "Charly"
  14. },
  15. "edges" : [
  16. {
  17. "_key" : "77933",
  18. "_id" : "relation/77933",
  19. "_from" : "male/charly",
  20. "_to" : "female/diana",
  21. "_rev" : "_Z2KDRI---A",
  22. "type" : "married",
  23. "vertex" : "charly"
  24. }
  25. ],
  26. "vertice" : [
  27. {
  28. "_key" : "diana",
  29. "_id" : "female/diana",
  30. "_rev" : "_Z2KDRH6---",
  31. "name" : "Diana"
  32. },
  33. {
  34. "_key" : "charly",
  35. "_id" : "male/charly",
  36. "_rev" : "_Z2KDRH2--A",
  37. "name" : "Charly"
  38. }
  39. ]
  40. },
  41. {
  42. "source" : {
  43. "_key" : "diana",
  44. "_id" : "female/diana",
  45. "_rev" : "_Z2KDRH6---",
  46. "name" : "Diana"
  47. },
  48. "destination" : {
  49. "_key" : "alice",
  50. "_id" : "female/alice",
  51. "_rev" : "_Z2KDRHy---",
  52. "name" : "Alice"
  53. },
  54. "edges" : [
  55. {
  56. "_key" : "77933",
  57. "_id" : "relation/77933",
  58. "_from" : "male/charly",
  59. "_to" : "female/diana",
  60. "_rev" : "_Z2KDRI---A",
  61. "type" : "married",
  62. "vertex" : "charly"
  63. },
  64. {
  65. "_key" : "77931",
  66. "_id" : "relation/77931",
  67. "_from" : "female/alice",
  68. "_to" : "male/charly",
  69. "_rev" : "_Z2KDRI----",
  70. "type" : "friend",
  71. "vertex" : "alice"
  72. }
  73. ],
  74. "vertice" : [
  75. {
  76. "_key" : "diana",
  77. "_id" : "female/diana",
  78. "_rev" : "_Z2KDRH6---",
  79. "name" : "Diana"
  80. },
  81. {
  82. "_key" : "charly",
  83. "_id" : "male/charly",
  84. "_rev" : "_Z2KDRH2--A",
  85. "name" : "Charly"
  86. },
  87. {
  88. "_key" : "alice",
  89. "_id" : "female/alice",
  90. "_rev" : "_Z2KDRHy---",
  91. "name" : "Alice"
  92. }
  93. ]
  94. },
  95. {
  96. "source" : {
  97. "_key" : "diana",
  98. "_id" : "female/diana",
  99. "_rev" : "_Z2KDRH6---",
  100. "name" : "Diana"
  101. },
  102. "destination" : {
  103. "_key" : "bob",
  104. "_id" : "male/bob",
  105. "_rev" : "_Z2KDRH2---",
  106. "name" : "Bob"
  107. },
  108. "edges" : [
  109. {
  110. "_key" : "77935",
  111. "_id" : "relation/77935",
  112. "_from" : "male/bob",
  113. "_to" : "female/diana",
  114. "_rev" : "_Z2KDRIC---",
  115. "type" : "friend",
  116. "vertex" : "bob"
  117. }
  118. ],
  119. "vertice" : [
  120. {
  121. "_key" : "diana",
  122. "_id" : "female/diana",
  123. "_rev" : "_Z2KDRH6---",
  124. "name" : "Diana"
  125. },
  126. {
  127. "_key" : "bob",
  128. "_id" : "male/bob",
  129. "_rev" : "_Z2KDRH2---",
  130. "name" : "Bob"
  131. }
  132. ]
  133. },
  134. {
  135. "source" : {
  136. "_key" : "diana",
  137. "_id" : "female/diana",
  138. "_rev" : "_Z2KDRH6---",
  139. "name" : "Diana"
  140. },
  141. "destination" : {
  142. "_key" : "alice",
  143. "_id" : "female/alice",
  144. "_rev" : "_Z2KDRHy---",
  145. "name" : "Alice"
  146. },
  147. "edges" : [
  148. {
  149. "_key" : "77935",
  150. "_id" : "relation/77935",
  151. "_from" : "male/bob",
  152. "_to" : "female/diana",
  153. "_rev" : "_Z2KDRIC---",
  154. "type" : "friend",
  155. "vertex" : "bob"
  156. },
  157. {
  158. "_key" : "77929",
  159. "_id" : "relation/77929",
  160. "_from" : "female/alice",
  161. "_to" : "male/bob",
  162. "_rev" : "_Z2KDRH6--A",
  163. "type" : "married",
  164. "vertex" : "alice"
  165. }
  166. ],
  167. "vertice" : [
  168. {
  169. "_key" : "diana",
  170. "_id" : "female/diana",
  171. "_rev" : "_Z2KDRH6---",
  172. "name" : "Diana"
  173. },
  174. {
  175. "_key" : "bob",
  176. "_id" : "male/bob",
  177. "_rev" : "_Z2KDRH2---",
  178. "name" : "Bob"
  179. },
  180. {
  181. "_key" : "alice",
  182. "_id" : "female/alice",
  183. "_rev" : "_Z2KDRHy---",
  184. "name" : "Alice"
  185. }
  186. ]
  187. },
  188. {
  189. "source" : {
  190. "_key" : "bob",
  191. "_id" : "male/bob",
  192. "_rev" : "_Z2KDRH2---",
  193. "name" : "Bob"
  194. },
  195. "destination" : {
  196. "_key" : "alice",
  197. "_id" : "female/alice",
  198. "_rev" : "_Z2KDRHy---",
  199. "name" : "Alice"
  200. },
  201. "edges" : [
  202. {
  203. "_key" : "77929",
  204. "_id" : "relation/77929",
  205. "_from" : "female/alice",
  206. "_to" : "male/bob",
  207. "_rev" : "_Z2KDRH6--A",
  208. "type" : "married",
  209. "vertex" : "alice"
  210. }
  211. ],
  212. "vertice" : [
  213. {
  214. "_key" : "bob",
  215. "_id" : "male/bob",
  216. "_rev" : "_Z2KDRH2---",
  217. "name" : "Bob"
  218. },
  219. {
  220. "_key" : "alice",
  221. "_id" : "female/alice",
  222. "_rev" : "_Z2KDRHy---",
  223. "name" : "Alice"
  224. }
  225. ]
  226. },
  227. {
  228. "source" : {
  229. "_key" : "charly",
  230. "_id" : "male/charly",
  231. "_rev" : "_Z2KDRH2--A",
  232. "name" : "Charly"
  233. },
  234. "destination" : {
  235. "_key" : "alice",
  236. "_id" : "female/alice",
  237. "_rev" : "_Z2KDRHy---",
  238. "name" : "Alice"
  239. },
  240. "edges" : [
  241. {
  242. "_key" : "77931",
  243. "_id" : "relation/77931",
  244. "_from" : "female/alice",
  245. "_to" : "male/charly",
  246. "_rev" : "_Z2KDRI----",
  247. "type" : "friend",
  248. "vertex" : "alice"
  249. }
  250. ],
  251. "vertice" : [
  252. {
  253. "_key" : "charly",
  254. "_id" : "male/charly",
  255. "_rev" : "_Z2KDRH2--A",
  256. "name" : "Charly"
  257. },
  258. {
  259. "_key" : "alice",
  260. "_id" : "female/alice",
  261. "_rev" : "_Z2KDRHy---",
  262. "name" : "Alice"
  263. }
  264. ]
  265. }
  266. ]

_shortestPath

The _shortestPath function returns all shortest paths of a graph.

graph._shortestPath(startVertexExample, endVertexExample, options)

This function determines all shortest paths in a graph.The function accepts an id, an example, a list of examplesor even an empty example as parameter forstart and end vertex.The length of a path is by default the amount of edges from one start vertex toan end vertex. The option weight allows the user to define an edge attributerepresenting the length.

Parameters

  • startVertexExample (optional) An example for the desired start Vertices (see Definition of examples).
  • endVertexExample (optional) An example for the desired end Vertices (see Definition of examples).
  • options (optional) An object containing options, see below:
    • direction: The direction of the edges as a string.Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction: One or multiple edgecollection names. Only edges from these collections will be considered for the path.
    • startVertexCollectionRestriction: One or multiple vertexcollection names. Only vertices from these collections will be considered asstart vertex of a path.
    • endVertexCollectionRestriction: One or multiple vertexcollection names. Only vertices from these collections will be considered asend vertex of a path.
    • weight: The name of the attribute ofthe edges containing the length as a string.
    • defaultWeight: Only used with the option weight.If an edge does not have the attribute named as defined in option weight this defaultis used as length.If no default is supplied the default would be positive Infinity so the path couldnot be calculated.

Examples

A route planner example, shortest path from all german to all french cities:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var g = examples.loadGraph("routeplanner");
  3. arangosh> g._shortestPath({}, {}, {weight : 'distance', endVertexCollectionRestriction : 'frenchCity',
  4. ........> startVertexCollectionRestriction : 'germanCity'});

Show execution results

Hide execution results

  1. [
  2. {
  3. "vertices" : [
  4. "frenchCity/Lyon",
  5. "frenchCity/Paris"
  6. ],
  7. "edges" : [
  8. {
  9. "_key" : "78373",
  10. "_id" : "frenchHighway/78373",
  11. "_from" : "frenchCity/Paris",
  12. "_to" : "frenchCity/Lyon",
  13. "_rev" : "_Z2KDRR6---",
  14. "distance" : 550
  15. }
  16. ],
  17. "distance" : 1
  18. },
  19. {
  20. "vertices" : [
  21. "frenchCity/Lyon",
  22. "germanCity/Berlin"
  23. ],
  24. "edges" : [
  25. {
  26. "_key" : "78375",
  27. "_id" : "internationalHighway/78375",
  28. "_from" : "germanCity/Berlin",
  29. "_to" : "frenchCity/Lyon",
  30. "_rev" : "_Z2KDRR6--A",
  31. "distance" : 1100
  32. }
  33. ],
  34. "distance" : 1
  35. },
  36. {
  37. "vertices" : [
  38. "frenchCity/Lyon",
  39. "germanCity/Cologne"
  40. ],
  41. "edges" : [
  42. {
  43. "_key" : "78383",
  44. "_id" : "internationalHighway/78383",
  45. "_from" : "germanCity/Cologne",
  46. "_to" : "frenchCity/Lyon",
  47. "_rev" : "_Z2KDRSC--A",
  48. "distance" : 700
  49. }
  50. ],
  51. "distance" : 1
  52. },
  53. {
  54. "vertices" : [
  55. "frenchCity/Lyon",
  56. "germanCity/Hamburg"
  57. ],
  58. "edges" : [
  59. {
  60. "_key" : "78381",
  61. "_id" : "internationalHighway/78381",
  62. "_from" : "germanCity/Hamburg",
  63. "_to" : "frenchCity/Lyon",
  64. "_rev" : "_Z2KDRSC---",
  65. "distance" : 1300
  66. }
  67. ],
  68. "distance" : 1
  69. },
  70. {
  71. "vertices" : [
  72. "frenchCity/Paris",
  73. "frenchCity/Lyon"
  74. ],
  75. "edges" : [
  76. {
  77. "_key" : "78373",
  78. "_id" : "frenchHighway/78373",
  79. "_from" : "frenchCity/Paris",
  80. "_to" : "frenchCity/Lyon",
  81. "_rev" : "_Z2KDRR6---",
  82. "distance" : 550
  83. }
  84. ],
  85. "distance" : 1
  86. },
  87. {
  88. "vertices" : [
  89. "frenchCity/Paris",
  90. "germanCity/Berlin"
  91. ],
  92. "edges" : [
  93. {
  94. "_key" : "78377",
  95. "_id" : "internationalHighway/78377",
  96. "_from" : "germanCity/Berlin",
  97. "_to" : "frenchCity/Paris",
  98. "_rev" : "_Z2KDRS----",
  99. "distance" : 1200
  100. }
  101. ],
  102. "distance" : 1
  103. },
  104. {
  105. "vertices" : [
  106. "frenchCity/Paris",
  107. "germanCity/Cologne"
  108. ],
  109. "edges" : [
  110. {
  111. "_key" : "78385",
  112. "_id" : "internationalHighway/78385",
  113. "_from" : "germanCity/Cologne",
  114. "_to" : "frenchCity/Paris",
  115. "_rev" : "_Z2KDRSG---",
  116. "distance" : 550
  117. }
  118. ],
  119. "distance" : 1
  120. },
  121. {
  122. "vertices" : [
  123. "frenchCity/Paris",
  124. "germanCity/Hamburg"
  125. ],
  126. "edges" : [
  127. {
  128. "_key" : "78379",
  129. "_id" : "internationalHighway/78379",
  130. "_from" : "germanCity/Hamburg",
  131. "_to" : "frenchCity/Paris",
  132. "_rev" : "_Z2KDRS---A",
  133. "distance" : 900
  134. }
  135. ],
  136. "distance" : 1
  137. },
  138. {
  139. "vertices" : [
  140. "germanCity/Berlin",
  141. "frenchCity/Lyon"
  142. ],
  143. "edges" : [
  144. {
  145. "_key" : "78375",
  146. "_id" : "internationalHighway/78375",
  147. "_from" : "germanCity/Berlin",
  148. "_to" : "frenchCity/Lyon",
  149. "_rev" : "_Z2KDRR6--A",
  150. "distance" : 1100
  151. }
  152. ],
  153. "distance" : 1
  154. },
  155. {
  156. "vertices" : [
  157. "germanCity/Berlin",
  158. "frenchCity/Paris"
  159. ],
  160. "edges" : [
  161. {
  162. "_key" : "78377",
  163. "_id" : "internationalHighway/78377",
  164. "_from" : "germanCity/Berlin",
  165. "_to" : "frenchCity/Paris",
  166. "_rev" : "_Z2KDRS----",
  167. "distance" : 1200
  168. }
  169. ],
  170. "distance" : 1
  171. },
  172. {
  173. "vertices" : [
  174. "germanCity/Berlin",
  175. "germanCity/Cologne"
  176. ],
  177. "edges" : [
  178. {
  179. "_key" : "78367",
  180. "_id" : "germanHighway/78367",
  181. "_from" : "germanCity/Berlin",
  182. "_to" : "germanCity/Cologne",
  183. "_rev" : "_Z2KDRRy--_",
  184. "distance" : 850
  185. }
  186. ],
  187. "distance" : 1
  188. },
  189. {
  190. "vertices" : [
  191. "germanCity/Berlin",
  192. "germanCity/Hamburg"
  193. ],
  194. "edges" : [
  195. {
  196. "_key" : "78369",
  197. "_id" : "germanHighway/78369",
  198. "_from" : "germanCity/Berlin",
  199. "_to" : "germanCity/Hamburg",
  200. "_rev" : "_Z2KDRR2---",
  201. "distance" : 400
  202. }
  203. ],
  204. "distance" : 1
  205. },
  206. {
  207. "vertices" : [
  208. "germanCity/Cologne",
  209. "frenchCity/Lyon"
  210. ],
  211. "edges" : [
  212. {
  213. "_key" : "78383",
  214. "_id" : "internationalHighway/78383",
  215. "_from" : "germanCity/Cologne",
  216. "_to" : "frenchCity/Lyon",
  217. "_rev" : "_Z2KDRSC--A",
  218. "distance" : 700
  219. }
  220. ],
  221. "distance" : 1
  222. },
  223. {
  224. "vertices" : [
  225. "germanCity/Cologne",
  226. "frenchCity/Paris"
  227. ],
  228. "edges" : [
  229. {
  230. "_key" : "78385",
  231. "_id" : "internationalHighway/78385",
  232. "_from" : "germanCity/Cologne",
  233. "_to" : "frenchCity/Paris",
  234. "_rev" : "_Z2KDRSG---",
  235. "distance" : 550
  236. }
  237. ],
  238. "distance" : 1
  239. },
  240. {
  241. "vertices" : [
  242. "germanCity/Cologne",
  243. "germanCity/Berlin"
  244. ],
  245. "edges" : [
  246. {
  247. "_key" : "78367",
  248. "_id" : "germanHighway/78367",
  249. "_from" : "germanCity/Berlin",
  250. "_to" : "germanCity/Cologne",
  251. "_rev" : "_Z2KDRRy--_",
  252. "distance" : 850
  253. }
  254. ],
  255. "distance" : 1
  256. },
  257. {
  258. "vertices" : [
  259. "germanCity/Cologne",
  260. "germanCity/Hamburg"
  261. ],
  262. "edges" : [
  263. {
  264. "_key" : "78371",
  265. "_id" : "germanHighway/78371",
  266. "_from" : "germanCity/Hamburg",
  267. "_to" : "germanCity/Cologne",
  268. "_rev" : "_Z2KDRR2--A",
  269. "distance" : 500
  270. }
  271. ],
  272. "distance" : 1
  273. },
  274. {
  275. "vertices" : [
  276. "germanCity/Hamburg",
  277. "frenchCity/Lyon"
  278. ],
  279. "edges" : [
  280. {
  281. "_key" : "78381",
  282. "_id" : "internationalHighway/78381",
  283. "_from" : "germanCity/Hamburg",
  284. "_to" : "frenchCity/Lyon",
  285. "_rev" : "_Z2KDRSC---",
  286. "distance" : 1300
  287. }
  288. ],
  289. "distance" : 1
  290. },
  291. {
  292. "vertices" : [
  293. "germanCity/Hamburg",
  294. "frenchCity/Paris"
  295. ],
  296. "edges" : [
  297. {
  298. "_key" : "78379",
  299. "_id" : "internationalHighway/78379",
  300. "_from" : "germanCity/Hamburg",
  301. "_to" : "frenchCity/Paris",
  302. "_rev" : "_Z2KDRS---A",
  303. "distance" : 900
  304. }
  305. ],
  306. "distance" : 1
  307. },
  308. {
  309. "vertices" : [
  310. "germanCity/Hamburg",
  311. "germanCity/Berlin"
  312. ],
  313. "edges" : [
  314. {
  315. "_key" : "78369",
  316. "_id" : "germanHighway/78369",
  317. "_from" : "germanCity/Berlin",
  318. "_to" : "germanCity/Hamburg",
  319. "_rev" : "_Z2KDRR2---",
  320. "distance" : 400
  321. }
  322. ],
  323. "distance" : 1
  324. },
  325. {
  326. "vertices" : [
  327. "germanCity/Hamburg",
  328. "germanCity/Cologne"
  329. ],
  330. "edges" : [
  331. {
  332. "_key" : "78371",
  333. "_id" : "germanHighway/78371",
  334. "_from" : "germanCity/Hamburg",
  335. "_to" : "germanCity/Cologne",
  336. "_rev" : "_Z2KDRR2--A",
  337. "distance" : 500
  338. }
  339. ],
  340. "distance" : 1
  341. }
  342. ]

A route planner example, shortest path from Hamburg and Cologne to Lyon:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var g = examples.loadGraph("routeplanner");
  3. arangosh> g._shortestPath([{_id: 'germanCity/Cologne'},{_id: 'germanCity/Munich'}], 'frenchCity/Lyon',
  4. ........> {weight : 'distance'});

Show execution results

Hide execution results

  1. [
  2. {
  3. "vertices" : [
  4. "germanCity/Cologne",
  5. "frenchCity/Lyon"
  6. ],
  7. "edges" : [
  8. {
  9. "_key" : "78459",
  10. "_id" : "internationalHighway/78459",
  11. "_from" : "germanCity/Cologne",
  12. "_to" : "frenchCity/Lyon",
  13. "_rev" : "_Z2KDRUW---",
  14. "distance" : 700
  15. }
  16. ],
  17. "distance" : 1
  18. }
  19. ]

_distanceTo

The _distanceTo function returns all paths and there distance within a graph.

graph._distanceTo(startVertexExample, endVertexExample, options)

This function is a wrapper of graph._shortestPath.It does not return the actual path but only the distance between two vertices.

Examples

A route planner example, shortest distance from all german to all french cities:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var g = examples.loadGraph("routeplanner");
  3. arangosh> g._distanceTo({}, {}, {weight : 'distance', endVertexCollectionRestriction : 'frenchCity',
  4. ........> startVertexCollectionRestriction : 'germanCity'});

Show execution results

Hide execution results

  1. [
  2. {
  3. "startVertex" : "frenchCity/Lyon",
  4. "vertex" : "frenchCity/Paris",
  5. "distance" : 1
  6. },
  7. {
  8. "startVertex" : "frenchCity/Lyon",
  9. "vertex" : "germanCity/Berlin",
  10. "distance" : 1
  11. },
  12. {
  13. "startVertex" : "frenchCity/Lyon",
  14. "vertex" : "germanCity/Cologne",
  15. "distance" : 1
  16. },
  17. {
  18. "startVertex" : "frenchCity/Lyon",
  19. "vertex" : "germanCity/Hamburg",
  20. "distance" : 1
  21. },
  22. {
  23. "startVertex" : "frenchCity/Paris",
  24. "vertex" : "frenchCity/Lyon",
  25. "distance" : 1
  26. },
  27. {
  28. "startVertex" : "frenchCity/Paris",
  29. "vertex" : "germanCity/Berlin",
  30. "distance" : 1
  31. },
  32. {
  33. "startVertex" : "frenchCity/Paris",
  34. "vertex" : "germanCity/Cologne",
  35. "distance" : 1
  36. },
  37. {
  38. "startVertex" : "frenchCity/Paris",
  39. "vertex" : "germanCity/Hamburg",
  40. "distance" : 1
  41. },
  42. {
  43. "startVertex" : "germanCity/Berlin",
  44. "vertex" : "frenchCity/Lyon",
  45. "distance" : 1
  46. },
  47. {
  48. "startVertex" : "germanCity/Berlin",
  49. "vertex" : "frenchCity/Paris",
  50. "distance" : 1
  51. },
  52. {
  53. "startVertex" : "germanCity/Berlin",
  54. "vertex" : "germanCity/Cologne",
  55. "distance" : 1
  56. },
  57. {
  58. "startVertex" : "germanCity/Berlin",
  59. "vertex" : "germanCity/Hamburg",
  60. "distance" : 1
  61. },
  62. {
  63. "startVertex" : "germanCity/Cologne",
  64. "vertex" : "frenchCity/Lyon",
  65. "distance" : 1
  66. },
  67. {
  68. "startVertex" : "germanCity/Cologne",
  69. "vertex" : "frenchCity/Paris",
  70. "distance" : 1
  71. },
  72. {
  73. "startVertex" : "germanCity/Cologne",
  74. "vertex" : "germanCity/Berlin",
  75. "distance" : 1
  76. },
  77. {
  78. "startVertex" : "germanCity/Cologne",
  79. "vertex" : "germanCity/Hamburg",
  80. "distance" : 1
  81. },
  82. {
  83. "startVertex" : "germanCity/Hamburg",
  84. "vertex" : "frenchCity/Lyon",
  85. "distance" : 1
  86. },
  87. {
  88. "startVertex" : "germanCity/Hamburg",
  89. "vertex" : "frenchCity/Paris",
  90. "distance" : 1
  91. },
  92. {
  93. "startVertex" : "germanCity/Hamburg",
  94. "vertex" : "germanCity/Berlin",
  95. "distance" : 1
  96. },
  97. {
  98. "startVertex" : "germanCity/Hamburg",
  99. "vertex" : "germanCity/Cologne",
  100. "distance" : 1
  101. }
  102. ]

A route planner example, shortest distance from Hamburg and Cologne to Lyon:

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var g = examples.loadGraph("routeplanner");
  3. arangosh> g._distanceTo([{_id: 'germanCity/Cologne'},{_id: 'germanCity/Munich'}], 'frenchCity/Lyon',
  4. ........> {weight : 'distance'});

Show execution results

Hide execution results

  1. [
  2. {
  3. "startVertex" : "germanCity/Cologne",
  4. "vertex" : "frenchCity/Lyon",
  5. "distance" : 1
  6. }
  7. ]

_absoluteEccentricity

Get theeccentricityof the vertices defined by the examples.

graph._absoluteEccentricity(vertexExample, options)

The function accepts an id, an example, a list of examples or even an emptyexample as parameter for vertexExample.

Parameters

  • vertexExample (optional) Filter the vertices, see Definition of examples
  • options (optional) An object defining further options. Can have the following values:
    • direction: The direction of the edges. Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction : One or a list of edge-collection names that should beconsidered to be on the path.
    • startVertexCollectionRestriction : One or a list of vertex-collection names that should beconsidered for source vertices.
    • endVertexCollectionRestriction : One or a list of vertex-collection names that should beconsidered for target vertices.
    • weight: The name of the attribute of the edges containing the weight.
    • defaultWeight: Only used with the option weight.If an edge does not have the attribute named as defined in option weight this defaultis used as weight.If no default is supplied the default would be positive infinity so the path andhence the eccentricity can not be calculated.

Examples

A route planner example, the absolute eccentricity of all locations.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteEccentricity({});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 1,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

A route planner example, the absolute eccentricity of all locations.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteEccentricity({}, {weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 1,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

A route planner example, the absolute eccentricity of all cities regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteEccentricity({}, {startVertexCollectionRestriction : 'germanCity',
  4. ........> direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

_eccentricity

Get the normalizedeccentricityof the vertices defined by the examples.

graph._eccentricity(vertexExample, options)

Similar to _absoluteEccentricity but returns a normalized result.

Examples

A route planner example, the eccentricity of all locations.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._eccentricity();

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 1,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

A route planner example, the weighted eccentricity.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._eccentricity({weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 1,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

_absoluteCloseness

Get theclosenessof the vertices defined by the examples.

graph._absoluteCloseness(vertexExample, options)

The function accepts an id, an example, a list of examples or even an emptyexample as parameter for vertexExample.

Parameters

  • vertexExample (optional) Filter the vertices, see Definition of examples
  • options (optional) An object defining further options. Can have the following values:
    • direction: The direction of the edges. Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction : One or a list of edge-collection names that should beconsidered to be on the path.
    • startVertexCollectionRestriction : One or a list of vertex-collection names that should beconsidered for source vertices.
    • endVertexCollectionRestriction : One or a list of vertex-collection names that should beconsidered for target vertices.
    • weight: The name of the attribute of the edges containing the weight.
    • defaultWeight: Only used with the option weight.If an edge does not have the attribute named as defined in option weight this defaultis used as weight.If no default is supplied the default would be positive infinity so the path andhence the closeness can not be calculated.

Examples

A route planner example, the absolute closeness of all locations.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteCloseness({});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 4,
  3. "frenchCity/Paris" : 4,
  4. "germanCity/Berlin" : 4,
  5. "germanCity/Cologne" : 4,
  6. "germanCity/Hamburg" : 4
  7. }

A route planner example, the absolute closeness of all locations.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteCloseness({}, {weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 4,
  3. "frenchCity/Paris" : 4,
  4. "germanCity/Berlin" : 4,
  5. "germanCity/Cologne" : 4,
  6. "germanCity/Hamburg" : 4
  7. }

A route planner example, the absolute closeness of all German Cities regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteCloseness({}, {startVertexCollectionRestriction : 'germanCity',
  4. ........> direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 4,
  5. "germanCity/Cologne" : 2,
  6. "germanCity/Hamburg" : 3
  7. }

_closeness

Get the normalizedclosenessof graphs vertices.

graph._closeness(options)

Similar to _absoluteCloseness but returns a normalized value.

Examples

A route planner example, the normalized closeness of all locations.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._closeness();

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 1,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

A route planner example, the closeness of all locations.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._closeness({weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 1,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 1,
  5. "germanCity/Cologne" : 1,
  6. "germanCity/Hamburg" : 1
  7. }

A route planner example, the closeness of all cities regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._closeness({direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 1,
  4. "germanCity/Berlin" : 0.25,
  5. "germanCity/Cologne" : 0.5,
  6. "germanCity/Hamburg" : 0.3333333333333333
  7. }

_absoluteBetweenness

Get thebetweennessof all vertices in the graph.

graph._absoluteBetweenness(vertexExample, options)

Parameters

  • vertexExample (optional) Filter the vertices, see Definition of examples
  • options (optional) An object defining further options. Can have the following values:
    • direction: The direction of the edges. Possible values are outbound, inbound and any (default).
    • weight: The name of the attribute of the edges containing the weight.
    • defaultWeight: Only used with the option weight.If an edge does not have the attribute named as defined in option weight this defaultis used as weight.If no default is supplied the default would be positive infinity so the path andhence the betweenness can not be calculated.

Examples

A route planner example, the absolute betweenness of all locations.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteBetweenness({});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 0,
  4. "germanCity/Berlin" : 0,
  5. "germanCity/Cologne" : 0,
  6. "germanCity/Hamburg" : 0
  7. }

A route planner example, the absolute betweenness of all locations.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteBetweenness({weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. }

A route planner example, the absolute betweenness of all cities regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._absoluteBetweenness({direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. }

_betweenness

Get the normalizedbetweennessof graphs vertices.

graph_module._betweenness(options)

Similar to _absoluteBetweenness but returns normalized values.

Examples

A route planner example, the betweenness of all locations.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._betweenness();

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 0,
  4. "germanCity/Berlin" : 0,
  5. "germanCity/Cologne" : 0,
  6. "germanCity/Hamburg" : 0
  7. }

A route planner example, the betweenness of all locations.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._betweenness({weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 0,
  4. "germanCity/Berlin" : 0,
  5. "germanCity/Cologne" : 0,
  6. "germanCity/Hamburg" : 0
  7. }

A route planner example, the betweenness of all cities regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._betweenness({direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. {
  2. "frenchCity/Lyon" : 0,
  3. "frenchCity/Paris" : 0,
  4. "germanCity/Berlin" : 0,
  5. "germanCity/Cologne" : 0,
  6. "germanCity/Hamburg" : 0
  7. }

_radius

Get theradiusof a graph.

`

Parameters

  • options (optional) An object defining further options. Can have the following values:
    • direction: The direction of the edges. Possible values are outbound, inbound and any (default).
    • weight: The name of the attribute of the edges containing the weight.
    • defaultWeight: Only used with the option weight.If an edge does not have the attribute named as defined in option weight this defaultis used as weight.If no default is supplied the default would be positive infinity so the path andhence the radius can not be calculated.

Examples

A route planner example, the radius of the graph.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._radius();

Show execution results

Hide execution results

  1. 1

A route planner example, the radius of the graph.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._radius({weight : 'distance'});

Show execution results

Hide execution results

  1. 1

A route planner example, the radius of the graph regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._radius({direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. 1

_diameter

Get thediameterof a graph.

graph._diameter(graphName, options)

Parameters

  • options (optional) An object defining further options. Can have the following values:
    • direction: The direction of the edges. Possible values are outbound, inbound and any (default).
    • weight: The name of the attribute of the edges containing the weight.
    • defaultWeight: Only used with the option weight.If an edge does not have the attribute named as defined in option weight this defaultis used as weight.If no default is supplied the default would be positive infinity so the path andhence the radius can not be calculated.

Examples

A route planner example, the diameter of the graph.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._diameter();

Show execution results

Hide execution results

  1. 1

A route planner example, the diameter of the graph.This considers the actual distances.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._diameter({weight : 'distance'});

Show execution results

Hide execution results

  1. 1

A route planner example, the diameter of the graph regarding onlyoutbound paths.

  1. arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
  2. arangosh> var graph = examples.loadGraph("routeplanner");
  3. arangosh> graph._diameter({direction : 'outbound', weight : 'distance'});

Show execution results

Hide execution results

  1. 1