0% found this document useful (0 votes)
17 views14 pages

Chap2 RecursionAndBB

The document outlines various algorithms and problems related to combinatorial optimization, including backtracking, branch and bound, and greedy algorithms. It discusses specific problems such as the bus routing problem and delivery truck routing problem, providing examples and methods for solving them. Additionally, it includes exercises to apply these concepts in practical scenarios.

Uploaded by

Du Đỗ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views14 pages

Chap2 RecursionAndBB

The document outlines various algorithms and problems related to combinatorial optimization, including backtracking, branch and bound, and greedy algorithms. It discusses specific problems such as the bus routing problem and delivery truck routing problem, providing examples and methods for solving them. Additionally, it includes exercises to apply these concepts in practical scenarios.

Uploaded by

Du Đỗ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI Contents

VIỆN CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG


HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY Chapter 1. Data structures and libraries
SCHOOL OF INFORMATION AND COMMUNICATION TECHNOLOGY
Chapter 2. Recursion, branch and bound
Chapter 3. Greedy algorithm
Chapter 4. Divide and conquer
Chapter 4. Dynamic programming
Applied Algorithms Chapter 5. Algorithms on graph and applications
Chapter 6. NP-complete
Nguyễn Khánh Phương

Computer Science department


School of Information and Communication technology
E-mail: phuongnk@[Link]

Contents Contents
1. General diagram of backtracking, branch and bound 1. General diagram of backtracking, branch and bound
2. Some exercises 2. Some exercises
2.1. The bus routing problem 2.1. The bus routing problem
2.2. Delivery truck route problem 2.2. Delivery truck route problem
1. General diagram of backtracking 1. General diagram of backtracking
• The backtracking algorithm allows us to solve combinatorial enumeration • The backtracking algorithm allows us to solve combinatorial enumeration problems
problems and combinatorial optimization problems: and combinatorial optimization problems:
– Each solution is represented by a sequence of decision variables X1, X2, . . ., Xn – Each solution is represented by a sequence of decision variables X1, X2, . . ., Xn
– We need to find for each variable Xi a value selected from a given discrete set Ai – We need to find for each variable Xi a value selected from a given discrete set Ai
such that: such that:
• The constraints of the problem are satisfied. • The constraints of the problem are satisfied.
• Optimize a given objective function. • Optimize a given objective function.
Example: • Backtracking algorithm:
• Combinatorial enumeration problem: – Traverse through all variables (e.g. in order from X1, X2, . . ., Xn), for each
– Enumerate all permutations of the set N = {1, 2, 3 …, n} variable Xk :
• Combinatorial optimization problem: • Traverse through all possible values that could be assigned to Xk, for each
– The Travelling salesman problem: there are n cities 1, 2, …, n. The traveler value v:
wants to start from a city then goes to each remaining city exactly once, then – Check if constraints are satisfied:
comes back to the starting city. Denote dij is the cost from city i to city j for i, j = » Assign Xk = v
1,…, n. Determine the journey with the smallest cost. » If k = n then record a solution to the problem
» Otherwise, consider the variable Xk+1

1. General diagram of backtracking 1. General diagram of branch and bound


Minimize optimization problem
(Denote fopt : optimal value)
Enumeration problem
try(k){//Try out the possible values assigned to Xk
try(k){ //Try out the possible values assigned to Xk
for v in Ak do {
for v in Ak do {
if check(v,k){
if check(v,k){
Xk = v;
Xk = v;
[Update a data structure D]
[Update a data structure D]
if k = n then updateBest();
if k = n then solution();
else {
else {
if g(X1, X2, …, Xk) < fopt then
try(k+1);
try(k+1);
}
}
[Recover the data structure D]
[Recover the data structure D]
}
}
}
}
} Calculate the lower
bound }
g(X1, X2, …, Xk) of
the objective
function for
solutions that are
being continued to
be built from here
1. General diagram of backtracking Contents
Minimize optimization problem 1. General diagram of backtracking, branch and bound
(Denote fopt : optimal value)

try(k){//Try out the possible values assigned to Xk 2. Some exercises


for v in Ak do {
if check(v,k){
2.1. The bus routing problem
Xk = v;
[Update a data structure D]
2.2. Delivery truck route problem
if k = n then updateBest();
else {
if g(X1, X2, …, Xk) < fopt then
try(k+1);
}
[Recover the data structure D]
}
}
}

Do not further build the


solution if
g(X1, X2, …, Xk) ≥ f*

2.1. The bus routing problem 2.1. The bus routing problem
• There are n passengers 1, 2,.., n and a bus. Passenger i has: the pick-up point is i and • Branch and bound:
the drop-off point is i + n (i = 1, 2, ... , n). – Modelling problem: x1, x2, . . ., x2n is the sequence of pick-up and drop-
• The bus has K seats to serve passengers, departs from point 0 to serve n passengers off points on the bus route (is a permutation of 1, 2, …, 2n).
and go back to point 0.
– Cmin: the smallest distance among the distances between 2 points
• Given distance matrix c2n+1 x c2n+1 where the travel distance from point i to point j is
c(i, j), with i, j = 0, 1, 2, . . , 2n. – Marker array: visited[v] = true means point v has appeared on the
Determine the route for the bus so that the total distance traveled is minimal, and the route of bus, and visited[v] = false, otherwise
number of passengers on the bus never exceeds K. – load: number of passengers is now on the bus
• Input • When the route reaches a pick-up point, the load increases by 1, and
– Line 1 consists of n and k (1 ≤ n ≤ 11, 1 ≤ k ≤ 10) when it reaches a drop-off point, the load decreases by 1
– Line i+1 (i = 1,…, 2n, 2n+1) contains ith line of matrix c2n+1×2n+1 – f: length of the partial route
• Output – fopt: shortest route length that has been found
– Minimum travel distance of taxi
Example:

11 12
2.1. The bus routing problem 2.1. The bus routing problem
Try (int k) { //determine value of x[k]
Assume we have partial route (0, x1, x2,…,xk) for (i = 1; i<=2*n; i++)
• The cost need to pay for this partial solution is: if (bus could go to point i) { bool UCV(int i)
x[k] = i; //return true if bus
f = c[0, x1] + c[x1, x2] + c[x2, x3] + c[xk-1, xk] visited[i] = 1; //could go to point i
• To develop it as the complete route: f = f + c[xk-1][i] ;
if (k == 2*n) updateBest( );
1 2 3 2n-k else {
x0  x1  . .  xk-1  xk  xk+1  xk+2  …..  x2n  x0 g = f + (2*n+k-1)cmin;
if (g < fopt) Try(k+1);
}
visited[i] = 0;
We still need to go through 2n-k+1 segments, each segment with the cost at f -= c[xk-1][i] ;
}//end if
least cmin, thus the lower bound of the partial solution (0, x1, ..., xk) can be }
calculated by the formula:
g(0, x1, ..., xk) = f + [(2*n)-k+1] cmin .

13 14

2.1. The bus routing problem 2.1. The bus routing problem
Try(int k) { //determine value of x[k]
• What does the bus do when it arrives at point i? (i = 1,…,2n):
for (i = 1; i<=2*n; i++)
• i ≤ n : Passenger i get on the bus (pick up passenger i) if (UCV(i)) {
if (i <=n) load++; else load--;
x[k] = i;
• i > n : Passenger (i-n) get off the bus
visited[i] = 1;
f = f + c[xk-1][i] ;
if (k == 2*n) updateBest( );
• When could the bus go to point i ? else {
• i ≤ n: visited[i] =0, Number of passengers on the bus < Number of seats on the bus g = f + (2*n+k-1)cmin;
if (g < fopt) Try(k+1);
}
• i > n : visited[i]=0 , visited[i-n] =1 visited[i] = 0;
f -= c[xk-1][i] ;
bool UCV(int i) //return true if bus could go to point i if (i <= n) load--; else load++;
{
}//end if
if (i <= n) //passenger i get on the bus at point i
}
return (!visited[i] && load < K);
else //passenger (i-n) get off the bus at point i
return (!visited[i] && visited[i-n]);
}
15 16
Contents 2.2. Delivery truck routing problem
Exercise 1: A fleet of K identical trucks needs to transport pepsi boxes from the warehouse (point 0) to
1. General diagram of backtracking, branch and bound customer points 1,2,...,n and back to the warehouse. The travel distance from point i to point j is c(i,j).
2. Some exercises • Each truck has a load capacity of Q (each truck trip can only transport a maximum of Q boxes),
• Each truck trip: starts from point 0 to load boxes (<=Q) onto the truck, then going to a number of
2.1. The bus routing problem customers to deliver boxes and returning to the warehouse when empty.
• Each customer point i has a required quantity of d[i] boxes, i = 1,…, n.
2.2. Delivery truck routing problem • It is necessary to develop a transportation plan so that:
– Each truck must delivery boxes to at least one customer (all K trucks must be used)
– The total amount of boxes on the vehicle must not exceed the vehicle's load Q.
– Each customer point can only be delivered by exactly one vehicle and only once.
Question: Calculate R as the number of all possible delivery plans that satisfy all the constraints of the
problem.
Note: the order of customers that the truck delivers to is important  the route 0->1->2->3->0 is
different from the route 0->3->2->1->0.
• Input
– Line 1: 3 positive integers n, K, Q (2 ≤ n ≤ 10, 1 ≤ K ≤ 5, 1 ≤ Q ≤ 20)
– Line 2: d1, d2,…,dn (1 ≤ di ≤ 10)
• Output
– R mod 109 + 7

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
List all possible solutions, it means: • Method 1: build trip for each vehicle, one by one
List all ways to partition the set N ={1,2,..,n} into K subsets: • Method 2: for each customer, assign it to all possible trucks
• has order (có thứ tự),
• not empty (khác rỗng),
• sum of d[i] in each subset ≤ Q (tổng d[i] trong mỗi tập con ≤ Q)
 Need to determine for each truck j (j=1,..,K): the sequence of customers that truck j
will deliver to
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Method 1: build the trip for each truck j = 1, …, K by adding each customer to the trip /*build trip for truck j (determine customer one by one that this truck j will serve):
one by one as long as the number of Pepsi boxes still remains ≤ Q currently on truck j, there are nBox pepsi boxes; and the number of customers
• nBox: number of pepsi boxes currently on truck j; initialize nBox = 0 already been served by trucks 1…j is nCus*/
void Try(int j, int nBox, int nCus) {
• nCus: number of customers that trucks 1…j have currently gone through
if (j > K) {// Completed the plan for all K trucks
(delivered); initialize: nCus = 0
if (nCus == n) R++;
When trips for all K trucks are built and all n customers have been delivered  we get a
return;
solution to the problem.
} Try(?,?,?);
//Method 1: Use another truck (Sử dụng thêm xe khác)
if (nBox > 0) Try(j+1,0,nCus);
//Method 2: only use truck j (go through each customer and check if it’s possible to add it to
//truck j)
for (int i = 1; i <= n; i++)
if (visited[i]==0 && nBox + d[i] <= Q ){
visited[i] = 1;
Try(j,nBox+d[i],nCus+1);
visited[i] = 0;
}
}

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
/*xây dựng hành trình cho xe j (xác định lần lượt từng khách hàng mà xe này sẽ int main() {
đi): khi mà trên xe j đã có sothung pepsi và tổng số khách hàng đã được phục cin >> n >> k >> Q;
vụ trên tất cả các xe từ 1 đến j là sokhach*/
for (int i = 1; i <= n; i++) cin >> d[i];
void Try(int j, int sothung, int sokhach) {
R=0;
if (j > K) { //đã xây dựng xong hành trình cho toàn bộ K xe
if (sokhach == n) R++;
Try(1,0,0);
return; …????..
} Try(?,?,?); }
//Cách 1: Sử dụng thêm xe khác
if (sothung > 0) Try(j+1,0,sokhach);
//Cách 2: chỉ sử dụng xe j (duyệt qua lần lượt từng khách: xét xem có cho vào xe j được ko)
for (int i = 1; i <= n; i++)
if (visited[i]==0 && sothung + d[i] <= Q ){
visited[i] = 1;
Try(j,sothung+d[i],sokhach+1);
visited[i] = 0;
}
}
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Method 2: Since the order of customers that the truck delivers to is important,
the route 0->1->2->3->0 is different from the route 0->3->2->1->0.
• For each truck j (j=1,..,K): need to determine which customers this truck will
serve.
• If truck j serves customer set {1, 2, 3} then it is clear that 3!=6 possible
plans can be constructed for this truck:
1) 01230 4) 0  2  3  1  0
2) 01320 5) 0  3  1- 2  0
3) 02130 6) 0  3  2  1  0
• So the remaining problem is: how to list all the ways to divide n customers
into K trucks. Or in other words, how to list all the ways to partition the set
of n elements {1, 2,..,n} into K subsets.
– Thus, for each partitioning: need nCus[j] array to store the number of
customers that truck j has served, j = 1,.,K. Then, the number of plans
built corresponding to this array (this partitioning method) will be:
(nCus[1] !) * (nCus[2] !) * … (nCus[K]!)

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem

Try(int i) { //determine which truck could serve customer i Try(int i) { //determine which truck could serve customer i
if (i > n) { //already found a partition that divides n customers into K trucks if (i > n) { //already found a partition that divides n customers into K trucks
Calculate the total number of plans could be built that corresponds to this
Calculate the total number of plans could be built that corresponds to this
partition, then save it to the temp variable;
partition, then save it to the temp variable; R = (R+temp)%mode;
R = (R+temp)%mode; }
}
Each truck must served at least 1 customer. Need to check: There is no truck j with nCus[j] = 0
else {//found the truck could serve customer i
for (int j=1;j<=K;j++) //try each truck j
if (nBox[j] + d[i] <= Q) { //could assign customer i to truck j
nCus[j]++; //increase the number of customer that truck j could serve by 1 if (*min_element(nCus+1, nCus+n+1) > 0) {
nBox[j] += d[i];//number of boxes on truck j temp = 1;
Try(i+1);//continue to find truck that could serve customer i+1 for (int j = 1; j<=K;j++) temp *= (nCus[j]!)
nCus[j]--; nBox[j] -=d[i]; R = (R+temp)%mode;
} }
=nCus[j] * (nCus[j]-1)*…*2*1
}
}
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem

Pre-calculated factorial array:: Example: 2 trucks; 3 customers (1, 2, 3):


int M = n-k+1; – (1) and (2, 3)  ? Is there how many solutions that corresponds to this partition
factorial[0] = 1; • nCus[1] ! * nCus[2] ! = 1! * 2! =2
– (1, 2) and (3)
for (int i = 1; i <= M; i++)
– (1, 3) and (2)
factorial[i] = factorial[i-1] * i;
– (1, 2, 3) and empty set  there exists empty truck
• nCus[j] == 0

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Exercise 2: A fleet of K identical trucks needs to transport pepsi boxes from the warehouse (point
0) to customer points 1,2,...,n and back to the warehouse. The travel distance from point i to point j
Try(int i) { //determine which truck could serve customer i is c(i,j).
if (i > n) { //already found a partition that divides n customers into K trucks
• Each truck has a load capacity of Q (each truck trip can only transport a maximum of Q boxes),
Calculate the total number of plans could be built that corresponds to this
partition, then save it to the temp variable; • Each truck trip: starts from point 0 to load boxes (≤ Q) onto the truck, then going to a number of
R = (R+temp)%mode; customers to deliver boxes and returning to the warehouse when empty.
}
• Each customer point i has a required quantity of d[i] boxes, i = 1,…, n.
Each truck must served at least 1 customer. Need to check: There is no truck j with nCus[j] = 0
• It is necessary to develop a transportation plan so that:
– The total amount of boxes on the vehicle must not exceed the vehicle's load Q.
– Each customer point can only be delivered by exactly one vehicle and only once.
if (*min_element(nCus+1, nCus+n+1) > 0) {
– Do not need to use all K trucks
temp = 1;
for (int j = 1; j<=K;j++) temp *= (nCus[j]!) The distance from point i to point j is cij (0 ≤ i,j ≤ n).
R = (R+temp)%mode; Question: Find the best plan for K trucks to serve all customers so that the total distance traveled by
}
factorial(nCus[j]) minimize.
Note: the order of customers that the truck delivers to is important  the route 0->1->2->3->0 is
different from the route 0->3->2->1->0.
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
• Input • Example n = 3, K = 2, Q = 10, d[1] = 3, d[2] = 2, d[3] = 1
– Line 1: 3 positive integers n, K, Q (2 ≤ n ≤ 10, 1 ≤ K ≤ 5, 1 ≤ Q ≤ 50)  There are 6 possible shipping plans if all trucks must be used:
– Line 2: d1, d2,…,dn (1 ≤ di ≤ 10)
Route[1] = 0 – 1 – 0 Route[1] = 0 – 1 – 2 – 0
– Line i+3 (i=0,…,n): ith row of distance matrix c (1≤c[i,j]≤30) Route[2] = 0 – 2 – 3 – 0 Route[2] = 0 – 3 – 0
Route[1] = 0 – 1 – 3 – 0 Route[1] = 0 – 2 – 0
• Output Route[2] = 0 – 2 – 0 Route[2] = 0 – 3 – 1 – 0
– The minimum distance Route[1] = 0 – 1 – 0 Route[1] = 0 – 2 – 1 – 0
Route[2] = 0 – 3 – 2 – 0 Route[2] = 0 – 3 – 0
 There are 6 additional possible shipping plans if don’t need to use all
2 trucks:
Route[1] = 0 – 1 – 2 – 3 – 0 Route[1] = 0 – 1 – 3 – 2 – 0
Route[1] = 0 – 2 – 1 – 3 – 0 Route[1] = 0 – 2 – 3 – 1 – 0
Route[1] = 0 – 3 – 1 – 2 – 0 Route[1] = 0 – 3 – 2 – 1 – 0

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
• Example n = 3, K = 2, Q = 4, d[1] = 3, d[2] = 2, d[3] = 1 • Design data structure
 There are 4 possible shipping plans: – y[k] the first delivery point of kth truck (y[k] {0, 1, 2,..., n}, k = 1, 2,…, K)
• y[k] = 0 ~ kth truck is not used
– x[i] is the next point of deliver point i on the trip (x[i] {0,1,2,…,n}, i = 1, .., n)
Route[1] = 0 – 1 – 0 Route[1] = 0 – 1 – 2 – 0 – As fleet of trucks is homogeneous, so we assume y[k] ≤ y[k+1], k = 1, 2,…, K-1
Route[2] = 0 – 2 – 3 – 0 Route[2] = 0 – 3 – 0
• If y[k] > 0 then y[k+1] > y[k]
Route[1] = 0 – 1 – 3 – 0 Route[1] = 0 – 2 – 0
– Variables associated with the partial solution:
Route[2] = 0 – 2 – 0 Route[2] = 0 – 3 – 1 – 0
• visited[v] = true if v is already visited by a truck
Route[1] = 0 – 1 – 0 Route[1] = 0 – 2 – 1 – 0
Route[2] = 0 – 3 – 2 – 0 Route[2] = 0 – 3 – 0 • load[k]: number of boxes already on kth truck
• f: total length of existing routes on current partial solution
Route[1] = 0 – 1 – 2 – 3 – 0 Route[1] = 0 – 1 – 3 – 2 – 0
• f*: distance length of the current best solution
Route[1] = 0 – 2 – 1 – 3 – 0 Route[1] = 0 – 2 – 3 – 1 – 0
Route[1] = 0 – 3 – 1 – 2 – 0 Route[1] = 0 – 3 – 2 – 1 – 0
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Strategy to traverse: determine first customers for K trucks, then build route for each truck
• Determine the first customer for each truck  traverse values for (y[1],.., y[K])
Example: n = 6, K = 2
• For each complete values of (y[1],. . ., y[K]), start traversing values for the x[1,...,n] derived from
x[y[1]]
• Each time: try to assign x[v] = u for the kth truck: 0
– If u > 0 (kth truck does not go back to the depot yet): try continuing to browse the other value
for x[u] still on the kth truck
– If u = 0 (kth truck already goes back to depot) then (y[1], y[2]) 1
• If k = K (all trips for K vehicles are complete) and all delivery points are visited, then
obtain a solution to the problem
• otherwise, try continuing to assign the values for the trip of (k+1)th truck, derived from
x[y[k+1]]
• Variable nbR: the number of vehicles that has been used for delivery
y[1]
• Variable segments
– Store the number of segments (segment is a connection
between 2 consecutive delivery points on the trip) y[2]
– When segments = N+nbR then obtain a solution
to the problem

y[3]

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2 Example: n = 6, K = 2

0 0

(y[1], y[2]) 1 2 (y[1], y[2]) 1 2

5
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2 Example: n = 6, K = 2

0 0

(y[1], y[2]) 1 2 (y[1], y[2]) 1 2

5 5

4 4

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2 Example: n = 6, K = 2

0 0

(y[1], y[2]) 1 2 (y[1], y[2]) 1 2

5 3 5 3

4 4 6

0 0
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2 Example: n = 6, K = 2

0 0

(y[1], y[2]) 1 2 (y[1], y[2]) 1 2

5 3 5 6

4 6 4

0 0 0

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2 Example: n = 6, K = 2

0 0

(y[1], y[2]) 1 2 (y[1], y[2]) 1 2

5 6 5 6

4 3 4 3

0 0 0
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2 Example: n = 6, K = 2

0 0

(y[1], y[2]) 1 2 1 (y[1], y[2]) 1 2 1 3

5 3

4 6

0 0 0 0

2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Example: n = 6, K = 2
checkY(v, k){ TRY_Y(k){ //assign value to y[k]: determine the first delivery point of kth truck
if v = 0 then return true; s = 0;
0 if visited[v] = true then if y[k-1] > 0 then s = y[k-1] + 1;
return false; for v = s to n do { // for each customer v
if load[k] + d[v] > Q then if checkY(v,k) then {//can assign customer v as first customer of kth truck
return false; y[k] = v;

(y[1], y[2]) 1 2 1 3 . . . return true; if v > 0 then segments = segments + 1; //kth truck is used
} visited[v] = true; f = f + c[0,v]; load[k] = load[k] + d[v];
if k < K then TRY_Y(k+1);//not finish determining first point for all trucks
solve(){
else { nbR = segments; TRY_X(y[1],1);}
f = 0; fopt = +; y[0] = 0;
4 for v = 1 to n do
if v > 0 then segments = segments – 1;
load[k] = load[k] – d[v]; visited[v] = false; f = f – c[0,v];
visited[v] = false;
}
. TRY_Y(1);
}
output(fopt);
. }
}

.
0 0
2.2. Delivery truck routing problem 2.2. Delivery truck routing problem
Exercise 3: A fleet of K identical trucks needs to transport pepsi boxes from the warehouse (point
0) to customer points 1,2,...,n and back to the warehouse. The travel distance from point i to point j
TRY_X(s, k){/*assign value to x[s] for v = 0 to n do { is c(i,j).
of kth truck */ if checkX(v,k) then {//can assign customer v to vehicle k
• Each truck has a load capacity of Q (each truck trip can only transport a maximum of Q boxes),
if (s = 0) then {//kth truck done x[s] = v; visited[v] = true; f = f + c[s,v];
if k < K then load[k] = load[k] + d[v]; segments = segments + 1;
• Each truck trip: starts from point 0 to load boxes (≤ Q) onto the truck, then going to a number of
TRY_X(y[k+1],k+1); if v > 0 then {if f + (n + nbR – segments)*Cmin < fopt then TRY_X(v,k);} customers to deliver boxes and returning to the warehouse when empty.
return; else { • Each customer point i has a required quantity of d[i] boxes, i = 1,…, n.
} if k = K then {
[try al possible values for x[s]]
• It is necessary to develop a transportation plan so that:
if segments = n + nbR then updateBest();
} } else{
– The total amount of boxes on the vehicle must not exceed the vehicle's load Q.
if f + (n + nbR – segments)*Cmin < fopt then TRY_X(y[k+1],k+1); – Each customer point can only be delivered by exactly one vehicle and only once.
checkX(v, k){
}
if v > 0 and visited[v]
– Must use all K trucks
}
then return false; visited[v] = false; f = f – c[s,v];
The distance from point i to point j is cij (0 ≤ i,j ≤ n).
if load[k] + d[v] > Q
load[k] = load[k] – d[v]; segments = segments – 1; Question: Find the best plan for K trucks to serve all customers so that the total distance traveled by
then return false;
} minimize.
return true;
}
}
Note: the order of customers that the truck delivers to is important  the route 0->1->2->3->0 is
different from the route 0->3->2->1->0.

You might also like