-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Release 3.0.0
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,26 @@ | ||
namespace McdaToolkit.Extensions; | ||
|
||
internal static class EnumerableExtentions | ||
namespace McdaToolkit.Extensions | ||
{ | ||
public static IEnumerable<(T item, int index)> Indexed<T>(this IEnumerable<T> source) | ||
public static class EnumerableExtentions | ||
{ | ||
if (source is null) | ||
public static T[,] To2DArray<T>(this IEnumerable<IEnumerable<T>> source) | ||
{ | ||
throw new ArgumentNullException(); | ||
} | ||
var sourceToArray = source.ToArray(); | ||
var rows = sourceToArray.Length; | ||
var cols = sourceToArray[0].Count(); | ||
var result = new T[rows, cols]; | ||
var i = 0; | ||
|
||
var i = 0; | ||
foreach (var item in source) | ||
{ | ||
yield return (item, i); | ||
++i; | ||
} | ||
} | ||
|
||
public static T[,] To2DArray<T>(this IEnumerable<IEnumerable<T>> source) | ||
{ | ||
var sourceToArray = source.ToArray(); | ||
var rows = sourceToArray.Length; | ||
var cols = sourceToArray[0].Count(); | ||
var result = new T[rows, cols]; | ||
var i = 0; | ||
|
||
foreach (var row in sourceToArray) | ||
{ | ||
var j = 0; | ||
foreach (var value in row) | ||
foreach (var row in sourceToArray) | ||
{ | ||
result[i, j] = value; | ||
j++; | ||
var j = 0; | ||
foreach (var value in row) | ||
{ | ||
result[i, j] = value; | ||
j++; | ||
} | ||
i++; | ||
} | ||
i++; | ||
return result; | ||
} | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using MathNet.Numerics.LinearAlgebra; | ||
|
||
namespace McdaToolkit.Extensions; | ||
|
||
public static class MatrixExtensions | ||
{ | ||
public static Vector<T> GetColMax<T>(this Matrix<T> matrix) where T : struct, IEquatable<T>, IFormattable | ||
{ | ||
var maxVector = Vector<T>.Build.Dense(matrix.ColumnCount); | ||
|
||
for (int i = 0; i < matrix.ColumnCount; i++) | ||
{ | ||
maxVector[i] = matrix.Column(i).Maximum(); | ||
} | ||
return maxVector; | ||
} | ||
|
||
public static Vector<T> GetColMin<T>(this Matrix<T> matrix) where T : struct, IEquatable<T>, IFormattable | ||
{ | ||
var maxVector = Vector<T>.Build.Dense(matrix.ColumnCount); | ||
|
||
for (int i = 0; i < matrix.ColumnCount; i++) | ||
{ | ||
maxVector[i] = matrix.Column(i).Min(); | ||
} | ||
return maxVector; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace McdaToolkit.Mcda.Factories.Enums; | ||
|
||
public enum McdaMethods | ||
{ | ||
Topsis = 0, | ||
Vikor = 1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using McdaToolkit.Mcda.Providers; | ||
using McdaToolkit.Validation.MatrixValidation; | ||
|
||
namespace McdaToolkit.Mcda.Factories; | ||
|
||
public class DefaultDataProviderBuilder | ||
{ | ||
private double[,] _matrix; | ||
Check warning on line 8 in src/McdaToolkit/Mcda/Factories/MatrixValidator.cs GitHub Actions / build
Check warning on line 8 in src/McdaToolkit/Mcda/Factories/MatrixValidator.cs GitHub Actions / build
Check warning on line 8 in src/McdaToolkit/Mcda/Factories/MatrixValidator.cs GitHub Actions / build
|
||
private double[] _weigths; | ||
Check warning on line 9 in src/McdaToolkit/Mcda/Factories/MatrixValidator.cs GitHub Actions / build
|
||
private int[] _criteriaDecision; | ||
Check warning on line 10 in src/McdaToolkit/Mcda/Factories/MatrixValidator.cs GitHub Actions / build
Check warning on line 10 in src/McdaToolkit/Mcda/Factories/MatrixValidator.cs GitHub Actions / build
|
||
|
||
public DefaultDataProviderBuilder AddDecisionMatrix(double[,] matrix) | ||
{ | ||
_matrix = matrix; | ||
return this; | ||
} | ||
|
||
public DefaultDataProviderBuilder AddWeights(double[] weights) | ||
{ | ||
_weigths = weights; | ||
return this; | ||
} | ||
|
||
public DefaultDataProviderBuilder AddDecisionCriteria(int[] criteriaDecision) | ||
{ | ||
_criteriaDecision = criteriaDecision; | ||
return this; | ||
} | ||
|
||
public McdaInputData Build() | ||
{ | ||
var matrixValidationResult = new MatrixValidation(_matrix, _weigths, _criteriaDecision).Validate(); | ||
if (matrixValidationResult.IsFailed) | ||
{ | ||
throw new ArgumentNullException($"Failed to provide data because of: {string .Join(", ",matrixValidationResult.Errors)}"); | ||
} | ||
var provider = new DefaultDataProvider(); | ||
var provideResult = provider.ProvideData(_matrix, _weigths, _criteriaDecision);; | ||
if (provideResult.IsFailed) | ||
{ | ||
throw new ArgumentNullException($"Failed to provide data because of: {string .Join(", ", provideResult.Errors)}"); | ||
} | ||
return provider.GetData(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using McdaToolkit.Mcda.Factories.Enums; | ||
using McdaToolkit.Mcda.Methods.Abstraction; | ||
using McdaToolkit.Mcda.Methods.Topsis; | ||
using McdaToolkit.Mcda.Methods.Vikor; | ||
using McdaToolkit.Normalization.Services.MatrixNormalizator; | ||
|
||
namespace McdaToolkit.Mcda.Factories; | ||
|
||
public static class MethodFactory | ||
{ | ||
private static IMcdaMethod CreateMethod( | ||
McdaMethods method, | ||
IMcdaMethodOptions options) | ||
{ | ||
var normalizationMatrixService = new MatrixNormalizatorService( | ||
new NormalizationMethodFactory(), | ||
options.NormalizationMethod); | ||
|
||
return method switch | ||
{ | ||
McdaMethods.Vikor => new Vikor(normalizationMatrixService,((VikorOptions)options).VikorParameters), | ||
McdaMethods.Topsis => new Topsis(normalizationMatrixService), | ||
_ => throw new ArgumentOutOfRangeException(nameof(method), method, null) | ||
}; | ||
} | ||
|
||
public static IVikorMethod CreateVikor(VikorOptions options) | ||
{ | ||
return (IVikorMethod)CreateMethod(McdaMethods.Vikor, options); | ||
} | ||
|
||
public static ITopsisMethod CreateTopsis(TopsisOptions options) | ||
{ | ||
return (ITopsisMethod)CreateMethod(McdaMethods.Topsis, options); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using MathNet.Numerics.LinearAlgebra; | ||
using McdaToolkit.Mcda.Methods.Abstraction; | ||
|
||
namespace McdaToolkit.Mcda; | ||
|
||
public record McdaInputData( | ||
Matrix<double> Matrix, | ||
Vector<double> Weights, | ||
int[] Types) | ||
{ | ||
public int[] Types { get; } = Types; | ||
public Matrix<double> Matrix { get; } = Matrix; | ||
public Vector<double> Weights { get; } = Weights; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using McdaToolkit.Normalization.Enums; | ||
|
||
namespace McdaToolkit.Mcda; | ||
|
||
/// <summary> | ||
/// Configuration for mcda methods | ||
/// </summary> | ||
public interface IMcdaMethodOptions | ||
{ | ||
/// <summary> | ||
/// Normalization method | ||
/// </summary> | ||
public NormalizationMethod NormalizationMethod { get; set; } | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
namespace McdaToolkit.Mcda.Methods.Abstraction; | ||
using LightResults; | ||
using McdaToolkit.Mcda.Providers; | ||
|
||
public interface IMcdaMethod : ICalculation<double> | ||
namespace McdaToolkit.Mcda.Methods.Abstraction; | ||
|
||
public interface IMcdaMethod<out TResult> : IMcdaMethod | ||
where TResult : IResult<IMcdaScore> | ||
{ | ||
new TResult Run(McdaInputData data); | ||
} | ||
|
||
public interface IMcdaMethod | ||
{ | ||
|
||
} | ||
IResult Run(McdaInputData data); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using MathNet.Numerics.LinearAlgebra; | ||
|
||
namespace McdaToolkit.Mcda.Methods.Abstraction; | ||
|
||
public interface IMcdaScore | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace McdaToolkit.Mcda.Methods.Abstraction; | ||
|
||
public interface IMcdaAdditionalParameters | ||
{ | ||
|
||
} |