public void setup(final EvolutionState state, final Parameter base) {
    super.setup(state, base);

    Parameter def = defaultBase();
    Parameter p = base.push(P_NODESELECTOR).push("0");
    Parameter d = def.push(P_NODESELECTOR).push("0");

    nodeselect1 =
        (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
    nodeselect1.setup(state, p);

    p = base.push(P_NODESELECTOR).push("1");
    d = def.push(P_NODESELECTOR).push("1");

    if (state.parameters.exists(p, d) && state.parameters.getString(p, d).equals(V_SAME))
      // can't just copy it this time; the selectors
      // use internal caches.  So we have to clone it no matter what
      nodeselect2 = (GPNodeSelector) (nodeselect1.clone());
    else {
      nodeselect2 =
          (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
      nodeselect2.setup(state, p);
    }

    numTries = state.parameters.getInt(base.push(P_NUM_TRIES), def.push(P_NUM_TRIES), 1);
    if (numTries == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid number of tries (it must be >= 1).",
          base.push(P_NUM_TRIES),
          def.push(P_NUM_TRIES));

    maxDepth = state.parameters.getInt(base.push(P_MAXDEPTH), def.push(P_MAXDEPTH), 1);
    if (maxDepth == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid maximum depth (it must be >= 1).",
          base.push(P_MAXDEPTH),
          def.push(P_MAXDEPTH));

    maxSize = NO_SIZE_LIMIT;
    if (state.parameters.exists(base.push(P_MAXSIZE), def.push(P_MAXSIZE))) {
      maxSize = state.parameters.getInt(base.push(P_MAXSIZE), def.push(P_MAXSIZE), 1);
      if (maxSize < 1) state.output.fatal("Maximum tree size, if defined, must be >= 1");
    }

    tree1 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0))) {
      tree1 =
          state.parameters.getInt(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0), 0);
      if (tree1 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }

    tree2 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1))) {
      tree2 =
          state.parameters.getInt(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1), 0);
      if (tree2 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }
    tossSecondParent = state.parameters.getBoolean(base.push(P_TOSS), def.push(P_TOSS), false);
  }
Ejemplo n.º 2
0
  public void setup(final EvolutionState state, final Parameter base) {
    super.setup(state, base);

    Parameter def = defaultBase();
    Parameter p = base.push(P_NODESELECTOR).push("0");
    Parameter d = def.push(P_NODESELECTOR).push("0");

    nodeselect1 =
        (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
    nodeselect1.setup(state, p);

    p = base.push(P_NODESELECTOR).push("1");
    d = def.push(P_NODESELECTOR).push("1");

    if (state.parameters.exists(p, d) && state.parameters.getString(p, d).equals(V_SAME))
      // can't just copy it this time; the selectors
      // use internal caches.  So we have to clone it no matter what
      nodeselect2 = (GPNodeSelector) (nodeselect1.clone());
    else {
      nodeselect2 =
          (GPNodeSelector) (state.parameters.getInstanceForParameter(p, d, GPNodeSelector.class));
      nodeselect2.setup(state, p);
    }

    numTries = state.parameters.getInt(base.push(P_NUM_TRIES), def.push(P_NUM_TRIES), 1);
    if (numTries == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid number of tries (it must be >= 1).",
          base.push(P_NUM_TRIES),
          def.push(P_NUM_TRIES));

    maxDepth = state.parameters.getInt(base.push(P_MAXDEPTH), def.push(P_MAXDEPTH), 1);
    if (maxDepth == 0)
      state.output.fatal(
          "GPCrossover Pipeline has an invalid maximum depth (it must be >= 1).",
          base.push(P_MAXDEPTH),
          def.push(P_MAXDEPTH));

    maxSize = NO_SIZE_LIMIT;
    if (state.parameters.exists(base.push(P_MAXSIZE), def.push(P_MAXSIZE))) {
      maxSize = state.parameters.getInt(base.push(P_MAXSIZE), def.push(P_MAXSIZE), 1);
      if (maxSize < 1) state.output.fatal("Maximum tree size, if defined, must be >= 1");
    }

    tree1 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0))) {
      tree1 =
          state.parameters.getInt(base.push(P_TREE).push("" + 0), def.push(P_TREE).push("" + 0), 0);
      if (tree1 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }

    tree2 = TREE_UNFIXED;
    if (state.parameters.exists(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1))) {
      tree2 =
          state.parameters.getInt(base.push(P_TREE).push("" + 1), def.push(P_TREE).push("" + 1), 0);
      if (tree2 == -1) state.output.fatal("Tree fixed value, if defined, must be >= 0");
    }
    tossSecondParent = state.parameters.getBoolean(base.push(P_TOSS), def.push(P_TOSS), false);

    GPInitializer initializer = ((GPInitializer) state.initializer);
    fs = initializer.treeConstraints[0].functionset;

    templateTree = (GPNode) (((GPNode[]) fs.nodesByName.get("+"))[0]).lightClone();
    GPNode left = (GPNode) (((GPNode[]) fs.nodesByName.get("*"))[0]).lightClone();
    GPNode right = (GPNode) (((GPNode[]) fs.nodesByName.get("*"))[0]).lightClone();
    // RegERC ercNode1 = (RegERC)((((GPNode[])fs.nodesByName.get("ERC"))[0]).lightClone());
    //
    // generate TR node that will be replated by random tree
    // GPNode TRNode = new GPNode();
    // ercNode.constraints = 6;
    // ercNode.children = new GPNode[0];

    templateTree.children = new GPNode[2];
    templateTree.children[0] = left;
    templateTree.children[1] = right;

    left.children = new GPNode[2];
    left.children[0] = null;
    left.children[1] = null;

    right.children = new GPNode[2];
    right.children[0] = null;
    right.children[1] = null;
  }