1) I agree that brute force is bad.
2) Your problem is the integer problem. However, they can be solved using linear programming.
3) You can distinguish between two different approaches: heuristics and exact approaches. Heuristics provides good solutions in a reasonable calculation time. They are used when there are strict requirements for calculation time or if the problem is too complex to calculate the optimal solution. Genetic algorithms are heuristic.
Since your problem is relatively simple, you will probably come up with the exact approach.
4) The standard way to solve this problem is to embed a linear program in the search and related search tree. It has a lot of literature. The procedure can be described as follows:
- Solve a linear program using a simplex algorithm
- Find the fractional variable for branching. That is, x = 1.5
- Create two new nodes and add constraints x <= 1 and x> = 2 respectively
- Go to one node (selected by some strategy)
- Go to step 1
In addition, on each node in the tree, after point 1, the algorithms check whether it is possible to trim the node. This means stopping the search “deeper” for this node, because
a) the problem has become unattainable,
b) a better solution already exists,
c) an integer solution is found. This objective value of this solution is used to determine point b.
The procedure ends when all nodes are cut.
Fortunately, as Nicholas said, there are free implementations that do just that. All you have to do is create your own model. Encode its purpose and limitations in some tool and allow it to be solved.
Kalle source share