THANGAVELU ENGINEERING COLLEGE
RAJIV GANDHISALAI, KARAPAKKAM.CHENNAI-600 097
AANOAVE
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
2024-2025
RECORD NOTE BOOK
AD3351- DESIGN AND ANALYSIS ALGORITHM
LABORATORY
STUDENT NAME
REGISTER NUMBER
THANGAVELUENGINEERING COLLEGE
RAJIV GANDHI SALAI, KARAPAKKAM, CHENNAI-600097.
BONAFIDE CERTIFICATE
Certified that this is the Bonafide record of work done by the Mr/Ms
in the Degree course in the
Laboratory during the academic
year
Station :Chennai - 600097
Date :
Staff Incharge Head of the Department
Submitted for the University practical Examination held on .... at
Thangavelu Engineering College, Karapakkam, Chennai-600097.
INTERNAL EXAMINER EXTERNAL EXAMINER
AD3351 DESIGN AND ANALYSIS OF
ALGORITHM LABORATORY
CONTENT
PAGE
S.NO. TOPIC DATE SIGNATURE
NO
Implement recursive and non-
recursive algorithms and study
1. the order of growth from log2n
to n!.
Divide and Conquer -
2. Strassen’s Matrix Multiplication
Decrease and Conquer -
Topological Sorting
3.
Transform and Conquer - Heap
4. Sort
Dynamic programming - Coin
change Problem, Warshall’s
5. and Floyd‘s algorithms,
Knapsack Problem
Greedy Technique – Dijkstra’s
algorithm, Huffman Trees and
6. codes
Iterative improvement - Simplex
7. Method
Backtracking – N-Queen
8. problem, Subset Sum Problem
Branch and Bound -
9. Assignment problem, Traveling
Salesman Problem
Ex.No: 1(a) IMPLEMENT RECURSIVE ALGORITHM.
Date :
AIM:
To Implement a python program for recursive algorithm.
PROCEDURE:
(FACTORIAL)
STEP 1:start
STEP 2:Read number n
STEP 3:Call factorial(n)
STEP 4:Print factorial(n)
STEP 5:Stop Factorial(n)
STEP 1:If n==1 return 1
STEP 2:else:
Fact=n=factorial(n-1) STEP 3:Return factor
PROGRAM/SOURCE CODE:
def factorial(n):
if n<=1:
return 1
else:
return n*factorial(n-1)
num = 5;
print("Factorial of",num,"is",factorial(num))
OUTPUT:
Factorial of 5 is 2
RESULT:
Thus the program to implement the concept of Recursive algorithm
using python has been executed successfully
Ex.No: 1(b) IMPLEMENT NON-RECURSIVE
ALGORITHM.
Date :
AIM:
To Implement a python program for Non-Recursive algorithm.
PROCEDURE:
(BINARY SEARCH)
STEP 1: set beg = lower_bound, end = upper_bound, pos = - 1
STEP 2: repeat steps 3 and 4 while beg <=end
STEP 3: set mid = (beg + end)/2 STEP 4:
if a[mid] = val set pos = mid print pos
go to step 6 else if a[mid] > val set end
= mid - 1 else set beg = mid + 1 STEP 5:
if pos = -1
print( "value is not present in the array")
STEP 6: exit
PROGRAM/SOURCE CODE:
def binarySearch(arr, l, r, x):
if r >= l:
mid = l + (r - l) // 2
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)
else:
return binarySearch(arr, mid + 1, r, x)
else:
return –1
arr = [2, 3, 4, 10, 40]
x = 10
result = binarySearch(arr, 0, len(arr)-1,x)
if result != -1:
print("Element is present at index % d" % result)
else:
print("Element is not present in array")
OUTPUT:
Element is present at index 3
RESULT:
Thus, the program to Implement Non-Recursive algorithm using python has been executed
successfully
Ex.No: 2 DIVIDE AND CONQUER -STRASSEN’S
MATRIX MULTIPLICATION
Date :
AIM:
To implement Strassen’s Matrix Multiplication using Divide and Conquer method
PROCEDURE:
STEP 1:Divide a matrix of order of 2*2 recursively till we get the matrix of 2*2.
STEP 2:Use the previous set of formulas to carry out 2*2 matrix multiplication.
STEP 3:In this eight multiplication and four additions, subtraction are performed.
STEP 4:Combine the result of two matrixes to
PROGRAM/SOURCE CODE:
import numpy as np
def split(matrix):
""" Splits a given matrix into quarters. Input: nxn matrix Output: tuple containing 4 n/2 x
n/2 matrices corresponding to a, b, c, d """
row, col = matrix.shape
row2, col2 = row//2, col//2
return matrix[:row2, :col2], matrix[:row2, col2:], matrix[row2:, :col2], matrix[row2:, col2:]
def strassen(x, y):
“””Computes matrix product by divide and conquer approach, recursively. Input: nxn
matrices x and y Output: nxn matrix, product of x and y “””
# Base case when size of matrices is 1x1
if len(x) == 1:
return x * y
# Splitting the matrices into quadrants. This will be done recursively
# until the base case is reached.
a, b, c, d = split(x)
e, f, g, h = split
# Computing the 7 products, recursively (p1, p2...p7)
p1 = strassen(a, f - h)
p2 = strassen(a + b, h)
p3 = strassen(c + d, e)
p4 = strassen(d, g - e)
p5 = strassen(a + d, e + h)
p6 = strassen(b - d, g + h)
p7 = strassen(a - c, e + f)
# Computing the values of the 4 quadrants of the final matrix c
c11 = p5 + p4 - p2 + p6
c12 = p1 + p2
c21 = p3 + p4
c22 = p1 + p5 - p3 - p7
# Combining the 4 quadrants into a single matrix by stacking horizontally and vertically.
c = np.vstack((np.hstack((c11, c12)), np.hstack((c21, c22))))
return c
A = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9,10,11,12],
[13,14,15,16]])
B = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9,10,11,12],
[13,14,15,16]])
C = strassen(A, B)
print(C)
OUTPUT:
[[ 90 100 110 120]
[202 228 254 280]
[314 356 398 440] [426
484 542 600]]
RESULT:
Thus, the python program to implement Strassen’s Matrix Multiplication using Divide and
Conquer has been executed successfully
Ex.No: 3 DECREASE AND CONQUER-TOPOLOGICAL SORTING
Date :
AIM:
To implement Topological sorting using Decrease and Conqueruer
PROCEDURE:
STEP 1:Start
STEP 2:Find a vertex that has indegree = 0 (no incoming edges)
STEP 3:Remove all the edges from that vertex that go outward (make it's outdegree = 0, remove outgoing edges)
STEP 4:Add that vertex to the array representing topological sorting of the graph
STEP 5:Repeat till there are no more vertices left.
STEP 6:Stop.
PROGRAM/SOURCE CODE:
# Python program to print topological sorting of a DAG from collections import defaultdict
# Class to represent a graph class Graph:
def __init__(self, vertices):
self.graph = defaultdict(list)
# dictionary containing adjacency
List self.V = vertices
# No. of vertices
#function to add an edge to graph
def addEdge(self, u, v):
self.graph[u].append(v)
# A recursive function used by topologicalSor
def topologicalSortUtil(self, v, visited, stack):
# Mark the current node as visited.
visited[v] = True
# Recur for all the vertices adjacent to this vertex
for i in self.graph[v]:
if visited[i] == False:
self.topologicalSortUtil(i, visited, stack)
# Push current vertex to stack which stores result stack.append(v)
# The function to do Topological Sort. It uses recursive
# topologicalSortUtil()
def topologicalSort(self):
# Mark all the vertices as not visited
visited = [False]*self.V stack = []
# Call the recursive helper function to store Topological
# Sort starting from all vertices one by one
for i in range(self.V):
if visited[i] == False:
self.topologicalSortUtil(i, visited, stack)
# Print contents of the stack
print(stack[::-1])
# return list in
# Driver Code
if __name__ == '__main__':
g = Graph(6)
g.addEdge(5, 2)
g.addEdge(5, 0)
g.addEdge(4, 0)
g.addEdge(4, 1)
g.addEdge(2, 3)
g.addEdge(3, 1)
print("Following is a Topological Sort of the given
graph")
# Function Call g.topologicalSort(
OUTPUT:
Following is a Topological Sort
RESULT:
Thus, the python program to implement Topological Sorting uing Decrease and Conquer has
been executed successfully
Ex.No: 4 TRANSFORM AND CONQUER-HEAP SORT
Date
AIM:
To implement Heap Sort using Transform and Conquer.
PROCEDURE:
STEP 1:Build a max heap from the input data.
STEP 2:At this point, the maximum element is stored at the root of the heap.
Replace it with the last item of the heap followed by reducing the size of the
heap by 1. Finally, heapify the root of the tree.
STEP 3:Repeat step 2 while the size of the heap is greater than 1.
PROGRAM/SOURCE CODE:
# Python program for implementation of heap Sort
# To heapify subtree rooted at index i.
# n is size of heap
def heapify(arr, N, i):
largest = i
# Initialize largest as root l = 2 * i
+ 1 # left = 2*i + 1 r = 2 * i
+ 2 # right = 2*i + 2
# See if left child of root exists and is
# greater than root
if l < N and arr[largest]<arr[l]:
largest = l
# See if right child of root exists an
# greater than root
if r < N and arr[largest] < arr[r]:
largest = r
# Change root, if needed
if largest != i: arr[i], arr[largest] = arr[largest], arr[i]
# swap
# Heapify the root.
heapify(arr, N, largest)
# The main function to sort an array of given size
def heapSort(arr):
N = len(arr)
# Build a maxheap.
for i in range(N//2 - 1, -1, -1):
heapify(arr, N, i)
# One by one extract elements
for i in range(N-1, 0, -1):
arr[i], arr[0] = arr[0], arr[i]
# swap heapify(arr, i, 0)
# Driver's code
if __name__ == '__main__':
arr = [28,11,17,13,18,29,25]
# Function call
heapSort(arr)N = len(arr)
print("Sorted array is")
for i in range(N):
print("%d" % arr[i],end=””)
OUTPUT:
Sorted array is
11131718252829
RESULT:
Thus, the program to implement character recognition using multilayer
perceptron has been executed successfully.
Ex.No: 5(a) DYNAMIC PROGRAMMING D COIN
CHANGING PROBLEM.
Date
AIM:
To implement Coin Changing Problem using dynamic programming
PROCEDURE:
STEP 1: Start.
STEP 2: Get input amount as a amt.
STEP 3:if amount = 0, then return 0.
STEP 4:if minimum of coins array > amount, then return -1.
STEP 5:Define one array called dp, of size amount + 1, and fill this
with -1.
STEP 6:for i in range coins array. if i > length of dp – 1, then skip the
next part, go for the next iteration. dp[i] := 1.
STEP 7:Return dp[amount].
STEP 8: stop
PROGRAM/SOURCE CODE:
class Solution(object):
def coinChange(self, coins, amount):
if amount == 0 :
return 0
if min(coins) > amount:
return –1
dp = [-1 for i in range(0, amount + 1)]
for i in coins:
if i > len(dp) - 1:
continue
dp[i] = 1
for j in range(i + 1, amount + 1):
if dp[j - i] == -1:
continue
elif dp[j] == -1:
dp[j] = dp[j - i] + 1
else:
dp[j] = min(dp[j], dp[j - i] + 1)
return dp[amount]
ob1 = Solution()
amt=int(input("Enter the amount:"))
print(ob1.coinChange([1,2,5],amt)
OUTPUT:
Enter the amount: 12
3
RESULT:
Thus, the python program to implement the Coin Changing Problem using
Dynamic Programming has been executed successfully
Ex.No: 5(b) WARSHALL’S AND FLOYD’S
ALGORITHM
Date
AIM:
To implement the Warshall’s and Flyod’s algorithms using Dynamic
programing
PROCEDURE:
STEP 1: Start
STEP 2: Get input ‘n’ where n = no of vertices
STEP 3:Assign A = matrix of dimension n*n
STEP 4:for k = 1 to n
STEP 5:for i = 1 to n
STEP 6:for j = 1 to n
STEP 7:Ak[i, j] = min (Ak-1[i, j], Ak-1[i, k] + Ak-1[k, j])
STEP 8: Return A
STEP 9: Stop
PROGRAM/SOURCE CODE:
nV = 4
INF = 999
def floyd_warshall(G):
distance = list(map(lambda i: list(map(lambda j: j, i)), G))
# Adding vertices individually
for k in range(nV):
for i in range(nV):
for j in range(nV):
distance[i][j] = min(distance[i][j], distance[i][k]
+ distance[k][j])
print_solution(distance)
# Printing the solution
def print_solution(distance):
for i in range(nV):
for j in range(nV):
if(distance[i][j] == INF):
print("INF", end=" ")
else:
print(distance[i][j], end=" ")
print(" ")
[INF, INF, 2, 0]]
floyd_warshall(G)
OUTPUT:
0375
2064
3105
5320
RESULT:
Thus, the python program to Warshall’s and Floyd’s algorithms using Dynamic
Programming has been executed successfull
Ex.No: 5(b) KNAPSACK PROBLEM
Date
AIM:
To Write a program to Knapsack Problem using Dynamic
Programming
PROCEDURE:
STEP 1: Start
STEP 2:Calculate the ratio(value/weight) for each item.
STEP 3:Sort all the items in decreasing order of the ratio.
STEP 4:Initialize res =0, curr_cap = given_cap.
STEP 5:Do the following for every item “i” in the sorted order.
STEP 6:If the weight of the current item is less than or equal to the
remaining capacity then add the value of that item into the result
STEP 7:Else add the current item as much as we can and break out of
the loop.
STEP 8:Return res.
STEP 9: Stop
PROGRAM/SOURCE CODE:
def knapSack(W, wt, val, n): K =
[[0 for x in range(W + 1)]
for x in range(n + 1)]:
# Build table K[][] in bottom up manner
for i in range(n + 1):
for w in range(W + 1):
if i == 0 or w == 0:
K[i][w] = 0
elif wt[i-1] <= w:
K[i][w] = max(val[i-1] +
K[i-1][w-wt[i-1]], K[i-
1][w])
else:
K[i][w] = K[i-1][w]
return K[n][W]
# Driver program to test above function
val = [60, 100,120]
wt = [10, 20, 30]
W = 50 n =
len(val)
print(knapSack(W, wt, val, n)
OUTPUT:
220
RESULT:
Thus, by using Dynamic Programming,the Knapsack Problem has been
demonsted successfully .
Ex.No: 6(a) GREEDY TECHNIQUE DIJKSTRA’S
ALGORITHM
Date
AIM:
To implement Dijkstra’s Algorithm using Greedy Technique
PROCEDURE:
STEP 1:Start
STEP 2:Create a set sptSet that keeps track of vertices included in the
shortest-path tree.
STEP 3:Assign a distance value to all vertices in the input graph.
Initialize all distance values as infinite. Assign the distance value as 0
for the source vertex so that it is picked first.
STEP 4:While sptSet doesn’t include all vertices, pick a vertex u which
is not there in sptSet and has a minimum distance.
STEP 5:Include u to sptSet.
STEP 6:Then update distance value of all adjacent vertices of u.
STEP 7:To update the distance values, iterate through all adjacent
vertices.
STEP 8:For every adjacent vertex v, if sum of the distance value of u
(from source) and weight of edge u- v, is less than the distance value
of v, then update the distance value of v.
STEP 9:Sto
PROGRAM/SOURCE CODE:
# Python program for Dijkstra's single
# source shortest path algorithm. The program is # for adjacency
matrix representation of the graph
# Library for INT_MAX
import sys
class Graph():
def __init__(self, vertices):
self.V = vertices
self.graph = [[0 for column in range(vertices)]
for row in range(vertices)]
def printSolution(self, dist):
print("Vertex \tDistance from Source")
for node in range(self.V):
print(node, "\t", dist[node])
# A utility function to find the vertex with
# minimum distance value, from the set of vertices
# not yet included in shortest path tree
def minDistance(self, dist, sptSet):
# Initialize minimum distance for next node
min = sys.maxsize
# Search not nearest vertex not in the
# shortest path tree
for u in range(self.V):
if dist[u] < min and sptSet[u] == False:
min = dist[u]
min_index=u
return min_index
# Function that implements Dijkstra's single source
# shortest path algorithm for a graph represented
# using adjacency matrix representation
def dijkstra(self, src):
dist = [sys.maxsize] * self.V
dist[src] = 0
sptSet = [False] * Self.V
for cout in range(self.V):
# Pick the minimum distance vertex from
# the set of vertices not yet processed.
# x is always equal to src in first iteration
x = self.minDistance(dist, sptSet)
# Put the minimum distance vertex in the
# shortest path tree
sptSet[x] = True
# Update dist value of the adjacent vertices
# of the picked vertex only if the current
# distance is greater than new distance and
# the vertex in not in the shortest path tree
for y in range(self.V):
if self.graph[x][y] > 0 and sptSet[y] == False and \
dist[y] > dist[x] + self.graph[x][y]:
dist[y] = dist[x] + self.graph[x][y]
self.printSolution(dist)
# Driver's code
if __name__ == "__main__":
g = Graph(9)
g.graph = [[0, 4, 0, 0, 0, 0, 0, 8, 0],
[4, 0, 8, 0, 0, 0, 0, 11, 0],
[0, 8, 0, 7, 0, 4, 0, 0, 2],
[0, 0, 7, 0, 9, 14, 0, 0, 0],
[0, 0, 0, 9, 0, 10, 0, 0, 0],
[0, 0, 4, 14, 10, 0, 2, 0, 0],
[0, 0, 0, 0, 0, 2, 0, 1, 6],
[8, 11, 0, 0, 0, 0, 1,0,7],
[0, 0, 2, 0, 0, 0, 6, 7, 0]]
g.dijkstra(0)
OUTPUT:
Vertex Distance from Source
0 0
1 4
2 12
3 19
4 21
5 11
6 9
7 8
8 14
RESULT:
hus, the python program to implement Dijkstras algorithm using Greedy
Technique has been executed successfully.
Ex.No: 6(b) HUFFMAN TREES AND CODES
Date
AIM:
To implement Huffman Trees and Codes using Greedy Technique.
PROCEDURE:
STEP 1:Start
STEP 2:Input is an array of unique characters along with their
frequency of occurrences
STEP 3:Create a leaf node for each unique character and build a min
heap of all leaf nodes (Min Heap is used as a priority queue. The
value of frequency field is used to compare two nodes in min heap.
Initially, the least frequent character is at root)
STEP 4:Extract two nodes with the minimum frequency from the min
heap.
STEP 5:Create a new internal node with a frequency equal to the sum
of the two nodes frequencies. Make the first extracted node as its
left child and the other extracted node as its right child. Add this
node to the min heap.
STEP 6:Repeat steps 2 and 3 until the heap contains only one node.
The remaining node is the root node and the tree is complete.
STEP 7:Stop
PROGRAM/SOURCE CODE:
# A Huffman Tree Node
import heapq
class node:
def __init__(self, freq, symbol, left=None, right=None):
# frequency of symbol
self.freq = freq
# symbol name (character)
self.symbol = symbol
# node left of current node
self.left = left
# node right of current node
self.right = right
# tree direction (0/1)
Self.huff = ''
def __lt__(self, nxt):
return self.freq < nxt.freq
# utility function to print huffman
# codes for all symbols in the newly
# created Huffman tree
def printNodes(node, val=''):
# huffman code for current node
newVal = val + str(node.huff)
# if node is not an edge node
# then traverse inside it
if(node.left):
print(node.left, newVal)
if(node.right):
printNodes(node.right,newVal)
# if node is edge node then
# display its huffman code
if(not node.left and not node.right):
print(f"{node.symbol}
{newVal}")
# characters for huffman tree
chars = ['a', 'b', 'c', 'd', 'e', 'f']
# frequency of characters
freq = [ 5, 9, 12, 13, 16, 45] #
list containing unused nodes
nodes = []
# converting characters and frequencies
# into huffman tree nodes
for x in range(len(chars)):
heapq.heappush(nodes, node(freq[x],
chars[x]))
while len(nodes) > 1:
# sort all the nodes in ascending order
# based on their frequency
left = heapq.heappop(nodes)
right = heapq.heappop(nodes)
# assign directional value to these
nodes
left.huff = 0
right.huff = 1
# combine the 2 smallest nodes to create
# new node as their parent
newNode=node(left.freq+right.freq,left.symbol+righ
t.symbol, left, right)
heapq.heappush(nodes, newNode)
printNodes(nodes[0]
OUTPUT:
f -> 0
c -> 100
d -> 101
a -> 1100
b -> 1101
e -> 111
RESULT:
Thus, the python program to implement Huffman Trees and Codes using
Greedy technique has been executed successfully
Ex.No: 7 ITERATION IMPOROVEMNT-SIMPLEX
METHOD
Date :
AIM:
To Implement a Iterartion improvement using simplex method
PROCEDURE:
STEP 1:start
STEP 2:get the input
STEP 3:plot the variable as
per the simplex rule
STEP 4:Print the output
Using simplex (c,A,B)
plot
STEP 5:Stop
PROGRAM/SOURCE CODE:
Import numpy as np
Import math
C = [1, 1, 0, 0, 0]
A=[
[-1, 1, 1, 0, 0],
[ 1, 0, 0, 1, 0],
[ 0, 1, 0, 0, 1]
]
B = [2, 4, 4]
Def to_tableau(c, A, b):
Xb = [eq + [x] for eq, x in zip(A, b)]
Z = c + [0]
Return xb + [z]
Def can_be_improved(tableau):
Z = tableau[-1]
Return any(x > 0 for x in z[:-1])
Import math
Def get_pivot_position(tableau):
Z = tableau[-1]
Column = next(I for I, x in enumerate(z[:-1]) if x > 0)
Restrictions = []
For eq in tableau[:-1]:
El = eq[column]
Restrictions.append(math.inf if el <= 0 else eq[-1] / el)
Row = restrictions.index(min(restrictions))
Return row, column
Def pivot_step(tableau, pivot_position):
New_tableau = [[] for eq in tableau]
I, j = pivot_position
Pivot_value = tableau[i][j]
New_tableau[i] = np.array(tableau[i]) / pivot_value
For eq_i, eq in enumerate(tableau):
If eq_i != i:
Multiplier = np.array(new_tableau[i]) * tableau[eq_i][j]
New_tableau[eq_i] = np.array(tableau[eq_i]) – multiplier
Return new_tableau
Def is_basic(column):
Return sum(column) == 1 and len([c for c in column if c == 0]) == len(column) – 1
Def get_solution(tableau):
Columns = np.array(tableau).T
Solutions = []
For column in columns:
Solution = 0
If is_basic(column):
One_index = column.tolist().index(1)
Solution = columns[-1][one_index]
Solutions.append(solution)
Return solutions
Def simplex(c, A, b):
Tableau = to_tableau(c, A, b)
While can_be_improved(tableau):
Pivot_position = get_pivot_position(tableau)
Tableau = pivot_step(tableau, pivot_position)
Return get_solution(tableau)
Solution = simplex(c, A, b)
Print(‘solution: ‘, solution)
C = [1, 1, 0, 0, 0]
A=[
[-1, 1, 1, 0, 0],
[ 1, 0, 0, 1, 0],
[ 0, 1, 0, 0, 1]
]
B = [2, 4, 4]
Def to_tableau(c, A, b):
Xb = [eq + [x] for eq, x in zip(A, b)]
Z = c + [0]
Return xb + [z]
Def can_be_improved(tableau):
Z = tableau[-1]
Return any(x > 0 for x in z[:-1])
Import math
Def get_pivot_position(tableau):
Z = tableau[-1]
Column = next(I for I, x in enumerate(z[:-1]) if x > 0)
Restrictions = []
For eq in tableau[:-1]:
El = eq[column]
Restrictions.append(math.inf if el <= 0 else eq[-1] / el)
Row = restrictions.index(min(restrictions))
Return row, column
Def pivot_step(tableau, pivot_position):
New_tableau = [[] for eq in tableau]
I, j = pivot_position
Pivot_value = tableau[i][j]
New_tableau[i] = np.array(tableau[i]) / pivot_value
For eq_i, eq in enumerate(tableau):
If eq_i != i:
Multiplier = np.array(new_tableau[i]) * tableau[eq_i][j]
New_tableau[eq_i] = np.array(tableau[eq_i]) – multiplier
Return new_tableau
Def is_basic(column):
Return sum(column) == 1 and len([c for c in column if c == 0]) == len(column) – 1
Def get_solution(tableau):
Columns = np.array(tableau).T
Solutions = []
For column in columns:
Solution = 0
If is_basic(column):
One_index = column.tolist().index(1)
Solution = columns[-1][one_index]
Solutions.append(solution)
Return solutions
Def simplex(c, A, b):
Tableau = to_tableau(c, A, b)
While can_be_improved(tableau):
Pivot_position = get_pivot_position(tableau)
Tableau = pivot_step(tableau, pivot_position)
Return get_solution(tableau)
Solution = simplex(c, A, b)
Print(‘solution: ‘, solution)
OUTPUT:
Solution: [4.0, 4.0, 2.0, 0, 0, 0]
solution: [4.0, 4.0, 2.0, 0, 0, 0]
RESULT:
Thus the program to implement the Iterartio improvement using
simplex method using python has been executed successfully