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.entity.aggregation</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Aggregation</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.entity.aggregation</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>1779484362552</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,10 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Aggregation
|
||||
Bundle-SymbolicName: flintstones.entity.aggregation
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.entity.aggregation
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.entity.problemelement,
|
||||
flintstones.helper.data
|
||||
Export-Package: flintstones.entity.aggregation
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
package flintstones.entity.aggregation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import flintstones.entity.problemelement.entities.Alternative;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.helper.DoubleHelper;
|
||||
|
||||
public class AggregationItem implements Cloneable {
|
||||
|
||||
// Current item
|
||||
Alternative element1;
|
||||
ProblemElement element2 = null;
|
||||
ProblemElement element3 = null;
|
||||
|
||||
// Relatives
|
||||
AggregationItem parent = null;
|
||||
List<AggregationItem> children = new LinkedList<>();
|
||||
|
||||
// Data
|
||||
Double weight = 0.0d;
|
||||
String aggregationOperatorId = "";
|
||||
boolean isEnabled = true;
|
||||
|
||||
public AggregationItem(Alternative alternative) {
|
||||
|
||||
element1 = alternative;
|
||||
setWeight(0.0);
|
||||
|
||||
}
|
||||
|
||||
public AggregationItem(Alternative cElement1, ProblemElement[] elements2, ProblemElement[] elements3) {
|
||||
|
||||
element1 = cElement1;
|
||||
|
||||
setWeight(1.0);
|
||||
|
||||
for (ProblemElement expert : elements2) {
|
||||
AggregationItem agg = new AggregationItem(cElement1, expert, elements3);
|
||||
agg.setParent(this);
|
||||
children.add(agg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public AggregationItem(Alternative cElement1, ProblemElement cElement2, ProblemElement[] elements3) {
|
||||
|
||||
element1 = cElement1;
|
||||
element2 = cElement2;
|
||||
|
||||
if (cElement2.hasChildren()) {
|
||||
ProblemElement[] experts = element2.getChildren();
|
||||
for (ProblemElement expert : experts) {
|
||||
AggregationItem agg = new AggregationItem(cElement1, expert, elements3);
|
||||
agg.setParent(this);
|
||||
children.add(agg);
|
||||
}
|
||||
} else {
|
||||
for (ProblemElement criterion : elements3) {
|
||||
AggregationItem agg = new AggregationItem(cElement1, cElement2, criterion);
|
||||
agg.setParent(this);
|
||||
children.add(agg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AggregationItem(Alternative cElement1, ProblemElement cElement2, ProblemElement cElement3) {
|
||||
|
||||
element1 = cElement1;
|
||||
element2 = cElement2;
|
||||
element3 = cElement3;
|
||||
|
||||
if (element3.hasChildren()) {
|
||||
ProblemElement[] criterions = cElement3.getChildren();
|
||||
for (ProblemElement c : criterions) {
|
||||
AggregationItem agg = new AggregationItem(cElement1, cElement2, c);
|
||||
agg.setParent(this);
|
||||
children.add(agg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(double w) {
|
||||
weight = w;
|
||||
}
|
||||
|
||||
public boolean validateParentWeights() {
|
||||
if( getParent() == null)
|
||||
return true;
|
||||
return parent.validateWeights();
|
||||
}
|
||||
|
||||
public boolean validateWeights() {
|
||||
double sum = 0.0d;
|
||||
for (AggregationItem item : children) {
|
||||
if(item.isEnabled())
|
||||
sum += item.getWeight();
|
||||
}
|
||||
return DoubleHelper.Equals(sum, 1.0d, 3);
|
||||
|
||||
}
|
||||
|
||||
public void setWeights(double[] weights) {
|
||||
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
children.get(i).setWeight(weights[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void shareWeight() {
|
||||
|
||||
int total = children.size() != 0 ? children.size() : 1;
|
||||
double partedWeight = 1.0d / total;
|
||||
|
||||
double[] arr = new double[total];
|
||||
Arrays.fill(arr, partedWeight);
|
||||
|
||||
setWeights(arr);
|
||||
|
||||
// Cascade
|
||||
for (AggregationItem item : children)
|
||||
item.shareWeight();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
String a = element1.getName();
|
||||
String e = element2 != null ? element2.getName() : "EX";
|
||||
String c = element3 != null ? element3.getName() : "CX";
|
||||
|
||||
return a + " : " + e + " : " + c + " => " + weight;
|
||||
}
|
||||
|
||||
public ProblemElement getFinalItem() {
|
||||
if (element3 != null)
|
||||
return element3;
|
||||
if (element2 != null)
|
||||
return element2;
|
||||
return element1;
|
||||
}
|
||||
|
||||
public void setParent(AggregationItem item) {
|
||||
parent = item;
|
||||
}
|
||||
|
||||
public AggregationItem getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public boolean hasChildren() {
|
||||
return children.size() != 0;
|
||||
}
|
||||
|
||||
public AggregationItem[] getChildren() {
|
||||
return children.toArray(new AggregationItem[0]);
|
||||
}
|
||||
|
||||
public void setChildren(List<AggregationItem> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public Alternative getAlternative() {
|
||||
return element1;
|
||||
}
|
||||
|
||||
public void setAlternative(Alternative item, boolean cascade) {
|
||||
this.element1 = item;
|
||||
if(cascade)
|
||||
children.stream().forEach(k -> k.setAlternative(item, cascade));
|
||||
}
|
||||
|
||||
public ProblemElement getElement2() {
|
||||
return element2;
|
||||
}
|
||||
|
||||
public ProblemElement getElement3() {
|
||||
return element3;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean x) {
|
||||
isEnabled = x;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public String getOperatorId() {
|
||||
return aggregationOperatorId;
|
||||
}
|
||||
|
||||
public void setOperatorId(String op) {
|
||||
this.aggregationOperatorId = op;
|
||||
}
|
||||
|
||||
public void setOperatorId(String op, boolean cascade) {
|
||||
|
||||
// If the aggregation item is leaf, do not assign operator
|
||||
if(children.size() == 0)
|
||||
return ;
|
||||
|
||||
this.aggregationOperatorId = op;
|
||||
if(cascade)
|
||||
children.stream().forEach(k -> k.setOperatorId(op, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
AggregationItem other = new AggregationItem(element1);
|
||||
other.element2 = this.element2;
|
||||
other.element3 = this.element3;
|
||||
other.setParent(this.parent);
|
||||
other.setChildren(this.children);
|
||||
other.setWeight(this.weight);
|
||||
other.setOperatorId(aggregationOperatorId, false);
|
||||
other.setEnabled(this.isEnabled);
|
||||
return other;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user