人工智能prolog
㈠ 求助人工智能农夫过河问题的prolog语言程序
/*
PROBLEM:
A farmer with his goat, wolf and cabbage come to a river that they
wish to cross. There is a boat, but it only has room for two, and
the farmer is the only one that can row. If the goat and cabbage
get in the boat at the same time, the cabbage gets eaten.
Similarly, if the wolf and goat are together without the farmer,
the goat is eaten. Devise a series of crossings of the river so that all
concerned make it across safely.
The state of the system is indicated by stating where the farmer, the goat
the wolf and the cabbage are located.
state( Farmer, Wolf, Goat, Cabbage )
The problem is that a state must only be visited once, and some states
are illegal. This is checked by 'unsafe' and 'member'.
The Predicate "go" can be called with a start state and a final state
go( state(east,east,east,east), state(west,west,west,west) ).
*/
DOMAINS
LOC = east ; west
STATE = state(LOC,LOC,LOC,LOC)
PATH = STATE*
PREDICATES
go(STATE,STATE) /* Start of the algorithm */
path(STATE,STATE,PATH,PATH) /* Finds a path from one state to another */
move(STATE,STATE) /* Transfer a system from one side to another */
opposite(LOC,LOC) /* Gives a location on the opposite side */
unsafe(STATE) /* Gives the unsafe states */
member(STATE,PATH) /* Checks if the state is already visited */
write_path(PATH)
write_move(STATE,STATE)
show_move(STATE,STATE)
showside(LOC,LOC,string)
s_river
GOAL
makewindow(4,7,0,"",0,0,24,80),
makewindow(3,7,7," The River ",15,0,10,80),
makewindow(2,112,0,"",0,0,1,80),
write("press any key for each step of solution"),
makewindow(1,7,7," Solutions ",2,0,13,80),
show_move(state(west,west,west,west),state(west,west,west,west)),
go(state(east,east,east,east),state(west,west,west,west)),
write("solved press any key to continue"),
readchar(_),
exit.
CLAUSES
go(S,G):-
path(S,G,[S],L),
nl,write("A solution is:"),nl,
write_path(L),
fail.
go(_,_).
path(S,G,L,L1):- move(S,S1),
not( unsafe(S1) ),
not( member(S1,L) ),
path( S1,G,[S1|L],L1),!.
path(G,G,T,T):- !. /* The final state is reached */
move(state(X,X,G,C),state(Y,Y,G,C)):-opposite(X,Y). /* FARMER + WOLF */
move(state(X,W,X,C),state(Y,W,Y,C)):-opposite(X,Y). /* FARMER + GOAT */
move(state(X,W,G,X),state(Y,W,G,Y)):-opposite(X,Y). /* FARMER + CABBAGE */
move(state(X,W,G,C),state(Y,W,G,C)):-opposite(X,Y). /* ONLY FARMER */
opposite(east,west).
opposite(west,east):-!.
unsafe( state(F,X,X,_) ):- opposite(F,X). /* The wolf eats the goat */
unsafe( state(F,_,X,X) ):- opposite(F,X). /* The goat eats the cabbage */
member(X,[X|_]).
member(X,[_|L]):-member(X,L).
write_path( [H1,H2|T] ) :- !,
readchar(_),
write_move(H1,H2),
show_move(H1,H2),
write_path([H2|T]).
write_path( [] ).
write_move( state(X,W,G,C), state(Y,W,G,C) ) :-!,
write("The farmer crosses the river from ",X," to ",Y),nl.
write_move( state(X,X,G,C), state(Y,Y,G,C) ) :-!,
write("The farmer takes the Wolf from ",X," of the river to ",Y),nl.
write_move( state(X,W,X,C), state(Y,W,Y,C) ) :-!,
write("The farmer takes the Goat from ",X," of the river to ",Y),nl.
write_move( state(X,W,G,X), state(Y,W,G,Y) ) :-!,
write("The farmer takes the cabbage from ",X," of the river to ",Y),nl.
/* Show them move across the river.*/
show_move( state(F,W,G,C), state(F1,W1,G1,C1) ) :-!,
s_river,
showside(F,F1,"Farmer "),
showside(W,W1," Wolf "),
showside(G,G1," Goat "),
showside(C,C1,"Cabbage"),
shiftwindow(1).
showside(east,east,Item):-!,
write(" ~~~~~ ",Item),nl.
showside(west,west,Item):-!,
write(" ",Item," ~~~~~ "),nl.
showside(east,west,Item):-!,
write(" ",Item," <= <= <= ",Item),nl.
showside(west,east,Item):-!,
write(" ",Item," => => => ",Item),nl.
s_river:-
shiftwindow(3),clearwindow,
write(" WEST river EAST"),nl,
write(" ----------------------------------------------------------------------"),
nl.
㈡ 自学人工智能需要学那些专业知识
一、人工智能是一个综合学科,如楼上所说。而其本身又分为多个方面如神经网络、机器识别、机器视觉、机器人等。一个人想自学所有人工智能方面并不是很容易的一件事。对于你想知道人工智能在编程方面需要多深的要求。怎么说好呢无论C++还是汇编他都是一门语言主要会灵活运用。大多机器人仿真都用的混合编程模式,也就是运用多种编程软件及语言组合使用。之所以这样是为了弥补语言间的不足。prolog在逻辑演绎方面比突出。C++在硬件接口及windos衔接方面比较突出,MATLAB在数学模型计算方面比较突出。如果单学人工智能算法的话prolog足以,如果想开发机器仿真程序的话VC++ MATLAB应该多学习点。对于你想买什么书学习。我只能对我看过的书给你介绍一下,你再自己酌量一下。
1.人工智能算法方面:《人工智能及其应用》第三版、人工智能与知识工程。这两本感觉买一本就可以了。第一本感觉能简单并且全面点。这类书其实很多可是。大多内容都是重复的所以买一到两本即可。
2.机器视觉算法方面:《机器视觉算法与应用》这本书讲的大多都是工业化生产中机器视觉应用。从内容来说并不是很简单,建议不要当入门教材来学习。
3.机器人方面:新版《机器人技术手册》日译的书,可能这是我当初在当当网里找到唯一一本比较全面实用的机器人方面的书。这本书由基础到应用以及一些机器人实际问题上讲述得很全面。强烈建议买一本。
二、学习人工智能AI需要下列最基础的知识:
1.需要数学基础:高等数学,线性代数,概率论数理统计和随机过程,离散数学,数值分析。
2.需要算法的积累:人工神经网络,支持向量机,遗传算法等等算法;当然还有各个领域需要的算法,比如要让机器人自己在位置环境导航和建图就需要研究SLAM;总之算法很多需要时间的积累。
3.需要掌握至少一门编程语言,毕竟算法的实现还是要编程的;如果深入到硬件的话,一些电类基础课必不可少。
人工智能一般要到研究生才会去学,本科也就是蜻蜓点水看看而已,毕竟需要的基础课过于庞大。
㈢ prolog 编程 人工智能 两人游戏
VHDL,Verilog HDL,还有就是如果程序对时序要求不很严格的地方可以用system C,这个比硬件描述语言简单。硬件的内部结构,基本就不用考虑啦!不然怎叫做可编程逻辑器件呢!他的硬件和软件是分开的,也就使得设计人员从一开始就被个个具体的器件所限制,也即从顶层开始设计,这比传统的从底层开始设计好多了。所以说编的程序跟具体硬件内部结构没有很大的关系。 利用这个VHDL就可以在可编程逻辑器件上写上你的人工智能算法了。
㈣ 用Visual Prolog实现一个人工智能程序。问题如下。
看你是中法的告诉你吧,,,我是你玺哥
三个传教士和三个野人的示例程序如下:
move(1,0).
move(0,1).
move(0,2).
move(2,0).
move(1,1).
legal((X,Y,_)):-legal1(X),legal1(Y).
legal1((X,Y)):-X=:=0,Y>=0,!.
legal1((X,Y)):-Y=:=0,X>=0,!.
legal1((X,Y)):-X>=Y,X>=0,Y>=0.
update((X,Y,0),Move,Statu1):-
(A,B)=X,
(C,D)=Y,
(E,F)=Move,
C1 is C+E,
D1 is D+F,
A1 is A-E,
B1 is B-F,
Statu1=((A1,B1),(C1,D1),1).
update((X,Y,1),Move,Statu1):-
(A,B)=X,
(C,D)=Y,
(E,F)=Move,
C1 is C-E,
D1 is D-F,
A1 is A+E,
B1 is B+F,
Statu1=((A1,B1),(C1,D1),0).
connect(Statu,Statu1):-
move(X,Y),
update(Statu,(X,Y),Statu1),
legal(Statu1).
findroad(X,X,L,L):-write(L).
findroad(X,Y,L,L1):-
connect(X,Z),
not(member(Z,L)),
findroad(Z,Y,[Z|L],L1).
㈤ 人工智能语言的lisp和prolog
函数型语言LISP和逻辑型语言PROLOG都适合作符号处理,都适合于结构化程序设计(LISP提供了函数定义,版prolog提供了谓词定义),都具权有递归功能(prolog还具有自动回溯功能),都具有人机交互能力(prolog还特别适合于推理),也都具有把过程与说明式数据结构混合起来的能力以及辨别数据、确定控制的模式匹配机制(LISP将程序与数据均表示为表,因此可以把程序作为数据处理,也可将数据当作程序来执行。Prolog用一致的数据结构“项(term)”来构造数据和程序,事实、规则和询问的表现形式都为Horn子句,执行时作统一的操作匹配。LISP的匹配函数、prolog的合一运算自动匹配、自动搜索都具有很强的模式匹配机制。)因此可以说LISP和prolog是两种较为典型的人工智能语言。
㈥ prolog nim 编程 AI 人工智能 两人游戏
lisp一定要学,对于coder来说,这完全是一种新的境界。会让你上升到另外的层次的。prolog没有使用过,不予评价。
㈦ 人工智能PROLOG语言与VB语言有什么差异
1.vp是Visual Pascal的简称,具体指Pascal语言,pascal是一种高级程序设计语言,语言比较严密,适合教学,目前的信内息学容奥林匹克竞赛大多采用pascal语言。
2.不是。 Visual FoxPro简称VFP。是,VFP是由FoxPro发展而来,并且根据“可视化编程”的需要,增加了一些新的操作。现在说的都是指vfp。
㈧ 人工智能导论prolog编程题目
随便从网上找的一个family tree
--------------------------------------------------
%FamilyMembers
male(tom).
male(john).
male(adam).
male(nike).
male(bob).
female(alisa).
female(abby).
female(anne).
female(alice).
female(betty).
female(carry).
female(chris).
%
mother(alisa,alice).
mother(alisa,anne).
mother(alice,carry).
mother(abby,adam).
mother(abby,betty).
mother(betty,chris).
mother(betty,bob).
%
father(tom,anne).
father(tom,alice).
father(john,adam).
father(john,betty).
father(nike,chris).
father(nike,bob).
father(adam,carry).
%%%%%%%%%%%%%%%%%%%%%%
%Parent:afatherormother
parent(A,B):-
(
(A,B);
mother(A,B)
).
%Child:ahumanoffspring(sonordaughter)ofanyage
child(A,B):-
parent(B,A).
%Daughter:afemalehumanoffspring
daughter(A,B):-
female(A),
child(A,B).
%Son:amalehumanoffspring
son(A,B):-
male(A),
child(A,B).
%Sibling:aperson'sbrotherorsister
sibling(A,B):-
parent(C,A),
parent(C,B),
A=B.
%Sister:
%asanotherperson
sister(A,B):-
sibling(A,B),
female(A).
%Brother:
brother(A,B):-
sibling(A,B),
male(A).
%%%%%%%%%%%%%%%%%%%%%%%%
%Aunt:thesisterofyourfatherormother
aunt(A,B):-
parent(C,B),
sister(A,C).
%Uncle:
uncle(A,B):-
parent(C,B),
brother(A,C).
%Cousin:thechildofyourauntoruncle
cousin(A,B):-
parent(C,B),
sibling(D,C),
child(A,D).
%%%%%%%%%%%%%%%%%%%%%%%%
%Grandparent:aparentofyourfatherormother
grandparent(A,B):-
parent(A,C),
parent(C,B).
%Grandfather:thefatherofyourfatherormother
grandfather(A,B):-
male(A),
grandparent(A,B).
%Grandmother:themotherofyourfatherormother
grandmother(A,B):-
female(A),
grandparent(A,B).
%Grandchild:achildofyoursonordaughter
grandchild(A,B):-
grandparent(B,A).
%Grandson:amalegrandchild
grandson(A,B):-
male(A),
grandchild(A,B).
%Granddaughter:afemalegrandchild
grandson(A,B):-
female(A),
grandchild(A,B).
------------------------------------------------------