<commit_before>/*

This file is part of VROOM.

Copyright (c) 2015-2020, <NAME>.
All rights reserved (see LICENSE).

*/

#include "problems/cvrp/operators/route_exchange.h"

namespace vroom {
namespace cvrp {

RouteExchange::RouteExchange(const Input& input,
                             const utils::SolutionState& sol_state,
                             RawRoute& s_route,
                             Index s_vehicle,
                             RawRoute& t_route,
                             Index t_vehicle)
  : Operator(input,
             sol_state,
             s_route,
             s_vehicle,
             0, // Dummy value
             t_route,
             t_vehicle,
             0) { // Dummy value
  assert(s_vehicle != t_vehicle);
  assert(s_route.size() >= 1 or t_route.size() >= 1);

  // TODO asserts about compatibilities.
}

void RouteExchange::compute_gain() {
  const auto& m = _input.get_matrix();
  const auto& v_source = _input.vehicles[s_vehicle];
  const auto& v_target = _input.vehicles[t_vehicle];

  Gain new_cost = 0;
  Gain previous_cost = 0;

  if (s_route.size() > 0) {
    auto first_s_index = _input.jobs[s_route.front()].index();
    if (v_source.has_start()) {
      previous_cost += m[v_source.start.get().index()][first_s_index];
    }<commit_msg>Assert route exchange validity wrt to compatibility.<commit_after>/*

This file is part of VROOM.

Copyright (c) 2015-2020, <NAME>.
All rights reserved (see LICENSE).

*/

#include "problems/cvrp/operators/route_exchange.h"

namespace vroom {
namespace cvrp {

RouteExchange::RouteExchange(const Input& input,
                             const utils::SolutionState& sol_state,
                             RawRoute& s_route,
                             Index s_vehicle,
                             RawRoute& t_route,
                             Index t_vehicle)
  : Operator(input,
             sol_state,
             s_route,
             s_vehicle,
             0, // Dummy value
             t_route,
             t_vehicle,
             0) { // Dummy value
  assert(s_vehicle != t_vehicle);
  assert(s_route.size() >= 1 or t_route.size() >= 1);

  // Whole routes should be transferable.
  assert(_sol_state.bwd_skill_rank[s_vehicle][t_vehicle] == 0);
  assert(_sol_state.bwd_skill_rank[t_vehicle][s_vehicle] == 0);
}

void RouteExchange::compute_gain() {
  const auto& m = _input.get_matrix();
  const auto& v_source = _input.vehicles[s_vehicle];
  const auto& v_target = _input.vehicles[t_vehicle];

  Gain new_cost = 0;
  Gain previous_cost = 0;

  if (s_route.size() > 0) {
    auto first_s_index = _input.jobs[s_route.front()].index();
    if (v_source.has_start()) {
      previous_cost += m[v_source.start.get().index()][first_s_index];
    }
{'fraction_non_alphanumeric': 0.11317321688500728, 'fraction_numerical': 0.011644832605531296, 'mean_word_length': 2.1489117983963344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1781476', 'n_tokens_mistral': 930, 'n_tokens_neox': 858, 'n_words': 189}