I need MATLAB code for heterogenous fleet Vehicle Routing Problem. Please help

4 views (last 30 days)
2 types of vehicles will distribute goods to 13 customers from a single depot. There are 2 vehicles (1 of each type) available.
I need to use the vehicles in such a way that 1 vehicle will reach a customer for once and fulfill it’s full demand. If the situation is like that there might be space in the vehicle in which that can meet a portion of a customer’s demand, I won’t choose that option, rather I would take another vehicle and that’ll fulfill the whole demand. The 2 vehicles have to start from the depot and return to the same depot after distribution.
The objective is to minimize the total cost. The cost section has 2 parts, one is for carbon emission cost and other is fuel consumption cost.
Latitude of the depot = 24.84773520196375
longitude of the depot = 89.36247177231718
Latitudes & longitudes of the routes (depot and 13 customers) are:
latitudes = [24.84773520196375, 24.87335674, 24.83320423, 25.53737433, 25.33029507, 25.38906214, 24.92971916, 25.10335573, 24.82309822, 25.04680312, 24.55426666, 24.45587069, 24.07761762, 24.31666401];
longitudes = [89.36247177231718, 89.17118594, 89.07546406, 89.44736919, 89.54767327, 88.99127121, 91.68730257, 89.02807458, 88.93028983, 88.75279426, 89.50367434, 89.65933574, 89.61773818, 89.56760534];
The parameters are:
Transportation cost from customer point i to customer point j
= Fuel consumption cost
= Carbon emission cost
Cp= Cost per unit fuel = 109 Tk per litre
Ce= Environmental cost of unit carbon emission = 374.42 Tk per Kg
xij = route selection variable = 1 if m type vehicle serves point i followed by j
= 0; if m type vehicle does not serve point i followed by j
dij = Distance travelled from customer point i to customer point j
epsilon_m = Fuel consumption per unit distance = [ 0.0675, 0.07479 ]
E = Carbon emission coefficient for unit fuel consumption = 2.6 Kg per litre
Demand (no. of cartons) of customer i = [48 36 15 35 14 28 18 29 17 24 57 30 8]
[note that, demand of depot is 0]
Load capacity of vehicle m = [116, 231]
h = type of vehicle = 2
n = number of customer = 13
[i=1 is depot]
A png file containing Cost functions, Objective Function and constraint functions are attached here.
Constraint 2,3 indicate that each customer point only can be served by 1 vehicle,
Constraint 4 indicates that the vehicles won’t be overloaded
Constraint 5 indicates that all vehicles start from the depot (i=1) & return to the depot after the completion of the distribution
  2 Comments
Steven Lord
Steven Lord on 12 May 2023
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Humayra Adiba
Humayra Adiba on 13 May 2023
I have already written the code. I have also installed CVX solver. But an error is showing that "SeDuMi does not support binary variables. Please select a different solver." Could you please tell me how to solve binary variables with MATLAB built-in solvers? Thanks in advance.
The code is:
% Parameters
g = [0, 48, 36, 15, 35, 14, 28, 18, 29, 17, 24, 57, 30, 8];
h = 2;
b = [116 231];
n = length(g);
Cp = 109; % Tk per litre
Ce = 374.42; % Tk per Kg
epsilon = [0.0675 0.07479]; % L/Km
E = 2.6; % Kg per litre
% distances between each point
distances = zeros(n,n);
distances = [0 19.50815442 29.00620008 77.15867599 56.80704345 70.85085821 234.6750531 44.09093748 43.69802305 65.33176759 35.61366498 52.90278382 89.44572393 62.58939896;
19.50815442 0 10.64009699 78.89056466 63.39328642 60.13608486 253.8428177 29.36168037 24.94081297 46.37815297 48.85535436 67.73645361 99.35483655 73.74425004;
29.00620008 10.64009699 0 86.78329873 72.91614085 62.38717068 263.6805669 30.41693163 14.69362728 40.28078205 53.23056828 72.40560757 100.3572904 75.99775107;
77.15867599 78.89056466 86.78329873 0 25.13277089 48.66857223 235.2119931 64.07200893 94.95007095 88.6099902 109.4636361 122.1401947 163.2257997 136.2771608;
56.80704345 63.39328642 72.91614085 25.13277089 0 56.2877433 219.950659 58.04308714 83.94574689 85.9696202 86.40437437 97.8816683 139.4710732 112.7285796;
70.85085821 60.13608486 62.38717068 48.66857223 56.2877433 0 276.1037268 31.98400676 63.23114691 44.98772141 106.2268961 123.7160745 158.9590374 132.6677688;
234.6750531 253.8428177 263.6805669 235.2119931 219.950659 276.1037268 0 268.6427292 278.3695889 296.0392463 224.433138 211.5440557 229.8328972 224.8457569;
44.09093748 29.36168037 30.41693163 64.07200893 58.04308714 31.98400676 268.6427292 0 32.6850663 28.42909328 77.66215158 96.15106353 128.6991433 103.0641737;
43.69802305 24.94081297 14.69362728 94.95007095 83.94574689 63.23114691 278.3695889 32.6850663 0 30.64402763 65.18724693 84.24277853 108.2284206 85.58534207;
65.33176759 46.37815297 40.28078205 88.6099902 85.9696202 44.98772141 278.3695889 28.42909328 30.64402763 0 93.50987654 112.6831433 102.4241872 115.6234057;
35.61366498 48.85535436 53.23056828 109.4636361 86.40437437 106.2268961 296.0392463 77.66215158 65.18724693 93.50987654 0 19.17707448 54.24657786 27.20137515;
52.90278382 67.73645361 72.40560757 122.1401947 97.8816683 123.7160745 224.433138 96.15106353 84.24277853 112.6831433 19.17707448 0 42.27066922 18.05283258;
89.44572393 99.35483655 100.3572904 163.2257997 139.4710732 158.9590374 229.8328972 128.6991433 108.2284206 102.4241872 54.24657786 42.27066922 0 27.06271612;
62.58939896 73.74425004 75.99775107 136.2771608 112.7285796 132.6677688 224.8457569 103.0641737 85.58534207 115.6234057 27.20137515 18.05283258 27.06271612 0];
% Formulate and solve the optimization problem
%cvx_solver('sedumi');
cvx_begin
variable x(n,n,h) binary % route selection variable
epsilon_resized = repmat(reshape(epsilon, 1, 1, []), [n, n, 1]);
minimize(Cp*sum(sum(sum(distances .* epsilon_resized .* x)))) % fuel consumption cost
subject to
for j=1:n
sum(x(:,j,:)) == 1; % each customer point can only be served by 1 vehicle
end
for i=2:n
sum(x(i,:,:)) == 1; % each vehicle can only serve 1 customer point
end
for m=1:h
sum(sum(x(:,:,m) * g')) <= b(m) % vehicles won't be overloaded
sum(x(1,:,m)) == sum(x(:,n,m)) % all vehicles start from and return to the distribution center
end
for i=1:n
for j=1:n
for m=1:h
x(i,j,m) >= 0;
end
end
end
cvx_end
% Display the solution
fprintf('Minimum cost: %f Tk\n', Cp*sum(sum(sum(repmat(epsilon,[n,n,h]).*distances.*x))) + Ce*E*sum(sum(sum(repmat(epsilon',[n,n,h]).*distances.*x))));
for m=1:h
fprintf('Routes for vehicle type %d:\n', m);
route = [1];
for i=2:n
if x(route(end),i,m) > 0
route = [route i];
end
end
fprintf('%d -> ', route);
fprintf('%d\n', n+1);
end

Sign in to comment.

Answers (1)

Torsten
Torsten on 13 May 2023
Moved: Torsten on 13 May 2023
Try MATLAB's problem-based approach to solve optimization problems.
Or - if your objective function and your constraints are linear and you are accustomed with the solver-based setup - directly use "intlinprog".

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!