Human diet planning is generally carried out by selecting the food items or groups of food items to be used in the diet and then calculating the composition. If nutrient quantities do not reach the desired nutritional requirements, foods are exchanged or quantities altered and the composition recalculated. Iterations are repeated until a suitable diet is obtained. This procedure is cumbersome and slow and often leads to compromises in composition of the final diets. A computerized model, planning diets for humans at minimum cost while supplying all nutritional requirements, maintaining nutrient relationships and preserving eating practices is presented. This is based on a mixed-integer linear-programming algorithm. Linear equations were prepared for each nutritional requirement. To produce linear equations for relationships between nutrients, linear transformations were performed. Logical definitions for interactions such as the frequency of use of foods, relationships between exchange groups and the energy content of different meals were defined, and linear equations for these associations were written. Food items generally eaten in whole units were defined as integers. The use of this program is demonstrated for planning diets using a large selection of basic foods and for clinical situations where nutritional intervention is desirable. The system presented begins from a definition of the nutritional requirements and then plans the foods accordingly, and at minimum cost. This provides an accurate, efficient and versatile method of diet formulation.