public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?flintstones.helper.data.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-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.valuation.elicit</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] TwoTuple</name>
<organization>
<name>Sinbad2</name>
</organization>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.valuation.elicit</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>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362744</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TwoTuple
Bundle-SymbolicName: flintstones.valuation.elicit;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Sinbad2
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.entity.valuation,
flintstones.model.valuation.service,
flintstones.valuation.linguistic,
flintstones.valuation.hesitant,
flintstones.valuation.twoTuple,
flintstones.operator,
flintstones.operator.aggregation.owa,
flintstones.domain.fuzzyset.unbalanced,
flintstones.quantifiers.yager,
flintstones.domain.numeric.real,
flintstones.helper.data.wxml,
org.eclipse.e4.core.contexts,
javax.inject,
flintstones.entity.domain,
org.eclipse.e4.core.di,
org.apache.commons.lang,
flintstones.entity.operator
Export-Package: flintstones.valuation.elicit
Automatic-Module-Name: flintstones.valuation.elicit
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<?eclipse version="3.4"?>
<plugin>
<extension
point="flintstones.valuation">
<valuation
domain="flintstones.domain.linguistic"
uid="flintstones.valuation.elicit"
implementation="flintstones.valuation.elicit.ELICIT"
is_intermediate="true"
name="ELICIT">
</valuation>
</extension>
</plugin>
@@ -0,0 +1,838 @@
package flintstones.valuation.elicit;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.domain.fuzzyset.FuzzySet;
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
import flintstones.domain.fuzzyset.label.LabelSetLinguisticDomain;
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
import flintstones.domain.fuzzyset.unbalanced.Unbalanced;
import flintstones.entity.domain.Domain;
import flintstones.entity.operator.AggregationOperator;
import flintstones.entity.valuation.Valuation;
import flintstones.helper.data.wxml.WNode;
import flintstones.helper.validator.Validator;
import flintstones.operator.aggregation.owa.OWA;
import flintstones.operator.service.IOperatorService;
import flintstones.quantifiers.yager.YagerQuantifiers;
import flintstones.valuation.hesitant.EUnaryRelationType;
import flintstones.valuation.twoTuple.TwoTupleValuation;
public class ELICIT extends Valuation {
@Inject
IOperatorService operatorService;
@Inject
IEclipseContext context;
public static final String ID = "flintstones.valuation.elicit"; //$NON-NLS-1$
private EUnaryRelationType unaryRelation;
private TwoTupleValuation term;
private TwoTupleValuation upperTerm;
private TwoTupleValuation lowerTerm;
private TwoTupleValuation label;
private TrapezoidalFunction beta;
private double gamma1;
private double gamma2;
public ELICIT() {
super();
this.unaryRelation = null;
this.term = null;
this.upperTerm = null;
this.lowerTerm = null;
this.label = null;
this.beta = null;
}
public ELICIT(FuzzySet domain) {
this();
this.setDomain(domain);
}
@Override
public void setDomain(Domain domain) {
Validator.notNull(domain);
Validator.notIllegalElementType(domain, new String[] { FuzzySet.class.toString(), Unbalanced.class.toString() });
Validator.notEmpty(((FuzzySet) domain).getLabelSet().getLabels().toArray());
this.domain = domain;
}
public void setTwoTupleLabel(int pos) {
LabelLinguisticDomain newLabel = ((FuzzySet) this.domain).getLabelSet().getLabel(pos);
Validator.notNull(newLabel);
TwoTupleValuation twoTuple = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTuple.build((FuzzySet) this.domain, newLabel, 0);
this.label = twoTuple;
this.disableRelations();
}
public void setTwoTupleLabel(String name) {
LabelLinguisticDomain newLabel = ((FuzzySet) this.domain).getLabelSet().getLabel(name);
Validator.notNull(newLabel);
TwoTupleValuation twoTuple = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTuple.build((FuzzySet) this.domain, newLabel, 0);
this.label = twoTuple;
this.disableRelations();
}
public void setTwoTupleLabel(LabelLinguisticDomain label) {
Validator.notNull(label);
if (((FuzzySet) this.domain).getLabelSet().containsLabel(label)) {
TwoTupleValuation twoTuple = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTuple.build((FuzzySet) this.domain, label, 0);
this.label = twoTuple;
this.disableRelations();
} else
throw new IllegalArgumentException("Label not contained in domain"); //$NON-NLS-1$
}
public void setTwoTupleLabel(TwoTupleValuation twoTuple) {
Validator.notNull(twoTuple);
if (((FuzzySet) this.domain).getLabelSet().containsLabel(twoTuple.getLabel())) {
this.label = twoTuple;
this.disableRelations();
} else
throw new IllegalArgumentException("Hesitant valuation label not contained in domain"); //$NON-NLS-1$
}
public TwoTupleValuation getTwoTupleLabel() {
return this.label;
}
public void setTwoTupleTerm(TwoTupleValuation term) {
this.term = term;
}
public TwoTupleValuation getTwoTupleTerm() {
return this.term;
}
public TwoTupleValuation getTwoTupleLowerTerm() {
return this.lowerTerm;
}
public TwoTupleValuation getTwoTupleUpperTerm() {
return this.upperTerm;
}
public void setBeta(TrapezoidalFunction beta) {
this.beta = beta;
}
public TrapezoidalFunction getBeta() {
return this.beta;
}
public void setGamma1(double gamma1) {
this.gamma1 = gamma1;
}
public double getGamma1() {
return this.gamma1;
}
public void setGamma2(double gamma2) {
this.gamma2 = gamma2;
}
public double getGamma2() {
return this.gamma2;
}
public void setUnaryRelation(EUnaryRelationType unaryRelation, TwoTupleValuation term) {
Validator.notNull(unaryRelation);
Validator.notNull(term);
if (!((FuzzySet) this.domain).getLabelSet().containsLabel(term.getLabel()))
throw new IllegalArgumentException("Label not contained in domain"); //$NON-NLS-1$
this.unaryRelation = unaryRelation;
this.term = term;
this.disablePrimary();
this.disableBinary();
}
public EUnaryRelationType getUnaryRelation() {
return this.unaryRelation;
}
public void setBinaryRelation(TwoTupleValuation lowerTerm, TwoTupleValuation upperTerm) {
Validator.notNull(lowerTerm);
Validator.notNull(upperTerm);
if (!((FuzzySet) this.domain).getLabelSet()
.containsLabel(lowerTerm.getLabel()))
throw new IllegalArgumentException("Lower term not contained in domain"); //$NON-NLS-1$
if (!((FuzzySet) this.domain).getLabelSet()
.containsLabel(upperTerm.getLabel()))
throw new IllegalArgumentException("Upper term is bigger than lower term"); //$NON-NLS-1$
if (upperTerm.compareTo(lowerTerm) < 0)
throw new IllegalArgumentException("Lower term is bigger than upper term"); //$NON-NLS-1$
this.lowerTerm = lowerTerm;
this.upperTerm = upperTerm;
this.disablePrimary();
this.disableUnary();
}
public void setBinaryRelation(int lowerTermPos, int upperTermPos) {
LabelLinguisticDomain lowerTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(lowerTermPos);
Validator.notNull(lowerTerm);
LabelLinguisticDomain upperTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(upperTermPos);
Validator.notNull(upperTerm);
if (upperTermPos <= lowerTermPos)
throw new IllegalArgumentException("Lower term is bigger than upper term"); //$NON-NLS-1$
TwoTupleValuation twoSomeUpper = ContextInjectionFactory.make(TwoTupleValuation.class, context);
TwoTupleValuation twoSomeLower = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoSomeLower.build((FuzzySet) this.domain, lowerTerm, 0);
twoSomeUpper.build((FuzzySet) this.domain, upperTerm, 0);
this.lowerTerm = twoSomeLower;
this.upperTerm = twoSomeUpper;
this.disablePrimary();
this.disableUnary();
}
public void setBinaryRelation(String lowerTermName, String upperTermName) {
LabelLinguisticDomain lowertTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(lowerTermName);
Validator.notNull(lowertTerm);
LabelLinguisticDomain upperTerm = ((FuzzySet) this.domain).getLabelSet().getLabel(upperTermName);
Validator.notNull(upperTerm);
if (upperTermName.compareTo(lowerTermName) <= 0)
throw new IllegalArgumentException("Lower term is bigger than upper term"); //$NON-NLS-1$
TwoTupleValuation twoSomeUpper = ContextInjectionFactory.make(TwoTupleValuation.class, context);
TwoTupleValuation twoSomeLower = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoSomeLower.build((FuzzySet) this.domain, lowertTerm, 0);
twoSomeUpper.build((FuzzySet) this.domain, upperTerm, 0);
this.lowerTerm = twoSomeLower;
this.upperTerm = twoSomeUpper;
this.disablePrimary();
this.disableUnary();
}
public boolean isPrimary() {
return (this.label != null);
}
public boolean isComposite() {
return (this.isUnary() || this.isBinary());
}
public boolean isUnary() {
return ((this.unaryRelation != null) && (this.term != null));
}
public boolean isBinary() {
return ((this.lowerTerm != null) && (this.upperTerm != null));
}
public void createRelation(TrapezoidalFunction beta) {
setBeta(beta);
double a = this.beta.getLimits()[0], b = this.beta.getLimits()[1], c = this.beta.getLimits()[2], d = this.beta.getLimits()[3];
// Step 1: Identify relation
if (c == d && c == 1) {
computeELICITExpressionAtLeastCase();
} else if (a == b && a == 0) {
computeELICITExpressionAtMostCase();
} else if(b == c) {
computeELICITPrimary();
} else {
computeELICITExpressionBetweenCase();
}
}
private void computeELICITExpressionAtLeastCase() {
// Step 1: Compute 2-tuple term from point b of beta to compute the HFLTS
setUnaryRelation(EUnaryRelationType.AtLeast, compute2TupleTerm(this.beta.getB()));
// Step 2: Compute fuzzy envelope
TrapezoidalFunction fuzzyEnvelope = calculateFuzzyEnvelope();
// Step 3: Compute gamma
setGamma1(this.beta.getA() - fuzzyEnvelope.getA());
}
private TwoTupleValuation compute2TupleTerm(Double point) {
Double distance, closestDistance = Double.MAX_VALUE;
LabelLinguisticDomain selectedTerm = null;
for (LabelLinguisticDomain label : ((FuzzySet) this.domain).getLabelSet().getLabels()) {
distance = point - ((TrapezoidalFunction) label.getSemantic()).getB();
if (Math.abs(distance) <= Math.abs(closestDistance)) {
closestDistance = distance;
selectedTerm = label;
}
}
double alpha = Math.round(closestDistance * (((FuzzySet) this.domain).getLabelSet().getCardinality() - 1) * 100d) / 100d;
TwoTupleValuation elicitTerm = ContextInjectionFactory.make(TwoTupleValuation.class, context);
elicitTerm.build((FuzzySet) this.domain, selectedTerm, alpha);
return elicitTerm;
}
public TrapezoidalFunction calculateFuzzyEnvelope() {
int cardinality = ((FuzzySet) this.domain).getLabelSet().getCardinality();
Boolean atMostCase = null;
if (isPrimary()) {
return computeFuzzyEnvelopePrimaryRelation();
} else {
if (isUnary()) {
atMostCase = (getUnaryRelation() == EUnaryRelationType.AtMost) ? true : false;
}
int envelope[] = getEnvelopeIndex();
if (atMostCase == null) { // Binary relation
return computeFuzzyEnvelopeBinaryRelation(cardinality, envelope);
} else { // Unary relation
return computeFuzzyEnvelopeUnaryRelation(cardinality, envelope, atMostCase);
}
}
}
private TrapezoidalFunction computeFuzzyEnvelopePrimaryRelation() {
IMembershipFunction semantic = this.label.getLabel().getSemantic();
TrapezoidalFunction envelopePrimary = new TrapezoidalFunction();
envelopePrimary.setLimits(new double[] {semantic.getCoverage().getMin(), semantic.getCenter().getMin(),
semantic.getCenter().getMax(), semantic.getCoverage().getMax()});
return envelopePrimary;
}
public int[] getEnvelopeIndex() {
int[] result = null;
LabelLinguisticDomain[] envelope = getEnvelope();
if (envelope != null) {
result = new int[2];
result[0] = ((FuzzySet) this.domain).getLabelSet().getPos(envelope[0]);
result[1] = ((FuzzySet) this.domain).getLabelSet().getPos(envelope[1]);
}
return result;
}
public LabelLinguisticDomain[] getEnvelope() {
LabelSetLinguisticDomain labelset = ((FuzzySet) this.domain).getLabelSet();
LabelLinguisticDomain[] result = new LabelLinguisticDomain[2];
int cardinality;
if (isPrimary()) {
result[0] = this.label.getLabel();
result[1] = this.label.getLabel();
} else if (isUnary()) {
switch (this.unaryRelation) {
case AtLeast:
cardinality = labelset.getCardinality();
result[0] = this.term.getLabel();
result[1] = labelset.getLabel(cardinality - 1);
break;
case AtMost:
result[0] = labelset.getLabel(0);
result[1] = this.term.getLabel();
break;
case LowerThan:
result[0] = labelset.getLabel(0);
result[1] = labelset.getLabel(labelset.getPos(this.term.getLabel()) - 1);
break;
case GreaterThan:
cardinality = labelset.getCardinality();
result[0] = labelset.getLabel(labelset.getPos(this.term.getLabel()) + 1);
result[1] = labelset.getLabel(cardinality - 1);
break;
default:
result = null;
}
} else if (isBinary()) {
result[0] = this.lowerTerm.getLabel();
result[1] = this.upperTerm.getLabel();
} else {
result = null;
}
return result;
}
private TrapezoidalFunction computeFuzzyEnvelopeBinaryRelation(int cardinality, int[] envelope) {
double a, b, c, d;
a = this.lowerTerm.getFuzzyNumber().getA();
d = this.upperTerm.getFuzzyNumber().getD();
if (envelope[0] + 1 == envelope[1]) {
b = this.lowerTerm.getFuzzyNumber().getB();
c = this.upperTerm.getFuzzyNumber().getB();
} else {
b = computeUnknownBBetweenCase();
c = computeUnknownCBetweenCase();
}
TrapezoidalFunction envelopeBinary = new TrapezoidalFunction();
envelopeBinary.setLimits(new double[] {a, b, c, d});
return envelopeBinary;
}
private Double computeUnknownBBetweenCase() {
AggregationOperator owa = this.operatorService.getAggregationOperator(OWA.ID, "flintstones.valuation.twoTuple");
TwoTupleValuation aux = (TwoTupleValuation) ((OWA) owa).computeAggregation(computeValuationsBetweenCasePointB(getEnvelopeIndex()),
computeOWAWeightsBetweenCase(true, 0d));
return aux.getFuzzyNumber().getB();
}
private List<Valuation> computeValuationsBetweenCasePointB(int[] envelope) {
List<Valuation> valuations = new LinkedList<Valuation>();
int max;
if ((envelope[0] + envelope[1]) % 2 != 0) {
max = (envelope[0] + envelope[1] - 1) / 2;
} else {
max = (envelope[0] + envelope[1]) / 2;
}
valuations.add(this.lowerTerm);
for (int i = envelope[0] + 1; i <= max; i++) {
TwoTupleValuation twoTupleTem = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTupleTem.build((FuzzySet) this.domain, ((FuzzySet) this.domain).getLabelSet().getLabel(i));
valuations.add(twoTupleTem);
}
return valuations;
}
private List<Double> computeOWAWeightsBetweenCase(Boolean pointB, Double alpha) {
YagerQuantifiers.NumeredQuantificationType nqt = YagerQuantifiers.NumeredQuantificationType.FilevYager;
double[] auxWeights = YagerQuantifiers.QWeigthedBinaryRelation(nqt,
((FuzzySet) this.domain).getLabelSet().getCardinality() - 1, getEnvelopeIndex(), pointB, alpha);
List<Double> weights = new LinkedList<Double>();
for (Double w : auxWeights) {
weights.add(w);
}
return weights;
}
private Double computeUnknownCBetweenCase() {
AggregationOperator owa = this.operatorService.getAggregationOperator(OWA.ID, "flintstones.valuation.twoTuple");
TwoTupleValuation aux = (TwoTupleValuation) ((OWA) owa).computeAggregation(computeValuationsBetweenCasePointC(getEnvelopeIndex()),
computeOWAWeightsBetweenCase(false, 1d));
return aux.getFuzzyNumber().getB();
}
private List<Valuation> computeValuationsBetweenCasePointC(int[] envelope) {
List<Valuation> valuations = new LinkedList<Valuation>();
int max;
if ((envelope[0] + envelope[1]) % 2 != 0) {
max = (envelope[0] + envelope[1] + 1) / 2;
} else {
max = (envelope[0] + envelope[1]) / 2;
}
valuations.add(this.upperTerm);
for (int i = envelope[1] - 1; i >= max; i--) {
TwoTupleValuation twoTupleTem = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTupleTem.build((FuzzySet) this.domain, ((FuzzySet) this.domain).getLabelSet().getLabel(i));
valuations.add(twoTupleTem);
}
return valuations;
}
private TrapezoidalFunction computeFuzzyEnvelopeUnaryRelation(int cardinality, int[] envelope, Boolean atMostCase) {
double a, b, c, d;
if (atMostCase.booleanValue()) {
a = 0.0D;
b = 0.0D;
c = computeUnknownC();
d = ((FuzzySet) this.domain).getLabelSet().getLabel(envelope[1]).getSemantic().getCoverage().getMax();
} else {
a = ((FuzzySet) this.domain).getLabelSet().getLabel(envelope[0]).getSemantic().getCoverage().getMin();
b = computeUnknownB();
c = 1.0D;
d = 1.0D;
}
TrapezoidalFunction envelopeUnary = new TrapezoidalFunction();
envelopeUnary.setLimits(new double[] {a, b, c, d});
return envelopeUnary;
}
private Double computeUnknownC() {
AggregationOperator owa = this.operatorService.getAggregationOperator(OWA.ID, "flintstones.valuation.twoTuple");
TwoTupleValuation aux = (TwoTupleValuation) ((OWA) owa).computeAggregation(computeValuationsAtMostCase(getEnvelopeIndex()),
computeOWAWeights(1d, true));
return aux.getFuzzyNumber().getB();
}
private List<Valuation> computeValuationsAtMostCase(int[] envelope) {
List<Valuation> valuations = new LinkedList<Valuation>();
for (int i = envelope[0]; i <= envelope[1] - 1; i++) {
TwoTupleValuation twoTupleTem = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTupleTem.build((FuzzySet) this.domain, ((FuzzySet) this.domain).getLabelSet().getLabel(i));
valuations.add(twoTupleTem);
}
valuations.add(this.term);
return valuations;
}
private List<Double> computeOWAWeights(Double alpha, Boolean lower) {
YagerQuantifiers.NumeredQuantificationType nqt = YagerQuantifiers.NumeredQuantificationType.FilevYager;
double[] auxWeights = YagerQuantifiers.QWeigthedUnaryRelation(nqt,
((FuzzySet) this.domain).getLabelSet().getCardinality() - 1, getEnvelopeIndex(), lower, alpha);
List<Double> weights = new LinkedList<Double>();
for (Double w : auxWeights) {
weights.add(w);
}
return weights;
}
private Double computeUnknownB() {
AggregationOperator owa = this.operatorService.getAggregationOperator(OWA.ID, "flintstones.valuation.twoTuple");
TwoTupleValuation aux = (TwoTupleValuation) ((OWA) owa).computeAggregation(computeValuationsAtLeastCase(getEnvelopeIndex()),
computeOWAWeights(0d, false));
return aux.getFuzzyNumber().getB();
}
private List<Valuation> computeValuationsAtLeastCase(int[] envelope) {
List<Valuation> valuations = new LinkedList<Valuation>();
valuations.add(this.term);
for (int i = envelope[0] + 1; i <= envelope[1]; i++) {
TwoTupleValuation twoTupleTem = ContextInjectionFactory.make(TwoTupleValuation.class, context);
twoTupleTem.build((FuzzySet) this.domain, ((FuzzySet) this.domain).getLabelSet().getLabel(i));
valuations.add(twoTupleTem);
}
return valuations;
}
private void computeELICITExpressionAtMostCase() {
// Step 1: Compute 2-tuple term from point b of beta to obtain the fuzzy
// envelope
setUnaryRelation(EUnaryRelationType.AtMost, compute2TupleTerm(this.beta.getC()));
// Step 2: Compute fuzzy envelope
TrapezoidalFunction fuzzyEnvelope = calculateFuzzyEnvelope();
// Step 3: Compute gamma
setGamma1(this.beta.getD() - fuzzyEnvelope.getD());
}
private void computeELICITPrimary() {
setTwoTupleLabel(compute2TupleTerm(this.beta.getB()));
}
private void computeELICITExpressionBetweenCase() {
// Step 1: Compute 2-tuple term from point b and c of beta to obtain the fuzzy
// envelope
setBinaryRelation(compute2TupleTerm(this.beta.getB()), compute2TupleTerm(this.beta.getC()));
// Step 2: Compute fuzzy envelope
TrapezoidalFunction fuzzyEnvelope = calculateFuzzyEnvelope();
// Step 3: Compute gammas
setGamma1(this.beta.getA() - fuzzyEnvelope.getA());
setGamma2(this.beta.getD() - fuzzyEnvelope.getD());
}
public TrapezoidalFunction computeInverse() {
Double a = null, b = null, c = null, d = null;
TrapezoidalFunction fuzzyEnvelope = this.calculateFuzzyEnvelope();
if (this.isPrimary()) {
TrapezoidalFunction tpf = getTwoTupleLabel().getFuzzyNumber();
a = tpf.getA();
b = tpf.getB();
c = tpf.getC();
d = tpf.getD();
} else if (this.isUnary()) {
if (this.unaryRelation.equals(EUnaryRelationType.AtLeast)) {
a = fuzzyEnvelope.getA() + this.gamma1;
b = fuzzyEnvelope.getB();
c = d = fuzzyEnvelope.getC();
} else if (this.unaryRelation.equals(EUnaryRelationType.AtMost)) {
a = b = fuzzyEnvelope.getA();
c = fuzzyEnvelope.getC();
d = fuzzyEnvelope.getD() + this.gamma1;
}
} else {
a = fuzzyEnvelope.getA() + this.gamma1;
b = fuzzyEnvelope.getB();
c = fuzzyEnvelope.getC();
d = fuzzyEnvelope.getD() + this.gamma2;
}
this.beta = new TrapezoidalFunction();
this.beta.setLimits(new double[] {a, b, c, d});
return this.beta;
}
public String toString() {
if (isPrimary()) {
return (this.label + " in " + this.domain.toString());
} else if (isUnary()) {
return (this.unaryRelation.toString() + " " + this.term + " in " //$NON-NLS-1$
+ this.domain.toString());
} else if (isBinary()) {
return ("Between" + this.lowerTerm + " and "
+ this.upperTerm + " in " + this.domain.toString());
} else {
return ""; //$NON-NLS-1$
}
}
@Override
public String changeFormatValuationToString() {
StringBuilder sb = new StringBuilder();
if (isPrimary()) {
return sb.append(this.label.prettyFormat()).toString();
} else {
if (isUnary()) {
String aux = this.getUnaryRelation().toString();
String[] splitUpper = aux.split("(?=\\p{Lu})");
aux = splitUpper[0] + " " + splitUpper[1].toLowerCase();
return sb.append(aux).append(' ') // $NON-NLS-1$
.append(getTwoTupleTerm().prettyFormat()).append('^') // $NON-NLS-1$
.append('(') // $NON-NLS-1$
.append(Math.round(this.gamma1 * 1000d) / 1000d).append(')').toString(); // $NON-NLS-1$
} else {
return sb.append("Bt").append(' ') // $NON-NLS-1$
.append(getTwoTupleLowerTerm().prettyFormat()).append('^') // $NON-NLS-1$
.append('(') // $NON-NLS-1$
.append(Math.round(this.gamma1 * 1000d) / 1000d).append(')') // $NON-NLS-1$
.append(' ').append("and").append(' ')
.append(getTwoTupleUpperTerm().prettyFormat()).append('^') // $NON-NLS-1$
.append('(') // $NON-NLS-1$
.append(Math.round(this.gamma2 * 1000d) / 1000d).append(')').toString(); // $NON-NLS-1$
}
}
}
@Override
public Valuation negateValuation() {
return null;
}
@Override
public int hashCode() {
if (this.unaryRelation != null) {
return new HashCodeBuilder(17, 31).append(this.label)
.append(this.domain)
.append(this.unaryRelation.toString())
.append(this.term)
.append(this.lowerTerm)
.append(this.upperTerm)
.toHashCode();
}
return new HashCodeBuilder(17, 31).append(this.label)
.append(this.domain)
.append("") //$NON-NLS-1$
.append(this.term)
.append(this.lowerTerm)
.append(this.upperTerm)
.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj.getClass() != this.getClass())
return false;
final ELICIT other = (ELICIT) obj;
return new EqualsBuilder().append(this.label, other.label)
.append(this.domain, other.domain)
.append(this.unaryRelation, other.unaryRelation)
.append(this.term, other.term)
.append(this.lowerTerm, other.lowerTerm)
.append(this.upperTerm, other.upperTerm)
.isEquals();
}
@Override
public Object clone() {
Object result = null;
result = super.clone();
return result;
}
private void disablePrimary() {
this.label = null;
}
private void disableRelations() {
this.disableUnary();
this.disableBinary();
}
private void disableUnary() {
this.unaryRelation = null;
this.term = null;
}
private void disableBinary() {
this.lowerTerm = null;
this.upperTerm = null;
}
/**
* S. Abbasbandy and T. Hajjari, “A new approach for ranking of trapezoidal fuzzy numbers,” Computers & Mathematics with Applications, vol. 57, no. 3, pp. 413419, 2009.
*/
@Override
public int compareTo(Valuation other) {
Validator.notNull(other);
Validator.notIllegalElementType(other, new String[] { ELICIT.class.toString() });
if (this.domain.equals(other.getDomain())) {
Double mag1 = this.computeMagnitude(this.beta);
Double mag2 = this.computeMagnitude(((ELICIT) other).getBeta());
return mag1.compareTo(mag2);
} else {
throw new IllegalArgumentException("Different domains");
}
}
private Double computeMagnitude(TrapezoidalFunction vtr) {
double alpha = distance(vtr.getA(), vtr.getB());
double beta = distance(vtr.getC(), vtr.getD());
return (1d / 2d) * (vtr.getB() + vtr.getC() - (alpha / 6) + (beta / 6));
}
private Double distance(double pointA, double pointB) {
return Math.abs(pointA - pointB);
}
public int[] getEnvelopeLinguisticLabelsIndex() {
int[] result = null;
LabelLinguisticDomain[] envelope = getEnvelope();
if (envelope != null) {
result = new int[2];
result[0] = ((FuzzySet) this.domain).getLabelSet().getPos(envelope[0]);
result[1] = ((FuzzySet) this.domain).getLabelSet().getPos(envelope[1]);
}
return result;
}
public TwoTupleValuation[] getEnvelopeELICITExpression() {
TwoTupleValuation[] result = new TwoTupleValuation[2];
int cardinality;
if (isPrimary()) {
result[0] = this.label;
result[1] = this.label;
} else if (isUnary()) {
switch (this.unaryRelation) {
case AtLeast:
cardinality = ((FuzzySet) this.domain).getLabelSet().getCardinality();
TwoTupleValuation envelopeUpperTerm = ContextInjectionFactory.make(TwoTupleValuation.class, context);
envelopeUpperTerm.build((FuzzySet) this.domain, ((FuzzySet) this.domain).getLabelSet().getLabel(cardinality - 1));
result[0] = this.term;
result[1] = envelopeUpperTerm;
break;
case AtMost:
TwoTupleValuation envelopeLowerTerm = ContextInjectionFactory.make(TwoTupleValuation.class, context);
envelopeLowerTerm.build((FuzzySet) this.domain, ((FuzzySet) this.domain).getLabelSet().getLabel(0));
result[0] = envelopeLowerTerm;
result[1] = this.term;
break;
default:
result = null;
}
} else if (isBinary()) {
result[0] = this.lowerTerm;
result[1] = this.upperTerm;
} else {
result = null;
}
return result;
}
@Override
public void initFromString(String value) {
throw new UnsupportedOperationException("Implementar, debería recibir la info y setearla");
}
@Override
public void write(XMLStreamWriter writer) {}
@Override
public void read(WNode node) {}
}