⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ant.cpp

📁 vrpsd -tabu搜索求解!!!!!!!!!!!!!!!!!!!!!!!
💻 CPP
字号:
#include "Ant.h"Ant::Ant() {  currentSolution = NULL;  fitness = INT_MAX;}Ant::Ant( Random* rnd, Control_acs& control, Problem* problem) {  // no customer visited yet  //  for (int i=0; i < problem->numberOfCustomers; i++) {    customer_served.push_back(false);  }  // initialize all tauij and piij values  //  tauij = new double[problem->numberOfCustomers];  piij = new double[problem->numberOfCustomers];  for (int i=0; i < problem->numberOfCustomers; i++) {    tauij[i] = 0.0;    piij[i] = 0.0;  }  roulette = new double[problem->numberOfCustomers];  // build a starting solution  // using the randomized farthest insertion heuristic  //  currentSolution = new Solution( rnd, control, problem);  randomizedFarthestInsertion(rnd, *currentSolution);  (*currentSolution).computeExpectedCost();}int Ant::solutionStep(int step, int source, Random* rnd, Control_acs& control, Problem* problem, double** pheromoneMatrix) {  double divisor = 0.0;  double pij = 0.0;  double q = rnd->next();  customer_served[source] = true;  // Calculate Tauij for fixed source i and all possible destinations j still to be served  //  double alfa = control.getALPHA();  for (int j=0; j < problem->numberOfCustomers; j++) {    if (! customer_served[j]) {      if (alfa = 1.0) {	tauij[j] = pheromoneMatrix[source][j];      }      else {	tauij[j] = pow (pheromoneMatrix[source][j],alfa);      }      divisor += tauij[j];    }  }  for (int j=0; j < problem->numberOfCustomers; j++) {    if (! customer_served[j]) {      roulette[j] = ( tauij[j] / divisor);    }  }    for (int i=0; i < problem->numberOfCustomers; i++) {    if (! customer_served[i]) {      pij += roulette[i];    }    if (q < pij) {      // customer i is the next one      return (i);    }  }}Ant::~Ant() {  delete currentSolution;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -