Author Archives: Gwilym

Object Happiness

Iv just been making my way though The archives  of  Codding Horror by Jeff Atwood as I often do. Its one of those good places where you can learn how to program, and think about why your writing that code that way, rather than just how to write java/C/Php…..

In one of his articles he mentions a concept called object happiness. I would like to take this opportunity to say this;

Hi my name is Gwilym and im Object Happy.

Worse I am design happy, the first thing I do when I get my greasy little fingers on a new coding project is this, I design the hell out of it. Im always leaning about new ways of coding and there will be a dozen things I want to try out. I will stand in front of my white board and be thinking “yes, yes we can have a singleton here, ar yes my precious oh and we can abstract this out to here, oh my and we can can use an interface to link these together”. The result of this is that I waste coding time because, the design will now be so reusable, robust and readable that it will need about an extra 50% more code than if I had sat down and just bashed the thing out. I know this because I have seen may other peoples solutions to the same problems were they have just coded it, any they nearly all work close to or just aswell as mine, we both get 1st’s and all I get for the extra week of coding I put in is a nice comment from the Lecturer who marked it.

Rimmer: Look, I’ve got my engineering re-sit on Monday; I don’t know anything. Where’s my revision timetable?
Lister: Wait, is this the thing in a- in all different colours, with all the subjects divided into study periods and rest periods and self-testin’ times?
Rimmer: It took me seven weeks to make it. I’ve got to cram my whole revision into one night.
Lister: Hang on, this the thing with a note on it, in red, said, “Vital, valuable, urgent! Do not touch on pain of death!”?
Rimmer: Yes!
Lister: I threw it away.

Red Dwarf

This has no good points-
Make sure you don’t spend stupid amounts of time on your design, and leave you self no time to implement
Make sure you design is worth something, otherwise you work will just be thrown away.

Having thought about this I would say this-

Find a percentage call it x make it sane about 10-20% when you design something make sure that all the exciting things you thought of, never add more than this the total size/ workload of your project.

For anything that you could code in a day , design it as you go along or you will be there for a week.

If you have to design it badly, code it, hand it in. Then if you really want to you can always go back and have quite little refactor by your self until your soul is once again happy.

But most of all remember as I try to we are programmer not designers so CODE,  design is something to help you do that, but it overall less inportant than code

When I have that distant expression

Im thinking of things this:

New found love is possibly the most one of the most addictive things in the known world. It has occurred to me that maybe you know you are truly in love when you are willing to go cold turkey.

That is your are both willing and happy to sacrifice, never feeling that again for a person.

Just a thought…..


A few personal thoughts I have had over the last week or so-

  • There is no point in having wisdom, if you do not have the common sense to know when to use it.
  • Nearly all the most stupid mistakes, and bad things I have done in my life would never had happened if I stopped and thought for 5 minutes.
  • There is a difference between an angry friend and an enemy.
  • When you are a betrayer, a fraudster and you have lied to your friends, when some of them chose to stick by you, have found true friends.

I have a lot of people to apologise to do,  a lot of begging for mecry,  and a lot of penance that is owed.

I have greater friends than I deserve, but I am thankful for them.

No self respecting introspective blog can finish without a quote;

    So do we pass the ghosts that haunt us later in our lives; they sit undramatically by the roadside like poor beggars, and we see them only from the corners of our eyes, if we see them at all. The idea that they have been waiting there for us rarely if ever crosses our minds. Yet they do wait, and when we have passed, they gather up their bundles of memory and fall in behind, treading in our footsteps and catching up, little by little

    Stephen King


    Have spent most of the evening plotting lights for sweet charity, The strobes in are horrific, but slightly awesome.

    Hightlights :-

    >Using s strobe in a small confined area causes significant deep perception problems, this is bad if the small area is also a set of stairs.
    >Barry Grimes – “Use Spanish lighting”….
    > Jonathan Nichols’s Police lights were an awesome , paretily as he made them in about 3 minutes

    My eyes now hurt, time to sleep me thinks

    Oh as a ps. a huge well done to Matt today fro getting Welfare

    Tired, Compski’s , Sweet Charity, and more….

    So Very Tired

    Thursday I went to formal which was on the whole pretty awesome, though my dear god I could only eat 1 of the 3 courses. The first one contained Port, so I got a fruit salad instead, and the Dessert contained gelatine, so I got a fruit salad instead.

    After this I watched the Dark Knight with my wonderful girls, Its strange I have only know them for a few months, but they have all become very dear to me. As far as I concerned I have 3 new sisters and a brother. Also Liv and Emma reactions to the Dark Knight possible the funniest thing I seen for a long time.

    After this JFI, Matt and vicky ended up in my room, then there was tequila, then for some reason we just did stop talking then it was 3am…..

    Friday I am proud to say I got up bright and early went to 3 out of my 5 lectures, rigged two sets of lights and built a stage. I was once again on my way to the glorious world of sleep when JFI decided to steal me for some help with his current coding project. This of course could only happen post pizza and and Malibu. Once again It was a late night causing me to over sleep this moring.

    JFI have come to a good agreement however; When we are friends we a good friends, but but we are enemies we are very bad enemies. This on the whole was a good discover for the night.

    Today I finished the set build for Sweet Charity, and spent a lot of time crawling around on my belly trailing cabling. twas fun ^_^

    Im off now to see if I can find lucy loo, as everyones going out on a Sweet Charity social which I can’t go one, damn enochlophobia.

    Got to be up for 7:15 in the morning yay!

    CUDA – The future of high performance computing?

    CUDA is NVIDIA’s parallel computing architecture that enables dramatic increases in computing performance by harnessing the power of the GPU (graphics processing unit).

    GPUs are massively multi-threaded many-core-chips.GPU threads are extremely lightweight, thus thread creation and context switching are essentially free. As they have this highly parallel structure, they are more effective than general-purpose CPUs for a range of complex algorithms.

    CUDA is formed of a small set of extensions to the C programming language, which allows the power of GPU’s to be harnessed for task normal performed by the CPU.

    This can speed up algorithms which require large amounts of computation, especially those which can make use of parallel computation, such as AI problems, Dense linear algebra, Sequencing (virus scanning, genomics), sorting and the list goes on.

    Many company’s and research project already make use of large GPU clusters, for projects, I believe the imitate future of high performance computing. and with more and more powerful GPUs being shipped in home computers many modern programs may be able to take advantage of large amounts of parallel computing power to produce optimal/close to optimal solutions to NP problems, as a matter of course.

    There is no patch for human stupidity

    A friend of mine who visited me this evening made this abundantly clear, but this is not about the small mistake, he made this evening, but of its possibly frighting consequences.

    The friend in question was coerced  by myself into providing some help with my DNS Problem , which he kindly solved, he then went about having a good old natter, and set to fixing a few bugs on some live servers he was working on.

    After he left, I sat down and was about to start work, after popping up firefox the first thing I find is im logged into his company email account, i have a little fun with this a sent a few emails to his own account to inform him he is a fool, within about 60 seconds he calls me as he’s obviously seen the emails come up on a one of his email clients, and I kill the tab.

    The next thing I realised is he’s left a copy of a rather confidential document open on my computer, this is not a huge risk as I am under a NDA about it already but i still feel more than a little worried by this.

    At this point I am called away, and don’t return to my computer for a few hours, when I return I finish off an amazon order im in the middle of placing when I notice the icon for putty is sitting at the bottom of my screen, Surely not, but yes there it is


    is blinking at the bottom of the putty window, I have mySQL console access to his company’s main database. A simple DROP command and there could be heaps of trouble, I kill it only then to find my self, with a linux BASH prompt. I also have admin SSH into one of his company’s servers.

    The point I want to make from all of thsi is not that my friend was a fool as that is not the case, what he was, is human, and that is terrifying for we are fallible beyond belief. In my many years of IT experance, many of which also involved a little harmless ‘white hat’ hacking, I keep coming back again and again to the same conclusion.

    We will never be able to build a secure system until we remove the humans from it.

    Software Applications AI Search Assignment

    Some Attempts at solving the traveling salesman problem with AI Search

    Having looked at the possible ways of solving the travelling salesmen problem it was my intention to use implementations that use simulated annealing and Genetic Algorithms, as they appeared to be the best options looking at the problem from varying levels of intelligent choice.

    >Initial Work on simulated annealing

    In my work on simulated annealing I initially experimented with variation of the thread / Crystal count and the maximum temperature of the second annealing. From this I found that using a large amount of threads produced better results, though when looked at, all this is throwing more and more attempts at problem until a better solution is found, which though we must admit works, and will require an exponential increase in computing power in relation to results.

    When adjusting the maximum temperature of the second annealing I found that higher temperatures made small consistent positive difference to fitness of tours.

    >Initial Work on Genetics

    My initial work on Genetics suffered problems in that my solutions would plateau far above an optimal solutions. In an effort to solve this I tried to give it a ‘head start’ by constructing tours  Intelligently before feeding them into the population , this worked exceptionally well as it could produce an optimal or  close to optimal tour (around 49k for file 535)about in ~0.06 seconds. However this then caused significant problems in genetics as in an attempt to diversify the population it destroy the patterns within these close to optimal tours and within 20 generations or so would return to level of the original plateau. This was solved by creating a more intelligent mutation and breeding algorithms designed for maximum pattern preservation within the tour, and convergence on a local optima.

    My new mutation algorithm works by attempting to break the pairs of cities with the greatest distances between them.  So the pair with longest distance AB and second longest distance  XY swapped  iff AVG(D(AY),D(YC),D(XB),D(BZ))<AVG(D(AB),D(BC),D(XY),D(YZ))
    D(AB)=Distance between A and B
    If my algorithm cannot find a pair AB XY to swap such the above condition is satisfied then will attempt a number of random order reversals of sub tours within the tour, and pick the fittest of these to return to the population, but not affect the tour designated to be mutated.

    My new breeding algorithm in an attempts to preserve patterns by taking a length(35-50%) of the tour from each parent and comparing the fitness of each subsection, and adding  the fittest sub section to a child repeating this until we have a child which has a complete tour, It produces around 20 children like this and returns the fittest of them to the population

    >Final Simulated Annealing Algorithm

    My final Simulated Annealing begins by constructing semi-optimal tours then passing them to Crystals/Threads. It runs with 10 concurrent threads, updating to a synchronized HashMap located in the Annealer Class which always them to dynamically update how fit they are relative to other thread this is then passed to annealing schedule with from a produces from this input and on the current stage of the annealing schedule a temperature.

    Based on this temperature a crystal with ether adds a city to the tour, remove a city from the tour, reorder the parts of the city or do nothing

    >Final Genetics Algorithm

    My final genetics algorithm constructs 10,000 possible tours as this only take about 6 minutes and takes the best pre constructed tour as the base of its population. It then forms a population of clones of this tour each with different mutation to provide local genetic diversity as soon as possible.

    The Population is run though a number of peaks controlled by a growth factor, so that the population should vary though the peak as a bell curve

    Each peak it made out of cycles where each cycle is composed of in order Deaths, Mutations, and Breeding at

    After all the cycles have finished the population is quick sorted and the tour with the highest fitness is output.

    >Comparative analysis
    In comparing the two it is clear from the results that the genetics produces better results.

    However getting the best results may not be the only criteria on which base evaluation, as for example the simulated annealing ran in ~ 15 minutes on file535 much less than the ~1hour and 25 minutes  required for  the genetics to run. In commercial applications of software computer time is expensive and time is valuable so quick and cheap, less than perfect results often more valuable than slow, expensive and close to perfect/perfect results. Route planners are a good example of this being close to the Traveling salesman in nature. Many  commercial  pieces of software produce less than optimal routes as can been seen by sometimes making small Intelligent adjustments as the user and producing a shorter/ more optimal solutions. However they run fast, you do not want to sit around all day waiting for a solution that can save you an extra 2 miles, getting it right now and also close optimal is ‘good enough’. It can be also argued that the non-deterministic nature of these algorithms makes optimizing their running times more important as its gives them a greater degree of reliability.

    >>Intelligent vs. Non-Intelligent

    For the purposive of the following I will define an algorithm as Intelligent if it makes its actions based, at least partially on a value (A fitness function) of a set of data.

    In their pure form and by my definition, Simulated Annealing is Non-Intelligent as it makes random realignments, and genetics performs all actions based on the preserved fitness of a solution.

    Fitness allows in many ways allows better decisions to be made about the next action to be made on a set of data including weather to perform an action or if to reverse a previous action made. However this also comes with several problems the first and most obvious of these is the cost of calculating the fitness in the genetics used here the FitnessFactor Function is O(n2) which means for file535 a cost of around 148k calculations per call . This can be solve to some degree with estimated fitness functions of reduced complexity, or by storing the fitness and only updating it when the data is changed, but with these you may not get as accurate results. The second main problem is convergence towards local optima i.e as fitness is always relative so if a set of data starts to converge towards to fitness the algorithm maybe be unable to move it towards a more global optima, as it designed such that it does not allow actions which have a negative effect upon that data’s fitness but may prove important to a global optima.

    In respect of my algorithms introducing a small amount of decision making into my Simulated annealing in the form of its re-order parts function which mimicked that of my genetic algorithms mutate function, allowed for large improvement in results.

    Drawing from this it would seem that an algorithms resource consumption vs  results rely heavily on the amount in which it is called to make intelligent decisions, the more complex the decision making functions the more resources are required but the more likely you are to make a possible step towards a optimal solution.

    It would also appear that that making positive decisions is more important in large the sets of data, as the number of solutions increases factorially with size, but for most problems there is only one or a few optimal solutions, so for larger and larger sets of data it become less and less likely that an algorithm will stumble upon the correct solution or ‘path’ to it.

    Thus in conclusion I would be my believe that simulated Annealing is a the most useful tool if the search space or available resources are small, but genetics will fare better with large state spaces, were resources are not at a premium.



    Creative Commons License
    Software Applications AI Search Assignment by Gwilym Newton is licensed under a Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License.
    Based on a work at

    Java 3d Wind Turbine Simulator

    Project to create a Java3D program that draws a simple horizontal axis wind turbine with rotating blades.  with  a 3D button to allow you to interactively change the direction of the wind and therefore rotate the blades and turbine head about the vertical axis.

    User Guide

    >To open make sure that the data folder is in the same directory as the Jar File.
    >To rotate the View, press down on the left mouse button and move the mouse to the left or right.
    >To zoom in roll the mouse wheel forwards, to zoom out roll the mouse wheel backwards
    >To Increase the Wind-Speed click on the + Button
    >To Decrease the Wind-Speed click on the – Button
    >To move Turbine Head right click on the -> Button
    >To move Turbine Head Right click on the <- Button

    Mark  1st -95%

    Creative Commons License
    Java 3d Wind Turbine Simulator by Gwilym Newton is licensed under a Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License.
    Based on a work at

    1 14 15 16 17