public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -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.ahp.decisionmatrix</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Decision Matrix</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.entity.ahp.decisionmatrix</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>1779484362554</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,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Decision Matrix
Bundle-SymbolicName: flintstones.entity.ahp.decisionmatrix
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.decisionmatrix
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.entity.valuation,
flintstones.entity.problemelement,
flintstones.valuation.numeric,
flintstones.helper.data,
flintstones.entity.wvaluation
Export-Package: flintstones.entity.ahp.decisionmatrix
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,263 @@
package flintstones.entity.ahp.decisionmatrix;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
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.helper.MatrixHelper;
import flintstones.valuation.numeric.NumericValuation;
/**
* The Class DecisionMatrix.
*/
public class DecisionMatrix implements Cloneable {
/* Decision Matrix
* ____| C_1 | C_2 | C_3 |
* A1 | V | V | V |
* A2 | V | V | V |
* A3 | V | V | V | */
/**
* Instantiates a new decision matrix.
*/
public DecisionMatrix() {
}
/** The criterion headers. */
ArrayList<ProblemElement> criterionHeaders;
/** The alternative headers. */
ArrayList<ProblemElement> alternativeHeaders;
/** The content. */
TreeMap<ProblemElement, TreeMap<ProblemElement, WValuation>> content = new TreeMap<>();
/** The cached values. */
ArrayList<ArrayList<Double>> cachedValues = null; // Poner a null para que se regenere
/** The expert. */
Expert expert;
/**
* Adds the content.
*
* @param entries the entries
*/
public void addContent(HashMap<ProblemElementKey, Valuation> entries) {
expert = entries.keySet().iterator().next().getExpert();
for (Entry<ProblemElementKey, Valuation> entry : entries.entrySet()) {
ProblemElementKey pek = entry.getKey();
Criterion c = pek.getCriterion();
Alternative a = pek.getAlternative();
WValuation w = new WValuation(entry);
// Get the criterion column
TreeMap<ProblemElement, WValuation> col = content.get(c);
if (col == null)
col = new TreeMap<>();
// Add the valuation
col.put(a, w);
content.put(c, col);
}
updateHeaders();
}
/**
* Update headers.
*/
public void updateHeaders() {
criterionHeaders = new ArrayList<>(content.keySet());
alternativeHeaders = new ArrayList<>(content.values()
.iterator()
.next()
.keySet());
}
/**
* Gets the content.
*
* @return the content
*/
public TreeMap<ProblemElement, TreeMap<ProblemElement, WValuation>> getContent() {
return content;
}
/**
* Gets the criterion header.
*
* @return the criterion header
*/
public ArrayList<String> getCriterionHeader() {
return (ArrayList<String>) criterionHeaders.stream()
.map(k -> k.getCanonicalName())
.collect(Collectors.toList());
}
/**
* Gets the alternative header.
*
* @return the alternative header
*/
public ArrayList<String> getAlternativeHeader() {
return (ArrayList<String>) alternativeHeaders.stream()
.map(k -> k.getCanonicalName())
.collect(Collectors.toList());
}
/**
* Gets the values.
*
* @return the values
*/
public ArrayList<ArrayList<Double>> getValues() {
if (cachedValues != null)
return cachedValues;
cachedValues = new ArrayList<>();
for (Entry<ProblemElement, TreeMap<ProblemElement, WValuation>> critEntry : content.entrySet()) {
ArrayList<Double> columnValues = new ArrayList<>();
for (Entry<ProblemElement, WValuation> altEntry : critEntry.getValue()
.entrySet()) {
NumericValuation value = (NumericValuation) altEntry.getValue().getValuation();
columnValues.add(value.getValue());
}
cachedValues.add(columnValues);
}
return cachedValues;
}
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
@Override
public Object clone() {
DecisionMatrix dm = new DecisionMatrix();
for( Entry<ProblemElement,TreeMap<ProblemElement,WValuation>> entry1 : this.getContent().entrySet() ) {
ProblemElement criterion = entry1.getKey();
for( Entry<ProblemElement, WValuation> entry2 : entry1.getValue().entrySet() ) {
ProblemElement alternative = entry2.getKey();
Valuation v = (Valuation) entry2.getValue().getValuation().clone();
dm.set(criterion, alternative, v);
}
}
dm.updateHeaders();
return dm;
}
/**
* Gets the criterions.
*
* @return the criterions
*/
public Criterion[] getCriterions() {
return this.criterionHeaders.stream()
.map(k -> (Criterion) k)
.toArray(Criterion[]::new);
}
/**
* Gets the alternatives.
*
* @return the alternatives
*/
public Alternative[] getAlternatives() {
return this.alternativeHeaders.stream()
.map(k -> (Alternative) k)
.toArray(Alternative[]::new);
}
/**
* Gets the column.
*
* @param crit the crit
* @return the column
*/
public TreeMap<ProblemElement, WValuation> getColumn(ProblemElement crit) {
TreeMap<ProblemElement, WValuation> column = content.get(crit);
return column;
}
/**
* Gets the row.
*
* @param alternative the alternative
* @return the row
*/
public ArrayList<WValuation> getRow(Alternative alternative){
// o(n) -> o(1)
return (ArrayList<WValuation>) content.values().stream().map( k -> k.get( alternative )).collect(Collectors.toList());
}
/**
* Sets the content.
*
* @param content the content
*/
public void setContent(TreeMap<ProblemElement, TreeMap<ProblemElement, WValuation>> content) {
this.content = content;
updateHeaders();
}
/**
* Sets the.
*
* @param crit the crit
* @param alt the alt
* @param value the value
*/
public void set(ProblemElement crit, ProblemElement alt, Valuation value) {
WValuation waluation = new WValuation(this.expert, (Alternative)alt, (Criterion)crit, value);
TreeMap<ProblemElement, WValuation> col = content.get(crit);
if (col == null)
col = new TreeMap<>();
col.put(alt, waluation);
content.put(crit, col);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
List<List<Double>> values = MatrixHelper.transpose(this.getValues());
StringBuilder sb = new StringBuilder("");
for (List<Double> arr : values) {
for (Double val : arr) {
sb.append(val);
sb.append(" ");
}
sb.append("\n");
}
return sb.toString();
}
}