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.decision.common.phase.normalization</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Normalization</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.method.decision.common.phase.normalization</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>1779484362658</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
|
||||
@@ -0,0 +1,20 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Normalization
|
||||
Bundle-SymbolicName: flintstones.method.decision.common.phase.normalization;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.method.decision.common.phase.normalization
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.entity.valuation,
|
||||
flintstones.model.valuation.service,
|
||||
javax.inject,
|
||||
flintstones.operator,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.entity.ahp.decisionmatrix,
|
||||
org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.di,
|
||||
flintstones.entity.wvaluation,
|
||||
flintstones.model.problemelement.service,
|
||||
flintstones.entity.operator,
|
||||
flintstones.entity.method.phase
|
||||
Export-Package: flintstones.method.decision.common.phase.normalization
|
||||
@@ -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.decision.common.phase.normalization"
|
||||
implementation="flintstones.method.decision.common.phase.normalization.NormalizationModel">
|
||||
</phase>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
package flintstones.method.decision.common.phase.normalization;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
|
||||
import flintstones.entity.ahp.decisionmatrix.DecisionMatrix;
|
||||
import flintstones.entity.method.phase.ImportedDataNotFoundException;
|
||||
import flintstones.entity.method.phase.PhaseMethod;
|
||||
import flintstones.entity.operator.AggregationOperator;
|
||||
import flintstones.entity.operator.NormalizationOperator;
|
||||
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.entity.wvaluation.WValuation;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
import flintstones.operator.service.IOperatorService;
|
||||
|
||||
public class NormalizationModel extends PhaseMethod {
|
||||
|
||||
@Inject
|
||||
IValuationService valuationService;
|
||||
|
||||
@Inject
|
||||
IOperatorService operatorService;
|
||||
|
||||
@Inject
|
||||
IProblemElementService problemService;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
final HashMap<Expert, DecisionMatrix> expertsMatrix = new HashMap<>();
|
||||
|
||||
final HashMap<String, NormalizationOperator> normalizationOperators = new HashMap<>();
|
||||
|
||||
final HashMap<String, AggregationOperator> aggregationOperators = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Normalization";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return "Se normalizan las valoraciones creando una matrix de decisión para cada experto.\n"
|
||||
+ "Normalizando por columnas esa matrix \n"
|
||||
+ "Y finalmente se agregan en una única matrix de decisión";
|
||||
}
|
||||
|
||||
public void init() {
|
||||
for( ProblemElement e : problemService.getSubElements(Expert.Type) ) {
|
||||
DecisionMatrix dm = ContextInjectionFactory.make(DecisionMatrix.class, context);
|
||||
HashMap<ProblemElementKey, Valuation> valuations = valuationService.getAllValuationsKVWith(e);
|
||||
dm.addContent(valuations);
|
||||
expertsMatrix.put((Expert) e, dm);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getNormalizationOperators() {
|
||||
|
||||
NormalizationOperator[] operators = operatorService.getNormalizationOperatorsFor(valuationService.getAll()[0]);
|
||||
ArrayList<String> operatorNames = new ArrayList<>();
|
||||
|
||||
for( NormalizationOperator op : operators ) {
|
||||
operatorNames.add(op.getName());
|
||||
normalizationOperators.put(op.getName(), op);
|
||||
}
|
||||
return operatorNames.stream().sorted().toArray( String[]::new );
|
||||
|
||||
}
|
||||
|
||||
public String[] getAggregationOperators() {
|
||||
|
||||
AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(valuationService.getAll()[0].getId(), checkWeightsExported());
|
||||
ArrayList<String> operatorNames = new ArrayList<>();
|
||||
|
||||
for( AggregationOperator op : operators ) {
|
||||
operatorNames.add(op.getName());
|
||||
aggregationOperators.put(op.getName(), op);
|
||||
}
|
||||
return operatorNames.stream().sorted().toArray( String[]::new );
|
||||
|
||||
}
|
||||
|
||||
private boolean checkWeightsExported() {
|
||||
try {
|
||||
this.importData(("criterionWeights"));
|
||||
return true;
|
||||
} catch(ImportedDataNotFoundException e) {}
|
||||
|
||||
try {
|
||||
this.importData(("expertWeights"));
|
||||
return true;
|
||||
} catch(ImportedDataNotFoundException e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public DecisionMatrix execute(String normalizationName, String aggregationName) {
|
||||
|
||||
if(normalizationName.equals("") || aggregationName.equals(""))
|
||||
return null;
|
||||
|
||||
HashMap<Expert, DecisionMatrix> normalizedDecisionMatrix = normalize(normalizationName);
|
||||
DecisionMatrix aggregatedDecisionMatrix = aggregate(aggregationName, normalizedDecisionMatrix);
|
||||
|
||||
this.exportData("decisionMatrix", aggregatedDecisionMatrix);
|
||||
|
||||
return aggregatedDecisionMatrix;
|
||||
}
|
||||
|
||||
private DecisionMatrix aggregate(String aggregationName, HashMap<Expert, DecisionMatrix> normalizedDecisionMatrix) {
|
||||
AggregationOperator operator = this.aggregationOperators.get(aggregationName);
|
||||
DecisionMatrix finalDM = (DecisionMatrix) normalizedDecisionMatrix.values().iterator().next().clone();
|
||||
|
||||
for( Alternative a : finalDM.getAlternatives() ) {
|
||||
for( Criterion c : finalDM.getCriterions() ) {
|
||||
ArrayList<Valuation> cellValuations = getEveryValuationFor(a, c, normalizedDecisionMatrix);
|
||||
Valuation aggValuation = operator.computeAggregation(cellValuations, null);
|
||||
finalDM.set(c, a, aggValuation);
|
||||
}
|
||||
|
||||
}
|
||||
return finalDM;
|
||||
}
|
||||
|
||||
public ArrayList<Valuation> getEveryValuationFor(Alternative a, Criterion c, HashMap<Expert, DecisionMatrix> normalizedDecisionMatrix) {
|
||||
|
||||
ArrayList<Valuation> valuations = new ArrayList<>();
|
||||
for( DecisionMatrix dm : normalizedDecisionMatrix.values() ) {
|
||||
valuations.add(dm.getColumn(c).get(a).getValuation());
|
||||
}
|
||||
return valuations;
|
||||
|
||||
}
|
||||
|
||||
private HashMap<Expert, DecisionMatrix> normalize(String normalizationName) {
|
||||
|
||||
String normalizationId = this.normalizationOperators.get(normalizationName).getId();
|
||||
|
||||
HashMap<Expert, DecisionMatrix> normalizedDecisionMatrix = new HashMap<>();
|
||||
|
||||
// Foreach decision matrix
|
||||
for( Entry<Expert, DecisionMatrix> entry : this.expertsMatrix.entrySet() ) {
|
||||
|
||||
Expert e = entry.getKey();
|
||||
final DecisionMatrix dm = entry.getValue();
|
||||
DecisionMatrix normDm = (DecisionMatrix) dm.clone();
|
||||
|
||||
// Grab each column and normalize it
|
||||
for( Criterion c : normDm.getCriterions() ) {
|
||||
TreeMap<ProblemElement, WValuation> column = normDm.getColumn(c);
|
||||
|
||||
WValuation[] beforeValuations = column.values().stream().toArray(WValuation[]::new);
|
||||
WValuation[] afterValuations = operatorService.normalize(normalizationId, Arrays.asList(beforeValuations));
|
||||
|
||||
Arrays.stream( afterValuations ).forEach( w -> normDm.set(w.getPEK().getCriterion(), w.getPEK().getAlternative(), w.getValuation()));
|
||||
|
||||
}
|
||||
|
||||
normalizedDecisionMatrix.put(e, normDm);
|
||||
}
|
||||
|
||||
return normalizedDecisionMatrix;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user