简单的介绍:
LKH-3 是 Lin-Kernighan 旅行商启发式算法的一个实现。目标是构建能够解决以下问题类型的 LKH-3 版本:
CVRPMTW:具有多个时间窗的容量车辆路径问题
检查:评论说“如何增加等待时间”
我需要做什么:
输出等待时间(最早)以及我们在哪个节点面临等待时间
示例以清晰理解:
|--------|____________________|--------|
等待 | 时间窗口节点 N | 惩罚
GainType Penalty_CVRPMTW()
{
static Node *StartRoute = 0;
Node *N, *NextN, *CurrentRoute;
GainType CostSum, DemandSum, P = 0;
int Forward = SUCC(Depot)->Id != Depot->Id + DimensionSaved;
int j;
int RouteCounter = 0;
if (!StartRoute)
StartRoute = Depot;
if (StartRoute->Id > DimensionSaved)
StartRoute -= DimensionSaved;
N = StartRoute;
do {
CurrentRoute = N;
CostSum = DemandSum = 0;
do {
if (N->Id <= Dim && N != Depot) {
if ((DemandSum += N->Demand) > Capacity)
P += DemandSum - Capacity;
if (MultipleTimeWindowPenaltyMode == PENALTY_ON_EARLIEST || MultipleTimeWindowPenaltyMode == NO) {
// Loop over the earliest values of the node's time windows and find the appropriate time window
if (CostSum > N->Latest)
P += CostSum - N->Latest;
else {
for (j = 0; j < N->NumberTimeWindows; j++){
if (CostSum < N->EarliestList[j]){
if (MultipleTimeWindowPenaltyMode == NO) {
*CostSum = N->EarliestList[j]*; //how can i add the waiting time in this line?
}
else if (MultipleTimeWindowPenaltyMode == PENALTY_ON_EARLIEST) {
// CostSum = N->EarliestList[j]; /* Enable this to also add the waiting time to the cost */
P += N->EarliestList[j] - CostSum;
}
break;
} else if (CostSum >= N->EarliestList[j] && CostSum <= N->LatestList[j]){
break;
}
}
}
}