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.wsm.mcc</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Weighted Sum Model</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.entity.sensitiveanalysismodel.wsm.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>1779484362582</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,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Weighted Sum Model
Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.wsm.mcc;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.common.phase.sensitiveanalysis.mcc.wsm
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: flintstones.entity.sensitiveanalysismodel,
flintstones.model.problemelement.service,
flintstones.valuation.twoTuple,
flintstones.valuation.numeric.real,
javax.inject,
org.eclipse.e4.core.di.annotations,
flintstones.valuation.fuzzy
Export-Package: flintstones.entity.sensitiveanalysismodel.wsm.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.wsm"
implementation="flintstones.entity.sensitiveanalysismodel.wsm.mcc.WeightedSumModelMCCTwoTuple"
name="weighted sum model">
</model>
<model
implementation="flintstones.entity.sensitiveanalysismodel.wsm.mcc.WeightedSumModelMCCNumeric"
name="weighted sum model"
uid="flintstones.entity.sensitiveanalysismodel.mcc.wsm.numeric">
</model>
<model
implementation="flintstones.entity.sensitiveanalysismodel.wsm.mcc.WeightedSumModelMCCFuzzy"
name="weighted sum model"
uid="flintstones.entity.sensitiveanalysismodel.mcc.wsm.fuzzy">
</model>
</extension>
</plugin>
@@ -0,0 +1,325 @@
package flintstones.entity.sensitiveanalysismodel.wsm.mcc;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Optional;
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 WeightedSumModelMCC extends SensitiveAnalysisModel {
@Inject
@Optional
IProblemElementService problemService;
protected Double[] alternativesFinalPreferences;
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 WeightedSumModelMCC() {
}
public Map<ProblemElement, Double> getCriteriaWeights() {
return criteriaWeights;
}
public void setCriteriaWeights(Map<ProblemElement, Double> criteriaWeights) {
this.criteriaWeights = criteriaWeights;
}
public Double[] getAlternativesFinalPreferences() {
return alternativesFinalPreferences;
}
public void setAlternativesFinalPreferences(Double[] alternativesFinalPreferences) {
this.alternativesFinalPreferences = alternativesFinalPreferences;
}
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;
}
/**
* The most sensitive criterion is computed from the minimum changes in criteria weights.
*/
@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() {
alternativesFinalPreferences = new Double[numAlternatives];
for (int alternative = 0; alternative < numAlternatives; alternative++) {
alternativesFinalPreferences[alternative] = 0d;
for (int criterion = 0; criterion < numCriteria; criterion++) {
alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion]
* criteriaWeights.get(problemService.getMainElements(Criterion.Type)[criterion]);
}
}
}
private void computeRanking() {
ranking = IntStream.range(0, alternativesFinalPreferences.length).boxed()
.sorted((j, i) -> alternativesFinalPreferences[i].compareTo(alternativesFinalPreferences[j]))
.mapToInt(ele -> ele).toArray();
}
/**
* 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];
for (int i = 0; i < numAlternatives - 1; i++) {
for (int j = i + 1; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
if ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k] == 0)
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE;
else {
minimumAbsoluteChangeInCriteriaWeights[i][j][k] = (alternativesFinalPreferences[j]
- alternativesFinalPreferences[i])
/ ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k]);
if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] > criteriaWeights
.get(problemService.getMainElements(Criterion.Type)[k]))
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];
for (int i = 0; i < numAlternatives - 1; i++) {
for (int j = i + 1; j < numAlternatives; j++) {
for (int k = 0; k < numCriteria; k++) {
if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] != NON_FEASIBLE)
minimumRelativeChangeInCriteriaWeights[i][j][k] = minimumAbsoluteChangeInCriteriaWeights[i][j][k]
* (100d / criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k]));
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,51 @@
package flintstones.entity.sensitiveanalysismodel.wsm.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 WeightedSumModelMCCFuzzy extends WeightedSumModelMCC {
@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,51 @@
package flintstones.entity.sensitiveanalysismodel.wsm.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 WeightedSumModelMCCNumeric extends WeightedSumModelMCC {
@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,51 @@
package flintstones.entity.sensitiveanalysismodel.wsm.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 WeightedSumModelMCCTwoTuple extends WeightedSumModelMCC {
@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);
}
}