/*Implementation of PStep_PricingProblemSolver

It contains the member functions of PStep_PricingProblemSolver and all derived classes

*/

#include "PStep_PricingProblemSolver.h"

//PStep_AllPricingProblemSequentialSolver:
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//Solve
//------------------------------------------------------------------------------------

//Solve all pricing problems sequentially
void PStep_AllPricingProblemSequentialSolver::Solve(std::forward_list<PStep_ShortestPathAlgorithm*>& Algorithms){

	//Go over all pricing problems
	for (auto CurrentAlgorithm = Algorithms.begin(); CurrentAlgorithm != Algorithms.end(); ++CurrentAlgorithm){

		//Solve
		(*CurrentAlgorithm)->Run();

	}

}

//PStep_AllPricingProblemSequentialSolverSavingsTimer:
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//Solve
//------------------------------------------------------------------------------------

//Solve all pricing problems sequentially, and also store a potential savings in 
//pricing time by full paralleisation.
void PStep_AllPricingProblemSequentialSolverSavingsTimer::Solve(std::forward_list<PStep_ShortestPathAlgorithm*>& Algorithms){

	//Initialize timepoints
	timePoint StartTime, tic, toc;
	//Initialize duration of an algorithm
	double Duration;
	//Initialize maximum time
	double MaxTime = 0;

	//Get pricing start time
	StartTime = HomeMadeclock::now();

	//Go over all pricing problems
	for (auto CurrentAlgorithm = Algorithms.begin(); CurrentAlgorithm != Algorithms.end(); ++CurrentAlgorithm){

		//Get current algorithm start time
		tic = HomeMadeclock::now();

		//Solve
		(*CurrentAlgorithm)->Run();

		//Get current algorithm stop time
		toc = HomeMadeclock::now();
		//Obtain total duration of the current algorithm
		Duration = HomeMadeclock::seconds(tic, toc);
		//Check whether the duration is larger than the max time
		if (Duration > MaxTime){
			//The duration is the new MaxTime
			MaxTime = Duration;
		}

	}

	//Update the potential savings
	TotalPotentialTimeSavings += (HomeMadeclock::seconds(StartTime, toc) - MaxTime);

}

//PStep_AllPricingProblemParallelSolver:
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//Solve
//------------------------------------------------------------------------------------

//Solve all pricing problems in parallel
void PStep_AllPricingProblemParallelSolver::Solve(std::forward_list<PStep_ShortestPathAlgorithm*>& Algorithms){

	//Go over all pricing problems
	for (auto CurrentAlgorithm = Algorithms.begin(); CurrentAlgorithm != Algorithms.end(); ++CurrentAlgorithm){
		
		//Solve
		(*CurrentAlgorithm)->Run();

	}

}