如何改善我的模拟退火输出?

时间:2019-02-23 19:53:25

标签: simulated-annealing

我正在通过混合整数编程模型来解决车辆路径问题,该模型使用模拟退火来求解我的代码的启发式部分,并使用CPLEX来获取精确的解决方案。与我的CPLEX输出相比,长时间运行的SA在1小时运行时间内效果不佳。有什么技巧可以改善我的SA代码吗?

const int NUM_ITERATIONS = 100; //Number of iterations for simulated 
annealing procedure
const double TEMP_FACTOR = .999; //Required parameter for simulated 
annealing
const double START_TEMPERATURE = 500; //Required parameter for simulated 
annealing
const int NUM_RUNS = 25; //Number of times to run program

我的SA代码:

//Evaluating objective value for the neighboring feasible solution just created.
    nextTourDist = 0;
    for (i = 0; i<NumberOfCustomers + DepotEndPoints - 1; i++)
        nextTourDist += distBetweenCustomers(CustomerCoordinates[(deliverySequence[i])][0], CustomerCoordinates[(deliverySequence[i])][1], CustomerCoordinates[(deliverySequence[i + 1])][0], CustomerCoordinates[(deliverySequence[i + 1])][1]);
    nextTourDist += distBetweenCustomers(CustomerCoordinates[(deliverySequence[NumberOfCustomers - 0])][0], CustomerCoordinates[(deliverySequence[NumberOfCustomers - 0])][1], CustomerCoordinates[(deliverySequence[0])][0], CustomerCoordinates[(deliverySequence[0])][1]);
    nextTourDist += 1000000 * IllegalTurns;

    double objValDifference = nextTourDist - currentTourDist;

    if (objValDifference >= 0)
    {
        acceptanceProbability = exp((-1.00*objValDifference) / temperature);

        double randNum = (static_cast<double>(rand())) / (RAND_MAX + 1);

        if (randNum < acceptanceProbability)
        {
            accept = true;
            steps++;
        }
        else
        {
            accept = false;
        }
    }
    else
    {
        accept = true;
        steps++;
    }

    if (accept == true)
    {
       //Storing next into current.
        for (i = 0; i<NumberOfCustomers + DepotEndPoints; i++)
            currentTour[i] = nextTour[i];
        currentTourDist = nextTourDist;
    }

    iterations++;
    //Compare the current tour (after "iterations" iterations and "steps" steps are taken)
    //to the best tour.  If current tour better, set best tour = current tour.

    if (currentTourDist < bestTourDist)
    {
        bestIteration = iterations;
        bestStep = steps;
        for (i = 0; i<NumberOfCustomers + DepotEndPoints; i++)
            bestTour[i] = currentTour[i];
        bestTourDist = currentTourDist;
    }

    temperature *= TEMP_FACTOR;
}

0 个答案:

没有答案