package graphmatcher.helper;
import graphmatcher.graph.Graph;
import graphmatcher.gui.GraphListPanel;
import graphmatcher.gui.GraphPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.SimpleLayout;
public class GraphViewer {
/**
* @param args
*/
public static void main(String[] args) {
BasicConfigurator.configure(new ConsoleAppender(new SimpleLayout()));
Vector<Graph> graphs = GraphLoader.loadGraphs("6e", 2000, 2000);
int numberOfNewEdges = 0;
int numberOfEdges = 0;
for (Graph graph : graphs) {
int edges = graph.edges().length;
numberOfEdges += edges;
int virtualEdges = graph.virtualEdges().length;
numberOfNewEdges += (virtualEdges - edges);
if (edges != virtualEdges) {
System.out.println(graph + ": " + edges + " <-> " + virtualEdges);
}
}
System.out.println("Anzahl Graphen: " + graphs.size());
System.out.println("Anzahl Kanten im Schnitt: " + (double) numberOfEdges / graphs.size());
System.out.println("Anzahl virtueller Kanten (gesamt): " + numberOfNewEdges);
System.out.println("Schnitt: " + ((double) numberOfNewEdges / graphs.size()));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
GraphListPanel listPanel = new GraphListPanel("");
listPanel.setInitialData(graphs);
frame.add(listPanel, BorderLayout.WEST);
final GraphPanel graphPanel = new GraphPanel(Color.BLACK, Color.GREEN);
frame.add(graphPanel, BorderLayout.CENTER);
listPanel.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
JList list = (JList) e.getSource();
Graph graph = (Graph) list.getSelectedValue();
graphPanel.setGraph(graph);
}
});
frame.pack();
frame.setVisible(true);
}
}