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 ...

+ Reply to Thread
Results 1 to 2 of 2

limited number of iterations

  1. Default 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. Default 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

+ Reply to Thread

Similar Threads

  1. Efficient way to store a limited number of booleans
    By Application Development in forum c++
    Replies: 11
    Last Post: 12-12-2007, 09:24 AM
  2. B-prolog : limited number of vars ?
    By Application Development in forum PROLOG
    Replies: 4
    Last Post: 11-05-2007, 01:14 PM
  3. [SUMMARY] Probable Iterations (#141)
    By Application Development in forum RUBY
    Replies: 0
    Last Post: 10-04-2007, 07:14 AM
  4. Replies: 0
    Last Post: 09-12-2007, 11:10 AM
  5. Number of Loop Iterations in GLSL
    By Application Development in forum Graphics
    Replies: 10
    Last Post: 01-06-2007, 07:53 PM