# What is an objective function?

Local search algorithms are useful for solving pure optimization problems, in which the aim is to find the best state according to an objective function.

My question is what is the objective function?

For example, in machine learning, you define a model, $$\mathcal{M}$$. To train $$\mathcal{M}$$, you usually define a loss function $$\mathcal{L}$$ (e.g., a mean squared error), which you want to minimise. $$\mathcal{L}$$ is the "objective function" of your problem (which in this case is to be minimised).
In the context of search algorithms, the objective function could represent e.g. the cost of the solution. For example, in the case of the travelling salesman problem (TSP), you define a function, call it $$C$$, which represents the "cost" of the tour or Hamiltonian cycle, that is, a function which sums up the weights of all edges in the tour. In this case, the "objective" of your problem is to minimise this function $$C$$, because, essentially, you want to find an inexpensive tour, which is associated with either a local (or global) minimum of $$C$$. This function $$C$$ is the "objective function".