9bool RandomSelector::is_valid_pair(
SimilarPair path_pair) {
17std::vector<SimilarPair> RandomSelector::get_similarity_pairs_filtered() {
20 std::vector<SimilarPair> ret;
21 for (
auto path_pair : path_pairs) {
22 if (is_valid_pair(path_pair)) {
23 ret.push_back(path_pair);
29std::vector<SimilarPair> RandomSelector::make_random_selection(std::vector<SimilarPair> path_pairs) {
30 shuffle(path_pairs.begin(), path_pairs.end(), rng);
31 while (
int(path_pairs.size()) > maximum_quantity) {
32 path_pairs.pop_back();
37void RandomSelector::print_path_pairs(std::vector<SimilarPair> path_pairs) {
38 std::vector<RandomSelectorEntry> vector_entry = {};
40 for (
const auto& path_pair : path_pairs) {
41 const Path& path1 = similarity_table->
get_path(path_pair.id1);
42 const Path& path2 = similarity_table->
get_path(path_pair.id2);
53 if (vector_entry.size() <= 0)
return;
63 similarity_table = _similarity_table;
65 minimum_similarity = 0;
66 maximum_similarity = 0;
71 if (
options.extra_args.size() <= 2) {
72 throw CLIError(
"Random expect three parameters, but less was given");
80 minimum_similarity = stod(
options.extra_args[0]);
81 maximum_similarity = stod(
options.extra_args[1]);
82 maximum_quantity = stod(
options.extra_args[2]);
84 auto path_pairs = get_similarity_pairs_filtered();
85 path_pairs = make_random_selection(path_pairs);
86 print_path_pairs(path_pairs);
Base class for CLI-related errors.
const CliOption * options() const final
Function load_metadata(const Path &path)
Loads function metadata from a path.
static std::string format_path_message_in_pair(const Function &function)
Formats path for display.
Represents a logical path to a function in the codebase.
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
bool run(const ParsedOptions &options) override
Handles random selection command.
Represents a similarity graph between functions (paths).
void update_similarity(double new_similarity_threshold)
Updates similarity threshold.
std::vector< SimilarPair > get_all_similar_pairs()
Gets all similar path pairs with scores, sorted.
const Path & get_path(PathId id) const
void sort_pairs_by_similarity(std::vector< SimilarPair > &similar_pairs) const
Sorts path pairs by similarity.
Provides functionality to load Function objects from external sources.
Provides utilities for printing function information and source code.
Random selection of similar code pairs.