DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005

    Genetic Algorithm Problem

    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.


  2. #2
    Join Date
    Nov 2004
    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
     // 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.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.