<commit_before>/*
VROOM (Vehicle Routing Open-source Optimization Machine)
Copyright (C) 2015, <NAME>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "logger.h"

logger::logger(const cl_args_t& cl_args):
  _cl_args(cl_args) {}

std::string logger::tour_to_string(const tsp& instance,
                                   const std::list<index_t>& tour,
                                   const timing_t& computing_times) const{
  std::string route_summary;
  unsigned long route_summary_duration = 0;
  if(_cl_args.loader == 0 and _cl_args.geometry){
    // Get route informations summary when using OSRM.
    auto start_route_summary = std::chrono::high_resolution_clock::now();
    route_summary = instance.get_route_summary(tour);
    auto end_route_summary = std::chrono::high_resolution_clock::now();
    route_summary_duration =
      std::chrono::duration_cast<std::chrono::milliseconds>
      (end_route_summary - start_route_summary).count();
  }

  // Execution informations.
  std::string json_log = "{\"computing_times\":{";
  json_log += "\"matrix_loading\":"
    + std::to_string(computing_times.matrix_loading) + ",";
  json_log += "\"route\":{\"heuristic\":"
    + std::to_string(computing_times.heuristic) + ",";
  json_log += "\"local_search\":"
    + std::to_string(computing_times.local_search) + "}";
  if(_cl_args.loader == 0 and _cl_args.geometry){
    // Log route information timing when using OSRM.
    json_log += ",\"detailed_geometry\":" + std::to_string(route_summary_duration);
  }
  json_log += "},";

  // Solution found.
  auto places = instance.get_places();
  auto m = instance.get_matrix();
  std::string tour_str = "\"route\":[";
  for(auto step = tour.cbegin(); step != tour.cend(); ++step){
    tour_str += "[" + std::to_string(places[*step].first)
      + "," + std::to_string(places[*step].second) + "],";
  }
  tour_str.pop_back();          // Remove trailing comma.
  tour_str += "],";

  json_log += tour_str;

  json_log += "\"total_length\":" + std::to_string(instance.cost(tour)) + ",";

  if(_cl_args.loader == 0 and _cl_args.geometry){
    // Add route informations summary when using OSRM.
    json_log += route_summary;
  }
  else{
    json_log.pop_back();        // Remove trailing comma.
  }
  
  json_log += "}";
  
  return json_log;
}
<commit_msg>Rename cost of solution in output.<commit_after>/*
VROOM (Vehicle Routing Open-source Optimization Machine)
Copyright (C) 2015, <NAME>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "logger.h"

logger::logger(const cl_args_t& cl_args):
  _cl_args(cl_args) {}

std::string logger::tour_to_string(const tsp& instance,
                                   const std::list<index_t>& tour,
                                   const timing_t& computing_times) const{
  std::string route_summary;
  unsigned long route_summary_duration = 0;
  if(_cl_args.loader == 0 and _cl_args.geometry){
    // Get route informations summary when using OSRM.
    auto start_route_summary = std::chrono::high_resolution_clock::now();
    route_summary = instance.get_route_summary(tour);
    auto end_route_summary = std::chrono::high_resolution_clock::now();
    route_summary_duration =
      std::chrono::duration_cast<std::chrono::milliseconds>
      (end_route_summary - start_route_summary).count();
  }

  // Execution informations.
  std::string json_log = "{\"computing_times\":{";
  json_log += "\"matrix_loading\":"
    + std::to_string(computing_times.matrix_loading) + ",";
  json_log += "\"route\":{\"heuristic\":"
    + std::to_string(computing_times.heuristic) + ",";
  json_log += "\"local_search\":"
    + std::to_string(computing_times.local_search) + "}";
  if(_cl_args.loader == 0 and _cl_args.geometry){
    // Log route information timing when using OSRM.
    json_log += ",\"detailed_geometry\":" + std::to_string(route_summary_duration);
  }
  json_log += "},";

  // Solution found.
  auto places = instance.get_places();
  auto m = instance.get_matrix();
  std::string tour_str = "\"route\":[";
  for(auto step = tour.cbegin(); step != tour.cend(); ++step){
    tour_str += "[" + std::to_string(places[*step].first)
      + "," + std::to_string(places[*step].second) + "],";
  }
  tour_str.pop_back();          // Remove trailing comma.
  tour_str += "],";

  json_log += tour_str;

  json_log += "\"solution_cost\":" + std::to_string(instance.cost(tour)) + ",";

  if(_cl_args.loader == 0 and _cl_args.geometry){
    // Add route informations summary when using OSRM.
    json_log += route_summary;
  }
  else{
    json_log.pop_back();        // Remove trailing comma.
  }
  
  json_log += "}";
  
  return json_log;
}

{'fraction_non_alphanumeric': 0.13442906574394464, 'fraction_numerical': 0.0031141868512110727, 'mean_word_length': 3.7114914425427874, 'pattern_counts': {'":': 16, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7180671', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1796, 'n_words': 477}