image

  • フォト Amazonギフト券
    ※この時計の時刻は、閲覧しているパソコンのものであり、必ずしも正確な時間とは限りません

検索

最近のトラックバック

無料ブログはココログ

« 2007-11-30 | トップページ | 2007-12-03 »

2007-12-02

2007-12-02

swi-prolog から graphviz を利用(その2)

Mazepath

- http://karel.tsuda.ac.jp/lec/prolog/intro3/
> > Prolog入門(3)
のページに "グラフの経路探索" というサンプルを見つけた。

経路結果を graphviz で表示させるようにしてみた。

$ cat maze.pl

% See http://karel.tsuda.ac.jp/lec/prolog/intro3/

/*
      a--b--c
      |  |  |
   d--e--f--+
   |     |
   g-----h
*/
connected(a,b).
connected(a,e).
connected(b,c).
connected(b,f).
connected(c,f).
connected(d,e).
connected(d,g).
connected(e,f).
connected(f,h).
connected(g,h).

can_go(X,Y) :- connected(X,Y).
can_go(X,Y) :- connected(Y,X).

go(X,X,Memo,[X|Memo]).
go(X,Y,Memo,Ans) :- can_go(X,Z), not(member(Z,Memo)), go(Z,Y,[X|Memo],Ans), genSVG(Ans).

% find solve.
% go(a,h,[],P).

% ----------------------
% Draw maze.
% ----------------------
genSVG(P) :- genDot(P), shell('dot -Tsvg temp.dot -o temp.svg', _Status).

genDot(P) :-
    tell('temp.dot'),
    writeln('graph sample {'),
    writePath(P),
    forall((connected(X,Y), concat_atom([X,Y],' -- ', W)), writeNode(W)),
    writeln('}'),
    told.

writePath([]) :- nl, !.
writePath([H|R]) :- write(H), write(' [color=red];'), nl, writePath(R).

writeNode(N) :- write(N), write(';'), nl.

検索を実行すると temp.dot, temp.xvg を生成する。

$ cat temp.dot
graph sample {
h [color=red];
f [color=red];
c [color=red];
b [color=red];
a [color=red];

a -- b;
a -- e;
b -- c;
b -- f;
c -- f;
d -- e;
d -- g;
e -- f;
f -- h;
g -- h;
}

google.co.jp での "xfy” 検索 100 位の圏外へ

ここの blog での"xfy" での検索についてである。
yahoo.co.jp で、半年前から 100 位圏外になってしまっていたが、
ここ数日で、google.co.jpでも、100位以内にはあらわれなくなった...

Amazonギフト券

swi-prolog から graphviz を利用

prolog で得た実行結果をグラフィカルに示す方法の実験をしてみた。
prolog から graphviz を呼び出して、svg ファイルを生成。
(ぜんぜん prolog らしくないアプローチだけど。
グラフ生成は graphviz という専門プログラムの任せるのが簡単だし).

$ cat link.pl
link(a,b).
link(a,c).
link(b,d).
link(c,d).
link(d,a).

draw:-
    tell('temp.dot'),
    writeln('digraph sample {'),
    forall((link(X,Y), concat_atom([X,Y],' -> ', W)), writeln(W)),
    writeln('}'),
    told.

genSVG :- draw, shell('dot -Tsvg temp.dot -o temp.svg', _Status).


$ swipl
Welcome to SWI-Prolog (Multi-threaded, Version 5.6.47)
Copyright (c) 1990-2007 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [link].
% link compiled 0.01 sec, 1,844 bytes

Yes
?- genSVG.

(process:734): Pango-WARNING **: Error loading GDEF table 85

(process:734): Pango-WARNING **: Error loading GSUB table 85

(process:734): Pango-WARNING **: Error loading GPOS table 85

Yes
?-

temp.dot, temp.svg が生成される。
temp.svg を firefox で表示させると、こんなふうになる。

Linkprolog

同じ事を erlang でもやってみつもりだ。(erlang の説明書籍を買ったし)

« 2007-11-30 | トップページ | 2007-12-03 »

mokuji

2013年12月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

google

  • twitter
  • __
  • _
    Googleボットチェッカー

合わせて読む

  • 合わせて読む
    フィードメーター - katoy: cocolog あわせて読みたい

リンク