An algorithm inspired by the way that a species of beetle changes colour to communicate with its peers and predators solves engineering problems faster than a range of previous approaches.

The golden tortoise beetle (Charidotella sexpunctata) is unusual in that males can change the colour of their wing casings at will between browns, purples, bright orange and gold. Doing so can attract females for mating opportunities and also deter predators.

The behaviour inspired Omid Tarkhaneh at the University of Tabriz, Iran, and his colleagues to mimic the behaviour algorithmically and apply it to solve a range of real-world engineering problems.

The researchers created a virtual landscape that represents all potential solutions to the problem being worked on – good and bad, feasible and infeasible. A population of virtual beetles inhabits this space, and the location of each one represents a single possible solution. The landscape is a matrix of possibilities in many dimensions, one for each variable in the problem.

Read more: Virtual computer chip tests expose flaws and protect against hackers

For each iteration of the algorithm, the quality of each solution is tested and the colour of each virtual beetle changes to represent how good a solution it is. A virtual beetle that performs well takes on a particularly attractive colour that draws other virtual beetles towards it – and so towards a better position in the problem space. As a result of this process of attraction, some or all of the population will eventually converge on a position in the landscape that represents the optimum solution to the problem.

The researchers applied their beetle-inspired algorithm to two common engineering problems: the welded beam design problem, which seeks to minimise the production cost of metal structures, and the gear train design problem, which seeks to minimise the gear ratio created by four cogs.

They found that their algorithm was more efficient at finding solutions than five existing nature-inspired evolutionary algorithms at finding solutions. This means it did so relatively rapidly and was also more likely to find the best available solution anywhere in the virtual landscape, rather than converging on a local solution as some other algorithms do – equivalent to finding the highest point in a virtual hilly landscape, rather than becoming stuck at the top of a relatively small hill without finding taller ones nearby.

“Most of the idea came from nature,” says Tarkhaneh. “This kind of beetle is kind of unique, and I saw some videos about it and I thought their reflective colour and the colour mechanism was kind of interesting, so I started to read some papers about the life of this beetle and I saw that their colour-reflective mechanism can be modelled mathematically.”

But the researchers warn that the “no-free-lunch” rule means that the golden beetle algorithm won’t solve all problems better than existing approaches. The idea proposes that any two optimisation algorithms perform equally well when solving all possible problems that exist. In essence, while this algorithm was shown to perform some tasks better than alternatives, the reverse will be true in other cases.