MulaiMulai sekarang secara gratis

Trying out lpSum

In this exercise you are making two types (premium and budget) of ice cream, using heavy cream, whole milk, and sugar. One version is a premium version containing more cream than your budget version. You are looking to find the mixture of ingredients that minimizes the total costs of ingredients.

Ingredient $/cup
Cream $1.5
Milk $0.125
Sugar $0.10

Two Python lists called prod_type and ingredient have been created for you, along with a dictionary var_dict containing the decision variables of the model. You can explore them in the console.

Latihan ini adalah bagian dari kursus

Supply Chain Analytics in Python

Lihat Kursus

Petunjuk latihan

  • Define the objective function using lpSum() with list comprehension and the information in the table above. Iterate over the product types and multiply the dictionary variable by the correct ingredient cost.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Define Objective Function
model += lpSum([1.5 * var_dict[(i, 'cream')] 
                + ____ * var_dict[(i, 'milk')] 
                + ____ * var_dict[(i, ____)]
                
                # Iterate over product types
                for i in ____])
Edit dan Jalankan Kode