Find the combination that maximize the objective function values from the data set.

8 views (last 30 days)
Hello,
I have a written a small piece of code to find the unique combinations from the excel file which has data from my objective optimzation problem.
The file has six columns other hidden columns are not important. The first column in the green shows the objective value, the second and third column with blue indicates the constraint outputs, and fourth, fifth and sixth column with the yellow represents the combinations that are maximizing my objective function.
I have to choose the maximum (green) value from first column each time in the iteration, which will then select the constraint values (blue) from second and third column, whatever they may be. Additionally, each time, it should select a unique combination (yellow) from fourth fifth and sixth column different from the previous combination that maximized the value. No combination value in column should be repeated like if in first iteration it selected [1 8 1] then in next it should [2 6 2] or [3 7 1] or [4 6 5] but every time based on the maximum value it should have unique combination which is maximizing the objective.
My code snippet is here as I am not able to figure out how to choose unique value in every column.
filename = 'Objective Optimization MATLAB.xlsx';
data = readtable(filename);
% Initialize variables
previous_combination = [0 0 0];
% Number of iterations (adjust as needed)
num_iterations = 10;
for i = 1:num_iterations
% Find the maximum objective value
[max_value, max_index] = max(data{:, 1});
% Get the corresponding constraint values and combination
constraint_value1 = data{max_index, 2};
constraint_value2 = data{max_index, 3};
combination = data{max_index, 4:6};
% Check if the combination is unique in each column
while ~isempty(previous_combination) && any(combination == previous_combination)
% Remove the current maximum value to find the next one
data{max_index, 1} = -inf;
[max_value, max_index] = max(data{:, 1});
constraint_value1 = data{max_index, 2};
constraint_value2 = data{max_index, 3};
combination = data{max_index, 4:6};
end
% Ensure no two column values are identical
while length(unique(combination)) < length(combination)
% Remove the current maximum value to find the next one
data{max_index, 1} = -inf;
[max_value, max_index] = max(data{:, 1});
constraint_value1 = data{max_index, 2};
constraint_value2 = data{max_index, 3};
combination = data{max_index, 4:6};
end
% Store the combination to avoid repetition
previous_combination = combination;
% Display the results
fprintf('Iteration %d:\n', i);
fprintf('Max Objective Value: %f\n', max_value);
fprintf('Constraint Value 1: %f\n', constraint_value1);
fprintf('Constraint Value 2: %f\n', constraint_value2);
fprintf('Combination: %s\n\n', mat2str(combination));
uniquecombinations(i,:) = combination;
% Remove the current maximum value to find the next one in the next iteration
data{max_index, 1} = -inf;
end
Iteration 1:
Max Objective Value: 8190.061500
Constraint Value 1: 0.001000
Constraint Value 2: 0.014125
Combination: [1 8 1]
Iteration 2:
Max Objective Value: 3212.347400
Constraint Value 1: 0.001460
Constraint Value 2: 0.020620
Combination: [3 7 2]
Iteration 3:
Max Objective Value: 2836.743900
Constraint Value 1: 0.001000
Constraint Value 2: 0.014125
Combination: [1 3 1]
Iteration 4:
Max Objective Value: 2582.596200
Constraint Value 1: 0.001460
Constraint Value 2: 0.020620
Combination: [3 6 2]
Iteration 5:
Max Objective Value: 2095.437000
Constraint Value 1: 0.001000
Constraint Value 2: 0.014125
Combination: [1 2 1]
Iteration 6:
Max Objective Value: 2024.398100
Constraint Value 1: 0.001460
Constraint Value 2: 0.020620
Combination: [3 5 2]
Iteration 7:
Max Objective Value: 1517.063600
Constraint Value 1: 0.001000
Constraint Value 2: 0.014125
Combination: [1 1 1]
Iteration 8:
Max Objective Value: 1154.079300
Constraint Value 1: 0.001460
Constraint Value 2: 0.020620
Combination: [3 3 2]
Iteration 9:
Max Objective Value: 919.346070
Constraint Value 1: 0.001000
Constraint Value 2: 0.014125
Combination: [7 8 1]
Iteration 10:
Max Objective Value: 843.311830
Constraint Value 1: 0.001460
Constraint Value 2: 0.020620
Combination: [3 2 2]
% Getting these combinations
1 8 2
3 7 1
1 3 2
3 6 1
1 2 3
3 5 1
7 8 1
3 2 4
3 1 2
4 8 1
% Since in first column 3 and 1 are repeated
% In 2nd column 8 is repeated
% In 3rd column 2 and 1 are repeated.
  1 Comment
Torsten
Torsten on 20 Aug 2024
Edited: Torsten on 20 Aug 2024
It seems that in your code you only compare with the previous combination, but what you really want is to compare with all previous combinations.

Sign in to comment.

Accepted Answer

Torsten
Torsten on 20 Aug 2024
filename = 'Objective Optimization MATLAB.xlsx';
data = xlsread(filename);
data(:,7:end) = [];
n = 1;
while(size(data,1) > 0)
[~,idx] = max(data(:,1));
taken(n,:) = data(idx,:);
jdx = data(:,4) == data(idx,4) | data(:,5) == data(idx,5) | data(:,6) == data(idx,6);
data(jdx,:) = [];
n = n+1;
end
taken
taken = 8x6
1.0e+03 * 8.1901 0.0000 0.0000 0.0010 0.0080 0.0010 3.2123 0.0000 0.0000 0.0030 0.0070 0.0020 0.5238 0.0000 0.0000 0.0070 0.0060 0.0030 0.2912 0.0000 0.0000 0.0040 0.0050 0.0040 0.1756 0.0000 0.0001 0.0060 0.0040 0.0050 0.0710 0.0000 0.0001 0.0020 0.0030 0.0060 0.0270 0.0000 0.0001 0.0080 0.0020 0.0070 0.0077 0.0000 0.0002 0.0050 0.0010 0.0080
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  2 Comments
Torsten
Torsten on 20 Aug 2024
Edited: Torsten on 20 Aug 2024
Note that this procedure doesn't ensure in general that the sum of the first column is maximized under the constraint that there are no repetitions in columns 4-6 (if this is what you had in mind).

Sign in to comment.

More Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!