Menu

#46 Create new problem with MOEA

Any Version
open
nobody
None
5
2015-07-09
2015-06-29
Ines
No

Hi I am new user of MOEA, I would like to use NSGAII for generating rules to evaluate interface. I have two objective : detect the maximum of problem and using minimum number of rules. I tried to difine new problem but I am not getting the correct solution yet.Can any one help me to define my own new problem and use it with the NSGAII.

Problem

 Exception in thread "main" org.moeaframework.core.FrameworkException:     java.lang.NoSuchMethodException: No such accessible constructor on object: org.moeaframework.examples.ga.EvaluationRule.Myprob
at org.moeaframework.ProblemBuilder.getProblemInstance(ProblemBuilder.java:296)
at org.moeaframework.Executor.runSingleSeed(Executor.java:657)
at org.moeaframework.Executor.run(Executor.java:629)
at org.moeaframework.examples.ga.EvaluationRule.evaluate.main(evaluate.java:55)
    Caused by: java.lang.NoSuchMethodException: No such accessible constructor on object: org.moeaframework.examples.ga.EvaluationRule.Myprob
at org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor(ConstructorUtils.java:121)
at org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor(ConstructorUtils.java:88)
at org.moeaframework.ProblemBuilder.getProblemInstance(ProblemBuilder.java:287)
... 3 more

I apperciate any suggestions and help.

Discussion

  • Anonymous

    Anonymous - 2015-06-30

    I believe the problem is the Myprob class is nested within the EvaluationRule class. Ensure the Myprob class is public and static:

    public static class Myprob ... {

    }

    If this is unable to resolve the issue, please post the code if able. Thanks!

     
    • Anonymous

      Anonymous - 2017-07-24
      Post awaiting moderation.
  • Anonymous

    Anonymous - 2015-06-30

    thanks a lot for responding, I tried to use pablic and static claas but it also caused a problem

       public  class Myprob implements Problem {
       public  Myprob(int numberOfVariables, int numberOfObjectives) {
        super();
        // TODO Auto-generated constructor stub
    }
    
    ArrayList<Solutions> sols ;
    ArrayList<Rule> rules ;
    ArrayList<String> str ;
    
    public void evaluate(Solution solution) {
        boolean[] d = EncodingUtils.getBinary(solution.getVariable(0));
         int nbr_prob = 0;
         for (int i=0; i<rules.size();i++){
              String Problem=rules.get(i).trg;
              str.add(Problem);   
                }
         for(int i=0; i<str.size();i++)
         {  String str2 = str.get(i);
            for(int j=1; j<str.size()-1;j++)
            { if(str.get(j).compareTo(str2)!=0)
            {  nbr_prob++; }
                }
         }
         solution.setObjective(0, nbr_prob);
         solution.setObjective(0,rules.size());
    
    }
    
    public Solution newSolution() {
        Solution solution = new Solution(1, 2);
        solution.setVariable(0, EncodingUtils.newBinary(rules.size()));     
        return solution;
             }
    
    @Override
    public void close() {
        //do nothing
    }
        @Override
    public String getName() {
        return "Myprob";
    }
    
    @Override
    public int getNumberOfVariables() {
        // TODO Auto-generated method stub
        return 1;
    }
    
    @Override
    public int getNumberOfObjectives() {
        // TODO Auto-generated method stub
        return 2;
    }
    
    @Override
    public int getNumberOfConstraints() {
        // TODO Auto-generated method stub
        return 0;
    }
    
     
  • Anonymous

    Anonymous - 2015-06-30

    Ok, replace the first two lines:

    ~~~~~~~
    public class Myprob implements Problem {
    public Myprob(int numberOfVariables, int numberOfObjectives) {

    with
    

    public static class Myprob implements Problem {
    public Myprob() {
    ~~~~~~

    By default, it's looking for the empty constructor, Myprob(). Since it doesn't appear you use the two arguments, they can be removed.

    If you do require arguments, then you will need to pass those arguments to the Executor, such as new Executor().withProblemClass(Myprob.class, 10, 5), so it can call the appropriate constructor.

     
  • Anonymous

    Anonymous - 2015-06-30

    Sorry, but when I use static it make this error : Illegal modifier for the class Myprob; only public, abstract & final are permitted

     
  • Anonymous

    Anonymous - 2015-06-30

    Ok, try it without the static modifier. Hopefully it works with the empty constructor.

     
  • Anonymous

    Anonymous - 2015-06-30

    I'm not sure what's happening then. Can you please post the Myprob.java file and any other files needed to run this problem (such as the file containing your main method)? (Use the Add attachments link to include any file attachments).

     
  • Anonymous

    Anonymous - 2015-07-01

    Try the following. When you are running the Executor, you are passing in the argument S.create_rules(...) with type ArrayList<Rule>:

    NondominatedPopulation result = new Executor()
        .withProblemClass(Myprob.class, S.create_rules(r, min_rules_size, max_rules_size))
    

    You'll need to have a corresponding constructor in Myprob.java to input this argument:

    public Myprob(ArrayList<Rule> rules) {
        this.rules = rules;
    }
    
     
  • Anonymous

    Anonymous - 2015-07-02

    Thanks a lot this problem is solve. But I dont understand who MOEA can do crossover, mutation... automatically. I create my own fitness function but I dont know when you should put it. I dont understand very well steps necessary to customize MOEA, Please you Can explain that??
    The result now is

    Solution 1:
    Number of problem -8.0
    Number of rules -0.0
    Rules: 10101110

    In Rules: I need to display My rules (String)

     

    Last edit: Anonymous 2015-07-02
  • Anonymous

    Anonymous - 2015-07-02

    The genetic operators are based on the type of your decision variables. Since you are using a binary representation, the MOEA Framework by default uses Half-uniform crossover (HUX) and bit-flip mutation. Refer to the OperatorFactory for more details on the available operators.

    You can customize the MOEA by changing the algorithm's parameters. Use the Executors's withProperty method to achieve this:

    new Executor()
        .withAlgorithm("NSGAII")
        .withProperty("populationSize", 200)
        .withProperty("hux.rate", 0.75)
        .withProperty("bf.rate", 0.1)
        ...
    

    See Chapter 9 in the user manual and the OperatorFactory documentation for more details on the available parameters.

    If you're looking for more customization, you will need to dive into the code. To start, I would suggest looking at the src/org/moeaframework/algorithm/NSGAII.java file to see how a basic MOEA is implemented.

    Good luck!

     

    Last edit: Anonymous 2015-07-02
  • Anonymous

    Anonymous - 2015-07-02

    No, the MOEA Framework supports real, binary, permutation, grammar, and program representations. Refer to this table to see which representations are supported by each algorithm.

     
  • Anonymous

    Anonymous - 2015-07-03

    Hi, I try to use Grammar representation because I need to generate rules :
    IF A and B then Prob i
    I evaluate the derivation using the Groovy scripting language but I have problem. Please find the attached files.
    The problem is that i'm getting the following error:

        Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No   such property: M for class: Script57
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:339)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:132)
    ... 8 more
        Caused by: groovy.lang.MissingPropertyException: No such property: M for class: Script57
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
    at Script57.run(Script57.groovy:1)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:336)
    ... 9 more
        javax.script.ScriptException: javax.script.ScriptException:  groovy.lang.MissingPropertyException: No such property: H for class: Script56
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:138)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at org.moeaframework.examples.ga.EvaluationRule.Myprob2.evaluate(Myprob2.java:94)
    at org.moeaframework.util.distributed.DistributedProblem$ProblemEvaluator.call(DistributedProblem.java:99)
    at org.moeaframework.util.distributed.DistributedProblem$ProblemEvaluator.call(DistributedProblem.java:1)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
        Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: H for class: Script56
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:339)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:132)
    ... 8 more
        Caused by: groovy.lang.MissingPropertyException: No such property: H for class:   Script56
    at   org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
    at Script56.run(Script56.groovy:1)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:336)
    ... 9 more
        javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
        Script64.groovy: 1: unexpected token: Cont @ line 1, column 4.
        IF Cont > H and metr > source_index Then prob
        ^
        1 error
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:138)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at org.moeaframework.examples.ga.EvaluationRule.Myprob2.evaluate(Myprob2.java:94)
    at org.moeaframework.util.distributed.DistributedProblem$ProblemEvaluator.call(DistributedProblem.java:99)
    at org.moeaframework.util.distributed.DistributedProblem$ProblemEvaluator.call(DistributedProblem.java:1)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
        Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup   failed:
        Script64.groovy: 1: unexpected token: Cont @ line 1, column 4.
        IF Cont > H and metr > source_index Then prob
        ^
        1 error
    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
    at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
    at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)
    at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:141)
    at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107)
    at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
    at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:161)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:900)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:564)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:540)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:517)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:283)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:264)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:202)
    at
        .............................
    
     
  • Anonymous

    Anonymous - 2015-07-08

    Hi, I see two issues in the files posted. First, it doesn't appear to be generating valid Groovy code. According to http://www.groovy-lang.org/semantics.html, the <rule> should be:

    "<rules> ::= 'if (' ' ' <context> ' ' <op>  ' ' <val> ' && ' <metrics>' ' <op> ' '<val1> ') ' <problem> \n" + 
    

    Second, whenever you see an exception saying No such property: M, it is indicating that one of the variables in the Groovy code is undefined. In this example, the variable M is missing. The bindings for these variables must be set:

    Bindings b = new SimpleBindings();
    ...
    b.put("M", ...);
    
     
  • Anonymous

    Anonymous - 2015-07-08

    what's wrong with this part ?? result is emplty

    ScriptEngineManager sem = new ScriptEngineManager();
    ScriptEngine engine = sem.getEngineByName("JAVASCRIPT");
    // initialize the variables used by the program
    Bindings b = new SimpleBindings();
    b.put("Cont", Input.Context()[source_index0]);
    b.put("level", Input.ValuesOfContext( [source_index3]);
    b.put("metr", Input.Metrics()[source_index1]);
    b.put("operator", Input.Operator()[source_index4]);
    b.put("source_index", number_generator.nextDouble());
    b.put("prob", Input.Problem()[source_index2]);
    try {
    result = ((String)engine.eval(program, b)).toString();
    // System.out.println("######"+result);
    } catch (ScriptException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

     

    Last edit: Anonymous 2015-07-08
  • Anonymous

    Anonymous - 2015-07-09

    Not 100% sure, but my guess is that since your expression is if (A and B) then C, it only returns a result, C, when conditions A and B are satisfied. If not satisfied, it returns null.

     
  • Anonymous

    Anonymous - 2015-07-09

    I tried to solve my problem with Jmetal (for mono-objective algorithm), but I need to use multi-objective algorithm, I heard about MOEA So I tried tu use it for the same problem with NSGA2.
    I need to generate this rules :
    IF (Interest=L) and ( Simplicity<0.14395609003413368 ) THEN ( Problem6 )
    IF (Age=H) and ( Symmetry<=0.9696987668669881 ) THEN ( Problem5 )
    IF (User Experience=M) and ( Unity>=0.6906152578571493 ) THEN ( Problem4 )
    IF (Education Level=L) and ( Regularity<=0.29971648662249517 ) THEN ( Problem5 )
    IF (User Experience=H) and ( Sequence>0.6977428629106479 ) THEN ( Problem4 )
    IF (Age=H) and ( Regularity<=0.4017929040344044 ) THEN ( Problem5 )
    IF (Motivation=M) and ( Simplicity<0.645669980192507 ) THEN ( Problem2 )
    IF (User Experience=L) and ( Symmetry>0.7240407949705044 ) THEN ( Problem4 )
    IF (Education Level=H) and ( Grouping<=0.9733628578631573 ) THEN ( Problem5 )
    IF (User Experience=M) and ( Simplicity<0.256567413247895 ) THEN ( Problem5 )

    In my case individual is :

    IF (Interest=L) and ( Simplicity<0.14395609003413368 ) THEN ( Problem6 )

    For this reason I choose Grammar representation to define my individuals and use it with NSAG2 algorithm.
    I need to generate set of perfect rules which detect maximum of problem.
    With Jmetal I generate this rules automatically and randomly then I choose the perfect rules (by using fitness function). Please , is it possible to solve this problem with MOEA ??? Grammar repsentation Let me to difine and generate this rule automacally ?? Please I don't know If I'm in the right way or no ??

     
  • Anonymous

    Anonymous - 2015-07-09

    You can definitely use the grammar representation to define these rules. However, it sounds like you already have this working in JMetal. JMetal also supports multi-objective algorithms, so you may be better off using JMetal's NSGA-II implementation since you already have working code there.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.