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

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

?? solution.cpp

?? 隨機vrp 3
?? 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();
 }


void Solution::perturbTSP(){  

  int n = problem->numberOfCustomers ;  
  move[0] = 1+(int)(rg->next()*(n-2)); 
  move[2] = move[0]+1+(int)(rg->next()*(n-(move[0]+1))); 
  while (move[0]<0 || move[0]>= n || move[0] > n-2 || move[2]< move[0]+2 ) { 
    move[0] = 1+(int)(rg->next()*(n-2)); 
    move[2] = move[0]+1+(int)(rg->next()*(n-(move[0]+1))); 
  } 
  if(move[0]<0 || move[0]>= n || move[0] > n-2 || move[2]< move[0] ){  
    cout << "Solution::shift(): Error! Move out of range. Exit." << endl;  
    return;  
  }
  int tmp;
  for(int i = 0; i < (move[2]-move[0])/2; i++) { 
    tmp = (*this)[move[0]+i];
    (*this)[move[0]+i] = (*this)[move[2]-i];
    (*this)[move[2]-i] = tmp;
  }

}  


// 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;//////////////
    }
    
    

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕亚洲综合久久菠萝蜜| 色婷婷久久99综合精品jk白丝| 精品国产91洋老外米糕| 丁香桃色午夜亚洲一区二区三区| 国产欧美精品区一区二区三区| 日韩欧美国产不卡| 91超碰这里只有精品国产| 在线视频中文字幕一区二区| 色综合亚洲欧洲| 97久久精品人人澡人人爽| 国产精品亚洲成人| 成人教育av在线| 91香蕉视频污| 欧美美女黄视频| 欧美精品日韩精品| 国产精品久久久久久久蜜臀| 亚洲欧美日韩国产综合在线| 亚洲欧美激情一区二区| 国产精品一二三区| 精品日韩在线一区| 国产午夜亚洲精品理论片色戒| 国产一区二区三区四| 欧美精品一区二区三区蜜臀 | 99久久er热在这里只有精品66| 欧美乱熟臀69xxxxxx| 亚洲精品高清在线| 亚洲一区二区在线观看视频| 视频一区二区欧美| 美女脱光内衣内裤视频久久网站| 奇米精品一区二区三区在线观看一 | 欧美一区在线视频| 亚洲精品在线一区二区| 丝袜a∨在线一区二区三区不卡 | 成人免费毛片片v| 久久精品一区四区| 国产麻豆精品一区二区| 蜜桃在线一区二区三区| 欧美在线不卡一区| 一区二区视频在线| 亚洲激情自拍视频| 日本韩国欧美在线| 国产免费成人在线视频| 成人免费高清在线观看| 亚洲欧洲成人自拍| 欧洲色大大久久| 午夜激情综合网| 97se亚洲国产综合自在线不卡| 亚洲国产精华液网站w| 日韩电影免费在线看| 91小视频免费观看| 亚洲国产精品一区二区久久恐怖片 | 欧美tickling挠脚心丨vk| 麻豆91在线播放免费| 日本一区二区三区久久久久久久久不 | 国产免费观看久久| 成人黄色免费短视频| 一区二区三区在线视频观看58| 欧美日韩精品欧美日韩精品一综合| 久久综合久久久久88| 日韩av电影免费观看高清完整版在线观看| 欧美久久一区二区| 久久99精品国产.久久久久久| 欧美专区亚洲专区| 久久国内精品视频| 日韩一区二区三区在线观看| 亚洲一区二区三区视频在线| 日韩一级完整毛片| 91免费版在线| 麻豆视频观看网址久久| 国产精品成人网| 日韩精品影音先锋| 91在线视频播放| 久久av中文字幕片| 一区二区三区四区高清精品免费观看 | 91最新地址在线播放| 日本午夜一本久久久综合| 国产欧美一区二区三区在线老狼| 欧美色精品在线视频| 一区二区三区在线播| 精品欧美一区二区在线观看| 在线欧美一区二区| 国产成人精品亚洲日本在线桃色| 国产日产精品一区| 日韩一区二区影院| 在线观看国产91| 成人久久久精品乱码一区二区三区| 午夜视频在线观看一区| 国产精品久久久久久久午夜片| 精品久久久久久久久久久久包黑料 | 国产成人免费视频| 日韩精品国产欧美| 一区二区成人在线| 国产目拍亚洲精品99久久精品| 日韩欧美的一区| 欧美色视频一区| 色欧美乱欧美15图片| 国产毛片精品视频| 美国十次综合导航| 日韩精品免费视频人成| 夜夜嗨av一区二区三区网页| 国产精品超碰97尤物18| 久久久91精品国产一区二区三区| 555夜色666亚洲国产免| 欧美色图一区二区三区| 日韩av在线播放中文字幕| 亚洲中国最大av网站| 亚洲美女屁股眼交| 亚洲精选免费视频| 亚洲精品成人天堂一二三| 18欧美亚洲精品| 中文字幕不卡在线播放| 国产精品久久久久久久久免费相片 | 午夜精品免费在线| 亚洲成人在线网站| 国产精品伊人色| 成人免费一区二区三区视频| 久久久99精品免费观看| 久久久久高清精品| 色综合久久99| 一本大道久久a久久综合婷婷| 成人av在线网站| 91丨porny丨首页| 色综合网站在线| 欧洲色大大久久| 欧美高清精品3d| 欧美一区二区三区免费大片| 日韩午夜三级在线| 精品福利在线导航| 欧美吞精做爰啪啪高潮| 欧美色图免费看| 欧美一二区视频| 国产性天天综合网| 日韩一区中文字幕| 丝袜国产日韩另类美女| 国产综合成人久久大片91| 午夜私人影院久久久久| 久久国产精品第一页| 国产成人精品www牛牛影视| www.av精品| 国产成人高清在线| 色就色 综合激情| 欧美一区二区私人影院日本| 国产亚洲人成网站| 亚洲激情av在线| 美女视频网站久久| 99久久国产免费看| 欧美一区二区黄| 中文字幕在线观看不卡| 亚洲一区二区三区四区在线观看| 九九视频精品免费| 99国产精品久久久久久久久久| 欧美日韩精品二区第二页| 久久先锋影音av| 一区二区三区视频在线看| 久久99精品国产91久久来源| 91一区二区三区在线观看| 日韩一区二区三区电影在线观看| 中文字幕不卡三区| 免费看日韩精品| 99在线精品视频| 欧美mv日韩mv国产网站app| 亚洲人精品一区| 国产盗摄女厕一区二区三区| 制服丝袜一区二区三区| 99精品视频一区二区三区| 亚洲免费资源在线播放| 琪琪久久久久日韩精品| 成人午夜电影久久影院| 91精品国产免费| 亚洲色图在线视频| 亚洲国产成人午夜在线一区 | 国产成人av福利| 欧美午夜精品一区| 国产精品色一区二区三区| 国产精品久久777777| 久久精品国产秦先生| 欧美亚洲免费在线一区| 中文字幕永久在线不卡| 韩国三级电影一区二区| 欧美福利电影网| 亚洲在线一区二区三区| 91色视频在线| 国产精品欧美精品| 国产精品99久| 久久一日本道色综合| 青青草伊人久久| 欧美另类videos死尸| 亚洲最新在线观看| 色婷婷久久久综合中文字幕| 国产精品电影一区二区| 国产xxx精品视频大全| 亚洲国产精品一区二区久久| 丁香五精品蜜臀久久久久99网站 | 一本到不卡免费一区二区| 国产日韩精品一区二区浪潮av| 激情综合五月婷婷| 精品国产乱码91久久久久久网站| 日产欧产美韩系列久久99| 欧美久久久久中文字幕| 午夜精品一区二区三区电影天堂 |