2013-10-29 3 views
1

나는 오일러 경로를 풀기 위해 Clingo에서 프로그램을 만들려고합니다. 지금까지 이것이 내가 생각해내는 것입니다. 그래프를 다음과 같이 표시하고 싶습니다. Graphical Representation 내 입력.Clingo의 그래프로 예기치 않은 결과가 발생했습니다.

edge(a,b). 
    edge(b,c). 
    edge(c,d). 
    edge(d,e). 
    edge(a,d). 
    edge(b,d). 
    %edge(x,y):-edge(y,x). 
    num(1..6). 

지금까지 내 프로그램.

%Generates paths with X and Ys equal to edges in the input, N can be in the range of 'num' 
    1{path(X,Y,N):edge(X,Y)}1:-num(N). 

    %Next edges Y and X1 are the same/connect. Where N is in the range of indices. 
    :-path(X,Y,N), path(X1,Y1,N+1), Y!=X1, num(N). 

내 프로그램에서 내 의견에 잘못 되었나요? 나는 프로그램이 항상 가장자리를 연결해야한다고 생각한다. 지금 당장은 대답을 얻지 못했습니다. 그러나 단계 수 "num"이 1..4에 이르면 해결책이 생깁니다. 나는 오일러 경로가 6 단계를 가져야한다고 믿지만 가능한 해결책은 다음과 같습니다.

path(b,d,1) 
path(d,a,2) 
path(a,b,3) 
path(b,c,4) 
path(c,d,5) 
path(d,e,6) 

답변

1

알아 냈어!

다음은 입력 파일입니다.

edge(a,b). 
    edge(b,c). 
    edge(c,d). 
    edge(d,e). 
    edge(a,d). 
    edge(b,d). 
    edge(X,Y):-edge(Y,X). 
    num(1..6). 

출력 파일. 내 컴퓨터에서 다음과 같이 출력을 생성

1{path(X,Y,N):edge(X,Y)}1:-num(N). 

    %Next edges Y and X1 are the same/connect. Where N is in the range of indices. 
    :-path(X,Y,N), path(X1,Y1,N+1), Y!=X1, num(N). 

    %Accept no duplicate paths 
    :-path(X,Y,N), path(X1,Y1,N2), Y==Y1, X==X1, num(N), num(N2), N!=N2. 
    :-path(X,Y,N), path(X1,Y1,N2), Y==X1, X==Y1, num(N), num(N2), N!=N2. 

    #hide. 
    #show path/3. 

(읽기 쉽도록 반전) :

path(e,d,1) 
    path(d,b,2) 
    path(b,c,3) 
    path(c,d,4) 
    path(d,a,5) 
    path(a,b,6) 
관련 문제