本文整理汇总了C#中IRoute.GetNeigbours方法的典型用法代码示例。如果您正苦于以下问题:C# IRoute.GetNeigbours方法的具体用法?C# IRoute.GetNeigbours怎么用?C# IRoute.GetNeigbours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRoute
的用法示例。
在下文中一共展示了IRoute.GetNeigbours方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Try3OptMoves
/// <summary>
/// Tries all 3Opt Moves for the neighbourhood of v_1 containing v_3.
/// </summary>
/// <param name="problem"></param>
/// <param name="weights"></param>
/// <param name="route"></param>
/// <param name="v1"></param>
/// <param name="v_2"></param>
/// <param name="weight_1_2"></param>
/// <param name="v_3"></param>
/// <returns></returns>
public bool Try3OptMoves(IProblemWeights problem, double[][] weights, IRoute route,
int v1, int v_2, double weight_1_2,
int v_3)
{
// get v_4.
int v_4 = route.GetNeigbours(v_3)[0];
double weight_1_2_plus_3_4 = weight_1_2 + weights[v_3][v_4];
double weight_1_4 = weights[v1][v_4];
double[] weights_3 = weights[v_3];
return this.Try3OptMoves(problem, weights, route, v1, v_2, v_3, weights_3, v_4, weight_1_2_plus_3_4, weight_1_4);
}
示例2: Improve
/// <summary>
/// Tries to improve the existing route using CI and return true if succesful.
/// </summary>
/// <param name="problem"></param>
/// <param name="route"></param>
/// <param name="difference"></param>
/// <returns></returns>
public bool Improve(IProblemWeights problem, IRoute route, out double difference)
{
bool improvement = false;
difference = 0;
if (route.Count > 3)
{
// loop over all customers and try cheapest insertion.
for (int customer = 0; customer < problem.Size; customer++)
{
//string route_string = route.ToString();
//IRoute previous = route.Clone() as IRoute;
if (route.Contains(customer))
{
// remove customer and keep position.
int next = route.GetNeigbours(customer)[0];
route.Remove(customer);
// insert again.
ArbitraryInsertionSolver.InsertOne(problem, route, customer, out difference);
if (!route.IsValid())
{
throw new Exception();
}
if (route.GetNeigbours(customer)[0] != next
&& difference < 0)
{ // another customer was found as the best, improvement is succesful.
improvement = true;
break;
}
}
}
}
return improvement;
}