Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: NSGA ii algorithm implementation

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default NSGA ii algorithm implementation

    Hi Guys

    Very sorry if I am posting this in the wrong forum!

    At the minute I am working on implementing the nsga ii algorithm like so http://www.cs.nott.ac.uk/~mvh/teachi...tedSorting.pdf

    At the minute I am using the same figures in the example provided and am looking to generate the first front, otherwise known as the undominated front.

    I have started to program this and I have got the part working where either 1 dominates the other but the problem comes in when I try program the code that works when neither solution dominates the other, this is severely hindering progress on my project and any help would greatly obliged.

    Please tell me this makes sense to some1 out there

    Code Provided:

     
    package dominationcheck;
     
    import java.util.ArrayList;
     
    /**
     *
     * @author 09523642
     */
    public class DominationCheck {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)
        {
     
           Solution s1 = new Solution(13,35);
           Solution s2 = new Solution(20,18);
           Solution s3 = new Solution(18,5);
           Solution s4 = new Solution(8,10);
           Solution s5 = new Solution(10,25);
           Solution s6 = new Solution(5,30);
     
           ArrayList<Solution> Undominated = new ArrayList<Solution>();
           ArrayList<Solution> Unsorted= new ArrayList<Solution>();
     
           Unsorted.add(s1);
           Unsorted.add(s2);
           Unsorted.add(s3);
           Unsorted.add(s4);
           Unsorted.add(s5);
           Unsorted.add(s6);
     
           int z;
           System.out.println("First List:"); 
           for(int i =0;i<=Unsorted.size()-1;i++)
           {
               z=Unsorted.get(i).f1;
     
              System.out.println(""+z+""); 
           }
     
           System.out.println("------------------\n"); 
     
     
           Undominated.add(Unsorted.get(0));
           Unsorted.remove(0);
     
     
          int endIdx = 0; 
     
    for(int x = 0; x <= Undominated.size()-1; x++)
    {
          for(int i=0; i <= Unsorted.size()-1;  i++)
          {
     
          Solution unsorted,undominated; 
     
          unsorted = Unsorted.get(i);
          undominated = Undominated.get(x);
     
     
     
          int p = DominationCheck(unsorted,undominated);
     
          switch (p) {
                case 1: 
                        Undominated.remove(x);
                        Undominated.add(unsorted);
     
                         break;
     
                case 2: 
     
                         break;
     
                case 3: if(x==Undominated.size()-1)
                        {
                        Undominated.add(unsorted);
                        break;
                        }
                else{
                         break;
                    }
     
                default: System.out.println("Error");
                         System.exit(0);
                         break;
     
     
        }    
          }
    }  
     
     
     
           System.out.println("Second List:"); 
           for(int a =0;a<=Undominated.size()-1;a++)
           {
               z=Undominated.get(a).f1;
     
              System.out.println(""+z+""); 
           }
     
           System.out.println("------------------\n"); 
     
        }
     
     
        public static int DominationCheck(Solution unsorted, Solution undominated)
        {
            int ans=0;
            if(unsorted.f1<undominated.f1 && unsorted.f2<undominated.f2) 
            {
                ans = 1;
            }
     
            else if(unsorted.f1>undominated.f1 && unsorted.f2>undominated.f2) //s2 dominates s1
            {
                ans = 2;
            }
     
     
            else //neither dominate
            {
                ans = 3;
            }
     
     
     
            return ans;
        }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: NSGA ii algorithm implementation

    the problem comes in when I try program the code that works when neither solution dominates the other
    Can you explain the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NSGA ii algorithm implementation

    Sorry if I didn't explain this well

    If you can see when neither dominates the other the solution taken from the unsorted list is added if the element it's tested against is the last in the undominated list, other wise if there are more elements to be tested against we move on to the next to be tested against .

    I hope I have this cleared up, the link above shows what I'm aiming for

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: NSGA ii algorithm implementation

    How can the posted code be tested? How would the problem be shown when the program is executed?
    What does the current program print out when executed? What should it print out?

    How can anyone tell if the algorithm is correctly implemented?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NSGA ii algorithm implementation

    It's a main class it should run as it is, all I'm missing from above is the solution class which all contains 2 int attributes, f1 and f2

    The link I have left in my 1st should describe what I'm trying to do

    A the min my program prints the f1 value of the unsorted list then when it goes to find the dominant front it hits a loop it cannot get out of.

    If it was correct it should print out the f1 values of the undominated solutions, so it should print out 18, 8, 5

    If it's implemented properly I should get that output

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: NSGA ii algorithm implementation

    The posted code does not compile without errors.

    What does the current program print? Post its output.
    What should it print? Post what it should output.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. very hard algorithm implementation
    By TheByt3 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 26th, 2012, 11:10 AM
  2. ArrayList implementation
    By meijuh in forum Collections and Generics
    Replies: 8
    Last Post: March 22nd, 2012, 01:03 PM
  3. closest pair algorithm implementation
    By srose in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 24th, 2011, 02:11 PM
  4. Interface Implementation
    By Samyx in forum Object Oriented Programming
    Replies: 1
    Last Post: December 2nd, 2009, 03:46 AM
  5. B+ Tree implementation
    By programmer in forum Java Theory & Questions
    Replies: 2
    Last Post: November 15th, 2009, 05:47 PM

Tags for this Thread