Files
AFRYCA/plugins/afryca.consensusmodel.Rodriguez2018HierarchicalClustering/src/afryca/consensusmodel/GenerateRecommendations.java
T
2026-05-22 11:14:29 +02:00

198 lines
8.3 KiB
Java

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;
}
}