/*Header file of the PStep_AlgorithmMembers class

//Implementation can be found in PStep_AlgorithmMembers.cpp

This class represents the members of the class PStep_Algorithm.
It is used to enable acces to all members of algorithm by outside functions via a single pointer or reference.
*/

#ifndef _PSTEP_ALGORITHMMEMBERS_H
#define _PSTEP_ALGORITHMMEMBERS_H

#include "CVRPInstance.h"
#include "PStep_AlgorithmSettings.h"
#include "PStep.h"
#include "PStep_Solution.h"
#include "PStep_BranchPriceAndCutStatistics.h"
#include "PStep_ColumnGenerationStatistics.h"
#include "PStep_Arc.h"
#include "PStep_TreeNode.h"
#include "PStep_PricingProblem.h"
#include "LysgaardPackageHeaders.h"
#include "PStep_EdgeAndCoefficientCut.h"
//The above files also include clock, iostream, fstream, sstream, iomanip, list, PStep_EdgeFlowCut

//Class used to represent the members of PStep_Algorithm
class PStep_AlgorithmMembers{
public:
	//General members:
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	//Problem Instance
	CVRPInstance Instance;

	//The objective coefficient of the feasibility dummy variable.
	//It should exceed the value of every possible feasible solution.
	double FeasibilityDummyObjectiveCoeficient;

	//Algorithm Settings
	PStep_AlgorithmSettings AlgorithmSettings;

	//Tolerance
	double Tolerance;

	//Network members:
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	//Arcs
	//Arcs[i][j] is the arc from i to j.
	//Arcs[i][j].Index=Arcs[j][i].Index refers to the corresponding edge.
	//For i<j, the index is (j-1)(j)/2+i, corresponding for instance to the index of the variable
	//dictating whether this edge is used.
	//Arcs[i][i]=-1 indicating this arc is not really used.
	std::vector<std::vector<PStep_Arc>> Arcs;

	//OutArcs[i][j] is the (j+1)'th cheapest arc out of location i,
	//i=0 is the depot, and OutArcs[i][0] is the cheapest arc out of location i.
	//They are sorted with respect to arc costs.
	std::vector<std::vector<PStep_Arc>> OutArcs;

	//InArcs[i][j] is the (j+1)'th cheapest arc into location i,
	//i=0 is the depot, and InArcs[i][0] is the cheapest arc into location i.
	//They are sorted with respect to arc costs.
	std::vector<std::vector<PStep_Arc>> InArcs;

	//Solution members:
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	//List of all created routes
	std::list<PStep> PSteps;

	//Column generation statistics
	PStep_ColumnGenerationStatistics CurrentCGStatistics;

	//Current branch and price statistics
	PStep_BranchPriceAndCutStatistics CurrentBPCStatistics;

	//Indicator indicating whether an integer solution is found and stored in
	//BestIntegerSolution.
	bool IntegerSolutionFound;

	//Best integer solution currently found
	//A solution is contained in BestIntegerSolution, when IntegerSolutionFound=true.
	PStep_Solution BestIntegerSolution;

	//Branching members:
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	//Last used ID, the rootnode gets ID 1
	int LastUsedNodeID;

	//List of active tree nodes
	std::list<PStep_TreeNode> Nodes;

	//Number of tree nodes in Nodes.
	int CurrentNumberOfNodes;

	//Current node in the branching tree
	std::list<PStep_TreeNode>::iterator CurrentTreeNode;

	//Current solution to (a relaxation of the) CVRP
	PStep_Solution CurrentSolution;

	//Column generation members:
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	//p-steps selected in a temporary formulation (for instance when solving the LP in a branching node)
	//The list contains pointers to p-steps stored in PSteps
	std::list<std::list<PStep>::iterator> CurrentPSteps;

	//List of indices indicating to which x variable in the p-step formulation a CurrentPStep corresponds.
	//That is CurrentPStep[i] corresponds to x[CurrentPStepsxIndices[i]].
	std::list<int> CurrentPStepsxIndices;

	//The number of p-steps in CurrentPSteps
	int NumberOfCurrentPSteps;

	//A shortlist of p-steps that are not currently included in the formulation, but are feasible.
	//This shortlist is of use when applying column management.
	//The list contains pointers to p-steps stored in PSteps
	std::list<std::list<PStep>::iterator> PStepShortList;

	//The number of p-steps in the PStepShortList
	int NumberOfPStepsInShortList;

	//Neighbourhoods:
	//Used when applying ng-path relaxation
	//Neighbourhoods.at(i).at(j) represents neighbour j of customer i,
	//i=0 and Neighbourhoods[i][j]=0 is the first customer.
	//The depot and customer i is not included in the neighbourhood.
	std::vector<std::vector<short int >> Neighbourhoods;
	//Not in neighborhood indicates whether a customer is not in the neighborhoud.
	//NotInNeighbourhood[i][j]=true if customer j is not a neighbor of customer i (0 is the first customer).
	bool** NotInNeighbourhood;

	//Pricing problems:
	//PricingProblems[i][j] is a pricing problem with location i as source and j as sink, i=0 and j=0 are the depot.
	//It is of use when decomposing the pricing problem to shortest path problems with fixed sources and sinks.
	//NOTE: Not all members need to be filled, some might remain empty!
	PStep_PricingProblem** PricingProblems;

	//Relevant depot-customer pricing problems
	//Contains pointers to PricingProblems with the depot as source and a customer as sink.
	//Includes only those PricingProblems for which a (demand-)feasible p-step exists.
	std::list<PStep_PricingProblem*> RelevantDepotCustomerPricingProblems;

	//Relevant customer-depot pricing problems
	//Contains pointers to PricingProblems with a customer as source and the depot as sink.
	//Includes only those PricingProblems for which a (demand-)feasible p-step exists.
	std::list<PStep_PricingProblem*> RelevantCustomerDepotPricingProblems;

	//Relevant customer-customer pricing problems
	//Contains pointers to PricingProblems with a customer as source and a customer as sink.
	//Includes only those PricingProblems for which a (demand-)feasible p-step exists.
	//NOTE: For source i and sink j, only if i<j is PricingProblem[i][j] included in the list,
	//		it is assumed that PricingProblem[j][i] is then also relevant.
	std::list<PStep_PricingProblem*> RelevantCustomerCustomerPricingProblems;

	//Indicator indicating whether a limited set of arcs are used during column generation.
	//It is used to determine whether this set should be initialized and updated.
	bool LimitedArcsUsed;

	//Indicator indicating whether decremental state-space relaxation is used during column generation.
	bool DSSRUsed;

	//Type of exact column generator used
	//1: LayeredLabeling (column generator 1)
	//2: DoubleLayeredLabeling (Column generator 12)
	//3: BidirectionalLayeredLabeling (Column generator 14)
	//4: BidirectionalLayeredLabelingWithCompletionBounds (Column generator 19)
	short int TypeOfExactColumnGenerator;

	//Inequality members
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	//Capacity cuts:
	std::list<PStep_EdgeFlowCut> CapacityCuts;

	//The number of capacity cuts
	int NumberOfCapacityCuts;

	//2 edge hypotour cuts:
	std::list<PStep_EdgeAndCoefficientCut> TwoEdgeHypotourCuts;

	//The number of 2 edge hypotour cuts
	int NumberOf2EHCuts;

	//strengthened comb cuts:
	std::list<PStep_EdgeAndCoefficientCut> StrengthenedCombCuts;

	//The number of strengthened comb cuts
	int NumberOfSCombCuts;

	//Framed capacity cuts:
	std::list<PStep_EdgeFlowCut> FramedCapacityCuts;

	//The number of framed capacity cuts
	int NumberOfFramedCapacityCuts;

	//Homogeneous multistar cuts:
	std::list<PStep_EdgeAndCoefficientCut> HomogeneousMultistarCuts;

	//The number of homogeneous multistar cuts
	int NumberOfHomogeneousMultistarCuts;

	//Lysgaards algorithm members
	CnstrMgrPointer LysgaardCuts;
	//NOTE:
	//Memory allocated for the lysgaardCuts should also be freed at the end using for instance the following code:
	//CMGR_FreeMemCMgr(&LysgaardCuts);

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

	//Default Constructor
	PStep_AlgorithmMembers();

	//Copy Constructor
	PStep_AlgorithmMembers(const PStep_AlgorithmMembers &OriginalPStep_AlgorithmMembers);

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

	//Assignment operator
	PStep_AlgorithmMembers operator=(PStep_AlgorithmMembers OriginalPStep_AlgorithmMembers);

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

	//Default destructor
	~PStep_AlgorithmMembers();

};

#endif