21

I was given directed graph with n nodes and edges with weigths of vectors (every vector has length m) of numbers 1, 0, -1. I would like to find any path (or say that such path doesn't exist) from one node to other (we can visit nodes many times) such that sum of its weights equals to vector of only zeros. I was thinking of brute-force backtracking algorithm but it is not guaranteed that it would end. Can we somehow limit length of such path in terms of n and m? Example of graph for n=8, m=2

enter image description here

Example of path

enter image description here

biqarboy
  • 852
  • 6
  • 15
Kacper Kowalski
  • 321
  • 1
  • 4
  • 1
    To simplify, you can collapse the vertices of any edges with weight 0 (since you can reach either one from the other without changing the accumulated weight). So it's really just weights -1 and 1. – Sneftel Apr 29 '19 at 20:46
  • Can you make it any more complicated? :) – גלעד ברקן Apr 29 '19 at 22:39
  • 5
    Interesting problem. It's definitely NP-hard, since you could solve (directed) Hamiltonian Path by setting m = n and making every in-edge to vertex v_i have +1 in the i-th position and 0 everywhere else, then adding a final vertex with an in-edge from every other vertex and -1 at every position. I'm not yet certain it's in NP though (it might be that there are instances requiring exponentially long paths). – j_random_hacker Apr 30 '19 at 09:39
  • 4
    I don't think it's in NP, even for m=1: For any coprime pair of positive integers p, q, the instance consisting of two cycles that intersect at a single vertex, one of size p and having each edge +1, the other of size q and having each edge -1, requires a walk of length at least 2pq (q laps of the p-cycle and p laps of the q-cycle, in any order). But perhaps there's a different way to encode a valid solution that's always polynomial in the input size. Or perhaps the problem isn't even decidable, and can simulate/encode a Turing machine :) – j_random_hacker Apr 30 '19 at 10:15
  • 2
    Sorry, my last comment is clearly false: a 2-edge walk spanning the common vertex suffices. But if we instead set m=4 and have 4 cycles intersecting at a single vertex, one of length p with all vectors [1 -1 0 0], another also of length p with all vectors [0 1 -1 0], another of length q with all vectors [0 0 1 -1] and another also of length q with all vectors [-1 0 0 1], then every walk must visit all 4 cycles, so the shortest walk has length 4pq. – j_random_hacker May 02 '19 at 09:38
  • 1
    Do you have any restrictions on the input graph (e.g. num nodes, num arcs, max in/outdegree, sum of all vectors) – Dave Nov 21 '19 at 23:40
  • 1
    A very naive solution I came up with would involve 3 steps. 1. Identify all cycles and assign to each node in each cycle the possible vectors formed by summing along all cycles to which this node belongs. 2. Find all unique paths without duplicated nodes. 3. For each such path form a linear equation that's a sum of the weights along the path plus an inner product of all the vectors computed in (1) for nodes in the path and a vector of unknowns; and try to solve each one. At least it's bounded. – Sopel Feb 07 '21 at 16:57

1 Answers1

1

We can upper bound the length of the path, by noting that if such a path exists it must consists of a mix of a simple path and some cycles. Each of those paths can have at most lenght n. For each cycle we can effectively apply a vector that corrispond to the change that happens by going through one of such cycles. We can only construct m cycles that are linearly indepednt of each other (note that we might need to go in both directions), which is sufficient to cover any vector that the simple path itself costs, so we can resolve any residual by going through each cycle the right amount of times (this relies on the cost of such an edge). The amount of times we have to go through the different cycles is upper bounded by something equivalent to the lowest common multiplier for the effective lengths of each of the vectors effects of the different cycles, which has the (rough) assymtotic bound O(n^2m). If this upper bound holds (you can construct a case reasonably close to it by sperating n into m regions of size roughly n/m, and then have them prime number lengths counting down from n/m, and then chain their dependencies together, which would give ´O((n/m)^m)`), then the solution as exponential size, which means any algorithm that uses (and reports) uncompressed path lengths would not fit in PSPACE (which is a superset of P and NP).

Ninetails
  • 254
  • 1
  • 5