亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
亚洲日本在线a| 午夜精品久久久久久久99水蜜桃| 一本久道久久综合中文字幕| 国内一区二区视频| 男人操女人的视频在线观看欧美| 亚洲一二三四在线| 香蕉久久夜色精品国产使用方法| 亚洲综合久久av| 亚洲国产欧美在线| 亚洲成人av福利| 亚洲一区二区三区国产| 亚洲在线视频一区| 天天做天天摸天天爽国产一区| 一区二区不卡在线播放| 91色|porny| 欧美另类videos死尸| 精品久久久久av影院| 中文字幕日韩av资源站| 久久久亚洲精华液精华液精华液| 日韩午夜中文字幕| xnxx国产精品| 国产精品久久毛片a| 一卡二卡三卡日韩欧美| 午夜电影一区二区三区| 美女免费视频一区二区| 国产91精品欧美| 色婷婷香蕉在线一区二区| 欧美精品在线视频| 精品国产免费一区二区三区香蕉| 国产女人aaa级久久久级| 亚洲欧美另类久久久精品| 午夜久久久久久电影| 国产精品美女久久久久久| 中文字幕免费观看一区| 欧美精品电影在线播放| 亚洲精品一区在线观看| 国产精品二三区| 日韩av网站在线观看| 国产精品一线二线三线精华| 国产成人亚洲精品青草天美| 91麻豆成人久久精品二区三区| 欧美精品久久99| 中文字幕中文字幕中文字幕亚洲无线| 樱桃国产成人精品视频| 国产一区二区三区在线观看免费视频| 一本一道综合狠狠老| 欧美精品一区二区在线观看| 亚洲男人的天堂网| 国产一区二区三区美女| 欧美午夜片在线看| 国产日韩精品久久久| 天堂va蜜桃一区二区三区| 成人黄色国产精品网站大全在线免费观看| 欧美视频一区在线观看| 国产精品丝袜一区| 免费在线观看精品| 欧美色成人综合| 国产精品成人一区二区艾草| 国内精品写真在线观看| 欧美裸体bbwbbwbbw| 亚洲免费资源在线播放| 国产福利91精品一区| 欧美一区二区三区爱爱| 亚洲国产成人高清精品| 91啪亚洲精品| 国产精品国产馆在线真实露脸| 欧美一级欧美一级在线播放| 日韩中文字幕不卡| 亚洲国产美女搞黄色| 国产1区2区3区精品美女| 91麻豆精品国产91久久久资源速度| 久久久91精品国产一区二区精品 | 国产精品成人免费精品自在线观看 | 爽好多水快深点欧美视频| av电影在线观看一区| 国产日韩欧美精品一区| 加勒比av一区二区| 欧美电影免费观看高清完整版在线 | 亚洲欧美日韩国产手机在线 | 日韩电影在线免费看| 91碰在线视频| 国产女主播视频一区二区| 精品在线亚洲视频| 日韩三级视频在线看| 婷婷国产在线综合| 欧美日韩一区二区三区四区五区 | 香蕉久久夜色精品国产使用方法 | 亚洲欧美区自拍先锋| 懂色av一区二区夜夜嗨| 久久精品综合网| 国产精品99久久久久久久女警| 精品日本一线二线三线不卡| 久久精品国产免费| 久久午夜老司机| 丰满少妇久久久久久久| 国产精品伦一区二区三级视频| 成人av动漫网站| 亚洲黄色录像片| 欧美伦理电影网| 久久精品国产99国产精品| 欧美va亚洲va香蕉在线| 国产成人亚洲综合色影视| 亚洲品质自拍视频| 欧美在线三级电影| 琪琪一区二区三区| 久久久99久久| 在线免费观看日本欧美| 日韩精品欧美精品| 欧美精品一区二| 波多野结衣亚洲一区| 亚洲成人高清在线| 久久久青草青青国产亚洲免观| 成人午夜电影小说| 午夜精品久久久久久不卡8050 | 国产一区二区福利| 1000部国产精品成人观看| 在线亚洲一区二区| 极品美女销魂一区二区三区| 中文字幕一区二区视频| 91.com视频| 99久久99久久免费精品蜜臀| 丝袜美腿成人在线| 国产精品久久看| 精品日韩一区二区三区免费视频| 91视频.com| 国产乱对白刺激视频不卡| 亚洲一区二区三区视频在线播放 | 欧美日韩国产123区| 国产91色综合久久免费分享| 亚洲成人黄色影院| 成人午夜视频在线| 国产精品视频线看| 一区二区三区在线免费视频 | 亚洲精选视频免费看| 日韩女优电影在线观看| 色悠悠亚洲一区二区| 久久精品99国产精品| 樱桃视频在线观看一区| 亚洲国产精品t66y| 2021中文字幕一区亚洲| 色噜噜狠狠色综合欧洲selulu| 国产在线视视频有精品| 日韩高清在线不卡| 一区二区三区免费| 国产精品视频观看| 久久一日本道色综合| 日韩一级精品视频在线观看| 欧美色图一区二区三区| 91麻豆国产精品久久| 99久久99久久久精品齐齐| 成人三级在线视频| 国产麻豆精品久久一二三| 久久精品国产精品亚洲精品| 国产精品高潮呻吟| 奇米888四色在线精品| 亚洲天堂福利av| 亚洲色图丝袜美腿| 一区精品在线播放| 亚洲色图欧美偷拍| 日韩一区中文字幕| 1024成人网| 一区二区三区高清不卡| 亚洲综合成人网| 亚洲成人先锋电影| 日本美女一区二区三区视频| 免费一区二区视频| 韩日精品视频一区| 成人免费观看av| 一本色道久久综合狠狠躁的推荐 | 在线观看视频91| 欧美日韩免费观看一区二区三区| 欧美日韩一级黄| 日韩一区二区影院| 久久理论电影网| 亚洲色图视频网站| 亚洲国产一区二区视频| 日韩精品电影一区亚洲| 美国一区二区三区在线播放| 欧美午夜精品久久久久久超碰| 亚洲欧洲另类国产综合| 日韩欧美资源站| 久久影音资源网| 亚洲欧美日韩久久| 视频一区视频二区在线观看| 美女爽到高潮91| 成人做爰69片免费看网站| 欧美视频一二三区| 欧美精品一区二区三区视频| 中文字幕一区在线观看视频| 偷拍一区二区三区| 99久久久国产精品| 精品视频999| 亚洲国产精品二十页| 亚洲成人精品一区二区| 国产精品一卡二卡在线观看| 日本丰满少妇一区二区三区| 日韩精品一区二区三区老鸭窝| 国产精品久久久久婷婷二区次| 亚洲国产成人va在线观看天堂| 国产精品一级片|