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.operator.aggregation.median</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Median</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.operator.aggregation.median</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>1779484362734</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,19 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Median
|
||||
Bundle-SymbolicName: flintstones.operator.aggregation.median;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.operator.aggregation.median
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.operator,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.model.valuation.service,
|
||||
flintstones.valuation.numeric.integer.interval,
|
||||
flintstones.valuation.numeric.integer,
|
||||
flintstones.valuation.numeric.real.interval,
|
||||
flintstones.valuation.numeric.real,
|
||||
flintstones.valuation.twoTuple,
|
||||
flintstones.valuation.linguistic,
|
||||
flintstones.domain.numeric.real,
|
||||
flintstones.entity.domain,
|
||||
flintstones.entity.operator
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="flintstones.operator.aggregation.extensionpoint">
|
||||
<aggregation_operator_type
|
||||
uid="flintstones.operator.aggregation.median"
|
||||
implementation="flintstones.operator.aggregation.median.Median">
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.median.operators.MedianInteger"
|
||||
valuationId="flintstones.valuation.integer">
|
||||
</aggregation_operator>
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.median.operators.MedianReal"
|
||||
valuationId="flintstones.valuation.real">
|
||||
</aggregation_operator>
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.median.operators.MedianRealInterval"
|
||||
valuationId="flintstones.valuation.real.interval">
|
||||
</aggregation_operator>
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.median.operators.MedianIntegerInterval"
|
||||
valuationId="flintstones.valuation.integer.interval">
|
||||
</aggregation_operator>
|
||||
<aggregation_operator
|
||||
implementation="flintstones.operator.aggregation.median.operators.MedianTwoTuple"
|
||||
valuationId="flintstones.valuation.twoTuple">
|
||||
</aggregation_operator>
|
||||
</aggregation_operator_type>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package flintstones.operator.aggregation.median;
|
||||
|
||||
import flintstones.entity.operator.AggregationOperator;
|
||||
import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator;
|
||||
|
||||
public abstract class Median extends AggregationOperator implements IUnweightedAggregationOperator {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Median";
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package flintstones.operator.aggregation.median.operators;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import flintstones.domain.numeric.integer.NumericIntegerDomain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.operator.aggregation.median.Median;
|
||||
import flintstones.valuation.numeric.integer.IntegerValuation;
|
||||
|
||||
public class MedianInteger extends Median {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations) {
|
||||
Valuation result = null;
|
||||
NumericIntegerDomain domain = null;
|
||||
List<Valuation> values = new LinkedList<Valuation>();
|
||||
|
||||
for(Valuation valuation: valuations) {
|
||||
Validator.notIllegalElementType(valuation, new String[] {IntegerValuation.class.toString()});
|
||||
|
||||
if(domain == null) {
|
||||
domain = (NumericIntegerDomain) valuation.getDomain();
|
||||
} else if(!domain.equals(valuation.getDomain())) {
|
||||
throw new IllegalArgumentException("Messages.IntegerOperator_Invalid_domain");
|
||||
}
|
||||
|
||||
values.add(valuation);
|
||||
}
|
||||
|
||||
if(!values.isEmpty()) {
|
||||
|
||||
Collections.sort(values);
|
||||
|
||||
if(values.size() % 2 != 0) {
|
||||
int median = (values.size() + 1) / 2;
|
||||
|
||||
result = values.get(median);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
} else {
|
||||
int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards
|
||||
int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards
|
||||
|
||||
Valuation auxValuation1 = values.get(firstPosMedian);
|
||||
Valuation auxValuation2 = values.get(secondPosMedian);
|
||||
|
||||
double value = (((IntegerValuation) auxValuation1).getValue() + ((IntegerValuation) auxValuation2).getValue()) / 2d;
|
||||
|
||||
result = values.get(firstPosMedian);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
((IntegerValuation) result).setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package flintstones.operator.aggregation.median.operators;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import flintstones.domain.numeric.integer.NumericIntegerDomain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.operator.aggregation.median.Median;
|
||||
import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation;
|
||||
|
||||
public class MedianIntegerInterval extends Median {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations) {
|
||||
Valuation result = null;
|
||||
NumericIntegerDomain domain = null;
|
||||
List<Valuation> values = new LinkedList<Valuation>();
|
||||
|
||||
for(Valuation valuation: valuations) {
|
||||
Validator.notIllegalElementType(valuation, new String[] {IntegerIntervalValuation.class.toString()});
|
||||
|
||||
if(domain == null) {
|
||||
domain = (NumericIntegerDomain) valuation.getDomain();
|
||||
} else if(!domain.equals(valuation.getDomain())) {
|
||||
throw new IllegalArgumentException("Messages.IntervalIntegerOperator_Invalid_domain");
|
||||
}
|
||||
|
||||
values.add(valuation);
|
||||
}
|
||||
|
||||
if(!values.isEmpty()) {
|
||||
Collections.sort(values);
|
||||
|
||||
if((values.size() % 2) != 0) {
|
||||
|
||||
int median = (values.size() + 1) / 2;
|
||||
|
||||
result = values.get(median);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
} else {
|
||||
|
||||
int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards
|
||||
int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards
|
||||
|
||||
Valuation auxValuation1 = values.get(firstPosMedian);
|
||||
Valuation auxValuation2 = values.get(secondPosMedian);
|
||||
|
||||
double minValue = (((IntegerIntervalValuation) auxValuation1).getMin()) + (((IntegerIntervalValuation) auxValuation2).getMin());
|
||||
double maxValue = (((IntegerIntervalValuation) auxValuation1).getMax()) + (((IntegerIntervalValuation) auxValuation2).getMax());
|
||||
|
||||
minValue /= 2d;
|
||||
maxValue /= 2d;
|
||||
|
||||
result = values.get(firstPosMedian);
|
||||
result = (Valuation) result.clone();//clone any valuation
|
||||
|
||||
((IntegerIntervalValuation) result).setMinMax(minValue, maxValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package flintstones.operator.aggregation.median.operators;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.operator.aggregation.median.Median;
|
||||
import flintstones.valuation.numeric.real.RealValuation;
|
||||
|
||||
public class MedianReal extends Median {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations) {
|
||||
Valuation result = null;
|
||||
NumericRealDomain domain = null;
|
||||
List<Valuation> values = new LinkedList<Valuation>();
|
||||
|
||||
for (Valuation valuation : valuations) {
|
||||
Validator.notIllegalElementType(valuation, new String[] { RealValuation.class.toString() });
|
||||
|
||||
if (domain == null) {
|
||||
domain = (NumericRealDomain) valuation.getDomain();
|
||||
} else if (!domain.equals(valuation.getDomain())) {
|
||||
throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain");
|
||||
}
|
||||
|
||||
values.add(valuation);
|
||||
}
|
||||
|
||||
if (!values.isEmpty()) {
|
||||
|
||||
Collections.sort(values);
|
||||
|
||||
if (values.size() % 2 != 0) {
|
||||
int median = (values.size() + 1) / 2;
|
||||
|
||||
result = values.get(median - 1);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
} else {
|
||||
int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);// the nearest integer when
|
||||
// rounding downwards
|
||||
int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);// the nearest integer when
|
||||
// rounding upwards
|
||||
|
||||
Valuation auxValuation1 = values.get(firstPosMedian);
|
||||
Valuation auxValuation2 = values.get(secondPosMedian);
|
||||
|
||||
double value = (((RealValuation) auxValuation1).getValue() + ((RealValuation) auxValuation2).getValue())
|
||||
/ 2d;
|
||||
|
||||
result = values.get(firstPosMedian);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
((RealValuation) result).setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package flintstones.operator.aggregation.median.operators;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import flintstones.domain.numeric.real.NumericRealDomain;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.operator.aggregation.median.Median;
|
||||
import flintstones.valuation.numeric.real.interval.RealIntervalValuation;
|
||||
|
||||
public class MedianRealInterval extends Median {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations) {
|
||||
Valuation result = null;
|
||||
NumericRealDomain domain = null;
|
||||
List<Valuation> values = new LinkedList<Valuation>();
|
||||
|
||||
for(Valuation valuation: valuations) {
|
||||
Validator.notIllegalElementType(valuation, new String[] {RealIntervalValuation.class.toString()});
|
||||
|
||||
if(domain == null) {
|
||||
domain = (NumericRealDomain) valuation.getDomain();
|
||||
} else if(!domain.equals(valuation.getDomain())) {
|
||||
throw new IllegalArgumentException("Messages.IntervalRealOperator_Invalid_domain");
|
||||
}
|
||||
|
||||
values.add(valuation);
|
||||
}
|
||||
|
||||
if(!values.isEmpty()) {
|
||||
Collections.sort(values);
|
||||
|
||||
if((values.size() % 2) != 0) {
|
||||
|
||||
int median = (values.size() + 1) / 2;
|
||||
|
||||
result = values.get(median);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
} else {
|
||||
|
||||
int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards
|
||||
int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards
|
||||
|
||||
Valuation auxValuation1 = values.get(firstPosMedian);
|
||||
Valuation auxValuation2 = values.get(secondPosMedian);
|
||||
|
||||
double minValue = (((RealIntervalValuation) auxValuation1).getMin()) + (((RealIntervalValuation) auxValuation2).getMin());
|
||||
double maxValue = (((RealIntervalValuation) auxValuation1).getMax()) + (((RealIntervalValuation) auxValuation2).getMax());
|
||||
|
||||
minValue /= 2d;
|
||||
maxValue /= 2d;
|
||||
|
||||
result = values.get(firstPosMedian);
|
||||
result = (Valuation) result.clone();//clone any valuation
|
||||
|
||||
((RealIntervalValuation) result).setMinMax(minValue, maxValue);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package flintstones.operator.aggregation.median.operators;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.validator.Validator;
|
||||
import flintstones.operator.aggregation.median.Median;
|
||||
import flintstones.valuation.twoTuple.TwoTupleValuation;
|
||||
|
||||
public class MedianTwoTuple extends Median {
|
||||
|
||||
@Override
|
||||
public Valuation aggregate(List<Valuation> valuations) {
|
||||
Valuation result = null;
|
||||
FuzzySet domain = null;
|
||||
List<Valuation> values = new LinkedList<Valuation>();
|
||||
|
||||
for(Valuation valuation: valuations) {
|
||||
Validator.notIllegalElementType(valuation, new String[] {TwoTupleValuation.class.toString()});
|
||||
|
||||
if(domain == null) {
|
||||
domain = (FuzzySet) valuation.getDomain();
|
||||
} else if(!domain.equals(valuation.getDomain())) {
|
||||
throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain");
|
||||
}
|
||||
|
||||
values.add(valuation);
|
||||
}
|
||||
|
||||
if(domain != null) {
|
||||
|
||||
if(!values.isEmpty()) {
|
||||
|
||||
Collections.sort(values);
|
||||
|
||||
if(values.size() % 2 != 0) {
|
||||
int median = (values.size() + 1) / 2;
|
||||
|
||||
result = values.get(median);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
} else {
|
||||
int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards
|
||||
int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards
|
||||
|
||||
Valuation auxValuation1 = values.get(firstPosMedian);
|
||||
Valuation auxValuation2 = values.get(secondPosMedian);
|
||||
|
||||
double beta = (((TwoTupleValuation) auxValuation1).calculateInverseDelta() + ((TwoTupleValuation) auxValuation2).calculateInverseDelta()) / 2d;
|
||||
|
||||
result = values.get(firstPosMedian);
|
||||
result = (Valuation) result.clone();
|
||||
|
||||
((TwoTupleValuation) result).calculateDelta(beta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user