Skip to content

Off-by-one error in vrptw::MixedExchange::is_valid #821

@jcoupey

Description

@jcoupey

When applying a vrptw::MixedExchange, we replace two jobs in target route (note the t_rank and t_rank + 2 arguments) by a single job from source route:

_tw_t_route.replace(_input,
s_job_ranks.begin(),
s_job_ranks.end(),
t_rank,
t_rank + 2);

The problem is that the matching validity check applies to replacing a single job in target route (note the t_rank and t_rank + 1 arguments):

valid =
valid && _tw_t_route.is_valid_addition_for_tw(_input,
s_route.begin() + s_rank,
s_route.begin() + s_rank + 1,
t_rank,
t_rank + 1);

This is bad since it means that we could theoretically apply an invalid operator, but then this would show up in the replace asserts. Now I've traced the introduction of this operator back to October 2018 with this problem already present. I guess the reason why this went unnoticed for so long are:

  • the capacity check in cvrp::MixedExchange::is_valid are OK;
  • the check for replacing a single job rather than two is actually more demanding.

That last point means that the mismatch always resulted in not applying some valid moves rather than apply invalid ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions