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,17 @@
<?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.linguistic.topsis.phase.collective</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Collective phase</name>
<organization>
<name>Sinbad2</name>
</organization>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.method.linguistic.topsis.phase.collective</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>1779484362681</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,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Collective phase
Bundle-SymbolicName: flintstones.method.linguistic.topsis.phase.collective;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Sinbad2
Automatic-Module-Name: flintstones.method.linguistic.topsis.phase.collective
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.entity.method.phase,
flintstones.entity.problemelement,
flintstones.entity.valuation,
flintstones.model.problemelement.service,
flintstones.valuation.twoTuple,
flintstones.model.domain.service,
org.eclipse.e4.core.services,
javax.inject,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di,
flintstones.operator.unification
Export-Package: flintstones.method.linguistic.topsis.phase.collective
@@ -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
implementation="flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo"
uid="flintstones.method.linguistic.topsis.phase.collective">
</phase>
</extension>
</plugin>
@@ -0,0 +1,396 @@
package flintstones.method.linguistic.topsis.phase.collective;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.nls.Translation;
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.problemelement.entities.Alternative;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.method.linguistic.topsis.phase.collective.messages.Messages;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.valuation.twoTuple.TwoTupleValuation;
public class CollectiveInfo extends PhaseMethod {
private FuzzySet domainWeights;
private FuzzySet valuationDomain;
private FuzzySet distanceDomain;
private Map<Expert, Valuation[]> closenessCoefficientsExperts = new HashMap<Expert, Valuation[]>();
private Map<Domain, LabelLinguisticDomain[]> weights = new HashMap<Domain, LabelLinguisticDomain[]>();
private Valuation[][] decisionMatrix;
private Valuation[][] distancesPositiveIdealSolution;
private Valuation[][] distancesNegativeIdealSolution;
private Valuation[] positiveIdealSolution;
private Valuation[] negativeIdealSolution;
private Valuation[] globalDistancesPositiveIdealSolution;
private Valuation[] globalDistancesNegativeIdealSolution;
private Valuation[] closenessCoefficients;
@Inject
IEclipseContext context;
@Inject
@Translation
private Messages messages;
@Inject
private IProblemElementService problemService;
@Inject
private IDomainService domainService;
@Override
public String getName() {
return messages.Phase_Name;
}
public ProblemElement[] getExperts() {
return problemService.getAll(Expert.Type);
}
public int getNumberExperts() {
return getExperts().length;
}
public String getExpertName(int pos) {
return getExperts()[pos].getName();
}
public int getNumberAlternatives() {
return getAlternatives().length;
}
public ProblemElement[] getAlternatives() {
return problemService.getAll(Alternative.Type);
}
public String getAlternativeName(int pos) {
return getAlternatives()[pos].getName();
}
public String[] getLinguisticDomainNames() {
ArrayList<String> names = new ArrayList<String>();
Domain[] domains = domainService.getAll();
for(Domain domain: domains) {
if(domain instanceof FuzzySet)
names.add(domain.getName());
}
return names.toArray(new String[0]);
}
public String[] getLinguisticLabelsNameDomain() {
String[] labels = new String[domainWeights.getLabelSet().getCardinality()];
for(int i = 0; i < labels.length; ++i)
labels[i] = domainWeights.getLabelSet().getLabel(i).getName();
return labels;
}
public void setDomainWeights(String domainName) {
this.domainWeights = (FuzzySet) domainService.getByName(domainName);
if(weights.get(domainWeights) == null)
initializeWeights();
}
public void initializeWeights() {
LabelLinguisticDomain[] weights = new LabelLinguisticDomain[getNumberExperts()];
LabelLinguisticDomain maxLabel = domainWeights.getLabelSet().getLabel(domainWeights.getLabelSet().getCardinality() - 1);
for(int i = 0; i < weights.length; ++i)
weights[i] = maxLabel;
this.weights.put(domainWeights, weights);
}
public void execute() {
setValuationDomain();
setDistanceDomain();
setClosenessCoefficientExperts();
buildCollectiveDecisionMatrix();
computeSolutions();
computeDistanceSolutions();
computeGlobalDistancesIdealSolutions();
computeClosenessCoefficients();
}
private void setValuationDomain() {
this.valuationDomain = (FuzzySet) importData("valuationDomain");
}
private void setDistanceDomain() {
this.distanceDomain = (FuzzySet) importData("distanceDomain");
}
@SuppressWarnings("unchecked")
private void setClosenessCoefficientExperts() {
this.closenessCoefficientsExperts = (Map<Expert, Valuation[]>) importData("coefficients");
}
private void buildCollectiveDecisionMatrix() {
decisionMatrix = new Valuation[getNumberAlternatives()][getNumberExperts()];
ProblemElement[] experts = getExperts();
LabelLinguisticDomain maxLabel = domainWeights.getLabelSet().getLabel(domainWeights.getLabelSet().getCardinality() - 1);
TwoTupleValuation maxLabelTwoTuple = new TwoTupleValuation(domainWeights, maxLabel);
Valuation[] coefficients;
TwoTupleValuation coef, weight, weightedValuation;
for(int i = 0; i < closenessCoefficientsExperts.size(); ++i) {
coefficients = closenessCoefficientsExperts.get(experts[i]);
weight = new TwoTupleValuation(domainWeights, weights.get(domainWeights)[i]);
for(int j = 0; j < coefficients.length; ++j) {
coef = (TwoTupleValuation) coefficients[j];
weightedValuation = new TwoTupleValuation(distanceDomain);
weightedValuation.calculateDelta(coef.calculateInverseDelta() * (weight.calculateInverseDelta() / maxLabelTwoTuple.calculateInverseDelta()));
decisionMatrix[j][i] = weightedValuation;
}
}
}
private void computeSolutions() {
computePositiveIdealSolution();
computeNegativeIdealSolution();
}
private void computePositiveIdealSolution() {
positiveIdealSolution = new Valuation[getNumberExperts()];
List<Valuation> valuationsExpert;
for (int exp = 0; exp < getNumberExperts(); ++exp) {
valuationsExpert = getValuationsExpert(exp);
Collections.sort(valuationsExpert);
positiveIdealSolution[exp] = valuationsExpert.get(valuationsExpert.size() - 1);
}
}
private List<Valuation> getValuationsExpert(int exp) {
List<Valuation> valuations = new ArrayList<>();
for(int alt = 0; alt < getNumberAlternatives(); ++alt)
valuations.add(decisionMatrix[alt][exp]);
return valuations;
}
private void computeNegativeIdealSolution() {
negativeIdealSolution = new Valuation[getNumberExperts()];
List<Valuation> valuationsExpert;
for (int exp = 0; exp < getNumberExperts(); ++exp) {
valuationsExpert = getValuationsExpert(exp);
Collections.sort(valuationsExpert);
negativeIdealSolution[exp] = valuationsExpert.get(0);
}
}
private void computeDistanceSolutions() {
computeDistanceIdealPositiveSolution();
computeDistanceIdealNegativeSolution();
}
private void computeDistanceIdealPositiveSolution() {
distancesPositiveIdealSolution = new Valuation[getNumberAlternatives()][getNumberExperts()];
TwoTupleValuation distance;
double dist;
for(int i = 0; i < decisionMatrix.length; ++i) {
for(int j = 0; j < decisionMatrix[i].length; ++j) {
dist = computeDistanceTwoTuple(decisionMatrix[i][j], positiveIdealSolution[j]);
distance = new TwoTupleValuation(distanceDomain);
distance.calculateDelta(dist);
distancesPositiveIdealSolution[i][j] = distance;
}
}
}
private Float computeDistanceTwoTuple(Valuation valuation1, Valuation valuation2) {
return (float) Math.abs(((TwoTupleValuation) valuation1).calculateInverseDelta() - ((TwoTupleValuation) valuation2).calculateInverseDelta());
}
private void computeDistanceIdealNegativeSolution() {
distancesNegativeIdealSolution = new Valuation[getNumberAlternatives()][getNumberExperts()];
TwoTupleValuation distance;
double dist;
for(int i = 0; i < decisionMatrix.length; ++i) {
for(int j = 0; j < decisionMatrix[i].length; ++j) {
dist = computeDistanceTwoTuple(decisionMatrix[i][j], negativeIdealSolution[j]);
distance = new TwoTupleValuation(distanceDomain);
distance.calculateDelta(dist);
distancesNegativeIdealSolution[i][j] = distance;
}
}
}
private void computeGlobalDistancesIdealSolutions() {
computeGlobalPositiveIdealSolutionDistances();
computeGlobalNegativeIdealSolutionDistances();
}
private void computeGlobalPositiveIdealSolutionDistances() {
globalDistancesPositiveIdealSolution = new Valuation[getNumberAlternatives()];
TwoTupleValuation distance;
double acum;
for(int i = 0; i < distancesPositiveIdealSolution.length; ++i) {
acum = 0;
for(int j = 0; j < distancesPositiveIdealSolution[i].length; ++j)
acum += ((TwoTupleValuation) distancesPositiveIdealSolution[i][j]).calculateInverseDelta();
distance = new TwoTupleValuation(distanceDomain);
distance.calculateDelta(acum /distancesPositiveIdealSolution[i].length);
globalDistancesPositiveIdealSolution[i] = distance;
}
}
private void computeGlobalNegativeIdealSolutionDistances() {
globalDistancesNegativeIdealSolution = new Valuation[getNumberAlternatives()];
TwoTupleValuation distance;
double acum;
for(int i = 0; i < distancesNegativeIdealSolution.length; ++i) {
acum = 0;
for(int j = 0; j < distancesNegativeIdealSolution[i].length; ++j)
acum += ((TwoTupleValuation) distancesNegativeIdealSolution[i][j]).calculateInverseDelta();
distance = new TwoTupleValuation(distanceDomain);
distance.calculateDelta(acum / distancesNegativeIdealSolution[i].length);
globalDistancesNegativeIdealSolution[i] = distance;
}
}
private void computeClosenessCoefficients() {
closenessCoefficients = new Valuation[getNumberAlternatives()];
TwoTupleValuation closeness;
double posDist, negDist, coeff;
for(int i = 0; i < globalDistancesPositiveIdealSolution.length; ++i) {
posDist = ((TwoTupleValuation) globalDistancesPositiveIdealSolution[i]).calculateInverseDelta();
negDist = ((TwoTupleValuation) globalDistancesNegativeIdealSolution[i]).calculateInverseDelta();
coeff = (distanceDomain.getLabelSet().getCardinality() - 1) * (negDist / (posDist + negDist));
closeness = new TwoTupleValuation(distanceDomain);
closeness.calculateDelta(coeff);
closenessCoefficients[i] = closeness;
}
}
public void setExpertWeight(int posExpert, String labelName) {
weights.get(domainWeights)[posExpert] = domainWeights.getLabelSet().getLabel(labelName);
}
public boolean distanceDomainChanged() {
FuzzySet oldDomain = (FuzzySet) this.distanceDomain.clone();
setDistanceDomain();
return (!oldDomain.equals(this.distanceDomain)) ? true:false;
}
public boolean valuationDomainChanged() {
FuzzySet oldDomain = (FuzzySet) this.valuationDomain.clone();
setValuationDomain();
return (!oldDomain.equals(this.valuationDomain)) ? true:false;
}
public String getStringExpertWeight(int posExpert) {
return weights.get(domainWeights)[posExpert].getName();
}
public String getStringDecisionMatrixValuation(int posExp, int posAlt) {
TwoTupleValuation v = (TwoTupleValuation) decisionMatrix[posAlt][posExp];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringPositiveIdealSolutionExpert(int posExp) {
TwoTupleValuation v = (TwoTupleValuation) positiveIdealSolution[posExp];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringNegativeIdealSolutionExpert(int posExp) {
TwoTupleValuation v = (TwoTupleValuation) negativeIdealSolution[posExp];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringCollectiveDistancePositiveIdealSolutionValuation(int posExpert, int posAlt) {
TwoTupleValuation v = (TwoTupleValuation) distancesPositiveIdealSolution[posAlt][posExpert];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringCollectiveDistanceNegativeIdealSolutionValuation(int posExpert, int posAlt) {
TwoTupleValuation v = (TwoTupleValuation) distancesNegativeIdealSolution[posAlt][posExpert];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringCollectiveGlobalDistancePositiveIdealSolutionValuation(int posAlt) {
TwoTupleValuation v = (TwoTupleValuation) globalDistancesPositiveIdealSolution[posAlt];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringCollectiveGlobalDistanceNegativeIdealSolutionValuation(int posAlt) {
TwoTupleValuation v = (TwoTupleValuation) globalDistancesNegativeIdealSolution[posAlt];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringCollectiveClosenessCoefficient(int posAlt) {
TwoTupleValuation v = (TwoTupleValuation) closenessCoefficients[posAlt];
return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")";
}
public String getStringRankingPositionAlternative(int posAlt) {
double[] values = new double[closenessCoefficients.length];
for(int i = 0; i < values.length; ++i)
values[i] = ((TwoTupleValuation) closenessCoefficients[i]).calculateInverseDelta();
return Integer.toString(findRank(values)[posAlt] + 1);
}
private int[] findRank(double[] inp) {
int[] outp = new int[inp.length];
for(int i = 0; i < inp.length; i++) {
for(int k = 0; k < inp.length; k++) {
if(inp[k] > inp[i]) outp[i]++;
}
}
return outp;
}
}
@@ -0,0 +1,10 @@
package flintstones.method.linguistic.topsis.phase.collective.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
public class Messages {
public String Phase_Name;
}