#include "EthernetNetworkCost.h"

namespace cosi
{

namespace models
{

namespace wiredbas
{

EthernetNetworkCost::EthernetNetworkCost(cosi::models::wiredbas::WireCost* pWireCost)
{
	mWireCost = pWireCost ;
	mNodeCost = new cosi::models::wiredbas::EthernetNodeCost ;
}

EthernetNetworkCost::~EthernetNetworkCost()
{
}



double EthernetNetworkCost::GetValue(cosi::commstruct::wiredbas::PlatformInstance pC) {
	return GetValue(&pC) ;
}

double EthernetNetworkCost::GetValue(cosi::commstruct::wiredbas::PlatformInstance* pC) {
	//Assume that this is a bus
	double RetVal = 0;
	IdGraph::v_iterator U, V;
	//Sum all node cost
	for (U = pC->v_begin() ; U != pC->v_end() ; U++) {
		//compute the cost of a node
		RetVal += mNodeCost->GetValue(pC->GetName(*U), (*pC)[*U].PRJ(Type)GetValue(),(*pC)[*U].PRJ(Ports)Get());
	}
	//Sum all wire cost
	for (U = pC->v_begin() ; U != pC->v_end() ; U++) {
		for (V = pC->v_begin() ; V != pC->v_end() ; V++) {
			if (pC->InE(*U, *V)) {
				RetVal += mWireCost->GetValue((*pC)[Edge(*U,*V)].PRJ(WiringPath)Get());
			}
		}
	}
	return RetVal ;
}

double EthernetNetworkCost::GetValue(cosi::commstruct::wiredbas::Implementation pC) {
	return GetValue(&pC) ;
}

double EthernetNetworkCost::GetValue(cosi::commstruct::wiredbas::Implementation* pC) {
	//Assume that this is a bus
	double RetVal = 0;
	IdGraph::v_iterator U, V;
	//Sum all node cost
	for (U = pC->v_begin() ; U != pC->v_end() ; U++) {
		//compute the cost of a node
		RetVal += mNodeCost->GetValue(pC->GetName(*U), (*pC)[*U].PRJ(Type)GetValue(),(*pC)[*U].PRJ(Ports)Get());
	}

	//cout << "Node Cost " << RetVal << endl  ;

	//Sum all wire cost
	for (U = pC->v_begin() ; U != pC->v_end() ; U++) {
		for (V = pC->v_begin() ; V != pC->v_end() ; V++) {
			if (pC->InE(*U, *V)) {
				RetVal += mWireCost->GetValue((*pC)[Edge(*U,*V)].PRJ(WiringPath)Get());
			}
		}
	}

	//cout << "Total Cost " << RetVal << endl ;

	return RetVal ;
}



}

}

}
