ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent version here: Try latest

Graph operations

This chapter describes graph related AQL functions.

Short explanation of the example parameter

A lot of the following functions accept a vertex (or edge) example as parameter. This can contain the following:

  • {} : Returns all possible vertices for this graph
  • idString : Returns the vertex/edge with the id idString
  • [idString1, idString2 …] : Returns the vertices/edges with the ids matching the given strings.
  • {key1 : value1, key2 : value2} : Returns the vertices/edges that match this example, which means that both have key1 and key2 with the corresponding attributes
  • {key1.key2 : value1, key3 : value2} : It is possible to chain keys, which means that a document {key1 : {key2 : value1}, key3 : value2} would be a match
  • [{key1 : value1}, {key2 : value2}] : Returns the vertices/edges that match one of the examples, which means that either key1 or key2 are set with the corresponding value

The complexity of the shortest path algorithms

Most of the functions described in this chapter calculate the shortest paths for subsets of the graphs vertices. Hence the complexity of these functions depends of the chosen algorithm for this task. For Floyd-Warshall it is O(n^3) with n being the amount of vertices in the graph. For Dijkstra it would be O(x*y*n^2) with n being the amount of vertices in the graph, x the amount of start vertices and y the amount of target vertices. Hence a suggestion may be to use Dijkstra when x*y < n and the functions supports choosing your algorithm.

Example Graph

All examples in this chapter will use this simple city graph:

Cities Example Graph

This section describes various AQL functions which can be used to receive information about the graph’s vertices, edges, neighbor relationship and shared properties.

GRAPH_EDGES


GRAPH_EDGES (graphName, vertexExample, options)
The GRAPH_EDGES function returns all edges of the graph connected to the vertices defined by the example.
The complexity of this method is O(n*m^x) with n being the vertices defined by the parameter vertexExamplex, m the average amount of edges of a vertex and x the maximal depths. Hence the default call would have a complexity of O(n*m);
Parameters

  • graphName : The name of the graph as a string.
  • vertexExample : An example for the desired vertices (see example).
  • options (optional) : An object containing the following options:
    • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction : One or multiple edge collection names. Only edges from these collections will be considered for the path.
    • startVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as start vertex of a path.
    • endVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as end vertex of a path.
    • edgeExamples : A filter example for the edges (see example).
    • minDepth : Defines the minimal length of a path from an edge to a vertex (default is 1, which means only the edges directly connected to a vertex would be returned).
    • maxDepth : Defines the maximal length of a path from an edge to a vertex (default is 1, which means only the edges directly connected to a vertex would be returned).
    • maxIterations: the maximum number of iterations that the traversal is allowed to perform. It is sensible to set this number so unbounded traversals will terminate.
    • includeData: Defines if the result should contain only ids (false) or if all documents should be fully extracted (true). By default this parameter is set to false, so only ids will be returned.

Examples
A route planner example, all edges to locations with a distance of either 700 or 600.:

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_EDGES("
........> +"'routeplanner', {}, {edgeExamples : [{distance: 600}, {distance: 700}]}) RETURN e"
........> ).toArray();
[ 
  "internationalHighway/1338460289" 
]


A route planner example, all outbound edges of Hamburg with a maximal depth of 2 :

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_EDGES("
........> +"'routeplanner', 'germanCity/Hamburg', {direction : 'outbound', maxDepth : 2}) RETURN e"
........> ).toArray();
show execution results


Including the data:

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_EDGES("
........> + "'routeplanner', 'germanCity/Hamburg', {direction : 'outbound',"
........> + "maxDepth : 2, includeData: true}) RETURN e"
........> ).toArray();
show execution results

GRAPH_VERTICES

The GRAPH_VERTICES function returns all vertices.
GRAPH_VERTICES (graphName, vertexExample, options)
According to the optional filters it will only return vertices that have outbound, inbound or any (default) edges.
Parameters

  • graphName : The name of the graph as a string.
  • vertexExample : An example for the desired vertices (see example).
  • options (optional) : An object containing the following options:
    • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
    • vertexCollectionRestriction : One or multiple vertex collections that should be considered.

Examples
A route planner example, all vertices of the graph

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_VERTICES("
........> +"'routeplanner', {}) RETURN e").toArray();
show execution results


A route planner example, all vertices from collection germanCity.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_VERTICES("
........> +"'routeplanner', {}, {direction : 'any', vertexCollectionRestriction" +
........> " : 'germanCity'}) RETURN e").toArray();
show execution results


GRAPH_NEIGHBORS

The GRAPH_NEIGHBORS function returns all neighbors of vertices.
GRAPH_NEIGHBORS (graphName, vertexExample, options)
By default only the direct neighbors (path length equals 1) are returned, but one can define the range of the path length to the neighbors with the options minDepth and maxDepth. The complexity of this method is O(n*m^x) with n being the vertices defined by the parameter 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

  • graphName : The name of the graph as a string.
  • vertexExample : An example for the desired vertices (see example).
  • options : An object containing the following options:
    • direction : The direction of the edges. Possible values are outbound, inbound and any (default).
    • edgeExamples : A filter example for the edges to the neighbors (see example).
    • neighborExamples : An example for the desired neighbors (see example).
    • edgeCollectionRestriction : One or multiple edge collection names. Only edges from these collections will be considered for the path.
    • vertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be contained in the result. This does not effect vertices on the path.
    • minDepth : Defines the minimal depth a path to a neighbor must have to be returned (default is 1).
    • maxDepth : Defines the maximal depth a path to a neighbor must have to be returned (default is 1).
    • maxIterations: the maximum number of iterations that the traversal is allowed to perform. It is sensible to set this number so unbounded traversals will terminate at some point.
    • includeData is a boolean value to define if the returned documents should be extracted instead of returning their ids only. The default is false.
      Note: in ArangoDB versions prior to 2.6 NEIGHBORS returned the array of neighbor vertices with all attributes and not just the vertex ids. To return to the same behavior, set the includeData option to true in 2.6 and above.

Examples
A route planner example, all neighbors of locations with a distance of either 700 or 600.:

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_NEIGHBORS("
........> +"'routeplanner', {}, {edgeExamples : [{distance: 600}, {distance: 700}]}) RETURN e"
........> ).toArray();
[ 
  "germanCity/Cologne", 
  "frenchCity/Lyon" 
]


A route planner example, all outbound neighbors of Hamburg with a maximal depth of 2 :

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_NEIGHBORS("
........> +"'routeplanner', 'germanCity/Hamburg', {direction : 'outbound', maxDepth : 2}) RETURN e"
........> ).toArray();
show execution results


GRAPH_COMMON_NEIGHBORS

The GRAPH_COMMON_NEIGHBORS function returns all common neighbors of the vertices defined by the examples.
GRAPH_COMMON_NEIGHBORS (graphName, vertex1Example, vertex2Examples, optionsVertex1, optionsVertex2)
This function returns the intersection of GRAPH_NEIGHBORS(vertex1Example, optionsVertex1) and GRAPH_NEIGHBORS(vertex2Example, optionsVertex2). The complexity of this method is O(n*m^x) with n being the maximal amount of vertices defined by the parameters vertexExamples, m the average amount of neighbors and x the maximal depths. Hence the default call would have a complexity of O(n*m);
For parameter documentation read the documentation of GRAPH_NEIGHBORS.

Examples
A route planner example, all common neighbors of capitals.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_COMMON_NEIGHBORS("
........> +"'routeplanner', {isCapital : true}, {isCapital : true}) RETURN e"
........> ).toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_COMMON_NEIGHBORS("
........> +"'routeplanner', 'germanCity/Hamburg', {}, {direction : 'outbound', maxDepth : 2}, "+
........> "{direction : 'outbound', maxDepth : 2}) RETURN e"
........> ).toArray();
show execution results


GRAPH_COMMON_PROPERTIES


GRAPH_COMMON_PROPERTIES (graphName, vertex1Example, vertex2Examples, options)
The GRAPH_COMMON_PROPERTIES function returns a list of objects which have the id of the vertices defined by vertex1Example as keys and a list of vertices defined by vertex21Example, that share common properties as value. Notice that only the vertex id and the matching attributes are returned in the result.
The complexity of this method is O(n) with n being the maximal amount of vertices defined by the parameters vertexExamples.
Parameters

  • graphName : The name of the graph as a string.
  • vertex1Example : An example for the desired vertices (see example).
  • vertex2Example : An example for the desired vertices (see example).
  • options (optional) : An object containing the following options:
    • vertex1CollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered.
    • vertex2CollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered.
    • ignoreProperties : One or multiple attributes of a document that should be ignored, either a string or an array..

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_COMMON_PROPERTIES("
........> +"'routeplanner', {}, {}) RETURN e"
........> ).toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_COMMON_PROPERTIES("
........> +"'routeplanner', {}, {}, {ignoreProperties: 'population'}) RETURN e"
........> ).toArray();
show execution results


Shortest Paths, distances and traversals.

This section describes AQL functions, that calculate paths from a subset of vertices in a graph to another subset of vertices.

GRAPH_PATHS

The GRAPH_PATHS function returns all paths of a graph.
GRAPH_PATHS (graphName, options)
The complexity of this method is O(n*n*m) with n being the amount of vertices in the graph and m the average amount of connected edges;
Parameters

  • graphName : The name of the graph as a string.
  • options : An object containing the following options:
    • 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 must have 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”:

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("social");
arangosh> db._query("RETURN GRAPH_PATHS('social')").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("social");
arangosh> db._query(
........> "RETURN GRAPH_PATHS('social', {direction : 'inbound', minLength : 1, maxLength :  2})"
........> ).toArray();
show execution results

GRAPH_SHORTEST_PATH

The GRAPH_SHORTEST_PATH function returns all shortest paths of a graph.
GRAPH_SHORTEST_PATH (graphName, startVertexExample, endVertexExample, options)
This function determines all shortest paths in a graph identified by graphName. If one wants to call this function to receive nearly all shortest paths for a graph the option algorithm should be set to Floyd-Warshall to increase performance. If no algorithm is provided in the options the function chooses the appropriate one (either Floyd-Warshall or Dijkstra) according to its parameters. The length of a path is by default the amount of edges from one start vertex to an end vertex. The option weight allows the user to define an edge attribute representing the length.
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • startVertexExample : An example for the desired start Vertices (see example).
  • endVertexExample : An example for the desired end Vertices (see example).
  • options (optional) : An object containing the following options:
    • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction : One or multiple edge collection names. Only edges from these collections will be considered for the path.
    • startVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as start vertex of a path.
    • endVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as end vertex of a path.
    • edgeExamples : A filter example for the edges in the shortest paths (see example).
    • algorithm : The algorithm to calculate the shortest paths. If both start and end vertex examples are empty Floyd-Warshall is used, otherwise the default is Dijkstra.
    • weight : The name of the attribute of the 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 default is used as length. If no default is supplied the default would be positive Infinity so the path could not be calculated.
    • stopAtFirstMatch : Only useful if targetVertices is an example that matches to more than one vertex. If so only the shortest path to the closest of these target vertices is returned. This flag is of special use if you have target pattern and you want to know which vertex with this pattern is matched first.
    • includeData : Triggers if only _id’s are returned (false, default) or if data is included for all objects as well (true) This will modify the content of vertex, path.vertices and path.edges.
      NOTE: Since version 2.6 we have included a new optional parameter includeData. This parameter triggers if the result contains the real data object true or it just includes the _id values false. The default value is false as it yields performance benefits.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_SHORTEST_PATH("
........> + "'routeplanner', {}, {}, {" +
........> "weight : 'distance', endVertexCollectionRestriction : 'frenchCity', " +
........> "includeData: true, " +
........> "startVertexCollectionRestriction : 'germanCity'}) RETURN [e.startVertex, e.vertex._id, " +
........> "e.distance, LENGTH(e.paths)]"
........> ).toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_SHORTEST_PATH("
........> +"'routeplanner', [{_id: 'germanCity/Cologne'},{_id: 'germanCity/Munich'}], " +
........> "'frenchCity/Lyon', " +
........> "{weight : 'distance'}) RETURN [e.startVertex, e.vertex, e.distance, LENGTH(e.paths)]"
........> ).toArray();
show execution results


GRAPH_TRAVERSAL

The GRAPH_TRAVERSAL function traverses through the graph.
GRAPH_TRAVERSAL (graphName, startVertexExample, direction, options)
This function performs traversals on the given graph.
The complexity of this function strongly depends on the usage.
Parameters

  • graphName : The name of the graph as a string.
  • startVertexExample : An example for the desired vertices (see example).
  • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
  • options: Object containing optional options.
    Options:
  • strategy: determines the visitation strategy. Possible values are depthfirst and breadthfirst. Default is breadthfirst.
  • order: determines the visitation order. Possible values are preorder and postorder.
  • itemOrder: determines the order in which connections returned by the expander will be processed. Possible values are forward and backward.
  • maxDepth: if set to a value greater than 0, this will limit the traversal to this maximum depth.
  • minDepth: if set to a value greater than 0, all vertices found on a level below the minDepth level will not be included in the result.
  • maxIterations: the maximum number of iterations that the traversal is allowed to perform. It is sensible to set this number so unbounded traversals will terminate at some point.
  • uniqueness: an object that defines how repeated visitations of vertices should be handled. The uniqueness object can have a sub-attribute vertices, and a sub-attribute edges. Each sub-attribute can have one of the following values:
    • “none”: no uniqueness constraints
    • “path”: element is excluded if it is already contained in the current path. This setting may be sensible for graphs that contain cycles (e.g. A -> B -> C -> A).
    • “global”: element is excluded if it was already found/visited at any point during the traversal.
  • filterVertices An optional array of example vertex documents that the traversal will treat specially. If no examples are given, the traversal will handle all encountered vertices equally. If one or many vertex examples are given, the traversal will exclude any non-matching vertex from the result and/or not descend into it. Optionally, filterVertices can contain a string containing the name of a user-defined AQL function that should be responsible for filtering. If so, the AQL function is expected to have the following signature:
    function (config, vertex, path)
    If a custom AQL function is used for filterVertices, it is expected to return one of the following values:

  • vertexFilterMethod: Only useful in conjunction with filterVertices and if no user-defined AQL function is used. If specified, it will influence how vertices are handled that don’t match the examples in filterVertices:

Examples
A route planner example, start a traversal from Hamburg :

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_TRAVERSAL('routeplanner', 'germanCity/Hamburg'," +
........> " 'outbound') RETURN e"
........> ).toArray();
show execution results


A route planner example, start a traversal from Hamburg with a max depth of 1 so only the direct neighbors of Hamburg are returned:

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_TRAVERSAL('routeplanner', 'germanCity/Hamburg'," +
........> " 'outbound', {maxDepth : 1}) RETURN e"
........> ).toArray();
show execution results


GRAPH_TRAVERSAL_TREE

The GRAPH_TRAVERSAL_TREE function traverses through the graph.
GRAPH_TRAVERSAL_TREE (graphName, startVertexExample, direction, connectName, options) This function creates a tree format from the result for a better visualization of the path. This function performs traversals on the given graph.
The complexity of this function strongly depends on the usage.
Parameters

  • graphName : The name of the graph as a string.
  • startVertexExample : An example for the desired vertices (see example).
  • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
  • connectName : The result attribute which contains the connection.
  • options (optional) : An object containing options, see Graph Traversals:

Examples
A route planner example, start a traversal from Hamburg :

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_TRAVERSAL_TREE('routeplanner', 'germanCity/Hamburg'," +
........> " 'outbound', 'connnection') RETURN e"
........> ).toArray();
show execution results


A route planner example, start a traversal from Hamburg with a max depth of 1 so only the direct neighbors of Hamburg are returned:

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_TRAVERSAL_TREE('routeplanner', 'germanCity/Hamburg',"+
........> " 'outbound', 'connnection', {maxDepth : 1}) RETURN e"
........> ).toArray();
show execution results


GRAPH_DISTANCE_TO

The GRAPH_DISTANCE_TO function returns all paths and there distance within a graph.
GRAPH_DISTANCE_TO (graphName, startVertexExample, endVertexExample, options)
This function is a wrapper of GRAPH_SHORTEST_PATH. It does not return the actual path but only the distance between two vertices.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_DISTANCE_TO("
........> +"'routeplanner', {}, {}, { " +
........> " weight : 'distance', endVertexCollectionRestriction : 'germanCity', " +
........> "startVertexCollectionRestriction : 'frenchCity'}) RETURN [e.startVertex, e.vertex, " +
........> "e.distance]"
........> ).toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("FOR e IN GRAPH_DISTANCE_TO("
........> + "'routeplanner', [{_id: 'germanCity/Cologne'},{_id: 'germanCity/Hamburg'}], " +
........> "'frenchCity/Lyon', " +
........> "{weight : 'distance'}) RETURN [e.startVertex, e.vertex, e.distance]"
........> ).toArray();
show execution results


Graph measurements.

This section describes AQL functions to calculate various graph related measurements as defined in the mathematical graph theory.

GRAPH_ABSOLUTE_ECCENTRICITY


GRAPH_ABSOLUTE_ECCENTRICITY (graphName, vertexExample, options)
The GRAPH_ABSOLUTE_ECCENTRICITY function returns the eccentricity of the vertices defined by the examples.
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • vertexExample : An example for the desired vertices (see example).
  • options (optional) : An object containing the following options:
    • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction : One or multiple edge collection names. Only edges from these collections will be considered for the path.
    • startVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as start vertex of a path.
    • endVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as end vertex of a path.
    • edgeExamples : A filter example for the edges in the shortest paths (see example).
    • algorithm : The algorithm to calculate the shortest paths as a string. If vertex example is empty Floyd-Warshall is used as default, otherwise the default is Dijkstra
    • weight : The name of the attribute of the 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 default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_ECCENTRICITY('routeplanner', {})").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_ECCENTRICITY("
........> +"'routeplanner', {}, {weight : 'distance'})").toArray();
show execution results


A route planner example, the absolute eccentricity of all German cities regarding only outbound paths.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_ECCENTRICITY("
........> + "'routeplanner', {}, {startVertexCollectionRestriction : 'germanCity', " +
........> "direction : 'outbound', weight : 'distance'})").toArray();
show execution results


GRAPH_ECCENTRICITY


GRAPH_ECCENTRICITY (graphName, options)
The GRAPH_ECCENTRICITY function returns the normalized eccentricity of the graphs vertices
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • options (optional) : An object containing the following options:
    • direction : The direction of the edges as a string. Possible values are outbound, inbound and any (default).
    • algorithm : The algorithm to calculate the shortest paths as a string. Possible values are Floyd-Warshall (default) and Dijkstra.
    • weight : The name of the attribute of the 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 default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ECCENTRICITY('routeplanner')").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ECCENTRICITY('routeplanner', {weight : 'distance'})"
........> ).toArray();
show execution results


GRAPH_ABSOLUTE_CLOSENESS


GRAPH_ABSOLUTE_CLOSENESS (graphName, vertexExample, options)
The GRAPH_ABSOLUTE_CLOSENESS function returns the closeness of the vertices defined by the examples.
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • vertexExample : An example for the desired vertices (see example).
  • options : An object containing the following options:
    • direction : The direction of the edges. Possible values are outbound, inbound and any (default).
    • edgeCollectionRestriction : One or multiple edge collection names. Only edges from these collections will be considered for the path.
    • startVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as start vertex of a path.
    • endVertexCollectionRestriction : One or multiple vertex collection names. Only vertices from these collections will be considered as end vertex of a path.
    • edgeExamples : A filter example for the edges in the shortest paths ( see example).
    • algorithm : The algorithm to calculate the shortest paths. Possible values are Floyd-Warshall (default) and Dijkstra.
    • weight : The name of the attribute of the edges containing the length.
    • defaultWeight : Only used with the option weight. If an edge does not have the attribute named as defined in option weight this default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_CLOSENESS('routeplanner', {})").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_CLOSENESS("
........> +"'routeplanner', {}, {weight : 'distance'})").toArray();
show execution results


A route planner example, the absolute closeness of all German cities regarding only outbound paths.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_CLOSENESS("
........> + "'routeplanner', {}, {startVertexCollectionRestriction : 'germanCity', " +
........> "direction : 'outbound', weight : 'distance'})").toArray();
show execution results


GRAPH_CLOSENESS


GRAPH_CLOSENESS (graphName, options)
The GRAPH_CLOSENESS function returns the normalized closeness of graphs vertices.
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • options : An object containing the following options:
    • direction : The direction of the edges. Possible values are outbound, inbound and any (default).
    • algorithm : The algorithm to calculate the shortest paths. Possible values are Floyd-Warshall (default) and Dijkstra.
    • weight : The name of the attribute of the edges containing the length.
    • defaultWeight : Only used with the option weight. If an edge does not have the attribute named as defined in option weight this default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_CLOSENESS('routeplanner')").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_CLOSENESS("
........> +"'routeplanner', {weight : 'distance'})").toArray();
show execution results


A route planner example, the absolute closeness of all cities regarding only outbound paths.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_CLOSENESS("
........> + "'routeplanner',{direction : 'outbound', weight : 'distance'})"
........> ).toArray();
show execution results


GRAPH_ABSOLUTE_BETWEENNESS


GRAPH_ABSOLUTE_BETWEENNESS (graphName, options)
The GRAPH_ABSOLUTE_BETWEENNESS function returns the betweenness of all vertices in the graph.
The complexity of the function is described here.

  • graphName : The name of the graph as a string.
  • options : An object containing the following options:
    • 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 length.
    • defaultWeight : Only used with the option weight. If an edge does not have the attribute named as defined in option weight this default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the betweenness can not be calculated.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_BETWEENNESS('routeplanner', {})").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_BETWEENNESS("
........> +"'routeplanner', {weight : 'distance'})").toArray();
show execution results


A route planner example, the absolute closeness regarding only outbound paths.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_ABSOLUTE_BETWEENNESS("
........> + "'routeplanner', {direction : 'outbound', weight : 'distance'})"
........> ).toArray();
show execution results


GRAPH_BETWEENNESS


GRAPH_BETWEENNESS (graphName, options)
The GRAPH_BETWEENNESS function returns the betweenness of graphs vertices.
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • options : An object containing the following options:
    • 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 length.
    • defaultWeight : Only used with the option weight. If an edge does not have the attribute named as defined in option weight this default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_BETWEENNESS('routeplanner')").toArray();
show execution results


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_BETWEENNESS('routeplanner', {weight : 'distance'})").toArray();
show execution results


A route planner example, the betweenness regarding only outbound paths.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_BETWEENNESS("
........> + "'routeplanner', {direction : 'outbound', weight : 'distance'})").toArray();
show execution results


GRAPH_RADIUS


GRAPH_RADIUS (graphName, options)
The GRAPH_RADIUS function returns the radius of a graph.
The complexity of the function is described here.

  • graphName : The name of the graph as a string.
  • options : An object containing the following options:
    • direction : The direction of the edges. Possible values are outbound, inbound and any (default).
    • algorithm : The algorithm to calculate the shortest paths as a string. Possible values are Floyd-Warshall (default) and Dijkstra.
    • weight : The name of the attribute of the edges containing the length.
    • defaultWeight : Only used with the option weight. If an edge does not have the attribute named as defined in option weight this default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

Examples
A route planner example, the radius of the graph.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_RADIUS('routeplanner')").toArray();
[ 
  1 
]


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_RADIUS('routeplanner', {weight : 'distance'})").toArray();
[ 
  850 
]


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_RADIUS("
........> + "'routeplanner', {direction : 'outbound', weight : 'distance'})"
........> ).toArray();
[ 
  550 
]


GRAPH_DIAMETER


GRAPH_DIAMETER (graphName, options)
The GRAPH_DIAMETER function returns the diameter of a graph.
The complexity of the function is described here.
Parameters

  • graphName : The name of the graph as a string.
  • options : An object containing the following options:
    • direction : The direction of the edges. Possible values are outbound, inbound and any (default).
    • algorithm : The algorithm to calculate the shortest paths as a string. Possible values are Floyd-Warshall (default) and Dijkstra.
    • weight : The name of the attribute of the edges containing the length.
    • defaultWeight : Only used with the option weight. If an edge does not have the attribute named as defined in option weight this default is used as length. If no default is supplied the default would be positive Infinity so the path and hence the eccentricity can not be calculated.

Examples
A route planner example, the diameter of the graph.

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_DIAMETER('routeplanner')").toArray();
[ 
  1 
]


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_DIAMETER('routeplanner', {weight : 'distance'})").toArray();
[ 
  1200 
]


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

arangosh> var examples = require("org/arangodb/graph-examples/example-graph.js");
arangosh> var g = examples.loadGraph("routeplanner");
arangosh> db._query("RETURN GRAPH_DIAMETER("
........> + "'routeplanner', {direction : 'outbound', weight : 'distance'})"
........> ).toArray();
[ 
  1200 
]