<commit_before>/*===========================================================================*
 * This file is part of a solver for the Vehicle Routing Problem             *
 * developed using the BiCePS Linear Integer Solver (BLIS).                  *
 *                                                                           *
 * This solver is distributed under the Common Public License as part of     * 
 * the COIN-OR repository (http://www.coin-or.org).                          *
 *                                                                           *
 * Authors: <NAME>, Lehigh University                                        *
 *          <NAME>, Lehigh University                                    *
 *                                                                           *
 * Copyright (C) 2007 <NAME> and <NAME>.                                 *
 * All Rights Reserved.                                                      *
 *===========================================================================*/

#include <iostream>
#include <cmath>

#include "VrpSolution.h"

VrpSolution::VrpSolution(int s, const double *values, double objValue, 
			 VrpModel *vrp) : BlisSolution(s, values, objValue)   
{
   if (!vrp) return;

   int msgLevel = vrp->AlpsPar()->entry(AlpsParams::msgLevel);

   opt_ = new _node[vrp->vertnum_];
   int cur_vert = 0, prev_vert = 0, cur_route, count = 0;
   elist *cur_route_start = NULL;
   edge *edge_data;
   vertex *verts = vrp->n_->verts_;
   int cost = 0;
   
   /*construct the tour corresponding to this solution vector*/
   for (cur_route_start = verts[0].first, cur_route = 1, cost = 0,
	   edge_data = cur_route_start->data; cur_route <= vrp->numroutes_;
	cur_route++){
      edge_data = cur_route_start->data;
      edge_data->scanned = true;
      cur_vert = edge_data->v1;
      opt_[prev_vert].next = cur_vert;
      opt_[cur_vert].route = cur_route;
      prev_vert = 0;
      cost += vrp->computeCost(prev_vert, cur_vert);
      while (cur_vert){
	 if (verts[cur_vert].first->other_end != prev_vert){
	    prev_vert = cur_vert;
	    edge_data = verts[cur_vert].first->data;
	    cur_vert = verts[cur_vert].first->other_end;
	 }
	 else{
	    prev_vert = cur_vert;
	    edge_data = verts[cur_vert].last->data; /*This statement could
						      possibly be taken out to
						      speed things up a bit*/
	    cur_vert = verts[cur_vert].last->other_end;
	 }
	 opt_[prev_vert].next = cur_vert;
	 opt_[cur_vert].route = cur_route;
	 cost += vrp->computeCost(prev_vert, cur_vert);
      }
      edge_data->scanned = true;
      
      while (cur_route_start->data->scanned){
	 if (!(cur_route_start = cur_route_start->next_edge)) break;
      }
   }

   /* Display the solution */
   
   if (msgLevel > 0) {
       std::cout << std::endl << "Solution Found:" << std::endl;
       std::cout << "Solution Cost: " << cost << std::endl;
   }
   
   cur_vert = opt_[0].next;
   
   if (opt_[0].route == 1 && msgLevel > 0) {
       std::cout << std::endl << "0 ";
   }
   
   while (cur_vert != 0){
      if (opt_[prev_vert].route != opt_[cur_vert].route){
	  if (msgLevel > 0) {
	      std::cout << std::endl << "Route #" << opt_[cur_vert].route << ": ";
	  }
	  count = 0;
      }
      if (msgLevel > 0) {
	  std::cout << cur_vert << " ";
      }
      count++;
      if (count > 15){
	  if (msgLevel > 0) {
	      std::cout << std::endl;
	  }
	 count = 0;
      }
      prev_vert = cur_vert;
      cur_vert = opt_[cur_vert].next;
   }
   if (msgLevel > 0) {
       std::cout << std::endl << std::endl;
   }
}

//#############################################################################

void 
VrpSolution::print(std::ostream& os) const {
   
   int cur_vert = opt_[0].next, prev_vert = 0, count = 0;
   
   if (opt_[0].route == 1)
      std::cout << std::endl << "0 ";
   while (cur_vert != 0){
      if (opt_[prev_vert].route != opt_[cur_vert].route){
	 std::cout << std::endl << "Route #" << opt_[cur_vert].route << ": ";
	 count = 0;
      }
      std::cout << cur_vert << " ";
      count++;
      if (count > 15){
	 std::cout << std::endl;
	 count = 0;
      }
      prev_vert = cur_vert;
      cur_vert = opt_[cur_vert].next;
   }
   std::cout << std::endl << std::endl;

   
#if 0
   double nearInt = 0.0;
   
   for (int j = 0; j < size_; ++j) {
      if (values_[j] > 1.0e-15 || values_[j] < -1.0e-15) {
	 nearInt = floor(values_[j] + 0.5);
	 if (ALPS_FABS(nearInt - values_[j]) < 1.0e-6) {
	    os << "x[" << j << "] = " << nearInt << std::endl;
	 }
	 else {
	    os << "x[" << j << "] = " << values_[j] << std::endl;
	 }   
      }
   }
#endif
}<commit_msg>make tsp solution start with 1<commit_after>/*===========================================================================*
 * This file is part of a solver for the Vehicle Routing Problem             *
 * developed using the BiCePS Linear Integer Solver (BLIS).                  *
 *                                                                           *
 * This solver is distributed under the Common Public License as part of     * 
 * the COIN-OR repository (http://www.coin-or.org).                          *
 *                                                                           *
 * Authors: <NAME>, Lehigh University                                        *
 *          <NAME>, Lehigh University                                    *
 *                                                                           *
 * Copyright (C) 2007 <NAME> and <NAME>.                                 *
 * All Rights Reserved.                                                      *
 *===========================================================================*/

#include <iostream>
#include <cmath>

#include "VrpSolution.h"

VrpSolution::VrpSolution(int s, const double *values, double objValue, 
			 VrpModel *vrp) : BlisSolution(s, values, objValue)   
{
   if (!vrp) return;

   int msgLevel = vrp->AlpsPar()->entry(AlpsParams::msgLevel);

   opt_ = new _node[vrp->vertnum_];
   int cur_vert = 0, prev_vert = 0, cur_route, count = 0;
   elist *cur_route_start = NULL;
   edge *edge_data;
   vertex *verts = vrp->n_->verts_;
   int cost = 0;
   
   /*construct the tour corresponding to this solution vector*/
   for (cur_route_start = verts[0].first, cur_route = 1, cost = 0,
	   edge_data = cur_route_start->data; cur_route <= vrp->numroutes_;
	cur_route++){
      edge_data = cur_route_start->data;
      edge_data->scanned = true;
      cur_vert = edge_data->v1;
      opt_[prev_vert].next = cur_vert;
      opt_[cur_vert].route = cur_route;
      prev_vert = 0;
      cost += vrp->computeCost(prev_vert, cur_vert);
      while (cur_vert){
	 if (verts[cur_vert].first->other_end != prev_vert){
	    prev_vert = cur_vert;
	    edge_data = verts[cur_vert].first->data;
	    cur_vert = verts[cur_vert].first->other_end;
	 }
	 else{
	    prev_vert = cur_vert;
	    edge_data = verts[cur_vert].last->data; /*This statement could
						      possibly be taken out to
						      speed things up a bit*/
	    cur_vert = verts[cur_vert].last->other_end;
	 }
	 opt_[prev_vert].next = cur_vert;
	 opt_[cur_vert].route = cur_route;
	 cost += vrp->computeCost(prev_vert, cur_vert);
      }
      edge_data->scanned = true;
      
      while (cur_route_start->data->scanned){
	 if (!(cur_route_start = cur_route_start->next_edge)) break;
      }
   }

   /* Display the solution (tours). */
   if (msgLevel > 0) {
       std::cout << std::endl << "Solution Found:" << std::endl;
       std::cout << "Solution Cost: " << cost << std::endl;
       print(std::cout);
   }
}

//#############################################################################

void 
VrpSolution::print(std::ostream& os) const 
{   
   int cur_vert = opt_[0].next, prev_vert = 0, count = 0;
   
   if (opt_[0].route == 1) {
       //std::cout << std::endl << "0 ";
       std::cout << std::endl << "1 ";  // TSP solution start with 1
   }
   
   while (cur_vert != 0){
      if (opt_[prev_vert].route != opt_[cur_vert].route){
          std::cout << std::endl << "Route #" << opt_[cur_vert].route << ": ";
          count = 0;
      }
      if  (opt_[0].route == 1) {
          std::cout << cur_vert+1 << " ";  // Stardard TSP solution
      }
      else {
          std::cout << cur_vert << " ";    // VRP solution start with 0
      }
      count++;
      if (count > 15){
	 std::cout << std::endl;
	 count = 0;
      }
      prev_vert = cur_vert;
      cur_vert = opt_[cur_vert].next;
   }
   std::cout << std::endl << std::endl;
}

//#############################################################################


{'fraction_non_alphanumeric': 0.19682576459684895, 'fraction_numerical': 0.010194624652455977, 'mean_word_length': 1.9882312218760816, 'pattern_counts': {'":': 3, '<': 138, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4419027', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2570, 'n_words': 600}