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,11 @@
<?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">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<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.method.ahp.sort.fuzzy.ranking</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Bundle-Name</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.method.ahp.sort.fuzzy.ranking</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>1779484362624</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,10 @@
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.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,23 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: flintstones.method.ahp.sort.fuzzy.ranking;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.ahp.sort.fuzzy.ranking
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: flintstones.domain.fuzzyset,
flintstones.entity.method.phase,
flintstones.method.ahp.sortii.phase.ranking,
flintstones.model.ahpsort.profileassignment.service,
javax.inject,
flintstones.model.problemelement.service,
flintstones.entity.ahpsort.profileassignment,
flintstones.helper.data.wxml,
flintstones.valuation.proportionaltwotuple,
flintstones.helper.data,
flintstones.entity.valuation,
flintstones.operator,
org.eclipse.e4.core.contexts,
flintstones.entity.operator
Export-Package: flintstones.method.ahp.sort.fuzzy.ranking,
flintstones.method.ahp.sort.fuzzy.ranking.FuzzyClass
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.phasemethod.extensionpoint">
<phase
uid="flintstones.method.ahp.sort.fuzzy.ranking"
implementation="flintstones.method.ahp.sort.fuzzy.ranking.FuzzyAHPSortRanking">
</phase>
</extension>
</plugin>
@@ -0,0 +1,307 @@
package flintstones.method.ahp.sort.fuzzy.ranking;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import javax.inject.Inject;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
import flintstones.entity.domain.Domain;
import flintstones.entity.method.phase.PhaseMethod;
import flintstones.entity.operator.AggregationOperator;
import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.FakeProblemElement;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.problemelement.entities.SortingClass;
import flintstones.entity.problemelement.entities.SortingProfile;
import flintstones.entity.problemelement.entities.SortingProfile.SortingProfileType;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.LinkedHashMatrix;
import flintstones.helper.data.adapter.TableAdapter;
import flintstones.method.ahp.sort.fuzzy.ranking.FuzzyClass.FuzzyClass;
import flintstones.method.ahp.sortii.phase.ranking.AHPSortIIModelAgglomerative;
import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.operator.service.IOperatorService;
import flintstones.valuation.proportionaltwotuple.ProportionalTwoTuple;
public class FuzzyAHPSortRanking extends PhaseMethod {
@Inject
IProblemElementService problemService;
@Inject
IProfileAssignmentService profileService;
@Inject
IOperatorService operatorService;
AHPSortIIModelAgglomerative db;
Expert[] experts;
Alternative[] alternatives;
SortingClass[] sortingClasses;
public boolean triangular = true;
public boolean central = true;
LinkedHashMap<Expert, LinkedList<FuzzyClass>> expertClasses; // Expert, Classes
LinkedHashMap<Expert, LinkedHashMap<Alternative, ProportionalTwoTuple>> tuples;
LinkedHashMap<Expert, FuzzySet> domains;
LinkedHashMap<Expert, Double> alfaValues;
@Override
public String getName() {
return "FuzzyAHPSortRanking";
}
public void execute() {
db = (AHPSortIIModelAgglomerative) importData("model");
if (profileService.getType() == SortingProfileType.Limiting)
central = false;
ProblemElement[] aux = problemService.getAll(Expert.Type);
experts = new Expert[aux.length];
for (int i = 0; i < aux.length; i++) {
experts[i] = (Expert) aux[i];
}
aux = problemService.getAll(Alternative.Type);
alternatives = new Alternative[aux.length];
for (int i = 0; i < aux.length; i++) {
alternatives[i] = (Alternative) aux[i];
}
aux = problemService.getAll(SortingClass.Type);
sortingClasses = new SortingClass[aux.length];
for (int i = 0; i < aux.length; i++) {
sortingClasses[i] = (SortingClass) aux[i];
}
expertClasses = new LinkedHashMap<>();
tuples = new LinkedHashMap<>();
domains = new LinkedHashMap<>();
alfaValues = new LinkedHashMap<>();
for (Expert expert : experts) {
alfaValues.put(expert, 0.0);
}
createClassesFromProfiles();
assignAlternativesToClasses();
}
public void recalculate() {
createClassesFromProfiles();
assignAlternativesToClasses();
}
private void createClassesFromProfiles() {
LinkedHashMap<Expert, LinkedHashMap<SortingProfile, Double>> profileGlobalPriorities = db.getProfileGlobalPriorities();
ArrayList<Double> globalPriorities;
LinkedList<FuzzyClass> classes;
for (Expert expert : experts) {
globalPriorities = new ArrayList<Double>(profileGlobalPriorities.get(expert).values());
classes = new LinkedList<FuzzyClass>();
if (triangular) {
if (!central)
globalPriorities = limitingToCentralProfiles(globalPriorities);
for (int i = 0; i < globalPriorities.size(); i++) { // Triangular classes
if (i == 0) { // Class 1
// a = cp2, b = cp1, d = Max
classes.add(new FuzzyClass(globalPriorities.get(1), globalPriorities.get(0), Integer.MAX_VALUE, i, sortingClasses[i].getName()));
} else if (i == globalPriorities.size() - 1) { // Class n
classes.add(new FuzzyClass(Integer.MIN_VALUE, globalPriorities.get(i), globalPriorities.get(i - 1), Integer.MAX_VALUE,
sortingClasses[i].getName())); // a=min,
// b=cpn,
// d=cp(n-1)
} else {// Remaining classes
classes.add(new FuzzyClass(globalPriorities.get(i + 1), globalPriorities.get(i), globalPriorities.get(i - 1), i,
sortingClasses[i].getName())); // a=cp(i+1), b=cpi,
// d=cp(i-1)
}
}
} else {
Double[] supportValues = new Double[globalPriorities.size() + 1];
Double[] centralProfiles = new Double[globalPriorities.size() + 1];
centralProfiles[0] = (1 + globalPriorities.get(0)) / 2;
centralProfiles[globalPriorities.size()] = globalPriorities.get(globalPriorities.size() - 1) / 2;
for (int i = 1; i <= globalPriorities.size(); i++) { // Support Values
if (i != globalPriorities.size())
centralProfiles[i] = (globalPriorities.get(i) + globalPriorities.get(i - 1)) / 2;
supportValues[i] = globalPriorities.get(i - 1) - (centralProfiles[i] + alfaValues.get(expert));
}
System.out.println("Support:" + Arrays.toString(supportValues));
System.out.println("GlobalPriorities: " + globalPriorities);
System.out.println("CentralProfiles:" + Arrays.toString(centralProfiles));
for (int i = 0; i < centralProfiles.length; i++) { // Trapezoidal classes
if (i == 0) { // Class 1
classes.add(new FuzzyClass(globalPriorities.get(0) - supportValues[1], globalPriorities.get(0) + supportValues[1], Integer.MAX_VALUE,
Integer.MAX_VALUE, Double.NaN, supportValues[1], i, sortingClasses[i].getName()));
} else if (i == centralProfiles.length - 1) { // Class n
classes.add(new FuzzyClass(Integer.MIN_VALUE, Integer.MIN_VALUE, globalPriorities.get(i - 1) - supportValues[i],
globalPriorities.get(i - 1) + supportValues[i], supportValues[i], Double.NaN, Integer.MAX_VALUE, sortingClasses[i].getName()));
} else {// Remaining classes
classes.add(new FuzzyClass(globalPriorities.get(i) - supportValues[i + 1], globalPriorities.get(i) + supportValues[i + 1],
globalPriorities.get(i - 1) - supportValues[i], globalPriorities.get(i - 1) + supportValues[i], supportValues[i],
supportValues[i + 1], i, sortingClasses[i].getName()));
}
}
}
System.out.println(expert);
System.out.println(classes);
System.out.println();
expertClasses.put(expert, classes);
}
}
private void assignAlternativesToClasses() {
LinkedHashMap<Expert, LinkedHashMap<Alternative, Double>> alternativesGlobalPriorities = db.getAlternativeGlobalPriorities();
for (Expert expert : experts) {
LinkedHashMap<Alternative, Double> expertAlternatives = alternativesGlobalPriorities.get(expert);
LinkedList<FuzzyClass> classes = expertClasses.get(expert);
LinkedHashMap<Alternative, ProportionalTwoTuple> tupleList = new LinkedHashMap<Alternative, ProportionalTwoTuple>();
FuzzySet fuzzySet = new FuzzySet();
for (FuzzyClass fuzzyClass : classes) { // Creamos el fuzzySet añadiendo una etiqueta por fuzzyClass
LabelLinguisticDomain label = new LabelLinguisticDomain();
label.setName(fuzzyClass.getName());
label.setSemantic(fuzzyClass);
fuzzySet.addLabel(label);
}
domains.put(expert, fuzzySet);
for (Alternative alternative : this.alternatives) {
ProportionalTwoTuple tuple = new ProportionalTwoTuple(fuzzySet); // Creamos la tupla
boolean second = false;
FuzzyClass aux = null;
for (FuzzyClass fuzzyClass : classes) {
double membershipValue = fuzzyClass.getMembershipValue(expertAlternatives.get(alternative));
if (second) {
tuple.setBeta(membershipValue);
tuple.setTerm2(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1));
break;
} else if (membershipValue > 0) {
if (fuzzyClass.getClassNumber() == Integer.MAX_VALUE) {
tuple.setAlpha(aux.getMembershipValue(expertAlternatives.get(alternative)));
tuple.setTerm1(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1));
tuple.setBeta(membershipValue);
tuple.setTerm2(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1));
break;
} else {
tuple.setAlpha(membershipValue); // Asignamos el alfa al primer elemento con un valor de
// pertenencia mayor a 0
tuple.setTerm1(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1));
second = true; // Ponemos second a true para que el valor de pertenencia del siguiente
// elemento
// se asigne a beta.
}
}
aux = fuzzyClass;
}
tupleList.put(alternative, tuple);
}
tuples.put(expert, tupleList);
}
}
private ArrayList<Double> limitingToCentralProfiles(ArrayList<Double> globalPriorities) {
ArrayList<Double> centralProfiles = new ArrayList<>();
centralProfiles.add((1 + globalPriorities.get(0)) / 2);
for (int i = 1; i < globalPriorities.size(); i++) {
centralProfiles.add((globalPriorities.get(i) + globalPriorities.get(i - 1)) / 2);
}
centralProfiles.add(globalPriorities.get(globalPriorities.size() - 1) / 2);
return centralProfiles;
}
@SuppressWarnings("unchecked")
public TableAdapter getClassesGlobalTable(Expert expert) {
HashMap<SortingProfile, Double> data = (HashMap<SortingProfile, Double>) db.getProfileGlobalPriorities().get(expert).clone();
if (!central) {
SortingProfile fakeSortingProfile = new SortingProfile(expert, new Criterion(""), 0d);
fakeSortingProfile.setName(sortingClasses[sortingClasses.length - 1].getName() + " " + (sortingClasses.length - 1));
data.put(fakeSortingProfile, 0d);
}
TableAdapter adapter = new TableAdapter(data);
return adapter;
}
public TableAdapter getAlternativeGlobalTable(Expert expert) {
HashMap<Alternative, Double> data = db.getAlternativeGlobalPriorities().get(expert);
LinkedHashMap<Alternative, ProportionalTwoTuple> proportionalTwoTuples = tuples.get(expert);
LinkedHashMatrix<ProblemElement, FakeProblemElement, Object> tableMatrix = new LinkedHashMatrix<>();
FakeProblemElement f1 = new FakeProblemElement("Global priority");
FakeProblemElement f2 = new FakeProblemElement("Proportional 2-tuple");
for (Entry<Alternative, Double> entry : data.entrySet())
tableMatrix.put(entry.getKey(), f1, entry.getValue());
if (proportionalTwoTuples != null)
for (Entry<Alternative, ProportionalTwoTuple> entry : proportionalTwoTuples.entrySet())
tableMatrix.put(entry.getKey(), f2, entry.getValue());
TableAdapter adapter = new TableAdapter(tableMatrix);
return adapter;
}
public TableAdapter getAggregatedTable(AggregationOperator operator) {
LinkedHashMatrix<ProblemElement, FakeProblemElement, Object> tableMatrix = new LinkedHashMatrix<>();
FakeProblemElement f2 = new FakeProblemElement("Aggregated Proportional Two Tuple");
HashMap<Alternative, ProportionalTwoTuple> result = new HashMap<>();
for (Alternative alternative : alternatives) {
LinkedList<Valuation> tuplesList = new LinkedList<Valuation>();
for (Expert expert : experts) {
tuplesList.add((Valuation) tuples.get(expert).get(alternative));
}
result.put(alternative, (ProportionalTwoTuple) operator.computeAggregation(tuplesList, null));
}
for (Entry<Alternative, ProportionalTwoTuple> entry : result.entrySet())
tableMatrix.put(entry.getKey(), f2, entry.getValue());
TableAdapter adapter = new TableAdapter(tableMatrix);
return adapter;
}
public void setAlfaValue(Expert expert, Double value) {
alfaValues.put(expert, value);
}
public double getAlfaValue(Expert expert) {
return alfaValues.get(expert);
}
public Domain getDomain(Expert expert) {
return domains.get(expert);
}
public double getMaxPriorityValue(Expert expert) {
return expertClasses.get(expert).getFirst().getB();
}
}
@@ -0,0 +1,119 @@
package flintstones.method.ahp.sort.fuzzy.ranking.FuzzyClass;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
public class FuzzyClass extends TrapezoidalFunction {
private int classNumber = 0;
private String className = null;
private double support1 = 0, support2 = 0;
// Si b=c -> triangular
public FuzzyClass(double a, double b, double d, int classNumber) {
super(a, b, b, d);
this.classNumber = classNumber;
}
public FuzzyClass(double a, double b, double d, int classNumber, String className) {
super(a, b, b, d);
this.classNumber = classNumber;
this.className = className;
}
public FuzzyClass(double a, double b, double c, double d, double support1, double support2, int classNumber, String className) {
super(a, b, c, d);
this.classNumber = classNumber;
this.className = className;
this.support1 = support1;
this.support2 = support2;
}
@Override
public double getMembershipValue(double x) {
if (this._b == this._c) {
if (classNumber == 0) { // Class 1
if (x < this._a) {
return 0;
} else if (this._a <= x && x < this._b) {
return (x - _a) / (_b - _a);
} else if (this._b <= x) {
return 1;
}
} else if (classNumber == Integer.MAX_VALUE) { // Class n
if (this._d < x) {
return 0;
} else if (this._b < x && x <= this._d) {
return (_d - x) / (_d - _b);
} else if (x <= this._b) {
return 1;
}
} else { // Remaining classes
if (this._d < x || x < this._a) {
return 0;
} else if (this._a <= x && x < this._b) {
return (x - _a) / (_b - _a);
} else if (this._b < x && x <= this._d) {
return (_d - x) / (_d - _b);
} else if (x == this._b) {
return 1;
}
}
} else {
if (classNumber == 0) { // Class 1
if (x < this._a) {
return 0;
} else if (this._a <= x && x < this._b) {
return (x - _a) / (2 * support2);
} else if (this._b <= x) {
return 1;
}
} else if (classNumber == Integer.MAX_VALUE) { // Class n
if (this._d < x) {
return 0;
} else if (this._c < x && x <= this._d) {
return (_c - x) / (2 * support1);
} else if (x <= this._c) {
return 1;
}
} else { // Remaining classes
if (this._d < x || x < this._a) {
return 0;
} else if (this._a <= x && x < this._b) {
return (x - _a) / (2 * support2);
} else if (this._c < x && x <= this._d) {
return (_d - x) / (2 * support1);
} else if (this._b <= x && x <= this._c) {
return 1;
}
}
}
return Double.NaN;
}
public int getClassNumber() {
return classNumber;
}
public String getClassName() {
if (className != null) {
return "Class " + className;
} else {
if (classNumber == Integer.MAX_VALUE)
return "Class n";
return "Class " + classNumber;
}
}
public String getName() {
return className;
}
public String toString() {
if (className != null)
return "Class " + className + " - " + this._a + " - " + this._b + " - " + this._c + " - " + this._d;
if (classNumber == Integer.MAX_VALUE)
return "Class n" + " - " + this._a + " - " + this._b + " - " + this._c + " - " + this._d;
return "Class " + classNumber + " - " + this._a + " - " + this._b + " - " + this._c + " - " + this._d;
}
}