Implementation of Optimization Software in MATLAB
Version 1.0.0 (1.74 KB) by
ali
optimizationWe selected MATLAB as our optimization software due to its robust capabilities for solving linear prog
% MATLAB script for urban transportation optimization
% Step 1: Define Input Data
% Cost coefficients
c_v = [10; 15; 20]; % Vehicle costs per hour
c_d = [5; 7; 6]; % Driver costs per hour
% Minimum required vehicles and drivers for each route
R = [2; 3; 1]; % Minimum vehicles for routes
D = [3; 2; 2]; % Minimum drivers for routes
% Maximum working hours per vehicle and driver
H = 8; % Maximum hours allowed
% Emission rates per vehicle for each route
e = [1; 2; 1]; % Emission per hour for vehicles
E = [10; 12; 10]; % Maximum emissions allowed for each route
% Step 2: Formulate the Linear Programming Problem
% Objective function coefficients
f = [c_v; c_d]; % Combine vehicle and driver costs
% Initialize constraints
A = []; % Coefficients for inequality constraints
b = []; % Right-hand side values for constraints
% Minimum route coverage constraints
for j = 1:length(R)
A = [A; zeros(1, length(c_v)), eye(1, length(c_d))]; % For drivers
b = [b; R(j)];
A = [A; eye(1, length(c_v)), zeros(1, length(c_d))]; % For vehicles
b = [b; D(j)];
end
% Maximum working hours constraints
for i = 1:length(c_v)
A = [A; eye(1, length(c_v)), zeros(1, length(c_d))]; % For vehicles
b = [b; H];
A = [A; zeros(1, length(c_v)), eye(1, length(c_d))]; % For drivers
b = [b; H];
end
% Environmental constraints
for j = 1:length(E)
A = [A; e(j) * eye(1, length(c_v)), zeros(1, length(c_d))];
b = [b; E(j)];
end
% Variable bounds
lb = zeros(length(c_v) + length(c_d), 1); % Lower bounds for decision variables
ub = []; % Upper bounds can be defined as needed
% Step 3: Solve the Linear Programming Problem
% Call linprog to solve the problem
options = optimoptions('linprog','Display','iter'); % Display output during optimization
[x, fval] = linprog(f, A, b, [], [], lb, ub, options);
% Step 4: Display Results
disp('Optimal Allocation of Vehicles and Drivers (hours):');
disp(x);
disp('Minimum Total Cost:');
disp(fval);
Cite As
ali (2026). Implementation of Optimization Software in MATLAB (https://uk.mathworks.com/matlabcentral/fileexchange/174865-implementation-of-optimization-software-in-matlab), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
