/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include "CombinedCompareFunction.h"

namespace smartcomparator
{

	namespace compare
	{

		CombinedCompareFunction::CombinedCompareFunction(std::vector<Matrices::SuperMatrixPtr> matrices, 
				std::vector<CompareFunctionPtr> cmp_functions) : CompareFunction(matrices[0]),
		m_vMatrices(matrices), m_vCmpFunctions(cmp_functions) 
		{
			if( m_vMatrices.size() != m_vCmpFunctions.size())
				throw std::runtime_error("Number of matrices must be equal to number of compare functions");
		}

		CombinedCompareFunction::~CombinedCompareFunction()
		{
		}

		double CombinedCompareFunction::Compare(size_t n1, size_t n2)
		{
			SelectCoefficients(n1, n2);
			double sim = 0;
			for(size_t i = 0; i < m_vCmpFunctions.size(); i++)
				sim += m_vCooefficients[i]*m_vCmpFunctions[i]->Compare(n1, n2);
			return sim;
		}//double CombinedCompareFunction::Compare(size_t n1, size_t n2, std::set<size_t> &out)

	}//namespace compare

}//namespace smartcomparator
