Find a maximum cardinality subset of vertices that can be visited by a walk with sum of weights not less than a threshold in a complete directed graph

166 Views Asked by At

Let $G=(V,E,w)$ be a complete directed graph with possibly negative weights. Let $s$, $t$ be two nodes in $V$. Let $T$ be a threshold. Find a maximum cardinality subset $S$ of $V$ such that $S$ is the distinct nodes visited by a walk $W$ from $s$ to $t$ where the sum of all weights in $W$ is not less than $T$.

For example, consider the following distance matrix of $G$, with $s=0$, $t=3$: $$ \begin{bmatrix} 0 & -2 & -2 & 1 \\ -1 & 0 & -2 & 1 \\ -1 & -1 & 0 & 1 \\ -1 & -2 & -2 & 0 \\ \end{bmatrix} $$ With threshold $T=-1$, the walk $W=(0,3,1,3,2,3)$, which has a sum of weights $1-2+1-2+1=-1$, visits all nodes in the graph, and hence produces the maximum cardinality subset $S=\{0,1,2,3\}$.

This is (seemingly) different from shortest paths or longest paths, because the problem requires maximizing the number of distinct nodes visited, but not quite the length of the path/walk. However, it also puts some constraints on the length of the walk, which has to be not less than a threshold.

Is there any way I can reduce this to a known problem or is there any algorithm related to maximum number of distinct nodes visited? At the moment, I do not need to worry about performance because I'm working with $|V|<10$.

1

There are 1 best solutions below

4
On BEST ANSWER

You can solve the problem via integer linear programming as follows. For $(i,j)\in E$, let integer decision variable $x_{ij}\ge 0$ denote the number of times arc $(i,j)$ is traversed. For $i\in V$, let binary decision variable $y_i\in\{0,1\}$ indicate whether node $i$ is visited. The problem is to maximize $\sum_i y_i$ subject to linear constraints \begin{align} \sum_j x_{ij} - \sum_j x_{ji} &= \begin{cases} 1 & \text{if $i=s$}\\ -1 & \text{if $i=t$}\\ 0 & \text{otherwise}\\ \end{cases} &&\text{for $i \in V$} \tag1\label1 \\ \sum_{(i,j)} w_{ij} x_{ij} &\ge T \tag2\label2 \\ y_i &\le \sum_j x_{ij} &&\text{for $i \in V$} \tag3\label3 \\ y_j &\le \sum_i x_{ij} &&\text{for $j \in V$} \tag4\label4 \end{align} Constraint \eqref{1} yields a walk from $s$ to $t$. Constraint \eqref{2} forces the sum of weights to be at least the threshold. Constraint \eqref{3} enforces the logical implication $y_i \implies \lor_j x_{ij}$. Constraint \eqref{4} enforces the logical implication $y_j \implies \lor_i x_{ij}$.

Now call an integer linear programming solver, which will be very fast for your use case with $|V|<10$.


Actually, the formulation above can yield disconnected solutions. You can enforce connectivity by dynamically generating a form of generalized subtour elimination constraints (GSECs). There are an exponential number of these, but most of them will naturally be satisfied, so the best approach is usually to generate them only if they are violated. Explicitly, for each node subset $T$ that does not contain $s$ and for each node $k\in T$, the constraint is $$y_k \le \sum_{i\notin T}\sum_{j\in T} x_{ij}$$ The idea is that if node $k$ is visited then at least one arc into $T$ must be traversed. Given an integer solution that satisfies constraints \eqref{1} through \eqref{4}, the violated GSECs can easily be obtained by computing the connected components of the support graph, that is, the subgraph consisting of the edges for which $x_{ij}>0$.