Let $G(V,E)$ be a directed graph, where $V=\{a_1,\ldots,a_n\}$ is a set of vertices and $E$ is a set of ordered pairs of $V$, with $|V|=n$.
Now, let be $G(W,F)$ be a graph where $W$ is a set of vertices, such that $W=\{a_1,\ldots,a_{2n}\}$ with $|W|=2n$, and $F$ is a set of ordered pairs of $W$ defined as follows: $$\forall i, j \in \{1, \ldots, n\} : (a_i,a_{j+n}) \in F \text{ if } (a_i,a_{j}) \in E \\ \forall i \in \{1, \ldots, n\} : (a_{i+n},a_i) \in F$$
Now we define the capacities: $$c(a,b)=1 \text{ if } (a,b) \in F$$
And we define a cost: $$\forall i \in \{1, \ldots, n\} : p(a_{i+n},a_i)=-1 \text{ if } (a_{i+n},a_i) \in F \\ p=0 \text{ else}$$
The source as $a_{n+1}$ and the sink as $a_{n+1}$.
Does the graph $G(W,F,c,p)$ have a minimum cost flow of $-n$ if and only if the graph $G(V,E)$ has a Hamiltonian cycle?
(Comment to an answer in the comments section)
Michael, for your matrix with capacities G(V,E) the matrix G(W,F) is:
cap = [[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]]
cost = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0]]
Here is an example where the program you gave fails. This gives details from my comment above. You can plug in the following data into the Python program you linked here: https://www.geeksforgeeks.org/minimum-cost-maximum-flow-from-a-graph-using-bellman-ford-algorithm/
This is a graph with 7 nodes labeled {0, 1, ..., 6}. The graph is symmetric, so for every link (i,j) there is a link (j,i). All link capacities are 1 and all costs are -1. Node 6 is only connected to node 5 and so the max flow to or from node 6 is 1 unit.
I used source s=6 and destination t=2. The program gives an output of 1, -5. This means a flow of 1 unit and a cost of -5 (5 hops). This is incorrect because there is a 6-hop Hamiltonian path that the program does not find:
$$ 6\rightarrow 5\rightarrow 4 \rightarrow 3 \rightarrow 1 \rightarrow 0 \rightarrow 2 $$
On the other hand, if we reverse the path and use s=2, t=6, the program gives a correct output of 1, -6.
Unfortunately the program only outputs the cost of the path, not the actual path, so I don't know what paths it is proposing in either case.