![人工智能实验室手册 使用Python的人工智能实验室_第1页](http://file4.renrendoc.com/view12/M07/04/12/wKhkGWYbS5yAe74xAAEOJrqEVa0064.jpg)
![人工智能实验室手册 使用Python的人工智能实验室_第2页](http://file4.renrendoc.com/view12/M07/04/12/wKhkGWYbS5yAe74xAAEOJrqEVa00642.jpg)
![人工智能实验室手册 使用Python的人工智能实验室_第3页](http://file4.renrendoc.com/view12/M07/04/12/wKhkGWYbS5yAe74xAAEOJrqEVa00643.jpg)
![人工智能实验室手册 使用Python的人工智能实验室_第4页](http://file4.renrendoc.com/view12/M07/04/12/wKhkGWYbS5yAe74xAAEOJrqEVa00644.jpg)
![人工智能实验室手册 使用Python的人工智能实验室_第5页](http://file4.renrendoc.com/view12/M07/04/12/wKhkGWYbS5yAe74xAAEOJrqEVa00645.jpg)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030全球高架轨道秤行业调研及趋势分析报告
- 2025打工人发财游园年会(打工人发财年会主题)活动策划方案
- 建筑节能的规划与实施策略
- 健身休闲行业服务交易合同范文
- 会计劳动合同模板
- 掌握数据分析的关键技能
- 石材幕墙施工合同范本
- 买卖合同原告代理词
- 2025个人与个人合作协议合同
- 2025禽蛋类购买合同样本
- 《性激素临床应用》课件
- 眼科疾病与视觉健康
- 2024年九省联考高考数学卷试题真题答案详解(精校打印)
- 洗涤塔操作说明
- 绘本分享《狐狸打猎人》
- 撤销因私出国(境)登记备案国家工作人员通知书
- (39)-总论第四节针灸处方
- 《民航服务沟通技巧》教案第10课儿童旅客服务沟通
- WTC瓦斯突出参数仪操作规程
- 运营维管段安全保护区环境管理实施细则(试行)
- 2022年云上贵州大数据(集团)有限公司招聘笔试试题及答案解析
评论
0/150
提交评论