🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16050

Genetic Algorithm

#16050
From: Jason Strehlow
Date: Fri, 09 Apr 1999 00:00
143 lines
4298 bytes
I need to create a genetic algorithm application in java to solve the
0/1
knapsack problem.

I have a working gene class and a working chromosome class with the
following
methods (I am using a vector to represent a chromosome and a
population):
package Chromosomes;

public class Gene implements Cloneable {
private boolean
value; // Holds the on/off status of the Gene

/** The default constructor that builds an OFF Gene. */
public Gene() {
}

/** The constructor that builds a Gene as either ON or OFF. */
public Gene(boolean v){
}

/** Returns a deep copy of the Gene. */
public Object clone(){
}

/** Returns "true" if the two Gene's have the same value. */
public boolean equals( Gene aGene ){
}

/** Alters the Gene to be the negative of its current ON/OFF state.
*/
public void mutate(){
}

/** Returns a string representation of the Gene. */
public String toString(){
}
}
package Chromosomes;

import java.util.*;
import com.objectspace.jgl.util.*;

public class Chromosome implements Cloneable {
  private Vector
    theGenes; // Holds the Genes that make up this chromosome.

  private final static int
    MUTATIONS = 3; // The number of mutated Genes per mutation.

  private static Randomizer
    r = new Randomizer();  // Used for all random numbers.

  /** The default constructor which builds an empty chromosome.*/
  public Chromosome(){
  }

  /** The constructor that builds a randomly constructed chromosome
      of size Genes. */
  public Chromosome(int size){
  }

  /** Returns a deep copy of the Chromosome. */
  public Object clone(){
  }

  /** Returns "true" if the chromosomes are copies of one another. */
  public boolean equals( Chromosome aChromosome ){
  }

  /** Returns access to the ith Gene. */
  public Gene geneAt(int i){
  }

  /** Returns the value of the Chromosome within this problem. */
  public int valueOf(){
  }

  /** Returns a new chromosome built from a subset of the current
      chromosome's Genes. */
  public Chromosome subchromosome(int i, int j){
  }

I also have most of the population class completed with the following
methods:

package Chromosomes;

import java.util.*;
import com.objectspace.jgl.util.*;

public class Population implements Cloneable{

  private static Randomizer
    r = new Randomizer();    // Used for all random numbers

  private Vector
    theChromosomeVector;  // Holds the Chromosomes of this population

  private final static int
    MUTATIONS = 2,   // The number of mutated chromosomes per pop
    CROSSOVERS = 3;  // The number of crossovers per pop

  private static int
    chromosomeSize;  // The problem size

  /** The default constructor which builds an empty population */
  public Population() {
  }

  /** The constructor which builds a population of popSize chromosomes,
      each chromoSize long. */
  public Population(int chromoSize, int popSize){
  }

  /** Sorts the Chromosomes in this population based on each
       Chromosome's valueOf. */
  private void sort() {
  }

  /** Extends the current population with CROSSOVER new chromosomes
      build by performing crossover on the randomly selected
      chromosomes. */
  private void crossover(){
  }

  /** Extends the current population by MUTATIONS chromosomes by
      performing mutation on the randomly selected chromosomes. */
  private void mutate(){
  }

What I'm having trouble with is the reproduce, select, crossover, and
sort
methods in population, and creating the genetic algorithm class that
will tie
these classes together and solve the 0/1 knapsack problem with a given
set of
items with their weights and values.

Any help would be greatly appreciated.

Jason Strehlow
Technical Details
Message-ID: <370E617D.D375B403@uwec.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,41b4e4499c89e2e6,start
X-Google-Attributes: gidf74b3,public
From: Jason Strehlow <strehljl@uwec.edu>
Subject: Genetic Algorithm
Date: 1999/04/09
Message-ID: <370E617D.D375B403@uwec.edu>
X-Deja-AN: 464557717
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language