"If the dog sees gaps between the sheep, or the gaps are getting bigger, the dog needs to bring them together."
Daniel Stroembom of Uppsala University in Sweden explained: "At every step in the model, the dog decides if the herd is cohesive enough or not.
"If not cohesive, it will make it cohesive, but if it's already cohesive, the dog will push the herd towards the target."
Single sheep dogs can successfully herd flocks of 80 or more sheep in their everyday work and in competitive herding trials.
But the model suggests that, in theory, a dog could herd more than 100 by following the two simple rules.
In contrast, other attempts at resolving the Sheepdog Mystery are more pessimistic. They say that 50 sheep would be the limit -- beyond this, another dog (or a human) would be needed to close up the gaps.
The study, published in the Journal of the Royal Society Interface, comes with an intimidatingly geeky headline: "Solving the Shepherding Problem: Heuristics for Herding Autonomous, Interacting Agents."
But the work goes beyond scientific curiosity, said the authors.
"There are numerous applications for this knowledge, such as crowd control, cleaning up the environment, herding of livestock, keeping animals away from sensitive areas and collective or guiding groups of exploring robots," said King.