Genetic Algorithms Applied to Travelling Saleman Problems in C++

Visual Studio 2010 Project downloadable from here.

Introduction

Following on from a previous posting on Simulated Annealing applied to travelling salesman problems, here is a posting that carries on in a similar vein, this time focusing on genetic algorithms as our optimization technique of choice.
Continue reading

C++ Implementation of Hill-climbing and Simulated Annealing applied to Travelling Salesman Problems

Visual Studio 2010 project is downloadable from here.

Introduction

Following from a previous post, I have extended the ability of the program to implement an algorithm based on Simulated Annealing and hill-climbing and applied it to some standard test problems. Once you get to grips with the terminology and background of this algorithm, it’s implementation is mercifully simple. The algorithm can be tweaked such that it can also be implemented as a greedy hill-climing heuristic.
Continue reading

C++ Implementation of 2-opt to the “Att48″ Travelling Salesman Problem

Introduction

Some initial results from experimenting with 2-opt and 3-opt heuristics and applying them to a standard travelling salesman test problem. Visual Studio 2010 project given here. A nearest neighbour search algorithm is included. A comparison is made of the kind of results we get from the 2-opt / 3-opt algorithms, with and without improving the initial tour using the nearest neighbour algorithm.
Continue reading

A Genetic Algorithm Function Optimizer in C++

Introduction

An example is presented here on how an algorithm employing standard genetic operators can be applied to optimize a standard mathematical function, such as the Rosenbrock function:

Sample Visual Studio projects implementing this genetic algorithm are available here and here.
Continue reading

Converting between binary and decimal representations of IEEE 754 floating-point numbers in C++

This post implements a previous post that explains how to convert 32-bit floating point numbers to binary numbers in the IEEE 754 format. What we have is some C++ routines that will allows us to convert a floating point value into it’s equivalent binary counterpart, using the standard IEEE 754 representation consisting of the sign bit, exponent and mantissa (fractional part).
Continue reading

Mixing Managed and Native Types in C++ / CLI

Brief Introduction

C++/CLI (Common Language Infrastructure) was designed to bring C++ to .NET as a means of developing managed code applications. Specifically it helps simplify writing managed code when using C++.

Suppose you are writing a WinForms application in Microsoft Visual Studio with a view to using C++ to write managed code. You may prefer to reuse existing libraries and headers written in C and C++ but are a little unsure as to how this is achieved exactly.
Continue reading

Counting the Number of Words in a Text File in C++

This post aims to illustrate the power of using STL’s associative arrays as a word counter. It reads the entire contents of the text file, word-by-word, and keeps a running total of the number of occurences of each word. All using just a few lines of code, discounting the bits that output the results.
Continue reading