0% found this document useful (0 votes)
3 views2 pages

Python 4

The document outlines a worksheet for a Numerical Methods and Optimization course, focusing on maximizing crop yield given constraints on water and fertilizer. It includes a Python code using the PuLP library to solve the optimization problem. Learning outcomes emphasize formulating optimization problems, using linear programming, and interpreting results.

Uploaded by

fakereality807
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python 4

The document outlines a worksheet for a Numerical Methods and Optimization course, focusing on maximizing crop yield given constraints on water and fertilizer. It includes a Python code using the PuLP library to solve the optimization problem. Learning outcomes emphasize formulating optimization problems, using linear programming, and interpreting results.

Uploaded by

fakereality807
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET- 4

Student Name: Anushka Jaiswal UID: 22BCS15089


Branch: CSE Section/Group: 818-B
Semester: 4 Date of Performance: 16/04/24
Subject Name: Numerical Methods and Optimization on using Python
Subject Code: 22CSH-259

1. Aim:

You are a farmer planning to grow two types of crops, Crop A and Crop B, on your farmland.
Each type of crop requires a certain amount of water and fertilizer to grow, and you have a
limited amount of both resources available. The objective is to maximize the total yield of
crops while respecting the resource constraints. Maximize the total yield of crops.
Crop details:
Crop A: Requires 5 gallons of water and 2 bags of fertilizer per acre.
Crop B: Requires 3 gallons of water and 4 bags of fertilizer per acre.
Constraints:
Ø Limited availability of water: You have 50 gallons of water available.
Ø Limited availability of fertilizer: You have 40 bags of fertilizer available.

2. Source Code:

from pulp import *

# Define the problem


prob = LpProblem("Crop_Optimization", LpMaximize)

# Define decision variables


x1 = LpVariable("Crop_A_Acres", lowBound=0, cat='Continuous')
x2 = LpVariable("Crop_B_Acres", lowBound=0, cat='Continuous')

# Define objective function


prob += 40*x1 + 50*x2, "Total_Yield_of_Crops"

# Define constraints
prob += 5*x1 + 3*x2 <= 50, "Water_Constraint"
prob += 2*x1 + 4*x2 <= 40, "Fertilizer_Constraint"

# Solve the problem


[Link]()

# Output the results


print("Optimal Solution:")
for v in [Link]():
print([Link], "=", [Link])

print("Total Yield of Crops:", value([Link]))

DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. Screenshot of Outputs:

4. Learning Outcomes

1. Understanding how to formulate optimization problems using linear programming.


2. Learning to use PuLP, a Python library for linear programming, to solve optimization
problems.
3. Understanding the importance of defining decision variables, objective function, and
constraints in optimization models.
4. Gaining insights into interpreting and analyzing the results of optimization models.
5. Understanding the significance of optimization techniques in resource allocation and
decision-making processes.

You might also like