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

<div className="kinetica-pydoc">
  <div className="dl py method">
    <div className="dt sig sig-object py" id="gpudb.GPUdb.solve_graph"> <span className="sig-name descname"><span className="pre">solve\_graph</span></span><span className="sig-paren">(</span><span className="em sig-param"><span className="n"><span className="pre">graph\_name</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">None</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">weights\_on\_edges</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">\[]</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">restrictions</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">\[]</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">solver\_type</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">'SHORTEST\_PATH'</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">source\_nodes</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">\[]</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">destination\_nodes</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">\[]</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">solution\_table</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">'graph\_solutions'</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">options</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">{"{"}{"}"}</span></span></span><span className="sig-paren">)</span><a href="https://github.com/kineticadb/kinetica-api-python/blob/master/gpudb/gpudb.py#L40663"><span className="viewcode-link"><span className="pre">\[source]</span></span></a></div>

    <div className="dd">
      <p>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.</p>
      <p>IMPORTANT: It’s highly recommended that you review the <a className="reference external" href="/content/graph_solver/network_graph_solver/">Graphs and Solvers</a> concepts documentation, the <a className="reference external" href="/content/guides/graph_rest_guide/">Graph REST Tutorial</a>, and/or some <a className="reference external" href="/content/guides/tags/graph-solve">/solve/graph examples</a> before using this endpoint.</p>
      <p><strong>Parameters</strong></p>

      <div className="blockquote">
        <div>
          <div className="dl">
            <div className="dt">graph\_name (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Name of the graph resource to solve.</p>
            </div>

            <div className="dt">weights\_on\_edges (<span className="em">list of str</span>) –</div>

            <div className="dd">
              <p>Additional weights to apply to the edges of an existing graph. Weights must be specified using <a className="reference external" href="/content/graph_solver/network_graph_solver/#identifiers">identifiers</a>; identifiers are grouped as <a className="reference external" href="/content/graph_solver/network_graph_solver/#id-combos">combinations</a>. 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 list ( \[] ). The user can provide a single element (which will be automatically promoted to a list internally) or a list.</p>
            </div>

            <div className="dt">restrictions (<span className="em">list of str</span>) –</div>

            <div className="dd">
              <p>Additional restrictions to apply to the nodes/edges of an existing graph. Restrictions must be specified using <a className="reference external" href="/content/graph_solver/network_graph_solver/#identifiers">identifiers</a>; identifiers are grouped as <a className="reference external" href="/content/graph_solver/network_graph_solver/#id-combos">combinations</a>. 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 list ( \[] ). The user can provide a single element (which will be automatically promoted to a list internally) or a list.</p>
            </div>

            <div className="dt">solver\_type (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>The type of solver to use for the graph. Allowed values are:</p>

              <ul className="simple">
                <li>
                  <p><strong>SHORTEST\_PATH</strong> – Solves for the optimal (shortest) path based on weights and restrictions from one source to destinations nodes. Also known as the Dijkstra solver.</p>
                </li>

                <li>
                  <p><strong>PAGE\_RANK</strong> – 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.</p>
                </li>

                <li>
                  <p><strong>PROBABILITY\_RANK</strong> – Solves for the transitional probability (Hidden Markov) for each node based on the weights (probability assigned over given edges).</p>
                </li>

                <li>
                  <p><strong>CENTRALITY</strong> – 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.</p>
                </li>

                <li>
                  <p><strong>MULTIPLE\_ROUTING</strong> – 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.</p>
                </li>

                <li>
                  <p><strong>INVERSE\_SHORTEST\_PATH</strong> – 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.</p>
                </li>

                <li>
                  <p><strong>BACKHAUL\_ROUTING</strong> – Solves for optimal routes that connect remote asset nodes to the fixed (backbone) asset nodes.</p>
                </li>

                <li>
                  <p><strong>ALLPATHS</strong> – 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.</p>
                </li>

                <li>
                  <p><strong>STATS\_ALL</strong> – Solves for graph statistics such as graph diameter, longest pairs, vertex valences, topology numbers, average and max cluster sizes, etc.</p>
                </li>

                <li>
                  <p><strong>CLOSENESS</strong> – Solves for the centrality closeness score per node as the sum of the inverse shortest path costs to all nodes in the graph.</p>
                </li>
              </ul>

              <p>The default value is ‘SHORTEST\_PATH’.</p>
            </div>

            <div className="dt">source\_nodes (<span className="em">list of str</span>) –</div>

            <div className="dd">
              <p>It can be one of the nodal identifiers - e.g: ‘NODE\_WKTPOINT’ for source nodes. For <span className="em">BACKHAUL\_ROUTING</span>, this list depicts the fixed assets. The default value is an empty list ( \[] ). The user can provide a single element (which will be automatically promoted to a list internally) or a list.</p>
            </div>

            <div className="dt">destination\_nodes (<span className="em">list of str</span>) –</div>

            <div className="dd">
              <p>It can be one of the nodal identifiers - e.g: ‘NODE\_WKTPOINT’ for destination (target) nodes. For <span className="em">BACKHAUL\_ROUTING</span>, this list depicts the remote assets. The default value is an empty list ( \[] ). The user can provide a single element (which will be automatically promoted to a list internally) or a list.</p>
            </div>

            <div className="dt">solution\_table (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Name of the table to store the solution, in \[schema\_name.]table\_name format, using standard <a className="reference external" href="/content/concepts/tables/#table-name-resolution">name resolution rules</a>. The default value is ‘graph\_solutions’.</p>
            </div>

            <div className="dt">options (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Additional parameters. Allowed keys are:</p>

              <ul>
                <li>
                  <p><strong>max\_solution\_radius</strong> – For <span className="em">ALLPATHS</span>, <span className="em">SHORTEST\_PATH</span> and <span className="em">INVERSE\_SHORTEST\_PATH</span> solvers only. Sets the maximum solution cost radius, which ignores the input parameter <span className="em">destination\_nodes</span> 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’.</p>
                </li>

                <li>
                  <p><strong>min\_solution\_radius</strong> – For <span className="em">ALLPATHS</span>, <span className="em">SHORTEST\_PATH</span> and <span className="em">INVERSE\_SHORTEST\_PATH</span> solvers only. Applicable only when <span className="em">max\_solution\_radius</span> is set. Sets the minimum solution cost radius, which ignores the input parameter <span className="em">destination\_nodes</span> 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’.</p>
                </li>

                <li>
                  <p><strong>max\_solution\_targets</strong> – For <span className="em">ALLPATHS</span>, <span className="em">SHORTEST\_PATH</span> and <span className="em">INVERSE\_SHORTEST\_PATH</span> solvers only. Sets the maximum number of solution targets, which ignores the input parameter <span className="em">destination\_nodes</span> 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’.</p>
                </li>

                <li>
                  <p><strong>uniform\_weights</strong> – When specified, assigns the given value to all the edges in the graph. Note that weights provided in input parameter <span className="em">weights\_on\_edges</span> will override this value.</p>
                </li>

                <li>
                  <p><strong>left\_turn\_penalty</strong> – This will add an additional weight over the edges labeled as ‘left turn’ if the ‘add\_turn’ option parameter of the <a className="reference internal" href="#gpudb.GPUdb.create_graph" title="gpudb.GPUdb.create_graph"><code className="xref py py-meth docutils literal notranslate"><span className="pre">GPUdb.create\_graph()</span></code></a> was invoked at graph creation. The default value is ‘0.0’.</p>
                </li>

                <li>
                  <p><strong>right\_turn\_penalty</strong> – This will add an additional weight over the edges labeled as’ right turn’ if the ‘add\_turn’ option parameter of the <a className="reference internal" href="#gpudb.GPUdb.create_graph" title="gpudb.GPUdb.create_graph"><code className="xref py py-meth docutils literal notranslate"><span className="pre">GPUdb.create\_graph()</span></code></a> was invoked at graph creation. The default value is ‘0.0’.</p>
                </li>

                <li>
                  <p><strong>intersection\_penalty</strong> – This will add an additional weight over the edges labeled as ‘intersection’ if the ‘add\_turn’ option parameter of the <a className="reference internal" href="#gpudb.GPUdb.create_graph" title="gpudb.GPUdb.create_graph"><code className="xref py py-meth docutils literal notranslate"><span className="pre">GPUdb.create\_graph()</span></code></a> was invoked at graph creation. The default value is ‘0.0’.</p>
                </li>

                <li>
                  <p><strong>sharp\_turn\_penalty</strong> – This will add an additional weight over the edges labeled as ‘sharp turn’ or ‘u-turn’ if the ‘add\_turn’ option parameter of the <a className="reference internal" href="#gpudb.GPUdb.create_graph" title="gpudb.GPUdb.create_graph"><code className="xref py py-meth docutils literal notranslate"><span className="pre">GPUdb.create\_graph()</span></code></a> was invoked at graph creation. The default value is ‘0.0’.</p>
                </li>

                <li>
                  <p><strong>num\_best\_paths</strong> – For <span className="em">MULTIPLE\_ROUTING</span> 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’.</p>
                </li>

                <li>
                  <p><strong>max\_num\_combinations</strong> – For <span className="em">MULTIPLE\_ROUTING</span> 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’.</p>
                </li>

                <li>
                  <p><strong>output\_edge\_path</strong> – 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. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>output\_wkt\_path</strong> – 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. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘true’.</p>
                </li>

                <li>
                  <p><strong>server\_id</strong> – 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.</p>
                </li>

                <li>
                  <p><strong>convergence\_limit</strong> – For <span className="em">PAGE\_RANK</span> 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’.</p>
                </li>

                <li>
                  <p><strong>max\_iterations</strong> – For <span className="em">PAGE\_RANK</span> solvers only; Maximum number of page rank iterations for satisfying convergence. Default value is 100. The default value is ‘100’.</p>
                </li>

                <li>
                  <p><strong>max\_runs</strong> – For all <span className="em">CENTRALITY</span> 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’.</p>
                </li>

                <li>
                  <p><strong>output\_clusters</strong> – For <span className="em">STATS\_ALL</span> solvers only; the cluster index for each node will be inserted as an additional column in the output. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>true</strong> – An additional column ‘CLUSTER’ will be added for each node.</p>
                    </li>

                    <li>
                      <p><strong>false</strong> – No extra cluster info per node will be available in the output.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>solve\_heuristic</strong> – Specify heuristic search criterion only for the geo graphs and shortest path solves towards a single target. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>astar</strong> – Employs A-STAR heuristics to speed up the shortest path traversal.</p>
                    </li>

                    <li>
                      <p><strong>none</strong> – No heuristics are applied.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘none’.</p>
                </li>

                <li>
                  <p><strong>astar\_radius</strong> – 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’.</p>
                </li>
              </ul>

              <p>The default value is an empty dict ( {"{"}{"}"} ).</p>
            </div>
          </div>
        </div>
      </div>

      <p><strong>Returns</strong></p>

      <div className="blockquote">
        <div>
          <p>A dict with the following entries–</p>

          <div className="dl simple">
            <div className="dt">result (<span className="em">bool</span>) –</div>

            <div className="dd">
              <p>Indicates a successful solution on all servers.</p>
            </div>

            <div className="dt">result\_per\_destination\_node (<span className="em">list of floats</span>) –</div>

            <div className="dd">
              <p>Cost or page rank (based on solver type) for each destination node requested. Only populated if ‘export\_solve\_results’ option is set to true.</p>
            </div>

            <div className="dt">info (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Additional information.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
