A lot of these optimization problems can benefit from using a genetic algorithm: https://github.com/lodenrogue/genetic-algorithm-js