<commit_before>#ifndef PANCAKE_H
#define PANCAKE_H

#include <stdint.h>
#include <iostream>
#include "SearchEnvironment.h"
#include "PermutationPuzzleEnvironment.h"

class PancakePuzzleState {
public:
	PancakePuzzleState() { puzzle.clear(); }

	PancakePuzzleState(unsigned int puzzle_size) {
		puzzle.resize(puzzle_size);
		for (unsigned int x = 0; x < puzzle.size(); x++)
			puzzle[x] = x;
	}
	std::vector<int> puzzle;
};

static std::ostream& operator <<(std::ostream & out, const PancakePuzzleState &loc)
{
	for (unsigned int x = 0; x < loc.puzzle.size(); x++)
		out << loc.puzzle[x] << " ";
	return out;
}

static bool operator==(const PancakePuzzleState &l1, const PancakePuzzleState &l2)
{
	if (l1.puzzle.size() != l2.puzzle.size())
		return false;

	for (unsigned int x = 0; x < l1.puzzle.size(); x++)
		if (l1.puzzle[x] != l2.puzzle[x])
			return false;
	return true;
}

class PancakePuzzle : public PermutationPuzzleEnvironment<PancakePuzzleState, unsigned> {
public:
	PancakePuzzle(unsigned s);
	PancakePuzzle(unsigned size, const std::vector<unsigned> op_order); // used to set action order

	~PancakePuzzle();
	void GetSuccessors(PancakePuzzleState &state, std::vector<PancakePuzzleState> &neighbors) const;
	void GetActions(PancakePuzzleState &state, std::vector<unsigned> &actions) const;
	unsigned GetAction(PancakePuzzleState &s1, PancakePuzzleState &s2) const;
	void ApplyAction(PancakePuzzleState &s, unsigned a) const;
	bool InvertAction(unsigned &a) const;

	double HCost(PancakePuzzleState &state1, PancakePuzzleState &state2);
	double HCost(PancakePuzzleState &state1);

	double GCost(PancakePuzzleState &, PancakePuzzleState &) {return 2.0;}
	double GCost(PancakePuzzleState &, unsigned &) { return 1.0; }
	bool GoalTest(PancakePuzzleState &state, PancakePuzzleState &goal);

	bool GoalTest(PancakePuzzleState &s);

	uint64_t GetActionHash(unsigned act) const;
	void StoreGoal(PancakePuzzleState &); // stores the locations for the given goal state
	void ClearGoal(){} // clears the current stored information of the goal

	bool IsGoalStored(){return goal_stored;} // returns if a goal is stored or not

	/**
	Changes the ordering of operators to the new inputted order
	**/
	void Change_Op_Order(const std::vector<unsigned> op_order);

	// currently not drawing anything
	void OpenGLDraw() const{}
	void OpenGLDraw(const PancakePuzzleState &) const {}
	void OpenGLDraw(const PancakePuzzleState &, const unsigned &) const {}
	void OpenGLDraw(const PancakePuzzleState&, const PancakePuzzleState&, float) const {}

	/**
	**/
	static void Create_Random_Pancake_Puzzles(std::vector<PancakePuzzleState> &puzzle_vector, unsigned size, unsigned num_puzzles);

	static int read_in_pancake_puzzles(const char *filename, bool first_counter, unsigned size, unsigned max_puzzles, std::vector<PancakePuzzleState> &puzzle_vector);

	bool State_Check(const PancakePuzzleState &to_check) {
		if(to_check.puzzle.size() != size)
			return false;

		return true;
	}

	bool Path_Check(PancakePuzzleState start, PancakePuzzleState goal, std::vector<unsigned> &actions);

	/**
	Returns a possible ordering of the operators. The orders are in a "lexicographic"
	with the original ordering being 2, 3, ..., num_pancakes. This is therefore the order
	returned with a call of order_num=0. The default ordering used when a PancakePuzzle
	environment is created is num_pancakes, ..., 2 which is returned with a call of
	num_pancakes! -1.
	**/
	static std::vector<unsigned> Get_Puzzle_Order(int64_t order_num, unsigned num_pancakes);

private:

	std::vector<unsigned> operators;
	bool goal_stored; // whether a goal is stored or not

	PancakePuzzleState goal;
	unsigned size;
};

//typedef UnitSimulation<PancakePuzzleState, unsigned, Pancake> PancakeSimulation;
#endif<commit_msg>Forgot this file in the last commit.<commit_after>#ifndef PANCAKE_H
#define PANCAKE_H

#include <stdint.h>
#include <iostream>
#include "SearchEnvironment.h"
#include "PermutationPuzzleEnvironment.h"
#include <sstream>

class PancakePuzzleState {
public:
	PancakePuzzleState() { puzzle.clear(); }

	PancakePuzzleState(unsigned int puzzle_size) {
		puzzle.resize(puzzle_size);
		for (unsigned int x = 0; x < puzzle.size(); x++)
			puzzle[x] = x;
	}
	std::vector<int> puzzle;
};

static std::ostream& operator <<(std::ostream & out, const PancakePuzzleState &loc)
{
	for (unsigned int x = 0; x < loc.puzzle.size(); x++)
		out << loc.puzzle[x] << " ";
	return out;
}

static bool operator==(const PancakePuzzleState &l1, const PancakePuzzleState &l2)
{
	if (l1.puzzle.size() != l2.puzzle.size())
		return false;

	for (unsigned int x = 0; x < l1.puzzle.size(); x++)
		if (l1.puzzle[x] != l2.puzzle[x])
			return false;
	return true;
}

class PancakePuzzle : public PermutationPuzzleEnvironment<PancakePuzzleState, unsigned> {
public:
	PancakePuzzle(unsigned s);
	PancakePuzzle(unsigned size, const std::vector<unsigned> op_order); // used to set action order

	~PancakePuzzle();
	void GetSuccessors(PancakePuzzleState &state, std::vector<PancakePuzzleState> &neighbors) const;
	void GetActions(PancakePuzzleState &state, std::vector<unsigned> &actions) const;
	unsigned GetAction(PancakePuzzleState &s1, PancakePuzzleState &s2) const;
	void ApplyAction(PancakePuzzleState &s, unsigned a) const;
	bool InvertAction(unsigned &a) const;

	double HCost(PancakePuzzleState &state1, PancakePuzzleState &state2);
	double Memory_Free_HCost(PancakePuzzleState &state1, std::vector<int> &goal_locs);
	double HCost(PancakePuzzleState &state1);

	double GCost(PancakePuzzleState &state1, PancakePuzzleState &state2) {return 1.0;}
	double GCost(PancakePuzzleState &state1, unsigned &act) { return 1.0; }

	bool GoalTest(PancakePuzzleState &state, PancakePuzzleState &goal);

	bool GoalTest(PancakePuzzleState &s);

	uint64_t GetActionHash(unsigned act) const;
	void StoreGoal(PancakePuzzleState &); // stores the locations for the given goal state

	virtual const std::string GetName();
	std::vector<unsigned> Get_Op_Order(){return operators;}

	/** Returns stored goal state if it is stored.**/
	PancakePuzzleState Get_Goal(){
		if(!goal_stored) {
			fprintf(stderr, "ERROR: Call to Get_Goal when no goal stored\n");
			exit(1);
		}
		return goal;
	}

	void ClearGoal(){} // clears the current stored information of the goal

	bool IsGoalStored(){return goal_stored;} // returns if a goal is stored or not

	/**
	Changes the ordering of operators to the new inputted order
	**/
	void Change_Op_Order(const std::vector<unsigned> op_order);

	// currently not drawing anything
	void OpenGLDraw() const{}
	void OpenGLDraw(const PancakePuzzleState &) const {}
	void OpenGLDraw(const PancakePuzzleState &, const unsigned &) const {}
	void OpenGLDraw(const PancakePuzzleState&, const PancakePuzzleState&, float) const {}

	/**
	**/
	static void Create_Random_Pancake_Puzzles(std::vector<PancakePuzzleState> &puzzle_vector, unsigned size, unsigned num_puzzles);

	static int read_in_pancake_puzzles(const char *filename, bool first_counter, unsigned size, unsigned max_puzzles, std::vector<PancakePuzzleState> &puzzle_vector);

	bool State_Check(const PancakePuzzleState &to_check) {
		if(to_check.puzzle.size() != size)
			return false;

		return true;
	}

	bool Path_Check(PancakePuzzleState start, PancakePuzzleState goal, std::vector<unsigned> &actions);

	/**
	Returns a possible ordering of the operators. The orders are in a "lexicographic"
	with the original ordering being 2, 3, ..., num_pancakes. This is therefore the order
	returned with a call of order_num=0. The default ordering used when a PancakePuzzle
	environment is created is num_pancakes, ..., 2 which is returned with a call of
	num_pancakes! -1.
	**/
	static std::vector<unsigned> Get_Puzzle_Order(int64_t order_num, unsigned num_pancakes);

	void Set_Use_Memory_Free_Heuristic(bool to_use){use_memory_free = to_use;}

private:

	std::vector<unsigned> operators;
	bool goal_stored; // whether a goal is stored or not
	bool use_memory_free;

	PancakePuzzleState goal;
	std::vector<int> goal_locations;
	unsigned size;
};

//typedef UnitSimulation<PancakePuzzleState, unsigned, Pancake> PancakeSimulation;
#endif
{'fraction_non_alphanumeric': 0.10888533857687108, 'fraction_numerical': 0.007496620376059973, 'mean_word_length': 5.759136212624584, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1656089', 'n_tokens_mistral': 2991, 'n_tokens_neox': 2722, 'n_words': 748}