Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use diagnostics;
- use Benchmark;
- use AI::Prolog;
- use Language::Prolog::Yaswi qw(:load :query);
- use Language::Prolog::Sugar
- vars => [qw(X Z)],
- functors => {travelFromTo => 'travelFromTo'};
- my $database = <<'END_PROLOG';
- directTrain(saarbruecken,dudweiler).
- directTrain(forbach,saarbruecken).
- directTrain(freyming,forbach).
- directTrain(stAvold,freyming).
- directTrain(fahlquemont,stAvold).
- directTrain(metz,fahlquemont).
- directTrain(nancy,metz).
- travelFromTo(X,Y) :- directTrain(X,Y).
- travelFromTo(X,Z) :-
- directTrain(X,Y),
- travelFromTo(Y,Z).
- END_PROLOG
- swi_inline <<"EOP";
- $database
- EOP
- sub by_yaswi {
- swi_set_query(travelFromTo(X, Z));
- while (swi_next) {
- swi_vars(X), swi_vars(Z);
- }
- return;
- }
- my $prolog = AI::Prolog->new($database);
- sub by_ai_prolog {
- $prolog->query("travelFromTo(X,Z).");
- while (my $result = $prolog->results) {
- my @results = @{$result}[1..2];
- }
- return;
- }
- timethese(1000, {
- "by yaswi" => 'by_yaswi()',
- "by ai prolog" => "by_ai_prolog()",
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement