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.method.electre.phase.gathering</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Gathering</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.method.electre.phase.gathering</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>1779484362664</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,22 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Gathering
Bundle-SymbolicName: flintstones.method.electre.phase.gathering;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.electre.phase.gathering
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.e4.core.contexts,
javax.inject,
flintstones.model.valuation.service,
flintstones.model.domain.service,
flintstones.valuation,
flintstones.valuation.numeric,
flintstones.helper.ui,
flintstones.helper.data,
flintstones.helper.debug,
flintstones.entity.problemelement,
flintstones.model.problemelement.service,
flintstones.application.perspective.framework.ui,
flintstones.entity.method.phase,
flintstones.entity.valuation
Export-Package: flintstones.method.electre.phase.gathering
@@ -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.electre.phase.gathering"
implementation="flintstones.method.electre.phase.gathering.Electre3Method">
</phase>
</extension>
</plugin>
@@ -0,0 +1,314 @@
package flintstones.method.electre.phase.gathering;
import java.util.ArrayList;
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.helper.debug.DH;
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 Electre3Method extends PhaseMethod {
@Inject
IEclipseContext context;
@Inject
IValuationService valuationService;
@Inject
IDomainService domainService;
@Inject
IProblemElementService problemService;
// Atributos
HashMap<ProblemElementKey, Valuation> mapVAluations;
Alternative[] allAlternatives;
Criterion[] allCriterion;
Expert[] allexperts;
double alfa;
double beta;
// Datos para Electre
double[][] matrizDesempe; // Alternativas frente criterios
double[][] fuzzyRelation; // Alternativas frente alternativas
int[] ranking;
ArrayList<ParametersElectre> datosUmbralesPesos;
HashMatrix<Expert,Criterion,Double> hmWeights;
public Electre3Method() {
}
@Override
public String getName() {
return "Electre 3";
}
@SuppressWarnings("unchecked")
public void inicializar() {
DH.out("electre","Init Electre 3");
datosUmbralesPesos = new ArrayList<>();
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);
fuzzyRelation = new double[allAlternatives.length][allAlternatives.length];
hmWeights = (HashMatrix<Expert,Criterion,Double>) this.importData("criterionWeights");
}
public void executeMethod(Expert e) {
this.matrizDesempe = this.getValuations(e);
electrealgorithm();
//Exportamos los datos para la UI resultados.
this.exportData("fuzzyRelation", fuzzyRelation);
this.exportData("alternativas", allAlternatives);
}
public void addDatoEntrada(ParametersElectre pE) {
ParametersElectre.Direccion dir = ( pE.getCriterion().isCost()) ? ParametersElectre.Direccion.minimizar : ParametersElectre.Direccion.maximizar;
double weight = hmWeights.get(allexperts[0], pE.getCriterion());
ParametersElectre dE = new ParametersElectre(pE.getIndiferencia(), pE.getPreferencia(), dir, weight, pE.getUsarVeto(), pE.getVeto());
datosUmbralesPesos.add(dE);
}
public String[] getAlernativesNames() {
String[] names = new String[allAlternatives.length];
for (int i = 0; i < names.length; i++)
names[i] = allAlternatives[i].getCanonicalName();
return names;
}
public Alternative[] getAlternatives() {
ProblemElement[] pes = problemService.getAll(Alternative.Type);
return ProblemElementHelper.asAlternatives(pes);
}
public Criterion[] getCriterion() {
ProblemElement[] pes = problemService.getAll(Criterion.Type);
return ProblemElementHelper.asCriterions(pes);
}
public Expert[] getExperts() {
ProblemElement[] pes = problemService.getAll(Expert.Type);
return ProblemElementHelper.asExperts(pes);
}
public void reiniciarDatos() {
datosUmbralesPesos.clear();
}
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];
//Obtenemos el hashmap
ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName());
mapVAluations = valuationService.getAllValuationsKVWith(pE);
//Para cada elemento, introducirlo ordenado en el array
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().getCanonicalName().equals( allAlternatives[i].getCanonicalName() )) {
a = i;
break;
}
for(int i = 0; i < allCriterion.length; i++)
if(entry.getKey().getCriterion().getCanonicalName().equals( allCriterion[i].getCanonicalName() )) {
b = i;
break;
}
valuation[a][b] = Double.valueOf(nV.getValue());
a = 0;
b = 0;
}
return valuation;
}
public String[] getCriterionNames() {
String[] names = new String[allCriterion.length];
for (int i = 0; i < names.length; i++)
names[i] = allCriterion[i].getCanonicalName();
return names;
}
public void establecerAlfaBeta(double alfa, double beta) {
this.alfa = alfa;
this.beta = beta;
}
// --------------------------------------------------------------------
private void electrealgorithm() {
fuzzyRelation = new double[allAlternatives.length][allAlternatives.length];
for (int i = 0; i < allAlternatives.length; i++) {
for (int j = 0; j < allAlternatives.length; j++) {
if (j == i)
fuzzyRelation[i][j] = 1;
else
fuzzyRelation[i][j] = sigma(matrizDesempe[i], matrizDesempe[j], this.datosUmbralesPesos);
}
}
}
private double sigma(double[] A, double[] B, ArrayList<ParametersElectre> datosUmbralesPesos) {
double sig = 0;
double d = 0, discordancia, c = 0, concordancia = 0, valDis;
for (int k = 0; k < allCriterion.length; k++) {
if (datosUmbralesPesos.get(k).getDireccion() == ParametersElectre.Direccion.maximizar) {
if (B[k] <= (A[k] + datosUmbralesPesos.get(k).getIndiferencia())) { // aSb
c = 1;
} else {
if (B[k] > (A[k] + datosUmbralesPesos.get(k).getPreferencia())) {
c = 0;
} else {
if ((A[k] + datosUmbralesPesos.get(k).getIndiferencia()) < B[k] && B[k] <= (A[k] + datosUmbralesPesos.get(k).getPreferencia())) {
c = (datosUmbralesPesos.get(k).getPreferencia() - (B[k] - A[k]))
/ (datosUmbralesPesos.get(k).getPreferencia() - datosUmbralesPesos.get(k).getIndiferencia());
}
}
}
} else { // minimizar
if (((A[k] - B[k]) <= datosUmbralesPesos.get(k).getIndiferencia()) || (A[k] <= B[k])) { // aSb
c = 1;
} else {
if ((A[k] - B[k]) > datosUmbralesPesos.get(k).getPreferencia()) {
c = 0;
} else {
if (datosUmbralesPesos.get(k).getIndiferencia() < (A[k] - B[k]) && (A[k] - B[k]) <= datosUmbralesPesos.get(k).getPreferencia()) {
c = (datosUmbralesPesos.get(k).getPreferencia() - (A[k] - B[k]))
/ (datosUmbralesPesos.get(k).getPreferencia() - datosUmbralesPesos.get(k).getIndiferencia());
}
}
}
}
concordancia += c * datosUmbralesPesos.get(k).getPeso();
}
// discordancia
// -----------------------------
discordancia = 0;
for (int k = 0; k < allCriterion.length; k++) {
d = 0;
if (datosUmbralesPesos.get(k).getUsarVeto()) { // Va usar veto (v)
d = -1; // para problar si esta entrando a las condiciones
if (datosUmbralesPesos.get(k).getDireccion() == ParametersElectre.Direccion.maximizar) {
if ((B[k] - A[k]) <= datosUmbralesPesos.get(k).getPreferencia()) {
d = 0;
} else {
if (datosUmbralesPesos.get(k).getPreferencia() < (B[k] - A[k]) && (B[k] - A[k]) < datosUmbralesPesos.get(k).getVeto()) {
d = ((B[k] - A[k]) - datosUmbralesPesos.get(k).getPreferencia())
/ (datosUmbralesPesos.get(k).getVeto() - datosUmbralesPesos.get(k).getPreferencia());
} else {
if ((B[k] - A[k]) >= datosUmbralesPesos.get(k).getPreferencia()) {
d = 1;
}
}
}
} else { // minimizar
if ((A[k] - B[k]) <= datosUmbralesPesos.get(k).getPreferencia()) {
d = 0;
} else {
if (datosUmbralesPesos.get(k).getPreferencia() < (A[k] - B[k]) && (A[k] - B[k] < datosUmbralesPesos.get(k).getVeto())) {
d = (A[k] - datosUmbralesPesos.get(k).getPreferencia() - B[k])
/ (datosUmbralesPesos.get(k).getVeto() - datosUmbralesPesos.get(k).getPreferencia());
} else {
if (A[k] - B[k] >= datosUmbralesPesos.get(k).getVeto()) {
d = 1;
}
}
}
}
}
if (d == 1) {
valDis = 1;
discordancia = 1; // esto veta al resto de criterios
} else {
if (d > concordancia && discordancia != 1) {
valDis = (1 - d) / (1 - concordancia);
if (discordancia == 0)
discordancia = valDis;
else
discordancia *= valDis;
} else {
valDis = 0;
}
}
}
if (discordancia > 0) {
if (discordancia == 1)
sig = 0;
else
sig = concordancia * discordancia;
} else
sig = concordancia;
return sig;
}
}
@@ -0,0 +1,98 @@
package flintstones.method.electre.phase.gathering;
import flintstones.entity.problemelement.entities.Criterion;
public class ParametersElectre {
public enum Direccion {maximizar, minimizar}
double indiferencia;
double preferencia;
boolean usarVeto;
double veto; //Opcional
Direccion direccion;
double peso;
Criterion c;
public ParametersElectre(double indiferencia, double preferencia, Direccion direccion, double peso, boolean usarVeto, double veto){
this.indiferencia = indiferencia;
this.preferencia = preferencia;
this.direccion = direccion;
this.peso = peso;
this.usarVeto = usarVeto;
this.veto = veto;
}
public Criterion getCriterion() {
return c;
}
public void setCriterion(Criterion c) {
this.c = c;
}
public double getIndiferencia() {
return indiferencia;
}
public double getPreferencia() {
return preferencia;
}
public boolean getUsarVeto() {
return usarVeto;
}
public double getVeto() {
return veto;
}
public Direccion getDireccion() {
return direccion;
}
public double getPeso() {
return peso;
}
public void setIndiferencia(double value) {
indiferencia = value;
}
public void setPreferencia(double value) {
preferencia = value;
}
public void setUsarVeto(boolean value) {
usarVeto = value;
}
public void setVeto(double value) {
veto = value;
}
public void setDireccion(Direccion value) {
direccion = value;
}
public void setPeso(double value) {
peso = value;
}
@Override
public String toString() {
String str = "Datos: ";
str += "Q: " + indiferencia;
str += " | P: " + preferencia;
str += " | ¿Usar veto?: " + usarVeto;
str += " | V: " + veto;
str += " | Direccion: " + direccion;
str += " | Peso: " + peso;
return str;
}
}