/*
 * AresVMyTree.cpp
 *
 *  Created on: 11-Jul-08
 *      Author: indurks
 */
#include "AresV.h"

MyTree::MyTree(int mySpecialChem, vector<Reaction> &rxns, int orientation)
{
	deMultiplierChemical = mySpecialChem;
	numRxns = rxns.size();

	for(int i = 0; i < (signed)rxns.size(); i++)
	{
		Reaction cobra;
		cobra.r1 = rxns[i].r1;
		cobra.r2 = rxns[i].r2;
		cobra.p1 = rxns[i].p1;
		cobra.p2 = rxns[i].p2;
		cobra.rate = rxns[i].rate;
		myRxns.push_back(cobra);
	}

	InitializeTree(myBefore, myAfter, myDepth, myRxns.size());

	// Now make the rxns oriented the right way
	for(int i = 0; i < (signed)myRxns.size(); i++)
	{
		if(myRxns[i].r1 != orientation)
		{
			int z = myRxns[i].r1;
			myRxns[i].r1 = myRxns[i].r2;
			myRxns[i].r2 = z;
		}

		if(myRxns[i].r1 != orientation)
		{
			cout << "ERROR: MyTree with orientation Chemical = " << orientation << " didn't have appropriate reaction" << std::endl;
			cout << "Reaction was: " << std::endl;
			cout << "\t" << myRxns[i].r1 << " + " << myRxns[i].r2 << " --> " << myRxns[i].p1 << " + " << myRxns[i].p2 << std::endl;
			exit(0);
		}
	}
}

int MyTree::getOffSet()
{
	return numRxns;
}

void MyTree::CalculateSumPropensity()
{
	mySumPropensity = 0.0;

	for(int i = 0; i < (signed)myRxns.size(); i++)
		mySumPropensity += myRxns[i].sumPropensity;
}

bool SortFunctionForRxns(Reaction r1, Reaction r2)
{
	return (r1.sumPropensity > r2.sumPropensity);
}

void MyTree::SortReactions()
{
	std::sort(myRxns.begin(), myRxns.end(), SortFunctionForRxns);
}
