/*Implementation of PStep_AlgorithmMembers.h

*/

#include "PStep_AlgorithmMembers.h"

//Constructor functions:
//------------------------------------------------------------------------------------

//Default Constructor
PStep_AlgorithmMembers::PStep_AlgorithmMembers(){

	//Set all settings to their default
	NotInNeighbourhood = 0;
	PricingProblems = 0;

}

//Copy Constructor
PStep_AlgorithmMembers::PStep_AlgorithmMembers(const PStep_AlgorithmMembers &OriginalPStep_AlgorithmMembers)
	: Instance(OriginalPStep_AlgorithmMembers.Instance),
	FeasibilityDummyObjectiveCoeficient(OriginalPStep_AlgorithmMembers.FeasibilityDummyObjectiveCoeficient),
	AlgorithmSettings(OriginalPStep_AlgorithmMembers.AlgorithmSettings),
	Tolerance(OriginalPStep_AlgorithmMembers.Tolerance),
	PSteps(OriginalPStep_AlgorithmMembers.PSteps),
	CurrentCGStatistics(OriginalPStep_AlgorithmMembers.CurrentCGStatistics),
	CurrentBPCStatistics(OriginalPStep_AlgorithmMembers.CurrentBPCStatistics),
	IntegerSolutionFound(OriginalPStep_AlgorithmMembers.IntegerSolutionFound),
	BestIntegerSolution(OriginalPStep_AlgorithmMembers.BestIntegerSolution),
	Arcs(OriginalPStep_AlgorithmMembers.Arcs),
	LastUsedNodeID(OriginalPStep_AlgorithmMembers.LastUsedNodeID),
	Nodes(OriginalPStep_AlgorithmMembers.Nodes),
	CurrentNumberOfNodes(OriginalPStep_AlgorithmMembers.CurrentNumberOfNodes),
	CurrentTreeNode(OriginalPStep_AlgorithmMembers.CurrentTreeNode),
	CurrentSolution(OriginalPStep_AlgorithmMembers.CurrentSolution),
	CurrentPSteps(OriginalPStep_AlgorithmMembers.CurrentPSteps),
	CurrentPStepsxIndices(OriginalPStep_AlgorithmMembers.CurrentPStepsxIndices),
	NumberOfCurrentPSteps(OriginalPStep_AlgorithmMembers.NumberOfCurrentPSteps),
	PStepShortList(OriginalPStep_AlgorithmMembers.PStepShortList),
	NumberOfPStepsInShortList(OriginalPStep_AlgorithmMembers.NumberOfPStepsInShortList),
	Neighbourhoods(OriginalPStep_AlgorithmMembers.Neighbourhoods),
	RelevantDepotCustomerPricingProblems(OriginalPStep_AlgorithmMembers.RelevantDepotCustomerPricingProblems),
	RelevantCustomerDepotPricingProblems(OriginalPStep_AlgorithmMembers.RelevantCustomerDepotPricingProblems),
	RelevantCustomerCustomerPricingProblems(OriginalPStep_AlgorithmMembers.RelevantCustomerCustomerPricingProblems),
	LimitedArcsUsed(OriginalPStep_AlgorithmMembers.LimitedArcsUsed),
	DSSRUsed(OriginalPStep_AlgorithmMembers.DSSRUsed),
	TypeOfExactColumnGenerator(OriginalPStep_AlgorithmMembers.TypeOfExactColumnGenerator),
	CapacityCuts(OriginalPStep_AlgorithmMembers.CapacityCuts),
	NumberOfCapacityCuts(OriginalPStep_AlgorithmMembers.NumberOfCapacityCuts),
	TwoEdgeHypotourCuts(OriginalPStep_AlgorithmMembers.TwoEdgeHypotourCuts),
	NumberOf2EHCuts(OriginalPStep_AlgorithmMembers.NumberOf2EHCuts),
	StrengthenedCombCuts(OriginalPStep_AlgorithmMembers.StrengthenedCombCuts),
	NumberOfSCombCuts(OriginalPStep_AlgorithmMembers.NumberOfSCombCuts),
	FramedCapacityCuts(OriginalPStep_AlgorithmMembers.FramedCapacityCuts),
	NumberOfFramedCapacityCuts(OriginalPStep_AlgorithmMembers.NumberOfFramedCapacityCuts),
	HomogeneousMultistarCuts(OriginalPStep_AlgorithmMembers.HomogeneousMultistarCuts),
	NumberOfHomogeneousMultistarCuts(OriginalPStep_AlgorithmMembers.NumberOfHomogeneousMultistarCuts),
	LysgaardCuts(OriginalPStep_AlgorithmMembers.LysgaardCuts)
{
	//Obtain number of customers and locations
	short int NumberOfCustomers = Instance.NumberOfCustomers;
	short int NumberOfLocations = NumberOfCustomers + 1;

	//Copy NotInNeighbourhood
	if (OriginalPStep_AlgorithmMembers.NotInNeighbourhood != 0 && NumberOfLocations>0){
		for (short int i = 0; i < NumberOfLocations; i++){
			for (short int j = 0; j < NumberOfLocations; ++j){
				NotInNeighbourhood[i][j] = OriginalPStep_AlgorithmMembers.NotInNeighbourhood[i][j];
			}
		}
	}
	else{
		PricingProblems = 0;
	}

	//Copy PricingProblems
	if (OriginalPStep_AlgorithmMembers.PricingProblems != 0 && NumberOfLocations>0){
		for (short int i = 0; i < NumberOfLocations; i++){
			for (short int j = 0; j < NumberOfLocations; ++j){
				PricingProblems[i][j] = OriginalPStep_AlgorithmMembers.PricingProblems[i][j];
			}
		}
	}
	else{
		PricingProblems = 0;
	}

}

//Operator functions:
//------------------------------------------------------------------------------------

//Assignment operator
PStep_AlgorithmMembers PStep_AlgorithmMembers::operator =(PStep_AlgorithmMembers OriginalPStep_AlgorithmMembers){

	//Obtain number of customers and locations
	short int NumberOfCustomers = Instance.NumberOfCustomers;
	short int NumberOfLocations = NumberOfCustomers + 1;

	//Delete NotInNeighbourhood
	if (NotInNeighbourhood != 0){
		for (short int i = 0; i < NumberOfCustomers; ++i){
			delete[] NotInNeighbourhood[i];
		}
		delete[]NotInNeighbourhood;
	}
	//Delete Pricing Problems
	if (PricingProblems != 0){
		for (short int i = 0; i < NumberOfLocations; ++i){
			delete[] PricingProblems[i];
		}
		delete[]PricingProblems;
	}
	RelevantDepotCustomerPricingProblems.clear();
	RelevantCustomerDepotPricingProblems.clear();
	RelevantCustomerCustomerPricingProblems.clear();

	//Copy
	Instance = OriginalPStep_AlgorithmMembers.Instance;
	FeasibilityDummyObjectiveCoeficient = OriginalPStep_AlgorithmMembers.FeasibilityDummyObjectiveCoeficient;
	AlgorithmSettings = OriginalPStep_AlgorithmMembers.AlgorithmSettings;
	Tolerance = OriginalPStep_AlgorithmMembers.Tolerance;
	PSteps = OriginalPStep_AlgorithmMembers.PSteps;
	CurrentCGStatistics = OriginalPStep_AlgorithmMembers.CurrentCGStatistics;
	CurrentBPCStatistics = OriginalPStep_AlgorithmMembers.CurrentBPCStatistics;
	IntegerSolutionFound = OriginalPStep_AlgorithmMembers.IntegerSolutionFound;
	BestIntegerSolution = OriginalPStep_AlgorithmMembers.BestIntegerSolution;
	Arcs = OriginalPStep_AlgorithmMembers.Arcs;
	LastUsedNodeID = OriginalPStep_AlgorithmMembers.LastUsedNodeID;
	Nodes = OriginalPStep_AlgorithmMembers.Nodes;
	CurrentNumberOfNodes = OriginalPStep_AlgorithmMembers.CurrentNumberOfNodes;
	CurrentTreeNode = OriginalPStep_AlgorithmMembers.CurrentTreeNode;
	CurrentSolution = OriginalPStep_AlgorithmMembers.CurrentSolution;
	CurrentPSteps = OriginalPStep_AlgorithmMembers.CurrentPSteps;
	CurrentPStepsxIndices = OriginalPStep_AlgorithmMembers.CurrentPStepsxIndices;
	NumberOfCurrentPSteps = OriginalPStep_AlgorithmMembers.NumberOfCurrentPSteps;
	PStepShortList = OriginalPStep_AlgorithmMembers.PStepShortList;
	NumberOfPStepsInShortList = OriginalPStep_AlgorithmMembers.NumberOfPStepsInShortList;
	Neighbourhoods = OriginalPStep_AlgorithmMembers.Neighbourhoods;
	LimitedArcsUsed = OriginalPStep_AlgorithmMembers.LimitedArcsUsed;
	DSSRUsed = OriginalPStep_AlgorithmMembers.DSSRUsed;
	TypeOfExactColumnGenerator = OriginalPStep_AlgorithmMembers.TypeOfExactColumnGenerator;
	CapacityCuts = OriginalPStep_AlgorithmMembers.CapacityCuts;
	NumberOfCapacityCuts = OriginalPStep_AlgorithmMembers.NumberOfCapacityCuts;
	TwoEdgeHypotourCuts = OriginalPStep_AlgorithmMembers.TwoEdgeHypotourCuts;
	NumberOf2EHCuts = OriginalPStep_AlgorithmMembers.NumberOf2EHCuts;
	StrengthenedCombCuts = OriginalPStep_AlgorithmMembers.StrengthenedCombCuts;
	NumberOfSCombCuts = OriginalPStep_AlgorithmMembers.NumberOfSCombCuts;
	FramedCapacityCuts = OriginalPStep_AlgorithmMembers.FramedCapacityCuts;
	NumberOfFramedCapacityCuts = OriginalPStep_AlgorithmMembers.NumberOfFramedCapacityCuts;
	HomogeneousMultistarCuts = OriginalPStep_AlgorithmMembers.HomogeneousMultistarCuts;
	NumberOfHomogeneousMultistarCuts = OriginalPStep_AlgorithmMembers.NumberOfHomogeneousMultistarCuts;
	LysgaardCuts = OriginalPStep_AlgorithmMembers.LysgaardCuts;

	//Copy NotInNeighbourhood
	if (OriginalPStep_AlgorithmMembers.NotInNeighbourhood != 0 && NumberOfLocations>0){
		for (short int i = 0; i < NumberOfLocations; i++){
			for (short int j = 0; j < NumberOfLocations; ++j){
				NotInNeighbourhood[i][j] = OriginalPStep_AlgorithmMembers.NotInNeighbourhood[i][j];
			}
		}
	}
	else{
		PricingProblems = 0;
	}
	//Copy PricingProblems
	if (OriginalPStep_AlgorithmMembers.PricingProblems != 0 ){
		for (short int i = 0; i < NumberOfLocations; i++){
			for (short int j = 0; j < NumberOfLocations; ++j){
				PricingProblems[i][j] = OriginalPStep_AlgorithmMembers.PricingProblems[i][j];
			}
		}
	}
	else{
		PricingProblems = 0;
	}

	//Copy relevant pricing problems:
	//Copy depot relevant depot-customer pricing problems.
	for (auto CurrentPricingProblem = OriginalPStep_AlgorithmMembers.RelevantDepotCustomerPricingProblems.begin(); CurrentPricingProblem != OriginalPStep_AlgorithmMembers.RelevantDepotCustomerPricingProblems.end(); ++CurrentPricingProblem){
		short int j = (*CurrentPricingProblem)->Sink;
		RelevantDepotCustomerPricingProblems.push_back(&(PricingProblems[0][j]));
	}
	//Copy depot relevant customer-depot pricing problems.
	for (auto CurrentPricingProblem = OriginalPStep_AlgorithmMembers.RelevantCustomerDepotPricingProblems.begin(); CurrentPricingProblem != OriginalPStep_AlgorithmMembers.RelevantCustomerDepotPricingProblems.end(); ++CurrentPricingProblem){
		short int i = (*CurrentPricingProblem)->Source;
		RelevantDepotCustomerPricingProblems.push_back(&(PricingProblems[i][0]));
	}
	//Copy depot relevant customer-customer pricing problems.
	for (auto CurrentPricingProblem = OriginalPStep_AlgorithmMembers.RelevantCustomerCustomerPricingProblems.begin(); CurrentPricingProblem != OriginalPStep_AlgorithmMembers.RelevantCustomerCustomerPricingProblems.end(); ++CurrentPricingProblem){
		short int i = (*CurrentPricingProblem)->Source;
		short int j = (*CurrentPricingProblem)->Sink;
		RelevantDepotCustomerPricingProblems.push_back(&(PricingProblems[i][j]));
	}
	
	return *this;

}

//Destructor functions
//------------------------------------------------------------------------------------

//Default destructor
PStep_AlgorithmMembers::~PStep_AlgorithmMembers(){
	
	//Obtain number of customers and locations
	short int NumberOfCustomers = Instance.NumberOfCustomers;
	short int NumberOfLocations = NumberOfCustomers + 1;

	//Delete NotInNeighbourhood
	if (NotInNeighbourhood != 0){
		for (short int i = 0; i < NumberOfCustomers; ++i){
			delete[] NotInNeighbourhood[i];
		}
		delete[]NotInNeighbourhood;
	}

	//Delete Pricing Problems
	if (PricingProblems != 0){
		for (short int i = 0; i < NumberOfLocations; ++i){
			delete[] PricingProblems[i];
		}
		delete[]PricingProblems;
	}

	//Free memory used by Lysgaard package
	CMGR_FreeMemCMgr(&LysgaardCuts);

}