Solving optimization problems by the public goods game