src/tpp.cpp
/**
 * Calculates edge weights based on Euclidean distances.
 *
 * See: http://jriera.webs.ull.es/TPPLIB/Description.pdf
 */
Calculates edge weights based on Euclidean distances.
Calculates edge weights based on Euclidean distances .
vector<vector<int>> calc_edge_weight_matrix(const vector<pair<int, int>> &coords,
                                            EdgeWeightType edge_weight_type) {
    assert(edge_weight_type == EdgeWeightType::EUC_2D);
    vector<vector<int>> weights;
    const auto dimension = coords.size();
    assert(dimension > 1u);
    weights.resize(dimension);
    for (auto &vec : weights) {
        vec.resize(dimension);
    }
    for (auto i = 0u; i < dimension; i++) {
        for (auto j = 0u; j < i; ++j) {
            const auto &a = coords[i];
            const auto &b = coords[j];
            double xd = a.first - b.first;
            double yd = a.second - b.second;
            double co = sqrt(xd * xd + yd * yd);
            int weight = static_cast<int>(co);
            weights[i][j] = weights[j][i] = weight;
        }
    }
    return weights;
}
vector < vector < int > > calc_edge_weight_matrix ( const vector < pair < int , int > > & coords , EdgeWeightType edge_weight_type ) { assert ( edge_weight_type == EdgeWeightType :: EUC_2D ) ; vector < vector < int > > weights ; const auto dimension = coords . size ( ) ; assert ( dimension > 1u ) ; weights . resize ( dimension ) ; for ( auto & vec : weights ) { vec . resize ( dimension ) ; } for ( auto i = 0u ; i < dimension ; i ++ ) { for ( auto j = 0u ; j < i ; ++ j ) { const auto & a = coords [ i ] ; const auto & b = coords [ j ] ; double xd = a . first - b . first ; double yd = a . second - b . second ; double co = sqrt ( xd * xd + yd * yd ) ; int weight = static_cast < int > ( co ) ; weights [ i ] [ j ] = weights [ j ] [ i ] = weight ; } } return weights ; }
Calculates edge weights based on Euclidean distances.
Calculates edge weights based on Euclidean distances .