public static Move getRandomMoveWithoutMutation(Graph g, int numOfMoves, int weightLevels) { Move moves = new Move(); RandomVertexIterator it = new RandomVertexIterator(g); while (moves.getVerticesCount() < numOfMoves) { // TODO: Something must be done to allow selecting less than numOfMoves vertices. moves.putVertex(it.next(), RandomHelper.getRandom().nextInt(weightLevels) + 1); } return moves; }
public static Move getRandomMoveWithMutation( Graph g, int numOfMoves, int weightLevels, Move lastMove) { double jump_probability = 0.2; // TODO: Make it an option, or even better adaptive since it should depend on the // diameter of the graph Move moves = new Move(); // TODO: This loop is problematic. There is a chance that 2 nodes surf to the same node and thus // create a move with less than numOfMoves nodes. // TODO: If this happens, it will never increase the nodes again for (Vertex mp : lastMove) { RandomSurferIterator randomSurfer = new RandomSurferIterator(g, 0.0, mp); while (RandomHelper.getRandom().nextDouble() < jump_probability) { mp = randomSurfer.next(); } moves.putVertex(mp, RandomHelper.getRandom().nextInt(weightLevels) + 1); } return moves; }