Solving and analyzing a model: the diet problem

This example shows you how to create and solve a Python-based model using a sample.

About this task

This well-known optimization problem identifies the best mix of foodstuffs to meet dietary requirements while minimizing costs. The data inputs are the nutritional profile and price of different foods and the min and max values for nutrients in a diet. The model is expressed as the minimization of a linear program. The files used in this sample are available in the DO-samples.

Procedure

  1. Download and unzip the DO-samples from the Decision Optimization GitHub on to your machine.
  2. Create a project in IBM Watson Studio. Select Create an empty project.
  3. Click Add to Project.
  4. Select Decision Optimization.
  5. Select the From file tab in the Decision Optimization model pane that opens.
  6. Click Add file. Then browse and choose Diet.zip from the Model_Builder folder in the DO-samples that you downloaded.
  7. Associate a Machine Learning service instance with your project and reload the page.
  8. Click Create.
    A Decision Optimization model is created with the same name as the sample.
  9. In the Prepare data view, you can see the data assets imported.
    These tables represent the min and max values for nutrients in the diet (diet_nutrients), the nutrients in different foods (diet_food_nutrients), and the price and quantity of specific foods (diet_food).Tables of input data in Prepare data view
  10. Click Run Model in the sidebar to view your model.
    The Python model minimizes the cost of the food in the diet while satisfying minimum nutrient and calorie requirements. Python model for diet problem displayed in Run Model view. Note also how the inputs (tables in the Prepare data view) and the outputs (in this case the solution table to be displayed in the Explore solution view) are specified in this model.
  11. Run the model using the Run button on the top right of the Model view.

Results

Once the model is solved, the page refreshes with the Solution view displayed. The solution contains a list of foods and their quantities, along with the nutrients that they provide. KPIs are also shown in this Solution view.

In the Visualization view, the solution is displayed as a table and a chart in the Solution page. You can add notes, different types of tables and charts to show input data, solution data or KPIs by selecting and editing the widgets. You can also create different pages in the Visualization view. For example, an Input page is also provided in this sample. See Visualization view.

You're ready to start running comparisons between different scenarios. For example, the basic solution contains a quantity of hot dog. You might want to check an alternate solution for someone who prefers a vegetarian diet.