public code v1

This commit is contained in:
2026-05-22 11:14:29 +02:00
parent 427197ec5a
commit b8141736eb
28859 changed files with 575079 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,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>afryca.consensusmodel.rodriguez2018HierarchicalClustering</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>
</projectDescription>
@@ -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,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: afryca.consensusmodel.rodriguez2018HierarchicalClustering;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: afryca.consensusmodel,
afryca.hpr,
afryca.fpr
Automatic-Module-Name: afryca.consensusmodel.Rodriguez2018HierarchicalClustering
@@ -0,0 +1,14 @@
#Properties file for afryca.consensusmodel.Rodriguez2018HierarchicalClustering
Bundle-Name = Rodriguez2018HierarchicalClustering
ConsensusModel.Information = Rodriguez2017HierarchicalClustering
ConsensusModel.MainFeatures = Rodriguez2017HierarchicalClustering
ConsensusModel.Name = Rodriguez2017HierarchicalClustering
ConsensusModel.Observations = Rodriguez2017HierarchicalClustering
Variable.description = max_rounds
Variable.description.0 = theta
Variable.description.1 = delta
Variable.description.2 = pointB
Variable.description.3 = beta
Variable.description.4 = pointA
Variable.description.5 = distance_measure_minkowski
Variable.description.6 = Activate to use CMeans, deactivate to use KMeans
@@ -0,0 +1,7 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
OSGI-INF/l10n/bundle.properties,\
OSGI-INF/
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="afryca.consensusmodel">
<ConsensusModel
ConsensusModel="afryca.consensusmodel.Rodriguez2017HierarchicalClustering"
Information="%ConsensusModel.Information"
MainFeatures="%ConsensusModel.MainFeatures"
Multicriteria="false"
Name="%ConsensusModel.Name"
Observations="%ConsensusModel.Observations"
Structure="afryca.fpr"
WithFeedback="true"
id="Rodriguez2017HierarchicalClustering">
<Variable
default_value="30"
description="%Variable.description"
id="max_rounds"
is_array="false"
is_internal="false"
type="Integer">
<Restriction
type="lower_limit"
value="1">
</Restriction>
</Variable>
<Variable
default_value="0.85"
description="%Variable.description.0"
id="theta"
is_array="false"
is_internal="false"
type="Float">
<Restriction
type="lower_limit"
value="0">
</Restriction>
<Restriction
type="upper_limit"
value="1">
</Restriction>
</Variable>
<Variable
default_value="0.7"
description="%Variable.description.1"
id="delta"
is_array="false"
is_internal="false"
type="Float">
</Variable>
<Variable
default_value="Math.round(experts/alternatives)"
description="%Variable.description.2"
id="pointB"
is_array="false"
is_internal="false"
type="Operation">
<Restriction
type="upper_limit"
value="100">
</Restriction>
<Restriction
type="lower_limit"
value="2">
</Restriction>
<Relation
type="greater_than"
variable="pointA">
</Relation>
</Variable>
<Variable
default_value="1.8"
description="%Variable.description.3"
id="beta"
is_array="false"
is_internal="false"
type="Float">
</Variable>
<Variable
default_value="Math.round(((experts*10)/100))"
description="%Variable.description.4"
id="pointA"
is_array="false"
is_internal="false"
type="Operation">
<Restriction
type="lower_limit"
value="0">
</Restriction>
<Restriction
type="upper_limit"
value="99">
</Restriction>
<Relation
type="lower_than"
variable="pointB">
</Relation>
</Variable>
<Variable
default_value="2"
description="%Variable.description.5"
id="distance_measure_minkowski"
is_array="false"
is_internal="false"
type="Integer">
<Restriction
type="lower_limit"
value="1">
</Restriction>
</Variable>
<Variable
default_value="true"
description="%Variable.description.6"
id="fuzzycmeanson"
is_array="false"
is_internal="false"
type="Boolean">
</Variable>
</ConsensusModel>
</extension>
</plugin>
@@ -0,0 +1,197 @@
package afryca.consensusmodel;
import java.util.LinkedList;
import java.util.List;
import afryca.hpr.HPR;
import afryca.hpr.valuation.ExpertDegree;
import afryca.hpr.valuation.HesitantNumericValuation;
/**
*
* @author Rosa M. Rodriguez
*/
public class GenerateRecommendations {
GenerateRecommendations() {
}
public static List<Recommendation> recommendationsForGroup(List<HPR> hesitantPreferenceRelationsHierarchical, HPR collectiveMatrix, double consensusThreshold, List<Double> consensusAlternatives) {
List<Recommendation> recommendations = new LinkedList<Recommendation>();
double hprDistance, hprProximity, hesitantDistance, hesitantSim, averagePR, averagePRA;
int idGroup, idAlternative1, idAlternative2;
float averageCollective, averageHesitant;
averagePR = averageProximityRelation(hesitantPreferenceRelationsHierarchical, collectiveMatrix);
averagePR = truncateToTwoDecimals(averagePR);
for (HPR hpr : hesitantPreferenceRelationsHierarchical) {
hprDistance = collectiveMatrix.distanceEuclideanHesitantPreferenceRelations(hpr);
hprProximity = 1 - hprDistance;
hprProximity = truncateToTwoDecimals(hprProximity);
if (hprProximity <= averagePR) {
idGroup = hpr.getId();
for (int i = 0; i < hpr.getNumberOfAlternatives(); i++) {
double ca_i = consensusAlternatives.get(i);
if (ca_i <= consensusThreshold) {
averagePRA = averageProximityAlternative_i(hpr, collectiveMatrix, i);
averagePRA = truncateToTwoDecimals(averagePRA);
for (int j = i + 1; j < hpr.getNumberOfAlternatives(); j++) {
HesitantNumericValuation hesitant = (HesitantNumericValuation) hpr.getValue(i, j);
hesitantDistance = hesitant.distanceEuclideanHesitantFuzzySet((HesitantNumericValuation) collectiveMatrix.getValue(i, j));
hesitantSim = 1 - hesitantDistance;
hesitantSim = truncateToTwoDecimals(hesitantSim);
if (hesitantSim <= averagePRA) {// select pair of alternatives
idAlternative1 = i + 1;
idAlternative2 = j + 1;
// computeDirection
// averageCollective = ((HesitantNumericValuation) collectiveMatrix.getValue(i, j)).computeAverageHesitantFuzzySet();
// averageHesitant = hesitant.computeAverageHesitantFuzzySet();
averageCollective = ((HesitantNumericValuation) collectiveMatrix.getValue(i, j)).computeFscoreFahradiniaHesitantFuzzySet();
averageHesitant = hesitant.computeFscoreFahradiniaHesitantFuzzySet();
//Insertar la funcion
EChangeType direction = computeDirection(averageHesitant, averageCollective);
Recommendation recommendation = new Recommendation(idGroup, idAlternative1, idAlternative2, -1, direction);
recommendations.add(recommendation);
}
} // END-FOR
} // END-IF
} // END-FOR
}
} // END-FOR
return recommendations;
}
public static List<Recommendation> recommendationsForExperts(List<HPR> hesitantPreferenceRelations, List<HPR> hesitantPreferenceRelationsHierarchical, HPR collectiveMatrix,
double consensusThreshold, List<Double> consensusAlternatives) {
List<Recommendation> recommendations = new LinkedList<Recommendation>();
double hprDistance, hprProximity, hesitantDistance, hesitantSim, difference, averagePR, averagePRA;
int idGroup, idAlternative1, idAlternative2, idExpert;
float averageCollective, value;
averagePR = averageProximityRelation(hesitantPreferenceRelationsHierarchical, collectiveMatrix);
averagePR = truncateToTwoDecimals(averagePR);
for (int t = 0; t < hesitantPreferenceRelations.size(); t++) {
hprDistance = collectiveMatrix.distanceEuclideanHesitantPreferenceRelations(hesitantPreferenceRelationsHierarchical.get(t));
hprProximity = 1 - hprDistance;
hprProximity = truncateToTwoDecimals(hprProximity);
if (hprProximity <= averagePR) {
idGroup = hesitantPreferenceRelations.get(t).getId();
for (int i = 0; i < hesitantPreferenceRelations.get(t).getNumberOfAlternatives(); i++) {
double ca_i = consensusAlternatives.get(i);
if (ca_i <= consensusThreshold) {
averagePRA = averageProximityAlternative_i(hesitantPreferenceRelationsHierarchical.get(t), collectiveMatrix, i);
averagePRA = truncateToTwoDecimals(averagePRA);
for (int j = i + 1; j < hesitantPreferenceRelations.get(t).getNumberOfAlternatives(); j++) {
HesitantNumericValuation hesitant = (HesitantNumericValuation) hesitantPreferenceRelations.get(t).getValue(i, j);
HesitantNumericValuation hesitantHierarchical = (HesitantNumericValuation) hesitantPreferenceRelationsHierarchical.get(t).getValue(i, j);
hesitantDistance = hesitantHierarchical.distanceEuclideanHesitantFuzzySet((HesitantNumericValuation) collectiveMatrix.getValue(i, j));
hesitantSim = 1 - hesitantDistance;
hesitantSim = truncateToTwoDecimals(hesitantSim);
if (hesitantSim <= averagePRA) {// select pair of
// alternatives
idAlternative1 = i + 1;
idAlternative2 = j + 1;
for (ExpertDegree expertDegree : hesitant.getHesitantValues()) {
if (expertDegree.getId() != -1) {// it is a
// real
// expert
value = expertDegree.getDegree();
difference = 1 - ((HesitantNumericValuation) collectiveMatrix.getValue(i, j)).distanceValorHesitant(value);
difference = truncateToTwoDecimals(difference);
if (difference <= averagePRA) { // select
// expert
idExpert = expertDegree.getId();// computeDirection
// averageCollective = ((HesitantNumericValuation) collectiveMatrix.getValue(i, j)).computeAverageHesitantFuzzySet();
averageCollective = ((HesitantNumericValuation) collectiveMatrix.getValue(i, j)).computeFscoreFahradiniaHesitantFuzzySet();
EChangeType direction = computeDirection(value, averageCollective);
Recommendation recommendation = new Recommendation(idGroup, idAlternative1, idAlternative2, idExpert, direction);
recommendations.add(recommendation);
}
}
} // END-FOR
}
} // END-FOR
} // END-IF
} // END-FOR
}
} // END-FOR
return recommendations;
}
public static double averageProximityRelation(List<HPR> hesitantPreferenceRelations, HPR collectiveMatrix) {
double hprDistance, hprProximity, average;
double sum = 0;
for (HPR hpr : hesitantPreferenceRelations) {
hprDistance = collectiveMatrix.distanceEuclideanHesitantPreferenceRelations(hpr);
hprProximity = 1 - hprDistance;
sum += hprProximity;
}
average = sum / hesitantPreferenceRelations.size();
return average;
}
public static double averageProximityAlternative_i(HPR hpr, HPR collectiveMatrix, int alt_i) {
double hesitantDistance, hesitantSim, average;
double sum = 0;
int alt_j = hpr.getNumberOfAlternatives();
for (int j = 0; j < alt_j; j++) {
HesitantNumericValuation hesitant = (HesitantNumericValuation) hpr.getValue(alt_i, j);
hesitantDistance = hesitant.distanceEuclideanHesitantFuzzySet((HesitantNumericValuation) collectiveMatrix.getValue(alt_i, j));
hesitantSim = 1 - hesitantDistance;
sum += hesitantSim;
}
average = sum / alt_j;
return average;
}
public static double averageProximityAlternative(List<HPR> hesitantPreferenceRelations, HPR collectiveMatrix, int alt1, int alt2) {
double hesitantDistance, hesitantSim, average;
double sum = 0;
for (HPR hpr : hesitantPreferenceRelations) {
HesitantNumericValuation hesitant = (HesitantNumericValuation) hpr.getValue(alt1, alt2);
hesitantDistance = hesitant.distanceEuclideanHesitantFuzzySet((HesitantNumericValuation) collectiveMatrix.getValue(alt1, alt2));
hesitantSim = 1 - hesitantDistance;
sum += hesitantSim;
}
average = sum / hesitantPreferenceRelations.size();
return average;
}
public static EChangeType computeDirection(float value1, float value2) {
EChangeType direction = EChangeType.NotChange;
if (value1 < value2) {
direction = EChangeType.Increase;
} else {
if (value1 > value2) {
direction = EChangeType.Decrease;
}
}
return direction;
}
public static Double truncateToTwoDecimals(Double value) {
return Math.round(value * 100.0d) / 100.0d;
}
}
@@ -0,0 +1,93 @@
package afryca.consensusmodel;
/**
*
* @author Rosa M. Rodriguez
*/
public class Recommendation {
private int idCluster;
private int idAlternative1;
private int idAlternative2;
private int idExpert;
private EChangeType direction;
Recommendation(){
idCluster = -1;
idAlternative1 = -1;
idAlternative2 = -1;
idExpert = -1;
direction = EChangeType.NotChange;
}
Recommendation(int idCluster, int idAlternative1, int idAlternative2, int idExpert, EChangeType direction){
this();
setIdCluster(idCluster);
setIdAlternative1(idAlternative1);
setIdAlternative2(idAlternative2);
setIdExpert(idExpert);
setDirection(direction);
}
Recommendation(int idCluster, int idAlternative1, int idAlternative2, EChangeType direction){
this();
setIdCluster(idCluster);
setIdAlternative1(idAlternative1);
setIdAlternative2(idAlternative2);
setIdExpert(-1);
setDirection(direction);
}
public int getIdCluster() {
return idCluster;
}
private void setIdCluster(int idCluster) {
this.idCluster = idCluster;
}
public int getIdAlternative1() {
return idAlternative1;
}
private void setIdAlternative1(int idAlternative1) {
this.idAlternative1 = idAlternative1;
}
public int getIdAlternative2() {
return idAlternative2;
}
private void setIdAlternative2(int idAlternative2) {
this.idAlternative2 = idAlternative2;
}
public int getIdExpert() {
return idExpert;
}
private void setIdExpert(int idExpert) {
this.idExpert = idExpert;
}
public EChangeType getDirection() {
return direction;
}
private void setDirection(EChangeType direction) {
this.direction = direction;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("\nId cluster: " + idCluster);
result.append("\nExpert: "+ idExpert);
result.append("\n(A1,A2): " + "("+idAlternative1+","+idAlternative2+")");
result.append("\nDirection: " + direction);
result.append("\n");
return result.toString();
}
}
@@ -0,0 +1,717 @@
package afryca.consensusmodel;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import afryca.ase.RunnableScript;
import afryca.consensusmodel.cluster.ClusterFPR;
import afryca.consensusmodel.clustering.FuzzyCMeansFPR;
import afryca.consensusmodel.clustering.FuzzyKMeansFPR;
import afryca.consensusmodel.definition.EResultElements;
import afryca.consensusmodel.definition.ERoundResult;
import afryca.domain.fuzzyset.function.types.TrapezoidalFunction;
import afryca.domain.fuzzyset.semantic.IMembershipFunction;
import afryca.fpr.FPR;
import afryca.hpr.HPR;
import afryca.hpr.valuation.ExpertDegree;
import afryca.hpr.valuation.HesitantNumericValuation;
import afryca.pr.PR;
import afryca.consensumodel.addon.E4DIAddon;
public class Rodriguez2017HierarchicalClustering extends ConsensusModel {
private static final String CONSENSUS_MODEL_NAME = "Rodriguez (2017)"; //$NON-NLS-1$
private static final String CONSENSUS_THRESHOLD = "theta"; //$NON-NLS-1$
private static final String CONSENSUS_LEVEL = "delta"; //$NON-NLS-1$
private static final String MAX_ROUNDS = "max_rounds"; //$NON-NLS-1$
private static final String BETA = "beta"; //$NON-NLS-1$
private static final String POINT_A = "pointA"; //$NON-NLS-1$
private static final String POINT_B = "pointB"; //$NON-NLS-1$
private static final String DISTANCE_MEASURE_MINKOWSKI = "distance_measure_minkowski"; //$NON-NLS-1$
private static final String FUZZYCMEANSON = "fuzzycmeanson"; //$NON-NLS-1$
private float pointA;
private float pointB;
private float beta;
private boolean fuzzyCMeansOn;
private Float consensusDegree;
private Float consensusThreshold;
private Float consensusLevel;
private Integer maxRounds;
private int currentRound;
private int p;
private int[] advises;
private FPR consensusMatrix;
private FPR[] preferencesWithoutGroup;
private List<ClusterFPR> postClusters = new LinkedList<ClusterFPR>();
private List<ClusterFPR> clustersAfterChanges = new LinkedList<ClusterFPR>();
private List<HPR> postHesitantPreferenceRelationsHierarchical = new LinkedList<HPR>();
private List<HPR> postHesitantPreferenceRelations = new LinkedList<HPR>();
private List<Double> consensusAlternatives;
@Override
protected void setModelConfiguration() {
}
@Override
protected void obtainConfigurationValues() {
pointA = (Float) configuration.getValue(POINT_A);
pointB = (Float) configuration.getValue(POINT_B);
beta = (Float) configuration.getValue(BETA);
consensusThreshold = (Float) configuration.getValue(CONSENSUS_THRESHOLD);
consensusLevel = (Float) configuration.getValue(CONSENSUS_LEVEL);
maxRounds = (Integer) configuration.getValue(MAX_ROUNDS);
p = (Integer) configuration.getValue(DISTANCE_MEASURE_MINKOWSKI);
fuzzyCMeansOn = (Boolean) configuration.getValue(FUZZYCMEANSON);
currentRound = 0;
consensusDegree = 0f;
preferencesWithoutGroup = new FPR[preferences.length - 1];
initializePreferencesWithoutGroup();
initializeAdvises();
}
private void initializePreferencesWithoutGroup() {
// Copy preferences except groupal
for (int i = 0; i < preferences.length - 1; i++) {
try {
preferencesWithoutGroup[i] = (FPR) preferences[i].clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
}
private void initializeAdvises() {
advises = new int[experts.length];
for (int i = 0; i < advises.length; i++) {
advises[i] = 0;
}
}
@Override
protected Float[][][] obtainVisualizeValues() {
Float[][][] preferencesGroupVisualization = new Float[numberOfExperts + 1][numberOfAlternatives][numberOfAlternatives];
for (int k = 0; k < numberOfExperts+1; k++) {
preferencesGroupVisualization[k] = preferences[k].obtainVisualizeValues();
}
return preferencesGroupVisualization;
}
@Override
protected void preFirstSaveRoundResults() {
FPR consensusMatrixAux;
postClusters = generateClusters(alternatives, experts, (FPR[]) preferencesWithoutGroup, p);
postHesitantPreferenceRelationsHierarchical = generateHesitantHierarchical(postClusters, alternatives.length);
double consensusDegree = 0;
try {
consensusMatrixAux = computeConsensusMatrix(cloneHesitantPreferenceRelations(postHesitantPreferenceRelationsHierarchical));
consensusDegree = computeConsensusDegree(consensusMatrixAux);
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
postHesitantPreferenceRelations.clear();
for (int i = 0; i < postClusters.size(); i++) {
if(!postClusters.get(i).getExperts().isEmpty()){
postHesitantPreferenceRelations.add( generateHesitantPreferenceRelation(postClusters.get(i), alternatives.length));
}
}
HPR collective = computeCollective(postHesitantPreferenceRelationsHierarchical,postClusters);
computeGroupPreference(collective);
preSaveRoundResult(1, preferences,obtainVisualizeValues(), (float) consensusDegree);
roundsResults.get(roundsResults.size() - 1).put(ERoundResult.clusters, postClusters);
roundsResults.get(roundsResults.size() - 1).put(ERoundResult.hprs, postHesitantPreferenceRelationsHierarchical);
result.put(EResultElements.initial_consensus_degree, consensusDegree);
result.put(EResultElements.maxround, maxRounds);
result.put(EResultElements.consensus_threshold, consensusThreshold);
result.put(EResultElements.consensus_model, CONSENSUS_MODEL_NAME);
}
@Override
protected void preSaveRoundResults() {
preSaveRoundResult(currentRound + 1, preferences,obtainVisualizeValues(), (float) consensusDegree);
roundsResults.get(roundsResults.size() - 1).put(ERoundResult.clusters, postClusters);
roundsResults.get(roundsResults.size() - 1).put(ERoundResult.hprs, postHesitantPreferenceRelationsHierarchical);
}
@Override
protected void consensusRound() {
HPR collective = computeCollective(postHesitantPreferenceRelationsHierarchical,postClusters);
computeGroupPreference(collective);
consensusMatrix = computeConsensusMatrix(postHesitantPreferenceRelationsHierarchical);
consensusDegree = computeConsensusDegree(consensusMatrix);
consensusAlternatives = computeConsensusAlternatives(consensusMatrix);
// control consensus
if ((float) consensusDegree < consensusThreshold) {
// feedback
// obtain collective preference relation by HesitantWeightedMean
// aggregation operator
postHesitantPreferenceRelations.clear();
for (int i = 0; i < postClusters.size(); i++) {
if(!postClusters.get(i).getExperts().isEmpty()){
postHesitantPreferenceRelations.add( generateHesitantPreferenceRelation(postClusters.get(i), alternatives.length));
}
}
initializeAdvises();
List<Recommendation> recommendations;
if (consensusDegree >= consensusLevel) {
recommendations = GenerateRecommendations.recommendationsForExperts(postHesitantPreferenceRelations,postHesitantPreferenceRelationsHierarchical, collective, consensusThreshold, consensusAlternatives);
for (Recommendation r : recommendations) {
if (r.getIdExpert() != -1) {
advises[r.getIdExpert()] = 1;
}
}
} else {
// Consensus low. Recommend group
recommendations = GenerateRecommendations.recommendationsForGroup(postHesitantPreferenceRelationsHierarchical, collective, consensusThreshold, consensusAlternatives);
for (Recommendation r : recommendations) {
if (r.getIdExpert() != -1) {
advises[r.getIdExpert()] = 1;
}
}
}
if (!recommendations.isEmpty()) {
clustersAfterChanges = changePreferencesExperts(postClusters, recommendations);
FPR[] preferences = unifyPreferencesClusters(clustersAfterChanges);
postClusters = generateClusters(alternatives, experts, preferences, p);
postHesitantPreferenceRelationsHierarchical = generateHesitantHierarchical(postClusters, alternatives.length);
}
currentRound++;
}
}
private void computeGroupPreference(HPR collective) {
HPR HPRClone = null;
try {
HPRClone = (HPR) collective.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
FPR groupPreference = new FPR(alternatives.length);
orderHPRPreferences(HPRClone);
float value;
List<ExpertDegree> degrees;
for (int i = 0; i < HPRClone.getPreferences().length; i++) {
for (int j = 0; j < HPRClone.getPreferences()[i].length; j++) {
value = 0.5f;
int pos = ((HesitantNumericValuation) collective.getPreferences()[i][j]).getHesitantValues().size() / 2;
degrees = ((HesitantNumericValuation) collective.getPreferences()[i][j]).getHesitantValues();
if ((pos % 2) == 0 && pos!=0) {
value = ((float) degrees.get(pos - 1).getDegree() + (float) (degrees.get(pos).getDegree())) / 2f;
} else {
value = (float) degrees.get(pos).getDegree();
}
groupPreference.setValueSymmetrically(i, j, value);
}
}
preferences[numberOfExperts] = groupPreference;
}
private void orderHPRPreferences(HPR HPRClone) {
for (Object[] h : HPRClone.getPreferences()) {
for (Object hAux : h) {
((HesitantNumericValuation) hAux).OrderHesitantDegreesIncreasing();
}
}
}
@Override
protected void posSaveRoundResults() {
HPR collective = computeCollective(postHesitantPreferenceRelationsHierarchical,postClusters);
computeGroupPreference(collective);
consensusMatrix = computeConsensusMatrix(postHesitantPreferenceRelationsHierarchical);
consensusDegree = computeConsensusDegree(consensusMatrix);
consensusAlternatives = computeConsensusAlternatives(consensusMatrix);
posSaveRoundResult(preferences,obtainVisualizeValues(), (float) consensusDegree, advises, preferences[numberOfExperts]);
roundsResults.get(roundsResults.size() - 1).put(ERoundResult.clusters, postClusters);
roundsResults.get(roundsResults.size() - 1).put(ERoundResult.hprs, postHesitantPreferenceRelationsHierarchical);
}
@Override
protected boolean mustBeCarriedOutAnotherRound() {
return ((consensusDegree < consensusThreshold) && (currentRound < maxRounds));
}
@Override
protected void saveExecutionResults() {
this.configuration.setValue(PREFERENCES, preferences);
result.put(EResultElements.number_of_rounds_required, currentRound);
result.put(EResultElements.consensus_degree_achieved, consensusDegree);
}
public HPR computeCollective(List<HPR> HPRs, List<ClusterFPR> postClusters2){
List<HPR> hprs=new LinkedList<HPR>();
for (int i = 0; i < postClusters2.size(); i++) {
if(!postClusters2.get(i).getExperts().isEmpty()){
hprs.add( generateHesitantPreferenceRelation(postClusters.get(i), alternatives.length));
}
}
Double [] weights=obtainWeightsGroups(hprs);
return (HPR) ((RunnableScript) E4DIAddon.aseService
.createExecutionBuilder()
.setFunction("weithedAverageHPRWithWeights")
.putVariable("hesitant", HPRs)
.putVariable("weights", weights)
.execute())
.getResult();
}
@SuppressWarnings("unchecked")
public List<ClusterFPR> generateClusters(String[] alternatives, String[] experts, FPR[] preferences, int parameter) {
// Do clustering
if(fuzzyCMeansOn){
if (roundsResults.isEmpty()) {
return FuzzyCMeansFPR.doClusteringFuzzyCMeansClusterForEachAlternative(alternatives, experts, preferences, null, parameter);
} else {
return FuzzyCMeansFPR.doClusteringFuzzyCMeansClusterForEachAlternative(alternatives, experts, preferences, (List<ClusterFPR>) roundsResults.get(roundsResults.size() - 1).get(ERoundResult.clusters), parameter);
}
}else{
if (roundsResults.isEmpty()) {
return FuzzyKMeansFPR.doClusteringKMeans(alternatives, experts, preferences, null);
} else {
return FuzzyKMeansFPR.doClusteringKMeans(alternatives, experts, preferences, (List<ClusterFPR>) roundsResults.get(roundsResults.size() - 1).get(ERoundResult.clusters));
}
}
}
public List<HPR> generateHesitantHierarchical(List<ClusterFPR> clusters, int nAlternatives) {
List<HPR> hesitantPreferenceRelations = new LinkedList<HPR>();
int nElements=Integer.MAX_VALUE;
// obtain a hesitant preference relation for each cluster and the minimum number of element in a cluster
for (ClusterFPR cluster : clusters) {
if (!cluster.getExperts().isEmpty() && nElements > cluster.getExperts().size()) {
nElements=cluster.getExperts().size();
}
}
for (ClusterFPR cluster : clusters) {
if (!cluster.getExperts().isEmpty()) {
hesitantPreferenceRelations.add(normalizeHPRHierarchicalClustering(generateHesitantPreferenceRelation(cluster, nAlternatives),nElements,cluster));
}
}
return hesitantPreferenceRelations;
}
public HPR normalizeHPRHierarchicalClustering(HPR hpr,int nElements,ClusterFPR cluster){
if(nElements == cluster.getExperts().size()){
return hpr;
}
HPR hesitantPreferenceRelation = new HPR(hpr.getId(),nElements, hpr.getNumberOfAlternatives());
HesitantNumericValuation hnv1=new HesitantNumericValuation();
for(int i=0;i<nElements;i++){
hnv1.addHesitantValue(new ExpertDegree(0,0.5f));
}
HesitantNumericValuation[][] preferences = new HesitantNumericValuation[hpr.getNumberOfAlternatives()][hpr.getNumberOfAlternatives()];
for (int i = 0; i < preferences.length; i++) {
preferences[i][i]=hnv1;
}
for(int i=0;i<hpr.getNumberOfAlternatives()-1;i++){
for(int j=i+1;j<hpr.getNumberOfAlternatives();j++){
Float[] valuation=new Float[((HesitantNumericValuation)hpr.getPreferences()[i][j]).getNumHesitantValues()];
List<Integer> expertList = new LinkedList<Integer>();
for (int k = 0; k < valuation.length; k++) {
valuation[k]=((HesitantNumericValuation)hpr.getPreferences()[i][j]).getHesitantValues().get(k).getDegree();
expertList.add(((HesitantNumericValuation)hpr.getPreferences()[i][j]).getHesitantValues().get(k).getId());
}
HesitantNumericValuation hnv=new HesitantNumericValuation();
if(nElements!=1){
Integer[][] matrixValues = (Integer[][]) ((RunnableScript) E4DIAddon.aseService.createExecutionBuilder()
.setFunction("HierarchicalClustering")
.putVariable("hpr",valuation)
.putVariable("numElements", nElements)
.execute())
.getResult();
List<List<ExpertDegree>> valuationEachCluster = new LinkedList<List<ExpertDegree>>();
int cont=matrixValues[0][0];
List<ExpertDegree> valuationAux = new LinkedList<ExpertDegree>();
for (int k = 0; k < matrixValues[0].length; k++) {
if(cont==matrixValues[0][k]){
valuationAux.add(new ExpertDegree(expertList.get(matrixValues[1][k]),valuation[matrixValues[1][k]]));
}else{
valuationEachCluster.add(valuationAux);
valuationAux = new LinkedList<ExpertDegree>();
valuationAux.add(new ExpertDegree(expertList.get(matrixValues[1][k]),valuation[matrixValues[1][k]]));
cont=matrixValues[0][k];
}
if(k==matrixValues[0].length-1){
valuationEachCluster.add(valuationAux);
}
}
for(int k=0;k<valuationEachCluster.size();k++){
hnv.addHesitantValue(calculateRepresentative(valuationEachCluster.get(k)));
}
}else{
List<ExpertDegree> valuationAux = new LinkedList<ExpertDegree>();
for (int k = 0; k < valuation.length; k++) {
valuationAux.add(new ExpertDegree(expertList.get(k),valuation[k]));
}
hnv.addHesitantValue(calculateRepresentative(valuationAux));
}
preferences[i][j]=hnv;
preferences[j][i]=hnv.getReciprocalHesitantValues();
}
}
hesitantPreferenceRelation.setPreferences(preferences);
return hesitantPreferenceRelation;
}
public ExpertDegree calculateRepresentative(List<ExpertDegree> valuation){
if(valuation.size()==1) return valuation.get(0);
float media=0.0f;
for (int i = 0; i < valuation.size(); i++) {
media+=valuation.get(i).getDegree();
}
media/=(float)valuation.size();
ExpertDegree result=new ExpertDegree();
float minDistance=Float.MAX_VALUE;
for (int i = 0; i < valuation.size(); i++) {
float distance=Math.abs(media-valuation.get(i).getDegree());
if(distance < minDistance){
result=valuation.get(i);
minDistance=distance;
}
}
return result;
}
public static HPR generateHesitantPreferenceRelation(ClusterFPR cluster, int nAlternatives) {
HPR hesitantPreferenceRelation = new HPR(cluster.getId(), cluster.getExperts().size(), nAlternatives);
float value;
HesitantNumericValuation hnv1=new HesitantNumericValuation();
for(int i=0;i<cluster.getExperts().size();i++){
hnv1.addHesitantValue(new ExpertDegree(0,0.5f));
}
HesitantNumericValuation[][] preferences = new HesitantNumericValuation[nAlternatives][nAlternatives];
for (int i = 0; i < preferences.length; i++) {
preferences[i][i]=hnv1;
}
for (int i = 0; i < nAlternatives-1; i++) {
for (int j = i+1; j < nAlternatives; j++) {
HesitantNumericValuation hesitant = new HesitantNumericValuation();
for (Integer expert : cluster.getExperts()) {
value = (float) cluster.getPreferences().get(expert).getValue(i, j);
ExpertDegree expertDegree = new ExpertDegree(expert, value);
hesitant.addHesitantValue(expertDegree);
}
preferences[i][j] = hesitant;
preferences[j][i] = hesitant.getReciprocalHesitantValues();
}
}
hesitantPreferenceRelation.setPreferences(preferences);
return hesitantPreferenceRelation;
}
public FPR computeConsensusMatrix(List<HPR> HPRs) {
List<FPR> listSimilarityMatrix = new LinkedList<FPR>();
int nGroups = HPRs.size();
// Compute similarity matrix among hpr
for (int i = 0; i < nGroups - 1; i++) {
HPR hpr1 = HPRs.get(i);
for (int j = i + 1; j < nGroups; j++) {
HPR hpr2 = HPRs.get(j);
FPR similarityMatrix = hpr1.similarityMatrixHesitantPreferenceRelations(hpr2);
listSimilarityMatrix.add(similarityMatrix);
}
}
// Compute consensus matrix
FPR fpr = new FPR();
int nAlt = HPRs.get(0).getNumberOfAlternatives();
Float[][] consensusMatrix = new Float[nAlt][nAlt];
float sum;
float value;
for (int i = 0; i < nAlt; i++) {
for (int j = 0; j < nAlt; j++) {
sum = 0;
for (FPR similarityMatrix : listSimilarityMatrix) {
sum += (float) similarityMatrix.getValue(i, j);
}
value = sum / listSimilarityMatrix.size();
consensusMatrix[i][j] = value;
}
}
fpr.prepareStructureForPreferences(consensusMatrix);
return fpr;
}
public float computeConsensusDegree(FPR matrix) {
List<Float> ca = new LinkedList<Float>();
float consensusDegree;
float sum;
for (int i = 0; i < matrix.getNumberOfAlternatives(); i++) {
sum = 0;
for (int j = 0; j < matrix.getNumberOfAlternatives(); j++) {
if (i != j)
sum += (float) matrix.getValue(i, j);
}
sum = sum / (matrix.getNumberOfAlternatives() - 1);
ca.add(sum);
}
sum = 0;
for (Float v : ca) {
sum += v;
}
consensusDegree = sum / matrix.getNumberOfAlternatives();
consensusDegree = truncateToTwoDecimals(consensusDegree);
return consensusDegree;
}
public List<Double> computeConsensusAlternatives(FPR matrix) {
List<Double> ca = new LinkedList<Double>();
double sum;
for (int i = 0; i < matrix.getNumberOfAlternatives(); i++) {
sum = 0;
for (int j = 0; j < matrix.getNumberOfAlternatives(); j++) {
if (i != j)
sum += (float) matrix.getValue(i, j);
}
sum = sum / (matrix.getNumberOfAlternatives() - 1);
sum = truncateToTwoDecimals(sum);
ca.add(sum);
}
return ca;
}
public double truncateToTwoDecimals(double value) {
return (double) (Math.round(value * 100.0d) / 100.0d);
}
public float truncateToTwoDecimals(float value) {
return (float) (Math.round(value * 100.0d) / 100.0d);
}
public FPR[] unifyPreferencesClusters(List<ClusterFPR> clusters) {
Map<Integer, PR> allPreferences = new HashMap<Integer, PR>();
Map<Integer, PR> preferences = null;
FPR[] result;
for (ClusterFPR cluster : clusters) {
if (!cluster.getExperts().isEmpty()) {
preferences = cluster.getPreferences();
allPreferences.putAll(preferences);
}
}
result = new FPR[allPreferences.size()];
Map<Integer, PR> treeMap = new TreeMap<Integer, PR>(allPreferences);
for (Integer str : treeMap.keySet()) {
result[str] = (FPR) treeMap.get(str);
}
return result;
}
public List<ClusterFPR> changePreferencesExperts(List<ClusterFPR> clusters, List<Recommendation> recommendations) {
List<ClusterFPR> postClusters = new LinkedList<ClusterFPR>();
for (ClusterFPR cluster : clusters) {
if (!cluster.getExperts().isEmpty()) {
ClusterFPR postCluster = changePreferences(cluster, recommendations);
postClusters.add(postCluster);
}
}
return postClusters;
}
private ClusterFPR changePreferences(ClusterFPR cluster, List<Recommendation> recommendations) {
double change = 0;
int nChanges=0;
for (Recommendation recommendation : recommendations) {
if(recommendation.getIdCluster()==cluster.getId()){
nChanges++;
}
}
double [] changesIndividual=getNChanges(nChanges);
int n=0;
try {
ClusterFPR postCluster = (ClusterFPR) cluster.clone();
// Random random = new Random();//añadido
for (Recommendation recommendation : recommendations) {
int m=0;
if (cluster.getId() == recommendation.getIdCluster()) {
int idAlt1 = recommendation.getIdAlternative1();
int idAlt2 = recommendation.getIdAlternative2();
int idExpert = recommendation.getIdExpert();
if (idExpert != -1) {// change expert' preference
if(changesIndividual[n]!=0){
change=changesIndividual[n];
float value = (float) ((FPR) cluster.getPreferencesExpert(idExpert)).getValue(idAlt1 - 1, idAlt2 - 1);
if (recommendation.getDirection() == EChangeType.Increase) {
value += change;
if (value > 1){
value = 1f;
}else if(value < 0){
value=0f;
}
} else {
if (recommendation.getDirection() == EChangeType.Decrease) {
value -= change;
if (value < 0){
value = 0f;
}else if(value > 1){
value=1f;
}
}
}
((FPR) postCluster.getPreferencesExpert(idExpert)).setValueSymmetrically(idAlt1 - 1, idAlt2 - 1, value);
((FPR) preferences[idExpert]).setValueSymmetrically(idAlt1 - 1, idAlt2 - 1, value);
}
n++;
} else {// change preferences for all experts
double [] changes=getNChanges(cluster.getExperts().size());
for (Integer expert : cluster.getExperts()) {
if(changes[m]!=0){
change=changes[m];
float value = (float) ((FPR) cluster.getPreferencesExpert(expert)).getValue(idAlt1 - 1, idAlt2 - 1);
if (recommendation.getDirection() == EChangeType.Increase) {
value += change;
if (value > 1){
value = 1f;
}else if(value < 0){
value=0f;
}
} else {
if (recommendation.getDirection() == EChangeType.Decrease) {
value -= change;
if (value < 0){
value = 0f;
}else if(value > 1){
value=1f;
}
}
}
((FPR) postCluster.getPreferencesExpert(expert)).setValueSymmetrically(idAlt1 - 1, idAlt2 - 1,value);
((FPR) preferences[expert]).setValueSymmetrically(idAlt1 - 1, idAlt2 - 1, value);
}
m++;
} // END-FOR
}
}
} // END-FOR
return postCluster;
} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
}
}
private List<HPR> cloneHesitantPreferenceRelations(List<HPR> input) throws CloneNotSupportedException {
List<HPR> hesitantPreferenceRelations = new LinkedList<HPR>();
for (HPR hpr : input) {
hesitantPreferenceRelations.add((HPR) hpr.clone());
}
return hesitantPreferenceRelations;
}
private static double powerFunction(double valor1,double valor2,double beta) {
double result=0;
result=Math.pow(1+valor2,valor1*beta);
return result;
}
public Double[] obtainWeightsGroups(List<HPR> hesitantPreferenceRelations){
Double[] weights = new Double[hesitantPreferenceRelations.size()];
double cohesion,size,degreeSize;
double[] func={pointA,pointB,100,100};
//Membership function for the atribute size. It is necessary to fix (a,b)
IMembershipFunction membershipFunctionSize = new TrapezoidalFunction(func);
int k=0;
for (HPR hpr: hesitantPreferenceRelations){
cohesion = hpr.computeCohesionHesitantPreferenceRelation();
size = hpr.getNExperts();
degreeSize = membershipFunctionSize.getMembershipValue(size);
weights[k]=powerFunction(cohesion, degreeSize,beta);
k++;
}
//Normalization weights
double sum = 0;
for (int i = 0; i < hesitantPreferenceRelations.size(); i++){
sum += weights[i];
}
Double[] weightsNorm = new Double[hesitantPreferenceRelations.size()];
for (int i = 0; i < hesitantPreferenceRelations.size(); i++){
weightsNorm[i]=weights[i]/sum;
}
return weightsNorm;
}
}
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: afryca.consensusmodel.rodriguez2018HierarchicalClus
tering;singleton:=true
Bundle-Version: 1.0.0.202101221157
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: afryca.consensusmodel,afryca.hpr,afryca.fpr
Automatic-Module-Name: afryca.consensusmodel.Rodriguez2018HierarchicalCl
ustering
@@ -0,0 +1,4 @@
#Fri Jan 22 13:01:40 CET 2021
artifact.main=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\afryca.consensusmodel.Rodriguez2018HierarchicalClustering\\target\\afryca.consensusmodel.rodriguez2018HierarchicalClustering-1.0.0-SNAPSHOT.jar
artifact.attached.p2artifacts=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\afryca.consensusmodel.Rodriguez2018HierarchicalClustering\\target\\p2artifacts.xml
artifact.attached.p2metadata=C\:\\Users\\\u00C1lvaro\\Workspaces\\afryca_2020\\afryca\\plugins\\afryca.consensusmodel.Rodriguez2018HierarchicalClustering\\target\\p2content.xml
@@ -0,0 +1,3 @@
artifactId=afryca.consensusmodel.rodriguez2018HierarchicalClustering
groupId=afryca.group
version=1.0.0-SNAPSHOT
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<?artifactRepository version='1.1.0'?>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='afryca.consensusmodel.rodriguez2018HierarchicalClustering' version='1.0.0.202101221157'>
<properties size='5'>
<property name='artifact.size' value='19613'/>
<property name='download.size' value='19613'/>
<property name='maven-groupId' value='afryca.group'/>
<property name='maven-artifactId' value='afryca.consensusmodel.rodriguez2018HierarchicalClustering'/>
<property name='maven-version' value='1.0.0-SNAPSHOT'/>
</properties>
</artifact>
</artifacts>
@@ -0,0 +1,45 @@
<?xml version='1.0' encoding='UTF-8'?>
<units size='1'>
<unit id='afryca.consensusmodel.rodriguez2018HierarchicalClustering' version='1.0.0.202101221157' generation='2'>
<update id='afryca.consensusmodel.rodriguez2018HierarchicalClustering' range='[0.0.0,1.0.0.202101221157)' severity='0'/>
<properties size='5'>
<property name='df_LT.Bundle-Name' value='Rodriguez2018HierarchicalClustering'/>
<property name='org.eclipse.equinox.p2.name' value='%Bundle-Name'/>
<property name='maven-groupId' value='afryca.group'/>
<property name='maven-artifactId' value='afryca.consensusmodel.rodriguez2018HierarchicalClustering'/>
<property name='maven-version' value='1.0.0-SNAPSHOT'/>
</properties>
<provides size='5'>
<provided namespace='org.eclipse.equinox.p2.iu' name='afryca.consensusmodel.rodriguez2018HierarchicalClustering' version='1.0.0.202101221157'/>
<provided namespace='osgi.bundle' name='afryca.consensusmodel.rodriguez2018HierarchicalClustering' version='1.0.0.202101221157'/>
<provided namespace='osgi.identity' name='afryca.consensusmodel.rodriguez2018HierarchicalClustering' version='1.0.0.202101221157'>
<properties size='1'>
<property name='type' value='osgi.bundle'/>
</properties>
</provided>
<provided namespace='org.eclipse.equinox.p2.eclipse.type' name='bundle' version='1.0.0'/>
<provided namespace='org.eclipse.equinox.p2.localization' name='df_LT' version='1.0.0'/>
</provides>
<requires size='4'>
<required namespace='osgi.bundle' name='afryca.consensusmodel' range='0.0.0'/>
<required namespace='osgi.bundle' name='afryca.hpr' range='0.0.0'/>
<required namespace='osgi.bundle' name='afryca.fpr' range='0.0.0'/>
<requiredProperties namespace='osgi.ee' match='(&amp;(osgi.ee=JavaSE)(version=1.8))'>
<description>
afryca.consensusmodel.rodriguez2018HierarchicalClustering
</description>
</requiredProperties>
</requires>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='afryca.consensusmodel.rodriguez2018HierarchicalClustering' version='1.0.0.202101221157'/>
</artifacts>
<touchpoint id='org.eclipse.equinox.p2.osgi' version='1.0.0'/>
<touchpointData size='1'>
<instructions size='1'>
<instruction key='manifest'>
Bundle-SymbolicName: afryca.consensusmodel.rodriguez2018HierarchicalClustering;singleton:=true&#xA;Bundle-Version: 1.0.0.202101221157&#xA;
</instruction>
</instructions>
</touchpointData>
</unit>
</units>