Skip to content

Commit

Permalink
[BUG] Taking into account if criterion is benefit (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
demid5111 committed May 6, 2022
1 parent 858dd67 commit bc558e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/main/java/dss/lingvo/samples/TT2HFLTSCoordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ private void processSimpleCase(File outputDirectory) throws IOException {

private void processNumericSample() {
// now how to work with numbers
int targetScaleSize = 7;

final float numeric_assessment = 0.78f;
List<Float> fSet = TTNormalizedTranslator.getInstance().getFuzzySetForNumericEstimation(numeric_assessment, 5);
float resTranslation = TTNormalizedTranslator.getInstance().getTranslationFromFuzzySet(fSet);
TTTuple resTuple = TTNormalizedTranslator.getInstance().getTTupleForNumericTranslation(resTranslation, 5);
System.out.printf("Translating %f to 2-tuple: %s\n", numeric_assessment, resTuple.toString());
}

private void processweightsGenerationSample() {
private void processWeightsGenerationSample() {
float[] expDistr = {0.8f, 0.2f};
float[] resVector = TTUtils.calculateWeightsVector(expDistr, 4);
System.out.println(Arrays.toString(resVector));
Expand Down Expand Up @@ -111,13 +109,22 @@ private void processMultiLevelAdvancedSample(File inputFile, File outputDirector
int targetScaleSize = 7;

TTJSONMultiLevelInputModel model = ttjsonReader.readJSONMultiLevelDescription(inputFile, false);
List<ArrayList<ArrayList<TT2HFLTS>>> all = TTUtils.getAllEstimationsFromMultiLevelJSONModel(model, 7);

TTNormalizedTranslator.registerScalesBatch(model.getScales());

List<ArrayList<ArrayList<TT2HFLTS>>> all = TTUtils.getAllEstimationsFromMultiLevelJSONModel(model,
targetScaleSize);

// Step 1. Aggregate by abstraction level
TT2HFLTSMHTWOWAMultiLevelOperator tt2HFLTSMHTWOWAMultiLevelOperator = new TT2HFLTSMHTWOWAMultiLevelOperator();
List<ArrayList<ArrayList<TT2HFLTS>>> allByLevel = tt2HFLTSMHTWOWAMultiLevelOperator.aggregateByAbstractionLevel(model.getCriteria(), model.getAbstractionLevels(), all, targetScaleSize, model.getCriteriaWeightsPerGroup());

List<ArrayList<ArrayList<TT2HFLTS>>> allByExpert = tt2HFLTSMHTWOWAMultiLevelOperator.transposeByAbstractionLevel(model.getAbstractionLevels().size(), model.getAlternatives().size(), model.getExperts().size(), allByLevel);
List<ArrayList<ArrayList<TT2HFLTS>>> allByLevel = tt2HFLTSMHTWOWAMultiLevelOperator.aggregateByAbstractionLevel(
model.getCriteria(), model.getAbstractionLevels(), all, targetScaleSize,
model.getCriteriaWeightsPerGroup());

List<ArrayList<ArrayList<TT2HFLTS>>> allByExpert =
tt2HFLTSMHTWOWAMultiLevelOperator.transposeByAbstractionLevel(model.getAbstractionLevels().size(),
model.getAlternatives().size(), model.getExperts().size(), allByLevel);

int numExperts = model.getExpertWeightsRule().values().size();
float[] a = new float[numExperts];
Expand All @@ -132,14 +139,15 @@ private void processMultiLevelAdvancedSample(File inputFile, File outputDirector
if (numExperts > 1) {
a[1] = 1 - curMax;
}
List<ArrayList<TT2HFLTS>> altToLevel = tt2HFLTSMHTWOWAMultiLevelOperator.aggregateByExpert(model.getAbstractionLevels().size(), model.getAlternatives().size(), 7, allByExpert, a);
List<ArrayList<TT2HFLTS>> altToLevel = tt2HFLTSMHTWOWAMultiLevelOperator.aggregateByExpert(
model.getAbstractionLevels().size(), model.getAlternatives().size(), targetScaleSize, allByExpert, a);

List<TT2HFLTS> altVec = tt2HFLTSMHTWOWAMultiLevelOperator.aggregateFinalAltEst(7, altToLevel);
List<TT2HFLTS> altVec = tt2HFLTSMHTWOWAMultiLevelOperator.aggregateFinalAltEst(targetScaleSize, altToLevel);

// all below is just processing

// saving to file
TTJSONOutputModel res = TTUtils.prepareAllResultsForJSON(altVec, model, 7);
TTJSONOutputModel res = TTUtils.prepareAllResultsForJSON(altVec, model, targetScaleSize);
Path outputJSONFilePath = Paths.get(outputDirectory.toString(), "result.json");
TTJSONUtils.getInstance().writeResultToJSON(outputJSONFilePath, res);

Expand All @@ -157,14 +165,8 @@ private void processMultiLevelAdvancedSample(File inputFile, File outputDirector
}

public void go(File inputFile, File outputDirectory) throws IOException {
processSimpleCase(outputDirectory);

processNumericSample();

processweightsGenerationSample();

processMHTWASample();

// processSimpleCase(outputDirectory);
// processNumericSample();
processMultiLevelAdvancedSample(inputFile, outputDirectory);
}
}
8 changes: 8 additions & 0 deletions src/main/java/dss/lingvo/utils/TTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ public static List<ArrayList<ArrayList<TT2HFLTS>>> getAllEstimationsFromMultiLev

float numericEstimation = valueToRemember / (averages.get(critEst.getCriteriaID()).floatValue());

if (!criterion.isBenefit()) {
assert numericEstimation >= 0. && numericEstimation <= 1: "should be already a normalized value";

// hereinafter all criteria are considered as benefit, therefore need to
// reverse cost criteria by subtracting them from one
numericEstimation = 1 - numericEstimation;
}

List<Float> fSet = translator.getFuzzySetForNumericEstimation(numericEstimation, targetScaleSize);
float resTranslation = translator.getTranslationFromFuzzySet(fSet);
TTTuple resTuple = translator.getTTupleForNumericTranslation(resTranslation, targetScaleSize);
Expand Down

0 comments on commit bc558e7

Please sign in to comment.