3

I need to minimize a predicate in Prolog. Currently I am using GNU Prolog Java. I have got this fact

army( Territory,X ).

It says that the given Territory has got X army. Now I want to find the minimum number of armies owned by a given player. So I am writing:

place_army( Player, Territory ):-
    fd_maximize( army(Territory, X), X ),
    owner( Player, Territory ).

The interpreter says:

java.lang.IllegalArgumentException: The goal is not currently active

after a bit I have found the problem: http://www.gprolog.org/manual/gprolog.html#htoc313 I assume that the problem is that the Java implementation of the interpreter has got no FD solver. Any hint/workaround?

false
  • 10,264
  • 13
  • 101
  • 209
Otacon
  • 314
  • 2
  • 11

2 Answers2

3

There are two different systems with a very similar name:

GNU Prolog (see ), an ISO Prolog system with a pioneering CLP(FD) implementation which adopted this name 1999-04-19 and which is actively developed – the most recent version was released an hour ago. fd_minimize/2 and such are part of GNU Prolog.

And then there is a recent system called GNU Prolog for Java - whose most recent version is from 2010-08-15.

Maybe this naming confusion can be resolved.

false
  • 10,264
  • 13
  • 101
  • 209
2

You could achieve the same result that fd_minimize/2 provides with findall/3 and keysort/2 predicates.

 findall(X-T,army(T,X),B),keysort(B,[MinX-Territory|Cs]),

could replace

  fd_minimize(army(Territory,X),X),

providing the same value for Territory.

Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
  • 1
    Thanks for your reply. The gnu prolog java implementation doesn't provide the Keysort method and I'm a noob in Prolog, so i have wrote this code: `place_army(Player,Territory):- findall( X, army(_,X), Values ), sort(Values, [Army | _]), army(Territory,Army), owner(Player,Territory),!.` – Otacon Apr 26 '12 at 19:05
  • @Otacon: A cut should be placed immediately after army/2 to maintain equivalence to the other two attempts. Not bad for a noob, anyway! – false Apr 26 '12 at 21:45
  • Thx a lot for your hints :D (and thanks a lot for the "not bad for a noob") :D I have decided to switch to SWI-PROLOG. It is a bit heavier but it has got everything I need for my little development :D However, still, thanks a lot for your support!!! – Otacon Apr 26 '12 at 21:51