This paper introduces a multiagent optimization algorithm inspired by the collective behavior of social insects. In our method, each agent encodes a possible solution of the problem to solve, and evolves in a way similar to real life insects. We test the algorithm on a classical difficult problem, the $k$-coloring of a graph, and we compare its performance in relation to a standard genetic algorithm and another multiagent
system. The results show that this algorithm
is faster and outperforms the other methods for a range of random graphs with different orders and densities. Moreover, the method is easy to adapt to solve different NP-complete problems.