still need help

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

still need help

susan al-naqshbandi
Hello All,
Thank you very much for your grate support.....I could run the example from cmd ...but still thers is a problem executing the classes.....in JBuilder4
when i tried to check the follwing code
 
package examples;

import org.jgap.Chromosome;
import org.jgap.FitnessFunction;

public class MinimizingMakeChangeFitnessFunction extends FitnessFunction
{
    private final int m_targetAmount;

        public MinimizingMakeChangeFitnessFunction( int a_targetAmount )
    {
        if( a_targetAmount < 1 || a_targetAmount > 99 )
        {
            throw new IllegalArgumentException(
                "Change amount must be between 1 and 99 cents." );
        }

        m_targetAmount = a_targetAmount;
    }


       public double evaluate( Chromosome a_subject )
    {
                int changeAmount = amountOfChange( a_subject );
        int totalCoins = getTotalNumberOfCoins( a_subject );
        int changeDifference = Math.abs( m_targetAmount - changeAmount );

               double fitness = ( 99 - changeDifference );

        
        if( changeAmount == m_targetAmount )
        {
            fitness += 100 - ( 10 * totalCoins );
        }

        return fitness;
    }


        public static int amountOfChange( Chromosome a_potentialSolution )
    {
        int numQuarters = getNumberOfCoinsAtGene( a_potentialSolution, 0 );
        int numDimes = getNumberOfCoinsAtGene( a_potentialSolution, 1 );
        int numNickels = getNumberOfCoinsAtGene( a_potentialSolution, 2 );
        int numPennies = getNumberOfCoinsAtGene( a_potentialSolution, 3 );

        return ( numQuarters * 25 ) + ( numDimes * 10 ) + ( numNickels * 5 ) +
               numPennies;
    }


        public static int getNumberOfCoinsAtGene( Chromosome a_potentialSolution,
                                              int a_position )
    {
        Integer numCoins =
          (Integer) a_potentialSolution.getAllele( a_position ).getValue();

        return numCoins.intValue();
    }


        public static int getTotalNumberOfCoins( Chromosome a_potentialsolution )
    {
        int totalCoins = 0;

        int numberOfGenes = a_potentialsolution.size();
        for( int i = 0; i < numberOfGenes; i++ )
        {
            totalCoins += getNumberOfCoinsAtGene( a_potentialsolution, i );
        }

        return totalCoins;
    }
}
 
and when i want to run it the following errors appear although i add the library of jgap to my project property
 
"MinimizingMakeChangeFitnessFunction.java": Error #: 302 : cannot access class org.jgap.Chromosome; class file has wrong version 48.0 at line 3, column 17
"MinimizingMakeChangeFitnessFunction.java": Error #: 302 : cannot access class org.jgap.FitnessFunction; class file has wrong version 48.0 at line 4, column 17
"MinimizingMakeChangeFitnessFunction.java": Error #: 300 : class FitnessFunction not found in class examples.MinimizingMakeChangeFitnessFunction at line 21, column 58
I hope there is any one can help me with this problem.....
Best Regards To all
 
SUSAN


How low will we go? Check out Yahoo! Messenger’s low PC-to-Phone call rates.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: still need help

Dan Clark-4
Susan,

This error message means that you are using an incompatible version of the JVM.  You either need to compile the JAR file yourself or upgrade your JVM.  I believe file version 48 corresponds to 1.4

--Dan

On 4/26/06, susan al-naqshbandi <[hidden email]> wrote:
Hello All,
Thank you very much for your grate support.....I could run the example from cmd ...but still thers is a problem executing the classes.....in JBuilder4
when i tried to check the follwing code
 
package examples;

import org.jgap.Chromosome;
import org.jgap.FitnessFunction;

public class MinimizingMakeChangeFitnessFunction extends FitnessFunction
{
    private final int m_targetAmount;

        public MinimizingMakeChangeFitnessFunction( int a_targetAmount )
    {
        if( a_targetAmount < 1 || a_targetAmount > 99 )
        {
            throw new IllegalArgumentException(
                "Change amount must be between 1 and 99 cents." );
        }

        m_targetAmount = a_targetAmount;
    }


       public double evaluate( Chromosome a_subject )
    {
                int changeAmount = amountOfChange( a_subject );
        int totalCoins = getTotalNumberOfCoins( a_subject );
        int changeDifference = Math.abs( m_targetAmount - changeAmount );

               double fitness = ( 99 - changeDifference );

        
        if( changeAmount == m_targetAmount )
        {
            fitness += 100 - ( 10 * totalCoins );
        }

        return fitness;
    }


        public static int amountOfChange( Chromosome a_potentialSolution )
    {
        int numQuarters = getNumberOfCoinsAtGene( a_potentialSolution, 0 );
        int numDimes = getNumberOfCoinsAtGene( a_potentialSolution, 1 );
        int numNickels = getNumberOfCoinsAtGene( a_potentialSolution, 2 );
        int numPennies = getNumberOfCoinsAtGene( a_potentialSolution, 3 );

        return ( numQuarters * 25 ) + ( numDimes * 10 ) + ( numNickels * 5 ) +
               numPennies;
    }


        public static int getNumberOfCoinsAtGene( Chromosome a_potentialSolution,
                                              int a_position )
    {
        Integer numCoins =
          (Integer) a_potentialSolution.getAllele( a_position ).getValue();

        return numCoins.intValue();
    }


        public static int getTotalNumberOfCoins( Chromosome a_potentialsolution )
    {
        int totalCoins = 0;

        int numberOfGenes = a_potentialsolution.size();
        for( int i = 0; i < numberOfGenes; i++ )
        {
            totalCoins += getNumberOfCoinsAtGene( a_potentialsolution, i );
        }

        return totalCoins;
    }
}
 
and when i want to run it the following errors appear although i add the library of jgap to my project property
 
"MinimizingMakeChangeFitnessFunction.java": Error #: 302 : cannot access class org.jgap.Chromosome; class file has wrong version 48.0 at line 3, column 17
"MinimizingMakeChangeFitnessFunction.java": Error #: 302 : cannot access class org.jgap.FitnessFunction; class file has wrong version 48.0 at line 4, column 17
"MinimizingMakeChangeFitnessFunction.java": Error #: 300 : class FitnessFunction not found in class examples.MinimizingMakeChangeFitnessFunction at line 21, column 58
I hope there is any one can help me with this problem.....
Best Regards To all
 
SUSAN


How low will we go? Check out Yahoo! Messenger�s low <a href="http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> PC-to-Phone call rates.


Loading...