How to write nonlinear optimisation model with multiple constraints with triangular fuzzy number data

6 views (last 30 days)
Dear all, I have following data realted to Best-Worst method:
I want to compute the weights corresponding to criteria C1, C2 and C3 in terms of triangular fuzzy numbers: (l1,m1,u1), (l2,m2,u2), (l3,m3,u3).
The values of (l1,m1,u1), (l2,m2,u2), (l3,m3,u3) and k* can be obtained by solving this optimisation model.
So far I have tried the following code:
clc; clear;
% Example: Assume 3 criteria (C1, C2, C3)
n = 3; % Number of criteria
% Get user input for best and worst criteria
criteria = {'C1', 'C2', 'C3'};
disp('Criteria List:');
Criteria List:
disp(criteria);
{'C1'} {'C2'} {'C3'}
best_index = input('Enter the index of the best criterion (1-3): ');
Error using input
Support for user input is required, which is not available on this platform.
worst_index = input('Enter the index of the worst criterion (1-3): ');
% Best-to-Others (B) and Others-to-Worst (W) in triangular fuzzy form
B = zeros(n, 3);
W = zeros(n, 3);
for i = 1:n
if i == best_index
B(i, :) = [1, 1, 1];
else
while true
B(i, :) = input(['Enter triangular fuzzy preference of best criterion over ', criteria{i}, ' as [low mid high]: ']);
if B(i, 1) <= B(i, 2) && B(i, 2) <= B(i, 3)
break;
else
disp('Error: Ensure low <= mid <= high. Please re-enter.');
end
end
end
if i == worst_index
W(i, :) = [1, 1, 1];
else
while true
W(i, :) = input(['Enter triangular fuzzy preference of ', criteria{i}, ' over worst criterion as [low mid high]: ']);
if W(i, 1) <= W(i, 2) && W(i, 2) <= W(i, 3)
break;
else
disp('Error: Ensure low <= mid <= high. Please re-enter.');
end
end
end
end
% Optimization Model to find optimal weights using triangular fuzzy numbers
cvx_begin quiet
variable w(n, 3) nonnegative % Weight vector (low, mid, high bounds)
variable k nonnegative % Slack variable (must be non-negative)
minimize(k)
subject to
% Best-to-others constraints
for i = 1:n
if i ~= best_index
w(best_index, 1) - B(i, 1) * w(i, 1) <= k* w(i, 1);
w(best_index, 1) - B(i, 1) * w(i, 1) >= -k* w(i, 1);
w(best_index, 2) - B(i, 2) * w(i, 2) <= k* w(i, 2);
w(best_index, 2) - B(i, 2) * w(i, 2) >= -k* w(i, 2);
w(best_index, 3) - B(i, 3) * w(i, 3) <= k* w(i, 3);
w(best_index, 3) - B(i, 3) * w(i, 3) >= -k* w(i, 3);
end
end
% Others-to-worst constraints
for i = 1:n
if i ~= worst_index
w(i, 1) - W(i, 1) * w(worst_index, 1) <= k* w(worst_index, 1);
w(i, 1) - W(i, 1) * w(worst_index, 1) >= -k* w(worst_index, 1);
w(i, 2) - W(i, 2) * w(worst_index, 2) <= k * w(worst_index, 2);
w(i, 2) - W(i, 2) * w(worst_index, 2) >= -k * w(worst_index, 2);
w(i, 3) - W(i, 3) * w(worst_index, 3) <= k* w(worst_index, 3);
w(i, 3) - W(i, 3) * w(worst_index, 3) >= -k* w(worst_index, 3);
end
end
% Normalization constraints
(w(1, 1)+ w(2, 1)+ w(3, 1))+ 4*(w(1, 2)+ w(2, 2)+ w(3, 2))+ (w(1, 3)+ w(2, 3)+ w(3, 3))/6 == 1 % Weights sum to 1.
% Ensure triangular fuzzy order
w(:, 1) <= w(:, 2);
w(:, 2) <= w(:, 3);
w(:, 1) >= 0;
cvx_end
% Display the results
disp('Optimal Triangular Fuzzy Weights for Criteria:');
disp(w);
disp('Consistency Value (Slack Variable):');
disp(k);
But I am getting some error afer running this code. If we modify the constraint as follows:
subject to
% Best-to-others constraints
for i = 1:n
if i ~= best_index
w(best_index, 1) - B(i, 1) * w(i, 1) <= k;
w(best_index, 1) - B(i, 1) * w(i, 1) >= -k;
w(best_index, 2) - B(i, 2) * w(i, 2) <= k;
w(best_index, 2) - B(i, 2) * w(i, 2) >= -k;
w(best_index, 3) - B(i, 3) * w(i, 3) <= k;
w(best_index, 3) - B(i, 3) * w(i, 3) >= -k;
end
end
% Others-to-worst constraints
for i = 1:n
if i ~= worst_index
w(i, 1) - W(i, 1) * w(worst_index, 1) <= k;
w(i, 1) - W(i, 1) * w(worst_index, 1) >= -k;
w(i, 2) - W(i, 2) * w(worst_index, 2) <= k ;
w(i, 2) - W(i, 2) * w(worst_index, 2) >= -k;
w(i, 3) - W(i, 3) * w(worst_index, 3) <= k;
w(i, 3) - W(i, 3) * w(worst_index, 3) >= -k;
end
end
Then code is running without error but giving wrong output. Please help to to resolve this issue.
  2 Comments
Rajkumar Verma
Rajkumar Verma on 6 Mar 2025
Input values:
Enter the index of the best criterion (1-3): 3
Enter the index of the worst criterion (1-3): 1
Enter triangular fuzzy preference of best criterion over C1 as [low mid high]: [7/2 4 9/2]
Enter triangular fuzzy preference of best criterion over C2 as [low mid high]: [2/3 1 3/2]
Enter triangular fuzzy preference of C2 over worst criterion as [low mid high]: [3/2 2 5/2]
Enter triangular fuzzy preference of C3 over worst criterion as [low mid high]: [7/2 4 9/2]
Sam Chak
Sam Chak on 6 Mar 2025
Your code is now formatted in to run in MATLAB Online. You may need to edit your code, as some lines appear to be treated as comments but are not annotated.
Additionally, it is advisable to provide an example so that users with in-depth knowledge and experience in applying MCDM methodologies can analyze your code.

Sign in to comment.

Answers (1)

Sam Chak
Sam Chak on 29 Apr 2025
Most parts of the code function correctly. However, you need to test it by inputting desired values into the arrays B and W, as the input() function, which prompts the user to enter values, is not supported in the MATLAB Online of this forum platform.
I also cannot find any fuzzy logic inference elements in the code. Therefore, if you want to verify that the for-loops are working correctly, you need to provide additional info so that the entire code runs without errors when the 'Run' button is clicked.
clc; clear;
% Example: Assume 3 criteria (C1, C2, C3)
n = 3; % Number of criteria
% Get user input for best and worst criteria
criteria = {'C1', 'C2', 'C3'};
disp('Criteria List:');
Criteria List:
disp(criteria);
{'C1'} {'C2'} {'C3'}
best_index = 3;
worst_index = 1;
% Best-to-Others (B) and Others-to-Worst (W) in triangular fuzzy form
B = zeros(n, 3);
W = zeros(n, 3);
for i = 1:n
if i == best_index
B(i, :) = [1, 1, 1];
else
while true
% B(i, :) = input(['Enter triangular fuzzy preference of best criterion over ', criteria{i}, ' as [low mid high]: ']);
B(i, :) = [1, 1, 1];
if B(i, 1) <= B(i, 2) && B(i, 2) <= B(i, 3)
break;
else
disp('Error: Ensure low <= mid <= high. Please re-enter.');
end
end
end
if i == worst_index
W(i, :) = [1, 1, 1];
else
while true
% W(i, :) = input(['Enter triangular fuzzy preference of ', criteria{i}, ' over worst criterion as [low mid high]: ']);
W(i, :) = [1, 1, 1];
if W(i, 1) <= W(i, 2) && W(i, 2) <= W(i, 3)
break;
else
disp('Error: Ensure low <= mid <= high. Please re-enter.');
end
end
end
end
% Optimization Model to find optimal weights using triangular fuzzy numbers
% cvx_begin quiet
% variable w(n, 3) nonnegative % Weight vector (low, mid, high bounds)
% variable k nonnegative % Slack variable (must be non-negative)
%
% minimize(k)
% subject to
w(n, 3) = 1;
k = 1;
% Best-to-others constraints
for i = 1:n
if i ~= best_index
w(best_index, 1) - B(i, 1) * w(i, 1) <= k* w(i, 1);
w(best_index, 1) - B(i, 1) * w(i, 1) >= -k* w(i, 1);
w(best_index, 2) - B(i, 2) * w(i, 2) <= k* w(i, 2);
w(best_index, 2) - B(i, 2) * w(i, 2) >= -k* w(i, 2);
w(best_index, 3) - B(i, 3) * w(i, 3) <= k* w(i, 3);
w(best_index, 3) - B(i, 3) * w(i, 3) >= -k* w(i, 3);
end
end
% Others-to-worst constraints
for i = 1:n
if i ~= worst_index
w(i, 1) - W(i, 1) * w(worst_index, 1) <= k* w(worst_index, 1);
w(i, 1) - W(i, 1) * w(worst_index, 1) >= -k* w(worst_index, 1);
w(i, 2) - W(i, 2) * w(worst_index, 2) <= k * w(worst_index, 2);
w(i, 2) - W(i, 2) * w(worst_index, 2) >= -k * w(worst_index, 2);
w(i, 3) - W(i, 3) * w(worst_index, 3) <= k* w(worst_index, 3);
w(i, 3) - W(i, 3) * w(worst_index, 3) >= -k* w(worst_index, 3);
end
end
% Normalization constraints
(w(1, 1)+ w(2, 1)+ w(3, 1))+ 4*(w(1, 2)+ w(2, 2)+ w(3, 2))+ (w(1, 3)+ w(2, 3)+ w(3, 3))/6 == 1 % Weights sum to 1.
ans = logical
0
% Ensure triangular fuzzy order
w(:, 1) <= w(:, 2);
w(:, 2) <= w(:, 3);
w(:, 1) >= 0;
% cvx_end
% Display the results
disp('Optimal Triangular Fuzzy Weights for Criteria:');
Optimal Triangular Fuzzy Weights for Criteria:
disp(w);
0 0 0 0 0 0 0 0 1
disp('Consistency Value (Slack Variable):');
Consistency Value (Slack Variable):
disp(k);
1

Categories

Find more on Fuzzy Inference System Modeling in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!