Note that there are some explanatory texts on larger screens.

plurals
  1. POOutOfMemoryError during heuristic search
    text
    copied!<p>I'm writing a program to solve an 8 tile sliding puzzle for an AI class. in theory this is pretty easy, but the number of node states generated is pretty large (estimated 180,000 or so). We're comparing different heuristic functions in class, so my code has to be able to handle even some very inefficient functions. I'm getting "OutOfMemoryError: Java heap space" when using java's PriorityQueue class. Heres the relevant code withing my solver function: (the error is on the openList.add(temp); line)</p> <pre><code>public void solve(char[] init,int searchOrder) { State initial = new State(init,searchOrder); //create initial state openList = new PriorityQueue&lt;State&gt;(); //create open list closedList = new LinkedList&lt;State&gt;(); // create closed list generated = new HashSet(); //Keeps track of all nodes generated to cut down search time openList.add(initial); //add initial state to the open list State expanded,temp = null,solution = null; //State currently being expanded int nodesStored = 0, nodesExpanded = 0; boolean same; //used for checking for state redundancy TreeGeneration: while(openList.size() &gt; 0) { expanded = openList.poll(); closedList.addLast(expanded); for (int k = 0; k &lt; 4; k++) { if (k == 0) { temp = expanded.moveLeft(); } else if (k == 1) { temp = expanded.moveRight(); } else if (k == 2) { temp = expanded.moveAbove(); } else { temp = expanded.moveBelow(); } if(temp.isSolution()) { solution = temp; nodesStored = openList.size() + closedList.size(); nodesExpanded = closedList.size(); break TreeGeneration; } if(!generated.contains(temp)) { // System.out.println(temp.toString()); openList.add(temp); // error here generated.add(temp); } // System.out.println(openList.toString()); } } </code></pre> <p>Am I doing something wrong here, or should I be using something else to handle this quantity of data? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload