@Override public BooleanMatrix combineRow( BooleanMatrix row, BooleanMatrix bm, BooleanMatrix basis, double onesWeight) { int dim = basis.getHeight(); BooleanMatrix combination = new BooleanMatrix(1, dim); HashSet<Integer> remainingIndices = new HashSet<Integer>(); for (int i = 0; i < dim; i++) { remainingIndices.add(i); } Cover cover = new Cover(row.getWidth(), onesWeight); while (true) { double maxUsefulness = Double.NEGATIVE_INFINITY; int bestIndex = -1; for (int i : remainingIndices) { BooleanMatrix basisRow = basis.getRow(i); double usefulness = usefulness(cover, row, basisRow); if (usefulness > maxUsefulness) { maxUsefulness = usefulness; bestIndex = i; } } if (maxUsefulness > 0) { remainingIndices.remove(bestIndex); cover.include(basis.getRow(bestIndex)); combination.update(bestIndex, TRUE); } else { break; } } return combination; }
public static void main(String[] args) { CoverDownloader cd = new CoverDownloader(); List covers = cd.search("yes", "yessongs"); System.out.println(covers.size() + " matches"); Iterator it = covers.iterator(); int i = 0; while (it.hasNext()) { Cover cover = (Cover) it.next(); System.out.println(cover); try { cover.saveAs(new File("/home/kikidonk/test-" + i + ".jpg")); } catch (CoverException e) { System.err.println("Could not save cover: \n" + cover); } i++; } }