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

90 lines
3.9 KiB
Java

package afryca.consensusmodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import afryca.cm.CM;
import afryca.consensusmodel.cluster.ClusterFPR;
import afryca.fpr.FPR;
public class GenerateRecommendations {
public static List<Recommendation> recommendationsForGroup(List<ClusterFPR> cluster, FPR collectiveMinimumCost,ArrayList<Double> proximityValues, Float [] consensusAlternatives,
ArrayList<CM> proximityMatrix,double proximityAverage,CM proximityMatrixAverage, Float consensusThreshold){
int numberOfAlternatives=consensusAlternatives.length;
List<Recommendation> recommendations = new LinkedList<Recommendation>();
for (int cl = 0; cl < cluster.size(); cl++) {
if(!cluster.get(cl).getExperts().isEmpty()){
if(Math.round(proximityValues.get(cl)*10000d)/10000d <= Math.round(proximityAverage*10000d)/10000d){
for (int alt = 0; alt < numberOfAlternatives; alt++) {
if(Math.round(consensusAlternatives[alt]*10000d)/10000d <= Math.round(consensusThreshold*10000d)/10000d){
for (int j = 0; j < numberOfAlternatives; j++) {
if( alt!=j && alt<j){
if(Math.round((float)proximityMatrix.get(cl).getValue(alt, j)*10000d)/10000d <= Math.round((float)proximityMatrixAverage.getValue(alt, j)*10000d)/10000d){
for(int key:cluster.get(cl).getPreferences().keySet()){ //Each expert in a cluster
EChangeType direction = computeDirection((float)cluster.get(cl).getPreferences().get(key).getValue(alt,j), (float)collectiveMinimumCost.getValue(alt,j));
Recommendation recommendation = new Recommendation(cluster.get(cl).getId(),alt,j,key,direction);
recommendations.add(recommendation);
}
}
}
}
}
}
}
}
}
return recommendations;
}
public static List<Recommendation> recommendationsIndividual(List<ClusterFPR> cluster, FPR collective,ArrayList<Double> proximityValues, Float [] consensusAlternatives,
ArrayList<CM> proximityMatrix,double proximityAverage,CM proximityMatrixAverage, Float consensusThreshold, Integer lamda){
int numberOfAlternatives=consensusAlternatives.length;
List<Recommendation> recommendations = new LinkedList<Recommendation>();
for (int cl = 0; cl < cluster.size(); cl++) {
if(!cluster.get(cl).getExperts().isEmpty()){
if(Math.round(proximityValues.get(cl)*10000d)/10000d <= Math.round(proximityAverage*10000d)/10000d){
for (int alt = 0; alt < numberOfAlternatives; alt++) {
if(Math.round(consensusAlternatives[alt]*10000d)/10000d <= Math.round(consensusThreshold*10000d)/10000d){
for (int j = 0; j < numberOfAlternatives; j++) {
if( alt!=j && alt<j){
if(Math.round((float)proximityMatrix.get(cl).getValue(alt, j)*10000d)/10000d <= Math.round((float)proximityMatrixAverage.getValue(alt, j)*10000d)/10000d && alt!=j){
for(int key:cluster.get(cl).getPreferences().keySet()){ //Each expert in a cluster
if(1f-ConsensusEngine.distanceMinkowskiValues((float)collective.getValue(alt,j), (float)cluster.get(cl).getPreferences().get(key).getValue(alt,j), lamda)
<= (float)proximityMatrixAverage.getValue(alt, j)){
EChangeType direction = computeDirection(1f,2f);
Recommendation recommendation = new Recommendation(cluster.get(cl).getId(),alt,j,key,direction);
recommendations.add(recommendation);
}
}
}
}
}
}
}
}
}
}
return recommendations;
}
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;
}
}