本文整理汇总了C#中IVRPProblemInstance.GetInsertionDistance方法的典型用法代码示例。如果您正苦于以下问题:C# IVRPProblemInstance.GetInsertionDistance方法的具体用法?C# IVRPProblemInstance.GetInsertionDistance怎么用?C# IVRPProblemInstance.GetInsertionDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVRPProblemInstance
的用法示例。
在下文中一共展示了IVRPProblemInstance.GetInsertionDistance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTourInsertionCosts
protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
out bool feasible) {
StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
double costs = 0;
feasible = true;
double startDistance, endDistance;
costs += instance.GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
return costs;
}
示例2: GetTourInsertionCosts
protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
out bool feasible) {
CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
double costs = 0;
feasible = tourInsertionInfo.Penalty < double.Epsilon;
ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
double overloadPenalty = cvrp.OverloadPenalty.Value;
ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
DoubleArray dueTime = vrptw.DueTime;
DoubleArray readyTime = vrptw.ReadyTime;
DoubleArray serviceTimes = vrptw.ServiceTime;
double tardinessPenalty = vrptw.TardinessPenalty.Value;
IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
int depots = mdp.Depots.Value;
double startDistance, endDistance;
costs += instance.GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
double demand = instance.GetDemand(customer);
if (demand > insertionInfo.SpareCapacity) {
feasible = false;
if (insertionInfo.SpareCapacity >= 0)
costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
else
costs += demand * overloadPenalty;
}
double time = 0;
double tardiness = 0;
if (index > 0)
time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
else
time = insertionInfo.TourStartTime;
time += startDistance;
int customerIndex = customer + depots - 1;
if (time > dueTime[customerIndex]) {
tardiness += time - dueTime[customerIndex];
}
if (time < readyTime[customerIndex])
time += readyTime[customerIndex] - time;
time += serviceTimes[customer - 1];
time += endDistance;
double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
if (additionalTime < 0) {
//arrive earlier than before
//wait probably
if (nextStop.WaitingTime < 0) {
double wait = nextStop.WaitingTime - additionalTime;
if (wait > 0)
additionalTime += wait;
} else {
additionalTime = 0;
}
//check due date, decrease tardiness
if (nextStop.SpareTime < 0) {
costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
}
} else {
//arrive later than before, probably don't have to wait
if (nextStop.WaitingTime > 0) {
additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime);
}
//check due date
if (nextStop.SpareTime > 0) {
double spare = nextStop.SpareTime - additionalTime;
if (spare < 0)
tardiness += -spare;
} else {
tardiness += additionalTime;
}
}
}
costs += additionalTime * vrptw.TimeFactor.Value;
if (tardiness > 0) {
feasible = false;
}
costs += tardiness * tardinessPenalty;
return costs;
}
示例3: GetTourInsertionCosts
protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
out bool feasible) {
CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo;
double costs = 0;
feasible = tourInsertionInfo.Penalty < double.Epsilon;
IHeterogenousCapacitatedProblemInstance cvrp = instance as IHeterogenousCapacitatedProblemInstance;
double overloadPenalty = cvrp.OverloadPenalty.Value;
double startDistance, endDistance;
costs += instance.GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance);
double demand = instance.GetDemand(customer);
if (demand > insertionInfo.SpareCapacity) {
feasible = false;
if (insertionInfo.SpareCapacity >= 0)
costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
else
costs += demand * overloadPenalty;
}
return costs;
}