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-11"/>
|
||||
<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.vikor.phase.result</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Result</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.method.vikor.phase.result</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>1779484362707</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,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
||||
@@ -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.method.vikor.phase.result;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.method.vikor.phase.result
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Require-Bundle: org.eclipse.e4.core.contexts,
|
||||
javax.inject,
|
||||
flintstones.model.valuation.service,
|
||||
flintstones.model.problemelement.service,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.model.domain.service,
|
||||
flintstones.entity.method.phase,
|
||||
flintstones.helper.data,
|
||||
flintstones.operator,
|
||||
flintstones.valuation.numeric,
|
||||
flintstones.valuation.linguistic,
|
||||
flintstones.model.domain.provider,
|
||||
flintstones.entity.valuation
|
||||
Export-Package: flintstones.method.vikor.phase.result
|
||||
@@ -0,0 +1,2 @@
|
||||
#Properties file for flintstones.method.vikor.phase.result
|
||||
Bundle-Name = Result
|
||||
@@ -0,0 +1,7 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml,\
|
||||
OSGI-INF/l10n/bundle.properties,\
|
||||
OSGI-INF/
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="flintstones.phasemethod.extensionpoint">
|
||||
<phase
|
||||
implementation="flintstones.method.vikor.phase.result.VikorResult"
|
||||
uid="flintstones.method.vikor.phase.result">
|
||||
</phase>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+413
@@ -0,0 +1,413 @@
|
||||
package flintstones.method.vikor.phase.result;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import flintstones.entity.method.phase.PhaseMethod;
|
||||
import flintstones.entity.problemelement.entities.Alternative;
|
||||
import flintstones.entity.problemelement.entities.Criterion;
|
||||
import flintstones.entity.problemelement.entities.ProblemElement;
|
||||
import flintstones.entity.problemelement.entities.ProblemElementHelper;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.data.HashMatrix;
|
||||
import flintstones.model.domain.service.IDomainService;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
import flintstones.operator.service.IOperatorService;
|
||||
import flintstones.valuation.numeric.NumericValuation;
|
||||
|
||||
/**
|
||||
* Fase de resultados para el metodo VIKOR
|
||||
*/
|
||||
public class VikorResult extends PhaseMethod {
|
||||
@Inject
|
||||
IProblemElementService problemService;
|
||||
|
||||
@Inject
|
||||
IOperatorService operatorService;
|
||||
|
||||
@Inject
|
||||
IValuationService valuationService;
|
||||
|
||||
@Inject
|
||||
IDomainService domainService;
|
||||
|
||||
/**
|
||||
* @param <K> Clave del par
|
||||
* @param <V> Valor del par usada para comparar
|
||||
*/
|
||||
public class Pair<K, V extends Comparable<V>> implements Comparable<Pair<K, V>> {
|
||||
public K key;
|
||||
public V value;
|
||||
|
||||
public Pair(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Pair<K, V> o) {
|
||||
return value.compareTo((V) o.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Valor Q del problema
|
||||
*/
|
||||
public double q = 0.5;
|
||||
|
||||
/**
|
||||
* Tipo de ranking para la solucion
|
||||
*/
|
||||
public char tipo = 'Q';
|
||||
|
||||
/**
|
||||
* Todas las alternativas en el problema
|
||||
*/
|
||||
Alternative[] allAlternatives;
|
||||
|
||||
/**
|
||||
* Todos los criterios en el problema
|
||||
*/
|
||||
Criterion[] allCriterion;
|
||||
|
||||
/**
|
||||
* Valoraciones agregadas de cada alternativa y criterio
|
||||
*/
|
||||
HashMatrix<Alternative, Criterion, Valuation> matriz;
|
||||
|
||||
/**
|
||||
* Pesos de cada criterio agregados
|
||||
*/
|
||||
HashMap<ProblemElement, Double> aggregatedWeights;
|
||||
|
||||
/**
|
||||
* Mejores y peores valoraciones de cada criterio
|
||||
*/
|
||||
double[] bestValuation, worstValuation;
|
||||
|
||||
// Variables empleadas en el procedimiento del metodo
|
||||
NumericValuation[][] matrizFase1;
|
||||
double[] Si, Ri, Qi;
|
||||
double minS = Double.MAX_VALUE, minR = Double.MAX_VALUE, maxS = Double.MIN_VALUE, maxR = Double.MIN_VALUE;
|
||||
double DQ;
|
||||
|
||||
/**
|
||||
* Ranking de cada alternativa basada en su valor Qi
|
||||
*/
|
||||
ArrayList<Pair<Integer, Double>> rankingQ;
|
||||
|
||||
/**
|
||||
* Ranking de cada alternativa basada en su valor Si
|
||||
*/
|
||||
ArrayList<Pair<Integer, Double>> rankingS;
|
||||
|
||||
/**
|
||||
* Ranking de cada alternativa basada en su valor Ri
|
||||
*/
|
||||
ArrayList<Pair<Integer, Double>> rankingR;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "VIKOR result";
|
||||
}
|
||||
|
||||
/**
|
||||
* Carga los datos del problema y de la fase anterior
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void LoadData() {
|
||||
|
||||
allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type));
|
||||
allCriterion = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type));
|
||||
|
||||
aggregatedWeights = (HashMap<ProblemElement, Double>) importData("criterionWeights");
|
||||
matriz = (HashMatrix<Alternative, Criterion, Valuation>) importData("decisionmatrix");
|
||||
|
||||
|
||||
matrizFase1 = new NumericValuation[allAlternatives.length][allCriterion.length];
|
||||
|
||||
bestValuation = new double[allCriterion.length];
|
||||
worstValuation = new double[allCriterion.length];
|
||||
|
||||
Si = new double[allAlternatives.length];
|
||||
Ri = new double[allAlternatives.length];
|
||||
Qi = new double[allAlternatives.length];
|
||||
rankingQ = new ArrayList<>();
|
||||
rankingS = new ArrayList<>();
|
||||
rankingR = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Aplica las diferentes fases del metodo
|
||||
*
|
||||
* @return Indice de la ultima alternativa del ranking que forma parte de la
|
||||
* solucion
|
||||
*/
|
||||
public int calcular() {
|
||||
rankingQ.clear();
|
||||
rankingR.clear();
|
||||
rankingS.clear();
|
||||
if (calculoFase1() == -1) {
|
||||
return -2;
|
||||
}
|
||||
calculoFase2();
|
||||
return calculoFinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Primera fase del metodo. Calcula mejores y peores valoraciones, y los valores
|
||||
* Si y Ri de cada alternativa
|
||||
*/
|
||||
private int calculoFase1() {
|
||||
|
||||
// Calculo de los mejores y los peores
|
||||
for (int c = 0; c < matrizFase1[0].length; c++) {
|
||||
if (!allCriterion[c].isCost()) {
|
||||
bestValuation[c] = Double.MIN_VALUE;
|
||||
worstValuation[c] = Double.MAX_VALUE;
|
||||
} else {
|
||||
bestValuation[c] = Double.MAX_VALUE;
|
||||
worstValuation[c] = Double.MIN_VALUE;
|
||||
}
|
||||
for (int a = 0; a < matrizFase1.length; a++) {
|
||||
if (!allCriterion[c].isCost()) {// Maximizar
|
||||
double tempVal = ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue();
|
||||
if (bestValuation[c] < tempVal) {
|
||||
bestValuation[c] = tempVal;
|
||||
}
|
||||
if (worstValuation[c] > tempVal) {
|
||||
worstValuation[c] = tempVal;
|
||||
}
|
||||
} else {// Minimizar
|
||||
double tempVal = ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue();
|
||||
if (bestValuation[c] > tempVal) {
|
||||
bestValuation[c] = tempVal;
|
||||
}
|
||||
if (worstValuation[c] < tempVal) {
|
||||
worstValuation[c] = tempVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Para cada alternativa
|
||||
for (int a = 0; a < matrizFase1.length; a++) {
|
||||
Si[a] = 0;
|
||||
Ri[a] = Double.MIN_VALUE;
|
||||
// Para cada criterio
|
||||
for (int c = 0; c < matrizFase1[0].length; c++) {
|
||||
matrizFase1[a][c] = (NumericValuation) matriz.get(allAlternatives[a], allCriterion[c]).clone();
|
||||
double temp = ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue();
|
||||
double t1 = bestValuation[c] - temp;
|
||||
double t2 = bestValuation[c] - worstValuation[c];
|
||||
|
||||
temp = t1 / t2;
|
||||
if (t2 == 0)
|
||||
return -1;
|
||||
temp *= aggregatedWeights.get(allCriterion[c]);
|
||||
|
||||
// Calcula el valor y se guarda en las estructuras correspondientes
|
||||
matrizFase1[a][c].setValue(temp);
|
||||
Si[a] += temp;
|
||||
if (temp > Ri[a]) {
|
||||
Ri[a] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Segunda fase del metodo. Calcula valores Qi y rankings
|
||||
*/
|
||||
private void calculoFase2() {
|
||||
|
||||
// Obtiene los mejores y peores valores Si y Ri
|
||||
for (int i = 0; i < allAlternatives.length; i++) {
|
||||
if (Si[i] < minS) {
|
||||
minS = Si[i];
|
||||
}
|
||||
if (Si[i] > maxS) {
|
||||
maxS = Si[i];
|
||||
}
|
||||
if (Ri[i] < minR) {
|
||||
minR = Ri[i];
|
||||
}
|
||||
if (Ri[i] > maxR) {
|
||||
maxR = Ri[i];
|
||||
}
|
||||
}
|
||||
|
||||
// A�ade cada alternativa a su ranking
|
||||
for (int i = 0; i < allAlternatives.length; i++) {
|
||||
double temp1 = this.q * ((Si[i] - minS) / (maxS - minS));
|
||||
double temp2 = (1 - this.q) * ((Ri[i] - minR) / (maxR - minR));
|
||||
Qi[i] = temp1 + temp2;
|
||||
|
||||
rankingQ.add(new Pair<Integer, Double>(i, Qi[i]));
|
||||
rankingR.add(new Pair<Integer, Double>(i, Ri[i]));
|
||||
rankingS.add(new Pair<Integer, Double>(i, Si[i]));
|
||||
|
||||
}
|
||||
// Ordena los rankings de menor a mayor valor
|
||||
Collections.sort(rankingQ);
|
||||
Collections.sort(rankingR);
|
||||
Collections.sort(rankingS);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculo final. Obtiene el indice de la ultima alternativa que forma parte de
|
||||
* la solucion
|
||||
*
|
||||
* @return Indice de la alternativa
|
||||
*/
|
||||
private int calculoFinal() {
|
||||
List<Pair<Integer, Double>> ranking;
|
||||
switch (tipo) {
|
||||
case 'S':
|
||||
ranking = rankingS;
|
||||
break;
|
||||
case 'R':
|
||||
ranking = rankingR;
|
||||
break;
|
||||
default:
|
||||
ranking = rankingQ;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ranking.get(0).value < 0) {
|
||||
return -1;
|
||||
}
|
||||
DQ = (1.0 / ((double) allAlternatives.length - 1.0));
|
||||
// C1: Si la alternativa de mejor rango tiene ventaja aceptable
|
||||
if ((ranking.get(1).value - ranking.get(0).value) >= DQ) {
|
||||
// C2: Si esa alternativa tiene estabilidad aceptable
|
||||
if (minS == Si[ranking.get(0).key] || minR == Ri[ranking.get(0).key]) {
|
||||
// A1 es la solucion
|
||||
return 0;
|
||||
} else {
|
||||
// A1 y A2 es la solucion
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Si C1 no se cumple, comprueba las siguientes alternativas
|
||||
int i = 1;
|
||||
while (i < ranking.size()) {
|
||||
// La alternativa que no entre en la solucion sera aquella que no tiene ventaja
|
||||
// aceptable
|
||||
if ((ranking.get(i).value - ranking.get(0).value) >= DQ) {
|
||||
return i - 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
public ArrayList<Pair<Integer, Double>> getRankingQ() {
|
||||
return rankingQ;
|
||||
}
|
||||
|
||||
public ArrayList<Pair<Integer, Double>> getRankingR() {
|
||||
return rankingR;
|
||||
}
|
||||
|
||||
public ArrayList<Pair<Integer, Double>> getRankingS() {
|
||||
return rankingS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ranking seleccionado para el calculo de la solucion
|
||||
*/
|
||||
public ArrayList<Pair<Integer, Double>> getRankingSeleccionado() {
|
||||
if (tipo == 'Q') {
|
||||
return rankingQ;
|
||||
} else if (tipo == 'S') {
|
||||
return rankingS;
|
||||
} else {
|
||||
return rankingR;
|
||||
}
|
||||
}
|
||||
|
||||
public Alternative[] getAlternatives() {
|
||||
return allAlternatives;
|
||||
};
|
||||
|
||||
public double getValuation(int a, int c) {
|
||||
return ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue();
|
||||
}
|
||||
|
||||
public Criterion[] getCriterions() {
|
||||
return allCriterion;
|
||||
}
|
||||
|
||||
public double[] getBestValuations() {
|
||||
return bestValuation;
|
||||
}
|
||||
|
||||
public double[] getWorstValuations() {
|
||||
return worstValuation;
|
||||
}
|
||||
|
||||
public double getValueMatrizFase1(int a, int c) {
|
||||
try {
|
||||
return matrizFase1[a][c].getValue();
|
||||
} catch (NullPointerException e) {
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
public double[] getSValues() {
|
||||
return Si;
|
||||
}
|
||||
|
||||
public double[] getRValues() {
|
||||
return Ri;
|
||||
}
|
||||
|
||||
public double[] getQValues() {
|
||||
return Qi;
|
||||
}
|
||||
|
||||
public double getDQ() {
|
||||
return DQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ranking Q como array de enteros
|
||||
*/
|
||||
public int[] getRankQArray() {
|
||||
int[] temp = new int[rankingQ.size()];
|
||||
for (int i = 0; i < rankingQ.size(); i++) {
|
||||
temp[i] = rankingQ.get(i).key;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ranking S como array de enteros
|
||||
*/
|
||||
public int[] getRankSArray() {
|
||||
int[] temp = new int[rankingS.size()];
|
||||
for (int i = 0; i < rankingS.size(); i++) {
|
||||
temp[i] = rankingS.get(i).key;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ranking R como array de enteros
|
||||
*/
|
||||
public int[] getRankRArray() {
|
||||
int[] temp = new int[rankingR.size()];
|
||||
for (int i = 0; i < rankingR.size(); i++) {
|
||||
temp[i] = rankingR.get(i).key;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user