The swarm behaviour can be controlled by different localizations of attractants (food pieces) and repellents (dangerous places), which, respectively, attract and repel the swarm propagation. If we assume that at each time step, the swarm can find out not more than p − 1 attractants (p = 2, 3, … ), then the swarm behaviour can be coded by p-adic integers, ie, by the numbers of the ring Z p . Each swarm propagation has the following 2 stages: (1) the discover of localizations of neighbour attractants and repellents and (2) the logistical optimization of the road system connecting all the reachable attractants and avoiding all the neighbour repellents. In the meanwhile, at the discovering stage, the swarm builds some direct roads and, at the logistical stage, the transporting network of the swarm gets loops (circles) and it permanently changes. So, at the first stage, the behaviour can be expressed by some linear p-adic valued strings. At the second stage, it is expressed by non-linear modifications of p-adic valued strings. The second stage cannot be described by conventional algebraic tools; therefore, I have introduced the so-called non-linear group theory for describing both stages in the swarm propagation.