/**
*	\file Utils.h
*	\brief	Contains useful functions needed in the code.
*	\author	Matteo Petris
*	\date	February 2023
*/
#ifndef UTILS_H
#define UTILS_H

#include "Header.h"

//THREAD ID: used to differentiate file names in parellel run
extern string thread;
extern string solutionPath;
extern string instanceName;
extern int labellingCalls;
extern double LB_before_final_MIP;
extern double gap_final_MIP;
extern double time_final_MIP;
//extern bool isOHnotFound;
//extern bool isCliqueNotFound;
//extern bool isToPrint;
extern bool isToBranch;
//extern int counter;

//TIME LIMIT CHECK
extern clock_t BPC_start;
extern double tl;
extern inline bool isBPC_toStop();

//METHODS FOR FLOATING POINT NUMBERS
extern inline bool strictly_less(double x, double y);
extern inline bool less(double x, double y);
extern inline bool equal(double x, double y);
extern inline bool strictly_greater(double x, double y);
extern inline bool greater(double x, double y);
extern inline double minimum(double x, double y);
extern inline double maximum(double x, double y);
extern inline double computeFractionalPart(double x);
extern inline double rounder(double x);
extern inline double rounderToNDecimals(double x, unsigned int precision);

//RANDOM GENERATORS
/**
 * \brief Picks randomly an integer in the interval[_min, _max] by uniform distribution.
 *
 * \param generator : mt19937
 * \return The random integer : int.
 */
extern inline int randomIntBetween(int _min, int _max, mt19937& generator);
/**
 * \brief Picks randomly a probability by uniform distribution.
 *
 * \param generator : mt19937
 * \return The probability : double.
 */
extern inline int pickProbabilityRandomly(mt19937& generator, double min_probability = 0, double max_probability = 1);

//EXCEPTIONS HANDLING
extern inline void handleException(const string& instance, const string& where, const string& when);

//PRINT ON FILE
extern inline void appendToFile(const string& file, const string& content);
extern inline void removeAndWriteFile(const string& file, const string& content);

#endif //UTILS_H