> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# /solve/graph

```
URL: http://<db.host>:<db.port>/solve/graph
```

Solves an existing graph for a type of problem (e.g., shortest path, page rank,
traveling salesman, etc.) using source nodes, destination nodes, and
additional, optional weights and restrictions.

IMPORTANT: It's highly recommended that you review the
[Graphs and Solvers](../../graph_solver/network_graph_solver/) concepts
documentation, the [Graph REST Tutorial](../../guides/graph_rest_guide/),
and/or some [/solve/graph examples](/content/guides/tags/graph-solve)
before using this endpoint.

## Input Parameter Description

<ParamField body="graph_name" type="string">
  Name of the graph resource to solve.
</ParamField>

<ParamField body="weights_on_edges" type="array of strings">
  Additional weights to apply to the edges of an existing graph. Weights must be specified using [identifiers](../../graph_solver/network_graph_solver/#identifiers); identifiers are grouped as [combinations](../../graph_solver/network_graph_solver/#id-combos). Identifiers can be used with existing column names, e.g., 'table.column AS WEIGHTS\_EDGE\_ID', expressions, e.g., 'ST\_LENGTH(wkt) AS WEIGHTS\_VALUESPECIFIED', or constant values, e.g., '\{4, 15, 2} AS WEIGHTS\_VALUESPECIFIED'. Any provided weights will be added (in the case of 'WEIGHTS\_VALUESPECIFIED') to or multiplied with (in the case of 'WEIGHTS\_FACTORSPECIFIED') the existing weight(s). If using constant values in an identifier combination, the number of values specified must match across the combination.

  The default value is an empty array ( \[] ).
</ParamField>

<ParamField body="restrictions" type="array of strings">
  Additional restrictions to apply to the nodes/edges of an existing graph. Restrictions must be specified using [identifiers](../../graph_solver/network_graph_solver/#identifiers); identifiers are grouped as [combinations](../../graph_solver/network_graph_solver/#id-combos). Identifiers can be used with existing column names, e.g., 'table.column AS RESTRICTIONS\_EDGE\_ID', expressions, e.g., 'column/2 AS RESTRICTIONS\_VALUECOMPARED', or constant values, e.g., '\{0, 0, 0, 1} AS RESTRICTIONS\_ONOFFCOMPARED'. If using constant values in an identifier combination, the number of values specified must match across the combination. If remove\_previous\_restrictions option is set to true, any provided restrictions will replace the existing restrictions. Otherwise, any provided restrictions will be added (in the case of 'RESTRICTIONS\_VALUECOMPARED') to or replaced (in the case of 'RESTRICTIONS\_ONOFFCOMPARED').

  The default value is an empty array ( \[] ).
</ParamField>

<ParamField body="solver_type" type="string">
  The type of solver to use for the graph.

  The default value is `SHORTEST_PATH`.

  * **SHORTEST\_PATH**: Solves for the optimal (shortest) path based on weights and restrictions from one source to destinations nodes. Also known as the Dijkstra solver.
  * **PAGE\_RANK**: Solves for the probability of each destination node being visited based on the links of the graph topology. Weights are not required to use this solver.
  * **PROBABILITY\_RANK**: Solves for the transitional probability (Hidden Markov) for each node based on the weights (probability assigned over given edges).
  * **CENTRALITY**: Solves for the degree of a node to depict how many pairs of individuals that would have to go through the node to reach one another in the minimum number of hops. Also known as betweenness.
  * **MULTIPLE\_ROUTING**: Solves for finding the minimum cost cumulative path for a round-trip starting from the given source and visiting each given destination node once then returning to the source. Also known as the traveling salesman problem.
  * **INVERSE\_SHORTEST\_PATH**: Solves for finding the optimal path cost for each destination node to route to the source node. Also known as inverse Dijkstra or the service man routing problem.
  * **BACKHAUL\_ROUTING**: Solves for optimal routes that connect remote asset nodes to the fixed (backbone) asset nodes.
  * **ALLPATHS**: Solves for paths that would give costs between max and min solution radia - Make sure to limit by the 'max\_solution\_targets' option. Min cost should be >= shortest\_path cost.
  * **STATS\_ALL**: Solves for graph statistics such as graph diameter, longest pairs, vertex valences, topology numbers, average and max cluster sizes, etc.
  * **CLOSENESS**: Solves for the centrality closeness score per node as the sum of the inverse shortest path costs to all nodes in the graph.
</ParamField>

<ParamField body="source_nodes" type="array of strings">
  It can be one of the nodal identifiers - e.g: 'NODE\_WKTPOINT' for source nodes. For *BACKHAUL\_ROUTING*, this list depicts the fixed assets.

  The default value is an empty array ( \[] ).
</ParamField>

<ParamField body="destination_nodes" type="array of strings">
  It can be one of the nodal identifiers - e.g: 'NODE\_WKTPOINT' for destination (target) nodes. For *BACKHAUL\_ROUTING*, this list depicts the remote assets.

  The default value is an empty array ( \[] ).
</ParamField>

<ParamField body="solution_table" type="string">
  Name of the table to store the solution, in \[schema\_name.]table\_name format, using standard [name resolution rules](../../concepts/tables/#table-name-resolution).

  The default value is `graph_solutions`.
</ParamField>

<ParamField body="options" type="map of string to strings">
  Additional parameters.

  The default value is an empty map ( \{} ).

  <Expandable title="options">
    <ParamField body="max_solution_radius">
      For *ALLPATHS*, *SHORTEST\_PATH* and *INVERSE\_SHORTEST\_PATH* solvers only. Sets the maximum solution cost radius, which ignores the input parameter *destination\_nodes* list and instead outputs the nodes within the radius sorted by ascending cost. If set to '0.0', the setting is ignored.

      The default value is `0.0`.
    </ParamField>

    <ParamField body="min_solution_radius">
      For *ALLPATHS*, *SHORTEST\_PATH* and *INVERSE\_SHORTEST\_PATH* solvers only. Applicable only when *max\_solution\_radius* is set. Sets the minimum solution cost radius, which ignores the input parameter *destination\_nodes* list and instead outputs the nodes within the radius sorted by ascending cost. If set to '0.0', the setting is ignored.

      The default value is `0.0`.
    </ParamField>

    <ParamField body="max_solution_targets">
      For *ALLPATHS*, *SHORTEST\_PATH* and *INVERSE\_SHORTEST\_PATH* solvers only. Sets the maximum number of solution targets, which ignores the input parameter *destination\_nodes* list and instead outputs no more than n number of nodes sorted by ascending cost where n is equal to the setting value. If set to 0, the setting is ignored.

      The default value is `1000`.
    </ParamField>

    <ParamField body="uniform_weights">
      When specified, assigns the given value to all the edges in the graph. Note that weights provided in input parameter *weights\_on\_edges* will override this value.
    </ParamField>

    <ParamField body="left_turn_penalty">
      This will add an additional weight over the edges labeled as 'left turn' if the 'add\_turn' option parameter of the [/create/graph](/content/api/rest/create_graph_rest) was invoked at graph creation.

      The default value is `0.0`.
    </ParamField>

    <ParamField body="right_turn_penalty">
      This will add an additional weight over the edges labeled as' right turn' if the 'add\_turn' option parameter of the [/create/graph](/content/api/rest/create_graph_rest) was invoked at graph creation.

      The default value is `0.0`.
    </ParamField>

    <ParamField body="intersection_penalty">
      This will add an additional weight over the edges labeled as 'intersection' if the 'add\_turn' option parameter of the [/create/graph](/content/api/rest/create_graph_rest) was invoked at graph creation.

      The default value is `0.0`.
    </ParamField>

    <ParamField body="sharp_turn_penalty">
      This will add an additional weight over the edges labeled as 'sharp turn' or 'u-turn' if the 'add\_turn' option parameter of the [/create/graph](/content/api/rest/create_graph_rest) was invoked at graph creation.

      The default value is `0.0`.
    </ParamField>

    <ParamField body="num_best_paths">
      For *MULTIPLE\_ROUTING* solvers only; sets the number of shortest paths computed from each node. This is the heuristic criterion. Default value of zero allows the number to be computed automatically by the solver. The user may want to override this parameter to speed-up the solver.

      The default value is `0`.
    </ParamField>

    <ParamField body="max_num_combinations">
      For *MULTIPLE\_ROUTING* solvers only; sets the cap on the combinatorial sequences generated. If the default value of two millions is overridden to a lesser value, it can potentially speed up the solver.

      The default value is `2000000`.
    </ParamField>

    <ParamField body="output_edge_path">
      If true then concatenated edge IDs will be added as the EDGE path column of the solution table for each source and target pair in shortest path solves.

      The default value is `false`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="output_wkt_path">
      If true then concatenated wkt line segments will be added as the Wktroute column of the solution table for each source and target pair in shortest path solves.

      The default value is `true`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="server_id">
      Indicates which graph server(s) to send the request to. Default is to send to the server, amongst those containing the corresponding graph, that has the most computational bandwidth. For SHORTEST\_PATH solver type, the input is split amongst the server containing the corresponding graph.
    </ParamField>

    <ParamField body="convergence_limit">
      For *PAGE\_RANK* solvers only; Maximum percent relative threshold on the page rank scores of each node between consecutive iterations to satisfy convergence. Default value is 1 (one) percent.

      The default value is `1.0`.
    </ParamField>

    <ParamField body="max_iterations">
      For *PAGE\_RANK* solvers only; Maximum number of page rank iterations for satisfying convergence. Default value is 100.

      The default value is `100`.
    </ParamField>

    <ParamField body="max_runs">
      For all *CENTRALITY* solvers only; Sets the maximum number of shortest path runs; maximum possible value is the number of nodes in the graph. Default value of 0 enables this value to be auto computed by the solver.

      The default value is `0`.
    </ParamField>

    <ParamField body="output_clusters">
      For *STATS\_ALL* solvers only; the cluster index for each node will be inserted as an additional column in the output.

      The default value is `false`.

      * **true**: An additional column 'CLUSTER' will be added for each node.
      * **false**: No extra cluster info per node will be available in the output.
    </ParamField>

    <ParamField body="solve_heuristic">
      Specify heuristic search criterion only for the geo graphs and shortest path solves towards a single target.

      The default value is `none`.

      * **astar**: Employs A-STAR heuristics to speed up the shortest path traversal.
      * **none**: No heuristics are applied.
    </ParamField>

    <ParamField body="astar_radius">
      For path solvers only when 'solve\_heuristic' option is 'astar'. The shortest path traversal front includes nodes only within this radius (kilometers) as it moves towards the target location.

      The default value is `70`.
    </ParamField>
  </Expandable>
</ParamField>

## Output Parameter Description

The Kinetica server embeds the endpoint response inside a standard response structure which contains status information and the actual response to the query.  Here is a description of the various fields of the wrapper:

<ResponseField name="status" type="String">
  'OK' or 'ERROR'
</ResponseField>

<ResponseField name="message" type="String">
  Empty if success or an error message
</ResponseField>

<ResponseField name="data_type" type="String">
  'solve\_graph\_response' or 'none' in case of an error
</ResponseField>

<ResponseField name="data" type="String">
  Empty string
</ResponseField>

<ResponseField name="data_str" type="JSON or String">
  This embedded JSON represents the result of the /solve/graph endpoint:

  <Expandable title="data_str">
    <ResponseField name="result" type="boolean">
      Indicates a successful solution on all servers.
    </ResponseField>

    <ResponseField name="result_per_destination_node" type="array of floats">
      Cost or page rank (based on solver type) for each destination node requested. Only populated if 'export\_solve\_results' option is set to true.
    </ResponseField>

    <ResponseField name="info" type="map of string to strings">
      Additional information.
    </ResponseField>
  </Expandable>

  Empty string in case of an error.
</ResponseField>
