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.flowsort.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.flowsort.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>1779484362672</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,25 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Result
|
||||
Bundle-SymbolicName: flintstones.method.flowsort.phase.result;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.method.flowsort.phase.result
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: flintstones.entity.method.phase,
|
||||
flintstones.model.problemelement.service,
|
||||
flintstones.model.valuation.service,
|
||||
flintstones.entity.valuation,
|
||||
flintstones.entity.problemelement,
|
||||
flintstones.valuation.numeric,
|
||||
javax.inject,
|
||||
flintstones.valuation.numeric.real,
|
||||
flintstones.entity.ahpsort.profileassignment,
|
||||
flintstones.model.ahpsort.profileassignment.service,
|
||||
javax.annotation,
|
||||
flintstones.helper.data,
|
||||
flintstones.model.domain.service,
|
||||
org.apache.commons.lang,
|
||||
flintstones.helper.data,
|
||||
flintstones.model.domain.service,
|
||||
org.apache.commons.lang
|
||||
Export-Package: flintstones.method.flowsort.phase.result
|
||||
@@ -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.flowsort.phase.result"
|
||||
implementation="flintstones.method.flowsort.phase.result.FlowSortResult">
|
||||
</phase>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package flintstones.method.flowsort.phase.result;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import flintstones.entity.problemelement.entities.Alternative;
|
||||
|
||||
public class AlternativeFlow {
|
||||
|
||||
Alternative alternative;
|
||||
|
||||
double[] positiveFlows;
|
||||
double[] negativeFlows;
|
||||
|
||||
double positiveFlow;
|
||||
double negativeFlow;
|
||||
String classFlow;
|
||||
|
||||
public AlternativeFlow(Alternative a, String classFlow, Float[] positiveFlows, Float[] negativeFlows, float[] alternativeFlow) {
|
||||
|
||||
this.alternative = a;
|
||||
this.positiveFlows = Arrays.stream(positiveFlows).mapToDouble(Float::doubleValue).toArray();
|
||||
this.negativeFlows = Arrays.stream(negativeFlows).mapToDouble(Float::doubleValue).toArray();
|
||||
|
||||
positiveFlow = Arrays.stream(positiveFlows).mapToDouble(Float::doubleValue).sum();
|
||||
negativeFlow = Arrays.stream(negativeFlows).mapToDouble(Float::doubleValue).sum();
|
||||
positiveFlow = alternativeFlow[0];
|
||||
negativeFlow = alternativeFlow[1];
|
||||
this.classFlow = classFlow;
|
||||
}
|
||||
|
||||
public double getPositiveFlow() { return positiveFlow; }
|
||||
public double getNegativeFlow() { return negativeFlow; }
|
||||
public double getNeutralFlow() { return positiveFlow - negativeFlow; }
|
||||
public String getClassFlow() { return classFlow; }
|
||||
public double[] getPositiveFlows() { return positiveFlows; }
|
||||
public double[] getNegativeFlows() { return negativeFlows; }
|
||||
|
||||
public Alternative getAlternative() {return alternative;}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String a = alternative.getName() + " +"+positiveFlow+" -"+negativeFlow+" ="+getNeutralFlow();
|
||||
String b = Arrays.toString(positiveFlows);
|
||||
String c = Arrays.toString(negativeFlows);
|
||||
|
||||
sb.append(a).append("\n").append(b).append("\n").append(c);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
package flintstones.method.flowsort.phase.result;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
import flintstones.entity.problemelement.entities.SortingClass;
|
||||
import flintstones.entity.problemelement.entities.SortingProfile;
|
||||
import flintstones.entity.ahpsort.profileassignment.ProfileAssignment;
|
||||
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.ProblemElementHelper;
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.data.HashMatrix;
|
||||
import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService;
|
||||
import flintstones.model.domain.service.IDomainService;
|
||||
import flintstones.model.problemelement.service.IProblemElementService;
|
||||
import flintstones.model.valuation.service.IValuationService;
|
||||
import flintstones.valuation.numeric.real.RealValuation;
|
||||
|
||||
public class FlowSortResult extends PhaseMethod {
|
||||
|
||||
@Inject
|
||||
IProblemElementService problemService;
|
||||
|
||||
@Inject
|
||||
IValuationService valuationService;
|
||||
|
||||
@Inject
|
||||
IProfileAssignmentService assignmentService;
|
||||
|
||||
@Inject
|
||||
IDomainService domainService;
|
||||
|
||||
// Atributos
|
||||
HashMap<ProblemElementKey, Valuation> mapVAluations;
|
||||
Alternative[] alternatives;
|
||||
Criterion[] criterions;
|
||||
Expert[] experts;
|
||||
String[] rowHeaderFlowSortResult;
|
||||
|
||||
Flowsort flowsort;
|
||||
float[] weights;
|
||||
// float[][] vaslues;
|
||||
int[] MinMax;
|
||||
|
||||
public FlowSortResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Phase FlowSort Result";
|
||||
}
|
||||
|
||||
//------------------------------- GETS AND SETTERS ---------------------------------
|
||||
public void cargarDatos() {
|
||||
rowHeaderFlowSortResult = new String[3];
|
||||
rowHeaderFlowSortResult[0] = "Positive Flow";
|
||||
rowHeaderFlowSortResult[1] = "Negative Flow";
|
||||
rowHeaderFlowSortResult[2] = "Neto Flow";
|
||||
|
||||
alternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type));
|
||||
criterions = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type));
|
||||
experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type));
|
||||
|
||||
// AHPSortIIDomain domain = (AHPSortIIDomain) domainService.getAll()[0];
|
||||
int classNumber = getClasses().length;
|
||||
int profileNumber = assignmentService.get(experts[0], criterions[0]).getAllProfiles().size();
|
||||
|
||||
boolean isCentralProfile = classNumber == profileNumber;
|
||||
flowsort = new Flowsort(alternatives, criterions, getClasses(), isCentralProfile );
|
||||
|
||||
float[] p = (float[]) this.importData("arrayP");
|
||||
float[] q = (float[]) this.importData("arrayQ");
|
||||
float[] s = (float[]) this.importData("arrayS");
|
||||
float[] w = (float[]) this.importData("arrayWeights");
|
||||
int[] MinMax = (int[]) this.importData("arrayMinMax");
|
||||
int[] typeFunc = (int[]) this.importData("arrayTypeFunc");
|
||||
|
||||
this.flowsort.Execute(getValuations(experts[0]), loadLimitMatrix(), w, MinMax, typeFunc, p, q, s);
|
||||
|
||||
exportData("flowsort",flowsort, true);
|
||||
|
||||
}
|
||||
|
||||
private HashMatrix<Criterion, Integer, Float> loadLimitMatrix(){
|
||||
HashMap<Criterion, ProfileAssignment> hm = assignmentService.get(experts[0]);
|
||||
|
||||
// float[][] limitMatrix = new float[allCriterion.length][hm.get(allCriterion[0]).getAllProfiles().size()];
|
||||
HashMatrix<Criterion, Integer, Float> limitMatrix = new HashMatrix<>();
|
||||
|
||||
// int i = 0;
|
||||
int j = 0;
|
||||
for(Criterion crit: criterions) {
|
||||
ProfileAssignment pa = hm.get(crit);
|
||||
|
||||
for(SortingProfile profile :pa.getAllProfiles()) {
|
||||
Float value = (float) profile.getValue();
|
||||
limitMatrix.put(crit, j, value);
|
||||
// limitMatrix[i][j] = (float) profile.getValue();
|
||||
j++;
|
||||
}
|
||||
// i++;
|
||||
j = 0;
|
||||
}
|
||||
|
||||
return limitMatrix;
|
||||
}
|
||||
|
||||
public HashMatrix<Alternative, Criterion, Float> getValuations(Expert e) {
|
||||
|
||||
HashMatrix<Alternative, Criterion, Float> initMatrix = new HashMatrix<>();
|
||||
|
||||
for(Alternative a : alternatives) {
|
||||
for(Criterion c : criterions) {
|
||||
ProblemElementKey pek = new ProblemElementKey(e, a, c);
|
||||
RealValuation v = (RealValuation) valuationService.getValuationFor(pek);
|
||||
Float val = (float) v.getValue();
|
||||
|
||||
initMatrix.put(a, c, val );
|
||||
|
||||
}
|
||||
}
|
||||
return initMatrix;
|
||||
}
|
||||
|
||||
public SortingClass[] getClasses() {
|
||||
|
||||
SortingClass[] classes = Arrays //
|
||||
.stream(problemService.getAll(SortingClass.Type)) //
|
||||
.map(k -> (SortingClass)k).toArray(SortingClass[]::new);
|
||||
|
||||
ArrayUtils.reverse(classes);
|
||||
return classes;
|
||||
}
|
||||
|
||||
public float[] getValueAlternative(Alternative alternative) {
|
||||
return flowsort.getValueAlternative(alternative);
|
||||
}
|
||||
|
||||
public Float[] getMatrixFlowPositive(Alternative alternative){
|
||||
return flowsort.getMatrixFlowPositive(alternative);
|
||||
}
|
||||
|
||||
public Float[] getMatrixFlowNegative(Alternative alternative){
|
||||
return flowsort.getMatrixFlowNegative(alternative);
|
||||
}
|
||||
|
||||
|
||||
public String[] getRowHeaderFlowSort() {
|
||||
return rowHeaderFlowSortResult;
|
||||
}
|
||||
|
||||
public Alternative[] getAlternatives() {
|
||||
return alternatives;
|
||||
}
|
||||
|
||||
public String[] getAlternativesNames() {
|
||||
String[] str = new String[alternatives.length];
|
||||
|
||||
for(int i = 0; i < alternatives.length; i++)
|
||||
str[i] = alternatives[i].getName();
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public String[] getCriterionNames() {
|
||||
String[] str = new String[criterions.length];
|
||||
|
||||
for(int i = 0; i < criterions.length; i++) {
|
||||
str[i] = criterions[i].getName();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public int numberCriterions() {
|
||||
return criterions.length;
|
||||
}
|
||||
}
|
||||
|
||||
+375
@@ -0,0 +1,375 @@
|
||||
package flintstones.method.flowsort.phase.result;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import flintstones.entity.problemelement.entities.SortingClass;
|
||||
import flintstones.entity.problemelement.entities.Alternative;
|
||||
import flintstones.entity.problemelement.entities.Criterion;
|
||||
import flintstones.helper.data.HashMatrix;
|
||||
|
||||
public class Flowsort {
|
||||
|
||||
//----------------- DATOS INICIALES DEL PROBLEMA ----------------------
|
||||
HashMatrix<Alternative, Criterion, Float> initMatrix;
|
||||
HashMatrix<Criterion, Integer, Float> limitMatrix;
|
||||
int[] MinMax; //0 --> Min || 1 --> Max
|
||||
float[] weights;
|
||||
int[] typeFunc;
|
||||
|
||||
Alternative[] alternatives;
|
||||
Criterion[] criterions;
|
||||
SortingClass[] classFlow;
|
||||
|
||||
boolean isCentralClass = false;
|
||||
|
||||
float[] p;
|
||||
float[] q;
|
||||
float[] s;
|
||||
|
||||
//--------------------- VARIABLES INTERNAS ----------------------------
|
||||
HashMatrix<Alternative, Integer, Float[][]> preferencesDegreesPositive;
|
||||
HashMatrix<Alternative, Integer, Float[][]> preferencesDegreesNegative;
|
||||
|
||||
HashMap<Alternative, Float[]> flowMatrixPositive;
|
||||
HashMap<Alternative, Float[]> flowMatrixNegative;
|
||||
|
||||
float[][] globalFlowMatrix;
|
||||
|
||||
// CACHE
|
||||
HashMap<Alternative, AlternativeFlow> alternativeFlows = new HashMap<>();
|
||||
|
||||
public Flowsort(Alternative[] alternatives, Criterion[] criterions, SortingClass[] classFlow, boolean isCentralClass) {
|
||||
this.alternatives = alternatives;
|
||||
this.criterions = criterions;
|
||||
this.classFlow = classFlow;
|
||||
this.isCentralClass = isCentralClass;
|
||||
}
|
||||
|
||||
public Float[] getMatrixFlowPositive(Alternative indexCriterion){
|
||||
return flowMatrixPositive.get(indexCriterion);
|
||||
}
|
||||
|
||||
public Float[] getMatrixFlowNegative(Alternative indexCriterion){
|
||||
return flowMatrixNegative.get(indexCriterion);
|
||||
}
|
||||
|
||||
public float[] getValueAlternative(Alternative index) {
|
||||
float[] value = new float[2];
|
||||
value[0] = 0.0f;
|
||||
value[1] = 0.0f;
|
||||
|
||||
float positive = 0.0f;
|
||||
float negative = 0.0f;
|
||||
|
||||
for(int r = 0; r < preferencesDegreesPositive.get(index).size(); r++) {
|
||||
|
||||
for(int i = 0; i < preferencesDegreesPositive.get(index).get(r).length; i++) {
|
||||
|
||||
positive += preferencesDegreesPositive.get(index).get(r)[i][0];
|
||||
negative += preferencesDegreesNegative.get(index).get(r)[i][0];
|
||||
}
|
||||
|
||||
value[1] += negative / preferencesDegreesPositive.get(index).size();
|
||||
value[0] += positive / preferencesDegreesNegative.get(index).size();
|
||||
|
||||
positive = 0.0f;
|
||||
negative = 0.0f;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//Classify values
|
||||
public String getClassFlow(Alternative alt, double positive, double negative) {
|
||||
int indexPositive = -1, indexNegative = -1, indexNeutral = -1;
|
||||
Float[] flowPositive = flowMatrixPositive.get(alt);
|
||||
Float[] flowNegative = flowMatrixNegative.get(alt);
|
||||
|
||||
if(isCentralClass) {
|
||||
//Flow positive
|
||||
for(int i = 1; i < flowPositive.length - 1; i++) {
|
||||
if(((flowPositive[i] + flowPositive[i + 1] / 2)) < positive
|
||||
&& positive <= ((flowPositive[i] + flowPositive[i - 1] / 2))) {
|
||||
indexPositive = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Flow negative
|
||||
for(int i = 1; i < flowNegative.length - 1; i++) {
|
||||
if(((flowNegative[i] + flowNegative[i + 1] / 2)) >= positive
|
||||
&& positive > ((flowNegative[i] + flowNegative[i - 1] / 2))) {
|
||||
indexNegative = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(indexPositive == -1) indexPositive = flowPositive.length - 1;
|
||||
if(indexNegative == -1) indexNegative = flowNegative.length - 1;
|
||||
|
||||
}else {
|
||||
//Flow positive
|
||||
for(int i = 0; i < flowPositive.length - 1; i++) {
|
||||
if(flowPositive[i] >= positive && positive > flowPositive[i + 1]) {
|
||||
indexPositive = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Flow negative
|
||||
for(int i = 0; i < flowNegative.length - 1; i++) {
|
||||
if(flowNegative[i] < positive && positive <= flowNegative[i + 1]) {
|
||||
indexNegative = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(indexPositive == -1) indexPositive = flowPositive.length - 1;
|
||||
if(indexNegative == -1) indexNegative = flowNegative.length - 1;
|
||||
|
||||
}
|
||||
|
||||
//We use the neutral values.
|
||||
if(indexPositive != indexNegative) {
|
||||
|
||||
double neutral = positive - negative;
|
||||
for(int i = 0; i < flowNegative.length - 1; i++) {
|
||||
if((flowPositive[i] - flowNegative[i]) >= neutral && neutral > (flowPositive[i + 1] - flowNegative[i + 1])) {
|
||||
indexNeutral = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(indexNeutral == -1) indexNeutral = flowPositive.length - 1;
|
||||
|
||||
return classFlow[(classFlow.length - 1) - indexNeutral].getName();
|
||||
}
|
||||
|
||||
//Return the class.
|
||||
return classFlow[(classFlow.length - 1) - indexPositive].getName();
|
||||
}
|
||||
|
||||
public float[][] getGlobalFLow(){
|
||||
return globalFlowMatrix;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
preferencesDegreesPositive = new HashMatrix<>();
|
||||
preferencesDegreesNegative = new HashMatrix<>();
|
||||
|
||||
flowMatrixPositive = new HashMap<>();
|
||||
flowMatrixNegative = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < alternatives.length; i++) {
|
||||
|
||||
Alternative alternative = alternatives[i];
|
||||
int size = limitMatrix.size();
|
||||
int innerSize = limitMatrix.innerSize();
|
||||
|
||||
flowMatrixPositive.put(alternative, new Float[innerSize] );
|
||||
flowMatrixNegative.put(alternative, new Float[innerSize] );
|
||||
|
||||
//Inicializamos el vector de matrices para cada criterio enfrentando alternativas con alternativas.
|
||||
for (int j = 0; j < innerSize; j++) {
|
||||
preferencesDegreesPositive.put(alternative, j, new Float[size][innerSize]);
|
||||
preferencesDegreesNegative.put(alternative, j, new Float[size][innerSize]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(
|
||||
HashMatrix<Alternative, Criterion, Float> initMatrix, // Valuations
|
||||
HashMatrix<Criterion, Integer, Float> limitMatrix, // ??
|
||||
float[] weights,
|
||||
int[] MinMax,
|
||||
int[] typeFunc, float[] p, float[] q, float[] s) {
|
||||
this.typeFunc = typeFunc;
|
||||
this.initMatrix = initMatrix;
|
||||
this.limitMatrix = limitMatrix;
|
||||
this.weights = weights;
|
||||
this.MinMax = MinMax;
|
||||
|
||||
init();
|
||||
//Iniciamos los valores
|
||||
this.p = p;
|
||||
this.q = q;
|
||||
this.s = s;
|
||||
|
||||
//Calculamos las matrices.
|
||||
calculatePreferencesPositive();
|
||||
|
||||
/*
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
for (int R = 0; R < preferencesDegreesPositive.size(); R++) {
|
||||
Alternative aR = alternatives[R];
|
||||
for (int iCriterion = 0; iCriterion < preferencesDegreesPositive.get(aR).size(); iCriterion++) {
|
||||
System.out.println();
|
||||
System.out.println("---------------------- R " + (iCriterion + 1) + "------------------------");
|
||||
for (int iAlternative = 0; iAlternative < preferencesDegreesPositive.get(aR).get(iCriterion).length; iAlternative++) {
|
||||
for (int jAlternative = 0; jAlternative < preferencesDegreesPositive.get(aR).get(iCriterion)[iAlternative].length; jAlternative++) {
|
||||
System.out.print(preferencesDegreesPositive.get(aR).get(iCriterion)[iAlternative][jAlternative] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("----------------------------------------------");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
System.out.println("---------------------- R Flows Positive------------------------");
|
||||
for (int i = 0; i < flowMatrixPositive.size(); i++) {
|
||||
Alternative ai = alternatives[i];
|
||||
|
||||
for (int j = 0; j < flowMatrixPositive.get(ai).length; j++) {
|
||||
System.out.print(flowMatrixPositive.get(ai)[j] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("----------------------------------------------");
|
||||
System.out.println();
|
||||
|
||||
System.out.println();
|
||||
System.out.println("---------------------- R Flows Negative------------------------");
|
||||
for (int i = 0; i < flowMatrixNegative.size(); i++) {
|
||||
Alternative ai = alternatives[i];
|
||||
|
||||
for (int j = 0; j < flowMatrixNegative.get(ai).length; j++) {
|
||||
System.out.print(flowMatrixNegative.get(ai)[j] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("----------------------------------------------");
|
||||
System.out.println();
|
||||
*/
|
||||
|
||||
|
||||
// CACHE
|
||||
alternativeFlows.clear();
|
||||
for (int i = 0; i < flowMatrixNegative.size(); i++) {
|
||||
Alternative ai = alternatives[i];
|
||||
String flowClass = getClassFlow(ai, getValueAlternative(ai)[0], getValueAlternative(ai)[1]);
|
||||
AlternativeFlow aflow = new AlternativeFlow(ai, flowClass, flowMatrixPositive.get(ai), flowMatrixNegative.get(ai), getValueAlternative(ai));
|
||||
alternativeFlows.put(ai, aflow);
|
||||
}
|
||||
}
|
||||
|
||||
public AlternativeFlow getFlow(Alternative a) {return alternativeFlows.get(a);}
|
||||
public HashMap<Alternative,AlternativeFlow> getFlows(){return alternativeFlows;}
|
||||
|
||||
//Calcula las matrices de preferencia según la función especificada.
|
||||
private void calculatePreferencesPositive() {
|
||||
float dPositive = 0.0f;
|
||||
float dNegative = 0.0f;
|
||||
int indexri = 0;
|
||||
int indexJ = 0;
|
||||
float colFlowPositive = 0.0f;
|
||||
float rowFlowPositive = 0.0f;
|
||||
float colFlowNegative = 0.0f;
|
||||
float rowFlowNegative = 0.0f;
|
||||
|
||||
for (int R = 0; R < preferencesDegreesPositive.size(); R++) {
|
||||
Alternative aR = alternatives[R];
|
||||
|
||||
System.out.println("R "+ R);
|
||||
//Nos recorremos los criteros para calcular cada matriz
|
||||
for (int r = 0; r < preferencesDegreesPositive.get(aR).size(); r++) {
|
||||
|
||||
System.out.println("r " + r);
|
||||
if(r == 5) {
|
||||
System.out.println("r " + r);
|
||||
}
|
||||
//Enfrentamos las alternativas según el criterio (iCriterion) que estamos calculando.
|
||||
for (int i = 0; i < preferencesDegreesPositive.get(aR).get(r).length; i++) {
|
||||
Criterion ci = criterions[i];
|
||||
|
||||
for (int j = 0; j < preferencesDegreesPositive.get(aR).get(r)[i].length; j++) {
|
||||
|
||||
if (j == 0) {
|
||||
dPositive = limitMatrix.get(ci, r) - initMatrix.get(aR,ci);
|
||||
dNegative = initMatrix.get(aR,ci) - limitMatrix.get(ci, r);
|
||||
|
||||
} else {
|
||||
if (indexri == indexJ) {
|
||||
indexJ++;
|
||||
}
|
||||
|
||||
dPositive = limitMatrix.get(ci,r) - limitMatrix.get(ci, indexJ);
|
||||
dNegative = limitMatrix.get(ci, indexJ) - limitMatrix.get(ci,r);
|
||||
|
||||
indexJ++;
|
||||
}
|
||||
|
||||
//preferencesDegreesPositive.get(R).get(r)[i][j] = getResultFunction(dPositive, i);
|
||||
//preferencesDegreesNegative.get(R).get(r)[i][j] = getResultFunction(dNegative, i);
|
||||
preferencesDegreesPositive.get(aR).get(r)[i][j] = getResultFunction(dPositive, i) * weights[i]; //Equation: 1.a
|
||||
preferencesDegreesNegative.get(aR).get(r)[i][j] = getResultFunction(dNegative, i) * weights[i]; //Equation: 1.b
|
||||
colFlowPositive += preferencesDegreesPositive.get(aR).get(r)[i][j];
|
||||
colFlowNegative += preferencesDegreesNegative.get(aR).get(r)[i][j];
|
||||
|
||||
}
|
||||
indexJ = 0;
|
||||
rowFlowPositive += colFlowPositive / preferencesDegreesPositive.get(aR).size();
|
||||
rowFlowNegative += colFlowNegative / preferencesDegreesNegative.get(aR).size();
|
||||
//rowFlowPositive += colFlowPositive;
|
||||
//rowFlowNegative += colFlowNegative;
|
||||
colFlowPositive = 0.0f;
|
||||
colFlowNegative = 0.0f;
|
||||
}
|
||||
indexri++;
|
||||
|
||||
// flowMatrixPositive.get(aR)[r] = rowFlowPositive / preferencesDegreesPositive.get(aR).size(); //Equation: 2
|
||||
// flowMatrixNegative.get(aR)[r] = rowFlowNegative / preferencesDegreesNegative.get(aR).size(); //Equation: 3
|
||||
flowMatrixPositive.get(aR)[r] = rowFlowPositive; //Equation: 2
|
||||
flowMatrixNegative.get(aR)[r] = rowFlowNegative; //Equation: 3
|
||||
rowFlowPositive = 0.0f;
|
||||
rowFlowNegative = 0.0f;
|
||||
}
|
||||
indexri = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Según la función especificada, te devuelve el valor P(d) correspondiente
|
||||
private float getResultFunction(float d, int iCriterion) {
|
||||
switch (typeFunc[iCriterion]) {
|
||||
case 1:
|
||||
if(d > 0 ) return 1;
|
||||
else return 0;
|
||||
case 2:
|
||||
if(d > q[iCriterion] ) return 1;
|
||||
else return 0;
|
||||
case 3:
|
||||
if(d > p[iCriterion] ) return 1;
|
||||
else if (d <= 0) return 0;
|
||||
else return d / p[iCriterion];
|
||||
case 4:
|
||||
if(d > p[iCriterion] ) return 1;
|
||||
else if (d <= q[iCriterion]) return 0;
|
||||
else return 1/2;
|
||||
case 5:
|
||||
if (d <= q[iCriterion]) {
|
||||
return 0.0f;
|
||||
} else if (d > p[iCriterion]) {
|
||||
return 1.0f;
|
||||
} else {
|
||||
return ((d - q[iCriterion]) / (p[iCriterion] - q[iCriterion]));
|
||||
}
|
||||
case 6:
|
||||
if(d <= 0 ) return 0;
|
||||
else {
|
||||
float exponentialFunc = (float) java.lang.Math.exp((-1) * (Math.pow(d, 2) / (2 * Math.pow(s[iCriterion], 2))));
|
||||
return 1 - exponentialFunc;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user