Package jcgp.backend.resources

Examples of jcgp.backend.resources.Resources


  private PopulationPane parent;
 
  public ChromosomePane(Chromosome chromosome, GUI gui, PopulationPane parent) {
    super();
   
    final Resources resources = gui.getExperiment().getResources();
    this.parent = parent;
   
    rows = resources.rows();
    columns = resources.columns();
   
    connectionLines = new ArrayList<Line>();
   
    content = new Pane();
    content.setId("content pane for genes");
   
    // generate the GUIGenes
    // inputs
    guiInputs = new GUIInput[resources.inputs()];
    for (int i = 0; i < guiInputs.length; i++) {
      // make the GUI elements
      guiInputs[i] = new GUIInput(this, chromosome.getInput(i));
      content.getChildren().addAll(guiInputs[i]);
    }
    // nodes
    guiNodes = new GUINode[rows][columns];
    double angle, xPos, yPos;
    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < columns; c++) {
        // make the connection lines
        Line lines[] = new Line[resources.arity()];
        for (int l = 0; l < lines.length; l++) {
          angle = ((((double) (l + 1)) / ((double) (lines.length + 1))) * Constants.THETA) - (Constants.THETA / 2);
          xPos = (-Math.cos(angle) * Constants.NODE_RADIUS) + (((c + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
          yPos = (Math.sin(angle) * Constants.NODE_RADIUS) + ((r * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS);
         
          lines[l] = new Line(xPos, yPos, xPos, yPos);
          lines[l].setMouseTransparent(true);
          lines[l].setVisible(false);
          connectionLines.add(lines[l]);
        }
        // make the GUI elements
        guiNodes[r][c] = new GUINode(this, chromosome.getNode(r, c), lines, gui);
      }
      content.getChildren().addAll(guiNodes[r]);
    }
    // outputs
    guiOutputs = new GUIOutput[resources.outputs()];
    for (int i = 0; i < guiOutputs.length; i++) {
      xPos = ((resources.columns() + 1) * (2 * Constants.NODE_RADIUS + Constants.SPACING));
      yPos = (chromosome.getOutput(i).getIndex() * (2 * Constants.NODE_RADIUS + Constants.SPACING)) + Constants.NODE_RADIUS;
      // make the line
      Line line = new Line(xPos, yPos, xPos, yPos);
      line.setMouseTransparent(true);
      line.setVisible(false);
View Full Code Here


   * @param gui a reference to the GUI.
   */
  public TestCaseTable(final TestCaseProblem<Object> testCaseProblem, final GUI gui) {
    super();
   
    Resources resources = gui.getExperiment().getResources();
   
    // create the actual table view
    table = new TableView<TestCase<Object>>();
    // get test cases from problem
    ObservableList<TestCase<Object>> testCaseList = testCaseProblem.getTestCases();
   
    // prepare input and output columns
    ArrayList<TableColumn<TestCase<Object>, String>> inputs = new ArrayList<TableColumn<TestCase<Object>, String>>(resources.inputs());
    ArrayList<TableColumn<TestCase<Object>, String>> outputs = new ArrayList<TableColumn<TestCase<Object>, String>>(resources.outputs());

    // create input columns
    TableColumn<TestCase<Object>, String> tc;
    for (int i = 0; i < resources.inputs(); i++) {
      tc = new TableColumn<TestCase<Object>, String>("I: " + i);
      inputs.add(tc);
      final int index = i;
      tc.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TestCase<Object>,String>, ObservableValue<String>>() {
        @Override
        public ObservableValue<String> call(CellDataFeatures<TestCase<Object>, String> param) {
          // create a new string property and give it the test case value, no need for dynamic binding - this wont change often
          return new SimpleStringProperty(param.getValue().getInputs()[index].toString());
        }
      });
      tc.setSortable(false);
      // set column width so all columns are distributed across the width of the stage
      tc.prefWidthProperty().bind(table.widthProperty().divide(resources.inputs() + resources.outputs()));
    }
   
    // create output columns
    for (int o = 0; o < resources.outputs(); o++) {
      tc = new TableColumn<TestCase<Object>, String>("O: " + o);
      outputs.add(tc);
      final int index = o;
      tc.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TestCase<Object>,String>, ObservableValue<String>>() {
        @Override
        public ObservableValue<String> call(CellDataFeatures<TestCase<Object>, String> param) {
          // create a new string property and give it the test case value, no need for dynamic binding - this wont change often
          return new SimpleStringProperty(param.getValue().getOutputs()[index].toString());
        }
      });
      tc.setSortable(false);
      // set column width so all columns are distributed across the width of the stage
      tc.prefWidthProperty().bind(table.widthProperty().divide(resources.inputs() + resources.outputs()));
    }
   
    // add created columns
    table.getColumns().addAll(inputs);
    table.getColumns().addAll(outputs);
View Full Code Here

    return function.run(args);
  }

  @Override
  public void mutate() {
    Resources resources = chromosome.getResources();
   
    // choose to mutate the function or a connection
    int geneType = resources.getRandomInt(1 + resources.arity());
   
    // if the int is less than 1, mutate function, else mutate connections
    if (geneType < 1) {     
      setFunction(resources.getRandomFunction());
    } else {
      // if we decided to mutate connection, subtract 1 from geneType so it fits into the arity range
      geneType--;
      setConnection(geneType, chromosome.getRandomConnection(column));
    }
View Full Code Here

TOP

Related Classes of jcgp.backend.resources.Resources

Copyright © 2018 www.massapicom. 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.