-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: deleted unused code feat: added checker service
- Loading branch information
1 parent
767771a
commit 3bde13c
Showing
20 changed files
with
202 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
src/McdaToolkit/Mcda/Errors/CriteriaNotBetweenMinusOneAndOne.cs
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/McdaToolkit/Mcda/Helpers/Errors/DecisionCriteriaHaveIncorrectValueError.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using LightResults; | ||
|
||
namespace McdaToolkit.Mcda.Helpers.Errors; | ||
|
||
public class DecisionCriteriaHaveIncorrectValueError() : Error("Criteria decision types should be number ∈Z{-1;1}"); |
5 changes: 5 additions & 0 deletions
5
src/McdaToolkit/Mcda/Helpers/Errors/MatrixColumnLengthNotEqualWeightsVectorLengthError.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using LightResults; | ||
|
||
namespace McdaToolkit.Mcda.Helpers.Errors; | ||
|
||
public class MatrixColumnLengthNotEqualWeightsVectorLengthError() : Error("Columns length of data matrix should be equal length of weights and types arrays"); |
2 changes: 1 addition & 1 deletion
2
...kit/Mcda/Errors/WeightNotSumToOneError.cs → .../Helpers/Errors/WeightNotSumToOneError.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using LightResults; | ||
|
||
namespace McdaToolkit.Mcda.Errors; | ||
namespace McdaToolkit.Mcda.Helpers.Errors; | ||
|
||
public class WeightNotSumToOneError() : Error("Sum of weight have to equal 1"); |
4 changes: 1 addition & 3 deletions
4
...aToolkit/Mcda/Abstraction/ICalculation.cs → .../Mcda/Methods/Abstraction/ICalculation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace McdaToolkit.Mcda.Methods.Abstraction; | ||
|
||
public interface IMcdaMethod : ICalculation<double> | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using LightResults; | ||
using MathNet.Numerics.LinearAlgebra; | ||
using McdaToolkit.Extensions; | ||
using McdaToolkit.Mcda.Services; | ||
|
||
namespace McdaToolkit.Mcda.Methods.Abstraction; | ||
|
||
public abstract class McdaMethod : IMcdaMethod | ||
{ | ||
private readonly MatrixCheckerService _matrixCheckerService = new(); | ||
|
||
protected abstract Result<Vector<double>> RunCalculation(double[,] matrix, double[] weights, int[] criteriaDirections); | ||
|
||
/// <inheritdoc cref="ICalculation{TValue}.Calculate(System.Collections.Generic.IEnumerable{System.Collections.Generic.IEnumerable{TValue}},System.Collections.Generic.IEnumerable{TValue},System.Collections.Generic.IEnumerable{int})"/> | ||
public Result<Vector<double>> Calculate(IEnumerable<IEnumerable<double>> matrix, IEnumerable<double> weights, IEnumerable<int> criteriaDirections) | ||
{ | ||
var convertedMatrix = matrix.To2DArray(); | ||
var convertedWeights = weights.ToArray(); | ||
var convertedCriteriaDecision = criteriaDirections.ToArray(); | ||
var matrixChecked = _matrixCheckerService.ValidateData(convertedMatrix, convertedWeights, convertedCriteriaDecision); | ||
|
||
if (matrixChecked.IsFailed) | ||
{ | ||
return Result.Fail<Vector<double>>(); | ||
} | ||
return RunCalculation(convertedMatrix, convertedWeights, convertedCriteriaDecision); | ||
} | ||
|
||
/// <summary> | ||
/// Calculate provided data | ||
/// </summary> | ||
/// <param name="matrix">Data as set of alternatives and theirs attributes</param> | ||
/// <param name="weights">Data determining relevance of each attribute</param> | ||
/// <param name="criteriaDirections">Data that determines the columns is profit or cost</param> | ||
/// <returns>Vector of processed data in descending order</returns> | ||
public Result<Vector<double>> Calculate(double[,] matrix,double[] weights,int[] criteriaDirections) | ||
{ | ||
var matrixChecked = _matrixCheckerService.ValidateData(matrix, weights, criteriaDirections); | ||
if (matrixChecked.IsFailed) | ||
{ | ||
return Result.Fail<Vector<double>>(); | ||
} | ||
return RunCalculation(matrix, weights, criteriaDirections); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/McdaToolkit/Options/McdaMethodOptions.cs → ...Toolkit/Mcda/Options/McdaMethodOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
using McdaToolkit.Enums; | ||
|
||
namespace McdaToolkit.Options; | ||
namespace McdaToolkit.Mcda.Options; | ||
|
||
/// <summary> | ||
/// Configuration for Mcda methods | ||
/// </summary> | ||
public record McdaMethodOptions | ||
{ | ||
/// <summary> | ||
/// Current normalization method | ||
/// </summary> | ||
public NormalizationMethod NormalizationMethod { get; set; } = NormalizationMethod.MinMax; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using LightResults; | ||
using McdaToolkit.Mcda.Helpers; | ||
using McdaToolkit.Mcda.Helpers.Errors; | ||
|
||
namespace McdaToolkit.Mcda.Services; | ||
|
||
internal sealed class MatrixCheckerService | ||
{ | ||
public Result ValidateData(double[,] matrix, double[] weights, int[] criteriaDirections) | ||
{ | ||
var isWeightsCorrect = CheckDataHelper.IsWeightEqualOne(weights); | ||
if (!isWeightsCorrect) | ||
{ | ||
return Result.Fail(new WeightNotSumToOneError()); | ||
} | ||
|
||
var isCriteriaDecisionCorrect = CheckDataHelper.IsCriteriaDesisionBetweenMinusOneAndOne(criteriaDirections); | ||
if (!isCriteriaDecisionCorrect) | ||
{ | ||
return Result.Fail(new DecisionCriteriaHaveIncorrectValueError()); | ||
} | ||
|
||
var isSizesAreCorrect = CheckDataHelper.IsDataWeightsAndTypesHaveCorrectSizes(matrix, weights, criteriaDirections); | ||
if (!isSizesAreCorrect) | ||
{ | ||
return Result.Fail(new MatrixColumnLengthNotEqualWeightsVectorLengthError()); | ||
} | ||
return Result.Ok(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.