<commit_before>/*VRP*********************************************************************
 *
 * vehicle routing problems
 *      A collection of C++ classes for developing VRP solutions
 *      and specific solutions developed using these classes.
 *
 * Copyright 2014 <NAME> <<EMAIL>>
 * Copyright 2014 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the MIT License. Please file LICENSE for details.
 *
 ********************************************************************VRP*/


#ifdef DOVRPLOG
#include "logger.h"
#endif

#include "pg_types_vrp.h"
#include "solution.h"

bool Solution::feasable() const
{
  assert( fleet.size() );

  for ( UINT i = 0; i < fleet.size(); i++ )
    if ( not fleet[i].feasable() ) return false;

  return true;
}

void Solution::evaluate()
{
  assert( fleet.size() );

  for ( UINT i = 0; i < fleet.size(); i++ )
    fleet[i].evaluate();

}


int Solution::countPickups() {
    assert( fleet.size() );

    int count = 0;
    for ( UINT i = 0; i < fleet.size(); i++ )
      count += fleet[i].countPickups();

    return count;
}


int Solution::v_computeCosts()
{
  totalCost = 0.0;
  totalDistance = 0.0;
  int removedPos = -1;

  for ( UINT i = 0; i < fleet.size(); i++ ) {
    if ( fleet[i].size() == 1 ) {
#ifdef DOVRPLOG
      DLOG( INFO ) << "FOUND A TRUCK WITHOUT CONTAINERS";
#endif
      removedPos = i;
      trucks.push_back( fleet[i] );
      fleet.erase( fleet.begin() + i );
      break;
    };
  }

  for ( UINT i = 0; i < fleet.size(); i++ ) {
    totalCost += fleet[i].getCost();
  }

  return removedPos;
}


double Solution::getCostOsrm() {
  totalCost = 0.0;

  for ( UINT i = 0; i < fleet.size(); i++ ) {
    totalCost += fleet[i].getCostOsrm();
  }

  return totalCost;
}

int Solution::computeCosts()
{
  return v_computeCosts();
}

double Solution::getCost() const
{
  return totalCost;
}

double Solution::getDistance() const
{
  return totalDistance;
}
/*
void Solution::dumpSolutionForPg () const
{
  vehicle_path_t *results;
  UINT count;
  results = getSolutionForPg( count ) ;

  for (UINT i = 0; i < count; i++)
    std::cout << "i" << i <<
              "\tseq:" << results[i].seq <<
              "\tVID:" << results[i].vid <<
              "\tnid" << results[i].nid <<
              "\tntype" << results[i].ntype <<
              "\tdeltaTime" << results[i].deltatime <<
              "\tcargo" << results[i].cargo << "\n";

  for ( UINT i = 0; i < fleet.size(); ++i ) {
    if ( fleet[i].size() <= 1 ) continue;

    for ( UINT j = 0; j < fleet[i].size(); ++j ) {
      std::cout << "VID: " << fleet[i].getVid() <<
                "\tid: " << fleet[i][j].id() <<
                "\tntype: " << fleet[i][j].type() <<
                "\tDeparture: " << fleet[i][j].departureTime() <<
                "\tdeltaTime:" << fleet[i][j].deltaTime() <<
                "\tdeltaCargo" << fleet[i][j].demand() << "\n";
    }

    std::cout << "VID: " << fleet[i].getVid() << "\tid: " <<
              fleet[i].getDumpSite().id() <<
              "\tntype: " << fleet[i].getDumpSite().type() <<
              "\tDeparture: " << fleet[i].getDumpSite().departureTime() <<
              "\tdeltaTime:" <<  fleet[i].getDumpSite().deltaTime() <<
              "\tdeltaCargo" << fleet[i].getDumpSite().demand() << "\n";
    std::cout << "VID: " << fleet[i].getVid() << "\tid: " <<
              fleet[i].getEndingSite().id() <<
              "\ttype: " << fleet[i].getEndingSite().type() <<
              "\tDeparture: " << fleet[i].getEndingSite().departureTime() <<
              "\tdeltaTime:" <<  fleet[i].getEndingSite().deltaTime() <<
              "\tdeltaCargo" << fleet[i].getEndingSite().demand() << "\n";
  }

  free(results);
}*/

//Duplicated dumpSolutionForPg in order to change the output
void Solution::dumpSolutionForPg () const
{
  vehicle_path_t *results;
  UINT count;
  results = getSolutionForPg( count ) ;
/*
  std::cout <<"\tseq:" <<
            "\tVID:" <<
            "\tnid" <<
            "\tntype" <<
            "\tdeltaTime" <<
            "\tcargo" << std::endl;
  for (UINT i = 0; i < count; i++)
    std::cout << i <<
              "\t" << results[i].seq <<
              "\t" << results[i].vid <<
              "\t" << results[i].nid <<
              "\t" << results[i].ntype <<
              "\t" << results[i].deltatime <<
              "\t" << results[i].cargo << std::endl;
              */

  for ( UINT i = 0; i < fleet.size(); ++i ) {
    if ( fleet[i].size() <= 1 ) continue;
    int seq = 0;
    std::cout <<
              "seq" <<
              "\tVID" <<
              "\tid" <<
              "\tntype" <<
              "\tDeparture" <<
              "\tdeltaTime" <<
              "\tdeltaCargo" << std::endl;
    for ( UINT j = 0; j < fleet[i].size(); ++j ) {
      seq++;
      std::cout <<
                 seq <<
                "\t" << fleet[i].getVid() <<
                "\t" << fleet[i][j].id() <<
                "\t" << fleet[i][j].type() <<
                "\t" << fleet[i][j].departureTime() <<
                "\t" << fleet[i][j].deltaTime() <<
                "\t" << fleet[i][j].demand() << std::endl;
    }
    seq++;
    std::cout <<
              seq  <<
              "\t" << fleet[i].getVid() <<
              "\t" << fleet[i].getDumpSite().id() <<
              "\t" << fleet[i].getDumpSite().type() <<
              "\t" << fleet[i].getDumpSite().departureTime() <<<commit_msg>se cambia salida<commit_after>/*VRP*********************************************************************
 *
 * vehicle routing problems
 *      A collection of C++ classes for developing VRP solutions
 *      and specific solutions developed using these classes.
 *
 * Copyright 2014 <NAME> <<EMAIL>>
 * Copyright 2014 <NAME> <<EMAIL>>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the MIT License. Please file LICENSE for details.
 *
 ********************************************************************VRP*/


#ifdef DOVRPLOG
#include "logger.h"
#endif

#include "pg_types_vrp.h"
#include "solution.h"

bool Solution::feasable() const
{
  assert( fleet.size() );

  for ( UINT i = 0; i < fleet.size(); i++ )
    if ( not fleet[i].feasable() ) return false;

  return true;
}

void Solution::evaluate()
{
  assert( fleet.size() );

  for ( UINT i = 0; i < fleet.size(); i++ )
    fleet[i].evaluate();

}


int Solution::countPickups() {
    assert( fleet.size() );

    int count = 0;
    for ( UINT i = 0; i < fleet.size(); i++ )
      count += fleet[i].countPickups();

    return count;
}


int Solution::v_computeCosts()
{
  totalCost = 0.0;
  totalDistance = 0.0;
  int removedPos = -1;

  for ( UINT i = 0; i < fleet.size(); i++ ) {
    if ( fleet[i].size() == 1 ) {
#ifdef DOVRPLOG
      DLOG( INFO ) << "FOUND A TRUCK WITHOUT CONTAINERS";
#endif
      removedPos = i;
      trucks.push_back( fleet[i] );
      fleet.erase( fleet.begin() + i );
      break;
    };
  }

  for ( UINT i = 0; i < fleet.size(); i++ ) {
    totalCost += fleet[i].getCost();
  }

  return removedPos;
}


double Solution::getCostOsrm() {
  totalCost = 0.0;

  for ( UINT i = 0; i < fleet.size(); i++ ) {
    totalCost += fleet[i].getCostOsrm();
  }

  return totalCost;
}

int Solution::computeCosts()
{
  return v_computeCosts();
}

double Solution::getCost() const
{
  return totalCost;
}

double Solution::getDistance() const
{
  return totalDistance;
}
/*
void Solution::dumpSolutionForPg () const
{
  vehicle_path_t *results;
  UINT count;
  results = getSolutionForPg( count ) ;

  for (UINT i = 0; i < count; i++)
    std::cout << "i" << i <<
              "\tseq:" << results[i].seq <<
              "\tVID:" << results[i].vid <<
              "\tnid" << results[i].nid <<
              "\tntype" << results[i].ntype <<
              "\tdeltaTime" << results[i].deltatime <<
              "\tcargo" << results[i].cargo << "\n";

  for ( UINT i = 0; i < fleet.size(); ++i ) {
    if ( fleet[i].size() <= 1 ) continue;

    for ( UINT j = 0; j < fleet[i].size(); ++j ) {
      std::cout << "VID: " << fleet[i].getVid() <<
                "\tid: " << fleet[i][j].id() <<
                "\tntype: " << fleet[i][j].type() <<
                "\tDeparture: " << fleet[i][j].departureTime() <<
                "\tdeltaTime:" << fleet[i][j].deltaTime() <<
                "\tdeltaCargo" << fleet[i][j].demand() << "\n";
    }

    std::cout << "VID: " << fleet[i].getVid() << "\tid: " <<
              fleet[i].getDumpSite().id() <<
              "\tntype: " << fleet[i].getDumpSite().type() <<
              "\tDeparture: " << fleet[i].getDumpSite().departureTime() <<
              "\tdeltaTime:" <<  fleet[i].getDumpSite().deltaTime() <<
              "\tdeltaCargo" << fleet[i].getDumpSite().demand() << "\n";
    std::cout << "VID: " << fleet[i].getVid() << "\tid: " <<
              fleet[i].getEndingSite().id() <<
              "\ttype: " << fleet[i].getEndingSite().type() <<
              "\tDeparture: " << fleet[i].getEndingSite().departureTime() <<
              "\tdeltaTime:" <<  fleet[i].getEndingSite().deltaTime() <<
              "\tdeltaCargo" << fleet[i].getEndingSite().demand() << "\n";
  }

  free(results);
}*/

//Duplicated dumpSolutionForPg in order to change the output
void Solution::dumpSolutionForPg () const
{
  vehicle_path_t *results;
  UINT count;
  results = getSolutionForPg( count ) ;
/*
  std::cout <<"\tseq:" <<
            "\tVID:" <<
            "\tnid" <<
            "\tntype" <<
            "\tdeltaTime" <<
            "\tcargo" << std::endl;
  for (UINT i = 0; i < count; i++)
    std::cout << i <<
              "\t" << results[i].seq <<
              "\t" << results[i].vid <<
              "\t" << results[i].nid <<
              "\t" << results[i].ntype <<
              "\t" << results[i].deltatime <<
              "\t" << results[i].cargo << std::endl;
              */

  for ( UINT i = 0; i < fleet.size(); ++i ) {
    if ( fleet[i].size() <= 1 ) continue;
    int seq = 0;
    std::cout <<
              "seq" <<
              "\tVID" <<
              "\tid" <<
              "\tntype" <<
              "\tDepart" <<
              "\tdTime" <<
              "\tdCargo" << std::endl;
    for ( UINT j = 0; j < fleet[i].size(); ++j ) {
      seq++;
      std::cout <<
                 seq <<
                "\t" << fleet[i].getVid() <<
                "\t" << fleet[i][j].id() <<
                "\t" << fleet[i][j].type() <<
                "\t" << fleet[i][j].departureTime() <<
                "\t" << fleet[i][j].deltaTime() <<
                "\t" << fleet[i][j].demand() << std::endl;
    }
    seq++;
    std::cout <<
              seq  <<
              "\t" << fleet[i].getVid() <<
              "\t" << fleet[i].getDumpSite().id() <<
              "\t" << fleet[i].getDumpSite().type() <<
              "\t" << fleet[i].getDumpSite().departureTime() <<
{'fraction_non_alphanumeric': 0.22623853211009173, 'fraction_numerical': 0.005871559633027523, 'mean_word_length': 2.0322670375521557, 'pattern_counts': {'":': 0, '<': 475, '<?xml version=': 0, '>': 15, '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': '1994513', 'n_tokens_mistral': 3742, 'n_tokens_neox': 3597, 'n_words': 772}