private void addNode() { int connectionIndex = this.randomGenerator.nextInt(this.connections.size()); Connection connection = this.connections.get(connectionIndex); connection.disable(); int nodeId = (this.hiddenNodes.isEmpty() ? this.outputNodes.get(this.outputNodes.size() - 1).getId() : this.hiddenNodes.get(this.hiddenNodes.size() - 1).getId()) + 1; this.hiddenNodes.add(new Node(nodeId, NodeType.HIDDEN)); this.connections.add(new Connection(connection.getFrom(), nodeId, 1)); this.connections.add(new Connection(nodeId, connection.getTo(), connection.getWeight())); }
private void addConnection() { // find unconnectedNodes int toCount = this.hiddenNodes.size() + this.outputNodes.size(); int fromCount = this.inputNodes.size() + toCount; // default boolean value is false boolean[][] connectivityMatrix = new boolean[fromCount][toCount]; for (Connection connection : this.connections) { int from = this.translateNodeIdToCoordinate(connection.getFrom(), true); int to = this.translateNodeIdToCoordinate(connection.getTo(), false); connectivityMatrix[from][to] = true; } List<Connection> connections = new LinkedList<Connection>(); for (int from = 0; from < connectivityMatrix.length; ++from) { for (int to = 0; to < connectivityMatrix[0].length; ++to) { if (!connectivityMatrix[from][to]) { int fromId = this.translateCoordinateToNodeId(from, true); int toId = this.translateCoordinateToNodeId(to, false); connections.add(new Connection(fromId, toId)); } } } int connectionIndex = this.randomGenerator.nextInt(connections.size()); this.connections.add(connections.get(connectionIndex)); }