Is there a more efficient way to manage large data than using facts?

Viewed 73

I finished working on an AI project that manages long strings (About 1300 characters each), the issue is the Out of local stack exception when trying to run the algorithm with a larger population (NP) than 10 or when trying a higher amount of iterations (G) than 20. Currently, i manage data using facts like this:

x(INDEX, NAMESTRING1, STRING1, NAMESTRING2, STRING2, FITNESS, VAR)

for storing current solutions

and

h(INDEX, NAMESTRING1, STRING1, NAMESTRING2, STRING2, FITNESS, VAR)

for storing possible solutions made by the algorithm.

Where STRING1 and STRING2 are two lists containing the characters of two DNA chains. These lists get modified adding '_' by the algorithm.

My code calls to assert/1 and retract/1 about NP * G * 4 * 2 times during each iteration.

I tried:

1.- Setting a higher stack limit, which seems to work with reservation.

2.- Using ! where necessary.

I was wondering if managing data with a list of lists would solve the problem.

1 Answers

Asserting and retracting facts should be very efficient and behave in the same way as inserting and removing document to/from an in-memory Key-Value database.

"Out of local stack space" indicates that your program recurses too deeply or has too many local variables in certain stack frames. Using ! certainly helps as the Prolog Processor can optimize away stack frames "that will never be re-visited in the future".

There is not enough information to judge this buit depending on the algorithm you may have the possibility to replace depth-first search with an iterative deepening approach (as one possibility that comes to mind)?

Related