Search optimum on connected simulation

Do you know how can I find minimum/maximum of a simulation written in a Module. The simulation calculates a potential value to a territory after some steps.

It would seem like this:

g[x1_,x2_,x3_,x4_,x5_,x6_] := Module[{x1,x2,x3,x4,x5,x6}, some code calling a simulator software]


So I would like to reach a maximum potential according to the parameters. All parameters should vary between [-2 ... 0 .. 2], with stepsize 1 discretely. So all variations are 5^6, I don't have so much time and resource to calculate each variation.

Can you advise me some code or algorithm where I only have to put the name of the target function?

• Uh... NMinimize/NMaximize? FindMinimum/FindMaximum? Read their documentation, try it, and if you have any trouble, you can update the question to get some help. – Oleksandr R. Jan 9 '15 at 1:15

Define so it only exists for explicitly numeric intput, as

g[x1_?NumberQ,x2_?NumberQ,x3_?NumberQ,x4_?NumberQ,x5_?NumberQ,x6_?NumberQ]


Then can do

vars = {x1,x2,x3,x4,x5,x6};
NMinimize[{g[x1,x2,x3,x4,x5,x6],Element[vars,Integers]

If NMinimize is too slow or not giving viable results, could try FindMinimum but I don't think it will directly accept the integrality constraints for a nonlinear problem. So you'd probably need to use some penalty term approach involving, for each variable, (xj-Round[xj])^2 or some such.