Results 1 to 6 of 6
  1. #1
    rdoane is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

    Default Help with project output.

    I have been working on a project lately and I am very close to finishing. It is a program that reads in a list of cities from a text file, creates 100 random tours between those cities, and then creates a genetic algorithm from the population of tours.

    Rather than explain each class and the main, I have attached a link to download the project which is in a zip file (it is too big to attach to this message).Since I only have 6 posts, copy and paste this link: h t t p ://rapidshare.com/files/221444928/rdoane_-_Distance_Project.zip.html

    Make sure the correct directory is used when reading in the text file (this is in the main).

    My question is, can anybody tell me why on my output the elite reproduction tours print twice (there should only be 10 numbers like in the crossover and mutation tours)? Also, could you tell me why on the final combined population every tour is repeated twice, and the elite reproduction tours are repeated 3 times?

    Thanks in advance and let me know if I need to clarify anything. By the way, this project was created in Netbeans.

  2. #2
    rdoane is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

    Default

    Also, here is the scan from virustotal.com to ensure that I really am looking for help and not trying to spread a virus:

    File rdoane_-_Distance_Project.zip received on 04.15.2009 03:04:36 (CET)
    Antivirus Version Last Update Result
    a-squared 4.0.0.101 2009.04.15 -
    AhnLab-V3 5.0.0.2 2009.04.14 -
    AntiVir 7.9.0.143 2009.04.14 -
    Antiy-AVL 2.0.3.1 2009.04.14 -
    Authentium 5.1.2.4 2009.04.14 -
    Avast 4.8.1335.0 2009.04.14 -
    AVG 8.5.0.285 2009.04.14 -
    BitDefender 7.2 2009.04.15 -
    CAT-QuickHeal 10.00 2009.04.14 -
    ClamAV 0.94.1 2009.04.15 -
    Comodo 1113 2009.04.14 -
    DrWeb 4.44.0.09170 2009.04.15 -
    eSafe 7.0.17.0 2009.04.13 -
    eTrust-Vet 31.6.6455 2009.04.14 -
    F-Prot 4.4.4.56 2009.04.14 -
    F-Secure 8.0.14470.0 2009.04.15 -
    Fortinet 3.117.0.0 2009.04.15 -
    GData 19 2009.04.15 -
    Ikarus T3.1.1.49.0 2009.04.15 -
    K7AntiVirus 7.10.703 2009.04.14 -
    Kaspersky 7.0.0.125 2009.04.15 -
    McAfee 5584 2009.04.14 -
    McAfee+Artemis 5584 2009.04.14 -
    McAfee-GW-Edition 6.7.6 2009.04.14 -
    Microsoft 1.4502 2009.04.14 -
    NOD32 4008 2009.04.15 -
    Norman 6.00.06 2009.04.14 -
    nProtect 2009.1.8.0 2009.04.15 -
    Panda 10.0.0.14 2009.04.14 -
    PCTools 4.4.2.0 2009.04.14 -
    Prevx1 V2 2009.04.15 To Rename Change to 2)._build.xml - is undecided
    Rising 21.25.14.00 2009.04.14 -
    Sophos 4.40.0 2009.04.15 -
    Sunbelt 3.2.1858.2 2009.04.15 -
    Symantec 1.4.4.12 2009.04.15 -
    TheHacker 6.3.4.0.308 2009.04.14 -
    TrendMicro 8.700.0.1004 2009.04.14 -
    VBA32 3.12.10.2 2009.04.12 -
    ViRobot 2009.4.14.1692 2009.04.14 -
    VirusBuster 4.6.5.0 2009.04.14 -
    Additional information
    File size: 167824 bytes
    MD5...: 519cc8c73da6fa892c82ddca2fd1de02

    Antivirus;Version;Last Update;Result
    a-squared;4.0.0.101;2009.04.15;-
    AhnLab-V3;5.0.0.2;2009.04.14;-
    AntiVir;7.9.0.143;2009.04.14;-
    Antiy-AVL;2.0.3.1;2009.04.14;-
    Authentium;5.1.2.4;2009.04.14;-
    Avast;4.8.1335.0;2009.04.14;-
    AVG;8.5.0.285;2009.04.14;-
    BitDefender;7.2;2009.04.15;-
    CAT-QuickHeal;10.00;2009.04.14;-
    ClamAV;0.94.1;2009.04.15;-
    Comodo;1113;2009.04.14;-
    DrWeb;4.44.0.09170;2009.04.15;-
    eSafe;7.0.17.0;2009.04.13;-
    eTrust-Vet;31.6.6455;2009.04.14;-
    F-Prot;4.4.4.56;2009.04.14;-
    F-Secure;8.0.14470.0;2009.04.15;-
    Fortinet;3.117.0.0;2009.04.15;-
    GData;19;2009.04.15;-
    Ikarus;T3.1.1.49.0;2009.04.15;-
    K7AntiVirus;7.10.703;2009.04.14;-
    Kaspersky;7.0.0.125;2009.04.15;-
    McAfee;5584;2009.04.14;-
    McAfee+Artemis;5584;2009.04.14;-
    McAfee-GW-Edition;6.7.6;2009.04.14;-
    Microsoft;1.4502;2009.04.14;-
    NOD32;4008;2009.04.15;-
    Norman;6.00.06;2009.04.14;-
    nProtect;2009.1.8.0;2009.04.15;-
    Panda;10.0.0.14;2009.04.14;-
    PCTools;4.4.2.0;2009.04.14;-
    Prevx1;V2;2009.04.15; To Rename Change to 2)/._build.xml - is undecided
    Rising;21.25.14.00;2009.04.14;-
    Sophos;4.40.0;2009.04.15;-
    Sunbelt;3.2.1858.2;2009.04.15;-
    Symantec;1.4.4.12;2009.04.15;-
    TheHacker;6.3.4.0.308;2009.04.14;-
    TrendMicro;8.700.0.1004;2009.04.14;-
    VBA32;3.12.10.2;2009.04.12;-
    ViRobot;2009.4.14.1692;2009.04.14;-
    VirusBuster;4.6.5.0;2009.04.14;-

    Additional information
    File size: 167824 bytes
    MD5...: 519cc8c73da6fa892c82ddca2fd1de02

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    you should provide more info...
    can you explain what the program doing?

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    personally i'd prefer if you just posted the significant portion of code that isn't executing as necessary, exactly what it is doing, and exactly what it is meant to be doing (because if you don't explain what it is meant to be doing, one conclusion for your results is that it's actually programmed to behave as so).

    some people here are nice enough to take their time to sift through a bunch of code or even compile/run it, but i find it much easier for everyone if you can localize the issue and quantify your issue. it also shows that the programmer actually has a solid understanding of his/her program and showed effort in discovering the problem.

  5. #5
    rdoane is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

    Default

    Basically the problem occurs when retrieving the information from an Arraylist. I have multiple Arraylists that contain objects of a class that I defined. Objects of this class store an array and integer value associated with that array.

    When I store these objects the arrays are fine (the correct length).

    However when I retrieve these arrays from the objects within the arraylist (by using a temp object, setting it equal to the desired value from the arraylist, and then calling the method from the temp array) the length of the array within the object has doubled, with the orginal array copying itself.

    For example, I set the following array in each of the objects that is to be stored in my Arraylist [1,2,3,4,5,6,7,8,9,10]. It stores that value correctly. However, when I retrieve that array from the objects within the Arraylist it returns this: [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10].

    Here is the main. I have noted where the error occurs:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package distanceproject;
    import java.io.*;
    import java.util.Random;
    import java.util.ArrayList;

    /**
    *
    * @author rdoane
    */

    public class Main {

    public static void main(String[] args){

    int i=0, j=0, k=0, l=0, m=0, l1=0, l2=0, randomCity1=0, randomCity2=0, temp1=0, temp2=0, crossOver=0;
    double totalDistance=0, optDistance=999;

    Random r = new Random();
    Random parent = new Random();
    Random cross = new Random();
    createTour tourCreator = new createTour();
    calcDistance d = new calcDistance();
    calcTour t = new calcTour();
    tours tempTour = new tours();
    tours parent1 = new tours();
    tours parent2 = new tours();
    eliteRepo elite = new eliteRepo();
    crossover crossObj = new crossover();
    mutation mutationObj = new mutation();
    ArrayList<tours> toursList = new ArrayList<tours>();
    ArrayList<tours> eliteList = new ArrayList<tours>();
    ArrayList<tours> mutationList = new ArrayList<tours>();
    ArrayList<tours> crossoverList = new ArrayList<tours>();
    ArrayList<tours> oldPop = new ArrayList<tours>();
    ArrayList<tours> newPop = new ArrayList<tours>();

    int [] cities = new int[10];
    int [] optCities = new int[10];
    int [] objTour1 = new int[10];
    int [] objTour2 = new int[10];
    int [] newTour = new int[10];
    Boolean [] checkTour = new Boolean[10];
    double[][] locations=new double[10][2];



    try{
    // Open the file that is the first
    FileInputStream fstream = new FileInputStream("C:/Users/Public/Documents/cities.txt");

    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));

    //Read in the number of cities
    String strLine = br.readLine();

    while ((strLine = br.readLine()) != null)
    {
    double temp = Double.parseDouble(strLine);
    locations[i][j]=temp ;
    //System.out.println(locations[i][j]);
    if(j<1)
    j=j+1;
    else
    j=j-1;
    if(j<1)
    i=i+1;
    }
    in.close();
    }

    catch (Exception e){//Catch exception if any
    }

    //Creates the tours by taking an initial list and scrambling it.
    for (k=0;k<100;k++)
    {
    tours store = new tours();
    tourCreator.createTour(cities, r);

    totalDistance=t.calcTour(r, l1, l2, locations, cities, d);
    store.set(cities, totalDistance);
    toursList.add(k,store);

    }

    //Print the arraylist that holds the tours.
    for(j=0;j<toursList.size();j++)
    {
    tempTour = toursList.get(j);
    System.out.println("The orginal tour order was: "+tempTour.printTour()+". The distance was: "+tempTour.getDistance());
    }
    System.out.println("");









    for(i=0;i<2;i++)
    {

    //ELITE REPRODUCTION
    elite.eliteReproduction(toursList, eliteList);

    //Print the elite tours from the initial population
    for(k=0;k<10;k++)
    {
    tempTour=eliteList.get(k);
    System.out.println("Elite Tour "+i+": "+tempTour.printTour()+". Distance: "+tempTour.getDistance());
    tempTour=null;

    }
    System.out.println("");

    //MUTATION
    //Creates one tour, then swaps two elements, and then creates another. Finally store in the array list.
    //Swap method for creating tours.
    mutationObj.doMutation(k, r, randomCity1, randomCity2, temp1, temp2, cities, t, totalDistance, l1, l2, locations, d, mutationList);

    //Print the Mutation tour
    for(k=0;k<100;k++)
    {
    tempTour=mutationList.get(k);
    System.out.println("Mutation Tour "+i+": "+tempTour.printTour()+". Distance: "+tempTour.getDistance());
    tempTour=null;

    }
    System.out.println("");

    //CROSSOVER
    crossObj.doCross(j, k, cities, newTour, checkTour, parent1, parent2, cross, crossOver, toursList,
    parent, objTour1, objTour2, totalDistance, t, l1, l2, locations, d, r, crossoverList);

    //Print the Crossover tour
    for(k=0;k<100;k++)
    {
    tempTour=crossoverList.get(k);
    System.out.println("Crossover Tour "+i+": "+tempTour.printTour()+". Distance: "+tempTour.getDistance());
    tempTour=null;

    }
    System.out.println("");

    //Add the Elite tours (10) to the new population
    for(k=0;k<10;k++)
    {
    newPop.add(eliteList.get(k));
    }

    //Add the Crossover (80) tours to the new population
    for(k=0;k<80;k++)
    {
    newPop.add(crossoverList.get(k));
    }

    //Add the Mutation (10) tours to the new population
    for(k=0;k<10;k++)
    {
    newPop.add(mutationList.get(k));
    }

    //ERROR OCCURS HERE
    //Print the new population
    for(j=0;j<newPop.size();j++)
    {
    tempTour = newPop.get(j);
    System.out.println("GA Tour "+i+": "+tempTour.printTour()+". Distance: "+tempTour.getDistance());
    }

    }
    }
    }

  6. #6
    rdoane is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

    Default

    Here is what the output looks like:
    (This prints when you store in a certain arraylist)
    Crossover Tour 0: 4126057893. Distance: 82.02438661763951
    Crossover Tour 0: 5728063149. Distance: 113.1370849898476
    Crossover Tour 0: 2906145783. Distance: 110.3086578651014
    Crossover Tour 0: 8354610792. Distance: 90.50966799187809
    Crossover Tour 0: 5728063149. Distance: 113.1370849898476


    (Here is what it prints when retrieving the arraylist)
    GA Tour 0: 41260578934126057893. Distance: 82.02438661763951
    GA Tour 0: 57280631495728063149. Distance: 113.1370849898476
    GA Tour 0: 29061457832906145783. Distance: 110.3086578651014
    GA Tour 0: 83546107928354610792. Distance: 90.50966799187809
    GA Tour 0: 57280631495728063149. Distance: 113.1370849898476

Similar Threads

  1. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  2. how to c the output
    By pro85 in forum Java Applets
    Replies: 1
    Last Post: 02-11-2009, 09:09 AM
  3. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 08:12 PM
  4. What will be output and why
    By huma in forum Threads and Synchronization
    Replies: 4
    Last Post: 06-26-2008, 10:14 PM

Posting Permissions

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