Genetic Algorithm Problem

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
Feb 2005
Posts
1

## Genetic Algorithm Problem

Hi,
I am currently writing a genetic algorithm program in Java for my final year project. I am finding some difficulties and was wondering if anyone out there might be able to help…

I am trying to optimise 2 objectives, Objective X and Objective Y. Values of both objectives are stored in separate arrays of size 100. I am trying to find the non-dominated solutions from the 100 solutions that I have generated, but my code only seems to be working for the first set of non-dominated solutions.

Below is a sample of some of my code.

/*Pass both objective arrays as parameters*/
public boolean[] calculateDominance(double[] objX, double[] objY)
{
for(int i=0; i<populationSize; i++)
{ double objX = objX[i];
double objY = objY[i];

/*Calculate whether solutions are dominated or not*/
for(int j=i+1; j<populationSize-1; j++)
{
if((objX[j]<objX) && (objY[j]<objY))
{ isDominated[j] = true;
isRanked[j] = 0;
}
}
}
return isDominated;
}

This method then returns a boolean array of all solutions, with
(isDominated[i] = = false) if that particular solution is non-dominated.

How can I improve or change this code to calculate whether all solutions in the array are dominated or not.
Any help would be greatly appreciated.

Thanks

2. I'm not entirely sure that I understand what you mean,
but if the problem is how to determine if all booleans in
an array are true you could just implement a method
like:
Code:
``` // boolean
public static boolean areAllSameValueAs(boolean val, boolean [] arr) {
int i=0;
while (i<arr.length) {
if (val && arr[i++]) continue;
return false;
}
return true;
}
// general form
public static boolean areAllSameValueAs(Object ob, Object [] arr) {
int i=0;
while (i<arr.length) {
if (!ob.equals(arr[i++])) return false;
}
return true;
}
// HashSet method
public static boolean areAllSameValueAs(Object ob, ArrayList list) {
HashSet hs=new HashSet(list);
return hs.size()==1 && ob.equals(list.get(0));
}```
Note (stating the obvious): if you implement one of
the Object version(s) and use
one of your own subclasses in the arrays, then that
subclass must implement the public boolean equals(object ob) method.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise