Examples of VecInstruction


Examples of gpinterpreter.vector.VecInstruction

    public static ClusterHead convertInstructionGene(List<InstructionGene> program, ClusterHead originalTree) {
        VecInterpreter interp = new VecInterpreter(new ArrayList<VecInstruction>(), originalTree.deepCopy());

        int size = originalTree.getSize();

        VecInstruction inst = null;

        for (int i = 0; i < program.size(); i++) {

            Gene g = program.get(i);
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    g.addNode(e);
    g.addNode(f);
   
    tree = new ClusterHead(g);
    VecInstruction[] p = {
        new VecInstruction(MOVE,1,2),
        new VecInstruction(NOP),
        new VecInstruction(NOP)
    };
    program = Arrays.asList(p);
    interpreter = new VecInterpreter(program, tree);
  }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    interpreter.step();
    assertTrue(original.getChildren().size() != tree.getChildren().size());
    //ClusterUtils.prettyPrintTree(tree);
   
    VecInstruction [] p = {
        new VecInstruction(MERGE,2,1),
        new VecInstruction(MERGE,2,3),
        new VecInstruction(MERGE,2,4),
        new VecInstruction(MERGE,2,5),
        new VecInstruction(MERGE,2,6),
        new VecInstruction(MERGE,2,1),
        new VecInstruction(MERGE,2,2)
    };
    tree = new ClusterHead(g);
    program = Arrays.asList(p);
    interpreter = new VecInterpreter(program,tree);
    while(!interpreter.isHalted())
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    int higher = (val >>> 15) & 0x7FFF;

    lower = (lower % (graphSize)) + 1;
    higher = (higher % (graphSize)) + 1;

    return new VecInstruction(operator, lower, higher, -1);

  }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    }

    public SymbolInstructionGene(Configuration aConfiguration)
            throws InvalidConfigurationException {
        super(aConfiguration);
        inst = new VecInstruction(NOP);

    }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    }

    public SymbolInstructionGene(Configuration aConfiguration, int gs)
            throws InvalidConfigurationException {
        super(aConfiguration);
        inst = new VecInstruction(NOP);
        graphSize = gs;

    }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    }

    @Override
    public void applyMutation(int index, double percentage) {

        VecInstruction toMutate = inst;
        double pc = percentage;
        percentage = Math.abs(percentage);

        if (index % 3 == 0) {
            toMutate.setOperand1((int) (Math.abs(toMutate.getOperand1()
                    + (pc * graphSize))));
        } else if (index % 3 == 1) {
            toMutate.setOperand2((int) (Math.abs(toMutate.getOperand2()
                    + (pc * graphSize))));
        } else {
            double places = (symbols.length - 1) * percentage;
            switch (toMutate.getType()) {
                case NOP:
                    places++;
                //case MERGE:
                //    places++;
                //case SPLIT:
                //    places++;
            }
            places = Math.round(places) % (symbols.length);
            toMutate.setType(symbols[(int) places]);

        }


        if (toMutate.getOperand1() == toMutate.getOperand2()) {
            toMutate.setOperand1(toMutate.getOperand1() + 1);
        }



        if (toMutate.getOperand1() <= 0) {
            toMutate.setOperand1(1);
        }
        if (toMutate.getOperand2() <= 0) {
            toMutate.setOperand2(1);
        }


        if (toMutate.getOperand1() > graphSize) {
            toMutate.setOperand1((int) (toMutate.getOperand1() % (double) graphSize));
        }
        if (toMutate.getOperand2() > graphSize) {
            toMutate.setOperand2((int) (toMutate.getOperand2() % (double) graphSize));
        }


    }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

        double places = (symbols.length - 1) * arg0.nextDouble();
        places = Math.abs(Math.round(places) % (symbols.length));
        if (graphSize < 1) {
            Logger.getLogger(SymbolInstructionGene.class.getName()).log(Level.WARNING, "Tried to set a gene to a random value with 0 graph size!");
        }
        inst = new VecInstruction(symbols[(int) places], arg0.nextInt(graphSize) + 1, arg0.nextInt(graphSize) + 1);

        VecInstruction lastInst = inst;
        if (lastInst.getOperand1() <= 0) {
            lastInst.setOperand1(1);
        }
        if (lastInst.getOperand2() <= 0) {
            lastInst.setOperand2(1);
        }
        if (lastInst.getOperand3() <= 0) {
            lastInst.setOperand3(1);
        }

    }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

    return p;
  }
 
  private static Tuple<VecInstruction,String[]> parseExpr(String[] tokens) throws ParseErrorException{
    if(tokens[0].equals("NOP") || tokens[0].equals(""))
      return new Tuple<VecInstruction,String[]>(new VecInstruction(NOP),Arrays.copyOfRange(tokens,1, tokens.length));
   
    if(tokens[0].equals("SPLIT")){
      int operand1;
      try{
        operand1 = Integer.parseInt(tokens[1]);
      }catch(Exception e){
        throw new ParseErrorException("parse failed on operands of SPLIT " + tokens[1]);
      }
      return new Tuple<VecInstruction,String[]>(new VecInstruction(SPLIT,operand1),Arrays.copyOfRange(tokens,2, tokens.length));
     
    }
   
    if(tokens[0].equals("MERGE")){
      //tokens = Arrays.copyOfRange(tokens,1, tokens.length);
      int operand1, operand2;
      try{
        operand1 = Integer.parseInt(tokens[1]);
        operand2 = Integer.parseInt(tokens[2]);
      }catch(Exception e){
        throw new ParseErrorException("parse failed on operands of MERGE " + tokens[1] + " " + tokens[2]);
      }
      return new Tuple<VecInstruction,String[]>(new VecInstruction(MERGE,operand1,operand2),Arrays.copyOfRange(tokens,3, tokens.length));
     
    }
     
    if(tokens[0].equals("MOVE")){
      int operand1, operand2;
      try{
        operand1 = Integer.parseInt(tokens[1]);
        operand2 = Integer.parseInt(tokens[2]);
      }catch(Exception e){

        String toks = "";
        for(String s : tokens) toks += ","+s;
        throw new ParseErrorException("parse failed on operands of MOVE " + tokens.length + "[" + toks +"]" );
       
      }
      return new Tuple<VecInstruction,String[]>(new VecInstruction(MOVE,operand1,operand2),Arrays.copyOfRange(tokens,3, tokens.length));
     
    }
   
    throw new ParseErrorException("Unexpected symbol <" + tokens[0] + ">");
  }
View Full Code Here

Examples of gpinterpreter.vector.VecInstruction

            } else {
                return -1;
            }
        }

        VecInstruction p2 = (VecInstruction) ((SymbolInstructionGene) o).getAllele();

        if (p2 != inst) {
            // do something
            if (p2.getType() == NOP && inst.getType() != NOP) {
                return 1;
            }
            if (inst.getType() == NOP && p2.getType() != NOP) {
                return -1;
            }

        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.