  We propose a new optimization method based on a demagnetization procedure
well known in magnetism. We show how this procedure can be applied as a general
tool to search for optimal solutions in any system where the configuration
space is endowed with a suitable `distance'. We test the new algorithm on
frustrated magnetic models and the traveling salesman problem. We find that the
new method successfully competes with similar basic algorithms such as
simulated annealing.
