If you want to implement an algorithm byon your own, then we suggest you a randomized, derivative-free search, even simpler than a Nelder-Mead approachesapproach. Given a feasible solution (respecting the sum equal to 1), move randomly the values of the variables by an epsilon while maintaining the constraint feasible. If the solution is better, then keep it,it; otherwise, throw it away. Start with this simple approach. To go further:, tune the wayhow you choose the epsilons to move, accept less good solutions along the search to diversify (as done in simulated annealing), restartingand restart the search.
LocalSolverHexaly (ex LocalSolver), our global optimization solver, combines several optimization techniques under the hood. Here, the above is essentially what allows LocalSolverHexaly to perform very well on your problem. Thanks to the small number of dimensions (only 3 variables), there is no need to use derivatives (even approximated) to guide and speed up the search. In the same way, there is no need offor surrogate modeling of the cost function because this one is extremely fast to evaluate (about 10,000 calls per second).
Disclaimer: LocalSolverHexaly is a commercial software. You can try it for free duringfor 1 month. In addition, LocalSolverHexaly is free for basic research and teaching.
Please find below the results obtained by LocalSolver,Hexaly using your cost function as external functionexternal function:
function model() {
X[0..2] <- float(0,1);
constraint sum[i in 0..2](X[i]) == 1;
func <- doubleExternalFunction(cost);
obj <- call(func, X);
minimize obj;
}
Having declared the cost function, LocalSolverHexaly solves the problem as is. Here "solve" means that LocalSolverHexaly will try to find the best feasible solution to the problem. You can also specify lower and upper bounds for the cost function so that LocalSolverHexaly computes an optimality gap, and then possibly proves the optimality of the solution found.
You can write your model using the LocalSolver modeling languageHexaly modeling language (namely LSP) or using Python, Java, C#, or C++ APIsPython, Java, C#, or C++ APIs. Here is the link to download the LSP file: https://www.localsolver.com/misc/emma.lsphttps://www.hexaly.com/misc/emma.lsp. Having installed LocalSolverHexaly, you can run it using the command "localsolver"hexaly emma.lsp" in console. The best solution found by LocalSolverHexaly after a few seconds on a basic laptop is:
cost = -4683181.09020784, X0 = 0.00106356929433748, X1 = 0.287235884100486, X2 = 0.711702039130129
The sum over the X is equal toequals 1.00000149252495, which is slightly above 1, because LocalSolverHexaly uses a tolerance to satisfy constraints. If you wish the sum over the X to be surely lower than 1, then you can set "< 1" in the above model instead of "== 1". In this case, you will find the following solution:
cost = -4683175.50600612, X0 = 0.00111513425966878, X1 = 0.286966585180356, X2 = 0.711915927974678
Now, the sum over the X is equal to 0.999997647414703.