public code v1
This commit is contained in:
+271
@@ -0,0 +1,271 @@
|
||||
package flintstones.valuation.twoTuple;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
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 org.eclipse.e4.core.services.nls.Translation;
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.valuation.linguistic.LinguisticValuation;
|
||||
import flintstones.valuation.twoTuple.messages.Messages;
|
||||
|
||||
public class TwoTupleValuation extends LinguisticValuation {
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
public static final String ID = "flintstones.valuation.twoTuple"; //$NON-NLS-1$
|
||||
|
||||
private double _alpha;
|
||||
|
||||
|
||||
public TwoTupleValuation() {}
|
||||
|
||||
public TwoTupleValuation(FuzzySet domain){
|
||||
this.domain = domain;
|
||||
this._label = null;
|
||||
this._alpha = 0d;
|
||||
|
||||
this.setId(TwoTupleValuation.ID);
|
||||
}
|
||||
|
||||
public TwoTupleValuation(FuzzySet domain, LabelLinguisticDomain label) {
|
||||
this.domain = domain;
|
||||
this._label = label;
|
||||
this._alpha = 0d;
|
||||
|
||||
this.setId(TwoTupleValuation.ID);
|
||||
}
|
||||
|
||||
public TwoTupleValuation(FuzzySet domain, LabelLinguisticDomain label, double alpha) {
|
||||
this.domain = domain;
|
||||
this._label = label;
|
||||
this._alpha = alpha;
|
||||
|
||||
this.setId(TwoTupleValuation.ID);
|
||||
}
|
||||
|
||||
public void build(FuzzySet domain){
|
||||
this.build(domain, null, 0d);
|
||||
}
|
||||
|
||||
public void build(FuzzySet domain, LabelLinguisticDomain label) {
|
||||
this.build(domain, label, 0d);
|
||||
}
|
||||
|
||||
public void build(FuzzySet domain, LabelLinguisticDomain label, double alpha) {
|
||||
// 0 Params
|
||||
this.setId(TwoTupleValuation.ID);
|
||||
|
||||
// 1 Param
|
||||
if(domain != null) {
|
||||
this.setDomain(domain);
|
||||
this._alpha = 0d;
|
||||
}
|
||||
|
||||
// 2 Params
|
||||
if(label != null) {
|
||||
this.setLabel(label);
|
||||
}
|
||||
|
||||
this.setAlpha(alpha);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLabel(String name) {
|
||||
super.setLabel(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLabel(LabelLinguisticDomain label) {
|
||||
super.setLabel(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLabel(int pos) {
|
||||
super.setLabel(pos);
|
||||
}
|
||||
|
||||
public void setAlpha(double alpha) {
|
||||
Validator.notInvalidSize(alpha, -0.5, 0.5, "alpha"); //$NON-NLS-1$
|
||||
|
||||
int pos = ((FuzzySet) this.domain).getLabelSet()
|
||||
.getPos(this._label);
|
||||
|
||||
if ((pos == 0) && (alpha < 0))
|
||||
throw new IllegalArgumentException(this.messages.TwoTuple_Invalid_alpha_value);
|
||||
|
||||
if ((pos == ((FuzzySet) this.domain).getLabelSet()
|
||||
.getCardinality() - 1) && (alpha > 0))
|
||||
throw new IllegalArgumentException(this.messages.TwoTuple_Invalid_alpha_value);
|
||||
|
||||
this._alpha = alpha;
|
||||
}
|
||||
|
||||
public double getAlpha() {
|
||||
return this._alpha;
|
||||
}
|
||||
|
||||
public void calculateDelta(double beta) {
|
||||
int labelIndex = (int) Math.round(beta);
|
||||
this.setLabel(labelIndex);
|
||||
|
||||
double alpha = Math.round((beta - labelIndex) * 10000d) / 10000d;
|
||||
|
||||
if (alpha == 0.5) {
|
||||
labelIndex++;
|
||||
this.setLabel(labelIndex);
|
||||
alpha = -0.5;
|
||||
}
|
||||
|
||||
this.setAlpha(alpha);
|
||||
}
|
||||
|
||||
public double calculateInverseDelta() {
|
||||
return this._alpha + ((FuzzySet) this.domain).getLabelSet()
|
||||
.getPos(this._label);
|
||||
}
|
||||
|
||||
public double calculateReverseDelta() {
|
||||
return (((FuzzySet) this.domain).getLabelSet()
|
||||
.getPos(this._label) / ((FuzzySet) this.domain).getLabelSet().getCardinality() - 1) + this._alpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuation negateValuation() {
|
||||
TwoTupleValuation result = (TwoTupleValuation) this.clone();
|
||||
|
||||
FuzzySet fdomain = (FuzzySet) this.domain;
|
||||
if (fdomain.getLabelSet().getCardinality() > 1)
|
||||
result.calculateDelta((fdomain.getLabelSet().getCardinality() - 1) - this.calculateInverseDelta());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public TwoTupleValuation transform(FuzzySet fuzzySet) {
|
||||
|
||||
TwoTupleValuation result = null;
|
||||
|
||||
Validator.notNull(fuzzySet);
|
||||
|
||||
if (!fuzzySet.isBLTS())
|
||||
throw new IllegalArgumentException(this.messages.TwoTuple_Not_BLTS_fuzzy_set);
|
||||
|
||||
int thisCardinality = ((FuzzySet) this.domain).getLabelSet().getCardinality();
|
||||
int otherCardinality = fuzzySet.getLabelSet().getCardinality();
|
||||
|
||||
double numerator = this.calculateInverseDelta() * (otherCardinality - 1);
|
||||
double denominator = thisCardinality - 1;
|
||||
|
||||
double beta = numerator / denominator;
|
||||
|
||||
result = ContextInjectionFactory.make(TwoTupleValuation.class, context);
|
||||
result.build(fuzzySet);
|
||||
result.calculateDelta(beta);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction getFuzzyNumber() {
|
||||
double distance = _alpha / (((FuzzySet) domain).getLabelSet().getCardinality() - 1);
|
||||
|
||||
double a;
|
||||
if(((TrapezoidalFunction) _label.getSemantic()).getA() + distance < 0)
|
||||
a = ((TrapezoidalFunction) _label.getSemantic()).getA();
|
||||
else
|
||||
a = ((TrapezoidalFunction) _label.getSemantic()).getA() + distance;
|
||||
|
||||
double d;
|
||||
if(((TrapezoidalFunction) _label.getSemantic()).getA() + distance > 1)
|
||||
d = ((TrapezoidalFunction) _label.getSemantic()).getD();
|
||||
else
|
||||
d = ((TrapezoidalFunction) _label.getSemantic()).getD() + distance;
|
||||
|
||||
TrapezoidalFunction fuzzyNumber = new TrapezoidalFunction();
|
||||
fuzzyNumber.setLimits(new double[] {a, ((TrapezoidalFunction) _label.getSemantic()).getB() + distance,
|
||||
((TrapezoidalFunction) _label.getSemantic()).getC() + distance, d});
|
||||
return fuzzyNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ("[" + this._label + ", " + Math.round(this._alpha * 10000d) / 10000d + "]" + this.messages.TwoTuple_In + this.domain); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String changeFormatValuationToString() {
|
||||
return "[" + this._label.getName() + ", " + Math.round(this._alpha * 10000d) / 10000d + "]";
|
||||
}
|
||||
|
||||
public String prettyFormat() {
|
||||
return ("(" + this._label + ", " + Math.round(this._alpha * 100d) / 100d + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
if (this.getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
TwoTupleValuation other = (TwoTupleValuation) obj;
|
||||
return new EqualsBuilder().append(this._label, other._label)
|
||||
.append(this.domain, other.domain)
|
||||
.append(this._alpha, other._alpha)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 31).append(this._label)
|
||||
.append(this.domain)
|
||||
.append(this._alpha)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Valuation other) {
|
||||
Validator.notNull(other);
|
||||
Validator.notIllegalElementType(other, new String[] { TwoTupleValuation.class.toString() });
|
||||
|
||||
if (this.domain.equals(other.getDomain())) {
|
||||
LabelLinguisticDomain otherLabel = ((TwoTupleValuation) other)._label;
|
||||
double otherAlpha = ((TwoTupleValuation) other)._alpha;
|
||||
|
||||
int aux;
|
||||
if ((aux = this._label.compareTo(otherLabel)) == 0)
|
||||
return Double.compare(this._alpha, otherAlpha);
|
||||
return aux;
|
||||
}
|
||||
throw new IllegalArgumentException(this.messages.TwoTuple_Differentdomains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
TwoTupleValuation result = (TwoTupleValuation) super.clone();
|
||||
|
||||
result = ContextInjectionFactory.make(TwoTupleValuation.class, context);
|
||||
result.setId(this.getId());
|
||||
result.domain = domain;
|
||||
result._alpha = _alpha;
|
||||
result._label = _label;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// This file has been auto-generated
|
||||
package flintstones.valuation.twoTuple.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public String TwoTuple_Invalid_alpha_value;
|
||||
public String TwoTuple_Not_BLTS_fuzzy_set;
|
||||
public String TwoTuple_In;
|
||||
public String TwoTuple_Differentdomains;
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
TwoTuple_Different_domains=Different domains
|
||||
TwoTuple_In=\ in
|
||||
TwoTuple_Invalid_alpha_value=Invalid alpha value
|
||||
TwoTuple_Not_BLTS_fuzzy_set=Not BLTS fuzzy set.
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
TwoTuple_Different_domains=Diferentes dominios
|
||||
TwoTuple_In=\ en
|
||||
TwoTuple_Invalid_alpha_value=Valor alpha no valido
|
||||
TwoTuple_Not_BLTS_fuzzy_set=No BLTS fuzzy establecido.
|
||||
Reference in New Issue
Block a user