Added Custom Graph

This commit is contained in:
cmerkens 2024-07-07 23:39:17 +02:00
parent 8de3c54775
commit e510bebc21
10 changed files with 126 additions and 75 deletions

15
.idea/workspace.xml generated
View File

@ -5,22 +5,29 @@
</component>
<component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet">
<change afterPath="$PROJECT_DIR$/graph/EdgeWeightMarking.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/EdgeMarking.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/EdgeMarking.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/UndirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/UndirectedGraph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/UndirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/UndirectedGraph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/EdgeWeightMarking.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/EdgeWeightMarking.class" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>

View File

@ -6,6 +6,7 @@ import visualisation.HybridWindow;
import visualizationElements.Vertex;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;
@ -53,7 +54,7 @@ public class OurApplication {
LogElementList<OurLogElement> logList=new LogElementList<OurLogElement>();
LogElementList<OurLogElement> logList = new LogElementList<>();
OurParameterArea parameterArea = new OurParameterArea();
OurMethodButtons methodButtons = new OurMethodButtons();
OurDrawArea drawArea = new OurDrawArea(logList,"GraphVisualization");
@ -76,5 +77,4 @@ public class OurApplication {
frame.setVisible(true);
}
}

View File

@ -1,9 +1,6 @@
package OurApplication;
import graph.DirectedGraph;
import graph.EdgeMarking;
import graph.ExampleGraphs;
import graph.VertexMarking;
import graph.*;
import visualisation.ParameterArea;
import javax.swing.*;
@ -22,13 +19,19 @@ public class OurParameterArea extends ParameterArea{
private static final long serialVersionUID = 1L;
private DirectedGraph<VertexMarking, EdgeMarking> customGraph;
private JRadioButton button1;
private JRadioButton button2;
private JRadioButton button3;
private JRadioButton button4;
private JRadioButton button5;
private ExampleGraphs temp;
private JButton buttonAddGraph;
private JTextField textField1;
private JTextField textField2;
private int selectedExample;
@ -41,8 +44,8 @@ public class OurParameterArea extends ParameterArea{
*/
public OurParameterArea() {
super();
temp = new ExampleGraphs();
selectedExample = 1; // Standardmäßig Beispiel 1
this.customGraph = new DirectedGraph<>();
setBorder(BorderFactory.createTitledBorder("ParameterArea"));
@ -56,6 +59,11 @@ public class OurParameterArea extends ParameterArea{
button4 = new JRadioButton("Beispiel 4");
button5 = new JRadioButton("Eigener Graph");
buttonAddGraph = new JButton("Graph einfügen");
// Eingabefelder
textField1 = new JTextField("Knoten");
textField2 = new JTextField("Kanten");
// ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
ButtonGroup group = new ButtonGroup();
@ -66,47 +74,33 @@ public class OurParameterArea extends ParameterArea{
group.add(button5);
// ActionListener hinzufügen
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 1;
}
button1.addActionListener(e -> selectedExample = 1);
button2.addActionListener(e -> selectedExample = 2);
button3.addActionListener(e -> selectedExample = 3);
button4.addActionListener(e -> selectedExample = 4);
button5.addActionListener(e -> selectedExample = 5);
buttonAddGraph.addActionListener(e -> {
String input1 = textField1.getText();
String input2 = textField2.getText();
this.customGraph = createGraph(input1, input2);
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 2;
}
});
// Buttons zum Panel hinzufügen
add(button1);
add(button2);
add(button3);
add(button4);
add(button5);
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 3;
}
});
button4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 4;
}
});
button5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 5;
}
});
// Buttons zum Panel hinzufügen
add(button1);
add(button2);
add(button3);
add(button4);
add(button5);
add(buttonAddGraph);
add(textField1);
add(textField2);
}
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
@ -119,11 +113,43 @@ public class OurParameterArea extends ParameterArea{
case 4:
return temp.example4();
case 5:
return new DirectedGraph<>();
return this.customGraph;
case 1:
default:
return temp.example1();
}
}
// Vertex Eingabe: A-23-23;A-23-23
// Edge Eingabe: A-B-15;A-B-15
public DirectedGraph<VertexMarking, EdgeMarking> createGraph(String vertices, String edges) {
DirectedGraph<VertexMarking, EdgeMarking> newGraph = new DirectedGraph<>();
String[] allVertices = vertices.split(";");
String[] allEdges = edges.split(";");
for (String i: allVertices) {
String[] current = i.split("-");
newGraph.addVertex(new MarkedVertex<>(Integer.parseInt(current[1]), Integer.parseInt(current[2]), current[0], null, Color.BLACK));
}
MarkedVertex<VertexMarking> start = null;
MarkedVertex<VertexMarking> end = null;
for (String i: allEdges) {
String[] current = i.split("-");
for (MarkedVertex<VertexMarking> j: newGraph.getAllVertexes()) {
if (j.getName() == current[0]) {
start = j;
} else if (j.getName() == current[1]) {
end = j;
}
}
newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2]))));
}
return newGraph;
}
}

View File

@ -254,7 +254,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging
textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription);
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) {
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
@ -305,7 +307,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription);
i.getScreenVertex().setColor(Color.YELLOW);
if (i.getScreenVertex().getColor() != Color.RED) {
i.getScreenVertex().setColor(Color.YELLOW);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf
@ -387,7 +391,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging
textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription);
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) {
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Wenn Weg gefunden, brich ab
@ -442,7 +448,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription);
i.getScreenVertex().setColor(Color.YELLOW);
if (i.getScreenVertex().getColor() != Color.RED) {
i.getScreenVertex().setColor(Color.YELLOW);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf

View File

@ -1,19 +1,4 @@
package graph;
public abstract class EdgeMarking extends Marking{
}
class EdgeWeightMarking extends EdgeMarking{
private int weight;
EdgeWeightMarking(int weight){
this.weight = weight;
}
public void setWeight(int weight){
this.weight=weight;
}
public int getWeight(){
return this.weight;
}
}
}

View File

@ -0,0 +1,17 @@
package graph;
public class EdgeWeightMarking extends EdgeMarking {
private int weight;
public EdgeWeightMarking(int weight){
this.weight = weight;
}
public void setWeight(int weight){
this.weight=weight;
}
public int getWeight(){
return this.weight;
}
}

View File

@ -189,7 +189,9 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
// Logging
textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription);
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) {
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
@ -240,7 +242,9 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
// Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription);
i.getScreenVertex().setColor(Color.YELLOW);
if (i.getScreenVertex().getColor() != Color.RED) {
i.getScreenVertex().setColor(Color.YELLOW);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf
@ -321,7 +325,9 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
// Logging
textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription);
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) {
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
@ -377,7 +383,9 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
// Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription);
i.getScreenVertex().setColor(Color.YELLOW);
if (i.getScreenVertex().getColor() != Color.RED) {
i.getScreenVertex().setColor(Color.YELLOW);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf