版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
AILABMANUAL
ArtificialIntelligenceLabUsingPython(LC-CSE-326G)
DEPARTMENTOFCOMPUTERSCIENCE&ENGINEERING
ChecklistforLabManual
S.No.
Particulars
1
MissionandVision
2
CourseOutcomes
3
Guidelinesforthestudent
4
ListofProgramsasperUniversity
5
SamplecopyofFile
DepartmentofComputerScience&Engineering
VisionandMissionoftheDepartmentVision
TobeaModelinQualityEducationforproducinghighlytalentedandgloballyrecognizablestudentswithsoundethics,latestknowledge,andinnovativeideasinComputerScience&Engineering.
MISSION
TobeaModelinQualityEducationby
M1:Impartinggoodsoundtheoreticalbasisandwide-rangingpracticalexperiencetotheStudentsforfulfillingtheupcomingneedsoftheSocietyinthevariousfieldsofComputerScience&Engineering.
M2:OfferingtheStudentsanoverallbackgroundsuitableformakingaSuccessfulcareerinIndustry/Research/HigherEducationinIndiaandabroad.
M3:ProvidingopportunitytotheStudentsforLearningbeyondCurriculumandimprovingCommunicationSkills.
M4:EngagingStudentsinLearning,UnderstandingandApplyingNovelIdeas.
Course:ArtificialIntelligenceLabusingPythonCourseCode:LC-CSE-326G
CO(CourseOutcomes)
RBT*-RevisedBloom’s
Taxonomy
CO1
ToUseControlStructuresandOperatorstowritebasicPythonprogramming.
L3
(Apply)
CO2
ToAnalyzeobject-orientedconceptsinPython.
L4
(Analyze)
CO3
ToEvaluatetheAImodelspre-processedthroughvariousfeature
engineeringalgorithmsbyPythonProgramming.
L5
(Evaluate)
CO4
ToDevelopthecodefortherecommendersystemusingNatural
Languageprocessing.
L6
(Create)
CO5
ToDesignvariousreinforcementalgorithmstosolvereal-timecomplex
problems.
L6
(Create)
COPO-PSOArticulationMatrices
Course
Outcomes(COs)
(POs)
PSOs
PO1
PO2
PO3
PO4
PO5
PO6
PO7
PO8
PO9
PO10
PO11
PO12
PSO1
PSO2
CO1
3
2
1
3
2
CO2
2
2
3
2
1
2
2
CO3
2
3
2
2
1
2
2
CO4
2
2
2
3
2
1
1
2
CO5
2
2
2
3
2
1
2
1
GuidelinesfortheStudents:
Studentsshouldberegularandcomepreparedforthelabpractice.
Incaseastudentmissesaclass,itishis/herresponsibilitytocompletethatmissedexperiment(s).
Studentsshouldbringtheobservationbook,labjournalandlabmanual.Prescribedtextbookandclassnotescanbekeptreadyforreferenceifrequired.
TheyshouldimplementthegivenProgramindividually.
Whileconductingtheexperimentsstudentsshouldseethattheirprogramswouldmeetthefollowingcriteria:
Programsshouldbeinteractivewithappropriatepromptmessages,errormessagesifany,anddescriptivemessagesforoutputs.
Programsshouldperforminputvalidation(Datatype,rangeerror,etc.)andgiveappropriateerrormessagesandsuggestcorrectiveactions.
Commentsshouldbeusedtogivethestatementoftheproblemandevery
functionshouldindicatethepurposeofthefunction,inputsandoutputs
Statementswithintheprogramshouldbeproperlyindented
Usemeaningfulnamesforvariablesandfunctions.
MakeuseofConstantsandtypedefinitionswhereverneeded.
Oncetheexperiment(s)getexecuted,theyshouldshowtheprogramandresultstotheinstructorsandcopythesameintheirobservationbook.
Questionsforlabtestsandexamneednotnecessarilybelimitedtothequestionsinthemanual,butcouldinvolvesomevariationsand/orcombinationsofthequestions.
ListofExperiments:
WriteaProgramtoImplementBreadthFirstSearchusingPython.
WriteaProgramtoImplementDepthFirstSearchusingPython.
WriteaProgramtoImplementTic-Tac-ToegameusingPython.
WriteaProgramtoImplement8-PuzzleproblemusingPython.
WriteaProgramtoImplementWater-JugproblemusingPython.
Write a Program to Implement Travelling SalesmanProblemusingPython.
WriteaProgramtoImplementTowerofHanoiusingPython.
WriteaProgramtoImplementMonkeyBananaProblemusingPython.
WriteaProgramtoImplementAlpha-BetaPruningusingPython.
WriteaProgramtoImplement8-QueensProblemusingPython.
EXPERIMENT1
#WriteaProgramtoImplementBreadthFirstSearchusingPython.
graph={
'A':['B','C'],
'B':['D','E'],
'C':['F'],
'D':[],
'E':['F'],'F':[]
}
visited=[]#Listtokeeptrackofvisitednodes.queue=[] #Initializeaqueue
defbfs(visited,graph,node):
visited.append(node)queue.append(node)
whilequeue:
s=queue.pop(0)print(s,end="")
forneighbouringraph[s]:ifneighbournotinvisited:
visited.append(neighbour)queue.append(neighbour)
#DriverCodebfs(visited,graph,'A')
Output:-
ABCDEF
EXPERIMENT2
#WriteaProgramtoImplementDepthFirstSearchusingPython.
#UsingaPythondictionarytoactasanadjacencylistgraph={
'A':['B','C'],
'B':['D','E'],
'C':['F'],
'D':[],
'E':['F'],'F':[]
}
visited=set()#Settokeeptrackofvisitednodes.
defdfs(visited,graph,node):ifnodenotinvisited:
print(node)visited.add(node)
forneighbouringraph[node]:dfs(visited,graph,neighbour)
#DriverCodedfs(visited,graph,'A')
Output:-
ABDEFC
EXPERIMENT3
#WriteaProgramtoImplementTic-Tac-ToegameusingPython.
#Tic-Tac-ToeProgramusing#randomnumberinPython
#importingallnecessarylibrariesimportnumpyasnp
importrandom
fromtimeimportsleep
#Createsanemptyboarddefcreate_board():
return(np.array([[0,0,0],
[0,0,0],
[0,0,0]]))
#Checkforemptyplacesonboarddefpossibilities(board):
l=[]
foriinrange(len(board)):
forjinrange(len(board)):
ifboard[i][j]==0:
l.append((i,j))
return(l)
#Selectarandomplacefortheplayerdefrandom_place(board,player):
selection=possibilities(board)current_loc=random.choice(selection)board[current_loc]=playerreturn(board)
#Checkswhethertheplayerhasthree#oftheirmarksinahorizontalrowdefrow_win(board,player):
forxinrange(len(board)):win=True
foryinrange(len(board)):
ifboard[x,y]!=player:win=Falsecontinue
ifwin==True:
return(win)
return(win)
#Checkswhethertheplayerhasthree#oftheirmarksinaverticalrow
defcol_win(board,player):
forxinrange(len(board)):win=True
foryinrange(len(board)):
ifboard[y][x]!=player:win=Falsecontinue
ifwin==True:
return(win)
return(win)
#Checkswhethertheplayerhasthree#oftheirmarksinadiagonalrow
defdiag_win(board,player):win=True
y=0
forxinrange(len(board)):
ifboard[x,x]!=player:win=False
ifwin:
returnwin
win=Trueifwin:
forxinrange(len(board)):y=len(board)-1-x
ifboard[x,y]!=player:win=False
returnwin
#Evaluateswhetherthereis#awinneroratie
defevaluate(board):
winner=0
forplayerin[1,2]:
if(row_win(board,player)or
col_win(board,player)ordiag_win(board,player)):
winner=player
ifnp.all(board!=0)andwinner==0:winner=-1
returnwinner
#Mainfunctiontostartthegamedefplay_game():
board,winner,counter=create_board(),0,1print(board)
sleep(2)
whilewinner==0:
forplayerin[1,2]:
board=random_place(board,player)print("Boardafter"+str(counter)+"move")print(board)
sleep(2)counter+=1
winner=evaluate(board)ifwinner!=0:
break
return(winner)
#DriverCode
print("Winneris:"+str(play_game()))
Output:-
[[0
0
0]
[0
0
0]
[0
0
0]]
Boardafter1move
[[0
0
0]
[0
0
0]
[1
0
0]]
Boardafter2move
[[0
0
0]
[0
2
0]
[1
0
0]]
Boardafter3move
[[0
1
0]
[0
2
0]
[1
0
0]]
Boardafter4move
[[0
1
0]
[2
2
0]
[1
0
0]]
Boardafter5move
[[1
1
0]
[2
2
0]
[1
0
0]]
Boardafter6move
[[1
1
0]
[2
2
0]
[1
2
0]]
Boardafter7move
[[1
1
0]
[2
2
0]
[1
2
1]]
Boardafter8move[[110]
[222]
[121]]
Winneris:2
EXPERIMENT4
#WriteaProgramtoImplement8-PuzzleproblemusingPython.
classSolution:
defsolve(self,board):
dict={}
flatten=[]
foriinrange(len(board)):
flatten+=board[i]
flatten=tuple(flatten)
dict[flatten]=0
ifflatten==(0,1,2,3,4,5,6,7,8):
return0
returnself.get_paths(dict)
defget_paths(self,dict):
cnt=0
whileTrue:
current_nodes=[xforxindictifdict[x]==cnt]
iflen(current_nodes)==0:
return-1
fornodeincurrent_nodes:
next_moves=self.find_next(node)
formoveinnext_moves:
ifmovenotindict:
dict[move]=cnt+1
ifmove==(0,1,2,3,4,5,6,7,8):
returncnt+1
cnt+=1
deffind_next(self,node):
moves={
0:[1,3],
1:[0,2,4],
2:[1,5],
3:[0,4,6],
4:[1,3,5,7],
5:[2,4,8],
6:[3,7],
7:[4,6,8],
8:[5,7],
}
results=[]
pos_0=node.index(0)
formoveinmoves[pos_0]:
new_node=list(node)
new_node[move],new_node[pos_0]=new_node[pos_0],new_node[move]
results.append(tuple(new_node))
returnresults
ob=Solution()
matrix=[
[3,1,2],
[4,7,5],
[6,8,0]
]
print(ob.solve(matrix))
Output:-
4
EXPERIMENT5
##WriteaProgramtoImplementWater-JugproblemusingPython.
#Thisfunctionisusedtoinitializethe
#dictionaryelementswithadefaultvalue.fromcollectionsimportdefaultdict
#jug1andjug2containthevaluejug1,jug2,aim=4,3,2
#Initializedictionarywith#defaultvalueasfalse.
visited=defaultdict(lambda:False)defwaterJugSolver(amt1,amt2):
.
if(amt1==aimandamt2==0)or(amt2==aimandamt1==0):
print(amt1,amt2)returnTrue
ifvisited[(amt1,amt2)]==False:print(amt1,amt2)
visited[(amt1,amt2)]=Truereturn(waterJugSolver(0,amt2)or
waterJugSolver(amt1,0)orwaterJugSolver(jug1,amt2)orwaterJugSolver(amt1,jug2)orwaterJugSolver(amt1+min(amt2,(jug1-amt1)),amt2-min(amt2,(jug1-amt1)))orwaterJugSolver(amt1-min(amt1,(jug2-amt2)),amt2+min(amt1,(jug2-amt2))))
else:
returnFalse
print("Steps:")waterJugSolver(0,0)
Output:-
Steps:
0
0
4
0
4
3
0
3
3
0
3
3
42
02
EXPERIMENT6
#WriteaProgramtoImplementTravellingSalesmanProblemusingPython.
#Python3implementationoftheapproachV=4
answer=[]
#Functiontofindtheminimumweight#HamiltonianCycle
deftsp(graph,v,currPos,n,count,cost):
#Iflastnodeisreachedandithas#alinktothestartingnodei.e
#thesourcethenkeeptheminimum#valueoutofthetotalcostof
#traversaland"ans"
#Finallyreturntocheckfor#morepossiblevalues
if(count==nandgraph[currPos][0]):answer.append(cost+graph[currPos][0])return
#BACKTRACKINGSTEP
#Looptotraversetheadjacencylist
#ofcurrPosnodeandincreasingthecount#by1andcostbygraph[currPos][i]valueforiinrange(n):
if(v[i]==Falseandgraph[currPos][i]):
#Markasvisitedv[i]=True
tsp(graph,v,i,n,count+1,cost+graph[currPos][i])
#Markithnodeasunvisitedv[i]=False
#Drivercode
#nisthenumberofnodesi.e.Vif name ==' main ':
n=4
graph=[[0,10,15,20],
[10,0,35,25],
[15,35,0,30],
[20,25,30,0]]
#Booleanarraytocheckifanode#hasbeenvisitedornot
v=[Falseforiinrange(n)]
#Mark0thnodeasvisitedv[0]=True
#FindtheminimumweightHamiltonianCycletsp(graph,v,0,n,1,0)
#ansistheminimumweightHamiltonianCycleprint(min(answer))
Output:-
80
EXPERIMENT7
#WriteaProgramtoImplementTowerofHanoiusingPython.
#RecursivePythonfunctiontosolvethetowerofhanoidefTowerOfHanoi(n,source,destination,auxiliary):
ifn==1:
print"Movedisk1fromsource",source,"todestination",destinationreturn
TowerOfHanoi(n-1,source,auxiliary,destination)
print"Movedisk",n,"fromsource",source,"todestination",destinationTowerOfHanoi(n-1,auxiliary,destination,source)
#Drivercoden=4
TowerOfHanoi(n,'A','B','C')
#A,C,Barethenameofrods
Output:-
Move
disk
1
from
rod
A
to
rod
B
Move
disk
2
from
rod
A
to
rod
C
Move
disk
1
from
rod
B
to
rod
C
Move
disk
3
from
rod
A
to
rod
B
Move
disk
1
from
rod
C
to
rod
A
Move
disk
2
from
rod
C
to
rod
B
Move
disk
1
from
rod
A
to
rod
B
Move
disk
4
from
rod
A
to
rod
C
Move
disk
1
from
rod
B
to
rod
C
Move
disk
2
from
rod
B
to
rod
A
Move
disk
1
from
rod
C
to
rod
A
Move
disk
3
from
rod
B
to
rod
C
Move
disk
1
from
rod
A
to
rod
B
Move
disk
2
from
rod
A
to
rod
C
Move
disk
1
from
rod
B
to
rod
C
EXPERIMENT8
#WriteaProgramtoImplementMonkeyBananaProblemusingPython.
'''
Pythonprogrammingimplementationofmonkeypickingbananaproblem'''
#GlobalVariableii=0
defMonkey_go_box(x,y):globali
i=i+1
print('step:',i,'monkeyslave',x,'Goto'+y)
defMonkey_move_box(x,y):globali
i=i+1
print('step:',i,'monkeytaketheboxfrom',x,'deliverto'+y)
defMonkey_on_box():globali
i=i+1
print('step:',i,'Monkeyclimbsupthebox')
defMonkey_get_banana():globali
i=i+1
print('step:',i,'Monkeypickedabanana')
importsys
#Readtheinputoperatingparameters,codeIn=sys.stdin.read()codeInList=codeIn.split()
#Theoperatingparametersindicatethelocationsofmonkey,banana,andboxrespectively.
monkey=codeInList[0]banana=codeInList[1]box=codeInList[2]
print('Thestepsareasfollows:')
#PleaseusetheleaststepstocompletethemonkeypickingbananataskMonkey_go_box(monkey,box)
Monkey_move_box(box,banana)Monkey_on_box()Monkey_get_banana()
EXPERIMENT9
#WriteaProgramtoImplementAlpha-BetaPruningusingPython.
#workingofAlpha-BetaPruning
#InitialvaluesofAplhaandBetaMAX,MIN=1000,-1000
#Returnsoptimalvalueforcurrentplayer#(Initiallycalledforrootandmaximizer)
defminimax(depth,nodeIndex,maximizingPlayer,
values,alpha,beta):
#Terminatingcondition.i.e#leafnodeisreached
ifdepth==3:
returnvalues[nodeIndex]ifmaximizingPlayer:
best=MIN
#Recurforleftandrightchildrenforiinrange(0,2):
val=minimax(depth+1,nodeIndex*2+i,
False,values,alpha,beta)best=max(best,val)
alpha=max(alpha,best)
#AlphaBetaPruningifbeta<=alpha:
break
returnbest
else:
best=MAX
#Recurforleftand#rightchildren
foriinrange(0,2):
val=minimax(depth+
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年國際私人民間貿(mào)易協(xié)議樣式
- 2024年期企業(yè)互保反擔(dān)保協(xié)議樣本
- 2024年企業(yè)勞動(dòng)協(xié)議范本要點(diǎn)
- 2024廣告影片拍攝場(chǎng)地使用協(xié)議
- DB11∕T 1570-2018 甜瓜設(shè)施栽培技術(shù)規(guī)程
- 2024年鋼材供應(yīng)協(xié)議鋼筋條款詳本
- 2024年適用場(chǎng)地租賃協(xié)議模板
- 不銹鋼欄桿建設(shè)施工服務(wù)協(xié)議2024
- 2024年定制銷售受托管理協(xié)議
- 2024年度特定物資委托采購合作協(xié)議
- 化妝品半成品成品檢驗(yàn)規(guī)程
- 電大中級(jí)財(cái)務(wù)會(huì)計(jì)二形成性考核冊(cè)
- 宮之奇諫假道(課堂PPT)
- 公司員工晉升管理辦法(草案)
- 英語介紹微信PPT課件
- 入戶門技術(shù)標(biāo)準(zhǔn)要求
- 關(guān)于銀行信息科技工作的幾點(diǎn)思考
- 單腳起跳、雙腳落地
- 毛竹腳手架施工方案
- 中南大學(xué)學(xué)位證書樣本掃描件WORD
- 多重中介模型及其應(yīng)用
評(píng)論
0/150
提交評(píng)論