0% found this document useful (0 votes)
2 views

Discrete Computational Structures Project Full Report

Uploaded by

MMT
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Discrete Computational Structures Project Full Report

Uploaded by

MMT
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Discrete Computational Mathematics Project

Name: Muaz Mohammed

Student Number: 2304050051

Project Number and Explantion: Number 6 – Linear Programming

1. Building the Algorithm

Define Decision Variables

Let:

- x_apple: units of apples

- x_rice: units of rice

- x_chicken: units of chicken

Define the Objective Function

The goal is to minimize the total cost of purchasing these items:

Minimize Cost = 0.5 * x_apple + 1 * x_rice + 3 * x_chicken

Define the Constraints

Nutritional requirements for calories, protein, and carbohydrates are defined


as follows:

Calorie Requirement: 80 * x_apple + 130 * x_rice + 200 * x_chicken ≥ 2000

Protein Requirement: 0.5 * x_apple + 2.5 * x_rice + 30 * x_chicken ≥ 50


Carbohydrate Requirement: 20 * x_apple + 28 * x_rice ≥ 300

Non-negativity: x_apple, x_rice, x_chicken ≥ 0

2. Writing a Code in Python using the Pulp Library

import pulp

# Step 1: Define the problem

problem = pulp.LpProblem("Minimize_Food_Cost", pulp.LpMinimize)

# Step 2: Define the variables (amounts of each food in 100g)

x_apple = pulp.LpVariable("x_apple", lowBound=0, cat="Continuous")

x_rice = pulp.LpVariable("x_rice", lowBound=0, cat="Continuous")

x_chicken = pulp.LpVariable("x_chicken", lowBound=0, cat="Continuous")

# Step 3: Define the objective function (minimize cost)

problem += 0.5 * x_apple + 1 * x_rice + 3 * x_chicken, "Total_Cost"

# Step 4: Add the constraints

# Calorie requirement

problem += 80 * x_apple + 130 * x_rice + 200 * x_chicken >= 2000,


"Calorie_Requirement"

# Protein requirement

problem += 0.5 * x_apple + 2.5 * x_rice + 30 * x_chicken >= 50,


"Protein_Requirement"

# Carbohydrate requirement
problem += 20 * x_apple + 28 * x_rice >= 300, "Carbohydrate_Requirement"

# Step 5: Solve the problem

problem.solve()

# Step 6: Display the results

print("Status:", pulp.LpStatus[problem.status])

print("Optimal Food Quantities (in 100g):")

print(f"Apple: {x_apple.varValue:.2f}g")

print(f"Rice: {x_rice.varValue:.2f}g")

print(f"Chicken: {x_chicken.varValue:.2f}g")

print("\nTotal Cost:", pulp.value(problem.objective))

This code defines the problem, defines the constraints, solves the LP problem
and prints out the result!

Result:
Status: Optimal

Optimal Food Quantities (in 100g):

Apple: 21.74g

Rice: 0.00g

Chicken: 1.30g

Total Cost: 14.782608399999999

You might also like