public code v1
This commit is contained in:
@@ -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,14 @@
|
||||
<?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.domain.fuzzyset</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Fuzzyset</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.domain.fuzzyset</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>1779484362537</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,19 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name
|
||||
Bundle-SymbolicName: flintstones.domain.fuzzyset;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.domain.numeric.real;visibility:=reexport,
|
||||
flintstones.helper.data.wxml,
|
||||
flintstones.entity.domain,
|
||||
javax.inject,
|
||||
org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.di,
|
||||
org.apache.commons.lang,
|
||||
javax.annotation
|
||||
Export-Package: flintstones.domain.fuzzyset,
|
||||
flintstones.domain.fuzzyset.function.types,
|
||||
flintstones.domain.fuzzyset.label,
|
||||
flintstones.domain.fuzzyset.semantic
|
||||
Automatic-Module-Name: flintstones.domain.fuzzyset
|
||||
@@ -0,0 +1,6 @@
|
||||
#Properties file for flintstones.domain.fuzzyset
|
||||
Bundle-Name = Fuzzyset
|
||||
domain.name.linguistic = Linguistic
|
||||
domain.name.hesitant = Hesitant
|
||||
domain.type.linguistic = Linguistic
|
||||
domain.type.hesitant = Linguistic
|
||||
@@ -0,0 +1,6 @@
|
||||
#Properties file for flintstones.domain.fuzzyset
|
||||
Bundle-Name = Conjunto difuso
|
||||
domain.name.linguistic = Lingüístico
|
||||
domain.name.hesitant = Hesitant
|
||||
domain.type.linguistic = Lingüísticos
|
||||
domain.type.hesitant = Lingüísticos
|
||||
@@ -0,0 +1,7 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml,\
|
||||
OSGI-INF/l10n/bundle.properties,\
|
||||
OSGI-INF/
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="flintstones.entity.domain">
|
||||
<domain
|
||||
category="flintstones.domain.linguistic.category"
|
||||
implementation="flintstones.domain.fuzzyset.FuzzySet"
|
||||
label="%domain.name.linguistic"
|
||||
uid="flintstones.domain.linguistic">
|
||||
</domain>
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
point="flintstones.entity.domain">
|
||||
<domain
|
||||
category="flintstones.domain.linguistic.category"
|
||||
implementation="flintstones.domain.fuzzyset.FuzzySet"
|
||||
label="%domain.name.hesitant"
|
||||
uid="flintstones.domain.hesitant">
|
||||
</domain>
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
point="flintstones.entity.domain.domain_category">
|
||||
<domain_category
|
||||
label="%domain.type.linguistic"
|
||||
uid="flintstones.domain.linguistic.category">
|
||||
</domain_category>
|
||||
</extension>
|
||||
<extension
|
||||
point="flintstones.entity.domain.fastadd">
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticQualityInstance"
|
||||
label="Quality Linguistic Domain"
|
||||
uid="flintstones.domain.fuzzyset.quality">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticRandomInstance"
|
||||
label="Random Linguistic Domain"
|
||||
uid="flintstones.domain.fuzzyset.random">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.hesitant"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticQualityInstance"
|
||||
label="Quality Hesitant Domain"
|
||||
uid="flintstones.domain.hesitant.quality">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.hesitant"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticRandomInstance"
|
||||
label="Random Hesitant Domain"
|
||||
uid="flintstones.domain.hesitant.random">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticS3Instance"
|
||||
label="S3 Linguistic Domain"
|
||||
uid="flintstones.domain.fuzzyset.s3">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticS5Instance"
|
||||
label="S5 Linguistic Domain"
|
||||
uid="flintstones.domain.fuzzyset.s5">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticS7Instance"
|
||||
label="S7 Linguistic Domain"
|
||||
uid="flintstones.domain.fuzzyset.s7">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic"
|
||||
implementation="flintstones.domain.fuzzyset.instance.LinguisticS9Instance"
|
||||
label="S9 Linguistic Domain"
|
||||
uid="flintstones.domain.fuzzyset.s9">
|
||||
</domain_instance>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
@@ -0,0 +1,595 @@
|
||||
package flintstones.domain.fuzzyset;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
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 org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.domain.fuzzyset.function.FragmentFunction;
|
||||
import flintstones.domain.fuzzyset.function.IFragmentFunction;
|
||||
import flintstones.domain.fuzzyset.function.types.LinearPieceFunction;
|
||||
import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction;
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
import flintstones.domain.fuzzyset.label.LabelSetLinguisticDomain;
|
||||
import flintstones.domain.fuzzyset.messages.Messages;
|
||||
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.helper.data.wxml.WNode;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FuzzySet extends Domain {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
public static final String ID = "flintstones.domain.linguistic"; //$NON-NLS-1$
|
||||
public static final int MINIMUM_NUMBER_LABELS = 3; // $NON-NLS-1$
|
||||
|
||||
protected LabelSetLinguisticDomain _labelSet;
|
||||
protected List<Double> _values;
|
||||
|
||||
public static enum Fields implements ExtensionEnum {
|
||||
value, values, v, labelSet
|
||||
};
|
||||
|
||||
public FuzzySet() {
|
||||
super();
|
||||
this._labelSet = new LabelSetLinguisticDomain();
|
||||
this._values = new LinkedList<>();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
this._labelSet = ContextInjectionFactory.make(LabelSetLinguisticDomain.class, this.context);
|
||||
this._values = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void clearFuzzySet() {
|
||||
this._labelSet = ContextInjectionFactory.make(LabelSetLinguisticDomain.class, this.context);
|
||||
this._values = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void setValues(List<Double> values) {
|
||||
Validator.notNull(values);
|
||||
int cardinality = this._labelSet.getCardinality();
|
||||
Validator.notInvalidSize(values.size(), cardinality, cardinality);
|
||||
for (Double value : values) {
|
||||
Validator.notNull(value);
|
||||
Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
this._values = values;
|
||||
}
|
||||
|
||||
public void setValue(int pos, Double value) {
|
||||
Validator.notEmpty(this._labelSet.getLabels().toArray());
|
||||
Validator.notInvalidSize(pos, 0, this._labelSet.getCardinality() - 1);
|
||||
|
||||
Validator.notNull(value);
|
||||
Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$
|
||||
|
||||
this._values.set(pos, value);
|
||||
}
|
||||
|
||||
public void setValue(String name, Double value) {
|
||||
Validator.notNull(name);
|
||||
Validator.notNull(value);
|
||||
Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$
|
||||
|
||||
int pos = this._labelSet.getPos(name);
|
||||
|
||||
if (pos != -1)
|
||||
this.setValue(pos, value);
|
||||
else
|
||||
throw new IllegalArgumentException(this.messages.FuzzySet_Inexistent_element);
|
||||
}
|
||||
|
||||
public void setValue(LabelLinguisticDomain label, Double value) {
|
||||
Validator.notNull(label);
|
||||
Validator.notNegative(value);
|
||||
Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$
|
||||
|
||||
int pos = this._labelSet.getPos(label);
|
||||
|
||||
if (pos != -1)
|
||||
this.setValue(pos, value);
|
||||
else
|
||||
throw new IllegalArgumentException(this.messages.FuzzySet_Inexistent_element);
|
||||
}
|
||||
|
||||
public Double getValue(int pos) {
|
||||
Validator.notEmpty(this._labelSet.getLabels().toArray());
|
||||
Validator.notInvalidSize(pos, 0, this._labelSet.getCardinality() - 1);
|
||||
|
||||
return this._values.get(pos);
|
||||
}
|
||||
|
||||
public Double getValue(String name) {
|
||||
|
||||
int pos = this._labelSet.getPos(name);
|
||||
|
||||
if (pos != -1)
|
||||
return this.getValue(pos);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Double getValue(LabelLinguisticDomain label) {
|
||||
|
||||
int pos = this._labelSet.getPos(label);
|
||||
|
||||
if (pos != -1)
|
||||
return this.getValue(pos);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public List<Double> getValues() {
|
||||
return this._values;
|
||||
}
|
||||
|
||||
public void setLabelSet(LabelSetLinguisticDomain labelSet) {
|
||||
this._labelSet = labelSet;
|
||||
}
|
||||
|
||||
public LabelSetLinguisticDomain getLabelSet() {
|
||||
return this._labelSet;
|
||||
}
|
||||
|
||||
public void addLabel(LabelLinguisticDomain label) {
|
||||
|
||||
int labels = this._labelSet.getCardinality();
|
||||
|
||||
if (labels == 0)
|
||||
this.addLabel(labels, label);
|
||||
else {
|
||||
boolean lower = false;
|
||||
int counter = 0;
|
||||
do
|
||||
if (label.compareTo(this._labelSet.getLabels().get(counter)) <= 0)
|
||||
lower = true;
|
||||
else
|
||||
counter++;
|
||||
while ((!lower) && (counter < labels));
|
||||
|
||||
if (lower)
|
||||
this.addLabel(counter, label);
|
||||
else
|
||||
this.addLabel(labels, label);
|
||||
}
|
||||
}
|
||||
|
||||
public void addLabel(LabelLinguisticDomain label, Double value) {
|
||||
this.addLabel(this._labelSet.getCardinality(), label, value);
|
||||
}
|
||||
|
||||
public void addLabel(int pos, LabelLinguisticDomain label) {
|
||||
this._labelSet.addLabel(pos, label);
|
||||
this._values.add(pos, 0d);
|
||||
}
|
||||
|
||||
public void addLabel(int pos, LabelLinguisticDomain label, Double value) {
|
||||
this._labelSet.addLabel(pos, label);
|
||||
|
||||
Validator.notNull(value);
|
||||
Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$
|
||||
|
||||
this._values.add(pos, value);
|
||||
}
|
||||
|
||||
public void removeLabel(int pos) {
|
||||
Validator.notEmpty(this._labelSet.getLabels().toArray());
|
||||
Validator.notInvalidSize(pos, 0, this._labelSet.getCardinality() - 1);
|
||||
|
||||
this._labelSet.getLabels().remove(pos);
|
||||
this._values.remove(pos);
|
||||
}
|
||||
|
||||
public void removeLabel(String name) {
|
||||
|
||||
if (name == null)
|
||||
return;
|
||||
|
||||
int pos = this._labelSet.getPos(name);
|
||||
|
||||
if (pos != -1)
|
||||
this.removeLabel(pos);
|
||||
}
|
||||
|
||||
public void removeLabel(LabelLinguisticDomain label) {
|
||||
|
||||
if (label == null)
|
||||
return;
|
||||
|
||||
int pos = this._labelSet.getPos(label);
|
||||
|
||||
if (pos != -1)
|
||||
this.removeLabel(pos);
|
||||
}
|
||||
|
||||
public void addValues(List<LabelLinguisticDomain> labels) {
|
||||
List<Double> values = new LinkedList<>();
|
||||
for (int element = 0; element < labels.size(); ++element)
|
||||
values.add(0d);
|
||||
|
||||
this._values = values;
|
||||
}
|
||||
|
||||
public void createTrapezoidalFunction(String[] labels) {
|
||||
LabelLinguisticDomain currentLabel;
|
||||
IMembershipFunction semantic;
|
||||
|
||||
this.clearFuzzySet();
|
||||
|
||||
if (labels.length == 1) {
|
||||
semantic = new TrapezoidalFunction();
|
||||
semantic.setLimits(new double[] { 0, 0, 1, 1 });
|
||||
|
||||
currentLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
currentLabel.initLabelLinguisticDomain(labels[0], semantic);
|
||||
|
||||
this.addLabel(currentLabel);
|
||||
} else {
|
||||
int numLabels = labels.length;
|
||||
double lower, central, upper, increment = 1d / (numLabels - 1), factor = 1e5;
|
||||
|
||||
for (int i = 0; i < numLabels; ++i) {
|
||||
lower = (i == 0) ? 0 : increment * (i - 1);
|
||||
central = increment * i;
|
||||
upper = (i == (numLabels - 1)) ? 1 : increment * (i + 1);
|
||||
|
||||
lower = Math.round(lower * factor) / factor;
|
||||
central = Math.round(central * factor) / factor;
|
||||
upper = Math.round(upper * factor) / factor;
|
||||
|
||||
semantic = new TrapezoidalFunction();
|
||||
semantic.setLimits(new double[] { lower, central, upper });
|
||||
|
||||
currentLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
currentLabel.initLabelLinguisticDomain(labels[i], semantic);
|
||||
|
||||
ContextInjectionFactory.inject(currentLabel, this.context);
|
||||
|
||||
this.addLabel(currentLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double chi() {
|
||||
double result, valuesSum, sum;
|
||||
int pos;
|
||||
|
||||
if (this._labelSet.getCardinality() == 0)
|
||||
return 0;
|
||||
|
||||
sum = valuesSum = pos = 0;
|
||||
|
||||
for (Double value : this._values) {
|
||||
sum += value * pos++;
|
||||
valuesSum += value;
|
||||
}
|
||||
|
||||
result = sum / valuesSum;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isFuzzy() {
|
||||
int cardinality = this._labelSet.getCardinality();
|
||||
|
||||
if (cardinality == 0)
|
||||
return false;
|
||||
|
||||
FragmentFunction fragmentFunction = new FragmentFunction();
|
||||
FragmentFunction semantic;
|
||||
Map<NumericRealDomain, IFragmentFunction> pieces;
|
||||
for (LabelLinguisticDomain label : this._labelSet.getLabels()) {
|
||||
semantic = label.getSemantic().toFragmentFunction();
|
||||
pieces = semantic.getPieces();
|
||||
for (NumericRealDomain domain : pieces.keySet()) {
|
||||
fragmentFunction.addPiece(domain, pieces.get(domain));
|
||||
fragmentFunction.simplify();
|
||||
}
|
||||
}
|
||||
|
||||
pieces = fragmentFunction.getPieces();
|
||||
if (pieces.size() == 1) {
|
||||
Object[] values = pieces.values().toArray();
|
||||
LinearPieceFunction piece = (LinearPieceFunction) values[0];
|
||||
if (piece != null)
|
||||
if ((Math.round(piece.getSlope() * 100d) / 100d == 0)
|
||||
&& (Math.round(piece.getCutOffY() * 100d) / 100d == 1))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOdd() {
|
||||
return (this._labelSet.getCardinality() % 2 != 0);
|
||||
}
|
||||
|
||||
public boolean isTriangular() {
|
||||
|
||||
if (this._labelSet.getCardinality() == 0)
|
||||
return false;
|
||||
|
||||
IMembershipFunction semantic;
|
||||
for (LabelLinguisticDomain label : this._labelSet.getLabels()) {
|
||||
semantic = label.getSemantic();
|
||||
if (semantic instanceof TrapezoidalFunction) {
|
||||
if (!((TrapezoidalFunction) semantic).isTriangular())
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isTOR() {
|
||||
if (this.isFuzzy())
|
||||
if (this.isOdd())
|
||||
return this.isTriangular();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSymmetrical() {
|
||||
|
||||
if (this._labelSet.getCardinality() == 0)
|
||||
return false;
|
||||
|
||||
double midPoint = this.midpoint();
|
||||
|
||||
if (midPoint != -1) {
|
||||
LabelLinguisticDomain label1, label2;
|
||||
int centralPos = this._labelSet.getCardinality() / 2;
|
||||
|
||||
for (int i = 0; i < centralPos; ++i) {
|
||||
label1 = this._labelSet.getLabels().get(i);
|
||||
label2 = this._labelSet.getLabels().get((this._labelSet.getCardinality() - 1) - i);
|
||||
if (!(label1.getSemantic().isSymmetrical(label2.getSemantic(), midPoint)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double midpoint() {
|
||||
LabelLinguisticDomain label1, label2;
|
||||
int centralPos = this._labelSet.getCardinality() / 2;
|
||||
double midPoint;
|
||||
|
||||
if (this.isOdd()) {
|
||||
label1 = this._labelSet.getLabels().get(centralPos);
|
||||
IMembershipFunction semantic = label1.getSemantic();
|
||||
if (!semantic.isSymmetrical())
|
||||
return -1;
|
||||
else
|
||||
midPoint = semantic.centroid();
|
||||
} else {
|
||||
label1 = this._labelSet.getLabels().get(centralPos - 1);
|
||||
label2 = this._labelSet.getLabels().get(centralPos);
|
||||
|
||||
midPoint = (label2.getSemantic().centroid() + label1.getSemantic().centroid()) / 2d;
|
||||
}
|
||||
|
||||
return midPoint;
|
||||
}
|
||||
|
||||
public boolean isUniform() {
|
||||
|
||||
int cardinality = this._labelSet.getCardinality();
|
||||
|
||||
if (cardinality <= 1)
|
||||
return true;
|
||||
|
||||
LabelLinguisticDomain label1 = this._labelSet.getLabels().get(0);
|
||||
LabelLinguisticDomain label2 = this._labelSet.getLabels().get(1);
|
||||
|
||||
double center1 = label1.getSemantic().getCenter().midpoint();
|
||||
double center2 = label2.getSemantic().getCenter().midpoint();
|
||||
double distance = center2 - center1;
|
||||
double error = (1 / Math.pow(10, Double.toString(distance).length() - 2)) * 1.5;
|
||||
double distanceLower = distance - error;
|
||||
double distanceUpper = distance + error;
|
||||
|
||||
for (int i = 2; i < cardinality; ++i) {
|
||||
label1 = (LabelLinguisticDomain) label2.clone();
|
||||
label2 = this._labelSet.getLabels().get(i);
|
||||
center1 = center2;
|
||||
center2 = label2.getSemantic().getCenter().midpoint();
|
||||
distance = center2 - center1;
|
||||
if (!((distanceLower <= distance) && (distance <= distanceUpper)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean belongtoFuzzySet(TrapezoidalFunction function) {
|
||||
for (LabelLinguisticDomain l : this._labelSet.getLabels()) {
|
||||
if (l.getSemantic().compareTo(function) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBLTS() {
|
||||
if (this.isTOR())
|
||||
if (this.isSymmetrical())
|
||||
return this.isUniform();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatDescriptionDomain() {
|
||||
String result = ""; //$NON-NLS-1$
|
||||
int cardinality;
|
||||
|
||||
if ((cardinality = this._labelSet.getCardinality()) != 0) {
|
||||
result += "("; //$NON-NLS-1$
|
||||
for (int i = 0; i < cardinality - 1; ++i)
|
||||
result += this._labelSet.getLabels().get(i).getName() + ", "; //$NON-NLS-1$
|
||||
result += this._labelSet.getLabels().get(cardinality - 1).getName() + ")"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = ""; //$NON-NLS-1$
|
||||
int cardinality = this._labelSet.getCardinality();
|
||||
|
||||
if (cardinality > 0)
|
||||
for (int i = 0; i < cardinality; ++i) {
|
||||
if (i > 0)
|
||||
result += ", "; //$NON-NLS-1$
|
||||
result += "[" + this._labelSet.getLabels() //$NON-NLS-1$
|
||||
.get(i) + ";" + this._values.get(i) + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
return "{" + result + "}"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public String toStringExport() {
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int cardinality = this._labelSet.getCardinality();
|
||||
if (cardinality > 0)
|
||||
for (int pos = 0; pos < cardinality; pos++) {
|
||||
if (pos > 0)
|
||||
result.append(", "); //$NON-NLS-1$
|
||||
result.append("["); //$NON-NLS-1$
|
||||
result.append(this._labelSet.getLabel(pos));
|
||||
result.append("::"); //$NON-NLS-1$
|
||||
result.append(((TrapezoidalFunction) this._labelSet.getLabel(pos).getSemantic()).toStringExport());
|
||||
result.append(";"); //$NON-NLS-1$
|
||||
result.append(this._values.get(pos));
|
||||
result.append("]"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return "{" + result + "}"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder hcb = new HashCodeBuilder(17, 31);
|
||||
hcb.append(super.hashCode());
|
||||
return hcb.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
if (this.getName() == null)
|
||||
return false;
|
||||
|
||||
if (this.getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
final FuzzySet other = (FuzzySet) obj;
|
||||
|
||||
EqualsBuilder eb = new EqualsBuilder();
|
||||
eb.append(this._values, other._values);
|
||||
|
||||
return eb.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
Object result;
|
||||
|
||||
result = super.clone();
|
||||
|
||||
List<Double> values = new LinkedList<>();
|
||||
for (Double value : this._values)
|
||||
values.add(Double.valueOf(value));
|
||||
|
||||
((FuzzySet) result)._values = values;
|
||||
((FuzzySet) result)._labelSet = (LabelSetLinguisticDomain) this._labelSet.clone();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter writer) throws XMLStreamException {
|
||||
writer.writeStartElement(FuzzySet.Fields.values.toString());
|
||||
for (Double value : _values) {
|
||||
writer.writeStartElement(FuzzySet.Fields.value.toString());
|
||||
writer.writeAttribute(FuzzySet.Fields.v.toString(), value.toString());
|
||||
writer.writeEndElement();
|
||||
}
|
||||
writer.writeEndElement();
|
||||
this._labelSet.write(writer);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(WNode node) {
|
||||
|
||||
if (node.getVersion().equals("3.0")) //$NON-NLS-1$
|
||||
this.readFS3(node);
|
||||
else
|
||||
this.readFS4(node);
|
||||
}
|
||||
|
||||
private void readFS3(WNode node) {
|
||||
WNode vNode = node.getFirst(FuzzySet.Fields.values);
|
||||
this.readValues(vNode);
|
||||
|
||||
WNode lNode = node.getFirst(FuzzySet.Fields.labelSet);
|
||||
this.readLabelSet(lNode);
|
||||
}
|
||||
|
||||
private void readFS4(WNode node) {
|
||||
this.readValues(node.getFirst(FuzzySet.Fields.values));
|
||||
|
||||
this.readLabelSet(node.getFirst(Fields.labelSet));
|
||||
}
|
||||
|
||||
private void readValues(WNode node) {
|
||||
List<WNode> values = node.getChildren();
|
||||
for (WNode item : values) {
|
||||
String valueS = item.getAttribute(FuzzySet.Fields.v);
|
||||
Double value = Double.valueOf(valueS);
|
||||
this._values.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void readLabelSet(WNode node) {
|
||||
this._labelSet = ContextInjectionFactory.make(LabelSetLinguisticDomain.class, this.context);
|
||||
this._labelSet.read(node);
|
||||
}
|
||||
|
||||
}
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
package flintstones.domain.fuzzyset.function;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import flintstones.domain.fuzzyset.function.types.LinearPieceFunction;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FragmentFunction {
|
||||
|
||||
Map<NumericRealDomain, IFragmentFunction> _pieces;
|
||||
|
||||
public FragmentFunction() {
|
||||
this._pieces = new HashMap<>();
|
||||
}
|
||||
|
||||
public Map<NumericRealDomain, IFragmentFunction> getPieces() {
|
||||
return this._pieces;
|
||||
}
|
||||
|
||||
public void addPiece(NumericRealDomain domain, IFragmentFunction piece) {
|
||||
Validator.notNull(domain);
|
||||
Validator.notNull(piece);
|
||||
|
||||
double otherMin = domain.getMin();
|
||||
double otherMax = domain.getMax();
|
||||
|
||||
if (otherMin == otherMax)
|
||||
return;
|
||||
|
||||
double currentMin, currentMax;
|
||||
NumericRealDomain lower, central, upper;
|
||||
IFragmentFunction currentPiece;
|
||||
|
||||
Set<NumericRealDomain> domains = this._pieces.keySet();
|
||||
|
||||
for (NumericRealDomain currentDomain : domains) {
|
||||
currentMin = currentDomain.getMin();
|
||||
currentMax = currentDomain.getMax();
|
||||
currentPiece = this._pieces.get(currentDomain);
|
||||
|
||||
switch (Double.compare(currentMin, otherMin)) {
|
||||
case -1:
|
||||
if (currentMax > otherMin) {
|
||||
switch (Double.compare(currentMax, otherMax)) {
|
||||
case -1:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(currentMin, otherMin);
|
||||
central = new NumericRealDomain();
|
||||
central.setMinMax(otherMin, currentMax);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(currentMax, otherMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(lower, currentPiece);
|
||||
this._pieces.put(central, piece.sumFunctions(currentPiece));
|
||||
this.addPiece(upper, piece);
|
||||
break;
|
||||
case 0:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(currentMin, otherMin);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(otherMin, otherMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(lower, currentPiece);
|
||||
this._pieces.put(upper, piece.sumFunctions(currentPiece));
|
||||
break;
|
||||
case 1:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(currentMin, otherMin);
|
||||
central = new NumericRealDomain();
|
||||
central.setMinMax(otherMin, otherMax);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(otherMax, currentMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(lower, currentPiece);
|
||||
this._pieces.put(central, piece.sumFunctions(currentPiece));
|
||||
this._pieces.put(upper, currentPiece);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0:
|
||||
|
||||
switch (Double.compare(currentMax, otherMax)) {
|
||||
case -1:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(otherMin, currentMax);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(currentMax, otherMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(lower, piece.sumFunctions(currentPiece));
|
||||
this.addPiece(upper, piece);
|
||||
break;
|
||||
case 0:
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(domain, piece.sumFunctions(currentPiece));
|
||||
break;
|
||||
case 1:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(currentMin, otherMax);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(otherMax, currentMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(lower, piece.sumFunctions(currentPiece));
|
||||
this._pieces.put(upper, currentPiece);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
case 1:
|
||||
|
||||
if (otherMax > currentMin) {
|
||||
|
||||
switch (Double.compare(otherMax, currentMax)) {
|
||||
case -1:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(otherMin, currentMin);
|
||||
central = new NumericRealDomain();
|
||||
central.setMinMax(currentMin, otherMax);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(otherMax, currentMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(central, piece.sumFunctions(currentPiece));
|
||||
this._pieces.put(upper, currentPiece);
|
||||
this.addPiece(lower, piece);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(otherMin, currentMin);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(currentMin, otherMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(upper, piece.sumFunctions(currentPiece));
|
||||
this.addPiece(lower, piece);
|
||||
break;
|
||||
case 1:
|
||||
lower = new NumericRealDomain();
|
||||
lower.setMinMax(otherMin, currentMin);
|
||||
central = new NumericRealDomain();
|
||||
central.setMinMax(currentMin, currentMax);
|
||||
upper = new NumericRealDomain();
|
||||
upper.setMinMax(currentMax, otherMax);
|
||||
|
||||
this._pieces.remove(currentDomain);
|
||||
this._pieces.put(central, piece.sumFunctions(currentPiece));
|
||||
this.addPiece(lower, piece);
|
||||
this.addPiece(upper, piece);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._pieces.put(domain, piece);
|
||||
}
|
||||
|
||||
public void simplify() {
|
||||
Map<NumericRealDomain, IFragmentFunction> simplifyPieces = new HashMap<>();
|
||||
LinearPieceFunction piece1, piece2;
|
||||
NumericRealDomain domain;
|
||||
|
||||
for (NumericRealDomain domain1 : this._pieces.keySet()) {
|
||||
piece1 = (LinearPieceFunction) this._pieces.get(domain1);
|
||||
|
||||
for (NumericRealDomain domain2 : simplifyPieces.keySet()) {
|
||||
piece2 = (LinearPieceFunction) simplifyPieces.get(domain2);
|
||||
|
||||
if (domain1.getMin() == domain2.getMax()) {
|
||||
if (piece1.equals(piece2)) {
|
||||
domain = new NumericRealDomain();
|
||||
domain.setMinMax(domain2.getMin(), domain1.getMax());
|
||||
this._pieces.remove(domain1);
|
||||
this._pieces.remove(domain2);
|
||||
this._pieces.put(domain, piece1);
|
||||
this.simplify();
|
||||
return;
|
||||
}
|
||||
} else if (domain1.getMax() == domain2.getMin())
|
||||
if (piece1.equals(piece2)) {
|
||||
domain = new NumericRealDomain();
|
||||
domain.setMinMax(domain1.getMin(), domain2.getMax());
|
||||
this._pieces.remove(domain1);
|
||||
this._pieces.remove(domain2);
|
||||
this._pieces.put(domain, piece1);
|
||||
this.simplify();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
simplifyPieces.put(domain1, piece1);
|
||||
}
|
||||
|
||||
this._pieces = simplifyPieces;
|
||||
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package flintstones.domain.fuzzyset.function;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public interface IFragmentFunction {
|
||||
|
||||
public IFragmentFunction sumFunctions(IFragmentFunction other);
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package flintstones.domain.fuzzyset.function.types;
|
||||
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
import flintstones.domain.fuzzyset.function.IFragmentFunction;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class LinearPieceFunction implements IFragmentFunction {
|
||||
|
||||
private final static double EPSILON = 0.00001;
|
||||
|
||||
private final double _slope;
|
||||
private final double _cutOffY;
|
||||
|
||||
public LinearPieceFunction(Double slope, Double cutOff) {
|
||||
this._slope = slope;
|
||||
this._cutOffY = cutOff;
|
||||
}
|
||||
|
||||
public double getSlope() {
|
||||
return this._slope;
|
||||
}
|
||||
|
||||
public double getCutOffY() {
|
||||
return this._cutOffY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFragmentFunction sumFunctions(IFragmentFunction other) {
|
||||
Validator.notNull(other);
|
||||
Validator.notIllegalElementType(other, new String[] { this.getClass()
|
||||
.toString() });
|
||||
|
||||
return new LinearPieceFunction(this._slope + ((LinearPieceFunction) other)._slope, this._cutOffY + ((LinearPieceFunction) other)._cutOffY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (this._cutOffY < 0) ? (this._slope + "x " + this._cutOffY) : (this._slope + "x + " + this._cutOffY); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
if (obj.getClass() != this.getClass())
|
||||
return false;
|
||||
|
||||
final LinearPieceFunction other = (LinearPieceFunction) obj;
|
||||
|
||||
if (Math.abs(this._slope - other._slope) < LinearPieceFunction.EPSILON)
|
||||
if (Math.abs(this._cutOffY - other._cutOffY) < LinearPieceFunction.EPSILON)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder hcb = new HashCodeBuilder(17, 31);
|
||||
hcb.append(this._cutOffY);
|
||||
hcb.append(this._slope);
|
||||
return hcb.hashCode();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+549
@@ -0,0 +1,549 @@
|
||||
package flintstones.domain.fuzzyset.function.types;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.function.FragmentFunction;
|
||||
import flintstones.domain.fuzzyset.semantic.IMembershipFunction;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.helper.data.wxml.WNode;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class TrapezoidalFunction extends IMembershipFunction {
|
||||
|
||||
private final static double EPSILON = 0.000001;
|
||||
private final static double ALPHA = 1;
|
||||
|
||||
protected double _a;
|
||||
protected double _b;
|
||||
protected double _c;
|
||||
protected double _d;
|
||||
|
||||
public static enum Fields implements ExtensionEnum {
|
||||
a, b, c, d
|
||||
};
|
||||
|
||||
public TrapezoidalFunction() {
|
||||
super();
|
||||
this._a = this._b = this._c = this._d = 0d;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction(double a, double b, double c, double d) {
|
||||
this._a = a;
|
||||
this._b = b;
|
||||
this._c = c;
|
||||
this._d = d;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction(double[] limits) {
|
||||
this();
|
||||
|
||||
Validator.notNull(limits);
|
||||
Validator.notInvalidSize(limits.length, 3, 4);
|
||||
|
||||
// Commented for usage in FuzzyVikor method
|
||||
// for(double limit: limits) {
|
||||
// Validator.notNegative(limit);
|
||||
// }
|
||||
|
||||
if (limits.length == 3) {
|
||||
_a = limits[0];
|
||||
_b = _c = limits[1];
|
||||
_d = limits[2];
|
||||
} else if (limits.length == 4) {
|
||||
_a = limits[0];
|
||||
_b = limits[1];
|
||||
_c = limits[2];
|
||||
_d = limits[3];
|
||||
}
|
||||
}
|
||||
|
||||
public double getA() {
|
||||
return _a;
|
||||
}
|
||||
|
||||
public double setA(double a) {
|
||||
return this._a = a;
|
||||
}
|
||||
|
||||
public double getB() {
|
||||
return _b;
|
||||
}
|
||||
|
||||
public double setB(double b) {
|
||||
return this._b = b;
|
||||
}
|
||||
|
||||
public double getC() {
|
||||
return _c;
|
||||
}
|
||||
|
||||
public double setC(double c) {
|
||||
return this._c = c;
|
||||
}
|
||||
|
||||
public double getD() {
|
||||
return _d;
|
||||
}
|
||||
|
||||
public double setD(double d) {
|
||||
return this._d = d;
|
||||
}
|
||||
|
||||
public double[] getLimits() {
|
||||
double limits[] = new double[4];
|
||||
limits[0] = this._a;
|
||||
limits[1] = this._b;
|
||||
limits[2] = this._c;
|
||||
limits[3] = this._d;
|
||||
|
||||
return limits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLimits(double[] limits) {
|
||||
Validator.notNull(limits);
|
||||
Validator.notInvalidSize(limits.length, 3, 4);
|
||||
|
||||
// Commented for usage in FuzzyVikor method
|
||||
// for (double limit : limits)
|
||||
// Validator.notNegative(limit);
|
||||
|
||||
if (limits.length == 3) {
|
||||
this._a = limits[0];
|
||||
this._b = this._c = limits[1];
|
||||
this._d = limits[2];
|
||||
} else if (limits.length == 4) {
|
||||
this._a = limits[0];
|
||||
this._b = limits[1];
|
||||
this._c = limits[2];
|
||||
this._d = limits[3];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FragmentFunction toFragmentFunction() {
|
||||
FragmentFunction result = new FragmentFunction();
|
||||
LinearPieceFunction piece;
|
||||
NumericRealDomain domain;
|
||||
double slope, cutoffY;
|
||||
|
||||
if (this._a != this._b) {
|
||||
slope = 1d / (this._b - this._a);
|
||||
cutoffY = -(slope * this._a);
|
||||
piece = new LinearPieceFunction(slope, cutoffY);
|
||||
domain = new NumericRealDomain();
|
||||
domain.setMinMax(this._a, this._b);
|
||||
result.addPiece(domain, piece);
|
||||
}
|
||||
|
||||
if (this._b != this._c) {
|
||||
slope = 0;
|
||||
cutoffY = 1;
|
||||
piece = new LinearPieceFunction(slope, cutoffY);
|
||||
domain = new NumericRealDomain();
|
||||
domain.setMinMax(this._b, this._c);
|
||||
result.addPiece(domain, piece);
|
||||
}
|
||||
|
||||
if (this._c != this._d) {
|
||||
slope = 1d / (this._c - this._d);
|
||||
cutoffY = -(slope * this._d);
|
||||
piece = new LinearPieceFunction(slope, cutoffY);
|
||||
domain = new NumericRealDomain();
|
||||
domain.setMinMax(this._c, this._d);
|
||||
result.addPiece(domain, piece);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSymmetrical() {
|
||||
return (Math.abs((this._b - this._a) - (this._d - this._c)) < TrapezoidalFunction.EPSILON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSymmetrical(IMembershipFunction other, double center) {
|
||||
double displacement = (center - this._d) * 2;
|
||||
|
||||
TrapezoidalFunction clone = (TrapezoidalFunction) this.clone();
|
||||
|
||||
clone._a = this._d;
|
||||
clone._b = clone._a + (this._d - this._c);
|
||||
clone._c = clone._b + (this._c - this._b);
|
||||
clone._d = clone._c + (this._b - this._a);
|
||||
|
||||
clone._a += displacement;
|
||||
clone._b += displacement;
|
||||
clone._c += displacement;
|
||||
clone._d += displacement;
|
||||
|
||||
return clone.equals(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumericRealDomain getCenter() {
|
||||
NumericRealDomain result = new NumericRealDomain();
|
||||
result.setMinMax(this._b, this._c);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumericRealDomain getCoverage() {
|
||||
NumericRealDomain result = new NumericRealDomain();
|
||||
result.setMinMax(this._a, this._d);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMembershipValue(double x) {
|
||||
double result;
|
||||
|
||||
if (x >= this._b && x <= this._c)
|
||||
result = 1d;
|
||||
else if (x <= this._a || x >= this._d)
|
||||
result = 0d;
|
||||
else if (x < this._b)
|
||||
result = (x - this._a) / (this._b - this._a);
|
||||
else
|
||||
result = (x - this._d) / (this._c - this._d);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isTriangular() {
|
||||
return (this._b == this._c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double centroid() {
|
||||
double centroidLeft, centroidCenter, centroidRight, areaLeft, areaCenter, areaRight, areaSum, result;
|
||||
|
||||
centroidLeft = (this._a + (2 * this._b)) / 3.;
|
||||
centroidCenter = (this._b + this._c) / 2.;
|
||||
centroidRight = ((2 * this._c) + this._d) / 3.;
|
||||
|
||||
areaLeft = (this._b - this._a) / 2.;
|
||||
areaCenter = (this._c - this._b);
|
||||
areaRight = (this._d - this._c) / 2.;
|
||||
areaSum = areaLeft + areaCenter + areaRight;
|
||||
|
||||
result = ((centroidLeft * areaLeft) + (centroidCenter * areaCenter) + (centroidRight * areaRight)) / areaSum;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double maxMin(double max, double min) {
|
||||
Validator.notDisorder(new double[] { min, max }, false);
|
||||
|
||||
if ((min >= this._b) && (max <= this._c))
|
||||
return 1d;
|
||||
if (min <= this._b && max >= this._c)
|
||||
return 1d;
|
||||
else if (max < this._b)
|
||||
return this.getMembershipValue(max);
|
||||
else
|
||||
return this.getMembershipValue(min);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double maxMin(IMembershipFunction function, FuzzySet blts, FuzzySet domainValuation) {
|
||||
TrapezoidalFunction tmf;
|
||||
|
||||
Validator.notNull(function);
|
||||
if (function instanceof TrapezoidalFunction)
|
||||
tmf = (TrapezoidalFunction) function;
|
||||
else
|
||||
throw new IllegalArgumentException("TrapezoidalFunction_Invalid_element_type"); //$NON-NLS-1$
|
||||
|
||||
// PATCH for only 1 domain
|
||||
if (blts.equals(domainValuation)) {
|
||||
if (tmf.equals(this)) {
|
||||
return 1;
|
||||
} else if (blts.belongtoFuzzySet(tmf)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
double values[] = new double[5];
|
||||
double result;
|
||||
double slopeThisAB, slopeFunctionAB, slopeThisCD, slopeFunctionCD;
|
||||
|
||||
values[0] = this.maxMin(tmf._c, tmf._b);
|
||||
|
||||
if (values[0] == 1)
|
||||
return 1d;
|
||||
|
||||
if (this._b == this._a)
|
||||
values[1] = values[2] = tmf.getMembershipValue(this._a);
|
||||
else {
|
||||
slopeThisAB = 1d / (this._b - this._a);
|
||||
|
||||
if (tmf._a == tmf._b)
|
||||
values[1] = this.getMembershipValue(tmf._a);
|
||||
else {
|
||||
slopeFunctionAB = 1d / (tmf._b - tmf._a);
|
||||
|
||||
if (slopeThisAB == slopeFunctionAB)
|
||||
values[1] = 0d;
|
||||
else
|
||||
values[1] = slopeFunctionAB * slopeThisAB * (this._a - tmf._a) / (slopeThisAB - slopeFunctionAB);
|
||||
}
|
||||
|
||||
if (tmf._c == tmf._d)
|
||||
values[2] = this.getMembershipValue(tmf._c);
|
||||
else {
|
||||
slopeFunctionCD = 1d / (tmf._c - tmf._d);
|
||||
values[2] = slopeFunctionCD * slopeThisAB * (this._a - tmf._d) / (slopeThisAB - slopeFunctionCD);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._c == this._d)
|
||||
values[3] = values[4] = tmf.getMembershipValue(this._c);
|
||||
else {
|
||||
slopeThisCD = 1d / (this._c - this._d);
|
||||
|
||||
if (tmf._a == tmf._b)
|
||||
values[3] = this.getMembershipValue(tmf._a);
|
||||
else {
|
||||
slopeFunctionAB = 1d / (tmf._b - tmf._a);
|
||||
values[3] = slopeFunctionAB * slopeThisCD * (this._d - tmf._a) / (slopeThisCD - slopeFunctionAB);
|
||||
}
|
||||
|
||||
if (tmf._c == tmf._d)
|
||||
values[4] = this.getMembershipValue(tmf._c);
|
||||
else {
|
||||
slopeFunctionCD = 1d / (tmf._c - tmf._d);
|
||||
|
||||
if (slopeThisCD == slopeFunctionCD)
|
||||
values[4] = 0d;
|
||||
else
|
||||
values[4] = slopeFunctionCD * slopeThisCD * (this._d - tmf._d) / (slopeThisCD - slopeFunctionCD);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < values.length; i++)
|
||||
if (values[i] > 1)
|
||||
values[i] = 0d;
|
||||
|
||||
result = Math.max(values[0], Math.max(values[1], Math.max(values[2], Math.max(values[3], values[4]))));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction addition(TrapezoidalFunction tpf) {
|
||||
|
||||
double[] limits = new double[] { this._a + tpf._a, this._b + tpf._b, this._c + tpf._c, this._d + tpf._d };
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction subtraction(TrapezoidalFunction tpf) {
|
||||
|
||||
double[] limits = new double[] { this._a - tpf._d, this._b - tpf._c, this._c - tpf._b, this._d - tpf._a };
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction multiplication(TrapezoidalFunction tpf) {
|
||||
|
||||
double[] limits = new double[] { this._a * tpf._a, this._b * tpf._b, this._c * tpf._c, this._d * tpf._d };
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction division(TrapezoidalFunction tpf) {
|
||||
|
||||
double[] limits = new double[] { this._a / tpf._d, this._b / tpf._c, this._c / tpf._b, this._d / tpf._a };
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction multiplicationScalar(double scalar) {
|
||||
double[] limits;
|
||||
|
||||
if (scalar >= 0)
|
||||
limits = new double[] { this._a * scalar, this._b * scalar, this._c * scalar, this._d * scalar };
|
||||
else
|
||||
limits = new double[] { this._d * scalar, this._c * scalar, this._b * scalar, this._a * scalar };
|
||||
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction divisionScalar(double scalar) {
|
||||
double[] limits = new double[] { _a / scalar, _b / scalar, _c / scalar, _d / scalar };
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction potence(double scalar) {
|
||||
double[] limits = new double[] { Math.pow(this._a, scalar), Math.pow(this._b, scalar),
|
||||
Math.pow(this._c, scalar), Math.pow(this._d, scalar) };
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction(limits);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public Double[] computeAlphaCut() {
|
||||
Double[] result = new Double[2];
|
||||
result[0] = _a + ALPHA * (_b - _a);
|
||||
result[1] = _d - ALPHA * (_d - _c);
|
||||
return result;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction additionAlphaCuts(TrapezoidalFunction fuzzyNumber) {
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction();
|
||||
tp.setLimits(new double[] { this._a + fuzzyNumber._a, this._b + fuzzyNumber._b, this._c + fuzzyNumber._c,
|
||||
this._d + fuzzyNumber._d });
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction subtractionAlphaCuts(TrapezoidalFunction fuzzyNumber) {
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction();
|
||||
tp.setLimits(new double[] { this._a - fuzzyNumber._d, this._b - fuzzyNumber._c, this._c - fuzzyNumber._b,
|
||||
this._d - fuzzyNumber._a });
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction multiplicationAlphaCuts(TrapezoidalFunction fuzzyNumber) {
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction();
|
||||
tp.setLimits(new double[] { this._a * fuzzyNumber._a, this._b * fuzzyNumber._b, this._c * fuzzyNumber._c,
|
||||
this._d * fuzzyNumber._d });
|
||||
return tp;
|
||||
}
|
||||
|
||||
public TrapezoidalFunction divisionAlphaCuts(TrapezoidalFunction fuzzyNumber) {
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction();
|
||||
tp.setLimits(new double[] { this._a / fuzzyNumber._d, this._b / fuzzyNumber._c, this._c / fuzzyNumber._b,
|
||||
this._d / fuzzyNumber._a });
|
||||
return tp;
|
||||
}
|
||||
|
||||
public double getSimpleDefuzzifiedValue() {
|
||||
return (this._a + (2d * this._b) + (2d * this._c) + this._d) / 6d;
|
||||
}
|
||||
|
||||
public double distance(TrapezoidalFunction tpf, double P) {
|
||||
double acum = 0;
|
||||
double limits1[] = this.getLimits(), limits2[] = tpf.getLimits();
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
acum += Math.pow(Math.abs(limits1[i] - limits2[i]), P);
|
||||
|
||||
return Math.pow(acum, 1 / P);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
DecimalFormat df = new DecimalFormat("#.########");
|
||||
df.setRoundingMode(RoundingMode.CEILING);
|
||||
|
||||
if (this._b == this._c) {
|
||||
String template = "T({0}, {1}, {2})";
|
||||
return MessageFormat.format(template, df.format(this._a), df.format(this._b), df.format(this._d))
|
||||
.toString();
|
||||
}
|
||||
String template = "T({0}, {1}, {2}, {3})";
|
||||
return MessageFormat
|
||||
.format(template, df.format(this._a), df.format(this._b), df.format(this._c), df.format(this._d))
|
||||
.toString();
|
||||
}
|
||||
|
||||
public String toStringExport() {
|
||||
|
||||
if (this._b == this._c) {
|
||||
String template = "Trapezoidal({0}, {1}, {2})";
|
||||
return MessageFormat.format(template, this._a, this._b, this._d).toString();
|
||||
}
|
||||
String template = "Trapezoidal({0}, {1}, {2}, {3})";
|
||||
return MessageFormat.format(template, this._a, this._b, this._c, this._d).toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
if (this.getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
final TrapezoidalFunction other = (TrapezoidalFunction) obj;
|
||||
|
||||
double aRound = Math.abs(new BigDecimal(this._a).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double bRound = Math.abs(new BigDecimal(this._b).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double cRound = Math.abs(new BigDecimal(this._c).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double dRound = Math.abs(new BigDecimal(this._d).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double aOtherRound = Math.abs(new BigDecimal(other._a).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double bOtherRound = Math.abs(new BigDecimal(other._b).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double cOtherRound = Math.abs(new BigDecimal(other._c).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
double dOtherRound = Math.abs(new BigDecimal(other._d).setScale(3, RoundingMode.HALF_UP).doubleValue());
|
||||
|
||||
if (aRound == aOtherRound)
|
||||
if (bRound == bOtherRound)
|
||||
if (cRound == cOtherRound)
|
||||
if (dRound == dOtherRound)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder hcb = new HashCodeBuilder(17, 31);
|
||||
hcb.append(this._a);
|
||||
hcb.append(this._b);
|
||||
hcb.append(this._c);
|
||||
hcb.append(this._d);
|
||||
return hcb.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
TrapezoidalFunction tp = new TrapezoidalFunction();
|
||||
tp.setLimits(this.getLimits());
|
||||
return tp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IMembershipFunction other) {
|
||||
Validator.notNull(other);
|
||||
|
||||
return Double.compare(this.centroid(), other.centroid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter writer) throws XMLStreamException {
|
||||
writer.writeAttribute(Fields.a.toString(), Double.toString(this._a));
|
||||
writer.writeAttribute(Fields.b.toString(), Double.toString(this._b));
|
||||
writer.writeAttribute(Fields.c.toString(), Double.toString(this._c));
|
||||
writer.writeAttribute(Fields.d.toString(), Double.toString(this._d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(WNode node) {
|
||||
this._a = Double.parseDouble(node.getAttribute(Fields.a));
|
||||
this._b = Double.parseDouble(node.getAttribute(Fields.b));
|
||||
this._c = Double.parseDouble(node.getAttribute(Fields.c));
|
||||
this._d = Double.parseDouble(node.getAttribute(Fields.d));
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package flintstones.domain.fuzzyset.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class LinguisticQualityInstance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
FuzzySet domain = (FuzzySet) getDomain();
|
||||
|
||||
String[] labels = new String[] {
|
||||
"Muy Malo",
|
||||
"Malo",
|
||||
"Normal",
|
||||
"Bueno",
|
||||
"Muy bueno"
|
||||
};
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package flintstones.domain.fuzzyset.instance;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class LinguisticRandomInstance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
|
||||
FuzzySet domain = (FuzzySet) getDomain();
|
||||
|
||||
Random rand = new Random();
|
||||
int size = rand.nextInt( 9 - 3 + 1 ) + 3;
|
||||
|
||||
|
||||
String[] labels = new String[size];
|
||||
String base = RandomStringUtils.randomAlphabetic(3);
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
labels[i] = "s_"+ i;
|
||||
}
|
||||
|
||||
String name = getLabel() + "_" + base;
|
||||
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package flintstones.domain.fuzzyset.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class LinguisticS3Instance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
FuzzySet domain = (FuzzySet) getDomain();
|
||||
|
||||
String[] labels = new String[] {
|
||||
"Low",
|
||||
"Medium",
|
||||
"High"
|
||||
};
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package flintstones.domain.fuzzyset.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class LinguisticS5Instance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
FuzzySet domain = (FuzzySet) getDomain();
|
||||
|
||||
String[] labels = new String[] {
|
||||
"Very Low",
|
||||
"Low",
|
||||
"Medium",
|
||||
"High",
|
||||
"Very High"
|
||||
};
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package flintstones.domain.fuzzyset.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class LinguisticS7Instance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
FuzzySet domain = (FuzzySet) getDomain();
|
||||
|
||||
String[] labels = new String[] {
|
||||
"Nothing",
|
||||
"Very Low",
|
||||
"Low",
|
||||
"Medium",
|
||||
"High",
|
||||
"Very High",
|
||||
"Perfect"
|
||||
};
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package flintstones.domain.fuzzyset.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class LinguisticS9Instance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
FuzzySet domain = (FuzzySet) getDomain();
|
||||
|
||||
String[] labels = new String[] {
|
||||
"Nothing",
|
||||
"Very Low",
|
||||
"Low",
|
||||
"Slightly Low",
|
||||
"Medium",
|
||||
"Slightly High",
|
||||
"High",
|
||||
"Very High",
|
||||
"Perfect"
|
||||
};
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
package flintstones.domain.fuzzyset.label;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
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.semantic.IMembershipFunction;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.helper.data.wxml.WNode;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class LabelLinguisticDomain implements Cloneable, Comparable<LabelLinguisticDomain> {
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
private String _name;
|
||||
private IMembershipFunction _semantic;
|
||||
|
||||
public static enum Fields implements ExtensionEnum {
|
||||
semantic, type
|
||||
};
|
||||
|
||||
public LabelLinguisticDomain() {
|
||||
_name = "";
|
||||
_semantic = null;
|
||||
}
|
||||
|
||||
public void initLabelLinguisticDomain(String name, IMembershipFunction semantic) {
|
||||
Validator.notEmpty(name);
|
||||
Validator.notNull(semantic);
|
||||
|
||||
this._name = name;
|
||||
this._semantic = semantic;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
if (this.context == null)
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
public IMembershipFunction getSemantic() {
|
||||
return this._semantic;
|
||||
}
|
||||
|
||||
public void setSemantic(IMembershipFunction semantic) {
|
||||
this._semantic = semantic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
if (this.getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
final LabelLinguisticDomain other = (LabelLinguisticDomain) obj;
|
||||
|
||||
EqualsBuilder eb = new EqualsBuilder();
|
||||
eb.append(this._name, other._name);
|
||||
eb.append(this._semantic, other._semantic);
|
||||
|
||||
return eb.isEquals();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder hcb = new HashCodeBuilder(17, 31);
|
||||
hcb.append(this._name);
|
||||
hcb.append(this._semantic);
|
||||
return hcb.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
Object result = null;
|
||||
|
||||
try {
|
||||
result = super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
((LabelLinguisticDomain) result)._name = new String(this._name);
|
||||
((LabelLinguisticDomain) result)._semantic = (IMembershipFunction) this._semantic.clone();
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LabelLinguisticDomain other) {
|
||||
Validator.notNull(other);
|
||||
|
||||
return this._semantic.compareTo(other._semantic);
|
||||
}
|
||||
|
||||
public void write(XMLStreamWriter writer) throws XMLStreamException {
|
||||
writer.writeStartElement(Fields.semantic.toString());
|
||||
writer.writeAttribute(Fields.type.toString(), this._semantic.getClass()
|
||||
.getName());
|
||||
this._semantic.write(writer);
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
public void read(WNode node) {
|
||||
WNode nnode = node.getFirst(Fields.semantic);
|
||||
|
||||
// Compatibilidad FS3-FS4
|
||||
String type = nnode.getAttribute(Fields.type);
|
||||
if (type.equals("sinbad2.domain.linguistic.fuzzy.function.types.TrapezoidalFunction")) //$NON-NLS-1$
|
||||
type = "flintstones.domain.fuzzyset.function.types.TrapezoidalFunction"; //$NON-NLS-1$
|
||||
|
||||
Class<?> function = null;
|
||||
try {
|
||||
function = Class.forName(type);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this._semantic = (IMembershipFunction) ContextInjectionFactory.make(function, this.context);
|
||||
|
||||
this._semantic.read(nnode);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
package flintstones.domain.fuzzyset.label;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
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 org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.domain.fuzzyset.messages.Messages;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.helper.data.wxml.WNode;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class LabelSetLinguisticDomain implements Cloneable {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
protected List<LabelLinguisticDomain> _labels = new LinkedList<>();
|
||||
|
||||
public static enum Fields implements ExtensionEnum {
|
||||
label, labels, labelSet, position, name
|
||||
};
|
||||
|
||||
public LabelSetLinguisticDomain() {
|
||||
}
|
||||
|
||||
public void setLabels(List<LabelLinguisticDomain> labels) {
|
||||
Validator.notNull(labels);
|
||||
|
||||
for (LabelLinguisticDomain label : labels)
|
||||
this.addLabel(label);
|
||||
|
||||
this._labels = labels;
|
||||
}
|
||||
|
||||
public List<LabelLinguisticDomain> getLabels() {
|
||||
return this._labels;
|
||||
}
|
||||
|
||||
public ArrayList<String> getLabelsName() {
|
||||
ArrayList<String> labelsName = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < _labels.size(); ++i) {
|
||||
labelsName.add(_labels.get(i).getName());
|
||||
}
|
||||
|
||||
return labelsName;
|
||||
}
|
||||
|
||||
public void addLabel(LabelLinguisticDomain label) {
|
||||
this.addLabel(this.getCardinality(), label);
|
||||
}
|
||||
|
||||
public void addLabel(int pos, LabelLinguisticDomain label) {
|
||||
Validator.notNull(label);
|
||||
Validator.notInvalidSize(pos, 0, this.getCardinality());
|
||||
|
||||
if (this.containsLabel(label.getName()))
|
||||
throw new IllegalArgumentException(this.messages.LabelSetLinguisticDomain_duplicated_label);
|
||||
|
||||
this._labels.add(pos, label);
|
||||
}
|
||||
|
||||
public void removeLabel(int pos) {
|
||||
Validator.notEmpty(this._labels.toArray());
|
||||
Validator.notInvalidSize(pos, 0, this.getCardinality() - 1);
|
||||
|
||||
this._labels.remove(pos);
|
||||
}
|
||||
|
||||
public void removeLabel(LabelLinguisticDomain label) {
|
||||
|
||||
if (label == null)
|
||||
return;
|
||||
|
||||
int pos = this.getPos(label);
|
||||
|
||||
if (pos != -1)
|
||||
this.removeLabel(pos);
|
||||
}
|
||||
|
||||
public boolean containsLabel(String name) {
|
||||
return (this.getPos(name) != -1);
|
||||
}
|
||||
|
||||
public boolean containsLabel(LabelLinguisticDomain label) {
|
||||
return this._labels.contains(label);
|
||||
}
|
||||
|
||||
public int getCardinality() {
|
||||
return this._labels.size();
|
||||
}
|
||||
|
||||
public LabelLinguisticDomain getLabel(int pos) {
|
||||
Validator.notEmpty(this._labels.toArray());
|
||||
Validator.notInvalidSize(pos, 0, this.getCardinality() - 1);
|
||||
|
||||
return this._labels.get(pos);
|
||||
}
|
||||
|
||||
public LabelLinguisticDomain getLabel(String name) {
|
||||
int pos = this.getPos(name);
|
||||
|
||||
if (pos != -1)
|
||||
return this.getLabel(pos);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getPos(String name) {
|
||||
|
||||
if (name == null)
|
||||
return -1;
|
||||
|
||||
if (Validator.isEmpty(name))
|
||||
return -1;
|
||||
|
||||
for (LabelLinguisticDomain auxLabel : this._labels)
|
||||
if (auxLabel.getName()
|
||||
.equals(name))
|
||||
return this._labels.indexOf(auxLabel);
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
public int getPos(LabelLinguisticDomain label) {
|
||||
int pos = this._labels.indexOf(label);
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = ""; //$NON-NLS-1$
|
||||
int cardinality = this.getCardinality();
|
||||
|
||||
if (cardinality > 0)
|
||||
for (int pos = 0; pos < cardinality; ++pos) {
|
||||
if (pos > 0)
|
||||
result += ", "; //$NON-NLS-1$
|
||||
result += this._labels.get(pos);
|
||||
}
|
||||
|
||||
String template = this.messages.LabelSetLinguisticDomain_toStringTemplate;
|
||||
return MessageFormat.format(template, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
if (this.getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
final LabelSetLinguisticDomain other = (LabelSetLinguisticDomain) obj;
|
||||
|
||||
EqualsBuilder eb = new EqualsBuilder();
|
||||
eb.append(this._labels, other._labels);
|
||||
|
||||
return eb.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCodeBuilder hcb = new HashCodeBuilder(17, 31);
|
||||
hcb.append(this._labels);
|
||||
return hcb.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
Object result = null;
|
||||
|
||||
try {
|
||||
result = super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<LabelLinguisticDomain> resultLabels = new LinkedList<>();
|
||||
for (LabelLinguisticDomain label : this._labels)
|
||||
resultLabels.add((LabelLinguisticDomain) label.clone());
|
||||
|
||||
((LabelSetLinguisticDomain) result)._labels = resultLabels;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void write(XMLStreamWriter writer) throws XMLStreamException {
|
||||
writer.writeStartElement(Fields.labelSet.toString());
|
||||
|
||||
for (LabelLinguisticDomain label : this._labels)
|
||||
this.writeLabel(writer, label);
|
||||
|
||||
writer.writeEndElement();
|
||||
|
||||
}
|
||||
|
||||
private void writeLabel(XMLStreamWriter writer, LabelLinguisticDomain label) throws XMLStreamException {
|
||||
writer.writeStartElement(Fields.label.toString());
|
||||
writer.writeAttribute(Fields.name.toString(), label.getName());
|
||||
label.write(writer);
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
public void read(WNode node) {
|
||||
if (node.getVersion()
|
||||
.equals("3.0"))
|
||||
this.readFS3(node);
|
||||
else
|
||||
this.readFS4(node);
|
||||
}
|
||||
|
||||
private void readFS3(WNode node) {
|
||||
|
||||
WNode labelset = node.getFirst(Fields.labels.toString());
|
||||
List<WNode> nodes = labelset.getChildren();
|
||||
for (WNode item : nodes) {
|
||||
|
||||
LabelLinguisticDomain label = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context);
|
||||
|
||||
String name = item.getAttribute(Fields.label);
|
||||
label.setName(name);
|
||||
label.read(item);
|
||||
this.addLabel(label);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void readFS4(WNode node) {
|
||||
|
||||
// WNode labelset = node.getFirst(Fields.labelSet.toString());
|
||||
List<WNode> nodes = node.getChildren();
|
||||
for (WNode item : nodes) {
|
||||
|
||||
LabelLinguisticDomain label = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context);
|
||||
|
||||
String name = item.getAttribute(Fields.name);
|
||||
label.setName(name);
|
||||
label.read(item);
|
||||
this.addLabel(label);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// This file has been auto-generated
|
||||
package flintstones.domain.fuzzyset.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public String TrapezoidalFunction_decimal_format;
|
||||
public String TrapezoidalFunction_template_tostring_short;
|
||||
public String TrapezoidalFunction_template_tostring_long;
|
||||
public String LabelSetLinguisticDomain_duplicated_label;
|
||||
public String LabelSetLinguisticDomain_toStringTemplate;
|
||||
public String FuzzySet_Inexistent_element;
|
||||
public String category;
|
||||
public String name_fuzzyset;
|
||||
public String name_hesitant;
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
FuzzySet_Inexistent_element=El elemento no exíste
|
||||
LabelSetLinguisticDomain_duplicated_label=Duplicated label name
|
||||
LabelSetLinguisticDomain_toStringTemplate=({0})
|
||||
category=Linguistic
|
||||
name_fuzzyset=Fuzzyset
|
||||
name_hesitant=Hesitant
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
FuzzySet_Inexistent_element=El elemento no exíste
|
||||
LabelSetLinguisticDomain_duplicated_label=Duplicated label name
|
||||
LabelSetLinguisticDomain_toStringTemplate=({0})
|
||||
category=Lingüísticos
|
||||
name_fuzzyset=Fuzzyset
|
||||
name_hesitant=Hesitant
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package flintstones.domain.fuzzyset.semantic;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.domain.fuzzyset.function.FragmentFunction;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.helper.data.wxml.WNode;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public abstract class IMembershipFunction implements Cloneable, Comparable<IMembershipFunction> {
|
||||
|
||||
public IMembershipFunction() {
|
||||
}
|
||||
|
||||
public abstract FragmentFunction toFragmentFunction();
|
||||
|
||||
public abstract boolean isSymmetrical();
|
||||
|
||||
public abstract boolean isSymmetrical(IMembershipFunction other, double center);
|
||||
|
||||
public abstract NumericRealDomain getCenter();
|
||||
|
||||
public abstract NumericRealDomain getCoverage();
|
||||
|
||||
public abstract double getMembershipValue(double x);
|
||||
|
||||
public abstract double centroid();
|
||||
|
||||
public abstract double maxMin(double max, double min);
|
||||
|
||||
public abstract double maxMin(IMembershipFunction function, FuzzySet bltsDomain, FuzzySet valuationDomain);
|
||||
|
||||
@Override
|
||||
public abstract Object clone();
|
||||
|
||||
public abstract void write(XMLStreamWriter writer) throws XMLStreamException;
|
||||
|
||||
public abstract void read(WNode node);
|
||||
|
||||
public abstract void setLimits(double[] limits);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user