Skip to main content
2 of 6
added 54 characters in body
Engineer
  • 30.4k
  • 4
  • 76
  • 124

but I don't know exactly how

Provided that you don't need to know how the algorithm ultimately works, but only need it to do the job per se, you might look into Genetic Algorithms. It is a highly iterative process that starts with a random genome per candidate, and, using an analogue to natural selection, slowly converges from those initial inputs toward an approximately optimal solution. The catch is that you must provide a fitness function by which to judge the genes of each successive generation. In your case this would be an evaluation of how much money was spent by the given candidate genome. You basically do this for say 100 sets of virtual "genes", look at the best ones as judged by your fitness function(s), and perform gene crossover and mutation to arrive at the next generation.

Rinse, repeat till you are happy with result.

Genetic Programming may also be useful; though I doubt it will be necessary in your case - as I imagine you only need your parameters to evolve - not your code as such.

These are large topics so I will not go further here. Refer there for a simple starter tutorial.

Engineer
  • 30.4k
  • 4
  • 76
  • 124