#include "SolutionStats.h"

SolutionStats::SolutionStats() {

}

SolutionStats::SolutionStats(Instance* instance, const vector<Exchange>& solution) {
	this->instance = instance;
	this->solution = solution;
}

SolutionStats::SolutionStats(const SolutionStats& s) {
	this->instance = s.instance;
	this->solution = s.solution;
}

SolutionStats::~SolutionStats()
{
}


bool operator==(const SolutionStats& s1, const SolutionStats& ss2) {
	return false;
}

bool operator!=(const SolutionStats& s1, const SolutionStats& s2) {
	return !(s1 == s2);
}

SolutionStats& SolutionStats::operator=(const SolutionStats& s) {
	this->instance = s.instance;
	this->solution = s.solution;
	return *this;
}

string SolutionStats::compute_length_stats() const {
	int max_length_paths = this->instance->getChainsLength();
	int max_length_circuits = this->instance->getCyclesLength();
	vector<int> path_length(max_length_paths, 0);
	vector<int> circuit_length(max_length_circuits, 0);
	for (const auto& col : this->solution) {
		int length = col.getLength();
		if (col.getType() == "chain") {
			path_length.at(length - 2)++;
		}
		else {
			circuit_length.at(length - 1)++;
		}
	}

	string str;
	for (int i = 0; i < path_length.size(); i++) {
		str += to_string(path_length.at(i)) + ",";
	}
	str += ",";
	for (int i = 0; i < circuit_length.size(); i++) {
		str += to_string(circuit_length.at(i)) + ",";
	}
	str += "\n";
	return str;
}

void SolutionStats::set_solution(const vector<Exchange>& solution) {
	this->solution = solution;
}