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.decision.common.phase.selection</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Selection</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.method.decision.common.phase.selection</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>1779484362660</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,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Selection
Bundle-SymbolicName: flintstones.method.decision.common.phase.selection;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.decision.common.phase.selection
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: flintstones.entity.problemelement,
flintstones.entity.valuation,
flintstones.model.valuation.service,
flintstones.valuation.twoTuple,
flintstones.domain.fuzzyset,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di,
flintstones.operator,
javax.inject,
flintstones.operator.aggregation.min,
flintstones.operator.aggregation.max,
flintstones.model.problemelement.service,
flintstones.model.domain.service,
flintstones.entity.domain,
flintstones.entity.method.phase,
flintstones.method.common.model.retranslation,
flintstones.entity.operator
Export-Package: flintstones.method.decision.common.phase.selection,
flintstones.method.decision.common.phase.selection.interfaces
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.phasemethod.extensionpoint">
<phase
uid="flintstones.method.decision.common.phase.selection.CalculateWeights"
implementation="flintstones.method.decision.common.phase.selection.CalculateWeightsSelectionModel">
</phase>
<phase
uid="flintstones.method.decision.common.phase.selection.CalculateDistances"
implementation="flintstones.method.decision.common.phase.selection.CalculateDistancesSelectionModel">
</phase>
<phase
uid="flintstones.method.decision.common.phase.selection.CalculateSolutions"
implementation="flintstones.method.decision.common.phase.selection.CalculateSolutionsSelectionModel">
</phase>
</extension>
</plugin>
@@ -0,0 +1,239 @@
package flintstones.method.decision.common.phase.selection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.entity.domain.Domain;
import flintstones.entity.method.phase.PhaseMethod;
import flintstones.entity.problemelement.entities.Alternative;
//import flintstones.entity.problemelement.entities.Alternative;
import flintstones.entity.valuation.Valuation;
import flintstones.method.common.model.retranslation.RetranslationModel;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.valuation.twoTuple.TwoTupleValuation;
@SuppressWarnings({ "unchecked", "javadoc" })
public class CalculateDistancesSelectionModel extends PhaseMethod {
@Inject
IDomainService domainService;
@Inject
IProblemElementService problemService;
private RetranslationModel retranslationModel;
private FuzzySet _distanceDomain;
private FuzzySet _similarityDomain;
private List<TwoTupleValuation> _idealDistance = new ArrayList<>();
private List<TwoTupleValuation> _noIdealDistance = new ArrayList<>();
private Map<Alternative, Valuation> _closenessCoefficient;
// Cache
private Valuation[][] _decisionMatrix;
private TwoTupleValuation[] _criteriaWeights;
@Override
public String getName() {
return "Calculate Distances";
}
@Inject
IEclipseContext context;
public Valuation[][] getDecisionMatrix() {
return (Valuation[][]) importData("decisionMatrix");
}
public FuzzySet getUnifiedDomain() {
return (FuzzySet) importData("unifiedDomain");
}
public TwoTupleValuation[] getCriteriaWeights() {
return this._criteriaWeights;
}
public Map<Alternative, Valuation> getClosenessCoeficient() {
return this._closenessCoefficient;
}
public FuzzySet getDistanceDomain() {
return _distanceDomain;
}
public void setDistanceDomain(FuzzySet distanceDomain) {
_distanceDomain = distanceDomain;
}
public List<TwoTupleValuation> getIdealDistances() {
return this._idealDistance;
}
public List<TwoTupleValuation> getNoIdealDistances() {
return this._noIdealDistance;
}
public FuzzySet getDefaultDistanceDomain() {
createDistanceLabels();
return _distanceDomain;
}
public FuzzySet getDistanceDomain(String id) {
return (FuzzySet) domainService.getByName(id);
}
public void retranslateResults() {
if(retranslationModel == null)
retranslationModel = ContextInjectionFactory.make(RetranslationModel.class, context);
Map<Alternative, Valuation> retranslatedClosenessCoefficient =
retranslationModel.retranslate(_closenessCoefficient, _distanceDomain);
orderCoefficients(retranslatedClosenessCoefficient);
}
public void execute() {
// Cache
_decisionMatrix = (Valuation[][]) importData("decisionMatrix");
_criteriaWeights = (TwoTupleValuation[]) importData("criteriaWeights");
createDistanceLabels();
createSimilarityLabels();
step7CalculateIdealEuclideanDistance();
step7CalculateNoIdealEuclideanDistance();
calculateClosenessCoefficient();
}
private void createDistanceLabels() {
_distanceDomain = (FuzzySet) domainService.create(FuzzySet.ID);
_distanceDomain.setName("default");
String[] labels = new String[]{"Equal", "Almost equal", "A bit close", "Neither close nor far", "A bit far", "Far", "Far away"};
_distanceDomain.createTrapezoidalFunction(labels);
}
private void createSimilarityLabels() {
_similarityDomain = ContextInjectionFactory.make(FuzzySet.class, context);
String[] labels = new String[]{"Total dissimilar", "Almost total dissimilar", "A bit dissimilar",
"Neither dissimilar nor dissimilar", "A bit similar", "Almost similar", "Completely similar"};
_similarityDomain.createTrapezoidalFunction(labels);
}
private void step7CalculateIdealEuclideanDistance() {
_idealDistance.clear();
TwoTupleValuation collective, idealSolution, distance = null;
double acum = 0;
for(int i = 0; i < _decisionMatrix[0].length; ++i) {
acum = 0;
for(int j = 0; j < _decisionMatrix.length; ++j) {
collective = (TwoTupleValuation) _decisionMatrix[j][i];
idealSolution = getIdealSolution().get(j);
distance = calculateDistanceBetweenTwoTuple(idealSolution, collective);
acum += distance.calculateInverseDelta();
}
acum /= _decisionMatrix.length;
distance.calculateDelta(acum);
_idealDistance.add(distance);
}
}
private TwoTupleValuation calculateDistanceBetweenTwoTuple(TwoTupleValuation t1, TwoTupleValuation t2) {
int t = getUnifiedDomain().getLabelSet().getCardinality() - 1;
int t_prima = _similarityDomain.getLabelSet().getCardinality() - 1;
int t_prima_prima = _distanceDomain.getLabelSet().getCardinality() - 1;
double factor = (t_prima + 1) - (t_prima - ((Math.abs(t1.calculateInverseDelta() - t2.calculateInverseDelta()) * (t_prima_prima - 1)) / t));
TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context);
result.build(_distanceDomain);
result.calculateDelta(factor);
return result;
}
private void step7CalculateNoIdealEuclideanDistance() {
_noIdealDistance.clear();
TwoTupleValuation collective, noIdealSolution;
TwoTupleValuation distance = null;
double acum = 0;
for(int i = 0; i < _decisionMatrix[0].length; ++i) {
acum = 0;
for(int j = 0; j < _decisionMatrix.length; ++j) {
collective = (TwoTupleValuation) _decisionMatrix[j][i];
noIdealSolution = getNoIdealSolution().get(j);
distance = calculateDistanceBetweenTwoTuple(noIdealSolution, collective);
acum += distance.calculateInverseDelta();
}
acum /= _decisionMatrix.length;
distance.calculateDelta(acum);
_noIdealDistance.add(distance);
}
}
private void calculateClosenessCoefficient() {
Map<Alternative, Valuation> disorderedCoefficients = new HashMap<>();
int t_prima_prima = _distanceDomain.getLabelSet().getCardinality() - 1;
TwoTupleValuation idealDistance, noIdealDistance, coefficient;
double closeness;
for(int i = 0; i < _decisionMatrix[0].length; ++i) {
idealDistance = _idealDistance.get(i);
noIdealDistance = _noIdealDistance.get(i);
closeness = ((noIdealDistance.calculateInverseDelta()) / ((idealDistance.calculateInverseDelta()) + (noIdealDistance.calculateInverseDelta()))) * t_prima_prima;
coefficient = ContextInjectionFactory.make(TwoTupleValuation.class, context);
coefficient.build(_distanceDomain);
coefficient.calculateDelta(closeness);
disorderedCoefficients.put((Alternative) problemService.getAll(Alternative.Type)[i], coefficient);
}
orderCoefficients(disorderedCoefficients);
}
private void orderCoefficients(Map<Alternative, Valuation> disorderedCoefficients) {
_closenessCoefficient = disorderedCoefficients
.entrySet()
.stream()
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
.collect(
java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2,
LinkedHashMap::new));
}
private List<TwoTupleValuation> getIdealSolution() {
return (List<TwoTupleValuation>) importData("idealSolution");
}
private List<TwoTupleValuation> getNoIdealSolution() {
return (List<TwoTupleValuation>) importData("noIdealSolution");
}
public String[] getDistanceDomainsIds() {
Domain[] domains = domainService.getAll();
String[] domainsIds = new String[domains.length];
for(int i = 0; i < domainsIds.length; ++i)
if(domains[i] instanceof FuzzySet)
domainsIds[i] = domains[i].getName();
return domainsIds;
}
}
@@ -0,0 +1,154 @@
package flintstones.method.decision.common.phase.selection;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.entity.method.phase.PhaseMethod;
import flintstones.entity.operator.AggregationOperator;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.valuation.Valuation;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.operator.aggregation.max.Max;
import flintstones.operator.aggregation.min.Min;
import flintstones.operator.service.IOperatorService;
@SuppressWarnings("javadoc")
public class CalculateSolutionsSelectionModel extends PhaseMethod {
@Inject
IEclipseContext context;
@Inject
IProblemElementService problemService;
@Inject
IOperatorService operatorService;
private Valuation[][] decisionMatrix;
List<Valuation> noIdealSolution = new LinkedList<Valuation>();
List<Valuation> idealSolution = new LinkedList<Valuation>();
@Override
public String getName() {
return "Calculate Solutions";
}
@SuppressWarnings("unchecked")
public Valuation[][] getExpertDecisionMatrix(String expert) {
Map<Expert, Valuation[][]> decisionMatrices = (Map<Expert, Valuation[][]>) importData("decisionMatricesExperts");
Valuation[][] decisionMatrix = decisionMatrices.get(problemService.getByName(Expert.Type, expert));
exportData("decisionMatrix", decisionMatrix);
return decisionMatrix;
}
public Valuation[][] getCollectiveDecisionMatrix() {
Valuation[][] decisionMatrix = (Valuation[][]) importData("decisionMatrix");
exportData("decisionMatrix", decisionMatrix);
return decisionMatrix;
}
public List<Valuation> getIdealSolution() {
return this.idealSolution;
}
public List<Valuation> getNoIdealSolution() {
return this.noIdealSolution;
}
private void exportData() {
exportData("idealSolution", this.idealSolution);
exportData("noIdealSolution", this.noIdealSolution);
exportData("unifiedDomain", importData("unifiedDomain"));
exportData("criteriaWeights", importData("criteriaWeights"));
}
public void execute(Valuation[][] decisionMatrix) {
// Cache
this.decisionMatrix = decisionMatrix;
step6CalculateIdealSolution();
step6CalculateNoIdealSolution();
exportData();
}
private void step6CalculateIdealSolution() {
idealSolution.clear();
Valuation idealSolutionValuation = null;
Criterion cri;
for (int i = 0; i < decisionMatrix.length; ++i) {
List<Valuation> valuationsByCriterion = new ArrayList<>();
cri = (Criterion) problemService.getSubElements(Criterion.Type)[i];
for (int j = 0; j < decisionMatrix[i].length; ++j) {
valuationsByCriterion.add(decisionMatrix[i][j]);
}
if (cri.isCost()) {
AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId());
idealSolutionValuation = min.computeAggregation(valuationsByCriterion, null);
} else {
AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId());
idealSolutionValuation = max.computeAggregation(valuationsByCriterion, null);
}
idealSolution.add(idealSolutionValuation);
}
}
private void step6CalculateNoIdealSolution() {
noIdealSolution.clear();
Valuation noIdealSolutionValuation = null;
Criterion cri;
for (int i = 0; i < decisionMatrix.length; ++i) {
List<Valuation> valuationsByCriterion = new ArrayList<>();
cri = (Criterion) problemService.getSubElements(Criterion.Type)[i];
for (int j = 0; j < decisionMatrix[i].length; ++j) {
valuationsByCriterion.add(decisionMatrix[i][j]);
}
if (cri.isCost()) {
AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId());
noIdealSolutionValuation = max.computeAggregation(valuationsByCriterion, null);
} else {
AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId());
noIdealSolutionValuation = min.computeAggregation(valuationsByCriterion, null);
}
noIdealSolution.add(noIdealSolutionValuation);
}
}
public String[] getExpertsName() {
ProblemElement[] experts = problemService.getSubElements(Expert.Type);
String[] expertsName = new String[experts.length];
for(int i = 0; i < experts.length; ++i)
expertsName[i] = experts[i].getName();
return expertsName;
}
public boolean isExpert(String expert) {
if(problemService.getByName(Expert.Type, expert) != null)
return true;
return false;
}
}
@@ -0,0 +1,259 @@
package flintstones.method.decision.common.phase.selection;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
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.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.valuation.Valuation;
import flintstones.method.decision.common.phase.selection.interfaces.ICalculateWeightsSelectionModel;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.valuation.twoTuple.TwoTupleValuation;
@SuppressWarnings("unchecked")
public class CalculateWeightsSelectionModel extends PhaseMethod implements ICalculateWeightsSelectionModel {
@Inject
IEclipseContext context;
@Inject
IProblemElementService problemService;
@Inject
IDomainService domainService;
private Map<Expert, LabelLinguisticDomain[]> criteriaWeightsByExperts = new HashMap<>();
private TwoTupleValuation[] criteriaWeights;
private Map<Expert, Valuation[][]> decisionMatricesExperts;
private Valuation[][] unweightedDecisionMatrix;
private Valuation[][] decisionMatrix;
private FuzzySet unificationDomain;
private FuzzySet weightsDomain;
@Override
public String getName() {
return "Calculate Weights";
}
@Override
public void exportData() {
exportData("decisionMatricesExperts", decisionMatricesExperts);
exportData("decisionMatrix", decisionMatrix);
exportData("criteriaWeights", this.criteriaWeights);
exportData("unifiedDomain", importData("unifiedDomain"));
}
public Domain getUnifiedDomain() {
return (Domain) importData("unifiedDomain");
}
public void setUnifiedDomain(Domain domain) {
unificationDomain = (FuzzySet) domain;
}
@Override
public FuzzySet getCurrentWeightsDomain() {
return weightsDomain;
}
public void setWeightsDomain(FuzzySet weightsDomain) {
this.weightsDomain = weightsDomain;
initializeWeightsExperts();
}
public LabelLinguisticDomain getExpertWeight(Expert e, int crit) {
return criteriaWeightsByExperts.get(e)[crit];
}
public void setExpertWeight(Expert e, int crit, LabelLinguisticDomain weight) {
LabelLinguisticDomain[] weights = criteriaWeightsByExperts.get(e);
weights[crit] = weight;
criteriaWeightsByExperts.put(e, weights);
}
public void setExperstWeights(Map<Expert, LabelLinguisticDomain[]> criteriaWeightsByExpert) {
criteriaWeightsByExperts = criteriaWeightsByExpert;
}
public String[] getWeightsDomainsIds() {
Domain[] domains = domainService.getAll();
List<String> domainsIds = new LinkedList<>();
for(Domain d: domains)
if(d instanceof FuzzySet)
domainsIds.add(d.getName());
return domainsIds.toArray(new String[0]);
}
@Override
public void execute() {
calculateDecisionMatrix();
exportData();
}
@Override
public void createWeightsLabels() {
weightsDomain = (FuzzySet) domainService.create(FuzzySet.ID);
weightsDomain.setName("default");
String[] labels = new String[] { "Very low", "Low", "Medium low", "Medium",
"Medium high", "High", "Very high" };
weightsDomain.createTrapezoidalFunction(labels);
initializeWeightsExperts();
}
private void calculateDecisionMatrix() {
unificationDomain = (FuzzySet) getUnifiedDomain();
computeWeights();
step3TransformExpertsMatricesInto2Tuple();
step4ComputeUnweightedOverallDecisionMatrix();
step5ComputeWeigthedOverallDecisionMatrix();
}
private void computeWeights() {
Map<Expert, TwoTupleValuation[]> weightsTwoTuple = step1TransformWeightsIntoTwoTuple();
step2ComputeCollectiveWeights(weightsTwoTuple);
}
private Map<Expert, TwoTupleValuation[]> step1TransformWeightsIntoTwoTuple() {
Map<Expert, TwoTupleValuation[]> result = new HashMap<>();
for (Expert e : criteriaWeightsByExperts.keySet()) {
LabelLinguisticDomain[] weights = criteriaWeightsByExperts.get(e);
TwoTupleValuation[] weights2T = new TwoTupleValuation[weights.length];
for (int i = 0; i < weights.length; ++i) {
weights2T[i] = ContextInjectionFactory.make(TwoTupleValuation.class, context);
weights2T[i].build(weightsDomain, weights[i]);
}
result.put(e, weights2T);
}
return result;
}
private void initializeWeightsExperts() {
for (ProblemElement e : problemService.getSubElements(Expert.Type)) {
LabelLinguisticDomain[] weights = new LabelLinguisticDomain[problemService.getSubElements(Criterion.Type).length];
for (int i = 0; i < weights.length; ++i) {
weights[i] = weightsDomain.getLabelSet()
.getLabel((weightsDomain.getLabelSet().getCardinality() - 1) / 2);
}
criteriaWeightsByExperts.put((Expert) e, weights);
}
}
private void step2ComputeCollectiveWeights(Map<Expert, TwoTupleValuation[]> weightsTwoTuple) {
criteriaWeights = new TwoTupleValuation[problemService.getSubElements(Criterion.Type).length];
double acum;
for (int i = 0; i < problemService.getSubElements(Criterion.Type).length; ++i) {
acum = 0;
for (Expert e : weightsTwoTuple.keySet())
acum += weightsTwoTuple.get(e)[i].calculateInverseDelta();
TwoTupleValuation weight = ContextInjectionFactory.make(TwoTupleValuation.class, context);
weight.build(weightsDomain);
weight.calculateDelta(acum / weightsTwoTuple.size());
criteriaWeights[i] = weight;
}
}
private void step3TransformExpertsMatricesInto2Tuple() {
decisionMatricesExperts = new HashMap<Expert, Valuation[][]>();
ProblemElement[] experts = problemService.getSubElements(Expert.Type);
ProblemElement[] criteria = problemService.getSubElements(Criterion.Type);
ProblemElement[] alternatives = problemService.getAll(Alternative.Type);
for (ProblemElement e : experts) {
Valuation[][] dm = new Valuation[criteria.length][alternatives.length];
for (ProblemElement c : criteria) {
for (ProblemElement a : alternatives) {
TwoTupleValuation twoTuple = getTwoTupleValuations().get(new ProblemElementKey((Expert) e, (Alternative) a, (Criterion) c));
dm[Arrays.asList(criteria).indexOf(c)][Arrays.asList(alternatives).indexOf(a)] = twoTuple;
}
}
decisionMatricesExperts.put((Expert) e, dm);
}
}
private void step4ComputeUnweightedOverallDecisionMatrix() {
unweightedDecisionMatrix = new Valuation[problemService.getSubElements(Criterion.Type).length][problemService.getAll(Alternative.Type).length];
double acum = 0;
for (int i = 0; i < problemService.getSubElements(Criterion.Type).length; ++i) {
for (int j = 0; j < problemService.getAll(Alternative.Type).length; ++j) {
for (Expert e : decisionMatricesExperts.keySet()) {
Valuation[][] dm = decisionMatricesExperts.get(e);
acum += ((TwoTupleValuation) dm[i][j]).calculateInverseDelta();
}
TwoTupleValuation collective = ContextInjectionFactory.make(TwoTupleValuation.class, context);
collective.build(unificationDomain);
collective.calculateDelta(acum / decisionMatricesExperts.size());
unweightedDecisionMatrix[i][j] = collective;
acum = 0;
}
}
}
private void step5ComputeWeigthedOverallDecisionMatrix() {
decisionMatrix = new Valuation[problemService.getSubElements(Criterion.Type).length][problemService.getAll(Alternative.Type).length];
TwoTupleValuation maxWeight = getMaxWeight();
for (int i = 0; i < unweightedDecisionMatrix.length; ++i) {
TwoTupleValuation weight = criteriaWeights[i];
for (int j = 0; j < unweightedDecisionMatrix[i].length; ++j) {
TwoTupleValuation v = (TwoTupleValuation) unweightedDecisionMatrix[i][j];
TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context);
result.build(unificationDomain);
result.calculateDelta(v.calculateInverseDelta() * (weight.calculateInverseDelta() / maxWeight.calculateInverseDelta()));
decisionMatrix[i][j] = result;
}
}
}
private TwoTupleValuation getMaxWeight() {
List<TwoTupleValuation> auxWeights = new LinkedList<TwoTupleValuation>(Arrays.asList(criteriaWeights));
Collections.sort(auxWeights);
return auxWeights.get(auxWeights.size() - 1);
}
private Map<ProblemElementKey, TwoTupleValuation> getTwoTupleValuations() {
Map<ProblemElementKey, TwoTupleValuation> twoTuple = (Map<ProblemElementKey, TwoTupleValuation>) importData(
"twoTupleUnifiedValuations");
exportData("twoTupleValuations", twoTuple);
return twoTuple;
}
public FuzzySet getWeightsDomain(String selectedDomainId) {
return (FuzzySet) domainService.getByName(selectedDomainId);
}
public FuzzySet getDefaultWeightsDomain() {
this.createWeightsLabels();
return this.weightsDomain;
}
}
@@ -0,0 +1,15 @@
package flintstones.method.decision.common.phase.selection.interfaces;
import flintstones.domain.fuzzyset.FuzzySet;
public interface ICalculateWeightsSelectionModel {
void createWeightsLabels();
FuzzySet getCurrentWeightsDomain();
void exportData();
void execute();
}