Using (nb_)setarg/3 with gnu.prolog in Java -


i'm trying use prolog out of java using gnu.prolog (http://www.gnu.org/software/gnuprologjava/).

thanks great of capellic have prolog program works perfect purpose. problem gnu.prolog not support reverse/2 nor support nb_setarg/3. java throw error:

exception in thread "game" java.lang.illegalargumentexception: goal not active 

it isn't big issue implement reverse/2 on own have no idea how replace nb_setarg/3 (setarg/3 doesn't work)

here prolog code:

findpath(_limit, [goal | rest], goal, temp, temp, [goal | rest]) :- !.  findpath(limit, [a | rest], goal, cost, temp, path) :-     path(a,b,c),     \+member(b, rest),     newcosts (temp + c),     newcosts < limit,     findpath(limit, [b, | rest], goal, cost, newcosts, path).  searchpath(start, goal, path_to_goal) :-     s = path_len([], 50),     repeat,     arg(2, s, limit),     (   findpath(limit, [start], goal, cost, 0, path)     ->  (   cost < limit         ->  nb_setarg(1, s, path),         nb_setarg(2, s, cost),         fail         )     ;   true     ),     arg(1, s, rev),     reverse(rev, path_to_goal). 

i tried use jpl swi prolog wasn't able run because of severel exceptions pointing out, eclipse wasn't able find library correctly. 1 of following exceptions:

exception in thread "main" java.lang.unsatisfiedlinkerror: no jpl in java.library.path   unsatisfiedlinkerror: d:\program files\prolog\bin\jpl.dll: can't find dependent libraries  swi-prolog: [fatal error:     not find system resources] 

even after following this , this guide wasn't able resolve problems. neither on windows (32bit) nor on ubuntu (64bit).

do have solutions me how can either jpl running or how able use nb_setarg/3? spent 1 , half days without results. quite frustrating...

i'm sorry, suggestion use gprolog setarg replacement swi-prolog nb_setarg wrong. reworked code in simpler , (i hope) more effective way, working under iso prolog.

% data original prolog dijkstra' algorithm implementation :- initialization( consult(salesman) ).  :- dynamic(best_so_far/2).  path(x,y,z) :- dist(x, y, z). path(x,y,z) :- dist(y, x, z).  findpath([goal | rest], goal, temp, temp, [goal | rest]) :-     !. findpath([a | rest], goal, cost, temp, path) :-     path(a, b, c),     \+ member(b, rest),     newcost temp + c,     best_so_far(limit, _),     newcost < limit,     findpath([b, | rest], goal, cost, newcost, path).  % ?- searchpath(aberdeen, glasgow, l, p). % searchpath(start, goal, bestlen, bestpath) :-     retractall(best_so_far(_, _)),     asserta(best_so_far(1000000, [])),     findpath([start], goal, cost, 0, path),     % if here, it's because lower cost exists     retractall(best_so_far(_, _)),     asserta(best_so_far(cost, path)),     fail     ;     best_so_far(bestlen, bestpath). 

if want fasten bit, there simple heuristic should applicable: namely make findpath greedy, selecting first lower cost branchs. can done setof+member...


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -