forked from SaeedMotedaveli/Unit-Commitment-FDP-Method
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitCombination.m
More file actions
39 lines (30 loc) · 954 Bytes
/
Copy pathunitCombination.m
File metadata and controls
39 lines (30 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function UCM = unitCombination(numOfUnit, unitsData)
allPossibleCombination = power(2, numOfUnit);
UCM = zeros(allPossibleCombination, numOfUnit + 2);
for i = 0 : allPossibleCombination - 1
combination = createCombination(i);
sumOfPmax = 0;
for n = 1 : numOfUnit
if combination(n) == '1'
UCM(i+1, n+2) = 1;
sumOfPmax = sumOfPmax + unitsData(n, 2);
end
end
UCM(i+1, 1) = i;
UCM(i+1, 2) = sumOfPmax;
end
UCM = sortrows(UCM, 2);
for i = 0 : allPossibleCombination - 1
UCM(i+1, 1) = i;
end
end
function combination = createCombination(num)
combination = dec2base(num, 2);
if length(combination) == 1
combination = ['000', combination];
elseif length(combination) == 2
combination = ['00', combination];
elseif length(combination) == 3
combination = ['0', combination];
end
end