<commit_before>/*VRP*********************************************************************
 *
 * vehicle routing problems
 *      A collection of C++ classes for developing VRP solutions
 *      and specific solutions developed using these classes.
 *
 * Copyright 2014 <NAME> <<EMAIL>>
 * Copyright 2014 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the MIT License. Please file LICENSE for details.
 *
 ********************************************************************VRP*/

#include <exception>
#include <string.h>

#include "signalhandler.h"
#include "vrptools.h"

#ifdef DOSTATS
#include "timer.h"
#endif

#ifdef DOVRPLOG
#include "logger.h"
#endif

#include "trashprob.h"
#include "feasableSol.h"
#include "tabuopt.h"

int vrp_trash_collection( container_t *containers, unsigned int container_count,
                          otherloc_t *otherlocs, unsigned int otherloc_count,
                          vehicle_t *vehicles, unsigned int vehicle_count,
                          ttime_t *ttimes, unsigned int ttime_count,
                          unsigned int iteration,
                          int check,
                          vehicle_path_t **vehicle_paths, int *vehicle_path_count,
                          char **err_msg ) {

    try {
        // register the signal handler
        REG_SIGINT

	#ifdef DOVRPLOG
        if ( not google::IsGoogleLoggingInitialized() ) {
            FLAGS_log_dir = "/tmp/";
            google::InitGoogleLogging( "vrp_trash_collection" );
            FLAGS_logtostderr = 0;
            FLAGS_stderrthreshold = google::FATAL;
            FLAGS_minloglevel = google::INFO;
        }
	#endif


        TrashProb prob(containers,container_count,otherlocs,otherloc_count,ttimes,ttime_count,vehicles,vehicle_count) ;

        if ( check ) {
            std::string err = prob.whatIsWrong();
            if ( err == "" )
                *err_msg = strdup("OK");
            else
                *err_msg = strdup( err.c_str() );
            return 0;
        }

        if ( not prob.isValid() ) {
            std::string err = prob.whatIsWrong();
            *err_msg = strdup( err.c_str() );
            return -1;
        }

        THROW_ON_SIGINT

        FeasableSol tp( prob );
        tp.computeCosts();

        THROW_ON_SIGINT

        TabuOpt ts( tp , iteration);

        Solution best = ts.getBestSolution();
        best.computeCosts();

        int count = 0;
        *vehicle_paths = ts.getSolutionForPg( count );
        *vehicle_path_count = count;

        if ( count == -1 ) {
            *err_msg = ( char * ) "Failed to allocate memory for results!";
            return -1;
        }

        twc->cleanUp();
    }
    catch ( std::exception &e ) {
        *err_msg = ( char * ) e.what();
        return -1;
    }
    catch ( ... ) {
        *err_msg = ( char * ) "Caught unknown expection!";
        return -1;
    }

    return EXIT_SUCCESS;
}<commit_msg>Fixed crashing issue in postgresql integration.<commit_after>/*VRP*********************************************************************
 *
 * vehicle routing problems
 *      A collection of C++ classes for developing VRP solutions
 *      and specific solutions developed using these classes.
 *
 * Copyright 2014 <NAME> <<EMAIL>>
 * Copyright 2014 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the MIT License. Please file LICENSE for details.
 *
 ********************************************************************VRP*/

#include <exception>
#include <string.h>

#include "signalhandler.h"
#include "vrptools.h"

#ifdef DOSTATS
#include "timer.h"
#endif

#ifdef DOVRPLOG
#include "logger.h"
#endif

#include "trashprob.h"
#include "feasableSol.h"
#include "tabuopt.h"

int vrp_trash_collection( container_t *containers, unsigned int container_count,
                          otherloc_t *otherlocs, unsigned int otherloc_count,
                          vehicle_t *vehicles, unsigned int vehicle_count,
                          ttime_t *ttimes, unsigned int ttime_count,
                          unsigned int iteration,
                          int check,
                          vehicle_path_t **vehicle_paths, int *vehicle_path_count,
                          char **err_msg ) {

    try {
        // register the signal handler
        REG_SIGINT

	#ifdef DOVRPLOG
        if ( not google::IsGoogleLoggingInitialized() ) {
            FLAGS_log_dir = "/tmp/";
            google::InitGoogleLogging( "vrp_trash_collection" );
            FLAGS_logtostderr = 0;
            FLAGS_stderrthreshold = google::FATAL;
            FLAGS_minloglevel = google::INFO;
        }
	#endif


        TrashProb prob(containers,container_count,otherlocs,otherloc_count,ttimes,ttime_count,vehicles,vehicle_count) ;

        if ( check ) {
            std::string err = prob.whatIsWrong();
            if ( err == "" )
                *err_msg = strdup("OK");
            else
                *err_msg = strdup( err.c_str() );
            return 0;
        }

        if ( not prob.isValid() ) {
            std::string err = prob.whatIsWrong();
            *err_msg = strdup( err.c_str() );
            return -1;
        }

        THROW_ON_SIGINT

        FeasableSol tp( prob );
        tp.computeCosts();

        THROW_ON_SIGINT

        TabuOpt ts( tp , iteration);

        Solution best = ts.getBestSolution();
        best.computeCosts();

        int count = 0;
        *vehicle_paths = ts.getSolutionForPg( count );
        *vehicle_path_count = count;

        if ( count == -1 ) {
            *err_msg = strdup( "Failed to allocate memory for results!" );
            return -1;
        }

        twc->cleanUp();
    }
    catch ( std::exception &e ) {
        *err_msg = strdup( e.what() );
        return -1;
    }
    catch ( ... ) {
        *err_msg = strdup( "Caught unknown expection!" );
        return -1;
    }

    *err_msg = (char *)0;

    return EXIT_SUCCESS;
}
{'fraction_non_alphanumeric': 0.14432647644326477, 'fraction_numerical': 0.005474452554744526, 'mean_word_length': 2.02964824120603, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '131352', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1706, 'n_words': 432}