Compare commits

...

2 Commits

Author SHA1 Message Date
cmerkens
80d48d5335 Merge branch 'main' of https://gitea.hb.dhbw-stuttgart.de/i23024/ProjektGraph
# Conflicts:
#	graph/EdgeMarking.java
#	out/production/ProjektGraph/graph/EdgeWeightMarking.class
2024-07-07 23:41:01 +02:00
cmerkens
e510bebc21 Added Custom Graph 2024-07-07 23:39:17 +02:00
9 changed files with 125 additions and 59 deletions

15
.idea/workspace.xml generated
View File

@ -5,22 +5,29 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet"> <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$/.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/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/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$/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/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/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/EdgeWeightMarking.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/EdgeWeightMarking.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" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>

View File

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

View File

@ -1,9 +1,6 @@
package OurApplication; package OurApplication;
import graph.DirectedGraph; import graph.*;
import graph.EdgeMarking;
import graph.ExampleGraphs;
import graph.VertexMarking;
import visualisation.ParameterArea; import visualisation.ParameterArea;
import javax.swing.*; import javax.swing.*;
@ -22,13 +19,19 @@ public class OurParameterArea extends ParameterArea{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private DirectedGraph<VertexMarking, EdgeMarking> customGraph;
private JRadioButton button1; private JRadioButton button1;
private JRadioButton button2; private JRadioButton button2;
private JRadioButton button3; private JRadioButton button3;
private JRadioButton button4; private JRadioButton button4;
private JRadioButton button5; private JRadioButton button5;
private ExampleGraphs temp; private JButton buttonAddGraph;
private JTextField textField1;
private JTextField textField2;
private int selectedExample; private int selectedExample;
@ -41,8 +44,8 @@ public class OurParameterArea extends ParameterArea{
*/ */
public OurParameterArea() { public OurParameterArea() {
super(); super();
temp = new ExampleGraphs();
selectedExample = 1; // Standardmäßig Beispiel 1 selectedExample = 1; // Standardmäßig Beispiel 1
this.customGraph = new DirectedGraph<>();
setBorder(BorderFactory.createTitledBorder("ParameterArea")); setBorder(BorderFactory.createTitledBorder("ParameterArea"));
@ -56,6 +59,11 @@ public class OurParameterArea extends ParameterArea{
button4 = new JRadioButton("Beispiel 4"); button4 = new JRadioButton("Beispiel 4");
button5 = new JRadioButton("Eigener Graph"); 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 erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
@ -66,39 +74,21 @@ public class OurParameterArea extends ParameterArea{
group.add(button5); group.add(button5);
// ActionListener hinzufügen // ActionListener hinzufügen
button1.addActionListener(new ActionListener() { button1.addActionListener(e -> selectedExample = 1);
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 1;
}
});
button2.addActionListener(new ActionListener() { button2.addActionListener(e -> selectedExample = 2);
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 2;
}
});
button3.addActionListener(new ActionListener() { button3.addActionListener(e -> selectedExample = 3);
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 3;
}
});
button4.addActionListener(new ActionListener() { button4.addActionListener(e -> selectedExample = 4);
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 4;
}
});
button5.addActionListener(new ActionListener() { button5.addActionListener(e -> selectedExample = 5);
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 5; buttonAddGraph.addActionListener(e -> {
} String input1 = textField1.getText();
String input2 = textField2.getText();
this.customGraph = createGraph(input1, input2);
}); });
// Buttons zum Panel hinzufügen // Buttons zum Panel hinzufügen
@ -107,6 +97,10 @@ public class OurParameterArea extends ParameterArea{
add(button3); add(button3);
add(button4); add(button4);
add(button5); add(button5);
add(buttonAddGraph);
add(textField1);
add(textField2);
} }
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() { public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
@ -119,11 +113,43 @@ public class OurParameterArea extends ParameterArea{
case 4: case 4:
return temp.example4(); return temp.example4();
case 5: case 5:
return new DirectedGraph<>(); return this.customGraph;
case 1: case 1:
default: default:
return temp.example1(); 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 // Logging
textDescription = "Visit " + nextVertex.getElement().getName(); textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription); System.out.println(textDescription);
if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) {
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); 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 // Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue."; textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription); System.out.println(textDescription);
if (i.getScreenVertex().getColor() != Color.RED) {
i.getScreenVertex().setColor(Color.YELLOW); i.getScreenVertex().setColor(Color.YELLOW);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf // Nehme nächsten Knoten in die Queue auf
@ -387,7 +391,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging // Logging
textDescription = "Visit " + nextVertex.getElement().getName(); textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription); System.out.println(textDescription);
if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) {
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Wenn Weg gefunden, brich ab // Wenn Weg gefunden, brich ab
@ -442,7 +448,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging // Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue."; textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription); System.out.println(textDescription);
if (i.getScreenVertex().getColor() != Color.RED) {
i.getScreenVertex().setColor(Color.YELLOW); i.getScreenVertex().setColor(Color.YELLOW);
}
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf // Nehme nächsten Knoten in die Queue auf

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

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