/*Header file of the PStep_Solution class

Implementation can be found in PStep_Solution.cpp

This class represents a solution to the LP relaxation of the CVRP.
It contains selected p-steps and the fractions by which they are selected,
as well as the edge-flow.

NOTE: psteps have a direction but the (edge-)flow does not.
*/

#ifndef _PSTEP_SOLUTION_H
#define _PSTEP_SOLUTION_H

#include "PStep.h" //Includes list and iostream
#include "clock.h"
#include <iomanip>
#include <fstream>

//Class used to represent an solution to the CVRP
class PStep_Solution{

public:
	//PSteps selected in this solution
	std::list<PStep> PSteps;
	//Fraction by which each p-step is selected, corresponding to PSteps
	std::list<double> PStepSelection;

	//Value by which each is selected
	//EdgeFraction[(j-1)(j)/2+i] indicates the fraction by which edge (i,j), i<j, is selected.
	//The edges of the depot could be selected with value 2, indicating a return trip.
	//Here i=0 corresonds to the depot.
	double *EdgeFraction;

	//Solution value
	double SolutionValue;

	//Number of locations
	//Used to determine the dimension of EdgeFraction.
	short int NumberOfLocations;

	//Time of construction
	timePoint ConstructionTime;

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

	//Default Constructor
	PStep_Solution();

	//Constructor that sets the number of locations and initializes EdgeFraction.
	PStep_Solution(short int newNumberOfLocations);

	//Copy Constructor
	PStep_Solution(const PStep_Solution &OriginalPStep_Solution);

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

	//Assignment operator
	PStep_Solution operator=(PStep_Solution OriginalPStep_Solution);

	//Other functions
	//------------------------------------------------------------------------------------

	//Check whether the current solution is integer upto tolerance level Tolerance.
	bool IsInteger(double Tolerance);

	//Initialize EdgeFraction, all values are set to zero.
	//NOTE: it is assumed that EdgeFraction is not initialized yet,
	//while NumberOfLocations is set to the proper value.
	void InitializeEdgeFraction();

	//Reinitialize the current solution, with the same NumberOfLocations.
	//It invokes EmptySolution and InitializeEdgeFraction.
	void Reinitialize();

	//Print functions
	//------------------------------------------------------------------------------------

	//Print solution
	void PrintSolution();

	//Print the edge fraction
	void PrintEdgeFraction();

	//Write functions
	//------------------------------------------------------------------------------------

	//Function to write the solution to file. The format can be deduced from the implementation.
	//It is assumed that all members are set properly to represent a feasible (integer) solution.
	//The orientation of the routes is arbitrary and might not match the selected p-steps.
	void Write(const char* FileName);

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

	//Default destructor
	~PStep_Solution();

	//Auxiliary functions
	//------------------------------------------------------------------------------------

	//Empty all entries
	void EmptySolution();

	//Copy all entries
	//IMPORTANT: it is assumed that the current solution is empty!
	void CopyEmptyAssumed(const PStep_Solution &OriginalPStep_Solution);

};

#endif