Exemple #1
0
def get_best(preference_text, record_list):
    '''
    Get best records according to CPTheory (classical algorithm)

    A record is best if it is not dominated by any other record
    '''
    # build theory
    theory = build_cptheory(preference_text)
    theory.split_rules()
    if not theory.is_consistent():
        return []
    result, _ = get_best_and_worst(theory, record_list)
    return result
Exemple #2
0
def get_mtopk_partition(preference_text, record_list, k):
    '''
    Returns the top-k records (partition algorithm)
    '''
    theory = build_cptheory(preference_text)
    theory.split_rules()
    if not theory.is_consistent():
        return []
    # Build formulas
    theory.build_formulas()
    # Build comparisons
    theory.build_comparisons()
    # Apply algorithm
    result = partition_mtopk(theory, record_list, k)
    return result
Exemple #3
0
def get_mbest_partition(preference_text, record_list):
    '''
    Get best records according to CPTheory (partition algorithm)
    A record is best if it is not dominated by any other record
    '''
    theory = build_cptheory(preference_text)
    theory.split_rules()
    if not theory.is_consistent():
        return []
    # Build formulas
    theory.build_formulas()
    # Build comparisons from formulas
    theory.build_comparisons()
    # Apply partition algorithm
    result = partition_mbest(theory, record_list)
    return result
Exemple #4
0
def get_topk(preference_text, record_list, k):
    '''
    Returns the top-k records with lowest level according to a cp-theory
    '''
    # build theory
    theory = build_cptheory(preference_text)
    theory.split_rules()
    if not theory.is_consistent():
        return []
    worst_list = record_list
    topk_list = []
    while len(topk_list) < k and worst_list:
        best_list, worst_list = get_best_and_worst(theory, worst_list)
        topk_list += best_list
    if len(topk_list) > k:
        topk_list = topk_list[:k]
    return topk_list