LAB0 UPDATED Converted - Compressed PDF
LAB0 UPDATED Converted - Compressed PDF
Step 1:
Type python 2.7 in Google, click on Python 2.7.0 Release | python.org
Step 2:
Click on Windows X86-64 MSI Installer (2.7.0)[1](sig)
Step 3:
Click on Exe file then start installing process
Click on Next
Click on Next
Click on Next
Click on Next and after completing installing process, Click on Next.
Installation of Anaconda:
Step 3:
Run the exe file then start installing process
Step 3.1: Click on Next
Step 3.2: click on I Agree
Step 3.5: Select Add anaconda to my PATH environment variable and click on
Install.
Step 3.6: Click on Next
-
Step3.8 : Click on Finish
PULP:
One of the strengths of the Python language is the extensive standard library that is available to every
program that uses the Python interpreter
The standard library includes hundreds of modules that allow the programmer to, for example:
Python Syntax To aid in the understanding of the examples, it is helpful to introduce some of the relevant
language features of Python.
• Whitespace: Python uses indentation (with spaces or tabs) to indicate subsections of code.
• Variable declaration: Variables do have specific types (e.g. string, number, object), but it is not necessary to
pre-declare the variable types - the Python interpreter will determine the type from the first use of the
variable.
• Dictionaries and Lists: These are two common data structures in Python. Lists are a simple container of
items, much like arrays in many languages. They can change size at any time, can contain items of different
types, and are one dimensional. Dictionaries are another storage structure, where each item is associated with
a “key”. This is sometimes called a map or associative array in other languages. The key maybe be almost
anything, as long as it is unique.
• List comprehension: These are “functional programming” devices used in Python to dynamically generate
lists, and are very useful for generating linear expressions like finding the sum of a set. Many examples are
provided in the code below, but the general concept is to create a new list in place by filtering, manipulating or
combining other lists. For example, a list comprehension that provides the even numbers between 1 and 9 is
implemented with the Python code:
Decision Variables
variable = LpVariable("variableName")
Another useful way to define variables in PuLP is using the dicts function.
This can be very useful in cases where we need to define a large number of
variables of the same type and bounds, variableNames would be a list of keys
for the dictionary:
varDict = LpVariable.dicts("varDict", variableNames, lowBound, upBound)
Solving
# solving
problem.solve()
You want to minimize the cost of shipping goods from 2 different warehouses to 4
different customers. Each warehouse has a limited supply and each customer has
a certain demand. We need to fulfill the demand of the customers by shipping
products from given warehouses such that the overall cost of shipping is minimum
and we are also able to satisfy the customer demands using limited supply
available with each warehouse.
# Supply Matrix
warehouse_supply = np.array([60000, 80000])
Model Initialization
Output will be
In order to leverage the Numpy array operations, we can convert our decision
variables to a Numpy array.
DV_variables = LpVariable.matrix("X", variable_names, cat = "Integer", lowBound= 0 )
allocation = np.array(DV_variables).reshape(2,4)
print("Decision Variable/Allocation Matrix: ")
print(allocation)
output will be
Objective Function
obj_func = lpSum(allocation*cost_matrix)print(obj_func)model +=
obj_funcprint(model)
Constraints
print(model).
Output is:
Output:
https://www.youtube.com/watch?v=8IRrgDoV8Eo
Steps involved in the Graphical Method
1. Step 1: Formulate the LP (Linear programming) problem. ...
2. Step 2: Construct a graph and plot the constraint lines. ...
3. Step 3: Determine the valid side of each constraint line. ...
4. Step 4: Identify the feasible solution region. ...
5. Step 5: Plot the objective function on the graph. ...
6. Step 6: Find the optimum point.
3x + 4y ≤ 24 ... (3)
x ≥ 0, y ≥ 0 ... (4)
Solution:
The shaded region in the following Fig is the feasible region ABC determined by the system of constraints (2) to
(4), which is bounded. The coordinates of corner points
A, B and C are (0,5), (4,3) and (0,6) respectively. Now we evaluate Z = 200x + 500y at these points.
https://www.youtube.com/watch?v=Im17WchPw6g&t=447s
Graphical Method:
https://www.youtube.com/watch?v=8IRrgDoV8Eo&t=675s