Concurrency (again!) - the bane of my Final Year Project

Concurrency (again!) - the bane of my Final Year Project

Advertisemen

Regarding my earlier moan about making my FYP concurrent, I thought I had solved the error but I hadn't. After hours of debugging again,  I *THINK* I've fixed it. Obviously, it's very hard to be sure when it's a seemingly random occurance. Solutions I've tried:

  • Creating a custom clone method for the world (in additional - custom clone methods for all of its fields which got a bit messy with superclasses and subclasses (the Item hierarchy))
  • Not resetting the chromosomes fitness each generation - this would work IF the map didn't change each generation and its not really fixing the problem, it's just a quick hack involving hiding the problem in a dark corner
  • There are probably other solutions which I can't remember off the top of my head as it has been quite a few hours
My current fix, which also is most definitely a bug fix (though I'm not sure this bug fix will fix the bug I'm initially trying to get rid off) is that when my GUI is created I am creating a separate thread to run the Evolver on. The Evolver manages all the genetic algorithms side of the project, it controls the sending off of the life forms to the threads to be simulated and also manages the world which the simulation occurs in. Anyway, my GUI was being created in a method and at the end the Evolver thread was started, in a function similar to:

evolverThread = new Thread(evolver);
evolverThread.start();
d out that the Evolver was being multiple times and this was causing a really weird error. Weird in that I assumed only one Evolver was running at the same time, and the error was a Concurrent Modification Exception. In my head I was like WTF as this is a procedural section of code. It was spouting the error when trying to add data into the graph's dataset, as a life form was being simulated at the same time. A previous fix was to stick the addition to the dataset in a synchronized block and ignore it (a major hack I know, but I was desperate at that point, it's a shame it came back to bite me in the ass.) Anyway, the GUI creation method was being called twice, causing two threads to run the same Evolver, thus where my Concurrent Modification Exception was occurring. The thread starting method required a quick fix:

if (evolverThread != null)
return;
evolverThread = new Thread(evolver);
evolverThread.start();
The downside is that my simulation is no longer running at lightning speed - something did seem fishy about it. Anyway I've simulated up to Generation 63 and there have been no errors, I think I will restart a simulation, get a glass of water, watch some TV. Check back on the simulation after, if no drop in maximum fitness I shall commit, push and go to bed trying not to get my hopes up. If a drop, then commit and push and go to bed angrily. At least my cat is on my lap right now - looks like I won't be getting a drink though :(

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Game Engine Tutorial