The diet problem is one of the earliest real-life problems to be solved using linear programming. This example shows how to use ojAlgo to model and solve a (miniature) instance of this problem. Background information as well as the actual numbers used in this example can be found at NEOS.

The original problem was to feed an army at the lowest possible cost while providing the soldiers with enough nutrients. Different kind of food comes at different prices and contain varying amounts of nutrients.

It should be easy for you to adapt this example code to whatever optimisation problem you want to model.

Example Code

Console Output

class TheDietProblem
ojAlgo
2019-05-10


OPTIMAL 3.149999999999999 @ { 1E+1, 1.94444444444444, 1E+1 }

Adding integer constraints...

OPTIMAL 3.16 @ { 1E+1, 2, 1E+1 }

############################################
0 <= Bread: 10 (0.05) <= 10
0 <= Corn: 2 (0.18) <= 10
8 <= Milk: 10 (0.23) <= 10
5000 <= Vitamin A: 5214.0 <= 50000
2000 <= Calories: 2004.0 <= 2250
############################################