001/** 002 * BoundedGreedySelection.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-Garc�a. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 05/11/2007 008 */ 009package es.ucm.fdi.gaia.jcolibri.method.retrieve.selection.diversity; 010 011import java.util.ArrayList; 012import java.util.Collection; 013import java.util.List; 014 015import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRCase; 016import es.ucm.fdi.gaia.jcolibri.cbrcore.CBRQuery; 017import es.ucm.fdi.gaia.jcolibri.method.retrieve.RetrievalResult; 018import es.ucm.fdi.gaia.jcolibri.method.retrieve.NNretrieval.NNConfig; 019import es.ucm.fdi.gaia.jcolibri.method.retrieve.selection.SelectCases; 020 021/** 022 * Tries to reduce the complexity of the greedy selection algorithm first selecting 023 * the best b�k cases according to their similarity to the query and then applies 024 * the greedy selection method to these cases. 025 * <p>See: 026 * <p> 027 * B. Smyth and P. McClave. Similarity vs. diversity. In ICCBR '01: Proceedings 028 * of the 4th International Conference on Case-Based Reasoning, pages 347-361, 029 * London, UK, 2001. Springer-Verlag. 030 * @author Juan A. Recio-Garcia 031 * @author Developed at University College Cork (Ireland) in collaboration with Derek Bridge. 032 * @version 1.0 033 * 034 */ 035public class BoundedGreedySelection 036{ 037 038 /** 039 * Executes the algorithm 040 * @param cases to retrieve from 041 * @param query to compare 042 * @param simConfig is the knn config that defines the k returned cases 043 * @param bound to create the bounded retrieval set 044 * @param k is the number of cases to select 045 * @return k cases 046 */ 047 public static Collection<CBRCase> boundedGreddySelection(Collection<RetrievalResult> cases, CBRQuery query, NNConfig simConfig, int k, int bound) { 048 049 Collection<CBRCase> C = SelectCases.selectTopK(cases, bound*k); 050 051 List<CBRCase> R = new ArrayList<>(); 052 053 for(int i=0; (i<k) && (!C.isEmpty()); i++) { 054 CBRCase best = GreedySelection.getMoreQuality(query, C, R, simConfig); 055 R.add(best); 056 C.remove(best); 057 } 058 059 return R; 060 } 061}