1: Procedure OPTIMIZENUMBEROFAGENTS( : SET OF MOBILE AGENTS)
2:   0
3:   null
4:  for all do               Find max. loaded agent
5:    getTaskLoad( )
6:   if then
7:    
8:    
9:   end if
10:  end for
11:  if not null then
12:    getSensorIDs( )
13:    findSuitableAgent( )
14:   if not null then               Local task passing
15:    assignSensors( , )
16:    kill( )
17:   else
18:     discoverLBAs()
19:     findSuitableAgent( , )
20:    if not null then            Remote task passing
21:      .findSuitableAgent( )
22:      .assignSensors( , )
23:     kill( )
24:    end if
25:   end if
26:  end if
27: end procedure
Algorithm 3: Algorithm to reduce the number of underloaded agents in the multi-agent system by using task merging. : minimum task load, : lower threshold task load, : agent task load, : most underloaded agent identifier, : second most underloaded agent identifier, and : list with sensor identifiers.