MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / evalRelocateMove

Method evalRelocateMove

pyvrp/cpp/search/Exchange.h:86–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85template <size_t N, size_t M>
86Cost Exchange<N, M>::evalRelocateMove(Route::Node *U,
87 Route::Node *V,
88 CostEvaluator const &costEvaluator) const
89{
90 assert(U->idx() > 0);
91
92 Cost deltaCost = 0;
93
94 if (U->route() != V->route())
95 {
96 auto const *uRoute = U->route();
97 auto const *vRoute = V->route();
98
99 // We're going to incur V's fixed cost if V is currently empty.
100 if (V->isStartDepot() && vRoute->empty())
101 deltaCost += vRoute->fixedVehicleCost();
102
103 // We lose U's fixed cost if we're moving all U's clients.
104 if (uRoute->numClients() == N)
105 deltaCost -= uRoute->fixedVehicleCost();
106
107 auto const uProposal = Route::Proposal(uRoute->before(U->idx() - 1),
108 uRoute->after(U->idx() + N));
109
110 auto const vProposal
111 = Route::Proposal(vRoute->before(V->idx()),
112 uRoute->between(U->idx(), U->idx() + N - 1),
113 vRoute->after(V->idx() + 1));
114
115 costEvaluator.deltaCost(deltaCost, uProposal, vProposal);
116 }
117 else // within same route
118 {
119 auto *route = U->route();
120
121 if (U->idx() < V->idx())
122 costEvaluator.deltaCost(
123 deltaCost,
124 Route::Proposal(route->before(U->idx() - 1),
125 route->between(U->idx() + N, V->idx()),
126 route->between(U->idx(), U->idx() + N - 1),
127 route->after(V->idx() + 1)));
128 else
129 costEvaluator.deltaCost(
130 deltaCost,
131 Route::Proposal(route->before(V->idx()),
132 route->between(U->idx(), U->idx() + N - 1),
133 route->between(V->idx() + 1, U->idx() - 1),
134 route->after(U->idx() + N)));
135 }
136
137 return deltaCost;
138}
139
140template <size_t N, size_t M>
141Cost Exchange<N, M>::evalSwapMove(Route::Node *U,

Callers

nothing calls this directly

Calls 11

ProposalClass · 0.85
idxMethod · 0.80
isStartDepotMethod · 0.80
beforeMethod · 0.80
afterMethod · 0.80
betweenMethod · 0.80
deltaCostMethod · 0.80
routeMethod · 0.45
emptyMethod · 0.45
fixedVehicleCostMethod · 0.45
numClientsMethod · 0.45

Tested by

no test coverage detected