The sheepdog is truly a superhero. Somehow, it manages to convince a group of uncooperative sheep to move in a particular direction. It sounds simple, but it's not as easy as it sounds. What the sheepdog appears to do intuitively has baffled mathematicians.

Most attempts to understand optimal sheepdog behavior start from a theoretical perspective in which an algorithm is pre-defined. Computer models are designed in which each individual within a herd moves according to simple rules of attraction (to each other) and repulsion (from a shepherd), derived from studies of collective animal behavior, while the shepherd gets a different set of instructions.

In one such algorithm, the shepherd sweeps back and forth behind the herd, slowly nudging it towards the desired goal. That seems like a reasonable strategy, since that's what sheepdogs look like they're doing. And that sort of strategy works, but only for herds containing fewer than 40 individuals. Any larger, and it's too easy for the herd to break into sub-groups, leading to failure.

But a single real life sheepdog can effortlessly move more than 80 individuals, both in everyday working situations and in herding competitions. "So, what are the sheepdogs doing that the [computerized] agent shepherds (or the flocking agents) are not?" That's what a group of Swedish and British researchers led by Andrew J. King wondered.

#### Nature Will Find A Way

King's approach was unique in that he began with basic animal behavior observations, rather than with theoretical assumptions. His research group outfitted a herd of 46 three-year-old female merino sheep with small backpacks containing GPS transmitters. The sheepdog, a trained female Australian Kelpie – a working farmdog – was also given a GPS tracker. For each trial, the dog was simply verbally instructed to move the sheep to the gate of a 5-hectare (12.3 acre) field.

Then, using data from the GPS trackers, the researchers derived a mathematical model describing the rules governing the movement of both the computerized sheep and a computerized shepherd.

What they found was that sheepdogs use just two simple rules: when the sheep are dispersed, she moves them together. They called that collecting. When the sheep are already aggregated, she moves them forward. That's called driving. If one sheep strays too far away from the group's center, then the dog shifts from driving to collecting. Once that sheep is close enough to the rest of the herd, the dog shifts from collecting to driving.

"At every time 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," said the study's lead author, Daniel Strömbom in a statement.

King explains that they started by thinking about what the dog could actually see as they developed their model. "It basically sees white, fluffy things in front of it. If the dogs sees gaps between the sheep, or the gaps are getting bigger, the dog needs to bring them together," he said. Dogs, after all, don't have a bird's-eye view of the flock.

By appearance alone, the dog's behavior is very similar to the sweeping back and forth of earlier efforts to understand the shepherding algorithm. But by starting from actual animal behavior rather than a theoretical model, King and his colleagues were able to more accurately define the rules that guide the dog's behavior, resulting in computerized shepherds that, like sheepdogs, can herd groups of more than 100 individuals. In other words, their algorithms produce shepherds that act more like actual sheepdogs.

Compare the behavior of the digital dog and sheep on the right in the video below, with the behavior of the actual dog and sheep on the left, to see how the researchers' algorithm accurately reflects real animal behavior.

#### I, For One, Welcome Our Robot Overlords

Cracking the sheepdog's code isn't just an exercise in understanding animal behavior. The researchers think that having a more effective, efficient mathematical model for shepherds has important implications for robotics. Some more obvious applications of the algorithm are for robot-assisted herding of livestock, or for keeping animals away from sensitive areas, like airports. But King stresses, "we never said we wanted to replace sheepdogs with robots!" This would be useful instead where a living dog would be impractical or undesirable.