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 edgeExamples
  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

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

Hide execution results

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 edgeExamples
  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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

  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" : "germanCity/Hamburg",
  34. "isCapital" : false,
  35. "population" : 1000000
  36. },
  37. {
  38. "_id" : "frenchCity/Lyon",
  39. "isCapital" : false
  40. }
  41. ]
  42. },
  43. {
  44. "germanCity/Hamburg" : [
  45. {
  46. "_id" : "germanCity/Cologne",
  47. "isCapital" : false,
  48. "population" : 1000000
  49. },
  50. {
  51. "_id" : "frenchCity/Lyon",
  52. "isCapital" : false
  53. }
  54. ]
  55. }
  56. ]

Hide execution results

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

  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" : "germanCity/Hamburg",
  34. "isCapital" : false
  35. },
  36. {
  37. "_id" : "frenchCity/Lyon",
  38. "isCapital" : false
  39. }
  40. ]
  41. },
  42. {
  43. "germanCity/Hamburg" : [
  44. {
  45. "_id" : "germanCity/Cologne",
  46. "isCapital" : false
  47. },
  48. {
  49. "_id" : "frenchCity/Lyon",
  50. "isCapital" : false
  51. }
  52. ]
  53. }
  54. ]

Hide execution results

_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

  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. ]

Hide execution results

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

  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. ]

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

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

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

Hide execution results

_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

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

Hide execution results

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

  1. {
  2. }

Hide execution results

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

  1. {
  2. }

Hide execution results

_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

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

Hide execution results

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

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

Hide execution results

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

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

Hide execution results

_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

  1. 1

Hide execution results

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

  1. 1

Hide execution results

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

  1. 1

Hide execution results

_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

  1. 1

Hide execution results

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

  1. 1

Hide execution results

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

  1. 1

Hide execution results