|
|
|
@@ -0,0 +1,755 @@
|
|
|
|
|
package flintstones.method.linguistic.topsis.phase.experts;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
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 org.eclipse.e4.core.services.nls.Translation;
|
|
|
|
|
|
|
|
|
|
import flintstones.domain.fuzzyset.FuzzySet;
|
|
|
|
|
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
|
|
|
|
import flintstones.domain.numeric.NumericDomain;
|
|
|
|
|
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.linguistic.topsis.phase.experts.messages.Messages;
|
|
|
|
|
import flintstones.model.domain.service.IDomainService;
|
|
|
|
|
import flintstones.model.problemelement.service.IProblemElementService;
|
|
|
|
|
import flintstones.model.valuation.service.IValuationService;
|
|
|
|
|
import flintstones.operator.unification.service.IUnificationOperatorService;
|
|
|
|
|
import flintstones.valuation.linguistic.LinguisticValuation;
|
|
|
|
|
import flintstones.valuation.numeric.NumericIntervalarValuation;
|
|
|
|
|
import flintstones.valuation.numeric.NumericValuation;
|
|
|
|
|
import flintstones.valuation.numeric.integer.IntegerValuation;
|
|
|
|
|
import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation;
|
|
|
|
|
import flintstones.valuation.numeric.real.RealValuation;
|
|
|
|
|
import flintstones.valuation.numeric.real.interval.RealIntervalValuation;
|
|
|
|
|
import flintstones.valuation.twoTuple.TwoTupleValuation;
|
|
|
|
|
|
|
|
|
|
public class ExpertsInfo extends PhaseMethod {
|
|
|
|
|
|
|
|
|
|
private Map<Expert, HashMap<Domain, Valuation[]>> weights = new HashMap<Expert, HashMap<Domain, Valuation[]>>();
|
|
|
|
|
private Map<Expert, Valuation[]> positiveIdealSolution = new HashMap<Expert, Valuation[]>();
|
|
|
|
|
private Map<Expert, Valuation[]> negativeIdealSolution = new HashMap<Expert, Valuation[]>();
|
|
|
|
|
private Map<Expert, Valuation[]> globalPositiveIdealSolutionDistance = new HashMap<Expert, Valuation[]>();
|
|
|
|
|
private Map<Expert, Valuation[]> globalNegativeIdealSolutionDistance = new HashMap<Expert, Valuation[]>();
|
|
|
|
|
private Map<Expert, Valuation[]> closenessCoefficients = new HashMap<Expert, Valuation[]>();
|
|
|
|
|
private Map<Expert, Valuation[][]> weightedDecisionMatrices = new HashMap<Expert, Valuation[][]>();
|
|
|
|
|
private Map<Expert, Valuation[][]> distancePositiveIdealSolutionMatrices = new HashMap<Expert, Valuation[][]>();
|
|
|
|
|
private Map<Expert, Valuation[][]> distanceNegativeIdealSolutionMatrices = new HashMap<Expert, Valuation[][]>();
|
|
|
|
|
|
|
|
|
|
private Domain weightsDomain;
|
|
|
|
|
private FuzzySet unificationDomainValuations;
|
|
|
|
|
private FuzzySet unificationDomainWeights;
|
|
|
|
|
private FuzzySet unificationDomainDistances;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
IEclipseContext context;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
@Translation
|
|
|
|
|
private Messages messages;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
private IProblemElementService problemService;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
private IValuationService valuationService;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
private IDomainService domainService;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
private IUnificationOperatorService unificationService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return messages.Phase_Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FuzzySet getUnificationDomainValuations() {
|
|
|
|
|
return this.unificationDomainValuations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setWeightsDomain(String domainName) {
|
|
|
|
|
this.weightsDomain = domainService.getByName(domainName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setUnificationDomainValuations() {
|
|
|
|
|
this.unificationDomainValuations = (FuzzySet) importData("unifiedDomain");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUnificationDomainWeights(String domainName) {
|
|
|
|
|
this.unificationDomainWeights = (FuzzySet) domainService.getByName(domainName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUnificationDomainDistances(String domainName) {
|
|
|
|
|
this.unificationDomainDistances = (FuzzySet) domainService.getByName(domainName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProblemElement[] getExperts() {
|
|
|
|
|
return problemService.getAll(Expert.Type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumberExperts() {
|
|
|
|
|
return getExperts().length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getExpertName(int pos) {
|
|
|
|
|
return getExperts()[pos].getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String[] getExpertsNames() {
|
|
|
|
|
ProblemElement[] experts = getExperts();
|
|
|
|
|
|
|
|
|
|
String[] names = new String[experts.length];
|
|
|
|
|
for(int i = 0; i < experts.length; ++i)
|
|
|
|
|
names[i] = experts[i].getName();
|
|
|
|
|
|
|
|
|
|
return names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProblemElement[] getCriteria() {
|
|
|
|
|
return problemService.getAll(Criterion.Type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getCriterionName(int pos) {
|
|
|
|
|
return getCriteria()[pos].getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumberCriteria() {
|
|
|
|
|
return getCriteria().length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumberAlternatives() {
|
|
|
|
|
return getAlternatives().length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProblemElement[] getAlternatives() {
|
|
|
|
|
return problemService.getAll(Alternative.Type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAlternativeName(int pos) {
|
|
|
|
|
return getAlternatives()[pos].getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String[] getLinguisticDomainNames() {
|
|
|
|
|
ArrayList<String> names = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
Domain[] domains = domainService.getAll();
|
|
|
|
|
for(Domain domain: domains) {
|
|
|
|
|
if(domain instanceof FuzzySet)
|
|
|
|
|
names.add(domain.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return names.toArray(new String[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String[] getDomainNames() {
|
|
|
|
|
Domain[] domains = domainService.getAll();
|
|
|
|
|
|
|
|
|
|
String[] names = new String[domains.length];
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < names.length; ++i) {
|
|
|
|
|
names[i] = domains[i].getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String[] getLabelsNameDomainWeightsExpert(int posExpert) {
|
|
|
|
|
ArrayList<String> names = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
FuzzySet domain = (FuzzySet) weightsDomain;
|
|
|
|
|
List<LabelLinguisticDomain> labels = domain.getLabelSet().getLabels();
|
|
|
|
|
for(LabelLinguisticDomain label: labels)
|
|
|
|
|
names.add(label.getName());
|
|
|
|
|
|
|
|
|
|
return names.toArray(new String[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean domainWeightsIsFuzzySet(int posExpert) {
|
|
|
|
|
if(weightsDomain instanceof FuzzySet)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Valuation getValuation(int posCriterion, int posExpert, int posAlternative) {
|
|
|
|
|
return valuationService.getAllKV().get(new ProblemElementKey(getExperts()[posExpert],
|
|
|
|
|
getCriteria()[posCriterion], getAlternatives()[posAlternative]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringWeightedValuation(int posCriterion, int posAlternative, int posExpert) {
|
|
|
|
|
if(weightedDecisionMatrices.get(getExperts()[posExpert]) != null) {
|
|
|
|
|
Valuation[][] weigthedDecisionMatrix = weightedDecisionMatrices.get((getExperts()[posExpert]));
|
|
|
|
|
return weigthedDecisionMatrix[posAlternative][posCriterion].changeFormatValuationToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Valuation getExpertWeight(int posCriterion, int posExpert) {
|
|
|
|
|
ProblemElement expert = getExperts()[posExpert];
|
|
|
|
|
|
|
|
|
|
Valuation[] weights = getWeightsByDomain(expert);
|
|
|
|
|
|
|
|
|
|
return weights[posCriterion];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Valuation[] getWeightsByDomain(ProblemElement expert) {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomains = weights.get(expert);
|
|
|
|
|
return weightsForDomains.get(weightsDomain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringExpertWeight(int posCriterion, int posExpert) {
|
|
|
|
|
return getExpertWeight(posCriterion, posExpert).changeFormatValuationToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setExpertWeight(int posCriterion, int posExpert, String weight) {
|
|
|
|
|
String valuationId = valuationService.getExtensionIdFor(weightsDomain.getType());
|
|
|
|
|
|
|
|
|
|
Valuation v;
|
|
|
|
|
if(valuationId.equals(IntegerIntervalValuation.ID)) {
|
|
|
|
|
String format = weight.replace("(", "");
|
|
|
|
|
format = format.replace(")", "");
|
|
|
|
|
format = format.replace("[", "");
|
|
|
|
|
format = format.replace("]", "");
|
|
|
|
|
String[] values = format.split(",");
|
|
|
|
|
|
|
|
|
|
v = ContextInjectionFactory.make(IntegerIntervalValuation.class, context);
|
|
|
|
|
v.setDomain(weightsDomain);
|
|
|
|
|
((NumericIntervalarValuation) v).setMinMax(Double.parseDouble(values[0]), Double.parseDouble(values[1]));
|
|
|
|
|
} else if(valuationId.equals(RealIntervalValuation.ID)) {
|
|
|
|
|
String format = weight.replace("(", "");
|
|
|
|
|
format = format.replace(")", "");
|
|
|
|
|
format = format.replace("[", "");
|
|
|
|
|
format = format.replace("]", "");
|
|
|
|
|
String[] values = format.split(",");
|
|
|
|
|
|
|
|
|
|
v = ContextInjectionFactory.make(RealIntervalValuation.class, context);
|
|
|
|
|
v.setDomain(weightsDomain);
|
|
|
|
|
((NumericIntervalarValuation) v).setMinMax(Double.parseDouble(values[0]), Double.parseDouble(values[1]));
|
|
|
|
|
} else if (valuationId.equals(IntegerValuation.ID)) {
|
|
|
|
|
v = ContextInjectionFactory.make(IntegerValuation.class, context);
|
|
|
|
|
v.setDomain(weightsDomain);
|
|
|
|
|
double w = Double.parseDouble(weight);
|
|
|
|
|
((NumericValuation) v).setValue(w);
|
|
|
|
|
} else if(valuationId.equals(RealValuation.ID)) {
|
|
|
|
|
v = ContextInjectionFactory.make(RealValuation.class, context);
|
|
|
|
|
v.setDomain(weightsDomain);
|
|
|
|
|
double w = Double.parseDouble(weight);
|
|
|
|
|
((NumericValuation) v).setValue(w);
|
|
|
|
|
} else {
|
|
|
|
|
v = ContextInjectionFactory.make(LinguisticValuation.class, context);
|
|
|
|
|
v.setDomain(weightsDomain);
|
|
|
|
|
((LinguisticValuation) v).setLabel(weight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Valuation[] expertWeights;
|
|
|
|
|
ProblemElement expert = getExperts()[posExpert];
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = weights.get(expert);
|
|
|
|
|
|
|
|
|
|
if(weights.get(expert) != null) {
|
|
|
|
|
if(weightsForDomain != null) {
|
|
|
|
|
expertWeights = weightsForDomain.get(weightsDomain);
|
|
|
|
|
expertWeights[posCriterion] = v;
|
|
|
|
|
} else {
|
|
|
|
|
weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
expertWeights = new Valuation[getNumberCriteria()];
|
|
|
|
|
expertWeights[posCriterion] = v;
|
|
|
|
|
weightsForDomain.put(weightsDomain, expertWeights);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
expertWeights = new Valuation[getNumberCriteria()];
|
|
|
|
|
expertWeights[posCriterion] = v;
|
|
|
|
|
weightsForDomain.put(weightsDomain, expertWeights);
|
|
|
|
|
weights.put((Expert) expert, weightsForDomain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void execute(int posExpert) {
|
|
|
|
|
setUnificationDomainValuations();
|
|
|
|
|
computeWeightedDecisionMatrixExpert(posExpert);
|
|
|
|
|
computeSolutions(posExpert);
|
|
|
|
|
computeDistanceSolutions(posExpert);
|
|
|
|
|
computeGlobalDistancesIdealSolutions(posExpert);
|
|
|
|
|
computeClosenessCoefficients(posExpert);
|
|
|
|
|
exportInfoToNextStep();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeWeightedDecisionMatrixExpert(int posExpert) {
|
|
|
|
|
Valuation[] expertUnifiedWeights = unifyWeights(posExpert);
|
|
|
|
|
|
|
|
|
|
if(expertUnifiedWeights != null && expertUnifiedWeights.length == getCriteria().length) {
|
|
|
|
|
TwoTupleValuation[][] expertDecisionMatrix = getExpertDecisionMatrix(posExpert);
|
|
|
|
|
TwoTupleValuation[][] expertWeightedDecisionmMatrix = computeWeightedDecisionMatrix(expertDecisionMatrix, expertUnifiedWeights);
|
|
|
|
|
weightedDecisionMatrices.put((Expert) getExperts()[posExpert], expertWeightedDecisionmMatrix);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Valuation[] unifyWeights(int posExpert) {
|
|
|
|
|
ProblemElement expert = getExperts()[posExpert];
|
|
|
|
|
|
|
|
|
|
Valuation[] expertWeights = weights.get(expert).get(weightsDomain);
|
|
|
|
|
Valuation[] expertUnifiedWeights = new Valuation[expertWeights.length];
|
|
|
|
|
|
|
|
|
|
String methodId = (String) this.importDataFromMethod("methodId"), finalValuationId = (String) this.importDataFromMethod("finalValuationId");
|
|
|
|
|
for(int i = 0; i < expertWeights.length; ++i) {
|
|
|
|
|
if(expertWeights[i] != null) {
|
|
|
|
|
expertUnifiedWeights[i] = unificationService.unify(unificationDomainWeights, expertWeights[i], finalValuationId, methodId);
|
|
|
|
|
} else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expertUnifiedWeights;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TwoTupleValuation[][] getExpertDecisionMatrix(int posExpert) {
|
|
|
|
|
ProblemElement[] alternatives = getAlternatives(), criteria = getCriteria();
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation[][] decisionMatrix = new TwoTupleValuation[alternatives.length][criteria.length];
|
|
|
|
|
|
|
|
|
|
Map<ProblemElementKey, TwoTupleValuation> expertUnifiedValuations = getTwoTupleValuations();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < alternatives.length; ++i) {
|
|
|
|
|
for (int j = 0; j < criteria.length; ++j) {
|
|
|
|
|
decisionMatrix[i][j] = expertUnifiedValuations.get(new ProblemElementKey(getExperts()[posExpert], criteria[j], alternatives[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decisionMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private Map<ProblemElementKey, TwoTupleValuation> getTwoTupleValuations() {
|
|
|
|
|
Map<ProblemElementKey, TwoTupleValuation> twoTuple = (Map<ProblemElementKey, TwoTupleValuation>) importData(
|
|
|
|
|
"twoTupleUnifiedValuations");
|
|
|
|
|
exportData("twoTupleValuations", twoTuple);
|
|
|
|
|
return twoTuple;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TwoTupleValuation[][] computeWeightedDecisionMatrix(TwoTupleValuation[][] expertDecisionMatrix,
|
|
|
|
|
Valuation[] expertUnifiedWeights) {
|
|
|
|
|
|
|
|
|
|
ProblemElement[] alternatives = getAlternatives(), criteria = getCriteria();
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation[][] weightedDecisionMatrix = new TwoTupleValuation[alternatives.length][criteria.length];
|
|
|
|
|
|
|
|
|
|
LabelLinguisticDomain maxLabel = unificationDomainWeights.getLabelSet().getLabel(unificationDomainWeights.getLabelSet().getCardinality() - 1);
|
|
|
|
|
TwoTupleValuation maxLabelTwoTuple = new TwoTupleValuation(unificationDomainWeights, maxLabel);
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation weight, valuation, weightedValuation;
|
|
|
|
|
for (int i = 0; i < expertDecisionMatrix.length; ++i) {
|
|
|
|
|
for (int j = 0; j < expertDecisionMatrix[i].length; ++j) {
|
|
|
|
|
weight = (TwoTupleValuation) expertUnifiedWeights[j];
|
|
|
|
|
valuation = (TwoTupleValuation) expertDecisionMatrix[i][j];
|
|
|
|
|
weightedValuation = new TwoTupleValuation(unificationDomainValuations);
|
|
|
|
|
weightedValuation.calculateDelta(valuation.calculateInverseDelta() * (weight.calculateInverseDelta() / maxLabelTwoTuple.calculateInverseDelta()));
|
|
|
|
|
weightedDecisionMatrix[i][j] = weightedValuation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return weightedDecisionMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeSolutions(int posExpert) {
|
|
|
|
|
computePositiveIdealSolution(posExpert);
|
|
|
|
|
computeNegativeIdealSolution(posExpert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computePositiveIdealSolution(int posExpert) {
|
|
|
|
|
Valuation[] idealSolution = new Valuation[getNumberCriteria()];
|
|
|
|
|
|
|
|
|
|
List<Valuation> valuationsCriterion;
|
|
|
|
|
|
|
|
|
|
boolean isCost;
|
|
|
|
|
|
|
|
|
|
for (int crit = 0; crit < getNumberCriteria(); ++crit) {
|
|
|
|
|
|
|
|
|
|
valuationsCriterion = getValuationsExpertByCriterion(posExpert, crit);
|
|
|
|
|
|
|
|
|
|
isCost = ((Criterion) getCriteria()[crit]).isCost();
|
|
|
|
|
|
|
|
|
|
Collections.sort(valuationsCriterion);
|
|
|
|
|
|
|
|
|
|
if (isCost)
|
|
|
|
|
idealSolution[crit] = valuationsCriterion.get(0);
|
|
|
|
|
else
|
|
|
|
|
idealSolution[crit] = valuationsCriterion.get(valuationsCriterion.size() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.positiveIdealSolution.put((Expert) getExperts()[posExpert], idealSolution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Valuation> getValuationsExpertByCriterion(int posExpert, int crit) {
|
|
|
|
|
List<Valuation> criterionValuations = new ArrayList<Valuation>();
|
|
|
|
|
|
|
|
|
|
Valuation[][] valuations = weightedDecisionMatrices.get(getExperts()[posExpert]);
|
|
|
|
|
for(int i = 0; i < valuations.length; ++i)
|
|
|
|
|
criterionValuations.add(valuations[i][crit]);
|
|
|
|
|
|
|
|
|
|
return criterionValuations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeNegativeIdealSolution(int posExpert) {
|
|
|
|
|
Valuation[] antiIdealSolution = new Valuation[getNumberCriteria()];
|
|
|
|
|
|
|
|
|
|
List<Valuation> valuationsCriterion;
|
|
|
|
|
|
|
|
|
|
boolean isCost;
|
|
|
|
|
|
|
|
|
|
for (int crit = 0; crit < getNumberCriteria(); ++crit) {
|
|
|
|
|
|
|
|
|
|
valuationsCriterion = getValuationsExpertByCriterion(posExpert, crit);
|
|
|
|
|
|
|
|
|
|
isCost = ((Criterion) getCriteria()[crit]).isCost();
|
|
|
|
|
|
|
|
|
|
Collections.sort(valuationsCriterion);
|
|
|
|
|
|
|
|
|
|
if (isCost)
|
|
|
|
|
antiIdealSolution[crit] = valuationsCriterion.get(valuationsCriterion.size() - 1);
|
|
|
|
|
else
|
|
|
|
|
antiIdealSolution[crit] = valuationsCriterion.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.negativeIdealSolution.put((Expert) getExperts()[posExpert], antiIdealSolution);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeDistanceSolutions(int posExpert) {
|
|
|
|
|
computeDistanceIdealPositiveSolution(posExpert);
|
|
|
|
|
computeDistanceIdealNegativeSolution(posExpert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeDistanceIdealPositiveSolution(int posExpert) {
|
|
|
|
|
Valuation[][] distances = new Valuation[getNumberAlternatives()][getNumberCriteria()];
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation distance;
|
|
|
|
|
|
|
|
|
|
ProblemElement[] experts = getExperts();
|
|
|
|
|
|
|
|
|
|
Valuation[] positiveIdealSolution = this.positiveIdealSolution.get(experts[posExpert]);
|
|
|
|
|
Valuation[][] weigthedDecisionMatrix = this.weightedDecisionMatrices.get(experts[posExpert]);
|
|
|
|
|
|
|
|
|
|
double dist;
|
|
|
|
|
for(int i = 0; i < weigthedDecisionMatrix.length; ++i) {
|
|
|
|
|
for(int j = 0; j < weigthedDecisionMatrix[i].length; ++j) {
|
|
|
|
|
dist = (unificationDomainDistances.getLabelSet().getCardinality() - 1) *
|
|
|
|
|
computeDistanceTwoTuple(weigthedDecisionMatrix[i][j], positiveIdealSolution[j]) / (unificationDomainValuations.getLabelSet().getCardinality() - 1);
|
|
|
|
|
|
|
|
|
|
distance = new TwoTupleValuation(unificationDomainDistances);
|
|
|
|
|
distance.calculateDelta(dist);
|
|
|
|
|
|
|
|
|
|
distances[i][j] = distance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.distancePositiveIdealSolutionMatrices.put((Expert) experts[posExpert], distances);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Float computeDistanceTwoTuple(Valuation valuation1, Valuation valuation2) {
|
|
|
|
|
return (float) Math.abs(((TwoTupleValuation) valuation1).calculateInverseDelta() - ((TwoTupleValuation) valuation2).calculateInverseDelta());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeDistanceIdealNegativeSolution(int posExpert) {
|
|
|
|
|
Valuation[][] distances = new Valuation[getNumberAlternatives()][getNumberCriteria()];
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation distance;
|
|
|
|
|
|
|
|
|
|
ProblemElement[] experts = getExperts();
|
|
|
|
|
|
|
|
|
|
Valuation[] negativeIdealSolution = this.negativeIdealSolution.get(experts[posExpert]);
|
|
|
|
|
Valuation[][] weigthedDecisionMatrix = this.weightedDecisionMatrices.get(experts[posExpert]);
|
|
|
|
|
|
|
|
|
|
double dist;
|
|
|
|
|
for(int i = 0; i < weigthedDecisionMatrix.length; ++i) {
|
|
|
|
|
for(int j = 0; j < weigthedDecisionMatrix[i].length; ++j) {
|
|
|
|
|
dist = (unificationDomainDistances.getLabelSet().getCardinality() - 1) *
|
|
|
|
|
computeDistanceTwoTuple(weigthedDecisionMatrix[i][j], negativeIdealSolution[j]) / (unificationDomainValuations.getLabelSet().getCardinality() - 1);
|
|
|
|
|
|
|
|
|
|
distance = new TwoTupleValuation(unificationDomainDistances);
|
|
|
|
|
distance.calculateDelta(dist);
|
|
|
|
|
|
|
|
|
|
distances[i][j] = distance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.distanceNegativeIdealSolutionMatrices.put((Expert) experts[posExpert], distances);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeGlobalDistancesIdealSolutions(int posExpert) {
|
|
|
|
|
computeGlobalPositiveIdealSolutionDistances(posExpert);
|
|
|
|
|
computeGlobalNegativeIdealSolutionDistances(posExpert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeGlobalPositiveIdealSolutionDistances(int posExpert) {
|
|
|
|
|
Valuation[] globalDistances = new Valuation[getNumberAlternatives()];
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation distance;
|
|
|
|
|
|
|
|
|
|
Valuation[][] distancesPositiveIdealSolution = distancePositiveIdealSolutionMatrices.get(getExperts()[posExpert]);
|
|
|
|
|
|
|
|
|
|
double acum;
|
|
|
|
|
for(int i = 0; i < distancesPositiveIdealSolution.length; ++i) {
|
|
|
|
|
acum = 0;
|
|
|
|
|
for(int j = 0; j < distancesPositiveIdealSolution[i].length; ++j)
|
|
|
|
|
acum += ((TwoTupleValuation) distancesPositiveIdealSolution[i][j]).calculateInverseDelta();
|
|
|
|
|
|
|
|
|
|
distance = new TwoTupleValuation(unificationDomainDistances);
|
|
|
|
|
distance.calculateDelta(acum /distancesPositiveIdealSolution[i].length);
|
|
|
|
|
globalDistances[i] = distance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.globalPositiveIdealSolutionDistance.put((Expert) getExperts()[posExpert], globalDistances);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeGlobalNegativeIdealSolutionDistances(int posExpert) {
|
|
|
|
|
Valuation[] globalDistances = new Valuation[getNumberAlternatives()];
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation distance;
|
|
|
|
|
|
|
|
|
|
Valuation[][] distancesNegativeIdealSolution = distanceNegativeIdealSolutionMatrices.get(getExperts()[posExpert]);
|
|
|
|
|
|
|
|
|
|
double acum;
|
|
|
|
|
for(int i = 0; i < distancesNegativeIdealSolution.length; ++i) {
|
|
|
|
|
acum = 0;
|
|
|
|
|
for(int j = 0; j < distancesNegativeIdealSolution[i].length; ++j)
|
|
|
|
|
acum += ((TwoTupleValuation) distancesNegativeIdealSolution[i][j]).calculateInverseDelta();
|
|
|
|
|
|
|
|
|
|
distance = new TwoTupleValuation(unificationDomainDistances);
|
|
|
|
|
distance.calculateDelta(acum / distancesNegativeIdealSolution[i].length);
|
|
|
|
|
globalDistances[i] = distance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.globalNegativeIdealSolutionDistance.put((Expert) getExperts()[posExpert], globalDistances);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeClosenessCoefficients(int posExpert) {
|
|
|
|
|
Valuation[] closenessCoefficients = new Valuation[getNumberAlternatives()];
|
|
|
|
|
|
|
|
|
|
TwoTupleValuation closeness;
|
|
|
|
|
|
|
|
|
|
Valuation[] globalPositiveIdealDistance = globalPositiveIdealSolutionDistance.get(getExperts()[posExpert]);
|
|
|
|
|
Valuation[] globalNegativeIdealDistance = globalNegativeIdealSolutionDistance.get(getExperts()[posExpert]);
|
|
|
|
|
|
|
|
|
|
double posDist, negDist, coeff;
|
|
|
|
|
for(int i = 0; i < globalPositiveIdealDistance.length; ++i) {
|
|
|
|
|
posDist = ((TwoTupleValuation) globalPositiveIdealDistance[i]).calculateInverseDelta();
|
|
|
|
|
negDist = ((TwoTupleValuation) globalNegativeIdealDistance[i]).calculateInverseDelta();
|
|
|
|
|
coeff = (unificationDomainDistances.getLabelSet().getCardinality() - 1) * (negDist / (posDist + negDist));
|
|
|
|
|
|
|
|
|
|
closeness = new TwoTupleValuation(unificationDomainDistances);
|
|
|
|
|
closeness.calculateDelta(coeff);
|
|
|
|
|
closenessCoefficients[i] = closeness;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.closenessCoefficients.put((Expert) getExperts()[posExpert], closenessCoefficients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void executeForAllExperts() {
|
|
|
|
|
for(int exp = 0; exp < getNumberExperts(); ++exp)
|
|
|
|
|
execute(exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringPositiveIdealSolutionCriterion(int posCriterion, int posExpert) {
|
|
|
|
|
return positiveIdealSolution.get(getExperts()[posExpert])[posCriterion].changeFormatValuationToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringNegativeIdealSolutionCriterion(int posCriterion, int posExpert) {
|
|
|
|
|
return negativeIdealSolution.get(getExperts()[posExpert])[posCriterion].changeFormatValuationToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringDistancePositiveIdealSolutionValuation(int posCriterion, int posAlternative, int posExpert) {
|
|
|
|
|
TwoTupleValuation distance = (TwoTupleValuation) distancePositiveIdealSolutionMatrices.get(getExperts()[posExpert])[posAlternative][posCriterion];
|
|
|
|
|
return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta() * 1000d) / 1000d + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringDistanceNegativeIdealSolutionValuation(int posCriterion, int posAlternative, int posExpert) {
|
|
|
|
|
TwoTupleValuation distance = (TwoTupleValuation) distanceNegativeIdealSolutionMatrices.get(getExperts()[posExpert])[posAlternative][posCriterion];
|
|
|
|
|
return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta() * 1000d) / 1000d + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringGlobalDistancePositiveIdealSolutionValuation(int posAlternative, int posExpert) {
|
|
|
|
|
TwoTupleValuation distance = (TwoTupleValuation) globalPositiveIdealSolutionDistance.get(getExperts()[posExpert])[posAlternative];
|
|
|
|
|
return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta() * 1000d) / 1000d + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringGlobalDistanceNegativeIdealSolutionValuation(int posAlternative, int posExpert) {
|
|
|
|
|
TwoTupleValuation distance = (TwoTupleValuation) globalNegativeIdealSolutionDistance.get(getExperts()[posExpert])[posAlternative];
|
|
|
|
|
return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta()* 1000d) / 1000d + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getStringClosenessCoefficient(int posAlternative, int posExpert) {
|
|
|
|
|
TwoTupleValuation coefficient = (TwoTupleValuation) closenessCoefficients.get(getExperts()[posExpert])[posAlternative];
|
|
|
|
|
return coefficient.changeFormatValuationToString() + " " + "(" + Math.round(coefficient.calculateInverseDelta() * 1000d) / 1000d + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initializeDefaultWeights() {
|
|
|
|
|
ProblemElement expert;
|
|
|
|
|
|
|
|
|
|
for(Domain domain: domainService.getAll()) {
|
|
|
|
|
|
|
|
|
|
String valuationId = valuationService.getExtensionIdFor(domain.getType());
|
|
|
|
|
|
|
|
|
|
if(valuationId.equals(IntegerIntervalValuation.ID)) {
|
|
|
|
|
|
|
|
|
|
NumericDomain numeric = (NumericDomain) domain;
|
|
|
|
|
IntegerIntervalValuation wVal;
|
|
|
|
|
|
|
|
|
|
Valuation[] weights;
|
|
|
|
|
for(int exp = 0; exp < getExperts().length; ++exp) {
|
|
|
|
|
weights = new Valuation[getCriteria().length];
|
|
|
|
|
for(int crit = 0; crit < weights.length; ++crit) {
|
|
|
|
|
wVal = ContextInjectionFactory.make(IntegerIntervalValuation.class, context);
|
|
|
|
|
wVal.setDomain(numeric);
|
|
|
|
|
wVal.setMinMax(numeric.getMin(), numeric.getMax());
|
|
|
|
|
weights[crit] = wVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expert = (Expert) getExperts()[exp];
|
|
|
|
|
if(this.weights.get(expert) != null) {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = this.weights.get(expert);
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
this.weights.put((Expert) expert, weightsForDomain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if(valuationId.equals(RealIntervalValuation.ID)) {
|
|
|
|
|
|
|
|
|
|
NumericDomain numeric = (NumericDomain) domain;
|
|
|
|
|
RealIntervalValuation wVal;
|
|
|
|
|
|
|
|
|
|
Valuation[] weights;
|
|
|
|
|
for(int exp = 0; exp < getExperts().length; ++exp) {
|
|
|
|
|
weights = new Valuation[getCriteria().length];
|
|
|
|
|
for(int crit = 0; crit < weights.length; ++crit) {
|
|
|
|
|
wVal = ContextInjectionFactory.make(RealIntervalValuation.class, context);
|
|
|
|
|
wVal.setDomain(numeric);
|
|
|
|
|
wVal.setMinMax(numeric.getMin(), numeric.getMax());
|
|
|
|
|
weights[crit] = wVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expert = (Expert) getExperts()[exp];
|
|
|
|
|
if(this.weights.get(expert) != null) {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = this.weights.get(expert);
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
this.weights.put((Expert) expert, weightsForDomain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (valuationId.equals(IntegerValuation.ID)) {
|
|
|
|
|
|
|
|
|
|
NumericDomain numeric = (NumericDomain) domain;
|
|
|
|
|
IntegerValuation wVal;
|
|
|
|
|
|
|
|
|
|
Valuation[] weights;
|
|
|
|
|
for(int exp = 0; exp < getExperts().length; ++exp) {
|
|
|
|
|
weights = new Valuation[getCriteria().length];
|
|
|
|
|
for(int crit = 0; crit < weights.length; ++crit) {
|
|
|
|
|
wVal = ContextInjectionFactory.make(IntegerValuation.class, context);
|
|
|
|
|
wVal.setDomain(domain);
|
|
|
|
|
wVal.setValue((double) Math.round((numeric.getMin() + numeric.getMax()) / 2));
|
|
|
|
|
weights[crit] = wVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expert = (Expert) getExperts()[exp];
|
|
|
|
|
if(this.weights.get(expert) != null) {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = this.weights.get(expert);
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
this.weights.put((Expert) expert, weightsForDomain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if(valuationId.equals(RealValuation.ID)) {
|
|
|
|
|
|
|
|
|
|
NumericDomain numeric = (NumericDomain) domain;
|
|
|
|
|
RealValuation wVal;
|
|
|
|
|
|
|
|
|
|
Valuation[] weights;
|
|
|
|
|
for(int exp = 0; exp < getExperts().length; ++exp) {
|
|
|
|
|
weights = new Valuation[getCriteria().length];
|
|
|
|
|
for(int crit = 0; crit < weights.length; ++crit) {
|
|
|
|
|
wVal = ContextInjectionFactory.make(RealValuation.class, context);
|
|
|
|
|
wVal.setDomain(domain);
|
|
|
|
|
wVal.setValue((numeric.getMin() + numeric.getMax()) / 2);
|
|
|
|
|
weights[crit] = wVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expert = (Expert) getExperts()[exp];
|
|
|
|
|
if(this.weights.get(expert) != null) {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = this.weights.get(expert);
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
this.weights.put((Expert) expert, weightsForDomain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
FuzzySet fuzzySet = (FuzzySet) domain;
|
|
|
|
|
LinguisticValuation wVal;
|
|
|
|
|
|
|
|
|
|
Valuation[] weights;
|
|
|
|
|
|
|
|
|
|
for(int exp = 0; exp < getExperts().length; ++exp) {
|
|
|
|
|
weights = new Valuation[getCriteria().length];
|
|
|
|
|
for(int crit = 0; crit < weights.length; ++crit) {
|
|
|
|
|
wVal = ContextInjectionFactory.make(LinguisticValuation.class, context);
|
|
|
|
|
wVal.setDomain(domain);
|
|
|
|
|
wVal.setLabel(fuzzySet.getLabelSet().getLabel((int) fuzzySet.getLabelSet().getCardinality() / 2));
|
|
|
|
|
weights[crit] = wVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expert = (Expert) getExperts()[exp];
|
|
|
|
|
if(this.weights.get(expert) != null) {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = this.weights.get(expert);
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<Domain, Valuation[]> weightsForDomain = new HashMap<Domain, Valuation[]>();
|
|
|
|
|
weightsForDomain.put(domain, weights);
|
|
|
|
|
this.weights.put((Expert) expert, weightsForDomain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean unificationDomainChanged() {
|
|
|
|
|
FuzzySet oldDomain = (FuzzySet) this.unificationDomainValuations.clone();
|
|
|
|
|
setUnificationDomainValuations();
|
|
|
|
|
return (!oldDomain.equals(this.unificationDomainValuations)) ? true: false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return (closenessCoefficients.size() == getNumberExperts()) ? true:false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void exportInfoToNextStep() {
|
|
|
|
|
exportData("valuationDomain", unificationDomainValuations);
|
|
|
|
|
exportData("distanceDomain", unificationDomainDistances);
|
|
|
|
|
exportData("coefficients", closenessCoefficients);
|
|
|
|
|
}
|
|
|
|
|
}
|