Skip to content
Permalink
Browse files
assignment submission
  • Loading branch information
jaffala committed Nov 2, 2022
1 parent ce80de7 commit 28850df6e62bd7c3cb266f46aebcc4368ac063f3
Show file tree
Hide file tree
Showing 35 changed files with 594 additions and 369 deletions.
@@ -349,14 +349,199 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"github test\n",
"............................................................\n",
"............................................................\n",
"............................................................\n",
"............................................................\n",
"............................................................\n",
"............................................................\n",
"```"
"The Ant Colony optimisation was successfully executed using the Sci-kit package, using the aca.run() function. \n",
"\n",
"## For n = 50 \n",
"\n",
"Results are as follows :- \n",
"\n",
"Cost of travel, Euclidean = 117.30634693659576\n",
"Cost of travel, Euclidean - Greedy= 124.5160306576604\n",
"Cost of travel for asymmetric graph is = 117\n",
"Cost of travel for asymmetric graph Greedy= 71\n",
"Cost of travel for symmetric graph is = 87\n",
"Cost of travel for symmetric graph Greedy= 81\n",
"\n",
"## Images of graphs and plots \n",
"\n",
"\n",
"$$ Euclidean \\space graph $$\n",
"\n",
"![title](ACO/EcuGraphn50.png)\n",
"\n",
"$$ Euclidean \\space Plot $$\n",
" \n",
"![title](ACO/Eucpltn50.png)\n",
"\n",
"\n",
"$$ Asymmetric \\space graph $$\n",
"\n",
"![title](ACO/Asygraph50.png)\n",
"\n",
"$$ Asymmetric \\space Plot $$\n",
" \n",
"![title](ACO/Asyplt50.png)\n",
"\n",
"\n",
"$$ Symmetric \\space graph $$\n",
"\n",
"![title](ACO/symgraph50.png)\n",
"\n",
"$$ Symmetric \\space Plot $$\n",
" \n",
"![title](ACO/symplt50.png)\n",
"\n",
"$$ $$ \n",
"\n",
"## For n = 100\n",
"\n",
"Results are as follows :- \n",
"\n",
"Cost of travel, Euclidean = 178.95818153604972\n",
"Cost of travel, Euclidean - Greedy= 206.00052858467922\n",
"Cost of travel for asymmetric graph is = 182\n",
"Cost of travel for asymmetric graph Greedy= 120\n",
"Cost of travel for symmetric graph is = 211\n",
"Cost of travel for symmetric graph Greedy= 132\n",
"\n",
"\n",
"$$ Euclidean \\space graph $$\n",
"\n",
"![title](ACO/EcuGraphn100.png)\n",
"\n",
"$$ Euclidean \\space Plot $$\n",
" \n",
"![title](ACO/Eucplt100.png)\n",
"\n",
"\n",
"$$ Asymmetric \\space graph $$\n",
"\n",
"![title](ACO/Asygraph100.png)\n",
"\n",
"$$ Asymmetric \\space Plot $$\n",
" \n",
"![title](ACO/Asyplt100.png)\n",
"\n",
"\n",
"$$ symmetric \\space graph $$\n",
"\n",
"![title](ACO/symgraph100.png)\n",
"\n",
"$$ symmetric \\space Plot $$\n",
" \n",
"![title](ACO/symplt100.png)\n",
"\n",
"\n",
"$$ $$ \n",
"\n",
"## For n = 150\n",
"\n",
"Results are as follows :- \n",
"\n",
"Cost of travel, Euclidean = 178.95818153604972\n",
"Cost of travel, Euclidean - Greedy= 206.00052858467922\n",
"Cost of travel for asymmetric graph is = 182\n",
"Cost of travel for asymmetric graph Greedy= 120\n",
"Cost of travel for symmetric graph is = 211\n",
"Cost of travel for symmetric graph Greedy= 132\n",
"\n",
"\n",
"$$ Euclidean \\space graph $$\n",
"\n",
"![title](ACO/Asygraph150.png)\n",
"\n",
"$$ Euclidean \\space Plot $$\n",
" \n",
"![title](ACO/Eucplt150.png)\n",
"\n",
"\n",
"$$ Asymmetric \\space graph $$\n",
"\n",
"![title](ACO/ecu(asy)graph150.png)\n",
"\n",
"$$ Asymmetric \\space Plot $$\n",
" \n",
"![title](ACO/asyplot150.png)\n",
"\n",
"\n",
"$$ Symmetric \\space graph $$\n",
"\n",
"![title](ACO/symgraph150.png)\n",
"\n",
"$$ Symmetric \\space Plot $$\n",
" \n",
"![title](ACO/symplot150.png)\n",
"\n",
"\n",
"## For n = 200\n",
"Results are as follows :- \n",
"Cost of travel, Euclidean = 287.6057902102739\n",
"Cost of travel, Euclidean - Greedy= 301.31792232560036\n",
"Cost of travel for asymmetric graph is = 242\n",
"Cost of travel for asymmetric graph Greedy= 220\n",
"Cost of travel for symmetric graph is = 210\n",
"Cost of travel for symmetric graph Greedy= 221\n",
"\n",
"$$ Euclidean \\space graph $$\n",
"\n",
"![title](ACO/Ecugraph200.png)\n",
"\n",
"$$ Euclidean \\space Plot $$\n",
"\n",
"![title](ACO/ecuplt200.png)\n",
"\n",
"$$ Asymmetric \\space graph $$\n",
"\n",
"![title](ACO/Asygrf200.png)\n",
"\n",
"$$ Asymmetric \\space Plot $$\n",
" \n",
"![title](ACO/Asyplt200.png)\n",
"\n",
"\n",
"$$ Symmetric \\space graph $$\n",
"\n",
"![title](ACO/symgrf200.png)\n",
"\n",
"$$ Symmetric \\space Plot $$\n",
" \n",
"![title](ACO/symplt200.png)\n",
"\n",
"\n",
"## For n = 250\n",
"Results are as follows :- \n",
"Cost of travel, Euclidean = 280.671643559593\n",
"Cost of travel, Euclidean - Greedy= 307.56913052707324\n",
"Cost of travel for asymmetric graph is = 221\n",
"Cost of travel for asymmetric graph Greedy= 225\n",
"Cost of travel for symmetric graph is = 422\n",
"Cost of travel for symmetric graph Greedy= 225\n",
"\n",
"$$ Euclidean \\space graph $$\n",
"\n",
"![title](ACO/Ecugrf250.png)\n",
"\n",
"$$ Euclidean \\space Plot $$\n",
"\n",
"![title](ACO/ecuplt250.png)\n",
"\n",
"$$ Asymmetric \\space graph $$\n",
"\n",
"![title](ACO/Asygrf250.png)\n",
"\n",
"$$ Asymmetric \\space Plot $$\n",
" \n",
"![title](ACO/Asyplt250.png)\n",
"\n",
"\n",
"$$ Symmetric \\space graph $$\n",
"\n",
"![title](ACO/symgrf250.png)\n",
"\n",
"$$ Symmetric \\space Plot $$\n",
" \n",
"![title](ACO/symplt250.png)\n",
"\n"
]
},
{
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,81 @@
def top_down(arr, n):
memo = {}

# recursive top down memoized solution
def solve(i, j):
if i > j or i >= n or j < 0:
return 0

k = (i, j)
if k in memo:
return memo[k]

# if the user chooses ith number, the opponent can choose from i+1th or jth number.
# if he chooses i+1th number, user is left with [i+2,j] range.
# if opp chooses jth number, then user is left with [i+1,j-1] range to choose from.
# Also opponent tries to choose
# in such a way that the user has minimum value left.
option1 = arr[i] + min(solve(i+2, j), solve(i+1, j-1))

# if user chooses jth number, opponent can choose ith number or j-1th number.
# if opp chooses ith number,user can choose in range [i+1,j-1].
# if opp chooses j-1th number, user can choose in range [i,j-2].
option2 = arr[j] + min(solve(i+1, j-1), solve(i, j-2))

# since the user wants to get maximum money
memo[k] = max(option1, option2)
return memo[k]

return solve(0, n-1)

def bot_up(arr, n):

#Create a table to store
#solutions of subproblems
table = [[0 for i in range(n)]
for i in range(n)]

# Fill table using above recursive
# formula. Note that the table is
# filled in diagonal fashion
# from diagonal elements to
# table[0][n-1] which is the result.
for gap in range(n):
for j in range(gap, n):
i = j - gap

# Here x is value of F(i + 2, j),
# y is F(i + 1, j-1) and z is
# F(i, j-2) in above recursive
# formula
x = 0
if((i + 2) <= j):
x = table[i + 2][j]
y = 0
if((i + 1) <= (j - 1)):
y = table[i + 1][j - 1]
z = 0
if(i <= (j - 2)):
z = table[i][j - 2]
table[i][j] = max(arr[i] + min(x, y),
arr[j] + min(y, z))
return table[0][n - 1]



# Test Code
list1 = [5, 3, 7, 10]
n = len(list1)
print('Maximum Profit of P1 using Top Down approach = ', top_down(list1, n))

print('Maximum Profit of P1 using Bottom Up approach = ', bot_up(list1, n))

list2 = [8, 15, 3, 7]
n = len(list2)
print('Maximum Profit of P1 using Top Down approach = ',top_down(list2, n))
print('Maximum Profit of P1 using Bottom Up approach = ', bot_up(list2, n))

list3 = [20, 30, 2, 2, 2, 10]
n = len(list3)
print( 'Maximum Profit of P1 using Top Down approach = ',top_down(list3, n))
print('Maximum Profit of P1 using Bottom Up approach = ', bot_up(list3, n))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,38 @@
# Import all classes of PuLP module
from pulp import *

# Create the problem variable to contain the problem data
model = LpProblem("ToolsProblem", LpMaximize)

# Create 3 variables Steel, Molding_machine, and Assembly_machine

T1 = LpVariable("Tool1", 0, None, LpInteger)
T2 = LpVariable("Tool2", 0, None, LpInteger)
T3 = LpVariable("Tool3", 0, None, LpInteger)

# Create maximize objective function
model += 0.13 * T1 + 0.1 * T2 + 0.12 * T3

#Constraints:

model += 1*T1 + 0.7 * T2 + 0.6 * T3 <= 10000, "Steel"
model += 1*T1 + 1 * T2 + 1 * T3 <= 20000, "Molding_machine"
model += 0.3*T1 + 0.5 * T2 + 0.4 * T3 <= 9000, "Assembly_machine"

#Demand limits:

model += T1 <= 15000, "T1_DemandLimit"
model += T2 <= 16000, "T2_DemandLimit"
model += T3 <= 12000, "T3_DemandLimit"

model.solve()

for v in model.variables():
print(v.name, "=", v.varValue)

# print("T1 = ", T1.varValue)
# print("T2 = ", T2.varValue)
# print("T3 =" , T3.varValue)



Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,60 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
from sklearn.metrics import accuracy_score
import warnings

warnings.filterwarnings("ignore")

data1 = pd.read_csv('datasets/weather.numeric.csv')
data2 = pd.read_csv('datasets/weather.nominal.csv')


X= data1.drop(columns=['play'], axis=1)

y= data1['play']

X_train, X_test, y_train, y_test= train_test_split(X,y,test_size= 0.3)

d1tree= DecisionTreeClassifier()
d1tree.fit(X_train,y_train)
predictions= d1tree.predict(X_test)

tree.plot_tree(d1tree)
plt.show()

from sklearn.metrics import classification_report, confusion_matrix
print("Accuracy:",accuracy_score(y_test,predictions))

print(confusion_matrix(y_test,predictions))
print('\n')
print(classification_report(y_test,predictions))

from sklearn import preprocessing
string_to_int= preprocessing.LabelEncoder() #encode your data
data2=data2.apply(string_to_int.fit_transform) #fit and transform it

#To divide our data into attribute set and Label:
feature_cols = ['outlook','temperature','humidity','windy']
X = data2[feature_cols] #contains the attribute
y = data2.play #contains the label

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30)

d2tree =DecisionTreeClassifier(criterion="entropy", random_state=100) # create a classifier object
d2tree.fit(X_train, y_train)

y_pred= d2tree.predict(X_test)


print("Accuracy:",accuracy_score(y_test, y_pred))

print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))

tree.plot_tree(d2tree)
plt.show()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 28850df

Please sign in to comment.