<commit_before>/* 
 * File:   main.cpp
 * Author: etudiant
 *
 * Created on 22 avril 2014, 13:44
 */

#include <cstdlib>

#include "parse/tspParser.h"
#include "core/Problem.h"
#include "strategy/Strategy.h"
#include "relation/Swap.h"
#include "strategy/BestFit.h"
#include "run/Runner.h"
#include "utils.h"
#include "strategy/FirstFit.h"
#include "strategy/WorstFit.h"
#include "relation/Insert.h"
#include "relation/Reverse.h"
#include "run/interval/IntervalManager.h"

using namespace std;

//TODO turn that into a function?
#define ARG_CHECK(line, expected) if (++i < argc) {\
                line;\
            } else {\
                PRINTLN("Unsufficient number of arguments, expexted"\
                    << expected);\
            }

bool SILENT = false;

Runner* main_runner;
Problem* main_problem;
int main_maxDepth = 1;
bool main_noDepth = false;
bool main_sameStartingPoint= false;
ofstream* main_f_out = NULL;
ofstream* main_f_out_csv = NULL;
string main_oFileName("");
string main_oFileNameCSV("");
bool main_quietMode = true;
bool main_doubleCheckCost = false;
bool main_noNeighborhoodCutoff = true;

bool main_printIntervalData = false;
bool main_saveIntervalData = false;
ostream* main_intervalCSVoutput = NULL;
IntervalType main_intervalType = DISJOINT;

enum OutputType {
    RESULT,
    CSV,
    INTERVAL_DATA
};

/**
 * Note: requires problem to be initialized.
 * @param type firstFit, bestFit or worstFit are valid types
 * @return Strategy object of the requested type
 * @throws Unrecognized Strategy type
 */
Strategy* createStrategy(std::string type) {
    Strategy* s = NULL;
    if (type == "firstFit") {
        s = new FirstFit(main_problem->getDimension());
    } else if (type == "bestFit") {
        s = new BestFit(main_problem->getDimension());
    } else if (type == "worstFit") {
        s = new WorstFit(main_problem->getDimension());
    } else {
        throw string("Unrecognized Stategy type ").append(type);
    }
    return s;
}

/**
 * Note: strategy must have been initialized.
 * @param type swap
 * @param strategy not NULL
 * @return Relation object of the requested type
 * @throws Unrecognized Relation type
 */
Relation* createRelation(std::string type, Strategy* strategy) {
    Relation* r = NULL;
    if (type == "swap") {
        r = new Swap(*main_problem, strategy);
    } else if (type == "insert") {
        r = new Insert(*main_problem, strategy);
    } else if (type == "reverse") {
        r = new Reverse(*main_problem, strategy);
    } else {
        throw string("Unrecognized Relation type ").append(type);
    }
    return r;
}

/**
 * Displays help.
 */
void printHelp() {
    PRINTLN("TSP - help");
    PRINTLN("\t-help\t\t\t\tdisplays this text");
    
    PRINTLN("\t-file [file path]\t\tspecify which file to read the problem from");
    
    PRINTLN("\t-maxDepth [int]\t\t\tspecify how many times a"
            << " relation will be applied; default = 1");
    PRINTLN("\t-noMaxDepth\t\t\tremoves the depth limit;"
            << " overrides the previous option");
    
    PRINTLN("\t-sameStartingPoint\treuse the same starting path for each run");
    
    PRINTLN("\t-r [relation]\t\t\tspecify a relation to apply to the problem");
    PRINTLN("\t-s [strategy]\t\t\tspecify a strategy to apply to the problem");
    PRINTLN("\t(deprecated) -rs [relation] [strategy]\tspecify a relation & strategy"
            << " to apply to the problem. Note that several -rs can/should"
            << " be specified.");
    
    PRINTLN("\t-quietMode [yes|no]\t\tIf set to no, print depth and loop info."
            << " Defaults to yes.");
    
    PRINTLN("\t-printIntervalData\t\tIf set, print interval status "
            << "everytime a suitable solution is found");
    PRINTLN("\t-intervalType [i_type]\t\tSpecifies the interval type. "
            << "Defaults to disjoint.");
    PRINTLN("\t-intervalStep [integer]\t\tSpecifies an interval growth step");
    
    PRINTLN("\t-doubleCheckCost\t\t\tperform a full calculation check at "
            << "the end of each execution and report inconsitencies");
    
    PRINTLN("\t-neighborhoodCutoff\t\tactivate the neighborhood cutoff "
            << "feature, see below");
    PRINTLN("\t(deprecated) -noNeighborhoodCutoff\tdo not remove any value "
            << "when creating pair lists, even meaningless or redundant ones. "
            << "Note: on by default");
    
    PRINTLN("\t-o [file path]\t\t\tspecifies an output file");
    PRINTLN("\t-o auto\t\t\t\tlet the application name the output file");
    
    PRINTLN("");
    PRINTLN("Valid Relations are\tswap, insert, reverse");
    PRINTLN("Valid Strategies are\tfirstFit, bestFit, worstFit");
    PRINTLN("Valid interval types are\tdisjoint, joined_at_origin");
}

std::string getOutputName(std::string problemName, OutputType type = RESULT) {
    string res("data/results/");
    res.append(problemName);
    time_t t = time(0);
    struct tm* now = localtime( & t );
    res.append(".");
    res.append(std::to_string(1900 + now->tm_year));
    res.append("-");
    res.append(std::to_string(1 + now->tm_mon));
    res.append("-");
    res.append(std::to_string(now->tm_mday));
    res.append("__");
    res.append(std::to_string(1 + now->tm_hour));
    res.append("_");
    res.append(std::to_string(1 + now->tm_min));
    res.append("_");
    res.append(std::to_string(1 + now->tm_sec));
    if (type == CSV)
        res.append(".csv");
    else if (type == INTERVAL_DATA)
        res.append(".csv.i");
    else
        res.append(".results");
    delete(now);
    return res;
}<commit_msg>actually, don't delete that struct, it screws things up<commit_after>/* 
 * File:   main.cpp
 * Author: etudiant
 *
 * Created on 22 avril 2014, 13:44
 */

#include <cstdlib>

#include "parse/tspParser.h"
#include "core/Problem.h"
#include "strategy/Strategy.h"
#include "relation/Swap.h"
#include "strategy/BestFit.h"
#include "run/Runner.h"
#include "utils.h"
#include "strategy/FirstFit.h"
#include "strategy/WorstFit.h"
#include "relation/Insert.h"
#include "relation/Reverse.h"
#include "run/interval/IntervalManager.h"

using namespace std;

//TODO turn that into a function?
#define ARG_CHECK(line, expected) if (++i < argc) {\
                line;\
            } else {\
                PRINTLN("Unsufficient number of arguments, expexted"\
                    << expected);\
            }

bool SILENT = false;

Runner* main_runner;
Problem* main_problem;
int main_maxDepth = 1;
bool main_noDepth = false;
bool main_sameStartingPoint= false;
ofstream* main_f_out = NULL;
ofstream* main_f_out_csv = NULL;
string main_oFileName("");
string main_oFileNameCSV("");
bool main_quietMode = true;
bool main_doubleCheckCost = false;
bool main_noNeighborhoodCutoff = true;

bool main_printIntervalData = false;
bool main_saveIntervalData = false;
ostream* main_intervalCSVoutput = NULL;
IntervalType main_intervalType = DISJOINT;

enum OutputType {
    RESULT,
    CSV,
    INTERVAL_DATA
};

/**
 * Note: requires problem to be initialized.
 * @param type firstFit, bestFit or worstFit are valid types
 * @return Strategy object of the requested type
 * @throws Unrecognized Strategy type
 */
Strategy* createStrategy(std::string type) {
    Strategy* s = NULL;
    if (type == "firstFit") {
        s = new FirstFit(main_problem->getDimension());
    } else if (type == "bestFit") {
        s = new BestFit(main_problem->getDimension());
    } else if (type == "worstFit") {
        s = new WorstFit(main_problem->getDimension());
    } else {
        throw string("Unrecognized Stategy type ").append(type);
    }
    return s;
}

/**
 * Note: strategy must have been initialized.
 * @param type swap
 * @param strategy not NULL
 * @return Relation object of the requested type
 * @throws Unrecognized Relation type
 */
Relation* createRelation(std::string type, Strategy* strategy) {
    Relation* r = NULL;
    if (type == "swap") {
        r = new Swap(*main_problem, strategy);
    } else if (type == "insert") {
        r = new Insert(*main_problem, strategy);
    } else if (type == "reverse") {
        r = new Reverse(*main_problem, strategy);
    } else {
        throw string("Unrecognized Relation type ").append(type);
    }
    return r;
}

/**
 * Displays help.
 */
void printHelp() {
    PRINTLN("TSP - help");
    PRINTLN("\t-help\t\t\t\tdisplays this text");
    
    PRINTLN("\t-file [file path]\t\tspecify which file to read the problem from");
    
    PRINTLN("\t-maxDepth [int]\t\t\tspecify how many times a"
            << " relation will be applied; default = 1");
    PRINTLN("\t-noMaxDepth\t\t\tremoves the depth limit;"
            << " overrides the previous option");
    
    PRINTLN("\t-sameStartingPoint\treuse the same starting path for each run");
    
    PRINTLN("\t-r [relation]\t\t\tspecify a relation to apply to the problem");
    PRINTLN("\t-s [strategy]\t\t\tspecify a strategy to apply to the problem");
    PRINTLN("\t(deprecated) -rs [relation] [strategy]\tspecify a relation & strategy"
            << " to apply to the problem. Note that several -rs can/should"
            << " be specified.");
    
    PRINTLN("\t-quietMode [yes|no]\t\tIf set to no, print depth and loop info."
            << " Defaults to yes.");
    
    PRINTLN("\t-printIntervalData\t\tIf set, print interval status "
            << "everytime a suitable solution is found");
    PRINTLN("\t-intervalType [i_type]\t\tSpecifies the interval type. "
            << "Defaults to disjoint.");
    PRINTLN("\t-intervalStep [integer]\t\tSpecifies an interval growth step");
    
    PRINTLN("\t-doubleCheckCost\t\t\tperform a full calculation check at "
            << "the end of each execution and report inconsitencies");
    
    PRINTLN("\t-neighborhoodCutoff\t\tactivate the neighborhood cutoff "
            << "feature, see below");
    PRINTLN("\t(deprecated) -noNeighborhoodCutoff\tdo not remove any value "
            << "when creating pair lists, even meaningless or redundant ones. "
            << "Note: on by default");
    
    PRINTLN("\t-o [file path]\t\t\tspecifies an output file");
    PRINTLN("\t-o auto\t\t\t\tlet the application name the output file");
    
    PRINTLN("");
    PRINTLN("Valid Relations are\tswap, insert, reverse");
    PRINTLN("Valid Strategies are\tfirstFit, bestFit, worstFit");
    PRINTLN("Valid interval types are\tdisjoint, joined_at_origin");
}

std::string getOutputName(std::string problemName, OutputType type = RESULT) {
    string res("data/results/");
    res.append(problemName);
    time_t t = time(0);
    struct tm* now = localtime( & t );
    res.append(".");
    res.append(std::to_string(1900 + now->tm_year));
    res.append("-");
    res.append(std::to_string(1 + now->tm_mon));
    res.append("-");
    res.append(std::to_string(now->tm_mday));
    res.append("__");
    res.append(std::to_string(1 + now->tm_hour));
    res.append("_");
    res.append(std::to_string(1 + now->tm_min));
    res.append("_");
    res.append(std::to_string(1 + now->tm_sec));
    if (type == CSV)
        res.append(".csv");
    else if (type == INTERVAL_DATA)
        res.append(".csv.i");
    else
        res.append(".results");
    //delete(now);
    return res;
}
{'fraction_non_alphanumeric': 0.14014611546685674, 'fraction_numerical': 0.0037419814682822525, 'mean_word_length': 3.0626131017010496, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 23, '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': '4757655', 'n_tokens_mistral': 3742, 'n_tokens_neox': 3519, 'n_words': 958}