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

using namespace std;

MyCloud::MyCloud(int deMul)
{
	deMultiplierChemical = deMul;
}

void MyCloud::SetMainTree(MyTree *t)
{
	if(t)
		mainTree = t;
	else {
		cout << "ERROR: Tried to add null tree." << std::endl;
		exit(0);
	}
}

void MyCloud::AddTree(MyTree *t)
{
	if(t)
		trees.push_back(t);
	else {
		cout << "ERROR: Tried to add null tree." << std::endl;
		exit(0);
	}
}

bool SortFunctionForTrees(MyTree *t1, MyTree *t2)
{
	return (t1->mySumPropensity > t2->mySumPropensity);
}

void MyCloud::SortCloud()
{
	mainTree->SortReactions();

	for(int i = 0; i < (signed)trees.size(); i++)
		trees[i]->SortReactions();

	std::sort(trees.begin(), trees.end(), SortFunctionForTrees);
}

int MyCloud::getOffSet()
{
	int sum = myPreviousOffset;
	for(int i = 0; i < (signed)trees.size(); i++)
		sum += trees[i]->getOffSet();
	return sum;
}

void MyCloud::CalculateSumPropensity()
{
	mainTree->CalculateSumPropensity();
	mySumPropensity = mainTree->mySumPropensity;

	for(int i = 0; i < (signed)trees.size(); i++) {
		trees[i]->CalculateSumPropensity();
		mySumPropensity += trees[i]->mySumPropensity;
	}
}
