153 lines
4.6 KiB
Plaintext
153 lines
4.6 KiB
Plaintext
<snippet>
|
|
<subclass>afryca.ase.Snippet</subclass>
|
|
<file></file>
|
|
<category>Library</category>
|
|
<name>unification</name>
|
|
<description>Unify different kinds of information</description>
|
|
<code>
|
|
var unification = (typeof exports === "undefined")?(function unification() {}):(exports);
|
|
if(typeof global !== "undefined") { global.unification = unification; }
|
|
|
|
unification.unify = function unify(preferences, blts) {
|
|
var structure;
|
|
var structurePreferences;
|
|
var unifiedPreferences=[];
|
|
var unifiedPreferences = new ArrayList(preferences.length);
|
|
var unifiedPreference;
|
|
|
|
for (var p = 0; p < preferences.length; p++) {
|
|
structure = preferences[p];
|
|
structurePreferences = structure.getPreferences();
|
|
unifiedPreference = structure.createDefaultStructure(structurePreferences[0].length | 0, structurePreferences.length | 0);
|
|
for(var row = 0; row < structurePreferences.length; row++) {
|
|
for(var col = 0; col < structurePreferences[row].length; col++) {
|
|
var domain=structure.getDomain(row|0, col|0);
|
|
if(typeof structurePreferences[row][col] === 'number') {
|
|
unifiedPreference.getPreferences()[row][col] = unification.unifyNumericValues(structurePreferences[row][col], blts, domain);
|
|
} else if(structurePreferences[row][col] instanceof HesitantLinguisticValuation) {
|
|
unifiedPreference.getPreferences()[row][col] = unification.unifyHesitantLinguisticValuation(structurePreferences[row][col], blts,domain);
|
|
} else if(structurePreferences[row][col] instanceof Label){
|
|
unifiedPreference.getPreferences()[row][col] = unification.unifyLinguisticValues(structurePreferences[row][col],blts,domain);
|
|
}else {
|
|
unifiedPreference.getPreferences()[row][col] = structurePreferences[row][col];
|
|
}
|
|
}
|
|
}
|
|
unifiedPreferences.add(unifiedPreference);
|
|
}
|
|
return unifiedPreferences;
|
|
}
|
|
|
|
unification.unifyNumericValues = function unifyNumericValues(value, blts, domain) {
|
|
var result;
|
|
if(typeof blts === 'undefined' || blts === null) {
|
|
return result;
|
|
} else {
|
|
if (!blts.isBLTS()) {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
var cardinality;
|
|
var normalized;
|
|
var membershipFunction;
|
|
|
|
result = blts.clone();
|
|
cardinality = blts.getLabelSet().getCardinality();
|
|
normalized = unification.normalize(value, domain);
|
|
for(var i = 0; i < cardinality; i++) {
|
|
membershipFunction = result.getLabelSet().getLabel(i).getSemantic();
|
|
result.setValue(i | 0, membershipFunction.getMembershipValue(normalized));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
unification.normalize = function normalize(value, domain) {
|
|
var min;
|
|
var max;
|
|
var intervalSize;
|
|
|
|
min = Math.round(domain.getMin());
|
|
max = Math.round(domain.getMax());
|
|
intervalSize = max - min;
|
|
|
|
return (value - min) / intervalSize;
|
|
}
|
|
|
|
|
|
unification.unifyHesitantLinguisticValuation = function(hlv, blts,domainValuation){
|
|
return ConsensusEngine.unificationTrapezoidalFunction(ConsensusEngine.calculateFuzzyEnvelope(blts, hlv), blts, domainValuation);
|
|
}
|
|
|
|
unification.unifyLinguisticValues = function unifyLinguisticValues(valuation, blts,domainValuation) {
|
|
|
|
var label;
|
|
if(valuation instanceof HesitantLinguisticValuation){
|
|
label = valuation.getLabel();
|
|
}else if(valuation instanceof Label){
|
|
label = valuation;
|
|
}
|
|
var result;
|
|
if(typeof blts === 'undefined' || blts === null) {
|
|
return result;
|
|
} else {
|
|
if (!blts.isBLTS()) {
|
|
return result;
|
|
}
|
|
}
|
|
var cardinality;
|
|
var membershipFunction;
|
|
|
|
result = blts.clone();
|
|
cardinality = blts.getLabelSet().getCardinality();
|
|
for(var i = 0; i < cardinality; i++) {
|
|
membershipFunction = result.getLabelSet().getLabel(i).getSemantic();
|
|
result.setValue(i | 0, membershipFunction.maxMin(label.getSemantic(),blts,domainValuation));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
unification.initMatrix = function initMatrix(alternatives) {
|
|
var matrix = new Array(alternatives);
|
|
|
|
//init the grid matrix
|
|
for (var i = 0; i < alternatives; i++) {
|
|
matrix[i] = new Array(alternatives);
|
|
}
|
|
return matrix;
|
|
}
|
|
|
|
unification.getBLTS = function getBLTS(preferences) {
|
|
var domains = [];
|
|
for(var k=0;k<preferences.length;k++){
|
|
for(var i=0;i<preferences[k].getPreferences().length;i++){
|
|
for(var j=0;j<preferences[k].getPreferences()[i].length;j++){
|
|
var domain = preferences[k].getDomain(i | 0, j | 0);
|
|
domains[k]=domain;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var cardinality = 0;
|
|
var blts = null;
|
|
for(var d = 0; d < domains.length; ++d) {
|
|
var domain = domains[d];
|
|
if (domain instanceof FuzzySet) {
|
|
if(domain.isUnification()) {
|
|
return domain;
|
|
} else if((domain.getLabelSet().getCardinality() > cardinality) && domain.isBLTS()) {
|
|
cardinality = domain.getLabelSet().getCardinality();
|
|
blts = domain;
|
|
}
|
|
}
|
|
}
|
|
return blts;
|
|
}
|
|
|
|
|
|
unification
|
|
</code>
|
|
</snippet> |