<commit_before>#include <gtsplibinstance.h>
#include <typeinfo>
#include <parser/exceptions/exceptions.h>
#include <sstream>

using namespace TSPLIB;


GTSPInstance::GTSPInstance(Instance &instance, TSP::TYPE type)
    : BaseInstance(instance, type)
{
    try {
        GTSPInstance &other = dynamic_cast<GTSPInstance&>(instance);
        // Copy the information from the other GTSP
        // TODO
    } catch(std::bad_cast) {
        // ignore
    }
}

bool GTSPInstance::set_gtsp_cluster_amount(int size)
{
    return true;
}

/**
 * Converts a string of integers to the cluster definitions
 * as follows:
 * add the nodes to the current cluster in case it is not a boundary token (-1)
 * otherwise, add the node to the current cluster
 *
 * Empties the incoming vector
 *
 * @param cluster_definition
 * @return
 */
bool GTSPInstance::set_gtsp_clusters(std::vector<int> cluster_definition)
{
    // TODO: double check for malformed input; does this method always terminate?

    auto begin = cluster_definition.begin();
    auto cluster = 0;
    while(begin != cluster_definition.end()) {
        auto end = begin;
        while(end != cluster_definition.end() && *end != -1) {
            ++end;
        }

        // ASSUMPTION: the cluster numbers are always incremented by 1, starting from 1
        begin++; // skip the cluster index

        clusters.resize(cluster + 1); // potentially expensive

        std::vector<unsigned int> cluster_list;
        for(auto it = begin; it != end; ++it) {
            clusters[cluster].push_back((*it) -1);
        }

        cluster++;
        begin = ++end;
    }

    return true;
}

std::vector<std::vector<unsigned int>> GTSPInstance::get_clusters() const
{
    return clusters;
}<commit_msg>Remove the unsigned restriction from the definition of clusters...<commit_after>#include <gtsplibinstance.h>
#include <typeinfo>
#include <parser/exceptions/exceptions.h>
#include <sstream>

using namespace TSPLIB;


GTSPInstance::GTSPInstance(Instance &instance, TSP::TYPE type)
    : BaseInstance(instance, type)
{
    try {
        GTSPInstance &other = dynamic_cast<GTSPInstance&>(instance);
        // Copy the information from the other GTSP
        // TODO
    } catch(std::bad_cast) {
        // ignore
    }
}

bool GTSPInstance::set_gtsp_cluster_amount(int size)
{
    return true;
}

/**
 * Converts a string of integers to the cluster definitions
 * as follows:
 * add the nodes to the current cluster in case it is not a boundary token (-1)
 * otherwise, add the node to the current cluster
 *
 * @param cluster_definition
 * @return
 */
bool GTSPInstance::set_gtsp_clusters(std::vector<int> cluster_definition)
{
    unsigned int cluster = 0; // convert to internal 0-based indexing
    for(int node : cluster_definition) {
        if(node == -1) {
            cluster++;
        } else if(0 >= node || node > dimension) {
            std::ostringstream err;
            err << "Node value " << node << " is out of range! Dimension of the problem is " << dimension;
            throw TSP::PARSER::Inconsistent_definition_exception(err.str());
        } else {
            if(clusters.size() < cluster + 1) {
                clusters.resize(cluster + 1);
            }
            clusters[cluster].push_back(node-1); // convert to internal 0-based indexing
        }
    }
    return true;
}


{'fraction_non_alphanumeric': 0.11276849642004773, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 2.84077892325315, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 20, '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': '1848550', 'n_tokens_mistral': 988, 'n_tokens_neox': 966, 'n_words': 288}