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 "solution(X)." returns
all possible ones which are in size 10^50 I just want the first 100
results.
I ...
-
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
-
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
Similar Threads
-
By Application Development in forum c++
Replies: 11
Last Post: 12-12-2007, 09:24 AM
-
By Application Development in forum PROLOG
Replies: 4
Last Post: 11-05-2007, 01:14 PM
-
By Application Development in forum RUBY
Replies: 0
Last Post: 10-04-2007, 07:14 AM
-
By Application Development in forum labview
Replies: 0
Last Post: 09-12-2007, 11:10 AM
-
By Application Development in forum Graphics
Replies: 10
Last Post: 01-06-2007, 07:53 PM