public code v1
This commit is contained in:
@@ -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-11"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.operator.aggregation.bonferroniMean</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>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
||||
@@ -0,0 +1,21 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Bonferroni Mean aggregation operator
|
||||
Bundle-SymbolicName: flintstones.operator.aggregation.bonferroniMean;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: Sinbad2
|
||||
Automatic-Module-Name: flintstones.operator.bonferroniMean
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Require-Bundle: flintstones.entity.operator,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.domain.fuzzyset,
|
||||
flintstones.model.ui.service,
|
||||
org.eclipse.jface,
|
||||
flintstones.operator,
|
||||
de.kupzog.ktable,
|
||||
javax.inject,
|
||||
flintstones.model.problemelement.service,
|
||||
flintstones.valuation.numeric.real,
|
||||
flintstones.valuation.fuzzy,
|
||||
org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.di
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="flintstones.operator.aggregation.extensionpoint">
|
||||
<aggregation_operator_type
|
||||
implementation="flintstones.operator.aggregation.bonferroniMean.BonferroniMean"
|
||||
uid="flintstones.operator.aggregation.bonferroniMean">
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.bonferroniMean.operators.BonferroniMeanDouble"
|
||||
valuationId="flintstones.valuation.real">
|
||||
</aggregation_operator>
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.bonferroniMean.operators.BonferroniMeanFuzzy"
|
||||
valuationId="flintstones.valuation.fuzzy">
|
||||
</aggregation_operator>
|
||||
</aggregation_operator_type>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package flintstones.operator.aggregation.bonferroniMean;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
|
||||
import flintstones.entity.operator.AggregationOperator;
|
||||
import flintstones.entity.operator.interfaces.IParameterizedOperator;
|
||||
import flintstones.entity.operator.interfaces.IWeightedAggregationOperator;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
|
||||
public abstract class BonferroniMean extends AggregationOperator implements IWeightedAggregationOperator, IParameterizedOperator {
|
||||
|
||||
@Inject
|
||||
protected IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
protected IProblemElementService problemService;
|
||||
|
||||
protected double p;
|
||||
protected double q;
|
||||
protected String[][] relations;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bonferroni Mean";
|
||||
}
|
||||
|
||||
public double getP() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public void setP(double p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public double getQ() {
|
||||
return q;
|
||||
}
|
||||
|
||||
public void setQ(double q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public String[][] getRelations() {
|
||||
return relations;
|
||||
}
|
||||
|
||||
public void setRelations(String[][] relations) {
|
||||
this.relations = relations;
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package flintstones.operator.aggregation.bonferroniMean.dialog;
|
||||
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.FontData;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Spinner;
|
||||
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
import flintstones.operator.aggregation.bonferroniMean.table.AttributesRelationTable;
|
||||
|
||||
public class BonferroniMeanDialog extends Dialog {
|
||||
|
||||
private static final int DIALOG_SIZE_Y = 600;
|
||||
private static final int DIALOG_SIZE_X = 650;
|
||||
|
||||
private ProblemElement[] items;
|
||||
private double p;
|
||||
private double q;
|
||||
|
||||
private AttributesRelationTable table;
|
||||
private Spinner spinner1;
|
||||
private Spinner spinner2;
|
||||
private Button okButton;
|
||||
|
||||
public BonferroniMeanDialog(Shell parentShell) {
|
||||
super(parentShell);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite container = (Composite) super.createDialogArea(parent);
|
||||
|
||||
UiService.setGridLayout(parent, 1);
|
||||
UiService.setGridDataAuto(parent);
|
||||
|
||||
this.addContent(container);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private void addContent(Composite container) {
|
||||
this.addSpinners(container);
|
||||
this.addRelationsTable(container);
|
||||
}
|
||||
|
||||
private void addSpinners(Composite container) {
|
||||
Composite parametersComposite = new Composite(container, SWT.BORDER);
|
||||
UiService.setGridLayout(parametersComposite, 3);
|
||||
UiService.setGridData(parametersComposite, 9, 9, false, false);
|
||||
|
||||
Composite spinner1Composite = new Composite(parametersComposite, SWT.NONE);
|
||||
UiService.setGridLayout(spinner1Composite, 2);
|
||||
UiService.setGridDataAuto(spinner1Composite);
|
||||
|
||||
Label parameterP = new Label(spinner1Composite, SWT.BOLD);
|
||||
FontData fontData = parameterP.getFont().getFontData()[0];
|
||||
Font font = new Font(Display.getDefault(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
|
||||
parameterP.setFont(font);
|
||||
parameterP.setText("P:");
|
||||
UiService.setGridData(parameterP, 9, 1, false, false);
|
||||
|
||||
spinner1 = new Spinner(spinner1Composite, SWT.NONE);
|
||||
spinner1.setDigits(2);
|
||||
spinner1.setMinimum((int) (1 * 100d));
|
||||
spinner1.setMaximum((int) (10 * 100d));
|
||||
spinner1.setSelection((int) (1 * 100d));
|
||||
UiService.setGridData(spinner1, 9, 1, true, false);
|
||||
p = spinner1.getSelection() / 100d;
|
||||
|
||||
spinner1.addModifyListener(e -> {
|
||||
p = spinner1.getSelection() / 100d;
|
||||
});
|
||||
|
||||
Composite spinner2Composite = new Composite(parametersComposite, SWT.NONE);
|
||||
UiService.setGridLayout(spinner2Composite, 2);
|
||||
UiService.setGridDataAuto(spinner2Composite);
|
||||
|
||||
Label parameterQ = new Label(spinner2Composite, SWT.BOLD);
|
||||
parameterQ.setFont(font);
|
||||
parameterQ.setText("Q:");
|
||||
UiService.setGridData(parameterQ, 9, 1, false, false);
|
||||
|
||||
spinner2 = new Spinner(spinner2Composite, SWT.NONE);
|
||||
spinner2.setDigits(2);
|
||||
spinner2.setMinimum((int) (1 * 100d));
|
||||
spinner2.setMaximum((int) (10 * 100d));
|
||||
spinner2.setSelection((int) (1 * 100d));
|
||||
UiService.setGridData(spinner2, 9, 1, true, false);
|
||||
q = spinner2.getSelection() / 100d;
|
||||
|
||||
spinner2.addModifyListener(e -> {
|
||||
q = spinner2.getSelection() / 100d;
|
||||
});
|
||||
}
|
||||
|
||||
private void addRelationsTable(Composite container) {
|
||||
Label relationLabel = new Label(container, SWT.BOLD);
|
||||
FontData fontData = relationLabel.getFont().getFontData()[0];
|
||||
Font font = new Font(Display.getDefault(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
|
||||
relationLabel.setFont(font);
|
||||
relationLabel.setText("If two arguments are interrelated then set 1 otherwise 0");
|
||||
|
||||
table = new AttributesRelationTable(container);
|
||||
table.setModel(items);
|
||||
UiService.setGridDataAuto(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureShell(Shell newShell) {
|
||||
super.configureShell(newShell);
|
||||
newShell.setText("Configuration");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getInitialSize() {
|
||||
return new Point(DIALOG_SIZE_X, DIALOG_SIZE_Y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void okPressed() {
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createButtonsForButtonBar(Composite parent) {
|
||||
this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
|
||||
this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
|
||||
|
||||
this.okButton = this.getButton(IDialogConstants.OK_ID);
|
||||
this.okButton.setEnabled(true);
|
||||
this.okButton.setToolTipText("Aggregate with this configuration");
|
||||
}
|
||||
|
||||
public void setItems(ProblemElement[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public String[][] getRelations() {
|
||||
return table.getRelations();
|
||||
}
|
||||
|
||||
public double getP() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public double getQ() {
|
||||
return q;
|
||||
}
|
||||
}
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
package flintstones.operator.aggregation.bonferroniMean.operators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.operator.aggregation.bonferroniMean.BonferroniMean;
|
||||
import flintstones.operator.aggregation.bonferroniMean.dialog.BonferroniMeanDialog;
|
||||
import flintstones.valuation.numeric.real.RealValuation;
|
||||
|
||||
/** Finding the extended Bonferroni mean for a set of crisp arguments
|
||||
B. Dutta, D. Guha, R. Mesiar, A Model based on linguistic 2-tuples for dealing with
|
||||
heterogeneous relationship among attributes in multi-expert decision making, IEEE
|
||||
Transaction on Fuzzy Systems, 23(5):1817–1830, 2015.
|
||||
Original author: Bapi Dutta, Apr. 9, 2021.
|
||||
relations is relationship matrix. For n arguments relationship matrix is a n*n matrix whose rows and columns are arguments and the entries are 0 or
|
||||
1. If two arguments are interrelated then entries are 1 otherwise 0.
|
||||
Note that a_i is not related to itself i.e. corresponding entry would be zero
|
||||
valuations is aggregated arguments
|
||||
weights normalized weight vector
|
||||
p, q parameters of EBM **/
|
||||
public class BonferroniMeanDouble extends BonferroniMean {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations, List<Double> weights) {
|
||||
|
||||
RealValuation result = null;
|
||||
|
||||
Double[] dependentAttributeWeights;
|
||||
Double[] v1, v2;
|
||||
Valuation[] dependentAttributes;
|
||||
double ebm_dep = 0, ebm_ind, ebm, part1, part2;
|
||||
|
||||
if(allDepedentAttributes()) {
|
||||
|
||||
for(int i = 0; i < valuations.size(); ++i) {
|
||||
|
||||
Validator.notIllegalElementType(valuations.get(i), new String[] {RealValuation.class.toString()});
|
||||
|
||||
part1 = (weights.get(i) * Math.pow(((RealValuation) valuations.get(i)).getValue(), p));
|
||||
|
||||
dependentAttributeWeights = getDependentAttributeWeights(i, weights);
|
||||
dependentAttributes = getDependentAttributes(i, valuations);
|
||||
|
||||
v1 = divideElementsBySum(dependentAttributeWeights);
|
||||
v2 = powerAttributes(dependentAttributes, q);
|
||||
|
||||
part2 = dot(v1, v2);
|
||||
|
||||
ebm_dep += part1 * part2;
|
||||
}
|
||||
|
||||
ebm = Math.pow(ebm_dep, 1d / (p + q));
|
||||
|
||||
} else {
|
||||
|
||||
Integer[] dependentIndexes = getDependentRelationsIndexes();
|
||||
|
||||
//dependent part computation
|
||||
double sum_dependent_attribute_weights = sumElementsByIndexes(dependentIndexes, weights);
|
||||
|
||||
for(Integer dep_ind: dependentIndexes) {
|
||||
|
||||
Validator.notIllegalElementType(valuations.get(dep_ind), new String[] {RealValuation.class.toString()});
|
||||
|
||||
part1 = (weights.get(dep_ind) / sum_dependent_attribute_weights) * Math.pow(((RealValuation) valuations.get(dep_ind)).getValue(), p);
|
||||
|
||||
dependentAttributeWeights = getDependentAttributeWeights(dep_ind, weights);
|
||||
dependentAttributes = getDependentAttributes(dep_ind, valuations);
|
||||
|
||||
v1 = divideElementsBySum(dependentAttributeWeights);
|
||||
v2 = powerAttributes(dependentAttributes, q);
|
||||
|
||||
part2 = dot(v1, v2);
|
||||
|
||||
ebm_dep += part1 * part2;
|
||||
}
|
||||
|
||||
ebm_dep = Math.pow(ebm_dep, p / (p + q));
|
||||
|
||||
//independent part computation
|
||||
Double[] independentAttributeWeights;
|
||||
Valuation[] independentAttributes;
|
||||
|
||||
Integer[] independentIndexes = getIndependentRelationsIndexes();
|
||||
|
||||
double sum_independent_attribute_weights = sumElementsByIndexes(independentIndexes, weights);
|
||||
|
||||
independentAttributeWeights = getWeightsForIndependentAttributes(independentIndexes, weights);
|
||||
independentAttributes = getIndependentAttributes(independentIndexes, valuations);
|
||||
|
||||
ebm_ind = (1d / sum_independent_attribute_weights) * dot(independentAttributeWeights, powerAttributes(independentAttributes, p));
|
||||
|
||||
//combining both
|
||||
ebm = (1d - sum_independent_attribute_weights) * ebm_dep + (Math.pow(sum_independent_attribute_weights * ebm_ind, 1d / p));
|
||||
}
|
||||
|
||||
result = (RealValuation) valuations.get(0).clone();
|
||||
result.setValue(ebm);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are relations among attributes
|
||||
* @return
|
||||
*/
|
||||
private boolean allDepedentAttributes() {
|
||||
boolean independent = true;
|
||||
for(int i = 0; i < relations.length - 1; ++i) {
|
||||
for (int j = i + 1; j < relations.length; ++j) {
|
||||
if(relations[i][j].equals("1"))
|
||||
independent = false;
|
||||
}
|
||||
|
||||
if(independent)
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get weights from dependent attributes
|
||||
* @param index current attribute
|
||||
* @param weights attribute weights
|
||||
* @return weights of the dependent attributes
|
||||
*/
|
||||
private Double[] getDependentAttributeWeights(int index, List<Double> weights) {
|
||||
Integer[] attributeRelationsIndexes = getAttributeDependentRelationsIndexes(index);
|
||||
|
||||
List<Double> dependentAttributeWeights = new ArrayList<Double>();
|
||||
for(Integer i: attributeRelationsIndexes)
|
||||
dependentAttributeWeights.add(weights.get(i));
|
||||
|
||||
return dependentAttributeWeights.toArray(new Double[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get indexes of the dependent attributes related to another attribute
|
||||
* @param index index of the attribute
|
||||
* @return indexes of the attributes with a relation
|
||||
*/
|
||||
private Integer[] getAttributeDependentRelationsIndexes(int index) {
|
||||
String[] attributeRelations = relations[index];
|
||||
|
||||
List<Integer> attributeRelationsIndexes = new ArrayList<Integer>();
|
||||
for(int i = 0; i < attributeRelations.length; ++i) {
|
||||
if(attributeRelations[i].equals("1"))
|
||||
attributeRelationsIndexes.add(i);
|
||||
}
|
||||
|
||||
return attributeRelationsIndexes.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valuations of the dependent attributes related to another attribute
|
||||
* @param index index of the attribute
|
||||
* @return valuation values of the attributes
|
||||
*/
|
||||
private Valuation[] getDependentAttributes(int index, List<Valuation> attributes) {
|
||||
Integer[] attributeRelationsIndexes = getAttributeDependentRelationsIndexes(index);
|
||||
|
||||
List<Valuation> dependentAttribute = new ArrayList<Valuation>();
|
||||
for(Integer i: attributeRelationsIndexes)
|
||||
dependentAttribute.add(attributes.get(i));
|
||||
|
||||
return dependentAttribute.toArray(new Valuation[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sum of all the dependent weights
|
||||
* @param dependentWeights weights of the dependent attributes
|
||||
* @return sum of the dependent attributes
|
||||
*/
|
||||
private double getSumWeights(Double[] dependentWeights) {
|
||||
double acum = 0;
|
||||
|
||||
for(Double dependentWeight: dependentWeights)
|
||||
acum += dependentWeight;
|
||||
|
||||
return acum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the division of each weight by the total sum
|
||||
* @param dependentAttributeWeights dependent weights
|
||||
* @return
|
||||
*/
|
||||
private Double[] divideElementsBySum(Double[] attributeWeights) {
|
||||
double sum = getSumWeights(attributeWeights);
|
||||
|
||||
Double[] result = new Double[attributeWeights.length];
|
||||
|
||||
for(int i = 0; i < result.length; ++i)
|
||||
result[i] = attributeWeights[i] /sum;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the power of each dependent attribute
|
||||
* @param dependentAttributes values of the dependent attributes
|
||||
* @return power of each dependent attribute
|
||||
*/
|
||||
private Double[] powerAttributes(Valuation[] dependentAttributes, double power) {
|
||||
Double[] result = new Double[dependentAttributes.length];
|
||||
|
||||
for(int i = 0; i < result.length; ++i)
|
||||
result[i] = Math.pow(((RealValuation) dependentAttributes[i]).getValue(), power);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dot operation among vectors
|
||||
* @param v1 vector1
|
||||
* @param v2 vector2
|
||||
* @return dot operation
|
||||
*/
|
||||
private double dot(Double[] v1, Double[] v2) {
|
||||
double acum = 0;
|
||||
for(int i = 0; i < v1.length; ++i)
|
||||
acum += v1[i] * v2[i];
|
||||
|
||||
return acum;
|
||||
}
|
||||
|
||||
private Integer[] getDependentRelationsIndexes() {
|
||||
List<Integer> dependentIndexes = new ArrayList<Integer>();
|
||||
|
||||
String[] relationsAttribute;
|
||||
for(int i = 0; i < relations.length; ++i) {
|
||||
relationsAttribute = relations[i];
|
||||
for(String relation: relationsAttribute) {
|
||||
if(relation.equals("1")) {
|
||||
dependentIndexes.add(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dependentIndexes.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
private Integer[] getIndependentRelationsIndexes() {
|
||||
List<Integer> independentIndexes = new ArrayList<Integer>();
|
||||
|
||||
String[] relationsAttribute;
|
||||
|
||||
boolean independent = true;
|
||||
for(int i = 0; i < relations.length; ++i) {
|
||||
relationsAttribute = relations[i];
|
||||
independent = true;
|
||||
for(String relation: relationsAttribute) {
|
||||
if(relation.equals("1")) {
|
||||
independent = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(independent)
|
||||
independentIndexes.add(i);
|
||||
}
|
||||
|
||||
return independentIndexes.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
private double sumElementsByIndexes(Integer[] indexes, List<Double> weights) {
|
||||
double acum = 0;
|
||||
for(Integer i: indexes)
|
||||
acum += weights.get(i);
|
||||
|
||||
return acum;
|
||||
}
|
||||
|
||||
private Double[] getWeightsForIndependentAttributes(Integer[] independentIndexes, List<Double> weights) {
|
||||
List<Double> independentWeights = new ArrayList<Double>();
|
||||
for(Integer i: independentIndexes)
|
||||
independentWeights.add(weights.get(i));
|
||||
|
||||
return independentWeights.toArray(new Double[0]);
|
||||
}
|
||||
|
||||
private Valuation[] getIndependentAttributes(Integer[] independentIndexes, List<Valuation> attributes) {
|
||||
List<Valuation> independentAttributes = new ArrayList<Valuation>();
|
||||
for(Integer i: independentIndexes)
|
||||
independentAttributes.add(attributes.get(i));
|
||||
|
||||
return independentAttributes.toArray(new Valuation[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openDialog(ProblemElement[] items) {
|
||||
BonferroniMeanDialog dialog = new BonferroniMeanDialog(Display.getDefault().getActiveShell());
|
||||
dialog.setItems(items);
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK) {
|
||||
p = dialog.getP();
|
||||
q = dialog.getQ();
|
||||
relations = dialog.getRelations();
|
||||
dialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package flintstones.operator.aggregation.bonferroniMean.operators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.operator.aggregation.bonferroniMean.BonferroniMean;
|
||||
import flintstones.operator.aggregation.bonferroniMean.dialog.BonferroniMeanDialog;
|
||||
import flintstones.valuation.fuzzy.FuzzyValuation;
|
||||
import flintstones.valuation.numeric.real.RealValuation;
|
||||
|
||||
public class BonferroniMeanFuzzy extends BonferroniMean {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations, List<Double> weights) {
|
||||
double[] limits = new double[4];
|
||||
|
||||
BonferroniMeanDouble bm_crisp = new BonferroniMeanDouble();
|
||||
bm_crisp.setP(p);
|
||||
bm_crisp.setQ(q);
|
||||
bm_crisp.setRelations(relations);
|
||||
|
||||
ContextInjectionFactory.inject(bm_crisp, context);
|
||||
|
||||
List<Valuation> crispValuations;
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
crispValuations = new ArrayList<Valuation>();
|
||||
for(Valuation v: valuations) {
|
||||
RealValuation crisp = new RealValuation();
|
||||
NumericRealDomain domain = new NumericRealDomain();
|
||||
domain.setMinMax(0, Double.MAX_VALUE);
|
||||
crisp.setDomain(domain);
|
||||
crisp.setValue(((FuzzyValuation) v).getFuzzyNumber().getLimits()[i]);
|
||||
crispValuations.add(crisp);
|
||||
}
|
||||
|
||||
limits[i] = ((RealValuation) bm_crisp.aggregate(crispValuations, weights)).getValue();
|
||||
}
|
||||
|
||||
TrapezoidalFunction fuzzy_number = new TrapezoidalFunction(limits);
|
||||
FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(fuzzy_number, valuations.get(0).getDomain());
|
||||
|
||||
return aggregatedFuzzyValuation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openDialog(ProblemElement[] items) {
|
||||
BonferroniMeanDialog dialog = new BonferroniMeanDialog(Display.getDefault().getActiveShell());
|
||||
dialog.setItems(items);
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK) {
|
||||
p = dialog.getP();
|
||||
q = dialog.getQ();
|
||||
relations = dialog.getRelations();
|
||||
}
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
package flintstones.operator.aggregation.bonferroniMean.table;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import de.kupzog.ktable.KTable;
|
||||
import de.kupzog.ktable.KTableCellEditor;
|
||||
import de.kupzog.ktable.KTableCellRenderer;
|
||||
import de.kupzog.ktable.KTableNoScrollModel;
|
||||
import de.kupzog.ktable.SWTX;
|
||||
import de.kupzog.ktable.editors.KTableCellEditorText;
|
||||
import de.kupzog.ktable.renderers.DefaultCellRenderer;
|
||||
import de.kupzog.ktable.renderers.FixedCellRenderer;
|
||||
import flintstones.entity.problemelement.entities.Criterion;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
|
||||
public class AttributesRelationContentProvider extends KTableNoScrollModel {
|
||||
|
||||
private KTable table;
|
||||
|
||||
private ProblemElement[] attributes;
|
||||
private String[][] relations;
|
||||
|
||||
private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD);
|
||||
private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS);
|
||||
|
||||
private class TableCellEditorText extends KTableCellEditorText {
|
||||
@Override
|
||||
protected void onKeyPressed(KeyEvent e) {
|
||||
if(e.keyCode == 13)
|
||||
this.close(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActivationSignals() {
|
||||
return SINGLECLICK;
|
||||
}
|
||||
}
|
||||
|
||||
private TableCellEditorText text;
|
||||
|
||||
public AttributesRelationContentProvider(KTable table) {
|
||||
super(table);
|
||||
}
|
||||
|
||||
public void init(KTable table, ProblemElement[] attributes) {
|
||||
this.table = table;
|
||||
this.attributes = attributes;
|
||||
|
||||
this.relations = new String[attributes.length][attributes.length];
|
||||
|
||||
for(int i = 0; i < this.relations.length; ++i) {
|
||||
for(int j = 0; j < this.relations.length; ++j) {
|
||||
|
||||
this.relations[i][j] = "0";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
initialize();
|
||||
setDesign();
|
||||
}
|
||||
|
||||
private void setDesign() {
|
||||
fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
|
||||
fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0));
|
||||
|
||||
editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER);
|
||||
editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFixedHeaderColumnCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFixedHeaderRowCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFixedSelectableColumnCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFixedSelectableRowCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowHeightMinimum() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColumnResizable(int arg0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRowResizable(int arg0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KTableCellEditor doGetCellEditor(int col, int row) {
|
||||
|
||||
if (col != 0 && row != 0 && col != row) {
|
||||
text = new TableCellEditorText();
|
||||
return text;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KTableCellRenderer doGetCellRenderer(int col, int row) {
|
||||
if((col < getFixedColumnCount()) || (row < getFixedRowCount()))
|
||||
return fixedRenderer;
|
||||
else
|
||||
return editableRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doGetColumnCount() {
|
||||
return attributes.length + getFixedColumnCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object doGetContentAt(int col, int row) {
|
||||
|
||||
if ((col == 0) && (row == 0))
|
||||
return "Relations"; //$NON-NLS-1$
|
||||
|
||||
Object content;
|
||||
|
||||
try {
|
||||
if (col == 0)
|
||||
content = criterionAbbreviation(row);
|
||||
else if (row == 0)
|
||||
content = criterionAbbreviation(col);
|
||||
else
|
||||
content = relations[row - 1][col - 1];
|
||||
} catch (Exception e) {
|
||||
content = ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
private Object criterionAbbreviation(int pos) {
|
||||
if(attributes[0] instanceof Criterion)
|
||||
return "C" + pos;
|
||||
else
|
||||
return "E" + pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int doGetRowCount() {
|
||||
return attributes.length + getFixedRowCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doSetContentAt(int col, int row, Object value) {
|
||||
if(((String) value).equals("0") || ((String) value).equals("1")) {
|
||||
relations[row - 1][col - 1] = (String) value;
|
||||
relations[col - 1][row - 1] = (String) value;
|
||||
table.redraw();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInitialColumnWidth(int arg0) {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInitialRowHeight(int arg0) {
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFixedCell(int col, int row) {
|
||||
if (col == 0)
|
||||
return true;
|
||||
else if (row == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHeaderCell(int col, int row) {
|
||||
return isFixedCell(col, row);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String doGetTooltipAt(int col, int row) {
|
||||
if ((col == 0) && (row == 0))
|
||||
return ""; //$NON-NLS-1$
|
||||
else if (col < getFixedColumnCount()) {
|
||||
return attributes[row - 1].getName();
|
||||
} else if (row < getFixedRowCount())
|
||||
return attributes[col - 1].getName();
|
||||
else
|
||||
return relations[row - 1][col - 1];
|
||||
}
|
||||
|
||||
public String[][] getRelations() {
|
||||
return relations;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package flintstones.operator.aggregation.bonferroniMean.table;
|
||||
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import de.kupzog.ktable.KTable;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
|
||||
public class AttributesRelationTable extends KTable {
|
||||
|
||||
private AttributesRelationContentProvider provider;
|
||||
|
||||
public AttributesRelationTable(Composite parent) {
|
||||
super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL);
|
||||
setBackground(new Color(Display.getCurrent(), 255, 255, 255));
|
||||
provider = null;
|
||||
}
|
||||
|
||||
public void setModel(ProblemElement[] items) {
|
||||
provider = new AttributesRelationContentProvider(this);
|
||||
provider.init(this, items);
|
||||
|
||||
setModel(provider);
|
||||
}
|
||||
|
||||
public String[][] getRelations() {
|
||||
return provider.getRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user