Fundamentals of Programming in Java
Assignment 2
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Submission instructions
Submit your work by the deadline above. The accepted submission format is a zip archive. Submit only
Java source files in your archive. Place all of the files in the same zip. Do NOT submit .class files. Please
do not submit Eclipse (or other IDE) projects.
Please make sure that the following package declaration is the first line of your Java files:
package com.bham.pij.assignments.a2a;
Do not output anything to the console unless explicitly asked to. You may, of course, use console output
to debug your programs. Just make sure that you comment out or delete such debug statements when you
submit.
Where applicable, your class for each of the exercises must have the name shown in the exercise heading.
In each of these exercises, you are not restricted to only creating the required methods. If you want to,
you can create others. However, you must create at least the required methods.
Do not use any input method (such as Scanner) in any method that is required by this specification.
Introduction
For this assignment you will implement a genetic algorithm (GA), which is a type of evolutionary algorithm.
1
As discussed in the lecture, the genetic algorithm is a search algorithm that is inspired by natural evolution.
Two key processes are adopted: genetic mutation and crossover. These processes are described
below. Using these two processes, the GA proceeds from an initial collection of random solutions to find
some desired solution. The critical component that determines the success or otherwise of the search is
called the fitness measure. The fitness measure assigns a numerical fitness to each solution, enabling the
algorithm to decide which ones are the ‘fittest’, i.e. the best. You do not need to know anything about
biology to implement this assignment.
This assignment is partly an implementation exercise but is also a design exercise. The design that you
choose will affect your mark. You should seek to utilise the object-oriented principles that we have been
discussing in lectures since week 3.
Algorithm overview
The GA starts with a collection of random individuals. This collection is usually of a fixed size, for example,
100. An individual is an attempted solution of the particular problem. Since all initial individuals
are random, none of them probably represents a particularly good solution. It will usually be the case,
however, that even though they are random, some individuals will be better than others.
Each individual has a chromosome. A chromosome is a collection of genes of fixed size. Each gene on a
chromosome can have one value from a set of values. For example, in a text-based task, each gene might
have the value of one of the alphabetic characters (like the ‘weasel’ example we discussed). So, a decision
must be taken about what are the legal values of a gene. In a task involving binary numbers, for example,
gene values can only be 1 or 0. No other values will be legal.