/*Header file of the PStep_TreeNodeSelecter class

Implementation can be found in PStep_TreeNodeSelecter.cpp

This class represents a function to select a node from the branching tree.

This file also includes derived classes of PStep_TreeNodeSelecter.

*/

#ifndef _PSTEP_TREENODESELECTER_H
#define _PSTEP_TREENODESELECTER_H

#include "PStep_TreeNode.h"

//Class used to represent a function to select a node from the branching tree,
//it returns the first node in the tree.
//The selected node is stored in CurrentTreeNode, which is a reference to an iterator which
//could be contained AlgorithmMembers.
class PStep_TreeNodeSelecter{
protected:
	//List of active tree nodes
	std::list<PStep_TreeNode>& Nodes;

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

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

	//Basic constructor
	PStep_TreeNodeSelecter(std::list<PStep_TreeNode>& NewNodes, std::list<PStep_TreeNode>::iterator& NewCurrentTreeNode)
		:Nodes(NewNodes), CurrentTreeNode(NewCurrentTreeNode)
	{};

	//Selection functions
	//------------------------------------------------------------------------------------

	//Select a node from the branching tree.
	//It stores the selected TreeNode in CurrentTreeNode.
	//This function selects the first node.
	virtual void Select();

protected:
	//Select the deepest node
	void SelectDeepestNode();

	//Select the node with the lowest lower bound
	void SelecteLowestLowerBoundNode();

};

//Class used to represent a function to select a node from the branching tree,
//it returns the deepest node in the tree.
//The selected node is stored in CurrentTreeNode, which is a reference to an iterator which
//could be contained AlgorithmMembers.
class PStep_DeepestNodeSelecter : public PStep_TreeNodeSelecter{
public:

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

	//Basic constructor
	PStep_DeepestNodeSelecter(std::list<PStep_TreeNode>& NewNodes, std::list<PStep_TreeNode>::iterator& NewCurrentTreeNode)
		:PStep_TreeNodeSelecter(NewNodes, NewCurrentTreeNode)
	{};

	//Selection functions
	//------------------------------------------------------------------------------------

	//Select a node from the branching tree.
	//It stores the selected TreeNode in CurrentTreeNode.
	//This function selects the deepest node.
	virtual void Select();

};

//Class used to represent a function to select a node from the branching tree,
//it returns the node in the tree with the lowest lower bound.
//The selected node is stored in CurrentTreeNode, which is a reference to an iterator which
//could be contained AlgorithmMembers.
class PStep_LowestLBNodeSelecter : public PStep_TreeNodeSelecter{
public:

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

	//Basic constructor
	PStep_LowestLBNodeSelecter(std::list<PStep_TreeNode>& NewNodes, std::list<PStep_TreeNode>::iterator& NewCurrentTreeNode)
		:PStep_TreeNodeSelecter(NewNodes, NewCurrentTreeNode)
	{};

	//Selection functions
	//------------------------------------------------------------------------------------

	//Select a node from the branching tree.
	//It stores the selected TreeNode in CurrentTreeNode.
	//This function selects the node with the lowest lower bound.
	virtual void Select();

};

//Class used to represent a function to select a node from the branching tree.
//If no integer solution is found, it selects the deepest node, otherwise the node with the lowest lower bound.
//The selected node is stored in CurrentTreeNode, which is a reference to an iterator which
//could be contained AlgorithmMembers.
class PStep_DepthFirstLowestLBSecondNodeSelecter : public PStep_TreeNodeSelecter{
protected:

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

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

	//Basic constructor
	PStep_DepthFirstLowestLBSecondNodeSelecter(std::list<PStep_TreeNode>& NewNodes, std::list<PStep_TreeNode>::iterator& NewCurrentTreeNode, bool& NewIntegerSolutionFound)
		:PStep_TreeNodeSelecter(NewNodes, NewCurrentTreeNode), IntegerSolutionFound(NewIntegerSolutionFound)
	{};

	//Selection functions
	//------------------------------------------------------------------------------------

	//Select a node from the branching tree.
	//It stores the selected TreeNode in CurrentTreeNode.
	//If no integer solution is found yet, this function selects the deepest node.
	//Otherwise it selects the node with the lowest lower bound.
	virtual void Select();

};

#endif