Brute force search is the simplest method for solving unconstrained optimization problems. Brute force search is a very general problem solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem. Mathematically, we go through all possible values of  x in the domain of the function to enumerate all the possible values of  f(x) . Then we pick the  x that corresponds to the smallest  f(x) .  In this method there can be more than one solution. One requirement of this method is that the domain should be enumerable. Hence this method is rarely used because it is not practical as we cannot enumerate infinitely infinite numbers. One way to simplify and solve this problem is through discretization. We can choose finitely many points from the given infinite domain. The drawback of discretization is that we likely get suboptimal solution when the points chosen do not contain the optimal answer. If the domain is unbounded  (-\infty,+\infty) , it is not clear how to choose the points for solving the problem. And the performance  is very slow for small sized problems. Like for a problem with 8 variables to solve, the dimension of the problem is  n^8 , where  n is the number  of discrete points chosen for each dimension. Hence the problems become more and more complex exponentially. Apart from all this, brute force search is easy to understand. 


					// An example univariate function.
val f: UnivariateRealFunction = object : AbstractUnivariateRealFunction() {
    override fun evaluate(x: Double): Double {
        return (x - 1) * (x - 1)

// Optimizes a univariate function using Brute Force Search method.
val solver = BruteForceMinimizer(
    1e-15, // epsilon
    20) // max number of iterations
val soln = solver.solve(f)
val xmin: Double = soln.minimizer()
val fmin: Double = f.evaluate(xmin)
println(String.format("f(%f) = %f", xmin, fmin))