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.unbalanced</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Unbalanced</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.domain.fuzzyset.unbalanced</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>1779484362541</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>
|
||||
+2
@@ -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,21 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %Bundle-Name
|
||||
Bundle-SymbolicName: flintstones.domain.fuzzyset.unbalanced;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.entity.domain,
|
||||
flintstones.domain.fuzzyset;visibility:=reexport,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.model.valuation.service,
|
||||
flintstones.valuation.linguistic,
|
||||
flintstones.operator,
|
||||
flintstones.helper.data.wxml,
|
||||
org.eclipse.e4.core.contexts,
|
||||
javax.inject,
|
||||
org.eclipse.e4.core.di
|
||||
Export-Package: flintstones.domain.fuzzyset.unbalanced,
|
||||
flintstones.domain.fuzzyset.unbalanced.utils
|
||||
Automatic-Module-Name: flintstones.domain.fuzzyset.unbalanced
|
||||
Import-Package: flintstones.valuation.twoTuple
|
||||
@@ -0,0 +1,4 @@
|
||||
#Properties file for flintstones.domain.fuzzyset.unbalanced
|
||||
Bundle-Name = Unbalanced
|
||||
domain.name = Unbalanced
|
||||
domain.type = Unbalanced
|
||||
@@ -0,0 +1,4 @@
|
||||
#Properties file for flintstones.domain.fuzzyset.unbalanced
|
||||
Bundle-Name = No balanceado
|
||||
domain.name = No balanceado
|
||||
domain.type = No balanceados
|
||||
@@ -0,0 +1,7 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml,\
|
||||
OSGI-INF/l10n/bundle.properties,\
|
||||
OSGI-INF/
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="flintstones.entity.domain">
|
||||
<domain
|
||||
category="flintstones.domain.fuzzyset.unbalanced.category"
|
||||
implementation="flintstones.domain.fuzzyset.unbalanced.Unbalanced"
|
||||
label="%domain.name"
|
||||
uid="flintstones.domain.linguistic.unbalanced">
|
||||
</domain>
|
||||
</extension>
|
||||
<extension
|
||||
point="flintstones.entity.domain.domain_category">
|
||||
<domain_category
|
||||
label="%domain.type"
|
||||
uid="flintstones.domain.fuzzyset.unbalanced.category">
|
||||
</domain_category>
|
||||
</extension>
|
||||
<extension
|
||||
point="flintstones.entity.domain.fastadd">
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic.unbalanced"
|
||||
implementation="flintstones.domain.fuzzyset.unbalanced.instance.Unbalanced5E3CIntance"
|
||||
label="Unbalanced 5E 3C"
|
||||
uid="flintstones.domain.fuzzyset.unbalanced.5e3c">
|
||||
</domain_instance>
|
||||
<domain_instance
|
||||
domain_id="flintstones.domain.linguistic.unbalanced"
|
||||
implementation="flintstones.domain.fuzzyset.unbalanced.instance.Unbalanced3C5EIntance"
|
||||
label="Unbalanced 3C 5E"
|
||||
uid="flintstones.domain.fuzzyset.unbalanced.3c5e">
|
||||
</domain_instance>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+902
@@ -0,0 +1,902 @@
|
||||
package flintstones.domain.fuzzyset.unbalanced;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
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.domain.fuzzyset.unbalanced.messages.Messages;
|
||||
import flintstones.entity.extensionenum.ExtensionEnum;
|
||||
import flintstones.helper.data.wxml.WNode;
|
||||
import flintstones.helper.validator.Validator;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Unbalanced extends FuzzySet {
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
public static enum FieldsFS3 implements ExtensionEnum {
|
||||
// left_lateral_set
|
||||
sl,
|
||||
// right_lateral_set
|
||||
sr,
|
||||
// left_lateral_set_density
|
||||
slDensity,
|
||||
// right_lateral_set_density
|
||||
srDensity,
|
||||
// cardinality, _labels.size(). NO ESCRIBIR
|
||||
cardinality,
|
||||
// muere
|
||||
labelU,
|
||||
// muere
|
||||
labelsU,
|
||||
// ?
|
||||
domainLabelMALMALMAL,
|
||||
// position - NO ESCRIBIR
|
||||
pos,
|
||||
// label
|
||||
la,
|
||||
// domain
|
||||
d,
|
||||
//
|
||||
l,
|
||||
// linguistic hierarchy
|
||||
lh,
|
||||
//
|
||||
labelSet,
|
||||
//
|
||||
values,
|
||||
// muere
|
||||
data
|
||||
};
|
||||
|
||||
public static enum Fields implements ExtensionEnum {
|
||||
// left_lateral_set
|
||||
leftLateralSet,
|
||||
// right_lateral_set
|
||||
rightLateralSet,
|
||||
// left_lateral_set_density
|
||||
leftLateralSetDensity,
|
||||
// right_lateral_set_density
|
||||
rightLateralSetDensity,
|
||||
// cardinality, _labels.size(). NO ESCRIBIR
|
||||
cardinality,
|
||||
// muere
|
||||
unbalancedLabel,
|
||||
// muere
|
||||
unbalancedLabels,
|
||||
// ?
|
||||
domainLabel,
|
||||
// position - NO ESCRIBIR
|
||||
position,
|
||||
// label
|
||||
label,
|
||||
// domain
|
||||
domain,
|
||||
//
|
||||
l,
|
||||
// linguistic hierarchy
|
||||
linguisticHierarchy,
|
||||
//
|
||||
linguisticTerm,
|
||||
//
|
||||
granularity,
|
||||
//
|
||||
labelSet,
|
||||
//
|
||||
value,
|
||||
// muere
|
||||
values,
|
||||
// muere
|
||||
data, domainGranularity
|
||||
};
|
||||
|
||||
public static final String ID = "flintstones.domain.linguistic.unbalanced"; //$NON-NLS-1$
|
||||
|
||||
private int[] _lh;
|
||||
private int _sl;
|
||||
private int _sr;
|
||||
private int _slDensity;
|
||||
private int _srDensity;
|
||||
private int _cardinality;
|
||||
private Map<Integer, Map<Integer, Integer>> _labels = new HashMap<Integer, Map<Integer,Integer>>();;
|
||||
|
||||
public Unbalanced() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void initUnbalanced() {
|
||||
setType(ID);
|
||||
}
|
||||
|
||||
public int[] getLh() {
|
||||
return _lh;
|
||||
}
|
||||
|
||||
public void setLh(int[] lh) {
|
||||
_lh = lh;
|
||||
}
|
||||
|
||||
public int getSl() {
|
||||
return _sl;
|
||||
}
|
||||
|
||||
public void setSl(int sl) {
|
||||
_sl = sl;
|
||||
}
|
||||
|
||||
public int getSr() {
|
||||
return _sr;
|
||||
}
|
||||
|
||||
public void setSr(int sr) {
|
||||
_sr = sr;
|
||||
}
|
||||
|
||||
public int getSlDensity() {
|
||||
return _slDensity;
|
||||
}
|
||||
|
||||
public void setSlDensity(int slDensity) {
|
||||
_slDensity = slDensity;
|
||||
}
|
||||
|
||||
public int getSrDensity() {
|
||||
return _srDensity;
|
||||
}
|
||||
|
||||
public void setSrDensity(int srDensity) {
|
||||
_srDensity = srDensity;
|
||||
}
|
||||
|
||||
public int getCardinality() {
|
||||
return _cardinality;
|
||||
}
|
||||
|
||||
public void setCardinality(int cardinality) {
|
||||
_cardinality = cardinality;
|
||||
}
|
||||
|
||||
public Map<Integer, Map<Integer, Integer>> getLabels() {
|
||||
return _labels;
|
||||
}
|
||||
|
||||
public void setLabels(Map<Integer, Map<Integer, Integer>> labels) {
|
||||
_labels = labels;
|
||||
}
|
||||
|
||||
public boolean isBrid(int pos) {
|
||||
return (_labels.get(pos).size() > 1);
|
||||
}
|
||||
|
||||
public void setLabel(int pos, Map<Integer, Integer> label) {
|
||||
_labels.put(pos, label);
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getLabel(int pos) {
|
||||
return _labels.get(pos);
|
||||
}
|
||||
|
||||
public void setLabelInDomain(int pos, int domain, int label) {
|
||||
|
||||
if(!_labels.containsKey(pos)) {
|
||||
_labels.put(pos, new HashMap<Integer, Integer>());
|
||||
}
|
||||
|
||||
_labels.get(pos).put(domain, label);
|
||||
|
||||
}
|
||||
|
||||
public Integer labelPos(int domain, int label) {
|
||||
Integer aux;
|
||||
for(int pos: _labels.keySet()) {
|
||||
aux = getLabelInDomain(pos, domain);
|
||||
if(aux != null) {
|
||||
if(aux == label) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer getLabelInDomain(int pos, int domain) {
|
||||
|
||||
if(_labels.containsKey(pos)) {
|
||||
return _labels.get(pos).get(domain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
//return this.formatDescriptionDomain();
|
||||
|
||||
String result = ""; //$NON-NLS-1$
|
||||
|
||||
for(int label: _labels.keySet()) {
|
||||
result += "Label " + label + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
for(int domain: _labels.get(label).keySet()) {
|
||||
result += "\tDomain: " + domain + ":" + _labels.get(label).get(domain) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
String result = ""; //$NON-NLS-1$
|
||||
|
||||
result = loadStringLh(result);
|
||||
result = loadStringFormat(result);
|
||||
return loadStringLabels(result);
|
||||
}
|
||||
|
||||
public void createUnbalancedDomain(String[] labels, int sr, int sl, int sldensity, int srdensity, int initialDomain) {
|
||||
Validator.notNull(labels);
|
||||
Validator.notEmpty(labels);
|
||||
|
||||
if(Validator.isNegative(sr)) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_sr);
|
||||
}
|
||||
|
||||
if(Validator.isNegative(sl)) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_sl);
|
||||
}
|
||||
|
||||
if(!Validator.isSameElement(sl + sr + 1, labels.length)) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_cardinality);
|
||||
}
|
||||
|
||||
if((labels.length % 2) == 0) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Pair_cardinality);
|
||||
}
|
||||
|
||||
if(!Validator.inRange(sldensity, 0, 1)) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_sl_density);
|
||||
}
|
||||
|
||||
if(!Validator.inRange(srdensity, 0, 1)) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_sr_density);
|
||||
}
|
||||
|
||||
if((initialDomain % 2) == 0) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Pair_initial_domain);
|
||||
}
|
||||
|
||||
if(initialDomain < 3) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_initial_domain);
|
||||
}
|
||||
|
||||
int aux = (initialDomain - 1) / 2;
|
||||
if((aux > sl) || (aux > sr)) {
|
||||
throw new IllegalArgumentException(messages.Unbalanced_Invalid_initial_domain);
|
||||
}
|
||||
|
||||
LabelLinguisticDomain leftCenterLabel, rightCenterLabel, centerLabel;
|
||||
|
||||
setSl(sl);
|
||||
setSr(sr);
|
||||
setSlDensity(sldensity);
|
||||
setSrDensity(srdensity);
|
||||
setCardinality(labels.length);
|
||||
|
||||
_labels = new HashMap<Integer, Map<Integer,Integer>>();
|
||||
|
||||
clearFuzzySet();
|
||||
|
||||
List<Integer> lh = new LinkedList<Integer>();
|
||||
lh.add(initialDomain);
|
||||
|
||||
int Lab_t;
|
||||
int Lab_t1;
|
||||
boolean directly;
|
||||
int sideCardinality = ((initialDomain - 1) / 2);
|
||||
|
||||
directly = false;
|
||||
aux = sideCardinality;
|
||||
while(aux < sl) {
|
||||
aux *= 2;
|
||||
lh.add((aux * 2) + 1);
|
||||
}
|
||||
|
||||
if (aux == sl) {
|
||||
directly = true;
|
||||
}
|
||||
|
||||
if(directly) {
|
||||
int leftCardinality = (sl * 2) + 1;
|
||||
String leftLabels[] = new String[leftCardinality];
|
||||
|
||||
for(int i = 0; i < leftCardinality; i++) {
|
||||
if(i < sl) {
|
||||
leftLabels[i] = labels[i];
|
||||
} else {
|
||||
leftLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
FuzzySet left = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
left.createTrapezoidalFunction(leftLabels);
|
||||
for(int i = 0; i < sl; i++) {
|
||||
setLabelInDomain(i, leftCardinality, i);
|
||||
addLabel(left.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(sl, leftCardinality, sl);
|
||||
leftCenterLabel = left.getLabelSet().getLabel(sl);
|
||||
} else {
|
||||
LabelLinguisticDomain leftBrid, rightBrid, brid;
|
||||
Lab_t = aux - sl;
|
||||
Lab_t1 = sl - Lab_t;
|
||||
int sleCardinality, slcCardinality;
|
||||
String sleLabels[], slcLabels[];
|
||||
FuzzySet sleFuzzySet, slcFuzzySet;
|
||||
|
||||
if(sldensity == 0) {
|
||||
sleCardinality = (aux * 2) + 1;
|
||||
sleLabels = new String[sleCardinality];
|
||||
|
||||
for(int i = 0; i < sleCardinality; i++) {
|
||||
if(i < Lab_t1) {
|
||||
sleLabels[i] = labels[i];
|
||||
} else {
|
||||
sleLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
sleFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
sleFuzzySet.createTrapezoidalFunction(sleLabels);
|
||||
for(int i = 0; i < Lab_t1; i++) {
|
||||
setLabelInDomain(i, sleCardinality, i);
|
||||
addLabel(sleFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(Lab_t1, sleCardinality, Lab_t1);
|
||||
leftBrid = sleFuzzySet.getLabelSet().getLabel(Lab_t1);
|
||||
|
||||
slcCardinality = aux + 1;
|
||||
slcLabels = new String[slcCardinality];
|
||||
|
||||
int alreadyUsed = Lab_t1 / 2;
|
||||
int j = 0;
|
||||
for(int i = 0; i < slcCardinality; i++) {
|
||||
if((i >= alreadyUsed) && (i < (Lab_t + alreadyUsed))) {
|
||||
slcLabels[i] = labels[Lab_t1 + j++];
|
||||
} else {
|
||||
slcLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
slcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
slcFuzzySet.createTrapezoidalFunction(slcLabels);
|
||||
for(int i = (alreadyUsed + 1); i < (Lab_t + alreadyUsed); i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, slcCardinality, i);
|
||||
addLabel(slcFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(Lab_t1, slcCardinality, alreadyUsed);
|
||||
rightBrid = slcFuzzySet.getLabelSet().getLabel(alreadyUsed);
|
||||
|
||||
double a = leftBrid.getSemantic().getCoverage().getMin();
|
||||
double b = rightBrid.getSemantic().getCenter().getMin();
|
||||
double d = rightBrid.getSemantic().getCoverage().getMax();
|
||||
double limits[] = {a, b, b, d};
|
||||
|
||||
TrapezoidalFunction semantic = new TrapezoidalFunction(limits);
|
||||
|
||||
// brid = new LabelLinguisticDomain(rightBrid.getName(), semantic);
|
||||
brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
brid.initLabelLinguisticDomain(rightBrid.getName(), semantic);
|
||||
|
||||
addLabel(Lab_t1, brid);
|
||||
|
||||
setLabelInDomain(sl, slcCardinality, Lab_t + alreadyUsed);
|
||||
leftCenterLabel = slcFuzzySet.getLabelSet().getLabel(Lab_t + alreadyUsed);
|
||||
|
||||
} else {
|
||||
sleCardinality = aux + 1;
|
||||
sleLabels = new String[sleCardinality];
|
||||
|
||||
for(int i = 0; i < sleCardinality; i++) {
|
||||
if(i < Lab_t) {
|
||||
sleLabels[i] = labels[i];
|
||||
} else {
|
||||
sleLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
sleFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
sleFuzzySet.createTrapezoidalFunction(sleLabels);
|
||||
for(int i = 0; i < Lab_t; i++) {
|
||||
setLabelInDomain(i, sleCardinality, i);
|
||||
addLabel(sleFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(Lab_t, sleCardinality, Lab_t);
|
||||
leftBrid = sleFuzzySet.getLabelSet().getLabel(Lab_t);
|
||||
|
||||
slcCardinality = (aux * 2) + 1;
|
||||
slcLabels = new String[slcCardinality];
|
||||
|
||||
int alreadyUsed = Lab_t * 2;
|
||||
int j = 0;
|
||||
for(int i = 0; i < slcCardinality; i++) {
|
||||
if((i >= alreadyUsed) && (i < (Lab_t1 + alreadyUsed))) {
|
||||
slcLabels[i] = labels[Lab_t + j++];
|
||||
} else {
|
||||
slcLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
slcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
slcFuzzySet.createTrapezoidalFunction(slcLabels);
|
||||
for(int i = (alreadyUsed + 1); i < (Lab_t1 + alreadyUsed); i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, slcCardinality, i);
|
||||
addLabel(slcFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(Lab_t, slcCardinality, alreadyUsed);
|
||||
rightBrid = slcFuzzySet.getLabelSet().getLabel(alreadyUsed);
|
||||
|
||||
double a = leftBrid.getSemantic().getCoverage().getMin();
|
||||
double b = rightBrid.getSemantic().getCenter().getMin();
|
||||
double d = rightBrid.getSemantic().getCoverage().getMax();
|
||||
double limits[] = {a, b, b, d};
|
||||
TrapezoidalFunction semantic = new TrapezoidalFunction(limits);
|
||||
|
||||
// brid = new LabelLinguisticDomain(rightBrid.getName(), semantic);
|
||||
brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
brid.initLabelLinguisticDomain(rightBrid.getName(), semantic);
|
||||
|
||||
addLabel(Lab_t, brid);
|
||||
|
||||
setLabelInDomain(sl, slcCardinality, Lab_t1 + alreadyUsed);
|
||||
leftCenterLabel = slcFuzzySet.getLabelSet().getLabel(Lab_t1 + alreadyUsed);
|
||||
}
|
||||
}
|
||||
|
||||
directly = false;
|
||||
aux = sideCardinality;
|
||||
int bigger = lh.get(lh.size() - 1);
|
||||
while(aux < sr) {
|
||||
aux *= 2;
|
||||
if (((aux * 2) + 1) > bigger) {
|
||||
lh.add((aux * 2) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if(aux == sr) {
|
||||
directly = true;
|
||||
}
|
||||
|
||||
if(directly) {
|
||||
int rightCardinality = (sr * 2) + 1;
|
||||
String rightLabels[] = new String[rightCardinality];
|
||||
|
||||
for(int i = 0; i < rightCardinality; i++) {
|
||||
if(i >= (rightCardinality - sr)) {
|
||||
rightLabels[i] = labels[labels.length - (rightCardinality - i)];
|
||||
} else {
|
||||
rightLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
FuzzySet right = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
right.createTrapezoidalFunction(rightLabels);
|
||||
for(int i = (rightCardinality - sr); i < rightCardinality; i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, rightCardinality, i);
|
||||
addLabel(right.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
rightCenterLabel = right.getLabelSet().getLabel(rightCardinality - sr - 1);
|
||||
|
||||
double a = leftCenterLabel.getSemantic().getCoverage().getMin();
|
||||
double b = rightCenterLabel.getSemantic().getCenter().getMin();
|
||||
double d = rightCenterLabel.getSemantic().getCoverage().getMax();
|
||||
double limits[] = { a, b, b, d };
|
||||
TrapezoidalFunction semantic = new TrapezoidalFunction(limits);
|
||||
|
||||
// centerLabel = new LabelLinguisticDomain(labels[sl], semantic);
|
||||
centerLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
centerLabel.initLabelLinguisticDomain(labels[sl], semantic);
|
||||
|
||||
|
||||
setLabelInDomain(sl, rightCardinality, rightCardinality - sr - 1);
|
||||
addLabel(sl, centerLabel);
|
||||
|
||||
} else {
|
||||
LabelLinguisticDomain leftBrid, rightBrid, brid;
|
||||
Lab_t = aux - sr;
|
||||
Lab_t1 = sr - Lab_t;
|
||||
int sreCardinality, srcCardinality;
|
||||
String sreLabels[], srcLabels[];
|
||||
FuzzySet sreFuzzySet, srcFuzzySet;
|
||||
|
||||
if(srdensity == 0) {
|
||||
srcCardinality = aux + 1;
|
||||
srcLabels = new String[srcCardinality];
|
||||
|
||||
int j = 0;
|
||||
for(int i = 0; i < srcCardinality; i++) {
|
||||
if((i > (aux / 2)) && (i <= ((aux / 2) + Lab_t))) {
|
||||
srcLabels[i] = labels[sl + 1 + j++];
|
||||
} else {
|
||||
srcLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
srcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
srcFuzzySet.createTrapezoidalFunction(srcLabels);
|
||||
for(int i = ((aux / 2) + 1); i < ((aux / 2) + Lab_t); i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, srcCardinality, i);
|
||||
addLabel(srcFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, srcCardinality, (aux / 2) + Lab_t);
|
||||
leftBrid = srcFuzzySet.getLabelSet().getLabel((aux / 2) + Lab_t);
|
||||
|
||||
rightCenterLabel = srcFuzzySet.getLabelSet().getLabel(aux / 2);
|
||||
|
||||
double a = leftCenterLabel.getSemantic().getCoverage().getMin();
|
||||
double b = rightCenterLabel.getSemantic().getCenter().getMin();
|
||||
double d = rightCenterLabel.getSemantic().getCoverage().getMax();
|
||||
double limits[] = { a, b, b, d };
|
||||
TrapezoidalFunction semantic = new TrapezoidalFunction(limits);
|
||||
|
||||
// centerLabel = new LabelLinguisticDomain(labels[sl], semantic);
|
||||
centerLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
centerLabel.initLabelLinguisticDomain(labels[sl], semantic);
|
||||
|
||||
|
||||
|
||||
setLabelInDomain(sl, srcCardinality, aux / 2);
|
||||
addLabel(sl, centerLabel);
|
||||
|
||||
sreCardinality = (aux * 2) + 1;
|
||||
sreLabels = new String[sreCardinality];
|
||||
|
||||
for(int i = 0; i < sreCardinality; i++) {
|
||||
if(i >= (sreCardinality - Lab_t1)) {
|
||||
sreLabels[i] = labels[labels.length - (sreCardinality - i)];
|
||||
} else {
|
||||
sreLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
sreFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
sreFuzzySet.createTrapezoidalFunction(sreLabels);
|
||||
for(int i = (sreCardinality - Lab_t1); i < sreCardinality; i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, sreCardinality, i);
|
||||
addLabel(sreFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(sl + Lab_t, sreCardinality, sreCardinality - Lab_t1 - 1);
|
||||
rightBrid = sreFuzzySet.getLabelSet().getLabel(sreCardinality - Lab_t1 - 1);
|
||||
|
||||
a = leftBrid.getSemantic().getCoverage().getMin();
|
||||
b = rightBrid.getSemantic().getCenter().getMin();
|
||||
d = rightBrid.getSemantic().getCoverage().getMax();
|
||||
double limits1[] = { a, b, b, d };
|
||||
TrapezoidalFunction semantic1 = new TrapezoidalFunction(limits1);
|
||||
|
||||
// brid = new LabelLinguisticDomain(leftBrid.getName(), semantic1);
|
||||
brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
brid.initLabelLinguisticDomain(leftBrid.getName(), semantic1);
|
||||
|
||||
|
||||
|
||||
addLabel(sl + Lab_t, brid);
|
||||
|
||||
} else {
|
||||
srcCardinality = (aux * 2) + 1;
|
||||
srcLabels = new String[srcCardinality];
|
||||
|
||||
int j = 0;
|
||||
for(int i = 0; i < srcCardinality; i++) {
|
||||
if((i > aux) && i < (aux + Lab_t1)) {
|
||||
srcLabels[i] = labels[sl + 1 + j++];
|
||||
} else {
|
||||
srcLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
srcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
srcFuzzySet.createTrapezoidalFunction(srcLabels);
|
||||
for(int i = (aux + 1); i < (aux + Lab_t1); i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, srcCardinality, i);
|
||||
addLabel(srcFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
leftBrid = srcFuzzySet.getLabelSet().getLabel(aux + Lab_t1);
|
||||
|
||||
rightCenterLabel = srcFuzzySet.getLabelSet().getLabel(aux);
|
||||
|
||||
double a = leftCenterLabel.getSemantic().getCoverage().getMin();
|
||||
double b = rightCenterLabel.getSemantic().getCenter().getMin();
|
||||
double d = rightCenterLabel.getSemantic().getCoverage().getMax();
|
||||
double limits[] = { a, b, b, d };
|
||||
TrapezoidalFunction semantic = new TrapezoidalFunction(limits);
|
||||
|
||||
// centerLabel = new LabelLinguisticDomain(labels[sl], semantic);
|
||||
centerLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
centerLabel.initLabelLinguisticDomain(labels[sl], semantic);
|
||||
|
||||
|
||||
setLabelInDomain(sl, srcCardinality, aux);
|
||||
addLabel(sl, centerLabel);
|
||||
|
||||
sreCardinality = aux + 1;
|
||||
sreLabels = new String[sreCardinality];
|
||||
|
||||
for(int i = 0; i < sreCardinality; i++) {
|
||||
if(i >= (sreCardinality - Lab_t - 1)) {
|
||||
sreLabels[i] = labels[labels.length - (sreCardinality - i)];
|
||||
} else {
|
||||
sreLabels[i] = "dirty label " + i; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
sreFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
sreFuzzySet.createTrapezoidalFunction(sreLabels);
|
||||
|
||||
for(int i = (sreCardinality - Lab_t); i < sreCardinality; i++) {
|
||||
setLabelInDomain(getLabelSet().getCardinality() + 1, sreCardinality, i);
|
||||
addLabel(sreFuzzySet.getLabelSet().getLabel(i));
|
||||
}
|
||||
|
||||
setLabelInDomain(sl + Lab_t1, srcCardinality, aux + Lab_t1);
|
||||
setLabelInDomain(sl + Lab_t1, sreCardinality, sreCardinality - Lab_t - 1);
|
||||
rightBrid = sreFuzzySet.getLabelSet().getLabel(sreCardinality - Lab_t - 1);
|
||||
a = leftBrid.getSemantic().getCoverage().getMin();
|
||||
b = rightBrid.getSemantic().getCenter().getMin();
|
||||
d = rightBrid.getSemantic().getCoverage().getMax();
|
||||
|
||||
double limits1[] = { a, b, b, d };
|
||||
TrapezoidalFunction semantic1 = new TrapezoidalFunction(limits1);
|
||||
|
||||
// brid = new LabelLinguisticDomain(rightBrid.getName(), semantic1);
|
||||
brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context);
|
||||
brid.initLabelLinguisticDomain(rightBrid.getName(), semantic1);
|
||||
|
||||
addLabel(sl + Lab_t1, brid);
|
||||
}
|
||||
}
|
||||
|
||||
_lh = new int[lh.size()];
|
||||
for(int i = 0; i < _lh.length; i++) {
|
||||
_lh[i] = lh.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
private String loadStringLh(String result) {
|
||||
StringBuilder lh = new StringBuilder("lh = "); //$NON-NLS-1$
|
||||
|
||||
for(int l: _lh) {
|
||||
lh.append(l + ","); //$NON-NLS-1$
|
||||
}
|
||||
lh.replace(lh.length() - 1, lh.length(), ""); //$NON-NLS-1$
|
||||
result += lh.toString();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String loadStringFormat(String result) {
|
||||
String format = ";sl = " + _sl + ";" + "slDensity = " + _slDensity + ";" + "sr = " + _sr + ";" + "srDensity = " + _srDensity; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
result += format;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String loadStringLabels(String result) {
|
||||
int numLabels;
|
||||
StringBuilder labels = new StringBuilder(";labels ="); //$NON-NLS-1$
|
||||
for(int label: _labels.keySet()) {
|
||||
labels.append(label + "={");
|
||||
numLabels = 0;
|
||||
for(int domain: _labels.get(label).keySet()) {
|
||||
if(numLabels != (_labels.get(label).size() - 1)) {
|
||||
labels.append(domain + "=" + _labels.get(label).get(domain) + ","); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else {
|
||||
labels.append(domain + "=" + _labels.get(label).get(domain)); //$NON-NLS-1$
|
||||
}
|
||||
numLabels++;
|
||||
}
|
||||
labels.append("}&"); //$NON-NLS-1$
|
||||
}
|
||||
labels.deleteCharAt(labels.lastIndexOf("&"));
|
||||
|
||||
result += labels.toString();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter writer) throws XMLStreamException {
|
||||
|
||||
writer.writeAttribute(Fields.leftLateralSet.toString(), Integer.toString(this._sl));
|
||||
writer.writeAttribute(Fields.rightLateralSet.toString(), Integer.toString(this._sr));
|
||||
writer.writeAttribute(Fields.leftLateralSetDensity.toString(), Integer.toString(this._slDensity));
|
||||
writer.writeAttribute(Fields.rightLateralSetDensity.toString(), Integer.toString(this._srDensity));
|
||||
writer.writeAttribute(Fields.cardinality.toString(), Integer.toString(this._cardinality));
|
||||
|
||||
// Write Linguistic Hierarchy
|
||||
writer.writeStartElement(Fields.linguisticHierarchy.toString());
|
||||
for (int element : this._lh) {
|
||||
writer.writeStartElement(Fields.linguisticTerm.toString());
|
||||
writer.writeAttribute(Fields.granularity.toString(), Integer.toString(element));
|
||||
writer.writeEndElement();
|
||||
}
|
||||
writer.writeEndElement();
|
||||
|
||||
// Labels
|
||||
writer.writeStartElement(Fields.unbalancedLabels.toString());
|
||||
for (Integer pos : this._labels.keySet()) {
|
||||
Map<Integer, Integer> labels = this._labels.get(pos);
|
||||
|
||||
writer.writeStartElement(Fields.unbalancedLabel.toString());
|
||||
// TODO: Se debería poder quitar, es autoincremental desde 0
|
||||
writer.writeAttribute(Fields.position.toString(), Integer.toString(pos));
|
||||
|
||||
for (Integer domain : labels.keySet()) {
|
||||
writer.writeStartElement(Fields.domainLabel.toString());
|
||||
writer.writeAttribute(Fields.domainGranularity.toString(), Integer.toString(domain));
|
||||
writer.writeAttribute(Fields.label.toString(), Integer.toString(labels.get(domain)));
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
writer.writeEndElement();
|
||||
|
||||
}
|
||||
writer.writeEndElement();
|
||||
|
||||
super.write(writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(WNode node) {
|
||||
if (node.getVersion()
|
||||
.equals("3.0")) //$NON-NLS-1$
|
||||
this.readFS3(node);
|
||||
else
|
||||
this.readFS4(node);
|
||||
super.read(node);
|
||||
|
||||
}
|
||||
|
||||
private void readFS3(WNode node) {
|
||||
|
||||
List<WNode> nodes = node.getChildren();
|
||||
for (WNode item : nodes) {
|
||||
String pseudoType = item.getName();
|
||||
|
||||
if (pseudoType.equals(FieldsFS3.lh.toString()))
|
||||
this.readLH(item);
|
||||
else if (pseudoType.equals(FieldsFS3.labelsU.toString()))
|
||||
this.readLabelsU(item);
|
||||
else if (pseudoType.equals(FieldsFS3.data.toString()))
|
||||
this.readDataFS3(item);
|
||||
else if (pseudoType.equals(FieldsFS3.values.toString()) || pseudoType.equals(FieldsFS3.labelSet.toString())) {
|
||||
// Do nothing, se hace arriba.
|
||||
} else
|
||||
throw new Error("Implementar para pseudoType " + pseudoType); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
// Read values & labelset
|
||||
super.read(node);
|
||||
|
||||
}
|
||||
|
||||
private void readFS4(WNode node) {
|
||||
this.readDataFS4(node);
|
||||
this.readLinguisticHierarchyFS4(node.getFirst(Fields.linguisticHierarchy));
|
||||
this.readUnbalancedLabelsFS4(node.getFirst(Fields.unbalancedLabels));
|
||||
super.read(node);
|
||||
}
|
||||
|
||||
private void readLH(WNode node) {
|
||||
|
||||
List<Integer> values = new ArrayList<>();
|
||||
List<WNode> nodes = node.getChildren();
|
||||
for (WNode item : nodes) {
|
||||
String valueS = item.getAttribute(FieldsFS3.l);
|
||||
Integer value = Integer.valueOf(valueS);
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
this._lh = new int[values.size()];
|
||||
for (int i = 0; i < values.size(); i++)
|
||||
this._lh[i] = values.get(i);
|
||||
|
||||
}
|
||||
|
||||
private void readLinguisticHierarchyFS4(WNode node) {
|
||||
List<Integer> values = new ArrayList<>();
|
||||
|
||||
for (WNode item : node.getChildren()) {
|
||||
int granularity = item.getAttributeInt(Fields.granularity);
|
||||
values.add(granularity);
|
||||
}
|
||||
this._lh = values.stream()
|
||||
.mapToInt(i -> i)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
private void readUnbalancedLabelsFS4(WNode node) {
|
||||
|
||||
for (WNode unbalancedLabelNode : node.getChildren()) {
|
||||
int position = unbalancedLabelNode.getAttributeInt(Fields.position);
|
||||
|
||||
Map<Integer, Integer> domainLabels = new HashMap<>();
|
||||
for (WNode domainLabel : unbalancedLabelNode.getChildren()) {
|
||||
int domainGranularity = domainLabel.getAttributeInt(Fields.domainGranularity);
|
||||
int label = domainLabel.getAttributeInt(Fields.label);
|
||||
domainLabels.put(domainGranularity, label);
|
||||
}
|
||||
this._labels.put(position, domainLabels);
|
||||
}
|
||||
}
|
||||
|
||||
private void readLabelsU(WNode node) {
|
||||
|
||||
List<WNode> nodes = node.getChildren();
|
||||
this._labels = new HashMap<>();
|
||||
|
||||
Map<Integer, Integer> data = new HashMap<>();
|
||||
|
||||
int pos = 0;
|
||||
for (WNode item : nodes) {
|
||||
|
||||
if(item.getName().equals("labelU")) {
|
||||
|
||||
this._labels.put(pos, new HashMap<>(data));
|
||||
data.clear();
|
||||
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
String domainS = item.getAttribute(FieldsFS3.d);
|
||||
String labelS = item.getAttribute(FieldsFS3.la);
|
||||
int domain = Integer.parseInt(domainS);
|
||||
int label = Integer.parseInt(labelS);
|
||||
data.put(domain, label);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void readDataFS3(WNode node) {
|
||||
this._sl = Integer.parseInt(node.getAttribute(FieldsFS3.sl));
|
||||
this._sr = Integer.parseInt(node.getAttribute(FieldsFS3.sr));
|
||||
this._slDensity = Integer.parseInt(node.getAttribute(FieldsFS3.slDensity));
|
||||
this._srDensity = Integer.parseInt(node.getAttribute(FieldsFS3.srDensity));
|
||||
this._cardinality = Integer.parseInt(node.getAttribute(FieldsFS3.cardinality));
|
||||
}
|
||||
|
||||
private void readDataFS4(WNode node) {
|
||||
this._sl = Integer.parseInt(node.getAttribute(Fields.leftLateralSet));
|
||||
this._sr = Integer.parseInt(node.getAttribute(Fields.rightLateralSet));
|
||||
this._slDensity = Integer.parseInt(node.getAttribute(Fields.leftLateralSetDensity));
|
||||
this._srDensity = Integer.parseInt(node.getAttribute(Fields.rightLateralSetDensity));
|
||||
this._cardinality = Integer.parseInt(node.getAttribute(Fields.cardinality));
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package flintstones.domain.fuzzyset.unbalanced.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.unbalanced.Unbalanced;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class Unbalanced3C5EIntance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
Unbalanced domain = (Unbalanced) getDomain();
|
||||
|
||||
String[] labels = new String[9];
|
||||
for(int i = 0; i < 9; i++)
|
||||
labels[i] = "s"+(i+1);
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createUnbalancedDomain(labels, 5, 3, 1, 0,5);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package flintstones.domain.fuzzyset.unbalanced.instance;
|
||||
|
||||
import flintstones.domain.fuzzyset.unbalanced.Unbalanced;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.DomainInstance;
|
||||
|
||||
public class Unbalanced5E3CIntance extends DomainInstance {
|
||||
|
||||
@Override
|
||||
public Domain getInstance() {
|
||||
Unbalanced domain = (Unbalanced) getDomain();
|
||||
|
||||
String[] labels = new String[9];
|
||||
for(int i = 0; i < 9; i++)
|
||||
labels[i] = "s"+(i+1);
|
||||
|
||||
String name = getLabel();
|
||||
|
||||
domain.createUnbalancedDomain(labels, 3, 5, 0, 1,5);
|
||||
domain.setName(name);
|
||||
return domain;
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// This file has been auto-generated
|
||||
package flintstones.domain.fuzzyset.unbalanced.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public static String Unbalanced_id;
|
||||
public String Unbalanced_Invalid_cardinality;
|
||||
public String Unbalanced_Invalid_initial_domain;
|
||||
public String Unbalanced_Invalid_sl;
|
||||
public String Unbalanced_Invalid_sl_density;
|
||||
public String Unbalanced_Invalid_sr;
|
||||
public String Unbalanced_Invalid_sr_density;
|
||||
public String Unbalanced_Pair_cardinality;
|
||||
public String Unbalanced_Pair_initial_domain;
|
||||
public String category;
|
||||
public String name;
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
Unbalanced_id=flintstones.domain.linguistic.unbalanced
|
||||
Unbalanced_Invalid_cardinality=Invalid cardinality
|
||||
Unbalanced_Invalid_initial_domain=Invalid initial domain
|
||||
Unbalanced_Invalid_sl=Invalid sl
|
||||
Unbalanced_Invalid_sl_density=Invalid sl density
|
||||
Unbalanced_Invalid_sr=Invalid sr
|
||||
Unbalanced_Invalid_sr_density=Invalid sr density
|
||||
Unbalanced_Pair_cardinality=Pair cardinality
|
||||
Unbalanced_Pair_initial_domain=Pair initial domain
|
||||
category=Unbalanced
|
||||
name=Unbalanced
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
Unbalanced_id=flintstones.domain.linguistic.unbalanced
|
||||
Unbalanced_Invalid_cardinality=Cardinalidad inválida
|
||||
Unbalanced_Invalid_initial_domain=Dominio inicial inválido
|
||||
Unbalanced_Invalid_sl=Sl inválida
|
||||
Unbalanced_Invalid_sl_density=Densidad sl inválida
|
||||
Unbalanced_Invalid_sr=Sr inválido
|
||||
Unbalanced_Invalid_sr_density=Densidad sr inválida
|
||||
Unbalanced_Pair_cardinality=Cardinalidad par
|
||||
Unbalanced_Pair_initial_domain=Dominio inicial par
|
||||
category=No balanceados
|
||||
name=No balanceado
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
package flintstones.domain.fuzzyset.unbalanced.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
|
||||
import flintstones.domain.fuzzyset.label.LabelLinguisticDomain;
|
||||
import flintstones.domain.fuzzyset.unbalanced.Unbalanced;
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.valuation.twoTuple.TwoTupleValuation;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
// PATCH class from FS3 to allow unbalanced work with unification/aggregation
|
||||
public class UnbalancedUtils {
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
private Unbalanced _unbalancedDomain;
|
||||
|
||||
private final int UNBALANCED_LEFT = 0;
|
||||
private final int UNBALANCED_RIGHT = 1;
|
||||
|
||||
public Map<ProblemElement, Valuation> transformUnbalanced(Map<ProblemElement, Valuation> problemResult, Unbalanced resultsDomain) {
|
||||
|
||||
_unbalancedDomain = resultsDomain;
|
||||
Map<ProblemElement, Valuation> results = null;
|
||||
|
||||
if(resultsDomain != null) {
|
||||
|
||||
results = new HashMap<ProblemElement, Valuation>();
|
||||
|
||||
Valuation valuation;
|
||||
Unbalanced hgls = null;
|
||||
LabelLinguisticDomain label, labelTest = null;
|
||||
double alpha;
|
||||
Map<Integer, Integer> domains = null;
|
||||
int testPos;
|
||||
boolean find;
|
||||
Integer labelPos;
|
||||
Unbalanced domainTest;
|
||||
int domainPos;
|
||||
int domainSize;
|
||||
|
||||
int size;
|
||||
Unbalanced[] auxDomains = null;
|
||||
LabelLinguisticDomain[] labels = null;
|
||||
double[] alphas = null;
|
||||
int[] sizes = null;
|
||||
|
||||
int[] lh = resultsDomain.getLh();
|
||||
Map<Integer, Unbalanced> lhDomains = new HashMap<Integer, Unbalanced>();
|
||||
|
||||
for(int i = 0; i < lh.length; i++) {
|
||||
lhDomains.put(lh[i], createDomain(lh[i]));
|
||||
}
|
||||
|
||||
for(ProblemElement alternative : problemResult.keySet()) {
|
||||
valuation = problemResult.get(alternative);
|
||||
if(valuation != null) {
|
||||
if(hgls == null) {
|
||||
hgls = (Unbalanced) valuation.getDomain();
|
||||
}
|
||||
label = ((TwoTupleValuation) valuation).getLabel();
|
||||
alpha = ((TwoTupleValuation) valuation).getAlpha();
|
||||
|
||||
find = false;
|
||||
|
||||
domainPos = lh.length - 1;
|
||||
do {
|
||||
domainSize = lh[domainPos];
|
||||
domainTest = lhDomains.get(domainSize);
|
||||
testPos = domainTest.getLabelSet().getPos(label);
|
||||
labelPos = resultsDomain.labelPos(domainSize, testPos);
|
||||
if(labelPos != null) {
|
||||
find = true;
|
||||
labelTest = _unbalancedDomain.getLabelSet().getLabel(labelPos);
|
||||
domains = resultsDomain.getLabel(labelPos);
|
||||
size = domains.size();
|
||||
auxDomains = new Unbalanced[size];
|
||||
labels = new LabelLinguisticDomain[size];
|
||||
sizes = new int[size];
|
||||
alphas = new double[size];
|
||||
int i = 0;
|
||||
for(Integer auxSize : domains.keySet()) {
|
||||
auxDomains[i] = lhDomains.get(auxSize);
|
||||
labels[i] = auxDomains[i].getLabelSet().getLabel(domains.get(auxSize));
|
||||
sizes[i] = auxSize;
|
||||
if (labels[i] == label) {
|
||||
alphas[i] = alpha;
|
||||
} else {
|
||||
alphas[i] = ((TwoTupleValuation) valuation).transform(auxDomains[i]).getAlpha();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
domainPos--;
|
||||
valuation = ((TwoTupleValuation) valuation).transform(lhDomains.get(lh[domainPos]));
|
||||
label = ((TwoTupleValuation) valuation).getLabel();
|
||||
alpha = ((TwoTupleValuation) valuation).getAlpha();
|
||||
}
|
||||
} while (!find);
|
||||
|
||||
if((domains.size() == 1) || (alpha == 0)) {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[0]);
|
||||
} else {
|
||||
if(alpha > 0) {
|
||||
if(smallSide(labelTest) == UNBALANCED_RIGHT) {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[0]);
|
||||
} else {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[1]);
|
||||
}
|
||||
} else {
|
||||
if(sizes[0] > sizes[1]) {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[1]);
|
||||
} else {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[0]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (smallSide(label) == UNBALANCED_RIGHT) {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[1]);
|
||||
} else {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[0]);
|
||||
}
|
||||
} else {
|
||||
if (sizes[0] > sizes[1]) {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[0]);
|
||||
} else {
|
||||
valuation = transformToResultsDomain(labelTest, alphas[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results.put(alternative, valuation);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private Unbalanced createDomain(int cardinality) {
|
||||
String[] labels = new String[cardinality];
|
||||
for(int i = 0; i < cardinality; i++) {
|
||||
labels[i] = Integer.toString(i);
|
||||
}
|
||||
|
||||
Unbalanced domain = ContextInjectionFactory.make(Unbalanced.class, context);
|
||||
domain.createTrapezoidalFunction(labels);
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
private int smallSide(LabelLinguisticDomain l) {
|
||||
NumericRealDomain center = l.getSemantic().getCenter();
|
||||
NumericRealDomain coverage = l.getSemantic().getCoverage();
|
||||
|
||||
double left = center.getMin() - coverage.getMin();
|
||||
double right = coverage.getMax() - center.getMax();
|
||||
|
||||
if(left > right) {
|
||||
return UNBALANCED_RIGHT;
|
||||
} else {
|
||||
return UNBALANCED_LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
private Valuation transformToResultsDomain(LabelLinguisticDomain label, double alpha) {
|
||||
TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context);
|
||||
result.build(_unbalancedDomain, label, alpha);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user