public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-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.method.common.phase.generateUnificationDomain</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] GenerateUnificationDomain</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.method.common.phase.generateUnificationDomain</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>1779484362649</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
|
||||
+7
@@ -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
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: GenerateUnificationDomain
|
||||
Bundle-SymbolicName: flintstones.method.common.phase.generateUnificationDomain;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.method.common.phase.generateUnificationDomain
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: javax.inject,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.model.valuation.service,
|
||||
flintstones.domain.fuzzyset,
|
||||
org.eclipse.e4.core.contexts,
|
||||
flintstones.model.problemelement.service,
|
||||
org.eclipse.e4.core.di,
|
||||
flintstones.entity.domain,
|
||||
flintstones.entity.method.phase
|
||||
Export-Package: flintstones.method.common.phase.generateUnificationDomain
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="flintstones.phasemethod.extensionpoint">
|
||||
<phase
|
||||
uid="flintstones.method.common.phase.generateUnificationDomain"
|
||||
implementation="flintstones.method.common.phase.generateUnificationDomain.GenerateUnificationDomainModel">
|
||||
</phase>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
|
||||
package flintstones.method.common.phase.generateUnificationDomain;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
|
||||
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.method.phase.PhaseMethod;
|
||||
import flintstones.entity.problemelement.ProblemElementKey;
|
||||
import flintstones.entity.problemelement.entities.Alternative;
|
||||
import flintstones.entity.problemelement.entities.Criterion;
|
||||
import flintstones.entity.problemelement.entities.Expert;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class GenerateUnificationDomainModel extends PhaseMethod {
|
||||
|
||||
@Inject
|
||||
IProblemElementService problemService;
|
||||
|
||||
@Inject
|
||||
IValuationService valuationService;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
private List<Object[]> _elhDomains;
|
||||
|
||||
private FuzzySet _unifiedDomain;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Generate Unification Domain";
|
||||
}
|
||||
|
||||
public void export() {
|
||||
this.exportData("unifiedDomain",_unifiedDomain);
|
||||
this.exportData("elhDomains",_elhDomains, true);
|
||||
}
|
||||
|
||||
private class MyComparator implements Comparator<Object[]> {
|
||||
@Override
|
||||
public int compare(Object[] o1, Object[] o2) {
|
||||
return Double.compare((Integer) o1[0], (Integer) o2[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private FuzzySet generateUnifiedDomain(Set<Integer> sizes) {
|
||||
|
||||
FuzzySet result = null;
|
||||
|
||||
if(sizes.size() != 0) {
|
||||
Integer[] formerModalPoints = sizes.toArray(new Integer[0]);
|
||||
for(int i = 0; i < formerModalPoints.length; i++) {
|
||||
formerModalPoints[i] = formerModalPoints[i] - 1;
|
||||
}
|
||||
|
||||
int unifiedDomainSize = lcm(formerModalPoints) + 1;
|
||||
|
||||
if(!sizes.contains(unifiedDomainSize)) {
|
||||
result = ContextInjectionFactory.make(FuzzySet.class, context);
|
||||
|
||||
String[] labels = new String[unifiedDomainSize];
|
||||
for(int i = 0; i < unifiedDomainSize; i++) {
|
||||
labels[i] = "s" + i; //$NON-NLS-1$
|
||||
}
|
||||
result.createTrapezoidalFunction(labels);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public List<Object[]> generateLH() {
|
||||
|
||||
_elhDomains = new LinkedList<Object[]>();
|
||||
|
||||
List<Object[]> domains = new LinkedList<Object[]>();
|
||||
Set<String> domainsNames = new HashSet<String>();
|
||||
int i = 1, cardinality;
|
||||
|
||||
String domainName;
|
||||
Domain generateDomain, domain;
|
||||
|
||||
for(ProblemElement alternative : problemService.getAll(Alternative.Type)) {
|
||||
for(ProblemElement criterion : problemService.getAll(Criterion.Type)) {
|
||||
if(!criterion.hasChildren()) {
|
||||
for(ProblemElement expert : problemService.getAll(Expert.Type)) {
|
||||
if(!expert.hasChildren()) {
|
||||
Valuation v = valuationService.getValuationFor(new ProblemElementKey((Expert)expert, (Alternative)alternative, (Criterion)criterion));
|
||||
if(v != null) {
|
||||
generateDomain = v.getDomain();
|
||||
if(generateDomain != null) {
|
||||
domainName = generateDomain.getName();
|
||||
if(generateDomain instanceof FuzzySet) {
|
||||
if(!domainsNames.contains(domainName)) {
|
||||
if(((FuzzySet) generateDomain).isBLTS()) {
|
||||
cardinality = ((FuzzySet) generateDomain).getLabelSet().getCardinality();
|
||||
domains.add(new Object[] { cardinality, domainName, generateDomain });
|
||||
domainsNames.add(domainName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(domains, new MyComparator());
|
||||
|
||||
Integer value;
|
||||
i = 0;
|
||||
Set<Integer> sizes = new HashSet<Integer>();
|
||||
int oldValue = -1;
|
||||
for(Object[] entry : domains) {
|
||||
value = (Integer) entry[0];
|
||||
sizes.add(value);
|
||||
if(oldValue != value) {
|
||||
oldValue = value;
|
||||
i++;
|
||||
}
|
||||
entry[0] = "l(" + i + "," + value + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
_elhDomains.addAll(domains);
|
||||
|
||||
String generate = "Generate";
|
||||
domain = generateUnifiedDomain(sizes);
|
||||
int index;
|
||||
if(domain != null) {
|
||||
domainName = generate;
|
||||
|
||||
index = 1;
|
||||
while(domainsNames.contains(domainName)) {
|
||||
domainName = generate + "_" + index++; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
cardinality = ((FuzzySet) domain).getLabelSet().getCardinality();
|
||||
if(cardinality != oldValue) {
|
||||
i++;
|
||||
}
|
||||
|
||||
domain.setName(domainName);
|
||||
domainsNames.add(domainName);
|
||||
|
||||
_elhDomains.add(new Object[] { "l(" + i + "," + cardinality + ")", domainName, domain }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
_unifiedDomain = (FuzzySet) ((FuzzySet) _elhDomains.get(_elhDomains.size() - 1)[2]).clone();
|
||||
|
||||
return _elhDomains;
|
||||
}
|
||||
|
||||
|
||||
private int lcm(Integer[] input) {
|
||||
int result = input[0];
|
||||
for(int i = 1; i < input.length; i++) {
|
||||
result = lcm(result, input[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private int lcm(int a, int b) {
|
||||
return a * (b / gcd(a, b));
|
||||
}
|
||||
|
||||
private int gcd(int a, int b) {
|
||||
int aux;
|
||||
while(b > 0) {
|
||||
aux = b;
|
||||
b = a % b;
|
||||
a = aux;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user