10.1. The AbstractProblem Class

 

          If we study the problem.java code, in JGDS v3.5 or update version, we will see a set of procedures and funtions that belong to the several implemented problems. The main procedures, that are common to all the implemented problems, have been extracted from Problem class to create a new class named AbstractProblem. This class contains the procedures and functions that must be implemented in all the problems code, and these may be considered as the kernel of every problem. Also, we added two functions to control the evaluations counter.


public class AbstractProblem {

     static int evals;

     public AbstractProblem()
     { this.evals=0;}


     public void print_solution(Individual indiv)
     { }

     public double evaluate(Individual indiv)
     { return 0.0; }

     public int get_num_evals()
     { return evals; }

     public int up_num_evals()
     { return evals++;}

}

AbstractProblem class implementation

          Therefore, every problem must compulsorily have a print_solution procedure and a evaluate function. The Problem class will call to the AbstractProblem constructor inside of its constructor. In the following table we can see underlining the modifications made in the Problem class

public class Problem extends AbstractProblem implements Constants
{
     // Variables must be static if they are used in subclasses
     static byte PROBLEM_TYPE;
     static byte FITNESS_FUNCTION;
     static double SOLUTION_FITNESS;
     private static AbstractProblem abs_problem;


     public Problem()
     { abs_problem=new AbstractProblem(); }


     public Problem(byte PROBLEM_TYPE,byte FITNESS_FUNCTION,double                                       SOLUTION_FITNESS)
     {
       this.PROBLEM_TYPE = PROBLEM_TYPE;
       this.FITNESS_FUNCTION = FITNESS_FUNCTION;
       this.SOLUTION_FITNESS = SOLUTION_FITNESS;
       abs_problem=new AbstractProblem();
     }

[...]

Changes made in Problem class

 

 

 

[Previous][Index][Home][Next]