def get_alternatives_positive_flows(*args, **kwargs): alternativesID = px.getAlternativesID(trees['alternatives']) flows = px.getAlternativeValue(trees['positive_flows'], alternativesID,) return flows
def get_categories_positive_flows(*args, **kwargs): profilesID = get_categories() flows = px.getAlternativeValue(trees['positive_flows'], profilesID,) return flows
def get_input_data(input_dir, filenames, params, **kwargs): trees = _get_trees(input_dir, filenames) d = _create_data_object(params) for p in params: if p == "alternatives": d.alternatives = px.getAlternativesID(trees["alternatives"]) elif p == "profiles": d.profiles = px.getProfilesID(trees["profiles"]) elif p == "categories_profiles": comparison_with = kwargs.get("comparison_with") if comparison_with is None: comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") d.categories_profiles = _get_categories_profiles(trees.get("categories_profiles"), comparison_with) elif p == "categories_rank": categories = px.getCategoriesID(trees["categories"]) d.categories_rank = px.getCategoriesRank(trees["categories"], categories) elif p == "comparison_with": d.comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") elif p == "concordance": alternatives = px.getAlternativesID(trees["alternatives"]) comparison_with = kwargs.get("comparison_with") if trees.has_key("methos_parameters"): comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") if kwargs.get("use_partials") is not None: use_partials = kwargs.get("use_partials") else: if trees.has_key("methos_parameters"): parameter = px.getParameterByName(trees["method_parameters"], "use_partials") use_partials = True if parameter == "true" else False categories_profiles = None profiles = None if comparison_with in ("boundary_profiles", "central_profiles"): categories_profiles = _get_categories_profiles(trees["categories_profiles"], comparison_with) if comparison_with == "profiles": profiles = px.getProfilesID(trees["profiles"]) d.concordance = _get_alternatives_comparisons( trees["concordance"], alternatives, profiles=profiles, categories_profiles=categories_profiles, use_partials=use_partials, ) elif p == "crisp_concordance": alternatives = px.getAlternativesID(trees["alternatives"]) comparison_with = kwargs.get("comparison_with") if trees.has_key("methos_parameters"): comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") if kwargs.get("use_partials") is not None: use_partials = kwargs.get("use_partials") else: if trees.has_key("methos_parameters"): parameter = px.getParameterByName(trees["method_parameters"], "use_partials") use_partials = True if parameter == "true" else False categories_profiles = None profiles = None if comparison_with in ("boundary_profiles", "central_profiles"): categories_profiles = _get_categories_profiles(trees["categories_profiles"], comparison_with) if comparison_with == "profiles": profiles = px.getProfilesID(trees["profiles"]) d.concordance = _get_alternatives_comparisons( trees["concordance"], alternatives, profiles=profiles, categories_profiles=categories_profiles, use_partials=use_partials, use_value=False, ) elif p == "credibility": alternatives = px.getAlternativesID(trees["alternatives"]) comparison_with = kwargs.get("comparison_with") if not comparison_with: comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") if comparison_with in ("boundary_profiles", "central_profiles"): categories_profiles = _get_categories_profiles(trees["categories_profiles"], comparison_with) else: categories_profiles = None eliminate_cycles_method = px.getParameterByName(trees.get("method_parameters"), "eliminate_cycles_method") tree = trees.get("credibility") if eliminate_cycles_method == "cut_weakest" and tree is None: raise RuntimeError( "'cut_weakest' option requires credibility as " "an additional input (apart from outranking)." ) d.credibility = _get_alternatives_comparisons(tree, alternatives, categories_profiles=categories_profiles) elif p == "criteria": if trees.has_key("criteria"): d.criteria = px.getCriteriaID(trees["criteria"]) elif p == "cut_threshold": cut_threshold = px.getParameterByName(trees["method_parameters"], "cut_threshold") if cut_threshold is None or not (0 <= float(cut_threshold) <= 1): raise RuntimeError( "'cut_threshold' should be in range [0, 1] " "(most commonly used values are 0.6 or 0.7)." ) d.cut_threshold = cut_threshold # 'cv_crossed' == 'counter-veto crossed' elif p == "cv_crossed": alternatives = px.getAlternativesID(trees["alternatives"]) comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") if comparison_with in ("boundary_profiles", "central_profiles"): categories_profiles = _get_categories_profiles(trees["categories_profiles"], comparison_with) else: categories_profiles = None d.cv_crossed = _get_alternatives_comparisons( trees["counter_veto_crossed"], alternatives, categories_profiles=categories_profiles, use_partials=True, mcda_concept="counterVetoCrossed", ) elif p == "discordance": alternatives = px.getAlternativesID(trees["alternatives"]) comparison_with = kwargs.get("comparison_with") if trees.has_key("methos_parameters"): comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") if kwargs.get("use_partials") is not None: use_partials = kwargs.get("use_partials") else: if trees.has_key("methos_parameters"): parameter = px.getParameterByName(trees["method_parameters"], "use_partials") use_partials = True if parameter == "true" else False categories_profiles = None profiles = None if comparison_with in ("boundary_profiles", "central_profiles"): categories_profiles = _get_categories_profiles(trees["categories_profiles"], comparison_with) if comparison_with == "profiles": profiles = px.getProfilesID(trees["profiles"]) d.discordance = _get_alternatives_comparisons( trees["discordance"], alternatives, profiles=profiles, categories_profiles=categories_profiles, use_partials=use_partials, ) elif p == "crisp_discordance": alternatives = px.getAlternativesID(trees["alternatives"]) comparison_with = kwargs.get("comparison_with") if trees.has_key("methos_parameters"): comparison_with = px.getParameterByName(trees["method_parameters"], "comparison_with") if kwargs.get("use_partials") is not None: use_partials = kwargs.get("use_partials") else: if trees.has_key("methos_parameters"): parameter = px.getParameterByName(trees["method_parameters"], "use_partials") use_partials = True if parameter == "true" else False categories_profiles = None profiles = None if comparison_with in ("boundary_profiles", "central_profiles"): categories_profiles = _get_categories_profiles(trees["categories_profiles"], comparison_with) if comparison_with == "profiles": profiles = px.getProfilesID(trees["profiles"]) d.discordance = _get_alternatives_comparisons( trees["discordance"], alternatives, profiles=profiles, categories_profiles=categories_profiles, use_partials=use_partials, use_value=False, ) elif p == "preorder": if trees.has_key("preorder"): alternatives = px.getAlternativesID(trees["alternatives"]) d.preorder = px.getAlternativeValue(trees["preorder"], alternatives, None) elif p == "downwards": alternatives = px.getAlternativesID(trees["alternatives"]) d.downwards = px.getAlternativeValue(trees["downwards"], alternatives, None) elif p == "upwards": alternatives = px.getAlternativesID(trees["alternatives"]) d.upwards = px.getAlternativeValue(trees["upwards"], alternatives, None) elif p == "eliminate_cycles_method": d.eliminate_cycles_method = px.getParameterByName(trees["method_parameters"], "eliminate_cycles_method") elif p == "interactions": criteria = px.getCriteriaID(trees["criteria"]) d.interactions = _get_criteria_interactions(trees["interactions"], criteria) elif p == "outranking": alternatives = px.getAlternativesID(trees["alternatives"]) outranking = _get_intersection_distillation(trees["outranking"], alternatives) if outranking == None: outranking = px.getAlternativesComparisons(trees["outranking"], alternatives) if outranking == {}: outranking = _get_outranking(trees["outranking"]) d.outranking = outranking elif p == "nonoutranking": if trees.has_key("nonoutranking"): alternatives = px.getAlternativesID(trees["alternatives"]) nonoutranking = _get_intersection_distillation(trees["nonoutranking"], alternatives) if nonoutranking == None: nonoutranking = px.getAlternativesComparisons(trees["nonoutranking"], alternatives) if nonoutranking == {}: nonoutranking = _get_outranking(trees["nonoutranking"]) d.nonoutranking = nonoutranking elif p == "performances": d.performances = px.getPerformanceTable(trees["performance_table"], None, None) elif p == "pref_directions": criteria = px.getCriteriaID(trees["criteria"]) d.pref_directions = px.getCriteriaPreferenceDirections(trees["criteria"], criteria) elif p == "profiles_performance_table": if comparison_with in ("boundary_profiles", "central_profiles"): tree = trees.get("profiles_performance_table") if tree is None: msg = ( "Missing profiles performance table (did you forget " "to provide 'profiles_performance_table.xml' file?)." ) raise RuntimeError(msg) d.profiles_performance_table = px.getPerformanceTable(tree, None, None) else: d.profiles_performance_table = None elif p == "reinforcement_factors": criteria = px.getCriteriaID(trees["criteria"]) factors = {} for c in criteria: rf = px.getCriterionValue(trees["reinforcement_factors"], c, "reinforcement_factors") if len(rf) == 0: continue if rf.get(c) <= 1: msg = ( "Reinforcement factor for criterion '{}' should be " "higher than 1.0 (ideally between 1.2 and 1.5)." ) raise RuntimeError(msg) factors.update(rf) d.reinforcement_factors = factors elif p == "thresholds": criteria = px.getCriteriaID(trees["criteria"]) d.thresholds = _get_thresholds(trees["criteria"]) elif p == "weights": criteria = px.getCriteriaID(trees["criteria"]) d.weights = px.getCriterionValue(trees["weights"], criteria) elif p == "z_function": d.z_function = px.getParameterByName(trees["method_parameters"], "z_function") elif p == "with_denominator": parameter = px.getParameterByName(trees["method_parameters"], "with_denominator") d.with_denominator = True if parameter == "true" else False elif p == "use_partials": parameter = px.getParameterByName(trees["method_parameters"], "use_partials") d.use_partials = True if parameter == "true" else False elif p == "use_pre_veto": parameter = px.getParameterByName(trees["method_parameters"], "use_pre_veto") d.use_pre_veto = True if parameter == "true" else False elif p == "alpha": d.alpha = px.getParameterByName(trees["method_parameters"], "alpha") elif p == "beta": d.beta = px.getParameterByName(trees["method_parameters"], "beta") elif p == "s1": d.s1 = px.getParameterByName(trees["method_parameters"], "s1") elif p == "s2": d.s2 = px.getParameterByName(trees["method_parameters"], "s2") elif p == "crisp_outranking": d.crisp_outranking = px.getParameterByName(trees["method_parameters"], "crisp_outranking") elif p == "direction": d.direction = px.getParameterByName(trees["method_parameters"], "direction") elif p == "conc_threshold": d.conc_threshold = px.getParameterByName(trees["method_parameters"], "conc_threshold") elif p == "disc_threshold": d.disc_threshold = px.getParameterByName(trees["method_parameters"], "disc_threshold") elif p == "comprehensive": d.comprehensive = px.getParameterByName(trees["method_parameters"], "comprehensive") else: raise RuntimeError("Unknown parameter '{}' specified.".format(p)) return d