亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? solution.cpp

?? vrpsd -tabu搜索求解!!!!!!!!!!!!!!!!!!!!!!!
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include "Solution.h"

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

Problem* Solution::problem=0 ;

// Construct a solution and a pointer to initialized problem data.
Solution::Solution( Random* rnd, Control& control,  Problem* p ) :
   vector<int>(p->numberOfCustomers), rg(rnd), computedExpectedCost(false),
   control_(control), move(3,-1),
   allocatedCostToGoMatrix(false),   computedCostToGoMatrix(false)
{
  problem = p;
  useProxy = control_.usingProxy();
 }



// Create a random initial solution (sequence of customers, without thresholds).
void
Solution::initializeRandomSolution() {

  int n = problem->numberOfCustomers;
  int i=0, pick;
  int redo;          // 1 if city already extracted, 0 otherwise
  vector<int> flag(n);
 
  //flag initialization
  flag[0]=1; //the depot cannot be chosen
  for(i=1;i<n;i++) flag[i]=0;

  (*this)[0]=0; //the depot
  for(i=1;i<n;i++){
    do{//extract a new city
      pick= 1+ (int)(rg->next()*(n-1));
      //      cout << pick << endl;///////(int)((double)(n-1)*rand()/(RAND_MAX+1.0));
      if(flag[pick]==1) redo=1;     //already exctracted
      else {                        //store extracted
	(*this)[i]= pick;
	flag[pick]=1;
	redo=0;
      }
    }while(redo==1);
  }
  for(pick=0;pick<n;pick++){       //last city is deterministic 
    if(flag[pick]==0) (*this)[n-1]=pick;
  }
  computedCostToGoMatrix = false; 
}



//OrOpt operator which shift a string into another position of the solution
//according to the current move, and updates the expected cost value.
void
Solution::shift(){
  int i = move[0];
  int k = move[1];
  int j = move[2];
  int n = problem->numberOfCustomers ;

  if(i<0 || i>= n || i+k > n-2 || j< i+k+1 ){
    cout << "Solution::shift(): Error! Move out of range. Exit." << endl;
    return;
  }
 

  vector<int>::iterator first, last, result;

  //cout << "shift(): ";///////////

  //Create a temporary vector with the string to be shifted.
  vector<int> string(k,-1);
  first = begin()+i+1;
  last = first +k;
  result = string.begin();
  copy( first, last, result );

  //Shift backwards the customers after the string untill jth customer.
  first = begin()+i+k+1;
  last = first +j-i-k;
  result = begin()+i+1;
  copy( first, last, result );

  //printOn(cout);//////////////

  //Copy the string into the solution vector.
  first = string.begin();
  last = string.end();
  result = begin() +j-k+1;
  copy( first, last, result );

  //printOn(cout);//////////////

  //Update expectedCost and costToGoMatrix
  if(allocatedCostToGoMatrix == false){
    allocateCostToGoMatrix();          
    allocatedCostToGoMatrix = true;
  }
  expectedCost = computeExpectedCost(costToGoMatrix);
  computedExpectedCost = true;
  computedCostToGoMatrix = true;
}



//OrOpt operator which shift a string into another position of the solution
//according to the current move, without updating the expected cost value.
void
Solution::shiftTSP(){
  int i = move[0];
  int k = move[1];
  int j = move[2];
  int n = problem->numberOfCustomers ;

  if(i<0 || i>= n || i+k > n-2 || j< i+k+1 ){
    cout << "Solution::shift(): Error! Move out of range. Exit." << endl;
    return;
  }
 

  vector<int>::iterator first, last, result;

  //cout << "shift(): ";///////////

  //Create a temporary vector with the string to be shifted.
  vector<int> string(k,-1);
  first = begin()+i+1;
  last = first +k;
  result = string.begin();
  copy( first, last, result );

  //Shift backwards the customers after the string untill jth customer.
  first = begin()+i+k+1;
  last = first +j-i-k;
  result = begin()+i+1;
  copy( first, last, result );

  //printOn(cout);//////////////

  //Copy the string into the solution vector.
  first = string.begin();
  last = string.end();
  result = begin() +j-k+1;
  copy( first, last, result );

  computedCostToGoMatrix = false;
}


//Set the move value equal to the one given as input parameter.
void
Solution::setMove(const vector<int>& m){

  move[0] = m[0];
  move[1]= m[1];
  move[2] = m[2];

}

//Set the first move with fixed string length.
bool 
Solution::firstMove(int len){
  if(len < 0 || len > 3){
    cerr << "Solution::firstMove(int len) error: len must be in the interval [1,3], exit";
      exit(-1);
   }
  int n = problem->numberOfCustomers;
  move[0]= 0;
  move[1]=len;
  
  int j = 1+len +(int)(rg->next()*(n-len-1));//((double)(n-len-1)*rand()/(RAND_MAX + 1.0) );
  move[2]=j;
      
  return true;
}



//Set the next move with fixed string length.
bool 
Solution::nextMove(int len){
  if(len < 0 || len > 3){
    cerr << "Solution::nextMove(int len) error: len must be in the interval [1,3], exit";
      exit(-1);
   }
  int n = problem->numberOfCustomers;

  if (move[0] +1 >= n-len-1) return false;
  else{
    move[0]+= 1;
    move[1]=len;
    int i = move[0];
    int j = i+len+1 +(int)(rg->next()*(n-i-len-1));//( (double)(n-i-len-1)*rand()/(RAND_MAX + 1.0) );
    move[2]=j;
        
    return true;
  }
}

double
Solution::computeMoveValueTSP( const double currentLen ){
  control_.nrDeltaLen++;

  double value = currentLen;
  int n = problem->numberOfCustomers;
  int i = move[0];
  int k = move[1];
  int j = move[2];
  value += problem->distanceMatrix[ (*this)[i] ][ (*this)[(i+k+1)%n] ];
  value += problem->distanceMatrix[ (*this)[(i+k)%n] ][ (*this)[(j+1)%n] ];
  value += problem->distanceMatrix[ (*this)[j] ][ (*this)[(i+1)%n] ];

  value -= problem->distanceMatrix[ (*this)[i] ][ (*this)[(i+1)%n] ];
  value -= problem->distanceMatrix[ (*this)[(i+k)%n] ][ (*this)[(i+ k+ 1)%n] ];
  value -= problem->distanceMatrix[ (*this)[j] ][ (*this)[(j+1)%n] ];

  return value;
}
  

//Compute the value of the solution that would be obtained, if the move would be
//applied to the current solution. 
//The value returned is not exact, if the delta has been computed with the 
//proxy function (computeProxyDelta).
double
Solution::computeMoveValue(){
  control_.nrDeltaCost++;

  double value;
  if( computedCostToGoMatrix == false ){
    if( allocatedCostToGoMatrix == false ) {
      allocateCostToGoMatrix();
      allocatedCostToGoMatrix = true;
    }
    computeExpectedCost(costToGoMatrix);
    computedCostToGoMatrix = true;
  }

  if(useProxy == true) value = expectedCost + computeProxyDelta();
  else value = expectedCost + computeExactDelta();

  return value;
}


//Compute the length of the a priori solution.
double
Solution::computeTourLength(){
  control_.nrLen++;

  int n = problem->numberOfCustomers;
  double len = 0;
  for (int i =0; i<n; i++){
    len += problem->distanceMatrix[ (*this)[i] ][ (*this)[(i+1)%n] ];
  }
  return len;
}


//Compute the expected cost-to-go  and the thresholds,
//the  threshold vector must be given as an argument to the function
//and it must have numberOfCustomers -1 elements
double
Solution::computeExpectedCostAndThresholds(vector<int>& thresholds){
  control_.nrCost++;

  int  Q = problem->capacity;
  int n = problem->numberOfCustomers;
  bool foundThreshold;
  
  if(thresholds.capacity() != (unsigned int)n ) 
    cout << "Error: Solution.cpp: in method double Solution::computeExpectedCostAndThresholds(vector<int> thresholds): thresholds vector does not have numberOfCustomers elements!" << endl;

  //initialization of cost-to-go vectors from the last customer to the depot
  vector<double> 
    costToGo_jplus1(Q+1,problem->distanceMatrix[(*this)[n-1]][0]);
  thresholds[(*this)[n-1]]= 0;  
  //cout << n-1 <<" f()= "<<  costToGo_jplus1[0] << endl;//////////////

  double costRestock;
  double costNoRestock;
  vector<double> costToGo_j(Q+1);
  for(int j=n-2; j>0; j--){
    foundThreshold = false;
    costRestock = this->computeCostIfPreventiveRestock(j,j+1,costToGo_jplus1);
    //cout << j <<" h' " << costRestock << endl;//////////////
    
    
    for(int q=Q; q>=0; q--){
      //compute costToGo in case of proceeding to the next customer
      costNoRestock = this->computeCostIfProceed(q,j,j+1,costToGo_jplus1);
      //cout << j <<" h(" << q << ")= "<< costNoRestock ;//////////////
      
      //choose smaller cost btw preventiveRestock and Proceed, and set threshold
      if(costRestock < costNoRestock){
	if(!foundThreshold){
	  thresholds[(*this)[j]] = q + 1;
	  foundThreshold = true;
	}
	costToGo_j[q]= costRestock;
      }
      else 
	costToGo_j[q] = costNoRestock;
      //cout << " f(" << q << ")= "<<  costToGo_j[q] << endl;//////////////
    }
    
    if(!foundThreshold){
      thresholds[(*this)[j]] = 0;
      foundThreshold = true;
    }
    
    //store chosen cost vector in costToGo_jplus1   
    for(int q=Q; q>=0; q--)
      costToGo_jplus1[q] = costToGo_j[q];
  }  
  
  //j==0: costToGo from the depot on (last iteration)
  thresholds[0] = Q;
  costToGo_j[Q] = this->computeCostIfProceed(Q,0,1,costToGo_jplus1);
  //  cout << " costToGo_j[Q]= " << costToGo_j[Q] << endl;/////////////
  
  expectedCost= costToGo_j[Q]; 
  computedExpectedCost = true;
  return costToGo_j[Q]; 
}



//compute the expected cost-to-go 
double
Solution::computeExpectedCost(){
  control_.nrCost++;

  int  Q = problem->capacity;
  int n = problem->numberOfCustomers;

  //initialization of cost-to-go vectors from the last customer to the depot
  vector<double> 
    costToGo_jplus1(Q+1,problem->distanceMatrix[(*this)[n-1]][0]);
  //cout << n-1 <<" f()= "<<  costToGo_jplus1[0] << endl;//////////////

  double costRestock;
  double costNoRestock;
  vector<double> costToGo_j(Q+1);
  for(int j=n-2; j>0; j--){
    costRestock = this->computeCostIfPreventiveRestock(j,j+1,costToGo_jplus1);
    //cout << j <<" h' " << costRestock << endl;//////////////
    
    for(int q=Q; q>=0; q--){
      //compute costToGo in case of proceeding to the next customer
      costNoRestock = this->computeCostIfProceed(q,j,j+1,costToGo_jplus1);
      //cout << j <<" h(" << q << ")= "<< costNoRestock ;//////////////
      
      //choose smaller cost btw preventiveRestock and Proceed, and set threshold
      if(costRestock < costNoRestock)
	costToGo_j[q]= costRestock;
      else 
	costToGo_j[q] = costNoRestock;
      //cout << " f(" << q << ")= "<<  costToGo_j[q] << endl;//////////////
    }
    
    //store chosen cost vector in costToGo_jplus1   
    for(int q=Q; q>=0; q--)
      costToGo_jplus1[q] = costToGo_j[q];
  }  
  
  //j==0: costToGo from the depot on (last iteration)
  costToGo_j[Q] = this->computeCostIfProceed(Q,0,1,costToGo_jplus1);
  //cout << " costToGo_j[Q]= " << costToGo_j[Q] << endl;/////////////
  
  expectedCost= costToGo_j[Q]; 
  computedExpectedCost = true;
  return costToGo_j[Q]; 
}



//Compute the expected cost-to-go 
//storing the intermediate cost-to-gos in the costToGoMatrix.
double
Solution::computeExpectedCost( vector<vector<double> >& costToGoMatrix){
  control_.nrCost++;

  int  Q = problem->capacity;
  int n = problem->numberOfCustomers;
  

  //Initialization of cost-to-go vectors from the last customer to the depot.
  vector<double> 
    costToGo_jplus1(Q+1,problem->distanceMatrix[(*this)[n-1]][0]);
  for(int q=Q; q>=0; q--)
    costToGoMatrix[n-1][q] = costToGo_jplus1[q];
  //cout << n-1 <<" f()= "<<  costToGo_jplus1[0] << endl;//////////////

  double costRestock;
  double costNoRestock;
  vector<double> costToGo_j(Q+1);
  for(int j=n-2; j>0; j--){
    costRestock = computeCostIfPreventiveRestock(j,j+1,costToGo_jplus1);
    //cout << j <<" h' " << costRestock << endl;//////////////
     
    for(int q=Q; q>=0; q--){
      //compute costToGo in case of proceeding to the next customer
      costNoRestock = computeCostIfProceed(q,j,j+1,costToGo_jplus1);
      //cout << j <<" h(" << q << ")= "<< costNoRestock ;//////////////
      
      //choose smaller cost btw preventiveRestock and Proceed, and set threshold
      if(costRestock < costNoRestock)
	costToGo_j[q]= costRestock;
      else 
	costToGo_j[q] = costNoRestock;

      costToGoMatrix[j][q]= costToGo_j[q]; 
      //cout << " f(" << q << ")= "<<  costToGo_j[q] << endl;//////////////
    }
    
    
    //store chosen cost vector in costToGo_jplus1   
    for(int q=Q; q>=0; q--)
      costToGo_jplus1[q] = costToGo_j[q];
  }  
  
  //j==0: costToGo from the depot on (last iteration)
  costToGo_j[Q] = computeCostIfProceed(Q,0,1,costToGo_jplus1);
  //  cout << " costToGo_j[Q]= " << costToGo_j[Q] << endl;/////////////

  expectedCost= costToGo_j[Q]; //Solution member
  computedExpectedCost = true; //Solution member

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品久久毛片av大全日韩| 亚洲日本一区二区三区| 麻豆精品新av中文字幕| 欧美精品一区二区在线观看| 国产精品456露脸| 亚洲天堂a在线| 日韩精品中午字幕| 日韩二区三区四区| 国产亚洲自拍一区| 色婷婷亚洲精品| 日本vs亚洲vs韩国一区三区| 精品国产乱码久久久久久免费| 亚洲欧洲av另类| 51精品秘密在线观看| 韩国女主播一区二区三区| 中文字幕av不卡| 91精品国产综合久久精品图片| 亚洲天堂成人在线观看| 3d动漫精品啪啪一区二区竹菊| 中文字幕一区在线观看| 日韩一二三区不卡| 色噜噜狠狠一区二区三区果冻| 欧美一区二区三级| 不卡视频免费播放| 免费久久99精品国产| 国产精品久久久久久妇女6080 | 9人人澡人人爽人人精品| 午夜精品久久久久久久久久| 国产精品免费丝袜| 精品国产在天天线2019| 9191国产精品| 在线电影国产精品| 色呦呦国产精品| 国产成人综合网站| 久久99热99| 视频一区欧美精品| 亚洲欧洲美洲综合色网| 久久精品视频在线免费观看| 日韩美女一区二区三区| 6080yy午夜一二三区久久| 欧美日韩国产一级| 欧美精品一级二级三级| 欧美日韩视频在线第一区 | 成人国产电影网| 国产高清亚洲一区| 精品亚洲成av人在线观看| 麻豆国产91在线播放| 日韩av中文在线观看| 国产成人精品网址| 国产在线精品视频| 国产精品99久久久久久宅男| 国产精品一区二区91| 高清在线不卡av| 色噜噜夜夜夜综合网| 欧美色偷偷大香| 欧美sm美女调教| 1024成人网| 亚洲成精国产精品女| 久久电影网站中文字幕| 国产精品1024| 91同城在线观看| 在线播放91灌醉迷j高跟美女| 成人在线视频一区| 97国产一区二区| 欧美蜜桃一区二区三区| 精品成人私密视频| 有码一区二区三区| 久久99精品国产.久久久久| 成人午夜av电影| 69堂亚洲精品首页| 久久久精品日韩欧美| 一区二区三区在线视频播放| 日韩精品三区四区| 成人av电影在线网| 日韩一区二区三区视频在线观看| 日本久久精品电影| 精品sm在线观看| 亚洲一区二区在线观看视频| 男女男精品网站| 在线视频中文字幕一区二区| 国产欧美一区在线| 日韩国产欧美在线播放| 粉嫩一区二区三区在线看| 欧美一激情一区二区三区| 国产欧美日本一区视频| 青青国产91久久久久久| 99精品热视频| 精品福利一二区| 日韩主播视频在线| 在线免费观看日本一区| 国产精品你懂的在线欣赏| 久久精品二区亚洲w码| 欧美精品日韩精品| 亚洲电影激情视频网站| 91成人国产精品| 一区二区三区日本| 欧美系列一区二区| 午夜精品123| 日韩一区二区三区电影 | 91久久精品一区二区| 自拍偷拍国产亚洲| 欧美丝袜丝nylons| 免费人成在线不卡| 国产三级精品三级| 欧美亚洲日本国产| 日韩精品乱码av一区二区| 精品免费日韩av| 成人av电影免费在线播放| 亚洲图片欧美视频| 日韩欧美一区二区视频| 成人av网在线| 婷婷综合五月天| 久久久久免费观看| 91福利区一区二区三区| 国内久久精品视频| 亚洲激情网站免费观看| 精品国产第一区二区三区观看体验| 亚洲婷婷综合久久一本伊一区| 麻豆成人av在线| 椎名由奈av一区二区三区| 精品婷婷伊人一区三区三| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美日韩视频一区二区| 亚洲伊人伊色伊影伊综合网| 日韩一区二区在线免费观看| 日韩激情视频在线观看| 欧美国产综合一区二区| 国产一区二区视频在线播放| 亚洲欧洲制服丝袜| 精品国产网站在线观看| 色综合久久综合网| 蜜桃av一区二区| 亚洲人亚洲人成电影网站色| 日韩一级欧美一级| 99精品视频在线观看免费| 免费成人美女在线观看| 亚洲欧洲精品一区二区三区 | 2022国产精品视频| 91欧美激情一区二区三区成人| 亚洲精品一区二区三区福利| 97精品国产97久久久久久久久久久久 | 国产不卡在线一区| 午夜精品福利久久久| 国产精品成人免费精品自在线观看| 国产综合久久久久久鬼色| 自拍偷自拍亚洲精品播放| 精品国产乱码久久| 亚洲午夜av在线| 一色屋精品亚洲香蕉网站| 久久伊人蜜桃av一区二区| 欧美男人的天堂一二区| 综合自拍亚洲综合图不卡区| 亚洲美女区一区| 亚洲国产岛国毛片在线| 精品日韩99亚洲| 日韩一级在线观看| 69精品人人人人| 欧美伦理电影网| 欧美三区免费完整视频在线观看| 亚洲成人福利片| 国产精品色呦呦| 国产精品灌醉下药二区| 中文一区二区在线观看| 国产亚洲成av人在线观看导航| 国产精品123区| 丁香天五香天堂综合| 九九**精品视频免费播放| 日韩不卡一区二区三区| 蜜桃精品视频在线| 精品一区二区国语对白| 精品无码三级在线观看视频| 激情文学综合丁香| 国产精品自拍网站| 99久久精品99国产精品| 91精品1区2区| 日韩欧美一级在线播放| 久久午夜羞羞影院免费观看| 国产精品三级av| 夜夜亚洲天天久久| 久久机这里只有精品| 国产九色精品成人porny| 91视视频在线观看入口直接观看www | 亚洲国产视频在线| 午夜久久久久久| 国产剧情一区二区| 99re成人精品视频| 911精品产国品一二三产区| 26uuu亚洲综合色| 亚洲欧美成aⅴ人在线观看 | 北条麻妃一区二区三区| 在线观看视频一区二区| 精品国产亚洲一区二区三区在线观看| av成人老司机| 日韩三级在线观看| 亚洲欧洲精品一区二区三区不卡| 日韩免费看的电影| 亚洲免费观看高清完整版在线观看熊 | 久久久激情视频| 亚洲一二三专区| 亚洲美腿欧美偷拍|