Many changes.
This commit is contained in:
@@ -15,15 +15,20 @@ public class Grafo {
|
||||
*/
|
||||
final static public class Tipos {
|
||||
/**
|
||||
* Tipo de grafoNoDirigido dirigido.
|
||||
* Tipo de grafo dirigido.
|
||||
*/
|
||||
static final public int DIRIGIDO = 0;
|
||||
|
||||
/**
|
||||
* Tipo de grafoNoDirigido no dirigido.
|
||||
* Tipo de grafo no dirigido.
|
||||
*/
|
||||
static final public int NO_DIRIGIDO = 1;
|
||||
|
||||
/**
|
||||
* Tipo de grafo dirigido con peso.
|
||||
*/
|
||||
static final public int PESO = 2;
|
||||
|
||||
/**
|
||||
* El tipo que está elegido.
|
||||
*/
|
||||
@@ -42,6 +47,9 @@ public class Grafo {
|
||||
case NO_DIRIGIDO:
|
||||
this.tipo = NO_DIRIGIDO;
|
||||
break;
|
||||
case PESO:
|
||||
this.tipo = PESO;
|
||||
break;
|
||||
default:
|
||||
this.tipo = NO_DIRIGIDO;
|
||||
}
|
||||
|
@@ -154,7 +154,8 @@ public class GrafoController implements Initializable {
|
||||
noDirigido.addEdge(grafoNodos[3], grafoNodos[1]);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int j = (grafoTipos.getTipo() == Grafo.Tipos.DIRIGIDO)?5:4;
|
||||
for (int i = 0; i < j; i++) {
|
||||
if (grafoNodos[i] == null) {
|
||||
|
||||
int numero = random.nextInt(rango) + minimo;
|
||||
@@ -170,12 +171,22 @@ public class GrafoController implements Initializable {
|
||||
dirigido.addVertex(vertex);
|
||||
}
|
||||
}
|
||||
dirigido.addEdge(dirigido.getVertex(0), dirigido.getVertex(1), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(1), dirigido.getVertex(2), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(2), dirigido.getVertex(4), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(2), dirigido.getVertex(0), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(4), dirigido.getVertex(3), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(3), dirigido.getVertex(1), PESO_PREDETERMINADO);
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.DIRIGIDO) {
|
||||
dirigido.addEdge(dirigido.getVertex(0), dirigido.getVertex(1), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(1), dirigido.getVertex(2), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(2), dirigido.getVertex(4), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(2), dirigido.getVertex(0), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(4), dirigido.getVertex(3), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(3), dirigido.getVertex(1), PESO_PREDETERMINADO);
|
||||
}
|
||||
else {
|
||||
dirigido.addEdge(dirigido.getVertex(0), dirigido.getVertex(3), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(1), dirigido.getVertex(2), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(2), dirigido.getVertex(0), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(1), dirigido.getVertex(0), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(2), dirigido.getVertex(3), PESO_PREDETERMINADO);
|
||||
dirigido.addEdge(dirigido.getVertex(3), dirigido.getVertex(1), PESO_PREDETERMINADO);
|
||||
}
|
||||
}
|
||||
|
||||
generarGrafico();
|
||||
@@ -358,7 +369,7 @@ public class GrafoController implements Initializable {
|
||||
}
|
||||
else {
|
||||
int peso = PESO_PREDETERMINADO;
|
||||
if (valorPeso.getText() != null || !valorPeso.getText().trim().equals("")) {
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO && valorPeso.getText() != null && !valorPeso.getText().trim().equals("")) {
|
||||
try {
|
||||
peso = Integer.valueOf(valorPeso.getText());
|
||||
}
|
||||
@@ -653,30 +664,41 @@ public class GrafoController implements Initializable {
|
||||
Grafo.Vertex<GrafoNodo> vTo = edge.getTo();
|
||||
GrafoNodo from = vFrom.getData();
|
||||
GrafoNodo to = vTo.getData();
|
||||
int peso = edge.getCost();
|
||||
|
||||
if (from == grafoNodos[0]) {
|
||||
if (to == from) {
|
||||
graphicsContext.strokeArc(15, 40, 29, 30, 145, 250, ArcType.OPEN);
|
||||
if (from == grafoNodos[0] && to == from) {
|
||||
graphicsContext.strokeArc(15, 40, 29, 30, 145, 250, ArcType.OPEN);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(15, String.valueOf(peso)), 80);
|
||||
}
|
||||
}
|
||||
if (from == grafoNodos[1]) {
|
||||
if (to == from) {
|
||||
graphicsContext.strokeArc(215, 40, 29, 30, 145, 250, ArcType.OPEN);
|
||||
if (from == grafoNodos[1] && to == from) {
|
||||
graphicsContext.strokeArc(215, 40, 29, 30, 145, 250, ArcType.OPEN);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(235, String.valueOf(peso)), 80);
|
||||
}
|
||||
}
|
||||
if (from == grafoNodos[2]) {
|
||||
if (to == from) {
|
||||
graphicsContext.strokeArc(15, 240, 29, 30, 145, 250, ArcType.OPEN);
|
||||
if (from == grafoNodos[2] && to == from) {
|
||||
graphicsContext.strokeArc(15, 240, 29, 30, 145, 250, ArcType.OPEN);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(15, String.valueOf(peso)), 280);
|
||||
}
|
||||
}
|
||||
if (from == grafoNodos[3]) {
|
||||
if (to == from) {
|
||||
graphicsContext.strokeArc(215, 240, 29, 30, 145, 250, ArcType.OPEN);
|
||||
if (from == grafoNodos[3] && to == from) {
|
||||
graphicsContext.strokeArc(215, 240, 29, 30, 145, 250, ArcType.OPEN);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(235, String.valueOf(peso)), 280);
|
||||
}
|
||||
}
|
||||
if (from == grafoNodos[4]) {
|
||||
if (to == from) {
|
||||
graphicsContext.strokeArc(110, 440, 29, 30, 145, 250, ArcType.OPEN);
|
||||
if (from == grafoNodos[4] && to == from) {
|
||||
graphicsContext.strokeArc(110, 440, 29, 30, 145, 250, ArcType.OPEN);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(120, String.valueOf(peso)), 485);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,6 +710,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {25.0, 30.0, 35.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), 120, 25);
|
||||
}
|
||||
}
|
||||
// Line between 1 and 0
|
||||
if (from == grafoNodos[1] && to == grafoNodos[0]) {
|
||||
@@ -697,6 +723,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {25.0, 30.0, 35.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), 120, 45);
|
||||
}
|
||||
}
|
||||
// Line between 2 and 3
|
||||
if (from == grafoNodos[2] && to == grafoNodos[3]) {
|
||||
@@ -706,6 +736,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {225.0, 230.0, 235.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), 120, 225);
|
||||
}
|
||||
}
|
||||
// Line between 3 and 2
|
||||
if (from == grafoNodos[3] && to == grafoNodos[2]) {
|
||||
@@ -715,6 +749,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {225.0, 230.0, 235.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), 120, 245);
|
||||
}
|
||||
}
|
||||
// Line between 0 and 2
|
||||
if (from == grafoNodos[0] && to == grafoNodos[2]) {
|
||||
@@ -724,6 +762,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {200.0, 200.0, 210.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(15, String.valueOf(peso)), 150);
|
||||
}
|
||||
}
|
||||
// Line between 2 and 0
|
||||
if (from == grafoNodos[2] && to == grafoNodos[0]) {
|
||||
@@ -733,6 +775,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {50.0, 60.0, 60.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), 35, 150);
|
||||
}
|
||||
}
|
||||
// Line between 1 and 3
|
||||
if (from == grafoNodos[1] && to == grafoNodos[3]) {
|
||||
@@ -742,6 +788,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {200.0, 200.0, 210.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(215, String.valueOf(peso)), 150);
|
||||
}
|
||||
}
|
||||
// Line between 3 and 1
|
||||
if (from == grafoNodos[3] && to == grafoNodos[1]) {
|
||||
@@ -751,6 +801,10 @@ public class GrafoController implements Initializable {
|
||||
new double[] {50.0, 60.0, 60.0},
|
||||
3
|
||||
);
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), 235, 150);
|
||||
}
|
||||
}
|
||||
// Line between 0 and 3
|
||||
if (from == grafoNodos[0] && to == grafoNodos[3]) {
|
||||
@@ -766,6 +820,10 @@ public class GrafoController implements Initializable {
|
||||
3
|
||||
);
|
||||
graphicsContext.restore();
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(90, String.valueOf(peso)), 110);
|
||||
}
|
||||
}
|
||||
// Line between 3 and 0
|
||||
if (from == grafoNodos[3] && to == grafoNodos[0]) {
|
||||
@@ -780,6 +838,10 @@ public class GrafoController implements Initializable {
|
||||
3
|
||||
);
|
||||
graphicsContext.restore();
|
||||
|
||||
if (grafoTipos.getTipo() == Grafo.Tipos.PESO) {
|
||||
graphicsContext.strokeText(String.valueOf(peso), textX(115, String.valueOf(peso)), 110);
|
||||
}
|
||||
}
|
||||
// Line between 1 and 2
|
||||
if (from == grafoNodos[1] && to == grafoNodos[2]) {
|
||||
|
@@ -17,7 +17,7 @@ public class Logs {
|
||||
/**
|
||||
* Estado de depuración.
|
||||
*/
|
||||
static final public boolean DEBUG = true;
|
||||
static final public boolean DEBUG = false;
|
||||
|
||||
/**
|
||||
* Tipos de depuración.
|
||||
|
@@ -253,6 +253,20 @@ public class MenuController extends VBox implements Initializable {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click en Grafo No Dirigidos.
|
||||
*/
|
||||
@FXML
|
||||
protected void menuGrafoPeso() {
|
||||
Grafo.Tipos grafoTipos = new Grafo.Tipos(Grafo.Tipos.PESO);
|
||||
loadStage(
|
||||
resourceBundle.getString("tituloGrafoDirigido"),
|
||||
"/cl/cromer/estructuras/fxml/grafoPeso.fxml",
|
||||
"/cl/cromer/estructuras/css/main.css",
|
||||
grafoTipos
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click en Hash Table.
|
||||
*/
|
||||
|
@@ -44,6 +44,7 @@ bTree=B-Tree
|
||||
grafos=Graphs
|
||||
dirigidos=Directed
|
||||
noDirigidos=Undirected
|
||||
grafoPeso=Weight
|
||||
tablaHash=Hash Table
|
||||
idioma=Language
|
||||
ingles=English
|
||||
|
@@ -43,6 +43,7 @@ bTree=B-Tree
|
||||
grafos=Grafo
|
||||
dirigidos=Dirigido
|
||||
noDirigidos=No Dirigido
|
||||
grafoPeso=Peso
|
||||
tablaHash=Tabla Hash
|
||||
idioma=Idioma
|
||||
ingles=Ingl\u00E9s
|
||||
|
@@ -28,8 +28,6 @@
|
||||
<Button text="%eliminar" onAction="#botonEliminarEdge"/>
|
||||
<TextFieldLimited fx:id="valorNodo1" maxLength="3" prefWidth="50"/>
|
||||
<TextFieldLimited fx:id="valorNodo2" maxLength="3" prefWidth="50"/>
|
||||
<Text text="%grafoWeight"/>
|
||||
<TextFieldLimited fx:id="valorPeso" maxLength="3" prefWidth="50"/>
|
||||
</HBox>
|
||||
<Canvas fx:id="contenidoGrafo" width="300" height="500"/>
|
||||
</VBox>
|
||||
|
41
src/cl/cromer/estructuras/fxml/grafoPeso.fxml
Normal file
41
src/cl/cromer/estructuras/fxml/grafoPeso.fxml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<?import cl.cromer.estructuras.TextFieldLimited?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="768.0" prefWidth="1024.0" spacing="10"
|
||||
xmlns="http://javafx.com/javafx/8.0.92" fx:controller="cl.cromer.estructuras.GrafoController">
|
||||
<fx:include source="menu.fxml"/>
|
||||
<ScrollPane fitToHeight="true" fitToWidth="true" VBox.vgrow="ALWAYS">
|
||||
<HBox alignment="TOP_CENTER" VBox.vgrow="ALWAYS" spacing="50">
|
||||
<VBox spacing="10">
|
||||
<HBox alignment="CENTER" spacing="10">
|
||||
<Button text="%llenar" onAction="#botonLlenar"/>
|
||||
<Button text="%vaciar" onAction="#botonVaciar"/>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" spacing="10">
|
||||
<Text text="%grafoNodos"/>
|
||||
<Button text="%insertar" onAction="#botonInsertar"/>
|
||||
<Button text="%eliminar" onAction="#botonEliminar"/>
|
||||
<TextFieldLimited fx:id="valorGrafo" maxLength="3" prefWidth="50"/>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" spacing="10">
|
||||
<Text text="%grafoEdges"/>
|
||||
<Button text="%insertar" onAction="#botonInsertarEdge"/>
|
||||
<Button text="%eliminar" onAction="#botonEliminarEdge"/>
|
||||
<TextFieldLimited fx:id="valorNodo1" maxLength="3" prefWidth="50"/>
|
||||
<TextFieldLimited fx:id="valorNodo2" maxLength="3" prefWidth="50"/>
|
||||
<Text text="%grafoWeight"/>
|
||||
<TextFieldLimited fx:id="valorPeso" maxLength="3" prefWidth="50"/>
|
||||
</HBox>
|
||||
<Canvas fx:id="contenidoGrafo" width="300" height="500"/>
|
||||
</VBox>
|
||||
<StackPane alignment="TOP_LEFT" minWidth="450">
|
||||
<Text fx:id="codigoGrafo"/>
|
||||
</StackPane>
|
||||
</HBox>
|
||||
</ScrollPane>
|
||||
</VBox>
|
@@ -34,6 +34,7 @@
|
||||
<Menu text="%grafos">
|
||||
<MenuItem text="%dirigidos" onAction="#menuGrafoDirigidos"/>
|
||||
<MenuItem text="%noDirigidos" onAction="#menuGrafoNoDirigidos"/>
|
||||
<MenuItem text="%grafoPeso" onAction="#menuGrafoPeso"/>
|
||||
</Menu>
|
||||
<MenuItem text="%tablaHash" onAction="#menuHashTable"/>
|
||||
</Menu>
|
||||
|
Reference in New Issue
Block a user