<commit_before>#include "bogart.h"
#include "bestOverlap_DFS.h"

static bool solutionCmp(solution_t a, solution_t b);
static solution_t dfs(overlapGraph_t& graph, int ix);

void BOG_DFS(overlapGraph_t& graph, std::set<int>& starters, std::vector<int>& result) {
	std::vector<solution_t> local_solutions;
	for (std::set<int>::iterator it = starters.begin(); it!= starters.end(); ++it) {
		local_solutions.push_back(dfs(graph,*it));
	}
	// sort local solutions
	std::sort(local_solutions.begin(),local_solutions.end(),solutionCmp);
	// store to result
	result = local_solutions[0].second;
}

static bool solutionCmp(solution_t a, solution_t b) {
	if (a.first != b.first) {
		return a.first > b.first;
	}
	return a.second.size() > b.second.size();
}

static solution_t dfs(overlapGraph_t& graph, int ix) {
	// all of the possible solutions from this node will be stored in this vector
	std::vector<solution_t> local_solutions;

	// iterate through all of the right overlaps of current node
	for (mhapList_t::iterator it = graph[ix].rOvlp.begin(); it!=graph[ix].rOvlp.end(); ++it) {
		mhapRead_t current_read;
		solution_t current_solution;
		int ovlp_ix;

		// get info on current overlap
		current_read = *(*it);

		// find the index of overlapping read
		if (current_read.id.first == ix) {
			ovlp_ix = current_read.id.second;
		} else {
			ovlp_ix = current_read.id.first;
		}

		if (graph[ovlp_ix].thisNodeHasBeenVisited == 0) {
			// best solution for the overlapping read has not been found yet
			graph[ovlp_ix].thisNodeHasBeenVisited = 2;
			current_solution = dfs(graph,ovlp_ix);
		} else if (graph[ovlp_ix].thisNodeHasBeenVisited == 1){
			// best solution already exists
			current_solution = graph[ovlp_ix].bestSolution;
		} else {
			std::cout << "Stuck in a cycle :(" << std::endl;
			std::cin >> ovlp_ix;
		}
		// TODO break cycles !
		/*
			ARBITRARY METRIC
				find the best cumulative jaccard
		*/

		// multiply the jaccardScore of this overlap with cumulative jaccard score of the child node
		current_solution.first *= current_read.jaccardScore;
		// add this node into the path vector
		current_solution.second.push_back(ix);
		local_solutions.push_back(current_solution);
	}
	/*
		Leaf node
			this node must return metric-neutral value as jaccard score (1 because we are multiplying)
			this node must return only itself as the best path
	*/
	if (local_solutions.empty()) {
		solution_t tmp;
		std::vector<int> tmpv(1,ix);
		tmp.first = 1.0;
		tmp.second = tmpv;
		local_solutions.push_back(tmp);
	}
	std::sort(local_solutions.begin(),local_solutions.end(),solutionCmp);
	return local_solutions[0];
}<commit_msg>git trouble<commit_after>#include "bogart.h"
#include "bestOverlap_DFS.h"

static bool solutionCmp(solution_t a, solution_t b);
static solution_t dfs(overlapGraph_t& graph, int ix);

void BOG_DFS(overlapGraph_t& graph, std::set<int>& starters, std::vector<int>& result) {
	std::vector<solution_t> local_solutions;
	for (std::set<int>::iterator it = starters.begin(); it!= starters.end(); ++it) {
		local_solutions.push_back(dfs(graph,*it));
	}
	// sort local solutions
	std::sort(local_solutions.begin(),local_solutions.end(),solutionCmp);
	// store to result
	result = local_solutions[0].second;
}

static bool solutionCmp(solution_t a, solution_t b) {
	if (a.first != b.first) {
		return a.first > b.first;
	}
	return a.second.size() > b.second.size();
}

static solution_t dfs(overlapGraph_t& graph, int ix) {
	// all of the possible solutions from this node will be stored in this vector
	std::vector<solution_t> local_solutions;

	// iterate through all of the right overlaps of current node
	for (mhapList_t::iterator it = graph[ix].rOvlp.begin(); it!=graph[ix].rOvlp.end(); ++it) {
		mhapRead_t current_read;
		solution_t current_solution;
		int ovlp_ix;

		// get info on current overlap
		current_read = *(*it);

		// find the index of overlapping read
		if (current_read.id.first == ix) {
			ovlp_ix = current_read.id.second;
		} else {
			ovlp_ix = current_read.id.first;
		}

		if (graph[ovlp_ix].thisNodeHasBeenVisited == 0) {
			// best solution for the overlapping read has not been found yet
			graph[ovlp_ix].thisNodeHasBeenVisited = 2;
			current_solution = dfs(graph,ovlp_ix);
		} else if (graph[ovlp_ix].thisNodeHasBeenVisited == 1){
			// best solution already exists
			current_solution = graph[ovlp_ix].bestSolution;
		} else {
			std::cout << "Stuck in a cycle :(" << std::endl;
			std::cin >> ovlp_ix;
		}
		// TODO break cycles !
		/*
			ARBITRARY METRIC
				find the best cumulative jaccard
		*/
		graph[ovlp_ix].thisNodeHasBeenVisited = 1;
		// multiply the jaccardScore of this overlap with cumulative jaccard score of the child node
		current_solution.first *= current_read.jaccardScore;
		// add this node into the path vector
		current_solution.second.push_back(ix);
		local_solutions.push_back(current_solution);
	}
	/*
		Leaf node
			this node must return metric-neutral value as jaccard score (1 because we are multiplying)
			this node must return only itself as the best path
	*/
	if (local_solutions.empty()) {
		solution_t tmp;
		std::vector<int> tmpv(1,ix);
		tmp.first = 1.0;
		tmp.second = tmpv;
		local_solutions.push_back(tmp);
	}
	std::sort(local_solutions.begin(),local_solutions.end(),solutionCmp);
	return local_solutions[0];
}
{'fraction_non_alphanumeric': 0.11974405850091407, 'fraction_numerical': 0.003473491773308958, 'mean_word_length': 3.7532580364900086, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3260408', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1844, 'n_words': 471}