limited number of iterations - PROLOG

This is a discussion on limited number of iterations - PROLOG ; Hello everybody, I have a rule solution(X) which represents an optimization algorithms where X returns a possible solution. Since just calling it &quot;solution(X).&quot; returns all possible ones which are in size 10^50 I just want the first 100 results. I ...

1. limited number of iterations

Hello everybody,

I have a rule solution(X) which represents an optimization algorithms where
X returns a possible solution. Since just calling it "solution(X)." returns
all possible ones which are in size 10^50 I just want the first 100
results.
I did it the following way:

finalResult([]).
count(0, 100).
getSolution(X) :-
solution(X),
checkNewSolution(X),
count(L, R),
retract(count(_, _)),
NewL is L+1,
assert(count(NewL, R)),
NewL > R,
!.

checkNewSolution(X) checks if the current solution is better than the one in
finalResult(X) and replaces it.

That did work, but now I have the problem that I am running this prolog
application within an environment (P# in .NET) where I cannot use the
assert and retract rules.

Is there any other way?

Greetings,
-Rainer Hahnekamp

2. Re: limited number of iterations

On 2005-08-09, Rainer H <tsubasa@aon.at> wrote:
> Hello everybody,
>
> I have a rule solution(X) which represents an optimization algorithms where
> X returns a possible solution. Since just calling it "solution(X)." returns
> all possible ones which are in size 10^50 I just want the first 100
> results.
> I did it the following way:
>
> finalResult([]).
> count(0, 100).
> getSolution(X) :-
> solution(X),
> checkNewSolution(X),
> count(L, R),
> retract(count(_, _)),
> NewL is L+1,
> assert(count(NewL, R)),
> NewL > R,
> !.
>
> checkNewSolution(X) checks if the current solution is better than the one in
> finalResult(X) and replaces it.
>
> That did work, but now I have the problem that I am running this prolog
> application within an environment (P# in .NET) where I cannot use the
> assert and retract rules.
>
> Is there any other way?

You will need some form of non-backtrackable data. Can be assert/retract,
record/recorded, global variables, non-backtrackable destructive assignment
on arguments of compounds and maybe more. If P# doesn't have any of these
I think it is time to look for another Prolog.

Cheers --- Jan