# Network flow feasibility check

`network-flow-feasibility-check` · version 1.0.0 · Numbers & math · free, no key needed

Check a claimed s-t flow for capacity bounds and conservation with exact integers; returns the first bad edge or node.

**Use when you need to: check if a network flow is feasible · verify flow conservation at every node · validate edge flows against capacities.**

## Decide before calling

Read the [versioned contract](/v1/tools/network-flow-feasibility-check/versions/1.0.0) and the supported scope below. Reuse `network-flow-feasibility-check@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `network-flow-feasibility-check@1.0.0` for check if a network flow is feasible. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- check if a network flow is feasible
- verify flow conservation at every node
- validate edge flows against capacities
- check claimed value of an s-t flow
- find the first node where flow is not conserved
- audit a flow assignment for a capacitated graph

## Not supported

- computing a maximum flow (use maximum-flow-certificate-check to verify one)
- flows with lower bounds, costs or multiple commodities
- fractional or floating-point flow values
- undirected edges

## Behavior

- Reference: CLRS 4th ed. (2022) section 24.1, flow network, capacity constraint 0 <= f(u,v) <= c(u,v), flow conservation at every vertex other than s and t, value |f| = flow out of s minus flow into s; reference_version is returned with every result.
- Network: nodes are 2-2000 unique strings (1-64 code points, exact comparison, no Unicode normalization); edges are 0-10000 directed {from, to, capacity} entries identified by their array index; parallel, antiparallel and self-loop edges are allowed; source and sink are distinct declared nodes.
- Integers: capacities are non-negative, flows may be signed; each is a JSON safe integer or a canonical decimal string of at most 30 digits; arithmetic is exact (BigInt).
- claim.flows lists one flow per edge in edge order; claim.value (optional) is the claimed flow value.
- Check order: flows length (reason flow_length_mismatch), then edges by index (negative_flow, then capacity_exceeded), then nodes in declared order except source and sink (conservation_violated, with inflow and outflow), then the value (value_mismatch).
- first_discrepancy.kind is claim, edge, node or value; flow_value is the exact net flow out of the source whenever the flow is feasible, else null.

## Input

- `nodes` (array of string, required): min items 2; max items 2000; each min length 1; each max length 64
- `edges` (array of object, required): max items 10000
- `source` (string, required): min length 1; max length 64
- `sink` (string, required): min length 1; max length 64
- `claim` (object, required)

## Output

- `valid` (boolean, required)
- `reason` (one of null, "flow_length_mismatch", "negative_flow", "capacity_exceeded", "conservation_violated", "value_mismatch", required)
- `first_discrepancy` (object or null, required)
- `flow_value` (string or null, required)
- `reference_version` (string, required)

## Limits

- max nodes: 2000
- max edges: 10000
- max id chars: 64
- max integer digits: 30

## Example

Request input:

```json
{
  "nodes": [
    "s",
    "v1",
    "v2",
    "v3",
    "v4",
    "t"
  ],
  "edges": [
    {
      "from": "s",
      "to": "v1",
      "capacity": 16
    },
    {
      "from": "s",
      "to": "v2",
      "capacity": 13
    },
    {
      "from": "v2",
      "to": "v1",
      "capacity": 4
    },
    {
      "from": "v1",
      "to": "v3",
      "capacity": 12
    },
    {
      "from": "v3",
      "to": "v2",
      "capacity": 9
    },
    {
      "from": "v2",
      "to": "v4",
      "capacity": 14
    },
    {
      "from": "v4",
      "to": "v3",
      "capacity": 7
    },
    {
      "from": "v3",
      "to": "t",
      "capacity": 20
    },
    {
      "from": "v4",
      "to": "t",
      "capacity": 4
    }
  ],
  "source": "s",
  "sink": "t",
  "claim": {
    "flows": [
      11,
      8,
      1,
      12,
      4,
      11,
      7,
      15,
      4
    ],
    "value": 19
  }
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reason": null,
    "first_discrepancy": null,
    "flow_value": "19",
    "reference_version": "CLRS 4th ed. (2022) ch. 24 Maximum Flow: flow networks, cuts, residual networks, max-flow min-cut theorem; r55-flow-certificate-verifiers@1.0.0"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "network-flow-feasibility-check",
  "version": "1.0.0",
  "input": {
    "nodes": [
      "s",
      "v1",
      "v2",
      "v3",
      "v4",
      "t"
    ],
    "edges": [
      {
        "from": "s",
        "to": "v1",
        "capacity": 16
      },
      {
        "from": "s",
        "to": "v2",
        "capacity": 13
      },
      {
        "from": "v2",
        "to": "v1",
        "capacity": 4
      },
      {
        "from": "v1",
        "to": "v3",
        "capacity": 12
      },
      {
        "from": "v3",
        "to": "v2",
        "capacity": 9
      },
      {
        "from": "v2",
        "to": "v4",
        "capacity": 14
      },
      {
        "from": "v4",
        "to": "v3",
        "capacity": 7
      },
      {
        "from": "v3",
        "to": "t",
        "capacity": 20
      },
      {
        "from": "v4",
        "to": "t",
        "capacity": 4
      }
    ],
    "source": "s",
    "sink": "t",
    "claim": {
      "flows": [
        11,
        8,
        1,
        12,
        4,
        11,
        7,
        15,
        4
      ],
      "value": 19
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/network-flow-feasibility-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"nodes":["s","v1","v2","v3","v4","t"],"edges":[{"from":"s","to":"v1","capacity":16},{"from":"s","to":"v2","capacity":13},{"from":"v2","to":"v1","capacity":4},{"from":"v1","to":"v3","capacity":12},{"from":"v3","to":"v2","capacity":9},{"from":"v2","to":"v4","capacity":14},{"from":"v4","to":"v3","capacity":7},{"from":"v3","to":"t","capacity":20},{"from":"v4","to":"t","capacity":4}],"source":"s","sink":"t","claim":{"flows":[11,8,1,12,4,11,7,15,4],"value":19}}'
```

The machine-readable contract is at [/v1/tools/network-flow-feasibility-check/versions/1.0.0](/v1/tools/network-flow-feasibility-check/versions/1.0.0).

### CLI

```sh
node cli.mjs run network-flow-feasibility-check 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Network cut capacity check](/tools/network-cut-capacity-check): Check a claimed s-t cut: source-side membership, the edges crossing it and its capacity, with exact integers.
- [Flow feasibility check](/tools/flow-feasibility-check): Check exact integer edge capacities and flow conservation, returning the first discrepancy.
- [Lp primal feasibility check](/tools/lp-primal-feasibility-check): Check that a claimed LP point satisfies x >= 0 and Ax <= b exactly; report the first violated bound or row.
- [Maximum flow certificate check](/tools/maximum-flow-certificate-check): Check a claimed max flow with a min-cut certificate or residual search; reports the first failure or augmenting path.
- [Graph coloring check](/tools/graph-coloring-check): Check that a node colouring of an undirected graph is proper (and within k colours); returns the first conflict.
- [Dimension expression check](/tools/dimension-expression-check): Check a formula over dimensioned symbols is consistent and has the claimed dimension; returns the first bad node.
