public List<Move> createMoveList(NQueens nQueens) { List<Move> moveList = new ArrayList<Move>(); for (Queen queen : nQueens.getQueenList()) { for (Row toRow : nQueens.getRowList()) { moveList.add(new RowChangeMove(queen, toRow)); } } return moveList; }
private List<Queen> createQueenList(NQueens nQueens) { int n = nQueens.getN(); List<Queen> queenList = new ArrayList<Queen>(n); long id = 0; for (Column column : nQueens.getColumnList()) { Queen queen = new Queen(); queen.setId(id); id++; queen.setColumn(column); // Notice that we leave the PlanningVariable properties on null queenList.add(queen); } return queenList; }
public NQueens createNQueens(int n) { NQueens nQueens = new NQueens(); nQueens.setId(0L); nQueens.setN(n); nQueens.setColumnList(createColumnList(nQueens)); nQueens.setRowList(createRowList(nQueens)); nQueens.setQueenList(createQueenList(nQueens)); BigInteger possibleSolutionSize = BigInteger.valueOf(nQueens.getN()).pow(nQueens.getN()); logger.info( "NQueens {} has {} queens with a search space of {}.", n, nQueens.getN(), AbstractSolutionImporter.getFlooredPossibleSolutionSize(possibleSolutionSize)); return nQueens; }
private List<Row> createRowList(NQueens nQueens) { int n = nQueens.getN(); List<Row> rowList = new ArrayList<Row>(n); for (int i = 0; i < n; i++) { Row row = new Row(); row.setId((long) i); row.setIndex(i); rowList.add(row); } return rowList; }
private List<Column> createColumnList(NQueens nQueens) { int n = nQueens.getN(); List<Column> columnList = new ArrayList<Column>(n); for (int i = 0; i < n; i++) { Column column = new Column(); column.setId((long) i); column.setIndex(i); columnList.add(column); } return columnList; }
public NQueens createNQueens(int n) { NQueens nQueens = new NQueens(); nQueens.setId(0L); nQueens.setN(n); nQueens.setColumnList(createColumnList(nQueens)); nQueens.setRowList(createRowList(nQueens)); nQueens.setQueenList(createQueenList(nQueens)); BigInteger possibleSolutionSize = BigInteger.valueOf(nQueens.getN()).pow(nQueens.getN()); String flooredPossibleSolutionSize = "10^" + (possibleSolutionSize.toString().length() - 1); logger.info( "NQueens {} has {} queens with a search space of {}.", n, nQueens.getN(), possibleSolutionSize.compareTo(BigInteger.valueOf(1000L)) < 0 ? possibleSolutionSize : flooredPossibleSolutionSize); return nQueens; }