本文整理汇总了C#中IRoute.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# IRoute.IsValid方法的具体用法?C# IRoute.IsValid怎么用?C# IRoute.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRoute
的用法示例。
在下文中一共展示了IRoute.IsValid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImproveIntraRoute
/// <summary>
/// Apply some improvements within one route.
/// </summary>
/// <param name="problem"></param>
/// <param name="route"></param>
/// <param name="currentWeight"></param>
private double ImproveIntraRoute(IProblemWeights problem, IRoute route, double currentWeight)
{
bool improvement = true;
double newWeight = currentWeight;
while (improvement)
{ // keep trying while there are still improvements.
improvement = false;
// loop over all improvement operations.
foreach (IImprovement improvementOperation in _intra_improvements)
{ // try the current improvement operations.
double difference;
if (improvementOperation.Improve(problem, route, out difference))
{ // there was an improvement.
OsmSharp.Logging.Log.TraceEvent("OsmSharp.Routing.VRP.NoDepot.MaxTime.VNS.GuidedVNS", TraceEventType.Information,
"Intra-improvement found {0} {1}->{2}",
improvementOperation.Name, newWeight, newWeight + difference);
// check if the route is valid.
if (!route.IsValid())
{
throw new Exception();
}
// update the weight.
newWeight = newWeight + difference;
improvement = true;
break;
}
}
}
return newWeight;
}
示例2: ImproveIntraRoute
/// <summary>
/// Apply some improvements within one route.
/// </summary>
/// <param name="problem"></param>
/// <param name="route"></param>
/// <param name="current_weight"></param>
private double ImproveIntraRoute(IProblemWeights problem, IRoute route, double current_weight)
{
bool improvement = true;
double new_weight = current_weight;
while (improvement)
{ // keep trying while there are still improvements.
improvement = false;
// loop over all improvement operations.
foreach (IImprovement improvement_operation in _intra_improvements)
{ // try the current improvement operations.
double difference;
if (improvement_operation.Improve(problem, route, out difference))
{ // there was an improvement.
OsmSharp.Tools.Output.OutputStreamHost.WriteLine("Intra-improvement found {0} {1}->{2}",
improvement_operation.Name, new_weight, new_weight + difference);
// check if the route is valid.
if (!route.IsValid())
{
throw new Exception();
}
// update the weight.
new_weight = new_weight + difference;
improvement = true;
break;
}
}
}
return new_weight;
}
示例3: 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="v_3"></param>
/// <param name="weights_3"></param>
/// <param name="v_4"></param>
/// <param name="weight_1_2_plus_3_4"></param>
/// <param name="weight_1_4"></param>
/// <returns></returns>
public bool Try3OptMoves(IProblemWeights problem, double[][] weights, IRoute route,
int v1, int v_2, int v_3, double[] weights_3, int v_4, double weight_1_2_plus_3_4, double weight_1_4)
{
//IEnumerable<int> between_v_4_v_1 = route.Between(v_4, v_1);
//foreach (int v_5 in between_v_4_v_1)
//{
// if (v_5 != v_1)
// {
// if (this.Try3OptMove(problem, weights, route, v_1, v_2, v_3, weights_3, v_4, weight_1_2_plus_3_4, weight_1_4, v_5))
// {
// return true;
// }
// }
//}
//return false;
IEnumerator<int> between_v_4_v_1_enumerator = route.Between(v_4, v1).GetEnumerator();
if (between_v_4_v_1_enumerator.MoveNext())
{
int v_5 = between_v_4_v_1_enumerator.Current;
if (v_5 != v1)
{
while (between_v_4_v_1_enumerator.MoveNext())
{
int v_6 = between_v_4_v_1_enumerator.Current;
//Console.WriteLine(v_6);
//if (this.Try3OptMove(problem, weights,
// route, v_1, v_2, v_3, weights_3, v_4,
// weight_1_2_plus_3_4, weight_1_4, v_5, v_6))
//{
// calculate the total weight of the 'new' arcs.
double weight_new = weight_1_4 +
weights_3[v_6] +
weights[v_5][v_2];
// calculate the total weights.
double weight = weight_1_2_plus_3_4 + weights[v_5][v_6];
if (weight - weight_new > _epsilon)
{ // actually do replace the vertices.
int count_before = route.Count;
//string route_string = route.ToString();
route.ReplaceEdgeFrom(v1, v_4);
route.ReplaceEdgeFrom(v_3, v_6);
route.ReplaceEdgeFrom(v_5, v_2);
int count_after = route.Count;
if (count_before != count_after)
{
throw new Exception();
}
// set bits.
//this.Set(problem, v_1, false);
this.Set(problem, v_3, false);
this.Set(problem, v_5, false);
if (!route.IsValid())
{
throw new Exception();
}
return true; // move succeeded.
}
//}
v_5 = v_6;
}
}
}
return false;
}
示例4: 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;
}
示例5: Improve
/// <summary>
/// Improves an existing solution.
/// </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)
{
if (!route.IsValid())
{
throw new Exception();
}
_dont_look_bits = new bool[problem.Size];
double[][] weights = problem.WeightMatrix;
// loop over all customers.
bool any_improvement = false;
bool improvement = true;
difference = -1;
while (improvement)
{
improvement = false;
foreach (int v_1 in route)
{
if (!this.Check(problem, v_1))
{
if (this.Try3OptMoves(problem, weights, route, v_1))
{
any_improvement = true;
improvement = true;
break;
}
this.Set(problem, v_1, true);
}
}
}
return any_improvement;
}