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,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.entity.sensitiveanalysismodel.wpm.mcc</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Weighted product model</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.entity.sensitiveanalysismodel.wpm.mcc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362581</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,14 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Weighted product model
Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.wpm.mcc;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.mcc.wpm
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: flintstones.entity.sensitiveanalysismodel,
javax.inject,
flintstones.model.problemelement.service,
flintstones.valuation.twoTuple,
flintstones.valuation.numeric,
flintstones.valuation.fuzzy
Export-Package: flintstones.entity.sensitiveanalysismodel.wpm.mcc
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.entity.sensitiveanalysismodel.extension">
<model
uid="flintstones.entity.sensitiveanalysismodel.mcc.wpm"
implementation="flintstones.entity.sensitiveanalysismodel.wpm.mcc.WeightedProductModelMCCTwoTuple"
name="weighted product model">
</model>
<model
implementation="flintstones.entity.sensitiveanalysismodel.wpm.mcc.WeightedProductModelMCCNumeric"
name="weighted product model"
uid="flintstones.entity.sensitiveanalysismodel.mcc.wpm.numeric">
</model>
<model
implementation="flintstones.entity.sensitiveanalysismodel.wpm.mcc.WeightedProductModelMCCFuzzy"
name="weighted product model"
uid="flintstones.entity.sensitiveanalysismodel.mcc.wpm.fuzzy">
</model>
</extension>
</plugin>
@@ -0,0 +1,357 @@
package flintstones.entity.sensitiveanalysismodel.wpm.mcc;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.HashMatrix;
import flintstones.model.problemelement.service.IProblemElementService;
public abstract class WeightedProductModelMCC extends SensitiveAnalysisModel {
@Inject
IProblemElementService problemService;
protected Double[][] alternativesRatioFinalPreferences;
protected Double[][][] minimumAbsoluteChangeInCriteriaWeights;
protected Double[][][] minimumRelativeChangeInCriteriaWeights;
protected List<Integer> absoluteTop;
protected List<Integer> absoluteAny;
protected List<Integer> relativeTop;
protected List<Integer> relativeAny;
protected int numAlternatives;
protected int numCriteria;
public Map<ProblemElement, Double> getCriteriaWeights() {
return criteriaWeights;
}
public void setCriteriaWeights(Map<ProblemElement, Double> criteriaWeights) {
this.criteriaWeights = criteriaWeights;
}
public Double[][] getAlternativesRatioFinalPreferences() {
return alternativesRatioFinalPreferences;
}
public void setAlternativesRatioFinalPreferences(Double[][] alternativesRatioFinalPreferences) {
this.alternativesRatioFinalPreferences = alternativesRatioFinalPreferences;
}
public Double[][][] getMinimumAbsoluteChangeInCriteriaWeights() {
return minimumAbsoluteChangeInCriteriaWeights;
}
public void setMinimumAbsoluteChangeInCriteriaWeights(Double[][][] minimumAbsoluteChangeInCriteriaWeights) {
this.minimumAbsoluteChangeInCriteriaWeights = minimumAbsoluteChangeInCriteriaWeights;
}
public Double[][][] getMinimumRelativeChangeInCriteriaWeights() {
return minimumRelativeChangeInCriteriaWeights;
}
public void setMinimumRelativeChangeInCriteriaWeights(Double[][][] minimumRelativeChangeInCriteriaWeights) {
this.minimumRelativeChangeInCriteriaWeights = minimumRelativeChangeInCriteriaWeights;
}
public List<Integer> getAbsoluteTop() {
return absoluteTop;
}
public void setAbsoluteTop(List<Integer> absoluteTop) {
this.absoluteTop = absoluteTop;
}
public List<Integer> getAbsoluteAny() {
return absoluteAny;
}
public void setAbsoluteAny(List<Integer> absoluteAny) {
this.absoluteAny = absoluteAny;
}
public List<Integer> getRelativeTop() {
return relativeTop;
}
public void setRelativeTop(List<Integer> relativeTop) {
this.relativeTop = relativeTop;
}
public List<Integer> getRelativeAny() {
return relativeAny;
}
public void setRelativeAny(List<Integer> relativeAny) {
this.relativeAny = relativeAny;
}
@Override
public void execute(HashMatrix<ProblemElement, ProblemElement, Valuation> decisionMatrix,
Map<ProblemElement, Double> criteriaWeights) {
numAlternatives = problemService.getAll(Alternative.Type).length;
numCriteria = problemService.getMainElements(Criterion.Type).length;
this.setCriteriaWeights(criteriaWeights);
this.normalizeDecisionMatrix(decisionMatrix);
this.computeFinalPreferences();
this.computeRanking();
this.computeMinimumAbsoluteChangeInCriteriaWeights();
this.computeMinimumRelativeChangeInCriteriaWeights();
this.computeAbsoluteTopCriticalCriterion();
this.computeAbsoluteAnyCriticalCriterion();
this.computeRelativeTopCriticalCriterion();
this.computeRelativeAnyCriticalCriterion();
}
protected abstract void normalizeDecisionMatrix(HashMatrix<ProblemElement, ProblemElement, Valuation> decisionMatrixAggregation);
private void computeFinalPreferences() {
alternativesRatioFinalPreferences = new Double[numAlternatives][numAlternatives];
for (int alt1 = 0; alt1 < numAlternatives - 1; alt1++) {
for (int alt2 = alt1 + 1; alt2 < numAlternatives; alt2++) {
alternativesRatioFinalPreferences[alt1][alt2] = 1d;
for (int cr = 0; cr < numCriteria; cr++) {
alternativesRatioFinalPreferences[alt1][alt2] *= Math.pow(
((Double) decisionMatrix[alt1][cr] / (Double) decisionMatrix[alt2][cr]),
criteriaWeights.get(problemService.getMainElements(Criterion.Type)[cr]));
}
}
}
}
private void computeRanking() {
ranking = new int[numAlternatives];
for (int i = 0; i < ranking.length; ++i)
ranking[i] = i + 1;
double ratio = 0;
for (int alt1 = 0; alt1 < numAlternatives - 1; ++alt1) {
for (int alt2 = alt1 + 1; alt2 < numAlternatives; ++alt2) {
ratio = alternativesRatioFinalPreferences[alt1][alt2];
if (ratio < 1) {
if (ranking[alt2] > ranking[alt1]) {
if (ranking[alt2] - 1 == ranking[alt1]) {
ranking[alt2] = ranking[alt1];
ranking[alt1] += 1;
} else {
ranking[alt2] = ranking[alt1];
incrementPosRanking(alt2);
}
}
}
}
}
}
private void incrementPosRanking(int alt2) {
int rank = ranking[alt2];
for (int alt = 0; alt < ranking.length; ++alt) {
if (ranking[alt] >= rank && ranking[alt] < ranking.length) {
if (alt != alt2)
ranking[alt] += 1;
}
}
}
/**
* Compute the minimum change in absolute terms to apply in criteria weights so that there is an exchange among any pair of alternatives
*/
private void computeMinimumAbsoluteChangeInCriteriaWeights() {
minimumAbsoluteChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria];
double numerator, denominator, total;
for (int i = 0; i < numAlternatives - 1; i++) {
for (int j = i + 1; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
numerator = Math.log(alternativesRatioFinalPreferences[i][j]);
if ((Double) decisionMatrix[j][k] == 0) {
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
} else {
denominator = Math.log((Double) decisionMatrix[i][k] / (Double) decisionMatrix[j][k]);
if (denominator != 0) {
total = numerator / denominator;
if (total > criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k])) {
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
} else {
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = total;
if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] > criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k]))
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
}
} else
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
}
}
}
}
}
/**
* Compute the minimum change in relative terms to apply in criteria weights so that there is an exchange among any pair of alternatives
*/
private void computeMinimumRelativeChangeInCriteriaWeights() {
minimumRelativeChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria];
Criterion cr;
for (int i = 0; i < numAlternatives - 1; i++) {
for (int j = i + 1; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
cr = (Criterion) problemService.getMainElements(Criterion.Type)[k];
if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] != NON_FEASIBLE) {
if (criteriaWeights.get(cr) == 0) {
minimumRelativeChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
} else {
minimumRelativeChangeInCriteriaWeights[i][j][k] = minimumAbsoluteChangeInCriteriaWeights[i][j][k] * (100d / criteriaWeights.get(cr));
}
} else
minimumRelativeChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
}
}
}
}
/**
* Look for the minimal change in absolute terms among the best alternative/s and the rest of them
*/
private void computeAbsoluteTopCriticalCriterion() {
List<Integer> bestAlternatives = getBestAlternatives();
absoluteTop = new LinkedList<Integer>();
Double minimum = Double.MAX_VALUE, change;
for (int i = 0; i < bestAlternatives.size(); i++) {
for (int j = 0; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
change = minimumAbsoluteChangeInCriteriaWeights[bestAlternatives.get(i)][j][k];
if (change != NON_FEASIBLE) {
change = Math.abs(change);
if (change < minimum) {
minimum = change;
absoluteTop.clear();
absoluteTop.add(Integer.valueOf(k));
} else if (change == minimum)
absoluteTop.add(Integer.valueOf(k));
}
}
}
}
}
/**
* Get the indexes of the best alternatives
* @return indexes of the best alternatives
*/
private List<Integer> getBestAlternatives() {
List<Integer> bestAlternatives = new LinkedList<Integer>();
for (int i = 0; i < numAlternatives; i++) {
if (ranking[i] == 0)
bestAlternatives.add(Integer.valueOf(i));
}
return bestAlternatives;
}
/**
* Look for the minimal change in absolute terms among all the alternatives
*/
private void computeAbsoluteAnyCriticalCriterion() {
absoluteAny = new LinkedList<Integer>();
Double minimum = Double.MAX_VALUE, change;
for (int i = 0; i < numAlternatives - 1; i++) {
for (int j = i + 1; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
change = minimumAbsoluteChangeInCriteriaWeights[i][j][k];
if (change != NON_FEASIBLE) {
change = Math.abs(change);
if (change < minimum) {
minimum = change;
absoluteAny.clear();
absoluteAny.add(Integer.valueOf(k));
} else if (change == minimum)
absoluteAny.add(Integer.valueOf(k));
}
}
}
}
}
/**
* Look for the minimal change in relative terms among the best alternative/s and the rest of them
*/
private void computeRelativeTopCriticalCriterion() {
List<Integer> bestAlternatives = getBestAlternatives();
relativeTop = new LinkedList<Integer>();
Double minimum = Double.MAX_VALUE, change;
for (int i = 0; i < bestAlternatives.size(); i++) {
for (int j = 0; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
change = minimumRelativeChangeInCriteriaWeights[bestAlternatives.get(i)][j][k];
if (change != NON_FEASIBLE) {
change = Math.abs(change);
if (change < minimum) {
minimum = change;
relativeTop.clear();
relativeTop.add(Integer.valueOf(k));
} else if (change == minimum)
relativeTop.add(Integer.valueOf(k));
}
}
}
}
}
/**
* Look for the minimal change in absolute terms among all the alternatives
*/
private void computeRelativeAnyCriticalCriterion() {
relativeAny = new LinkedList<Integer>();
Double minimum = Double.MAX_VALUE, change;
for (int i = 0; i < numAlternatives - 1; i++) {
for (int j = i + 1; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
change = minimumRelativeChangeInCriteriaWeights[i][j][k];
if (change != NON_FEASIBLE) {
change = Math.abs(change);
if (change < minimum) {
minimum = change;
relativeAny.clear();
relativeAny.add(Integer.valueOf(k));
} else if (change == minimum)
relativeAny.add(Integer.valueOf(k));
}
}
}
}
}
@Override
public Double[][][] getChanges(FieldsChanges typeOfChange) {
switch(typeOfChange) {
case absolute:
return minimumAbsoluteChangeInCriteriaWeights;
case relative:
return minimumRelativeChangeInCriteriaWeights;
default:
return null;
}
}
}
@@ -0,0 +1,50 @@
package flintstones.entity.sensitiveanalysismodel.wpm.mcc;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.HashMatrix;
import flintstones.valuation.fuzzy.FuzzyValuation;
public class WeightedProductModelMCCFuzzy extends WeightedProductModelMCC {
@Override
protected void normalizeDecisionMatrix(HashMatrix<ProblemElement, ProblemElement, Valuation> decisionMatrixAggregation) {
decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length];
int critPos = 0, altPos;
for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) {
altPos = 0;
for(ProblemElement alt: problemService.getAll(Alternative.Type)) {
decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB();
altPos++;
}
critPos++;
}
normalize();
}
private Double[][] normalize() {
double acum, noStandarizedValue;
for (int i = 0; i < numCriteria; ++i) {
acum = sumCriteria(i);
for (int j = 0; j < numAlternatives; ++j) {
noStandarizedValue = (Double) decisionMatrix[j][i];
decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d;
}
}
return decisionMatrix;
}
private double sumCriteria(int numCriterion) {
double value = 0;
for (int j = 0; j < numAlternatives; ++j) {
value += Math.pow((Double) decisionMatrix[j][numCriterion], 2);
}
return Math.sqrt(value);
}
}
@@ -0,0 +1,49 @@
package flintstones.entity.sensitiveanalysismodel.wpm.mcc;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.HashMatrix;
import flintstones.valuation.numeric.NumericValuation;
public class WeightedProductModelMCCNumeric extends WeightedProductModelMCC {
@Override
protected void normalizeDecisionMatrix(HashMatrix<ProblemElement, ProblemElement, Valuation> decisionMatrixAggregation) {
decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length];
int critPos = 0, altPos;
for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) {
altPos = 0;
for(ProblemElement alt: problemService.getAll(Alternative.Type)) {
decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue();
altPos++;
}
critPos++;
}
normalize();
}
private Double[][] normalize() {
double acum, noStandarizedValue;
for (int i = 0; i < numCriteria; ++i) {
acum = sumCriteria(i);
for (int j = 0; j < numAlternatives; ++j) {
noStandarizedValue = (Double) decisionMatrix[j][i];
decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d;
}
}
return decisionMatrix;
}
private double sumCriteria(int numCriterion) {
double value = 0;
for (int j = 0; j < numAlternatives; ++j) {
value += Math.pow((Double) decisionMatrix[j][numCriterion], 2);
}
return Math.sqrt(value);
}
}
@@ -0,0 +1,50 @@
package flintstones.entity.sensitiveanalysismodel.wpm.mcc;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.HashMatrix;
import flintstones.valuation.twoTuple.TwoTupleValuation;
public class WeightedProductModelMCCTwoTuple extends WeightedProductModelMCC {
@Override
protected void normalizeDecisionMatrix(HashMatrix<ProblemElement, ProblemElement, Valuation> decisionMatrixAggregation) {
decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length];
int critPos = 0, altPos;
for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) {
altPos = 0;
for(ProblemElement alt: problemService.getAll(Alternative.Type)) {
decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta();
altPos++;
}
critPos++;
}
normalize();
}
private Double[][] normalize() {
double acum, noStandarizedValue;
for (int i = 0; i < numCriteria; ++i) {
acum = sumCriteria(i);
for (int j = 0; j < numAlternatives; ++j) {
noStandarizedValue = (Double) decisionMatrix[j][i];
decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d;
}
}
return decisionMatrix;
}
private double sumCriteria(int numCriterion) {
double value = 0;
for (int j = 0; j < numAlternatives; ++j) {
value += Math.pow((Double) decisionMatrix[j][numCriterion], 2);
}
return Math.sqrt(value);
}
}