人工智慧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).
------------------------------------------------------