---
title: "Resource Allocation"
component: "graph-ml"
version: "3.10"
module: "link-prediction"
html_url: "/graph-ml/3.10/link-prediction/resource-allocation"
canonical_url: "https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/resource-allocation"
markdown_url: "https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/resource-allocation.md"
---

[View as HTML](https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/resource-allocation)

# Resource Allocation

Supported Graph Characteristics

| Unweighted edges |
| --- |
| Homogeneous vertex types |
| Heterogeneous vertex types |

Algorithm link: [Resource Allocation](https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Topological%20Link%20Prediction/resource%5Fallocation)

Resource Allocation is used to compute the closeness of nodes based on their shared neighbors. It is computed by the following formula:

\\\[{RA(x,y)=\\sum \_{u\\in N(x)\\cap N(y)}{\\frac {1} {|N(u)|}}}\\\]

Where \\({N(u)}\\) is the set of nodes adjacent to _u_.

## Notes

This algorithm ignores edge weights.

## Specifications

```gsql
CREATE QUERY tg_resource_allocation(VERTEX v_source VERTEX v_target, SET<STRING> e_type)
```

### Parameters

| Name | Description | Data type |
| --- | --- | --- |
| `VERTEX v_source` | The first vertex to compare. Provide the vertex ID and type as a tuple: `("id","type")` | N/A |
| `VERTEX v_target` | The second vertex to compare with the first. Provide the vertex ID and type as a tuple: `("id","type")` | N/A |
| `SET<STRING> e_type_set` | Edge types to traverse. | (A blank set of strings) |

### Output

Returns a closeness value for two input vertices.

### Time complexity

The algorithm has a time complexity of \\(O(D1 + D2)\\), where \\(D1\\) and \\(D2\\) are the degrees of the two vertices.

## Example

Suppose we have the following graph:

![preferential attachment ex](https://www.tigergraph.com/docs/graph-ml/3.10/link-prediction/_images/preferential-attachment-ex.png) 

Dan and Jenny have one shared neighbor `Tom`, who has two neighbors. Running the algorithm between Dan and Jenny with `friendship` edges returns a result of `0.5`.

* Query
* Result

```gsql
RUN QUERY resource_allocation (("Jenny", "person"), ("Dan", "person"), ["friendship"])
```

```json
{
  "error": false,
  "message": "",
  "version": {
    "schema": 1,
    "edition": "enterprise",
    "api": "v2"
  },
  "results": [{
    "@@closeness": 0.5
  }]
}
```
