How can I efficiently check whether one unit arrangement can become another in a single turn?

0
1
Asked By VelvetMango42 On

I have a map represented as a graph of connected regions. For each region, I know how many units it contains in the starting state and in the proposed ending state. How can I determine whether the ending arrangement is reachable in exactly one turn, with each unit allowed to move at most 1 space—or at most 2 spaces—along the map? Units may stay put, the total number of units must remain constant, and regions have no capacity limit. I'm looking for an efficient method, whether that means a practical algorithm, compact implementation, or even something humans could check without too much effort.

3 Answers

Answered By CopperSparrow18 On

Simply comparing each region with its neighbors isn’t enough, because several destinations may all depend on the same nearby supply. For example, two regions might each appear able to receive units, while the only available units can actually satisfy just one of them. The flow formulation catches that shared-supply conflict. If the map is small, you can instead use backtracking or integer programming, but max flow is the clean general solution.

Answered By OrbitingLlama3 On

There’s also a useful necessary-and-sufficient way to think about it: for every set of destination regions, the starting units that can reach that set must be at least as numerous as the units required there. Checking all such sets directly is expensive, but a max-flow algorithm performs those checks efficiently. Build the graph with source → starting regions, allowed movement edges, and destination regions → sink; capacities on the outer edges are the starting and ending unit counts. Run max flow and compare it with the total number of units.

Answered By QuietPine7 On

Treat it as a transportation or max-flow problem. Make one node for every region in the starting state and another node for every region in the target state. Connect a starting-region node to a target-region node when a unit can travel between them within the allowed number of spaces: distance at most 1 for a one-space move, or at most 2 for a two-space move. Give each starting node supply equal to its unit count and each target node demand equal to its final count. A feasible flow that satisfies every demand means the move is legal; if no such flow exists, some units would have to travel too far or appear from nowhere. This automatically handles units staying in place and avoids trying to match individual units by hand.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.