I am writing an educational program for students, where they can see how different algorithms work when solving Traveling salesman problem (Time consumption, visual representation of state etc.). The problem is that not only I have to show good algorithms but I have to show bad ones as well. For instance I implement Breadth-first search algorithm for TSP (horrible choice).
Program itself is written in Java. I have a seperate thread for problem solver algorithm and all algorithms implement a specific interface which allows me to interfere after each iteration.
All blind-search algoritms which run over a tree structure with N nodes (n= number of cities) and each node is an array of N elements, that implementation produces a StackOverFlow Exception after around generating ~ 50k nodes. I dont want to limit user interface so that limited ammount of cities can be used- simulated anneal works with thousands of cities.
Here is the question: Is there some reliable function I could use in some specified logical statement so that I could identify the point when System is about to crash? Something is style : if (System.memoryLeft() <= 100 /bytes/ ) { // Stop working and take action
Thanks in advance.