public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,191 @@
package flintstones.method.todim.phase.gathering;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.entity.method.phase.PhaseMethod;
import flintstones.entity.problemelement.ProblemElementKey;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.problemelement.entities.ProblemElementHelper;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.HashMatrix;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
import flintstones.valuation.numeric.NumericValuation;
public class phaseTodim extends PhaseMethod {
@Inject
IEclipseContext context;
@Inject
IValuationService valuationService;
@Inject
IDomainService domainService;
@Inject
IProblemElementService problemService;
// Atributos
HashMap<ProblemElementKey, Valuation> mapVAluations;
HashMatrix<Expert, Criterion, Double> hmWeights;
Alternative[] allAlternatives;
Criterion[] allCriterion;
Expert[] allexperts;
double[][] initialMatrix;
double[][] normalizeMatrix;
double[] weights;
double[] relativeWeights;
double[] scaleNormalization;
double maxWeight;
double totalRelativeWeight;
public phaseTodim() {
}
@Override
public String getName() {
return "TODIM";
}
@SuppressWarnings("unchecked")
public void initialize() {
ProblemElement[] pes = problemService.getAll(Alternative.Type);
allAlternatives = ProblemElementHelper.asAlternatives(pes);
pes = problemService.getAll(Criterion.Type);
allCriterion = ProblemElementHelper.asCriterions(pes);
pes = problemService.getAll(Expert.Type);
allexperts = ProblemElementHelper.asExperts(pes);
hmWeights = (HashMatrix<Expert, Criterion, Double>) this.importData("criterionWeights");
this.weights = getWeights();
}
public Criterion[] getCriteria() {
return this.allCriterion;
}
public Alternative[] getAlternatives() {
return this.allAlternatives;
}
public String[] getAlternativesNames() {
String[] str = new String[allAlternatives.length];
for (int i = 0; i < allAlternatives.length; i++)
str[i] = allAlternatives[i].getCanonicalName();
return str;
}
public String[] getCriterionNames() {
String[] str = new String[allCriterion.length];
for (int i = 0; i < allCriterion.length; i++)
str[i] = allCriterion[i].getCanonicalName();
return str;
}
public void executeMethod(Expert e, double[] scaleNormalization) {
this.scaleNormalization = scaleNormalization;
this.initialMatrix = this.getValuations(e);
normalize();
getRelativeWeight();
// exportamos los datos a la ventana de resultados.
this.exportData("normalizeMatrix", normalizeMatrix);
this.exportData("relativeWeights", relativeWeights);
this.exportData("maxWeight", maxWeight);
this.exportData("totalRelativeWeight", totalRelativeWeight);
}
public HashMap<ProblemElementKey, Valuation> getMapValuations(Expert e) {
ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName());
mapVAluations = valuationService.getAllValuationsKVWith(pE);
return mapVAluations;
}
public double[][] getValuations(Expert e) {
double[][] valuation = new double[allAlternatives.length][allCriterion.length];
ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName());
mapVAluations = valuationService.getAllValuationsKVWith(pE);
int a = 0, b = 0;
for (Entry<ProblemElementKey, Valuation> entry : mapVAluations.entrySet()) {
NumericValuation nV = (NumericValuation) entry.getValue();
for (int i = 0; i < allAlternatives.length; i++)
if (entry.getKey().getAlternative().getId().equals(allAlternatives[i].getId())) {
a = i;
break;
}
for (int i = 0; i < allCriterion.length; i++)
if (entry.getKey().getCriterion().getId().equals(allCriterion[i].getId())) {
b = i;
break;
}
valuation[a][b] = Double.valueOf(nV.getValue());
a = 0;
b = 0;
}
return valuation;
}
private double[] getWeights() {
double[] ws = new double[allCriterion.length];
double w;
for (int i = 0; i < allCriterion.length; i++) {
w = hmWeights.get(allexperts[0], allCriterion[i]);
ws[i] = w;
}
return ws;
}
private void normalize() {
normalizeMatrix = new double[allAlternatives.length][allCriterion.length];
for (int i = 0; i < initialMatrix.length; i++)
for (int j = 0; j < initialMatrix[i].length; j++)
normalizeMatrix[i][j] = initialMatrix[i][j] / scaleNormalization[j];
}
private void getRelativeWeight() {
maxWeight = Arrays.stream(weights).max().getAsDouble();
relativeWeights = new double[allCriterion.length];
for (int i = 0; i < relativeWeights.length; i++)
relativeWeights[i] = weights[i] / maxWeight;
totalRelativeWeight = 0.0f;
for (int i = 0; i < relativeWeights.length; i++)
totalRelativeWeight += relativeWeights[i];
}
}