# Maximum flow certificate check

`maximum-flow-certificate-check` · version 1.0.0 · Numbers & math · free, no key needed

Check a claimed max flow with a min-cut certificate or residual search; reports the first failure or augmenting path.

**Use when you need to: verify a maximum flow answer · check max flow with a min cut certificate · is this flow maximum or is there an augmenting path.**

## Decide before calling

Read the [versioned contract](/v1/tools/maximum-flow-certificate-check/versions/1.0.0) and the supported scope below. Reuse `maximum-flow-certificate-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 `maximum-flow-certificate-check@1.0.0` for verify a maximum flow answer. 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

- verify a maximum flow answer
- check max flow with a min cut certificate
- is this flow maximum or is there an augmenting path
- validate claimed max flow value of a network
- certify max-flow min-cut duality for a solution
- find an augmenting path that disproves a max flow claim

## Not supported

- computing a maximum flow from scratch without a claimed flow
- minimum-cost or multi-commodity flows
- real-valued capacities (exact integers only)
- listing every minimum cut

## Behavior

- Reference: CLRS 4th ed. (2022) sections 24.1-24.2: a flow f is maximum iff its residual network has no augmenting path iff |f| = c(S, T) for some cut (max-flow min-cut theorem); reference_version is returned with every result.
- Network and integer rules as in network-flow-feasibility-check. claim.flows (one per edge, edge order) and claim.value are required; claim.source_side (optional) is a cut certificate.
- Check order: feasibility exactly as network-flow-feasibility-check (flow_length_mismatch, negative_flow, capacity_exceeded, conservation_violated), then claim.value against the flow value (value_mismatch).
- With claim.source_side (method cut_certificate): source-side checks as in network-cut-capacity-check (unknown_node, duplicate_node, source_not_in_source_side, sink_in_source_side), then edges by index: an S-to-T edge below capacity is cut_edge_not_saturated, a T-to-S edge with positive flow is backward_edge_has_flow. Passing all checks proves |f| = c(S, T), so f is maximum and (S, T) is a minimum cut.
- Without claim.source_side (method residual_search): breadth-first search from the source in the residual network, dequeuing nodes first-in first-out and scanning each node's incident edges once in edge index order (forward residual when the edge leaves the node with flow < capacity, backward residual when it enters with flow > 0; self-loops skipped). Reaching the sink gives reason augmenting_path with path (edge_index, direction), path_nodes and residual_capacity (the bottleneck).
- flow_value is the exact flow value 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", "unknown_node", "duplicate_node", "source_not_in_source_side", "sink_in_source_side", "cut_edge_not_saturated", "backward_edge_has_flow", "augmenting_path", required)
- `first_discrepancy` (object or null, required)
- `flow_value` (string or null, required)
- `method` (one of "cut_certificate", "residual_search", 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,
      12,
      1,
      12,
      0,
      11,
      7,
      19,
      4
    ],
    "value": 23,
    "source_side": [
      "s",
      "v1",
      "v2",
      "v4"
    ]
  }
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reason": null,
    "first_discrepancy": null,
    "flow_value": "23",
    "method": "cut_certificate",
    "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": "maximum-flow-certificate-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,
        12,
        1,
        12,
        0,
        11,
        7,
        19,
        4
      ],
      "value": 23,
      "source_side": [
        "s",
        "v1",
        "v2",
        "v4"
      ]
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/maximum-flow-certificate-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,12,1,12,0,11,7,19,4],"value":23,"source_side":["s","v1","v2","v4"]}}'
```

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

### CLI

```sh
node cli.mjs run maximum-flow-certificate-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.
- [Lp optimality certificate check](/tools/lp-optimality-certificate-check): Check an LP optimum claim from a primal x and dual y: feasibility, complementary slackness and zero duality gap.
- [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.
- [Network flow feasibility check](/tools/network-flow-feasibility-check): Check a claimed s-t flow for capacity bounds and conservation with exact integers; returns the first bad edge or node.
- [Linear inconsistency certificate check](/tools/linear-inconsistency-certificate-check): Check a witness y that A x = b has no solution (yA = 0, yb != 0) or no x >= 0 solution (Farkas: yA >= 0, yb < 0).
- [Lp dual feasibility check](/tools/lp-dual-feasibility-check): Check that LP dual multipliers satisfy y >= 0 and yA >= c exactly; return the proven upper bound y.b.
