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.ahp.sortii.phase.ranking</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Ranking</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.method.ahp.sortii.phase.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>1779484362633</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,37 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ranking
Bundle-SymbolicName: flintstones.method.ahp.sortii.phase.ranking;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.method.ahp.sortii.phase.ranking
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: flintstones.entity.method.phase,
org.eclipse.e4.core.contexts,
javax.inject,
org.eclipse.e4.core.di,
flintstones.entity.preferences.preferencecollection,
flintstones.model.ahppreferences.service,
flintstones.entity.ahp,
flintstones.helper.data,
flintstones.entity.problemelement,
flintstones.entity.ahppreferences,
flintstones.model.problemelement.service,
flintstones.entity.ahpsort.referencepoint,
flintstones.method.ahp.sort.phase.ranking,
flintstones.entity.ahpsort.priority,
flintstones.model.valuation.service,
flintstones.entity.valuation,
flintstones.valuation.numeric.real,
flintstones.model.ahp.referencepoint.service,
flintstones.model.domain.service,
flintstones.helper.debug,
flintstones.model.ahpsort.profileassignment.service,
flintstones.entity.ahpsort.profileassignment,
flintstones.clustering.agglomerative,
org.apache.commons.lang,
flintstones.entity.domain,
org.jfree.chart.jfreechart,
flintstones.helper.ahp,
flintstones.domain.numeric.real,
flintstones.engine.R
Export-Package: flintstones.method.ahp.sortii.phase.ranking
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.phasemethod.extensionpoint">
<phase
uid="flintstones.method.ahp.sortii.phase.ranking"
implementation="flintstones.method.ahp.sortii.phase.ranking.AHPSortIIRankingModelAgglomerative">
</phase>
</extension>
<extension
point="flintstones.phasemethod.extensionpoint">
<phase
uid="flintstones.method.ahp.sortii.phase.ranking2"
implementation="flintstones.method.ahp.sortii.phase.ranking.AHPSortIIRanking2ModelAgglomerative">
</phase>
</extension>
</plugin>
@@ -0,0 +1,566 @@
package flintstones.method.ahp.sortii.phase.ranking;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import javax.inject.Inject;
import org.apache.commons.lang.ArrayUtils;
import flintstones.entity.ahp.AHPMatrix;
import flintstones.entity.ahppreferences.PreferenceCollectionKey;
import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint;
import flintstones.entity.preferences.preferencecollection.PreferenceCollection;
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.problemelement.entities.SortingClass;
import flintstones.entity.problemelement.entities.SortingProfile;
import flintstones.helper.DoubleHelper;
import flintstones.helper.EigenHelper;
import flintstones.helper.MapHelper;
import flintstones.helper.ahp.AHPHelper;
import flintstones.helper.data.HashMatrix;
import flintstones.helper.data.LinkedHashMatrix;
import flintstones.helper.data.Pair;
import flintstones.helper.debug.DH;
import flintstones.method.ahp.sort.phase.ranking.ahpcluster.AHPCluster;
import flintstones.method.ahp.sort.phase.ranking.ahpcluster.AHPClusterer;
import flintstones.model.ahp.referencepoint.service.IReferencePointService;
import flintstones.model.ahppreferences.service.IProblemPreferencesService;
import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService;
import flintstones.model.problemelement.service.IProblemElementService;
import flintstones.model.valuation.service.IValuationService;
import flintstones.valuation.numeric.real.RealValuation;
public class AHPSortIIModel {
@Inject
IProblemElementService problemService;
@Inject
IValuationService valuationService;
@Inject
IReferencePointService referenceService;
@Inject
IProblemPreferencesService preferenceService;
@Inject
IProfileAssignmentService profileService;
Criterion[] criteria;
Expert[] experts;
// TODO: REVISAR 06/06/2019
boolean isOptimisticx = false;
public ArrayList<SortingClass> getClasses() {
SortingClass[] classes = Arrays //
.stream(problemService.getAll(SortingClass.Type)) //
.map(k -> (SortingClass) k).toArray(SortingClass[]::new);
return new ArrayList<SortingClass>(Arrays.asList(classes));
}
//
LinkedHashMap<Expert, LinkedHashMap<Criterion, Double>> expertsWeights = new LinkedHashMap<>();
public LinkedHashMap<Expert, LinkedHashMap<Criterion, Double>> getExpertsWeights() {
return expertsWeights;
}
public void cacheCriterionWeightsFor(PreferenceCollection col) {
// Cache some data
ProblemElement[] expertsPes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Expert.Type));
experts = ProblemElementHelper.asExperts(expertsPes);
ProblemElement[] criterionsPes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Criterion.Type));
criteria = ProblemElementHelper.asCriterions(criterionsPes);
for(Expert expert: experts) {
LinkedHashMap<Criterion, Double> criteriaWeights = new LinkedHashMap<>();
HashMap<Criterion, Double> criteriaWeightsA = new HashMap<>();
AHPMatrix matrix = col.getAHPMatrix(null, expert);
double[] values = EigenHelper.GetNormalizedEigenVector(matrix.getValues());
for (int i = 0; i < matrix.getCols().length; i++) {
ProblemElement criterion = matrix.getCols()[i];
Double value = values[i];
criteriaWeightsA.put((Criterion) criterion, value);
}
criteriaWeights = MapHelper.sortByExample(criteriaWeightsA, criteria);
expertsWeights.put(expert, criteriaWeights);
}
}
//
public void execute() {
cacheClusters();
cacheProfileAndReferenceLocalPriorities();
cacheAlternativeLocalPriorities();
cacheAlternativeGlobalPriorities();
cacheProfileGlobalPriorities();
}
LinkedHashMap<Expert, LinkedHashMap<Criterion, AHPClusterer>> expertsClusterers = new LinkedHashMap<>();
// Punto de referencia + Perfiles
LinkedHashMap<Expert, LinkedHashMap<Criterion, LinkedList<ProblemElement>>> expertsRepresentativePoints = new LinkedHashMap<>();
private void cacheClusters() {
for(Expert expert: experts) {
LinkedHashMap<Criterion, AHPClusterer> clusterers = new LinkedHashMap<>();
LinkedHashMap<Criterion, LinkedList<ProblemElement>> representativePoints = new LinkedHashMap<>();
for (Criterion c : criteria) {
LinkedList<SortingProfile> profiles = profileService.get(expert, c).getAllProfiles();
Double[] values = profiles.stream().map(k -> Double.valueOf(k.getValue())).toArray(Double[]::new);
double[] valuesp = ArrayUtils.toPrimitive(values);
if (DoubleHelper.IsDescending(valuesp))
Collections.reverse(profiles);
LinkedList<AHPSortReferencencePoint> refPoints = referenceService.get(c);
LinkedList<ProblemElement> elements_criterion = new LinkedList<>();
LinkedList<Double> values_criterion = new LinkedList<>();
int pIndex = 0;
int rIndex = 0;
for (int i = 0; i < profiles.size() + refPoints.size(); i++) {
SortingProfile profile = pIndex < profiles.size() ? profiles.get(pIndex) : null;
AHPSortReferencencePoint refPoint = rIndex < refPoints.size() ? refPoints.get(rIndex) : null;
Double pValue = profile != null ? profile.getValue() : null;
Double rValue = refPoint != null ? refPoint.getValue() : null;
if (rValue == null) {
elements_criterion.add(profile);
values_criterion.add(pValue);
pIndex++;
} else if (pValue == null) {
elements_criterion.add(refPoint);
values_criterion.add(rValue);
rIndex++;
} else if (pValue < rValue) {
elements_criterion.add(profile);
values_criterion.add(pValue);
pIndex++;
} else {
elements_criterion.add(refPoint);
values_criterion.add(rValue);
rIndex++;
}
}
AHPClusterer clusterer = new AHPClusterer(elements_criterion.toArray(new ProblemElement[0]));//Aquí se hace la división del clustering
clusterers.put(c, clusterer);
representativePoints.put(c, elements_criterion);
}
expertsClusterers.put(expert, clusterers);
expertsRepresentativePoints.put(expert, representativePoints);
}
}
public LinkedHashMap<Expert, LinkedHashMap<Criterion, AHPClusterer>> getClusterers() {
return expertsClusterers;
}
LinkedHashMap<Expert, LinkedHashMatrix<Criterion, ProblemElement, Double>> pro_ref_localPriorities = new LinkedHashMap<>();
private void cacheProfileAndReferenceLocalPriorities() {
PreferenceCollectionKey prof_prof = new PreferenceCollectionKey(Expert.Type, Criterion.Type,
SortingProfile.Type, SortingProfile.Type);
PreferenceCollection prof_prof_col = preferenceService.get(prof_prof);
PreferenceCollectionKey ref_ref = new PreferenceCollectionKey(Expert.Type, Criterion.Type,
AHPSortReferencencePoint.Type, AHPSortReferencencePoint.Type);
PreferenceCollection ref_ref_col = preferenceService.get(ref_ref);
PreferenceCollectionKey ref_pro = new PreferenceCollectionKey(Expert.Type, Criterion.Type,
AHPSortReferencencePoint.Type, SortingProfile.Type);
PreferenceCollection ref_pro_col = preferenceService.get(ref_pro);
for(Expert expert: experts) {
LinkedHashMatrix<Criterion, ProblemElement, Double> prof_ref_localPriorities_matrix = new LinkedHashMatrix<>();
for (Criterion c : criteria) {
AHPMatrix ppm = prof_prof_col.getAHPMatrix(expert, c);
AHPMatrix rrm = ref_ref_col.getAHPMatrix(expert, c);
AHPClusterer clusterer = expertsClusterers.get(expert).get(c);
for (AHPCluster cluster : clusterer) {
AHPMatrix ahpmatrix = new AHPMatrix(cluster.getElements());
for (ProblemElement pe1 : cluster) {
for (ProblemElement pe2 : cluster) {
Integer index = null;
if (pe1.getType().equals(SortingProfile.Type) && pe2.getType().equals(SortingProfile.Type)) {
index = ppm.getIndex(pe1, pe2);
} else if (pe1.getType().equals(AHPSortReferencencePoint.Type)
&& pe2.getType().equals(AHPSortReferencencePoint.Type)) {
index = rrm.getIndex(pe1, pe2);
} else if (pe1.getType().equals(AHPSortReferencencePoint.Type)
&& pe2.getType().equals(SortingProfile.Type)) {
index = ref_pro_col.get(expert, c, pe1, pe2);
} else if (pe1.getType().equals(SortingProfile.Type)
&& pe2.getType().equals(AHPSortReferencencePoint.Type)) {
index = AHPHelper.getInverseIndex(ref_pro_col.get(expert, c, pe2, pe1));
}
ahpmatrix.set(pe1, pe2, index);
}
}
double[] weights = EigenHelper.GetNormalizedEigenVector(ahpmatrix.getValues());
cluster.setLocalPriorities(weights);
}
LinkedHashMap<ProblemElement, Double> pes = clusterer.getNormalizedPriorities();
for (Entry<ProblemElement, Double> pe : pes.entrySet())
prof_ref_localPriorities_matrix.put(c, pe.getKey(), pe.getValue());
}
pro_ref_localPriorities.put(expert, prof_ref_localPriorities_matrix);
}
}
// Alt, Int, Double
LinkedHashMap<Expert, LinkedHashMap<Alternative, Double>> expertsAlternativeG = new LinkedHashMap<>();
public LinkedHashMap<Expert, LinkedHashMap<Alternative, Double>> getAlternativeGlobalPriorities() {
return expertsAlternativeG;
}
private void cacheAlternativeGlobalPriorities() {
ProblemElement[] alternatives = problemService.getAll(Alternative.Type);
for(Expert expert: experts) {
LinkedHashMap<Alternative, Double> alternativeG = new LinkedHashMap<>();
for (ProblemElement a : alternatives) {
Double indexTotal = 0.0;
for (ProblemElement c : criteria) {
double localValue = alternativeLocalPriorities.get(expert).get((Alternative) a, (Criterion) c);
double weight = expertsWeights.get(expert).get(c);
double weighted = localValue * weight;
indexTotal += weighted;
}
alternativeG.put((Alternative) a, indexTotal);
}
expertsAlternativeG.put(expert, alternativeG);
}
}
LinkedHashMap<Expert, LinkedHashMap<SortingProfile, Double>> expertsProfileG = new LinkedHashMap<>();
public LinkedHashMap<Expert, LinkedHashMap<SortingProfile, Double>> getProfileGlobalPriorities() {
return expertsProfileG;
}
private void cacheProfileGlobalPriorities() {
Criterion[] criteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type));
Expert[] experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type));
int indexes = profileService.get(experts[0], criteria[0]).getAllProfiles().size();
ArrayList<SortingClass> cls = getClasses();
for(Expert expert: experts) {
LinkedHashMap<SortingProfile, Double> profileG = new LinkedHashMap<>();
for (int index = 0; index < indexes; index++) {
Double indexTotal = 0.0;
for (Criterion c : criteria) {
SortingProfile profile = profileService.get(expert, c).getAllProfiles().get(index);
double localValue = pro_ref_localPriorities.get(expert).get(c, profile);
double weight = expertsWeights.get(expert).get(c);
double weighted = localValue * weight;
indexTotal += weighted;
}
String name = cls.get(index) + " " + index;
SortingProfile prof = new SortingProfile(expert, new Criterion(name), indexTotal);
prof.setName(name);
profileG.put(prof, indexTotal);
}
expertsProfileG.put(expert, profileG);
}
}
LinkedHashMap<Expert, HashMatrix<Alternative, Criterion, Double>> alternativeLocalPriorities = new LinkedHashMap<>();
public LinkedHashMap<Expert, HashMatrix<Alternative, Criterion, Double>> getAlternativeLocalPriorities() {
return alternativeLocalPriorities;
}
private void cacheAlternativeLocalPriorities() {
ProblemElement[] alternatives = problemService.getAll(Alternative.Type);
for(Expert expert: experts) {
HashMatrix<Alternative, Criterion, Double> alternativeLocalPrioritiesMatrix = new HashMatrix<>();
for (ProblemElement a : alternatives) {
for (ProblemElement c : criteria) {
double pkj = p(expert, (Alternative) a, (Criterion) c);
alternativeLocalPrioritiesMatrix.put((Alternative) a, (Criterion) c, pkj);
}
}
alternativeLocalPriorities.put(expert, alternativeLocalPrioritiesMatrix);
}
}
private double p(Expert e, Alternative a, Criterion c) {
double gaj = gaj(e, a, c);
Pair<ProblemElement, ProblemElement> pair = getAlternativeIntervalElements(e, c, gaj);
ProblemElement refA = pair.getLeft();
ProblemElement refB = pair.getRight();
double soj = soj(refA);
double so1j = soj(refB);
double poj = poj(e, c, refA);
double poj1 = poj(e, c, refB);
double up = poj1 - poj;
double down = so1j - soj;
double division = up / down;
double right = gaj - soj;
double total = poj + (division * right);
return total;
}
private Pair<ProblemElement, ProblemElement> getAlternativeIntervalElements(Expert e, Criterion c, double gaj) {
LinkedList<ProblemElement> points = expertsRepresentativePoints.get(e).get(c);
double[] pointsArr = points.stream().map(k -> {
if (k instanceof SortingProfile) {
return ((SortingProfile) k).getValue();
} else {
return ((AHPSortReferencencePoint) k).getValue();
}
}).mapToDouble(Double::doubleValue).toArray();
int pos = -1;
if (DoubleHelper.IsAscending(pointsArr)) {
pos = DoubleHelper.FindInAscendingRange(pointsArr, gaj);
} else if (DoubleHelper.IsDescending(pointsArr)) {
pos = DoubleHelper.FindInDescendingRange(pointsArr, gaj);
} else {
throw new RuntimeException("Not orderer");
}
if (pos == pointsArr.length - 1) {
pos = pos - 1;
}
ProblemElement pA = points.get(pos);
ProblemElement pB = points.get(pos + 1);
return new Pair<>(pA, pB);
}
private double poj(Expert e, Criterion c, ProblemElement ref) {
return pro_ref_localPriorities.get(e).get(c).get(ref);
}
private double soj(ProblemElement k) {
if (k instanceof SortingProfile) {
return ((SortingProfile) k).getValue();
} else {
return ((AHPSortReferencencePoint) k).getValue();
}
}
private double gaj(Expert expert, Alternative a, Criterion c) {
RealValuation v = (RealValuation) valuationService.getValuationFor(new ProblemElementKey(expert, a, c));
double value = v.getValue();
return value;
}
////////////////////////////
////////////////////////////
////////////////////////////
////////////////////////////
////////////////////////////
////////////////////////////
LinkedHashMap<Expert, HashMap<ProblemElement, SortingClass>> classification = new LinkedHashMap<>();
public LinkedHashMap<Expert, HashMap<ProblemElement, SortingClass>> getClassification() {
return classification;
}
public void classify() {
// REVISAR
Criterion[] criterions = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type));
Expert[] experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type));
Alternative[] alternatives = Arrays.stream(problemService.getAll(Alternative.Type)).map(k -> (Alternative) k).toArray(Alternative[]::new);
int profileNumber = profileService.get(experts[0], criterions[0]).getAllProfiles().size();;
int classNumber = getClasses().size();
boolean isCentral = profileNumber == classNumber;
if (!isCentral) {
for(Expert expert: experts) {
HashMap<ProblemElement, SortingClass> classificationAlternative = new HashMap<>();
for (Alternative alternative : alternatives) {
int index = classifyByLimitingAlternativeV2(expert, alternative);
SortingClass classs = getClasses().get(index);
classificationAlternative.put(alternative, classs);
}
classification.put(expert, classificationAlternative);
}
} else if (isCentral) {
for(Expert expert: experts) {
HashMap<ProblemElement, SortingClass> classificationAlternative = new HashMap<>();
for (Alternative alternative : alternatives) {
int index = classifyByCentralAlternativeV2(expert, alternative);
SortingClass classs = getClasses().get(index);
classificationAlternative.put(alternative, classs);
}
classification.put(expert, classificationAlternative);
}
}
DH.l(2);
}
//
//
private Double getAlternativePrioritiesFor(Expert e, Alternative a) {
return expertsAlternativeG.get(e).get(a);
}
////
private ArrayList<Double> getProfileLimits(Expert e) {
return new ArrayList<Double>(expertsProfileG.get(e).values());
}
//
//
//
private int classifyByCentralAlternativeV2(Expert expert, Alternative alternative) {
Double onlyHit = getAlternativePrioritiesFor(expert, alternative);
ArrayList<Double> limits = getProfileLimits(expert);
DH.l(2);
DH.out(onlyHit);
double minDistance = Double.MAX_VALUE;
int minDistanceIndex = -1;
int i = 0;
for (Double limit : limits) {
double diff = Math.abs(limit - onlyHit);
if (diff < minDistance) {
minDistanceIndex = i;
minDistance = diff;
} else if (diff == minDistance) { // TIE!!
if (!isOptimisticx) { // GET THE NEW ONE, ELSE KEEP THE OLD ONE
minDistanceIndex = i;
}
}
i++;
}
return minDistanceIndex;
//
}
//
private int classifyByLimitingAlternativeV2(Expert expert, Alternative alternative) {
Double onlyHit = getAlternativePrioritiesFor(expert, alternative);
ArrayList<Double> profileLimits = getProfileLimits(expert);
for (int i = 0; i < profileLimits.size(); i++) {
double hit = onlyHit;
double limit = profileLimits.get(i);
if (hit > limit)
return i;
}
// No clasification, last one, bad.
return profileLimits.size();
}
}
@@ -0,0 +1,104 @@
package flintstones.method.ahp.sortii.phase.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import javax.inject.Inject;
import flintstones.entity.method.phase.PhaseMethod;
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.helper.data.HashMatrix;
import flintstones.helper.data.LinkedHashMatrix;
import flintstones.helper.data.adapter.TableAdapter;
import flintstones.model.problemelement.service.IProblemElementService;
public class AHPSortIIRanking2Model extends PhaseMethod {
AHPSortIIModel db;
@Inject
IProblemElementService problemService;
@Override
public String getName() {
return "Classification";
}
public void execute() {
db = (AHPSortIIModel) importData("model");
}
public ArrayList<SortingClass> getClasses(){
return db.getClasses();
}
public TableAdapter getAlternativeLocalTable(Expert expert) {
HashMatrix<Alternative, Criterion, Double> alternatives_local = db.getAlternativeLocalPriorities().get(expert);
TableAdapter adapter = new TableAdapter(alternatives_local);
return adapter;
}
public TableAdapter getAlternativeGlobalTable(Expert expert) {
HashMap<Alternative, Double> data = db.getAlternativeGlobalPriorities().get(expert);
HashMap<ProblemElement, SortingClass> classification = db.getClassification().get(expert);
LinkedHashMatrix<ProblemElement, FakeProblemElement, Object> aggregatedMatrix = new LinkedHashMatrix<>();
FakeProblemElement f1 = new FakeProblemElement("Global priority");
FakeProblemElement f2 = new FakeProblemElement("Classification");
for(Entry<Alternative, Double> entry : data.entrySet())
aggregatedMatrix.put(entry.getKey(), f1, entry.getValue());
for(Entry<ProblemElement, SortingClass> entry : classification.entrySet())
aggregatedMatrix.put(entry.getKey(), f2, entry.getValue());
TableAdapter adapter = new TableAdapter(aggregatedMatrix);
return adapter;
}
public TableAdapter getProfilesGlobalTable(Expert expert) {
HashMap<SortingProfile, Double> data = db.getProfileGlobalPriorities().get(expert);
TableAdapter adapter = new TableAdapter(data);
return adapter;
}
public TableAdapter getGlobalClassificationTable() {
LinkedHashMap<ProblemElement, ProblemElement> globalClassification = new LinkedHashMap<>();
LinkedHashMap<Expert, HashMap<ProblemElement, SortingClass>> classificationByExperts = db.getClassification();
ProblemElement[] sClasses = problemService.getAll(SortingClass.Type);
LinkedHashMap<ProblemElement, Integer> assignments = new LinkedHashMap<>();
int count;
for(ProblemElement alternative: problemService.getAll(Alternative.Type)) {
for(ProblemElement sClass: sClasses)
assignments.put(sClass, 0);
for(Expert expert: classificationByExperts.keySet()) {
HashMap<ProblemElement, SortingClass> classification = classificationByExperts.get(expert);
count = assignments.get(classification.get(alternative));
assignments.put(classification.get(alternative), count + 1);
}
//Take the first one (optimistic vision) for applying pesimistic TODO
ProblemElement max = Collections.max(assignments.entrySet(), (entry1, entry2) -> entry1.getValue() - entry2.getValue()).getKey();
globalClassification.put(alternative, max);
}
TableAdapter adapter = new TableAdapter(globalClassification);
return adapter;
}
}
@@ -0,0 +1,104 @@
package flintstones.method.ahp.sortii.phase.ranking;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import javax.inject.Inject;
import flintstones.entity.method.phase.PhaseMethod;
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.helper.data.HashMatrix;
import flintstones.helper.data.LinkedHashMatrix;
import flintstones.helper.data.adapter.TableAdapter;
import flintstones.model.problemelement.service.IProblemElementService;
public class AHPSortIIRanking2ModelAgglomerative extends PhaseMethod {
AHPSortIIModelAgglomerative db;
@Inject
IProblemElementService problemService;
@Override
public String getName() {
return "Classification";
}
public void execute() {
db = (AHPSortIIModelAgglomerative) importData("model");
}
public ArrayList<SortingClass> getClasses(){
return db.getClasses();
}
public TableAdapter getAlternativeLocalTable(Expert expert) {
HashMatrix<Alternative, Criterion, Double> alternatives_local = db.getAlternativeLocalPriorities().get(expert);
TableAdapter adapter = new TableAdapter(alternatives_local);
return adapter;
}
public TableAdapter getAlternativeGlobalTable(Expert expert) {
HashMap<Alternative, Double> data = db.getAlternativeGlobalPriorities().get(expert);
HashMap<ProblemElement, SortingClass> classification = db.getClassification().get(expert);
LinkedHashMatrix<ProblemElement, FakeProblemElement, Object> aggregatedMatrix = new LinkedHashMatrix<>();
FakeProblemElement f1 = new FakeProblemElement("Global priority");
FakeProblemElement f2 = new FakeProblemElement("Classification");
for(Entry<Alternative, Double> entry : data.entrySet())
aggregatedMatrix.put(entry.getKey(), f1, entry.getValue());
for(Entry<ProblemElement, SortingClass> entry : classification.entrySet())
aggregatedMatrix.put(entry.getKey(), f2, entry.getValue());
TableAdapter adapter = new TableAdapter(aggregatedMatrix);
return adapter;
}
public TableAdapter getProfilesGlobalTable(Expert expert) {
HashMap<SortingProfile, Double> data = db.getProfileGlobalPriorities().get(expert);
TableAdapter adapter = new TableAdapter(data);
return adapter;
}
public TableAdapter getGlobalClassificationTable() {
LinkedHashMap<ProblemElement, ProblemElement> globalClassification = new LinkedHashMap<>();
LinkedHashMap<Expert, HashMap<ProblemElement, SortingClass>> classificationByExperts = db.getClassification();
ProblemElement[] sClasses = problemService.getAll(SortingClass.Type);
LinkedHashMap<ProblemElement, Integer> assignments = new LinkedHashMap<>();
int count;
for(ProblemElement alternative: problemService.getAll(Alternative.Type)) {
for(ProblemElement sClass: sClasses)
assignments.put(sClass, 0);
for(Expert expert: classificationByExperts.keySet()) {
HashMap<ProblemElement, SortingClass> classification = classificationByExperts.get(expert);
count = assignments.get(classification.get(alternative));
assignments.put(classification.get(alternative), count + 1);
}
//Take the first one (optimistic vision) for applying pesimistic TODO
ProblemElement max = Collections.max(assignments.entrySet(), (entry1, entry2) -> entry1.getValue() - entry2.getValue()).getKey();
globalClassification.put(alternative, max);
}
TableAdapter adapter = new TableAdapter(globalClassification);
return adapter;
}
}
@@ -0,0 +1,151 @@
package flintstones.method.ahp.sortii.phase.ranking;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint;
import flintstones.entity.method.phase.PhaseMethod;
import flintstones.entity.preferences.preferencecollection.PreferenceCollection;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.problemelement.entities.SortingProfile;
import flintstones.helper.DoubleHelper;
import flintstones.helper.StringHelper;
import flintstones.helper.data.adapter.TableAdapter;
import flintstones.method.ahp.sort.phase.ranking.ahpcluster.AHPClusterer;
import flintstones.model.ahppreferences.service.IProblemPreferencesService;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
public class AHPSortIIRankingModel extends PhaseMethod {
@Inject
IEclipseContext context;
@Inject
IProblemPreferencesService prefService;
@Inject
IProblemElementService problemService;
@Inject
IDomainService domainService;
@Override
public String getName() {
return "Priority Functions";
}
AHPSortIIModel db;
public void execute() {
// XTRA
db = ContextInjectionFactory.make(AHPSortIIModel.class, context);
// Weights
PreferenceCollection criterionCol = prefService.get(null, Expert.Type, Criterion.Type, Criterion.Type);
db.cacheCriterionWeightsFor(criterionCol);
db.execute();
db.classify();
exportData("model",db);
}
public TableAdapter getClustersTable(Expert expert) {
TableAdapter adapter = new TableAdapter();
LinkedHashMap<Criterion, AHPClusterer> clusterers = db.getClusterers().get(expert);
LinkedHashMap<Criterion, Double> criterionWeights = db.getExpertsWeights().get(expert);
ProblemElement[] criterions = clusterers.keySet().toArray(new ProblemElement[0]);
int nCriterion = clusterers.size();
int nExperts = db.getExpertsWeights().size();
int nProfiles = problemService.getAll(SortingProfile.Type).length / (nCriterion * nExperts);
int nRefPoints = problemService.getAll(AHPSortReferencencePoint.Type).length / nCriterion;
int cols = nProfiles + nRefPoints;
// VHeader
ArrayList<String> vHeaderL = new ArrayList<>();
for (int i = 0; i < nCriterion; i++) {
vHeaderL.add(StringHelper.Draw(criterions[i].getName()));
}
adapter.setVerticalHeaders(vHeaderL.toArray(new String[0]));
// H Header
String[] hHeader = new String[cols + 1];
hHeader[0] = "C. Weight";
for (int i = 1; i < cols+1; i++) {
hHeader[i] = "E. " + i;
}
adapter.setHorizontalHeaders(hHeader);
String[][] data = new String[nCriterion][cols+1];
for (int i = 0; i < nCriterion; i++) {
Criterion c = (Criterion) criterions[i];
AHPClusterer clusterer = clusterers.get(c);
LinkedHashMap<ProblemElement, Double> priorities = clusterer.getNormalizedPriorities();
int j = 1;
for (Entry<ProblemElement, Double> entry : priorities.entrySet()) {
String cellName = entry.getKey().getShortName() + " (" + DoubleHelper.Draw(entry.getValue()) + ")";
data[i][j] = cellName;
j++;
}
data[i][0] = DoubleHelper.Draw(criterionWeights.get(c));
}
adapter.setData(data);
return adapter;
}
public XYDataset getDataset(Expert e, Criterion c) {
LinkedHashMap<Criterion, AHPClusterer> clusterers = db.getClusterers().get(e);
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series = new XYSeries(c.getName());
AHPClusterer cluster = clusterers.get(c);
LinkedHashMap<ProblemElement, Double> values = cluster.getNormalizedPriorities();
for (Entry<ProblemElement, Double> entry : values.entrySet()) {
ProblemElement pe = entry.getKey();
Double keyVal = null;
if (pe instanceof AHPSortReferencencePoint) {
keyVal = ((AHPSortReferencencePoint) pe).getValue();
} else if (pe instanceof SortingProfile) {
keyVal = ((SortingProfile) pe).getValue();
}
Double val = entry.getValue();
// ABAJO - > IZQ
series.add(keyVal, val);
}
dataset.addSeries(series);
return dataset;
}
}
@@ -0,0 +1,145 @@
package flintstones.method.ahp.sortii.phase.ranking;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint;
import flintstones.entity.method.phase.PhaseMethod;
import flintstones.entity.preferences.preferencecollection.PreferenceCollection;
import flintstones.entity.problemelement.entities.Criterion;
import flintstones.entity.problemelement.entities.Expert;
import flintstones.entity.problemelement.entities.ProblemElement;
import flintstones.entity.problemelement.entities.SortingProfile;
import flintstones.helper.DoubleHelper;
import flintstones.helper.StringHelper;
import flintstones.helper.data.adapter.TableAdapter;
import flintstones.model.ahppreferences.service.IProblemPreferencesService;
import flintstones.model.domain.service.IDomainService;
import flintstones.model.problemelement.service.IProblemElementService;
public class AHPSortIIRankingModelAgglomerative extends PhaseMethod {
@Inject
IEclipseContext context;
@Inject
IProblemPreferencesService prefService;
@Inject
IProblemElementService problemService;
@Inject
IDomainService domainService;
@Override
public String getName() {
return "Priority Functions";
}
AHPSortIIModelAgglomerative db;
public void execute() {
// XTRA
db = ContextInjectionFactory.make(AHPSortIIModelAgglomerative.class, context);
// Weights
PreferenceCollection criterionCol = prefService.get(null, Expert.Type, Criterion.Type, Criterion.Type);
db.cacheCriterionWeightsFor(criterionCol);
db.execute();
db.classify();
exportData("model",db);
}
public TableAdapter getClustersTable(Expert expert) {
TableAdapter adapter = new TableAdapter();
LinkedHashMap<Criterion, Double> criterionWeights = db.getExpertsWeights().get(expert);
int nCriterion = criterionWeights.size();
int nExperts = db.getExpertsWeights().size();
int nProfiles = problemService.getAll(SortingProfile.Type).length / (nCriterion * nExperts);
int nRefPoints = problemService.getAll(AHPSortReferencencePoint.Type).length / nCriterion;
int cols = nProfiles + nRefPoints;
// VHeader
ProblemElement[] criteria = problemService.getAll(Criterion.Type);
ArrayList<String> vHeaderL = new ArrayList<>();
for (int i = 0; i < nCriterion; i++)
vHeaderL.add(StringHelper.Draw(criteria[i].getName()));
adapter.setVerticalHeaders(vHeaderL.toArray(new String[0]));
// H Header
String[] hHeader = new String[cols + 1];
hHeader[0] = "C. Weight";
for (int i = 1; i < cols+1; i++)
hHeader[i] = "E. " + i;
adapter.setHorizontalHeaders(hHeader);
String[][] data = new String[nCriterion][cols+1];
for (int i = 0; i < nCriterion; i++) {
Criterion c = (Criterion) criteria[i];
LinkedHashMap<ProblemElement, Double> priorities = db.getLocalPrioritiesRepresentativePoints().get(expert).get(c);
int j = 1;
for (Entry<ProblemElement, Double> entry : priorities.entrySet()) {
String cellName = entry.getKey().getShortName() + " (" + DoubleHelper.Draw(entry.getValue()) + ")";
data[i][j] = cellName;
j++;
}
data[i][0] = DoubleHelper.Draw(criterionWeights.get(c));
}
adapter.setData(data);
return adapter;
}
public XYDataset getDataset(Expert e, Criterion c) {
LinkedHashMap<ProblemElement, Double> localPriorities = db.getLocalPrioritiesRepresentativePoints().get(e).get(c);
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries series = new XYSeries(c.getName());
for (Entry<ProblemElement, Double> entry : localPriorities.entrySet()) {
ProblemElement pe = entry.getKey();
Double keyVal = null;
if (pe instanceof AHPSortReferencencePoint)
keyVal = ((AHPSortReferencencePoint) pe).getValue();
else if (pe instanceof SortingProfile)
keyVal = ((SortingProfile) pe).getValue();
Double val = entry.getValue();
// ABAJO - > IZQ
series.add(keyVal, val);
}
dataset.addSeries(series);
return dataset;
}
}