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.promethee.phase.result</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Result</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.method.promethee.phase.result</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>1779484362693</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: Result
Bundle-SymbolicName: flintstones.method.promethee.phase.result;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.promethee.phase.result
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.entity.method.phase,
flintstones.entity.problemelement,
javax.inject,
flintstones.model.problemelement.service,
flintstones.entity.valuation,
flintstones.model.valuation.service,
flintstones.valuation.numeric
Export-Package: flintstones.method.promethee.phase.result
@@ -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.promethee.phase.result"
implementation="flintstones.method.promethee.phase.result.PrometheeResult">
</phase>
</extension>
</plugin>
@@ -0,0 +1,178 @@
package flintstones.method.promethee.phase.result;
import java.util.ArrayList;
/**
* @author Alex
*/
public class Promethee {
//----------------- DATOS INICIALES DEL PROBLEMA ----------------------
float[][] initMatrix;
int[] MinMax; //0 --> Min || 1 --> Max
float[] weights;
int[] typeFunc;
String[] alternatives;
String[] criteria;
//--------------------- VARIABLES INTERNAS ----------------------------
ArrayList<float[][]> preferencesDegrees;
ArrayList<float[][]> flowMatrix;
float[][] globalFlowMatrix;
float[] p;
float[] q;
float[] s;
public Promethee(String[] alternatives, String[] criterions) {
this.alternatives = alternatives;
this.criteria = criterions;
}
//-------------------- GETTERS AND SETTERS ---------------------------
public float[][] getMAtrixFlow(int indexCriterion){
return flowMatrix.get(indexCriterion);
}
public float[][] getGlobalFLow(){
return globalFlowMatrix;
}
//-------------------- PROMETHEE FUNCTIONS ---------------------------
public void init() {
preferencesDegrees = new ArrayList<float[][]>();
flowMatrix = new ArrayList<float[][]>();
globalFlowMatrix = new float[alternatives.length][3];
//Inicializamos el vector de matrices para cada criterio enfrentando alternativas con alternativas.
for (int i = 0; i < criteria.length; ++i) {
preferencesDegrees.add(new float[alternatives.length][alternatives.length]);
flowMatrix.add(new float[alternatives.length][3]);
}
}
public void Execute(float[][] initMatrix, float[] weights, int[] MinMax, int[] typeFunc, float[] p, float[] q, float[] s) {
//Iniciamos los valores
this.initMatrix = initMatrix;
this.weights = weights;
this.MinMax = MinMax;
this.typeFunc = typeFunc;
this.p = p;
this.q = q;
this.s = s;
init();
//Calculamos las matrices.
calculatePreferences();
//Calculamos el flujo
calculateFlow();
//Calculamos el flujo global según sus pesos.
calculateGlobalsFlow();
}
//Calcula las matrices de preferencia según la función especificada.
private void calculatePreferences() {
float d = 0.0f;
//Nos recorremos los criteros para calcular cada matriz
for (int iCriterion = 0; iCriterion < criteria.length; iCriterion++) {
//Enfrentamos las alternativas según el criterio (iCriterion) que estamos calculando.
for (int iAlternative = 0; iAlternative < alternatives.length; iAlternative++) {
for (int jAlternative = 0; jAlternative < alternatives.length; jAlternative++) {
if (iAlternative != jAlternative) {
//Comprobamos si es de beneficio o de coste.
d = (MinMax[iCriterion] == 0)
? -(initMatrix[iAlternative][iCriterion] - initMatrix[jAlternative][iCriterion])
: (initMatrix[iAlternative][iCriterion] - initMatrix[jAlternative][iCriterion]);
preferencesDegrees.get(iCriterion)[iAlternative][jAlternative] = getResultFunction(d, iCriterion);
} else {
preferencesDegrees.get(iCriterion)[iAlternative][jAlternative] = 0.0f;
}
}
}
}
}
//Calculamos el flujo positivo y negativo de cada matriz según sus criterios.
private void calculateFlow() {
float positive = 0, negative = 0;
for (int i = 0; i < preferencesDegrees.size(); i++) {
//Caculamos el flujo positivo, negativo y neto.
for (int iAlt = 0; iAlt < alternatives.length; iAlt++) {
for (int jAlternative = 0; jAlternative < alternatives.length; jAlternative++) {
positive += preferencesDegrees.get(i)[iAlt][jAlternative];
negative += preferencesDegrees.get(i)[jAlternative][iAlt];
}
flowMatrix.get(i)[iAlt][0] = positive / (alternatives.length - 1);
flowMatrix.get(i)[iAlt][1] = negative / (alternatives.length - 1);
flowMatrix.get(i)[iAlt][2] = flowMatrix.get(i)[iAlt][0] - flowMatrix.get(i)[iAlt][1];
positive = 0;
negative = 0;
}
}
}
//Calculamos el flujo positivo y negativo de cada matriz según sus criterios.
private void calculateGlobalsFlow() {
float positive = 0, negative = 0;
//Caculamos el flujo global positivo, negativo y neto.
for (int iAlt = 0; iAlt < alternatives.length; iAlt++) {
for (int j = 0; j < flowMatrix.size(); j++) {
positive += flowMatrix.get(j)[iAlt][0] * weights[j];
negative += flowMatrix.get(j)[iAlt][1] * weights[j];
}
globalFlowMatrix[iAlt][0] = positive;
globalFlowMatrix[iAlt][1] = negative;
globalFlowMatrix[iAlt][2] = positive - negative;
positive = 0;
negative = 0;
}
}
//Según la función especificada, te devuelve el valor P(d) correspondiente
private float getResultFunction(float d, int iCriterion) {
switch (typeFunc[iCriterion]) {
case 1:
if(d > 0 ) return 1;
else return 0;
case 2:
if(d > q[iCriterion] ) return 1;
else return 0;
case 3:
if(d > p[iCriterion] ) return 1;
else if (d <= 0) return 0;
else return d / p[iCriterion];
case 4:
if(d > p[iCriterion] ) return 1;
else if (d <= q[iCriterion]) return 0;
else return 1/2;
case 5:
if (d <= q[iCriterion]) {
return 0.0f;
} else if (d > p[iCriterion]) {
return 1.0f;
} else {
return ((d - q[iCriterion]) / (p[iCriterion] - q[iCriterion]));
}
case 6:
if(d <= 0 ) return 0;
else {
float exponentialFunc = (float) java.lang.Math.exp((-1) * (Math.pow(d, 2) / (2 * Math.pow(s[iCriterion], 2))));
return 1 - exponentialFunc;
}
}
return -1;
}
}
@@ -0,0 +1,148 @@
package flintstones.method.promethee.phase.result;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.inject.Inject;
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.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
import flintstones.valuation.numeric.NumericValuation;
public class PrometheeResult extends PhaseMethod {
@Inject
IProblemElementService problemService;
@Inject
IValuationService valuationService;
// Atributos
HashMap<ProblemElementKey, Valuation> mapVAluations;
Alternative[] allAlternatives;
Criterion[] allCriterion;
Expert[] Allexperts;
String[] rowHeaderPromethee;
Promethee promethee;
float[] weights;
float[][] values;
int[] MinMax;
public PrometheeResult() {
}
@Override
public String getName() {
return "Phase Promethee Result";
}
//------------------------------- GETS AND SETTERS ---------------------------------
public void cargarDatos() {
rowHeaderPromethee = new String[3];
rowHeaderPromethee[0] = "Positive Flow";
rowHeaderPromethee[1] = "Negative Flow";
rowHeaderPromethee[2] = "Neto Flow";
allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type));
allCriterion = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type));
Allexperts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type));
promethee = new Promethee(getAlternativesNames(), getCriterionNames());
values = this.getValuations(Allexperts[0]);
float[] p = (float[]) this.importData("arrayP");
float[] q = (float[]) this.importData("arrayQ");
float[] s = (float[]) this.importData("arrayS");
float[] w = (float[]) this.importData("arrayWeights");
int[] MinMax = (int[]) this.importData("arrayMinMax");
int[] typeFunc = (int[]) this.importData("arrayTypeFunc");
this.promethee.Execute(this.values, w, MinMax, typeFunc, p, q, s);
}
public float[][] getValuations(Expert e) {
String[] alternatives = getAlternativesNames();
String[] criterions = getCriterionNames();
float[][] valuation = new float[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().getName().equals( alternatives[i] )) {
a = i;
break;
}
}
for(int i = 0; i < allCriterion.length; i++) {
if(entry.getKey().getCriterion().getName().equals( criterions[i])) {
b = i;
break;
}
}
double number = Double.valueOf(nV.getValue());
valuation[a][b] = (float) number;
a = 0;
b = 0;
}
return valuation;
}
public float[][] getResult() {
return promethee.getGlobalFLow();
}
public float[][] getCriterionMatrixFlow(int indexCriterion){
return promethee.getMAtrixFlow(indexCriterion);
}
public void executePromethee() {
}
public String[] getRowHeaderPromethee() {
return rowHeaderPromethee;
}
public String[] getAlternativesNames() {
String[] str = new String[allAlternatives.length];
for(int i = 0; i < allAlternatives.length; i++)
str[i] = allAlternatives[i].getName();
return str;
}
public String[] getCriterionNames() {
String[] str = new String[allCriterion.length];
for(int i = 0; i < allCriterion.length; i++) {
str[i] = allCriterion[i].getName();
}
return str;
}
public int numberCriterions() {
return allCriterion.length;
}
}