As the rudimentary graphics enabled me to see what was happening in the underlying model I'd designed, myself and my supervisor decided it was time to tackle several other aspects of the model, namely: the introduction of trucks, the ability for the vehicles to change lanes, and the ability to extract data from the model (or for the model to just shoot the data out). Since I ran into some problems with the first two, and have been working on them since, I'll talk about them.
Introducing other vehicles to the model didn't seem like too large a task, as I'd been working on the vehicle "factory" - just a class to generate a vehicle when one is needed - for a while before I switched focus to the graphics. Generating cars is no problem as they don't contain much data, but a Monte-Carlo simulation is used for the generation of trucks, and I was provided with a very sophisticated, and unfortunately hard to decipher, model to do this.
A fair bit of hacking and shenanigans were needed to squeeze this model into the code I was working on, but I got it in the end. There were some teething problems (mostly to do with me forgetting to initialise variables, and other silly things), but pretty soon I had some trucks driving around on screen with the cars. I've added a bit of colour so that smaller (2/3 axle) trucks can be separated from larger (4/5/6 axle) trucks.
Red blocks are the larger trucks, green represents smaller trucks, and black represents cars. The size of the truck on screen is also fairly representative of the size of the truck in the model (if you want to compare, all cars are 4.8 meters long).
Implementing lane-changing was a bit more troublesome, unfortunately. For a start, the code that I wrote was quite messy because the model from which I'm working inserts "virtual" cars to help in the calculation of acceleration, lane-changing, and such; we are not taking this approach. Therefore, there are several cases in which a car can find itself when it is changing lanes: the other lane may be empty, there may be a car in front, there may be a car behind, or there may be cars both in front and behind. Each case is quite different in terms of parameters, and as yet I haven't figured out an elegant solution.
Now, part of the reason I haven't found out an elegant solution is because I had a visit from my my project lead, Colin, during the week and after tweaking the model a bit, we discovered that my lane-changing was not just inelegant, it didn't actually work at all! Trucks and cars were crashing into each other, driving over the vehicle in front with no hesitation: it was bedlam.
After much deliberation, we suspected that it must be the vehicles were going on their merry way to the end of the road, and were not being passed proper pointers for the preceding vehicles. I began to overhaul the functions involved, and tracked down a few places where the simulation would fall apart. I'm finishing up fixing them today, and so far things seem to be working a lot better than they were previously, so it's a start anyway.
Since the non-existent initialisations and silly bugs in the lane-changing have caused me such grief, I'm on the look out for anything troublesome now. I had a very tricky problem during the week when the program was leaking lots and lots of memory over the course of it running, and it turned out that the memory leaks were actually originating from an add-on I'd installed to help me spot leaks in the program...D'oh.
Subscribe to:
Post Comments (Atom)
I love that a crash creates what appears to be one giant vehicle! It's like one of the road trains they have in Australia.