-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
ParetoOptimization.cs
71 lines (65 loc) · 2.7 KB
/
ParetoOptimization.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using System.Linq;
namespace Algorithms.Other;
/// <summary>
/// Almost all real complex decision-making task is described by more than one criterion.
/// Therefore, the methods of multicriteria optimization are important. For a wide range
/// of tasks multicriteria optimization, described by some axioms of "reasonable"
/// behavior in the process of choosing from a set of possible solutions X, each set of
/// selected solutions Sel X should be contained in a set optimal for Pareto.
/// </summary>
public class ParetoOptimization
{
/// <summary>
/// Performs decision optimizations by using Paretor's optimization algorithm.
/// </summary>
/// <param name="matrix">Contains a collection of the criterias sets.</param>
/// <returns>An optimized collection of the criterias sets.</returns>
public List<List<decimal>> Optimize(List<List<decimal>> matrix)
{
var optimizedMatrix = new List<List<decimal>>(matrix.Select(i => i));
int i = 0;
while (i < optimizedMatrix.Count)
{
for (int j = i + 1; j < optimizedMatrix.Count; j++)
{
decimal directParwiseDifference = GetMinimalPairwiseDifference(optimizedMatrix[i], optimizedMatrix[j]);
decimal indirectParwiseDifference = GetMinimalPairwiseDifference(optimizedMatrix[j], optimizedMatrix[i]);
/*
* in case all criteria of one set are larger that the criteria of another, this
* decision is not optimal and it has to be removed
*/
if (directParwiseDifference >= 0 || indirectParwiseDifference >= 0)
{
optimizedMatrix.RemoveAt(directParwiseDifference >= 0 ? j : i);
i--;
break;
}
}
i++;
}
return optimizedMatrix;
}
/// <summary>
/// Calculates the smallest difference between criteria of input decisions.
/// </summary>
/// <param name="arr1">Criterias of the first decision.</param>
/// <param name="arr2">Criterias of the second decision.</param>
/// <returns>Values that represent the smallest difference between criteria of input decisions.</returns>
private decimal GetMinimalPairwiseDifference(List<decimal> arr1, List<decimal> arr2)
{
decimal min = decimal.MaxValue;
if (arr1.Count == arr2.Count)
{
for (int i = 0; i < arr1.Count; i++)
{
decimal difference = arr1[i] - arr2[i];
if (min > difference)
{
min = difference;
}
}
}
return min;
}
}