Package jcgp.backend.population

Examples of jcgp.backend.population.Connection


      @Override
      public void handle(MouseDragEvent event) {
        // the drag has entered this node, react appropriately
        // this happens even if we are the source of the drag
        ((GUIGene) event.getGestureSource()).setConnectionLine((GUIGene) event.getSource());
        Connection source = ((GUIGene) event.getGestureSource()).getChangingConnection();
        if (input == source) {
          setState(GUIGeneState.NO_CHANGE_TARGET);
        } else {
          setState(GUIGeneState.VALID_TARGET);
        }
      }
    });

    addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
      @Override
      public void handle(MouseDragEvent event) {
        // the drag has exited this node, react appropriately
        // this happens even if we are the source of the drag
        parent.setTarget(false);
        if (event.isPrimaryButtonDown()) {
          if (getState() == GUIGeneState.NO_CHANGE_TARGET) {
            setState(GUIGeneState.INDIRECT_HOVER);
          } else {
            setState(GUIGeneState.NEUTRAL);
            ((GUIGene) event.getGestureSource()).setConnectionStates(GUIGeneState.INDIRECT_HOVER);
          }
        }
      }

    });

    addEventFilter(MouseDragEvent.MOUSE_DRAG_RELEASED, new EventHandler<MouseDragEvent>() {
      @Override
      public void handle(MouseDragEvent event) {
        GUIGene source = ((GUIGene) event.getGestureSource());
        // set states to reflect the new situation
        if (source.isLocked()) {
          source.setState(GUIGeneState.HOVER);
          source.setConnectionStates(GUIGeneState.HOVER);
        } else {
          source.setState(GUIGeneState.NEUTRAL);
          source.setConnectionStates(GUIGeneState.NEUTRAL);
        }
       
        // the user released the drag gesture on this node, react appropriately
        if (source.isLocked()) {
          // remove locks from the old connection, add the to the new
          // note that the old connection may still have locks after this
          parent.getGuiGene(source.getChangingConnection()).removeLocks(source.getLocks());
          source.setChangingConnection(input);
          addLocks(source.getLocks());
        } else {
          source.setChangingConnection(input);
        }

        source.updateLines();
        setState(GUIGeneState.HOVER);     
      }
    });
   
    addEventFilter(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
View Full Code Here


      in = new Scanner(fr);
     
      resources.println("[Parser] Parsing file: " + file.getAbsolutePath() + "...");
     
      int gene;
      Connection newConnection;
      Node changingNode;
      // for all nodes, columns first
      for (int c = 0; c < resources.columns(); c++) {
        for (int r = 0; r < resources.rows(); r++) {
          // store the changing node
View Full Code Here

    // for all nodes, columns first
    for (int c = 0; c < resources.columns(); c++) {
      for (int r = 0; r < resources.rows(); r++) {
        for (int i = 0; i < resources.arity(); i++) {
          // print the connections, separated by spaces
          Connection conn = chromosome.getNode(r, c).getConnection(i);
          if (conn instanceof Input) {
            writer.print(" " + ((Input) conn).getIndex());
          } else if (conn instanceof Node) {
            writer.print(" " + (((((Node) conn).getColumn() + 1) * resources.inputs()) + ((Node) conn).getRow()));
          } else {
            resources.println("[Parser] Error: could not handle " + conn.getClass() + " as a subclass of Connection");
          }
        }
        // print the function numbers
        writer.print(" " + resources.getFunctionIndex(chromosome.getNode(r, c).getFunction()));
        // node is done, print tab
        writer.print("\t");
      }
    }
    // nodes are done, print two tabs to separate from output
    writer.print("\t\t");
    for (int o = 0; o < resources.outputs(); o ++) {
      Connection source = chromosome.getOutput(o).getSource();
      if (source instanceof Input) {
        writer.print(" " + ((Input) source).getIndex());
      } else if (source instanceof Node) {
        writer.print(" " + (((((Node) source).getColumn() + 1) * resources.inputs()) + ((Node) source).getRow()));
      } else {
        resources.println("[Parser] Error: could not handle " + source.getClass() + " as a subclass of Connection");
      }
    }
   
    writer.close();
   
View Full Code Here

    // for all nodes, columns first
    for (int c = 0; c < resources.columns(); c++) {
      for (int r = 0; r < resources.rows(); r++) {
        for (int i = 0; i < resources.arity(); i++) {
          // print the connections, separated by spaces
          Connection conn = chromosome.getNode(r, c).getConnection(i);
          if (conn instanceof Input) {
            resources.print(" " + ((Input) conn).getIndex());
          } else if (conn instanceof Node) {
            resources.print(" " + (((((Node) conn).getColumn() + 1) * resources.inputs()) + ((Node) conn).getRow()));
          } else {
            resources.println("[Parser] Error: could not handle " + conn.getClass() + " as a subclass of Connection");
          }
        }
        // print the function numbers
        resources.print(" " + resources.getFunctionIndex(chromosome.getNode(r, c).getFunction()));
        // node is done, print tab
        resources.print("\t");
      }
    }
    // nodes are done, print two tabs to separate from output
    resources.print("\t\t");
    for (int o = 0; o < resources.outputs(); o ++) {
      Connection source = chromosome.getOutput(o).getSource();
      if (source instanceof Input) {
        resources.print(" " + ((Input) source).getIndex());
      } else if (source instanceof Node) {
        resources.print(" " + (((((Node) source).getColumn() + 1) * resources.inputs()) + ((Node) source).getRow()));
      } else {
        resources.println("[Parser] Error: could not handle " + source.getClass() + " as a subclass of Connection");
      }
    }
   
    resources.println("");
  }
View Full Code Here

  @Before
  public void setUp() throws Exception {
    node = new Node(chromosome, 0, 0);
    // make node with addition function and hard-coded value connections
    node.initialise(resources.getFunction(0),
        new Connection[]{new Connection() {

          @Override
          public Object getValue() {
            // hardcode a value
            return arg1;
          }
        },
        new Connection() {

          @Override
          public Object getValue() {
            // hardcode a value
            return arg2;
View Full Code Here

  }

  @Test
  public void connectionsTest() {
    // make new blank connections, check that they are returned correctly when addressed
    Connection conn0, conn1, conn2;
    conn0 = new Connection() {

      @Override
      public Object getValue() {
        // blank
        return 0;
      }
    };
    conn1 = new Connection() {

      @Override
      public Object getValue() {
        // blank
        return 0;
      }
    };
   
    Function function = new Function() {
      @Override
      public Object run(Object... connections) {
        // blank
        return null;
      }

      @Override
      public int getArity() {
        return 2;
      }
    };
   
    node.initialise(function, conn0, conn1);

    assertTrue("Connection 0 is incorrect.", node.getConnection(0) == conn0);
    assertTrue("Connection 1 is incorrect.", node.getConnection(1) == conn1);

    // make yet another connection, set it randomly, check that it is one of the node's connections
    conn2 = new Connection() {

      @Override
      public Object getValue() {
        // blank
        return 0;
View Full Code Here

  }

  @Test
  public void evaluationsTest() {
    // set source connection, check that the appropriate value is returned
    output.setSource(new Connection() {

      @Override
      public Object getValue() {
        // test value
        return outputValue;
View Full Code Here

  }

  @Test
  public void connectionTest() {
    // set a new connection, check that it is correctly returned
    Connection newConn = new Connection() {

      @Override
      public Object getValue() {
        // blank
        return 0;
View Full Code Here

    // get random connections with the last column as reference, check that they're all within range
    int connectionNodes = 0, connectionOutOfRange = 0, connectionInputs = 0, connectionPicks = 100000;
    int chosenColumn = resources.columns() - 1;
    for (int i = 0; i < connectionPicks; i++) {
      Connection c = chromosome.getRandomConnection(chosenColumn);
      if (c instanceof Node) {
        connectionNodes++;
        if (((Node) c).getColumn() >= chosenColumn) {
          connectionOutOfRange++;
        }
View Full Code Here

        // the drag has entered this node, react appropriately
        // this happens even if we are the source of the drag
        if (isAllowed((GUIGene) event.getGestureSource(), (GUIGene) event.getSource())) {
          ((GUIGene) event.getGestureSource()).setConnectionLine((GUIGene) event.getSource());
         
          Connection source = ((GUIGene) event.getGestureSource()).getChangingConnection();
          if (node == source) {
            setState(GUIGeneState.NO_CHANGE_TARGET);
          } else {
            setState(GUIGeneState.VALID_TARGET);
          }
        } else {
          setState(GUIGeneState.INVALID_TARGET);
        }
      }
    });

    addEventFilter(MouseDragEvent.MOUSE_DRAG_EXITED, new EventHandler<MouseDragEvent>() {
      @Override
      public void handle(MouseDragEvent event) {
        // the drag has exited this node, react appropriately
        // this happens even if we are the source of the drag
        parent.setTarget(false);
        if (event.isPrimaryButtonDown()) {
          if (event.getGestureSource() == event.getSource()) {
            setState(GUIGeneState.SOURCE);
          } else {
            if (getState() == GUIGeneState.NO_CHANGE_TARGET) {
              setState(GUIGeneState.INDIRECT_HOVER);
            } else {
              setState(GUIGeneState.NEUTRAL);
              ((GUIGene) event.getGestureSource()).setConnectionStates(GUIGeneState.INDIRECT_HOVER);
            }
          }
        }
      }
    });

    addEventFilter(MouseDragEvent.MOUSE_DRAG_RELEASED, new EventHandler<MouseDragEvent>() {
      @Override
      public void handle(MouseDragEvent event) {
        GUIGene source = ((GUIGene) event.getGestureSource());
        // set states to reflect the new situation
        if (source.isLocked()) {
          source.setState(GUIGeneState.HOVER);
          source.setConnectionStates(GUIGeneState.HOVER);
        } else {
          source.setState(GUIGeneState.NEUTRAL);
          source.setConnectionStates(GUIGeneState.NEUTRAL);
        }

        // the user released the drag gesture on this node, react appropriately
        if (isAllowed((GUIGene) event.getGestureSource(), (GUIGene) event.getSource())) {
          if (source.isLocked()) {
            // remove locks from the old connection, add the to setConnethe new
            // note that the old connection may still have locks after this
            parent.getGuiGene(source.getChangingConnection()).removeLocks(source.getLocks());
            addLocks(source.getLocks());
          } else {
            if (source instanceof GUIOutput) {
              source.resetState();
            }
          }
          source.setChangingConnection(node);

        }
        source.updateLines();
        setState(GUIGeneState.HOVER);
      }
    });

    addEventFilter(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
View Full Code Here

TOP

Related Classes of jcgp.backend.population.Connection

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.