Commit 13bb1064 authored by Falucho's avatar Falucho

Retoques finales

parent ee4be057
......@@ -41,9 +41,29 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>C:/Desarrollo/glpk-4.65/w64</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addClasspath>true</addClasspath>
......@@ -51,7 +71,6 @@
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
......
......@@ -119,7 +119,7 @@ public final class AEControlador {
best = poblacion.get(0);
}
Individuo individuo = poblacion.parallelStream().min(Comparator.comparingInt(Individuo::getCosto)).orElse(best);
Individuo individuo = poblacion.parallelStream().min(Comparator.comparingLong(Individuo::getCosto)).orElse(best);
ProblemaControlador.getInstance().calculoDeFrecuencias(individuo);
if (individuo.getCosto() < best.getCosto()) {
......
......@@ -18,6 +18,7 @@ public final class GuiHelper {
private static javax.swing.JLabel lblEstado;
private static javax.swing.JPanel mapa;
private static List<Arista> individuo = null;
private GuiHelper() {
}
......@@ -30,6 +31,14 @@ public final class GuiHelper {
GuiHelper.mapa = mapa;
}
public static void setIndividuo(List<Arista> individuo) {
GuiHelper.individuo = individuo;
}
public static List<Arista> getIndividuo() {
return individuo;
}
public static void dibujarNodos() {
Graphics g = mapa.getGraphics();
resetStroke(g);
......@@ -37,6 +46,7 @@ public final class GuiHelper {
}
public static void dibujarAristas(List<Arista> aristas, Color color, int px) {
GuiHelper.setIndividuo(aristas);
Graphics g = mapa.getGraphics();
clearAristas(g);
dibujarAristas(g);
......@@ -94,6 +104,8 @@ public final class GuiHelper {
lblEstado.setText("Generacion: " + gen + " | Frecuencias: " + frecs + " | Costo Total: " + best.getCosto() + " | Costo USD: " + best.getCostoDinero() + " | Tiempo: " + tiempo);
dibujarLinas(best, consentradoresActivos);
} else {
GuiHelper.dibujarAristas(individuo, Color.MAGENTA, 2);
}
}
......
......@@ -7,7 +7,6 @@ import uy.edu.fing.lrt.genetic.Parte1;
import uy.edu.fing.lrt.genetic.Parte2;
import uy.edu.fing.lrt.modelo.Arista;
import uy.edu.fing.lrt.modelo.Individuo;
import uy.edu.fing.lrt.modelo.Linea;
import uy.edu.fing.lrt.modelo.Nodo;
import uy.edu.fing.lrt.test.Parada;
import uy.edu.fing.lrt.util.GlpkUtil;
......@@ -33,7 +32,6 @@ public final class Principal extends javax.swing.JFrame {
private String rutaDatos = PropiedadesEnum.WORKSPACE.getValorDefecto();
private String rutaProp = null;
private List<Arista> individuo = null;
private Boolean[] consentradoresActivos = {true, true, true, true};
private void mostrarMensaje(String mensaje, String titulo, int type) {
......@@ -135,7 +133,7 @@ public final class Principal extends javax.swing.JFrame {
jMenu6.setText("jMenu6");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Metaheuristicas y Optimizacion de Redes");
setTitle("Diseño optimizado para un backbone de transporte metropolitano");
setFocusableWindowState(false);
setMaximumSize(new java.awt.Dimension(1000, 1000));
setMinimumSize(new java.awt.Dimension(700, 700));
......@@ -149,12 +147,12 @@ public final class Principal extends javax.swing.JFrame {
javax.swing.GroupLayout mapaLayout = new javax.swing.GroupLayout(mapa);
mapa.setLayout(mapaLayout);
mapaLayout.setHorizontalGroup(
mapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 788, Short.MAX_VALUE)
mapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 788, Short.MAX_VALUE)
);
mapaLayout.setVerticalGroup(
mapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 536, Short.MAX_VALUE)
mapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 536, Short.MAX_VALUE)
);
lblEstado.setText(".");
......@@ -162,17 +160,17 @@ public final class Principal extends javax.swing.JFrame {
javax.swing.GroupLayout barraEstadoLayout = new javax.swing.GroupLayout(barraEstado);
barraEstado.setLayout(barraEstadoLayout);
barraEstadoLayout.setHorizontalGroup(
barraEstadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(barraEstadoLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblEstado)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
barraEstadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(barraEstadoLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblEstado)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
barraEstadoLayout.setVerticalGroup(
barraEstadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, barraEstadoLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lblEstado))
barraEstadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, barraEstadoLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lblEstado))
);
menuPintar.setText("Datos");
......@@ -335,22 +333,22 @@ public final class Principal extends javax.swing.JFrame {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(barraEstado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(barraEstado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(barraEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(barraEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
......@@ -426,10 +424,9 @@ public final class Principal extends javax.swing.JFrame {
if (rutaProp != null) {
PropiedadesControlador.load(new File(rutaProp));
}
individuo = Parte1.run();
printNodosUsados(individuo);
GuiHelper.dibujarAristas(individuo, Color.MAGENTA, 2);
List<Arista> ind = Parte1.run();
printNodosUsados(ind);
GuiHelper.dibujarAristas(ind, Color.MAGENTA, 2);
} catch (Exception ex) {
mostrarMensajeError(ex);
Logger.error(null, ex);
......@@ -506,7 +503,7 @@ public final class Principal extends javax.swing.JFrame {
if (individuoAE.getCosto() > individuoTMP.getCosto()) {
GuiHelper.dibujarBest(consentradoresActivos);
individuoAE = individuoTMP;
individuo = individuoAE.getAristas();
GuiHelper.setIndividuo(individuoAE.getAristas());
}
String tiempo = AEControlador.getInstance().getTime();
gen = AEControlador.getInstance().getGeneracion();
......@@ -539,14 +536,9 @@ public final class Principal extends javax.swing.JFrame {
if (rutaProp != null) {
PropiedadesControlador.load(new File(rutaProp));
}
individuo = Parte2.run();
//List<Arista> aristas = ProblemaControlador.getInstance().getAristas();
//individuo = GlpkUtil.SPP(aristas, 3, 55, Arista::getLargo);
Linea l = new Linea(individuo);
List<Integer> nodos = l.getNodos();
List<Arista> ind = Parte2.run();
GuiHelper.dibujarAristas(individuo, Color.MAGENTA, 2);
GuiHelper.dibujarAristas(ind, Color.MAGENTA, 2);
} catch (Exception ex) {
mostrarMensajeError(ex);
Logger.error(null, ex);
......@@ -554,6 +546,7 @@ public final class Principal extends javax.swing.JFrame {
}//GEN-LAST:event_menuParte2ActionPerformed
private void menuGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGuardarActionPerformed
List<Arista> individuo = GuiHelper.getIndividuo();
if (individuo != null) {
final JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File("."));
......
......@@ -11,9 +11,9 @@ import java.util.stream.IntStream;
public final class Individuo {
private Integer costoConstruccion = null;
private Integer costoOperacion = null;
private Integer costoUsuario = null;
private Long costoConstruccion = null;
private Long costoOperacion = null;
private Long costoUsuario = null;
private String id = null;
private Concentrador[] concentradores;
......@@ -29,7 +29,7 @@ public final class Individuo {
this.concentradores = concentradores;
}
public Integer getCosto() {
public Long getCosto() {
if (costoUsuario == null) {
calcularCostoUsuario();
}
......@@ -37,7 +37,7 @@ public final class Individuo {
return getCostoDinero() + costoUsuario;
}
public Integer getCostoDinero() {
public Long getCostoDinero() {
if (costoConstruccion == null) {
calcularCostoConstruccion();
}
......@@ -56,19 +56,19 @@ public final class Individuo {
private void calcularCostoConstruccion() {
Double factorA = PropiedadesControlador.getDoubleProperty(PropiedadesEnum.FITNESS_A);
costoConstruccion = MathUtil.plus(factorA, getAristas().stream().map(Arista::getCosto).reduce(0, Integer::sum)).intValue();
costoConstruccion = MathUtil.plus(factorA, getAristas().stream().map(Arista::getCosto).reduce(0, Integer::sum)).longValue();
}
private void calcularCostoOperacion() {
Double factorB = PropiedadesControlador.getDoubleProperty(PropiedadesEnum.FITNESS_B);
checkOperacion();
costoOperacion = MathUtil.plus(factorB, getLineas().stream().map(l -> l.getLargo() * l.getFrecuencia()).reduce(0, Integer::sum)).intValue();
costoOperacion = MathUtil.plus(factorB, getLineas().stream().map(l -> l.getLargo() * l.getFrecuencia()).reduce(0, Integer::sum)).longValue();
}
private void calcularCostoUsuario() {
Double factorC = PropiedadesControlador.getDoubleProperty(PropiedadesEnum.FITNESS_C);
checkOperacion();
costoUsuario = MathUtil.plus(factorC, ProblemaControlador.getInstance().calculoDeCostoUsuario(this)).intValue();
costoUsuario = MathUtil.plus(factorC, ProblemaControlador.getInstance().calculoDeCostoUsuario(this)).longValue();
}
public boolean isValido() {
......
package uy.edu.fing.lrt.modelo;
import uy.edu.fing.lrt.controlador.PropiedadesControlador;
import uy.edu.fing.lrt.util.Logger;
import uy.edu.fing.lrt.util.MathUtil;
import uy.edu.fing.lrt.util.PropiedadesEnum;
......@@ -35,56 +36,61 @@ public final class Linea {
}
private void ordenarAristas() {
if (tramos.size() == 1) {
Nodo[] nodos = {tramos.get(0).getNodoA(), tramos.get(0).getNodoB()};
this.nodos = Arrays.asList(nodos);
return;
}
final Map<Integer, Nodo> cache = new HashMap<>();
final List<Arista> nuevoTramo = new ArrayList<>();
final List<Nodo> nodosOrdenados = new ArrayList<>();
for (Arista arista : tramos) {
cache.put(arista.getIdNodoA(), arista.getNodoA());
cache.put(arista.getIdNodoB(), arista.getNodoB());
}
try {
if (tramos.size() == 1) {
Nodo[] nodos = {tramos.get(0).getNodoA(), tramos.get(0).getNodoB()};
this.nodos = Arrays.asList(nodos);
return;
}
final Map<Integer, Nodo> cache = new HashMap<>();
final List<Arista> nuevoTramo = new ArrayList<>();
final List<Nodo> nodosOrdenados = new ArrayList<>();
Nodo pivotN = null;
Arista pivotA = null;
List<Nodo> nodosUsados = new ArrayList<>(cache.values());
nodosUsados.sort(Comparator.comparing(Nodo::getNombre));
for (Nodo value : nodosUsados) {
List<Arista> collect = tramos.stream()
.filter(a -> a.getIdNodoA() == value.getNombre() || a.getIdNodoB() == value.getNombre())
.collect(Collectors.toList());
if (collect.size() == 1) {
pivotN = value;
pivotA = collect.get(0);
break;
for (Arista arista : tramos) {
cache.put(arista.getIdNodoA(), arista.getNodoA());
cache.put(arista.getIdNodoB(), arista.getNodoB());
}
}
for (int i = 0; i < cache.size(); i++) {
nodosOrdenados.add(pivotN);
if (pivotA.getIdNodoA() == pivotN.getNombre()) {
pivotN = pivotA.getNodoB();
} else {
pivotN = pivotA.getNodoA();
Nodo pivotN = null;
Arista pivotA = null;
List<Nodo> nodosUsados = new ArrayList<>(cache.values());
nodosUsados.sort(Comparator.comparing(Nodo::getNombre));
this.nodos = nodosUsados;
for (Nodo value : nodosUsados) {
List<Arista> collect = tramos.stream()
.filter(a -> a.getIdNodoA() == value.getNombre() || a.getIdNodoB() == value.getNombre())
.collect(Collectors.toList());
if (collect.size() == 1) {
pivotN = value;
pivotA = collect.get(0);
break;
}
}
for (Arista a : tramos) {
if (a.getId().equals(pivotA.getId())) {
continue;
for (int i = 0; i < cache.size(); i++) {
nodosOrdenados.add(pivotN);
if (pivotA.getIdNodoA() == pivotN.getNombre()) {
pivotN = pivotA.getNodoB();
} else {
pivotN = pivotA.getNodoA();
}
if (a.getIdNodoA() == pivotN.getNombre() || a.getIdNodoB() == pivotN.getNombre()) {
nuevoTramo.add(pivotA);
pivotA = a;
break;
for (Arista a : tramos) {
if (a.getId().equals(pivotA.getId())) {
continue;
}
if (a.getIdNodoA() == pivotN.getNombre() || a.getIdNodoB() == pivotN.getNombre()) {
nuevoTramo.add(pivotA);
pivotA = a;
break;
}
}
}
nodos = nodosOrdenados;
tramos = nuevoTramo;
} catch (Exception e) {
Logger.error("No se pudo ORDENAR", e);
}
nodos=nodosOrdenados;
tramos=nuevoTramo;
}
public List<Integer> getNodos() {
......
......@@ -19,7 +19,7 @@ public final class GlpkUtil {
private GlpkUtil() {
}
public static void config(String libPath){
public static void config(String libPath) {
System.setProperty("java.library.path", libPath);
try {
......
......@@ -16,7 +16,7 @@ fitness.peso.c=15
inicializacion=2
inicializacion.try=250
inicializacion.pop.size=50
inicializacion.pop.size=25
ae.cant.generaciones=1000
ae.cant.generaciones.invariantes=200
......@@ -26,7 +26,7 @@ seleccion.factor=100000
cruzamiento=1
cruzamiento.prob=50
cruzamiento.cant=50
cruzamiento.cant=25
mutacion=1
mutacion.prob=10
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment