This a GA implementation using binary and real coded variables. Mixed variables can be used. Constraints can also be handled. All constraints must be greater-than-equal-to type (g >= 0) and normalized (see the sample problem in prob1 in objective()).
此為編譯原理實驗報告 學習消除文法左遞規算法,了解消除文法左遞規在語法分析中的作用 內含 設計算法 目的 源碼 等等.... 算法:消除左遞歸算法為: (1)把文法G的所有非終結符按任一種順序排列成P1,P2,…Pn 按此順序執行 (2)FOR i:=1 TO n DO BEGIN FOR j:=1 DO 把形如Pi→Pjγ的規則改寫成 Pi→δ1γ δ2γ … δkγ。其中Pj→δ1 δ2 … δk是關于Pj的所有規則; 消除關于Pi規則的直接左遞歸性 END (3)化簡由(2)所得的文法。即去除那些從開始符號出發永遠無法到達的非終結符的 產生規則。
prolog 找路例子程序:
=== === === === === ===
Part 1-Adding connections
Part 2-Simple Path
example
| ?- path1(a,b,P,T).
will produce the response:
T = 15
P = [a,b] ?
Part 3 - Non-repeating path
As an example, the query:
?- path2(a,h,P,T).
will succeed and may produce the bindings:
P = [a,depot,b,d,e,f,h]
T = 155
Part 4 - Generating a path below a cost threshold
As an example, the query:
?- path_below_cost(a,[a,b,c,d,e,f,g,h],RS,300).
returns:
RS = [a,b,depot,c,d,e,g,f,h] ?
RS = [a,c,depot,b,d,e,g,f,h] ?
no
==================================