diff --git a/ss2010/gdi2/java/H1/.classpath b/ss2010/gdi2/java/H1/.classpath
new file mode 100644
index 00000000..18d70f02
--- /dev/null
+++ b/ss2010/gdi2/java/H1/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/ss2010/gdi2/java/H1/.project b/ss2010/gdi2/java/H1/.project
new file mode 100644
index 00000000..8960eae0
--- /dev/null
+++ b/ss2010/gdi2/java/H1/.project
@@ -0,0 +1,17 @@
+
+
+ GDI 2 U1
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/ss2010/gdi2/java/H1/.settings/org.eclipse.jdt.core.prefs b/ss2010/gdi2/java/H1/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..96b83ee9
--- /dev/null
+++ b/ss2010/gdi2/java/H1/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Thu Apr 22 09:55:02 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ss2010/gdi2/java/H1/bin/a.class b/ss2010/gdi2/java/H1/bin/a.class
new file mode 100644
index 00000000..0ea20724
Binary files /dev/null and b/ss2010/gdi2/java/H1/bin/a.class differ
diff --git a/ss2010/gdi2/java/H1/bin/selectionsort.class b/ss2010/gdi2/java/H1/bin/selectionsort.class
new file mode 100644
index 00000000..78481f8d
Binary files /dev/null and b/ss2010/gdi2/java/H1/bin/selectionsort.class differ
diff --git a/ss2010/gdi2/java/H1/src/mergesort.java b/ss2010/gdi2/java/H1/src/mergesort.java
new file mode 100644
index 00000000..571d7fb3
--- /dev/null
+++ b/ss2010/gdi2/java/H1/src/mergesort.java
@@ -0,0 +1,20 @@
+
+
+class a
+{
+
+public static int potenz(int basis, int exponent)
+{
+ if (exponent==1) return basis;
+
+ int temp = potenz(basis,exponent/2);
+ temp = temp*temp;
+
+ if ((exponent % 2) == 0) {
+ return temp;
+ } else {
+ return temp*basis;
+ }
+}
+
+}
diff --git a/ss2010/gdi2/java/H1/src/selectionsort.java b/ss2010/gdi2/java/H1/src/selectionsort.java
new file mode 100644
index 00000000..6febd78a
--- /dev/null
+++ b/ss2010/gdi2/java/H1/src/selectionsort.java
@@ -0,0 +1,67 @@
+
+public class selectionsort {
+
+ final static int[] data = {23,11,13,44,14,24,22,12,21,32,41,43,31,33,34,42};
+
+ public void selectionSort2(int[] x) {
+ for (int i=0; i x[j]) {
+ minIndex = j; // Remember index of new minimum
+ }
+ }
+ if (minIndex != i) {
+ //... Exchange current element with smallest remaining.
+ int temp = x[i];
+ x[i] = x[minIndex];
+ x[minIndex] = temp;
+
+ System.out.println("step: "+i+" "+minIndex+" number:"+temp+" "+x[i]);
+
+ printdata();
+ }
+ }
+ }
+
+
+ public void selectionSort(int[] x) {
+ for (int i=0; i x[j]) {
+ //... Exchange elements
+ int temp = x[i];
+ x[i] = x[j];
+ x[j] = temp;
+
+ System.out.println("step: "+i+" "+j+" number:"+temp+" "+x[i]);
+
+ printdata();
+ }
+ }
+ }
+ }
+
+ public void printdata()
+ {
+ String s = new String("{");
+
+ for(int i=0; i
+
+
+
+
+
diff --git a/ss2010/gdi2/java/H6/.project b/ss2010/gdi2/java/H6/.project
new file mode 100644
index 00000000..36733106
--- /dev/null
+++ b/ss2010/gdi2/java/H6/.project
@@ -0,0 +1,17 @@
+
+
+ H6 GDI
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/ss2010/gdi2/java/H6/.settings/org.eclipse.jdt.core.prefs b/ss2010/gdi2/java/H6/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..506edbea
--- /dev/null
+++ b/ss2010/gdi2/java/H6/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Wed Jun 02 10:07:28 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ss2010/gdi2/java/H6/bin/h6_6a_gdi.class b/ss2010/gdi2/java/H6/bin/h6_6a_gdi.class
new file mode 100644
index 00000000..5fc0373c
Binary files /dev/null and b/ss2010/gdi2/java/H6/bin/h6_6a_gdi.class differ
diff --git a/ss2010/gdi2/java/H6/src/h6_6a_gdi.java b/ss2010/gdi2/java/H6/src/h6_6a_gdi.java
new file mode 100644
index 00000000..022efbdf
--- /dev/null
+++ b/ss2010/gdi2/java/H6/src/h6_6a_gdi.java
@@ -0,0 +1,85 @@
+
+public class h6_6a_gdi {
+
+ //Die Adiazenzmatrix für ein Ungerichteten Graphen mit booleans dargestellt
+ public static final boolean[][] Adiazenz =
+ {{false, false, true, true, false },
+ {false, false, true, false, true },
+ {true, true, false, true, false },
+ {true, false, true, true, false },
+ {false, true, false, false, false }};
+
+ public boolean[][] calculate()
+ {
+ //Zähler für die Kanten
+ int connections = 0;
+
+ //Durchsuche obere Dreiecksmatrix der AidazenzMatrix
+ for(int i=0; i
+
+
+
+
+
+
diff --git a/ss2010/gdi2/java/Project0/.project b/ss2010/gdi2/java/Project0/.project
new file mode 100644
index 00000000..60e1a7c7
--- /dev/null
+++ b/ss2010/gdi2/java/Project0/.project
@@ -0,0 +1,17 @@
+
+
+ Project0
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/ss2010/gdi2/java/Project0/.settings/org.eclipse.jdt.core.prefs b/ss2010/gdi2/java/Project0/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..aacf42a8
--- /dev/null
+++ b/ss2010/gdi2/java/Project0/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Thu Apr 15 17:29:36 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ss2010/gdi2/java/Project0/bin/Contains.class b/ss2010/gdi2/java/Project0/bin/Contains.class
new file mode 100644
index 00000000..1f5b4a88
Binary files /dev/null and b/ss2010/gdi2/java/Project0/bin/Contains.class differ
diff --git a/ss2010/gdi2/java/Project0/bin/ContainsTest.class b/ss2010/gdi2/java/Project0/bin/ContainsTest.class
new file mode 100644
index 00000000..37276c8f
Binary files /dev/null and b/ss2010/gdi2/java/Project0/bin/ContainsTest.class differ
diff --git a/ss2010/gdi2/java/Project0/bin/ListFileReader.class b/ss2010/gdi2/java/Project0/bin/ListFileReader.class
new file mode 100644
index 00000000..7c67d352
Binary files /dev/null and b/ss2010/gdi2/java/Project0/bin/ListFileReader.class differ
diff --git a/ss2010/gdi2/java/Project0/countries.txt b/ss2010/gdi2/java/Project0/countries.txt
new file mode 100644
index 00000000..6bef82e7
--- /dev/null
+++ b/ss2010/gdi2/java/Project0/countries.txt
@@ -0,0 +1,246 @@
+Aegypten
+Aequatorialguinea
+Aethiopien
+Afghanistan
+Aland
+Albanien
+Algerien
+Amerikanisch-Samoa
+Amerikanische Jungferninseln
+Andorra
+Angola
+Anguilla
+Antarktis
+Antigua und Barbuda
+Argentinien
+Armenien
+Aruba
+Ascension
+Aserbaidschan
+Australien
+Bahamas
+Bahrain
+Bangladesch
+Barbados
+Belgien
+Belize
+Benin
+Bermuda
+Bhutan
+Bolivien
+Bosnien und Herzegowina
+Botswana
+Bouvetinsel
+Brasilien
+Britische Jungferninseln
+Britisches Territorium im Indischen Ozean
+Brunei
+Bulgarien
+Burkina Faso
+Burundi
+Chile
+China
+Cookinseln
+Costa Rica
+Cote d'Ivoire
+Daenemark
+Deutschland
+Die Kronkolonie St. Helena und Nebengebiete
+Diego Garcia
+Dominica
+Dominikanische Republik
+Dschibuti
+Ecuador
+El Salvador
+Eritrea
+Estland
+Europaeische Union
+Falklandinseln
+Fidschi
+Finnland
+Frankreich
+Franzoesisch-Guayana
+Franzoesisch-Polynesien
+Franzoesische Sued- und Antarktisgebiete
+Gabun
+Gambia
+Georgien
+Ghana
+Gibraltar
+Grenada
+Griechenland
+Gruenland
+Guadeloupe
+Guam
+Guatemala
+Guernsey
+Guinea
+Guinea-Bissau
+Guyana
+Haiti
+Heard und McDonaldinseln
+Honduras
+Hongkong
+Indien
+Indonesien
+Insel Mann
+Irak
+Iran
+Irland
+Island
+Israel
+Italien
+Jamaika
+Japan
+Jemen
+Jersey
+Jordanien
+Kaimaninseln
+Kambodscha
+Kamerun
+Kanada
+Kanarische Inseln
+Kap Verde
+Kasachstan
+Katar
+Kenia
+Kirgisistan
+Kiribati
+Kokosinseln
+Kolumbien
+Komoren
+Kongo
+Kongo
+Korea
+Korea
+Kosovo
+Kroatien
+Kuba
+Kuwait
+Laos
+Lesotho
+Lettland
+Libanon
+Liberia
+Libyen
+Liechtenstein
+Litauen
+Luxemburg
+Macao
+Madagaskar
+Malawi
+Malaysia
+Malediven
+Mali
+Malta
+Marokko
+Marshallinseln
+Martinique
+Mauretanien
+Mauritius
+Mayotte
+Mazedonien
+Mexiko
+Moldawien
+Monaco
+Mongolei
+Montenegro
+Montserrat
+Mosambik
+Myanmar
+Namibia
+Nauru
+Nepal
+Neukaledonien
+Neuseeland
+Neutrale Zone
+Nicaragua
+Niederlande
+Niederlanndische Antillen
+Niger
+Nigeria
+Niue
+Norfolkinsel
+Norwegen
+Noerdliche Marianen
+Oesterreich
+Oman
+Pakistan
+Palaestinensische Autonomiegebiete
+Palau
+Panama
+Papua-Neuguinea
+Paraguay
+Peru
+Philippinen
+Pitcairninseln
+Polen
+Portugal
+Puerto Rico
+Ruanda
+Rumänien
+Russland
+Salomonen
+Sambia
+Samoa
+San Marino
+Saudi-Arabien
+Schweden
+Schweiz
+Senegal
+Serbien
+Seychellen
+Sierra Leone
+Simbabwe
+Singapur
+Slowakei
+Slowenien
+Somalia
+Spanien
+Sri Lanka
+St. Kitts und Nevis
+St. Lucia
+St. Pierre und Miquelon
+St. Vincent und die Grenadinen (GB)
+Sudan
+Suedafrika
+Suriname
+Svalbard und Jan Mayen
+Swasiland
+Syrien
+Suedgeorgien und die Suedlichen Sandwichinseln
+Tadschikistan
+Taiwan
+Tansania
+Thailand
+Timor-Leste
+Togo
+Tokelau
+Tonga
+Trinidad und Tobago
+Tristan da Cunha
+Tschad
+Tschechische
+Tuerkei
+Tunesien
+Turkmenistan
+Turks- und Caicosinseln
+Tuvalu
+Uganda
+Ukraine
+Ungarn
+Uruguay
+Usbekistan
+Vanuatu
+Vatikanstadt
+Venezuela
+Vereinigte Arabische Emirate
+Vereinigte Staaten von Amerika
+Vereinigtes Koenigreich von Grossbritannien und Nordirland
+Vietnam
+Wallis und Futuna
+Weihnachtsinsel
+Weißrussland
+Westsahara
+Zentralafrikanische Republik
+Zypern
diff --git a/ss2010/gdi2/java/Project0/src/Contains.java b/ss2010/gdi2/java/Project0/src/Contains.java
new file mode 100644
index 00000000..9aa7ba7c
--- /dev/null
+++ b/ss2010/gdi2/java/Project0/src/Contains.java
@@ -0,0 +1,146 @@
+/*******************************************************************
+ * Gruppe: Timo Singer, Michael Scholz, Ulf Gebhardt
+ *
+ *******************************************************************
+ *
+ * Questions / Fragen
+ *******************************************************************
+ * a) How does the measured performance of contains_fast and
+ * contains_lecture relate to each other? Explain the result!
+ *
+ * Wie verh�lt sich die gemessene Laufzeit von den Methoden
+ * contains_fast und contains_lecture zu einander?
+ * Erkl�ren Sie das Ergebnis!
+ * ----------------------------------------------------------------
+ *
+ * contains_fast ist circa doppelt (2x) so schnell, ben�tigt also in etwa
+ * die H�lfte der Zeit, die contains_lecture ben�tigt.
+ *
+ * Dieses Verhalten l�sst sich dadurch erkl�ren, dass das gesuchte Element
+ * im Mittel in der Mitte der Liste liegt, d.h. die for-schleife in
+ * contains_fast (im Mittel = f�r sehr viele Aufrufe) schon nach der H�lfte
+ * abbricht, da das Element gefunden wurde und die funktion mit return
+ * verlassen wird.
+ *
+ * Vergleich der Funktionen:
+ *
+ * Eingabemenge Funktion Schleifendurchl�ufe
+ * n contains_lecture n (jedes mal)
+ * n contains_fast n/2 (im Durchschnitt!)
+ * ----------------------------------------------------------------
+ * b) The method contains_java calls the predefined Java contains
+ * function for Lists. How does contains_java perform compared to
+ * the other methods? Do you have an idea, why?
+ *
+ * Die Methode contains_java ruft die in der Java-API vordefinierte
+ * contains-Funktion f�r Listen auf. Wie verh�lt sich die Laufzeit
+ * von contains_java zu den anderen? Was k�nnte der Grund sein?
+ * ----------------------------------------------------------------
+ *
+ * contains_java ist nochmal schneller als contains_fast.
+ *
+ * D.h, wenn man alle 3 Funktionen vergleicht, dann gilt f�r die Laufzeit
+ * im Durchschnitt:
+ *
+ * Laufzeit (im Durchschnitt):
+ *
+ * contains_lecture > contains_fast > contains_java
+ *
+ * contains_java ist schneller als contains_fast, da die f�r Listen
+ * in der Java-API definierte Funktion einen noch effizienteren
+ * Suchalgorithmus benutzt, als contains_fast.
+ *
+ * Wir vermuten, dass als Suchalgorithmus die Bin�re-Suche eingesetzt wird.
+ * Diese hat eine Komplexit�t von O(log(n)), im Gegensatz zu O(n) f�r
+ * contains_lecture & contains_fast.
+ *
+ * Eine andere Erkl�rungsm�glichkeit, warum contains_java schneller ist, ist
+ * dass die List-Klasse intern Hashing vornimmt. Dies f�hrt im Durchschnitt
+ * zu einem O(1), im schlechtesten Fall allerdings zu O(n).
+ *
+ *******************************************************************/
+import java.util.List;
+import java.util.Random;
+
+
+/**
+ * This class offers three different implementations of the "contains" method.
+ * Each method takes a list of strings and a string and checks whether the
+ * string is contained in the list.
+ */
+public class Contains {
+
+ /**
+ * Calls the "contains"-function predefined by the Java List class.
+ *
+ * @param list A list of strings
+ * @param element A single string
+ * @return True if element is contained in list, false otherwise.
+ */
+ public boolean contains_java(List list, String element) {
+ return list.contains(element);
+ }
+
+
+ /**
+ * The contains function as defined in the lecture
+ * (Slide set 3, page 11).
+ *
+ * @param list A list of strings
+ * @param element A single string
+ * @return True if element is contained in list, false otherwise.
+ */
+ public boolean contains_lecture(List list, String element) {
+ boolean found = false;
+ for (String s : list) {
+ if (s.equals(element)) {
+ found = true;
+ }
+ }
+ return found;
+ }
+
+ /**
+ * Implemented a small optimization for the contains function
+ * defined in the lecture: As soon as the element is found,
+ * true is returned and iteration stops
+ *
+ * @param list A list of strings
+ * @param element A single string
+ * @return True if element is contained in list, false otherwise.
+ */
+ public boolean contains_fast(List list, String element) {
+ for (String s : list) {
+ if (s.equals(element)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Reads a list and performs a lot of random lookups using the three
+ * contains methods defined above. The elements looked for are
+ * randomly chosen from the list beforehand.
+ *
+ * @param argv not used
+ */
+ public static void main(String[] argv) {
+ Contains c = new Contains();
+ // Reads a long list of strings
+ ListFileReader fr = new ListFileReader("countries.txt");
+ // Random number generator
+ Random rand = new Random();
+ List list = fr.getList();
+ int length = list.size();
+
+ for (int i=0; i<5000; i++) {
+ // Read a random string from the list
+ String string = list.get(rand.nextInt(length));
+ // Check whether the string is contained (should always return true)
+ c.contains_lecture(list, string);
+ c.contains_fast(list, string);
+ c.contains_java(list, string);
+ }
+ }
+}
diff --git a/ss2010/gdi2/java/Project0/src/ListFileReader.java b/ss2010/gdi2/java/Project0/src/ListFileReader.java
new file mode 100644
index 00000000..48b4e51f
--- /dev/null
+++ b/ss2010/gdi2/java/Project0/src/ListFileReader.java
@@ -0,0 +1,44 @@
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+public class ListFileReader{
+
+ private String filename = null;
+ private List dataList = null;
+
+ public ListFileReader(String filename) {
+ this.filename = filename;
+ this.dataList = new LinkedList();
+ readFile();
+ }
+
+ public void readFile() {
+ try {
+ FileReader fr = new FileReader(filename);
+ BufferedReader in = new BufferedReader(fr);
+ String line;
+ while((line = in.readLine())!=null) {
+ dataList.add(line);
+ for (int i=0; i<100; i++) {
+ dataList.add(line + i);
+ }
+ }
+
+ in.close();
+ fr.close();
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public List getList(){
+ return dataList;
+ }
+}
diff --git a/ss2010/gdi2/java/Project0/tests/ContainsTest.java b/ss2010/gdi2/java/Project0/tests/ContainsTest.java
new file mode 100644
index 00000000..97d6e0e6
--- /dev/null
+++ b/ss2010/gdi2/java/Project0/tests/ContainsTest.java
@@ -0,0 +1,69 @@
+import static org.junit.Assert.*;
+import java.util.LinkedList;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ContainsTest {
+
+ static ListFileReader fr = null;
+ static Contains c = null;
+ static String myCountry = null;
+ static String noCountry = null;
+
+
+ @BeforeClass
+ public static void init() {
+ c = new Contains();
+ fr = new ListFileReader("countries.txt");
+ myCountry = "Senegal";
+ noCountry = "12345";
+ }
+
+ @Test
+ public void testJavaContainsTrue() {
+ assertTrue(c.contains_java(fr.getList(), myCountry));
+ }
+
+ @Test
+ public void testJavaContainsFalse() {
+ assertFalse(c.contains_java(fr.getList(), noCountry));
+ }
+
+ @Test
+ public void testJavaContainsEmptyList() {
+ assertFalse(c.contains_java(new LinkedList(), noCountry));
+ }
+
+ @Test
+ public void testLectureContainsTrue() {
+ assertTrue(c.contains_lecture(fr.getList(), myCountry));
+ }
+
+ @Test
+ public void testLectureContainsFalse() {
+ assertFalse(c.contains_lecture(fr.getList(), noCountry));
+ }
+
+ @Test
+ public void testLectureContainsEmptyList() {
+ assertFalse(c.contains_lecture(new LinkedList(), noCountry));
+ }
+
+ @Test
+ public void testFastContainsTrue() {
+ assertTrue(c.contains_fast(fr.getList(), myCountry));
+ }
+
+ @Test
+ public void testFastContainsFalse() {
+ assertFalse(c.contains_fast(fr.getList(), noCountry));
+ }
+
+ @Test
+ public void testFastContainsEmptyList() {
+ assertFalse(c.contains_fast(new LinkedList(), noCountry));
+ }
+
+
+}
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project1/.classpath b/ss2010/gdi2/java/Project1/.classpath
new file mode 100644
index 00000000..b10b8d9b
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/ss2010/gdi2/java/Project1/.project b/ss2010/gdi2/java/Project1/.project
new file mode 100644
index 00000000..627aed82
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/.project
@@ -0,0 +1,17 @@
+
+
+ Project1
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/ss2010/gdi2/java/Project1/.settings/org.eclipse.jdt.core.prefs b/ss2010/gdi2/java/Project1/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..3f5531bc
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Sat May 08 11:41:49 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ss2010/gdi2/java/Project1/bin/CapacityExceededException.class b/ss2010/gdi2/java/Project1/bin/CapacityExceededException.class
new file mode 100644
index 00000000..8eccafb2
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/CapacityExceededException.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/ObjectAlreadyPresentException.class b/ss2010/gdi2/java/Project1/bin/ObjectAlreadyPresentException.class
new file mode 100644
index 00000000..3205e615
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/ObjectAlreadyPresentException.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/ObjectNotPresentException.class b/ss2010/gdi2/java/Project1/bin/ObjectNotPresentException.class
new file mode 100644
index 00000000..d6d472f5
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/ObjectNotPresentException.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/PackingObject.class b/ss2010/gdi2/java/Project1/bin/PackingObject.class
new file mode 100644
index 00000000..778b5704
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/PackingObject.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/Rucksack.class b/ss2010/gdi2/java/Project1/bin/Rucksack.class
new file mode 100644
index 00000000..f3312d2d
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/Rucksack.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/RucksackProblem.class b/ss2010/gdi2/java/Project1/bin/RucksackProblem.class
new file mode 100644
index 00000000..0be75efb
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/RucksackProblem.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/RucksackProblemTest.class b/ss2010/gdi2/java/Project1/bin/RucksackProblemTest.class
new file mode 100644
index 00000000..31066f3e
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/RucksackProblemTest.class differ
diff --git a/ss2010/gdi2/java/Project1/bin/abc.class b/ss2010/gdi2/java/Project1/bin/abc.class
new file mode 100644
index 00000000..7bbb73b0
Binary files /dev/null and b/ss2010/gdi2/java/Project1/bin/abc.class differ
diff --git a/ss2010/gdi2/java/Project1/src/CapacityExceededException.java b/ss2010/gdi2/java/Project1/src/CapacityExceededException.java
new file mode 100644
index 00000000..3f60af24
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/src/CapacityExceededException.java
@@ -0,0 +1,6 @@
+
+public class CapacityExceededException extends RuntimeException {
+
+ private static final long serialVersionUID = -3768115092191702079L;
+
+}
diff --git a/ss2010/gdi2/java/Project1/src/ObjectAlreadyPresentException.java b/ss2010/gdi2/java/Project1/src/ObjectAlreadyPresentException.java
new file mode 100644
index 00000000..fe4fb0c6
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/src/ObjectAlreadyPresentException.java
@@ -0,0 +1,6 @@
+
+public class ObjectAlreadyPresentException extends RuntimeException {
+
+ private static final long serialVersionUID = -6499002999657327239L;
+
+}
diff --git a/ss2010/gdi2/java/Project1/src/ObjectNotPresentException.java b/ss2010/gdi2/java/Project1/src/ObjectNotPresentException.java
new file mode 100644
index 00000000..39bcdd85
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/src/ObjectNotPresentException.java
@@ -0,0 +1,6 @@
+
+public class ObjectNotPresentException extends RuntimeException {
+
+ private static final long serialVersionUID = 1870950568231197185L;
+
+}
diff --git a/ss2010/gdi2/java/Project1/src/PackingObject.java b/ss2010/gdi2/java/Project1/src/PackingObject.java
new file mode 100644
index 00000000..dc26099e
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/src/PackingObject.java
@@ -0,0 +1,80 @@
+/**
+ * An object that can be put into a Rucksack. Each PackingObject
+ * has a value and a weight.
+ *
+ * Each PackingObject also has a unique index, which you can use
+ * for an optimized storing of PackingObjects in a Rucksack.
+ *
+ * @author Johannes Kinder
+ */
+public class PackingObject {
+
+ private static int maxIndex = 0;
+
+ /**
+ * Returns the number of PackingObjects that have been created.
+ * All test cases ensure that all PackingObjects have been created
+ * before the first Rucksack object is created. Therefore, you can safely
+ * use this function to get the total number of PackingObjects.
+ *
+ * @return the number of packing objects that have been created.
+ */
+ public static int getTotalNumberOfObjects() {
+ return maxIndex;
+ }
+
+ /**
+ * This is used by the test cases to reset the counter for PackingObjects.
+ */
+ public static void reset() {
+ maxIndex = 0;
+ }
+
+ private final int value;
+ private final int weight;
+ private final int index;
+
+ public PackingObject(int value, int weight) {
+ this.value = value;
+ this.weight = weight;
+ this.index = maxIndex++;
+ }
+
+ /**
+ * Returns the unique index of this PackingObject.
+ *
+ * @return index
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the value of this PackingObject.
+ *
+ * @return value
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Returns the weight of this PackingObject.
+ *
+ * @return weight
+ */
+ public int getWeight() {
+ return weight;
+ }
+
+ /**
+ * Creates a string representation of this PackingObject of the
+ * form (value,weight).
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append('(').append(getValue()).append(',').append(getWeight()).append(')');
+ return sb.toString();
+ }
+}
diff --git a/ss2010/gdi2/java/Project1/src/Rucksack.java b/ss2010/gdi2/java/Project1/src/Rucksack.java
new file mode 100644
index 00000000..f8c276d5
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/src/Rucksack.java
@@ -0,0 +1,215 @@
+import java.util.ArrayList;
+
+/**
+ * The Rucksack class represents a rucksack that holds objects
+ * of type PackingObject. Implement the predefined interface and
+ * use it from RucksackProblem.java to solve a Rucksack problem
+ * instance.
+ */
+public class Rucksack {
+
+ /**
+ * Max capacity of the rucksack.
+ *
+ * Is Initialized with 0
+ */
+ private int m_capacity = 0;
+
+ /**
+ * Current Value of all Objects in rucksack
+ *
+ * Initialized with 0
+ */
+ private int m_currentValue = 0;
+
+ /**
+ * Current Weight of all Objects in rucksack.
+ *
+ * Initialized with 0
+ */
+ private int m_currentWeight = 0;
+
+ /**
+ * ObjectList
+ *
+ * Is initialized. (empty)
+ */
+ //private LinkedList m_objects = new LinkedList();
+ private ArrayList m_objects = new ArrayList();
+
+ /**
+ * Do NOT MODIFY!!! -> For Copying and reading only
+ * @return
+ */
+ public ArrayList getObjects() {
+ return m_objects;
+ }
+
+ /**
+ * Initializes a new Rucksack object with a given capacity.
+ * Sets up all required data structures.
+ *
+ * @param capacity The capacity of the Rucksack.
+ */
+ public Rucksack(int capacity) {
+ if(capacity >= 0)
+ {
+ this.m_capacity = capacity;
+ } else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /**
+ * Inserts an object into the Rucksack.
+ *
+ * @param o The object to be added.
+ * @throws ObjectAlreadyPresentException if the object is already present.
+ * @throws CapacityExceededException if the capacity is exceeded by the
+ * new object.
+ */
+ void putObject(PackingObject o) {
+ if(this.getTotalCapacity() >= this.getTotalWeight() + o.getWeight())
+ {
+ if(!this.contains(o))
+ {
+ this.m_objects.add(o);
+
+ this.m_currentWeight += o.getWeight();
+ this.m_currentValue += o.getValue();
+ } else
+ {
+ throw new ObjectAlreadyPresentException();
+ }
+ } else
+ {
+ throw new CapacityExceededException();
+ }
+ }
+
+ /**
+ * Removes an object from the Rucksack.
+ *
+ * @param o The object to be removed.
+ * @throws ObjectNotPresentException if the object is not in the rucksack.
+ */
+ void removeObject(PackingObject o) {
+ if(this.m_objects.remove(o))
+ {
+ this.m_currentValue -= o.getValue();
+ this.m_currentWeight -= o.getWeight();
+ } else
+ {
+ throw new ObjectNotPresentException();
+ }
+ }
+
+ /**
+ * Checks whether an object is contained in the Rucksack
+ *
+ * @param o The object to check for.
+ * @return True if the object is present, false otherwise.
+ */
+ public boolean contains(PackingObject o) {
+ return this.m_objects.contains(o);
+ }
+
+ /**
+ * Returns the total weight of all objects in the rucksack.
+ *
+ * @return total weight
+ */
+ public int getTotalWeight() {
+ /*int result = 0;
+
+ for(int i = 0; i < this.m_objects.size(); i++)
+ {
+ result +=this.m_objects.get(i).getWeight();
+ }
+
+ return result;*/
+
+ return this.m_currentWeight;
+ }
+
+ /**
+ * Returns the total value of all objects in the rucksack.
+ *
+ * @return total value
+ */
+ public int getTotalValue() {
+
+ /*int result = 0;
+
+ for(int i = 0; i < this.m_objects.size(); i++)
+ {
+ result +=this.m_objects.get(i).getValue();
+ }
+
+ return result;*/
+
+ return this.m_currentValue;
+ }
+
+ /**
+ * Returns the initial capacity of the rucksack.
+ *
+ * @return total capacity
+ */
+ public int getTotalCapacity() {
+ return this.m_capacity;
+ }
+
+ /**
+ * Returns the capacity of the Rucksack still available.
+ *
+ * @return available capacity
+ */
+ public int getAvailableCapacity() {
+ return this.getTotalCapacity() - this.getTotalWeight();
+ }
+
+ /**
+ * Copies the contents of another Rucksack to this Rucksack.
+ *
+ * @param other The Rucksack to copy from.
+ */
+ @SuppressWarnings("unchecked")
+ public void copyFrom(Rucksack other) {
+ if(other != null)
+ {
+ this.m_capacity = other.getTotalCapacity();
+ this.m_objects = (ArrayList) other.getObjects().clone();
+ this.m_currentWeight = other.getTotalWeight();
+ this.m_currentValue = other.getTotalValue();
+ }
+ }
+
+ /**
+ * Prints all objects in this Rucksack by iterating over a list of
+ * passed PackingObjects and checking for each object whether it
+ * is in the Rucksack using contains().
+ *
+ * You can use this function for debugging purposes.
+ *
+ * @param objects The complete list of objects that might be in the
+ * rucksack
+ * @return A string of the format [(value1,weight1), (value2,weight2), ...]
+ */
+ public String toString(PackingObject[] objects) {
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (PackingObject object : objects) {
+ if (contains(object)){
+ sb.append(object.toString()).append(", ");
+ }
+ }
+ if (sb.length() > 1) {
+ sb.delete(sb.length() - 2, sb.length());
+ }
+
+ sb.append(']');
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project1/src/RucksackProblem.java b/ss2010/gdi2/java/Project1/src/RucksackProblem.java
new file mode 100644
index 00000000..fdb73502
--- /dev/null
+++ b/ss2010/gdi2/java/Project1/src/RucksackProblem.java
@@ -0,0 +1,246 @@
+/*******************************************************************
+ * Questions / Fragen
+ *******************************************************************
+ * a) What are the asymptotic time complexities T(n) of the
+ * recursive and iterative versions of the algorithm, with n being
+ * the total number of available packing objects? State your answer
+ * in big-Oh notation.
+ *
+ * Was sind die Laufzeitkomplexit�ten T(n) der rekursiven und der
+ * iterativen Version des Algorithmus, wobei n die Anzahl der
+ * packbaren Objekte ist? Geben Sie die Komplexit�t in O-Notation an.
+ * ----------------------------------------------------------------
+ *
+ * Iterativ: solveIterative = O()
+ *
+ * Recursiv: solveRecursive = O()
+ * ----------------------------------------------------------------
+ * b) Use TPTP to profile RucksackProblem.main(). Try different
+ * values for the variable numObjects in main() and measure the
+ * total execution time of solveRecursive(int) and solveIterative,
+ * and the number of recursive calls to solveRecursive. To what
+ * problem size can you go on your machine?
+ * Enter at least 5 different, meaningful runs in the table below.
+ *
+ * Verwenden Sie TPTP um RucksackProblem.main() zu profilen.
+ * Probieren Sie verschiedene Werte f�r die Variable numObjects in
+ * main() aus und messen Sie die Laufzeit von solveRecursive(int)
+ * und solveIterative sowie die Anzahl der rekursiven Aufrufe von
+ * solveRecursive(int). Bis zu welcher Gr��e k�nnen Sie auf Ihrem
+ * Rechner gehen? Tragen Sie mindestens
+ * 5 verschiedene, aussagekr�ftige Resultate in der Tabelle ein.
+ * ----------------------------------------------------------------
+ *
+ *
+ * numObj | Cumul. time (iter)| Cumul. time (rec) | Recursive calls
+ * ---------+-------------------+-------------------+----------------
+ * 5 | | |
+ * 7 | | |
+ * 10 | | |
+ * 12 | | |
+ * 15 | | |
+ * 18 | | |
+ *
+ *******************************************************************/
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.Random;
+
+/**
+ * A class describing an instance of the Rucksack problem. A call to the
+ * constructor initializes the problem, and a call to solve() starts a
+ * recursive search.
+ */
+public class RucksackProblem {
+
+ private PackingObject[] objects;
+
+ private Rucksack init_rucksack = null;
+ private Rucksack best_rucksack = null;
+
+ /**
+ * The constructor initializes the class with a set of objects to pack
+ * and a rucksack of a given capacity.
+ *
+ * @param objects An array of PackingObjects to store optimally in the
+ * rucksack
+ * @param rucksack A Rucksack that has been initialized with some
+ * capacity
+ */
+ public RucksackProblem(PackingObject[] objects, Rucksack rucksack) {
+
+ //check objects
+ for(int i=0; i< objects.length; i++)
+ {
+ if(objects[i].getValue() < 0 ||
+ objects[i].getWeight() < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ //Check rucksack
+ if(rucksack == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //Initialize Data
+ this.objects = objects;
+ this.init_rucksack = rucksack;
+ this.best_rucksack = new Rucksack(0);
+ }
+
+ public Rucksack getOptimalRucksack() {
+ return this.best_rucksack;
+ }
+
+ public PackingObject[] getAllObjects() {
+ return objects;
+ }
+
+ /**
+ * Start the recursive algorithm to solve the Rucksack problem at
+ * the 0-th object.
+ */
+ public void solveRecursive() {
+ solveRecursive(0);
+ }
+
+ /**
+ * The recursive algorithm. Do not use loops here, implement only
+ * using recursive calls.
+ *
+ * For every object, tries to solve the rest of the problem both
+ * with the object and without the object using recursive calls
+ * to solveRecursive(i+1).
+ *
+ * @param i the current position in the object array.
+ */
+ private void solveRecursive(int i) {
+ if(i >= this.objects.length)
+ {
+ //Anchor -> No Objects left in Array
+ return;
+ } else
+ {
+ //Solve without the actual object
+ solveRecursive(i+1);
+
+ try
+ {
+ //Put Object into Rucksack if possible
+ this.init_rucksack.putObject(this.objects[i]); //throws
+
+ //Is New Rucksack better then the old?
+ if(init_rucksack.getTotalValue() > best_rucksack.getTotalValue())
+ {
+ this.best_rucksack.copyFrom(this.init_rucksack);
+ }
+ //Solve with object
+ solveRecursive(i+1);
+
+ //Remove Object again -> so all cases are covered
+ this.init_rucksack.removeObject(this.objects[i]); //can not throw -> object is in list
+
+ //Catch Exceptions if putObject fails
+ } catch(ObjectAlreadyPresentException e1){}
+ catch(CapacityExceededException e2){}
+ }
+ }
+
+ /**
+ * The iterative version of the algorithm. Do not include any
+ * recursive calls, but implement it using a loop and a stack.
+ *
+ * Loop:
+ * Have we processed all objects?
+ * Stop if there are no backtracking points left
+ * Else backtrack to last object that was put into rucksack
+ * Remove it and continue with next object
+ *
+ * Does the object still fit into the available capacity?
+ * Put object into rucksack
+ * Remember this object as a backtracking point
+ * Remember if the new rucksack is the best we know
+ *
+ * Continue loop with next object
+ */
+ public void solveIterative() {
+
+ // A stack to use with the algorithm
+ Deque stack = new LinkedList();
+
+ // The current position in the array of objects
+ int i = 0;
+
+ //Do till done
+ while(true)
+ {
+ //Still objects in array?
+ if(i < this.objects.length)
+ {
+ try
+ {
+ //Put Object into Rucksack if possible
+ this.init_rucksack.putObject(this.objects[i]); //throws
+
+ //Put current Index to stack to allow backtracking
+ stack.push(i);
+
+ //Is New Rucksack better then the old?
+ if(init_rucksack.getTotalValue() > best_rucksack.getTotalValue())
+ {
+ this.best_rucksack.copyFrom(this.init_rucksack);
+ }
+
+ //Catch Exceptions if putObject fails
+ } catch(ObjectAlreadyPresentException e1){}
+ catch(CapacityExceededException e2){}
+
+ i++; //Move to next Object
+ } else
+ {
+ try
+ {
+ //get index of backtracking element from stack
+ int obj = stack.pop(); //throws when empty
+
+ //remove the object
+ this.init_rucksack.removeObject(this.objects[obj]);
+
+ //start search with objects excluding the obj from the stack
+ i = obj +1;
+
+ //Catch exception when stack is empty
+ } catch(NoSuchElementException e1)
+ {
+ //All cases covered
+ return;
+ }
+ }
+
+ }
+ }
+
+ public static void main(String[] argv) {
+ int numObjects = 5;
+
+ PackingObject[] objects = new PackingObject[numObjects];
+ Random rand = new Random();
+ for (int i=0; i
+
+
+
+
+
+
+
diff --git a/ss2010/gdi2/java/Project2/.project b/ss2010/gdi2/java/Project2/.project
new file mode 100644
index 00000000..feda5236
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/.project
@@ -0,0 +1,17 @@
+
+
+ P2
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/ss2010/gdi2/java/Project2/.settings/org.eclipse.jdt.core.prefs b/ss2010/gdi2/java/Project2/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..a286470b
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Tue May 25 15:12:57 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ss2010/gdi2/java/Project2/bin/Puzzle.class b/ss2010/gdi2/java/Project2/bin/Puzzle.class
new file mode 100644
index 00000000..19765129
Binary files /dev/null and b/ss2010/gdi2/java/Project2/bin/Puzzle.class differ
diff --git a/ss2010/gdi2/java/Project2/bin/PuzzleAStar.class b/ss2010/gdi2/java/Project2/bin/PuzzleAStar.class
new file mode 100644
index 00000000..89c0cd24
Binary files /dev/null and b/ss2010/gdi2/java/Project2/bin/PuzzleAStar.class differ
diff --git a/ss2010/gdi2/java/Project2/bin/PuzzleFileFormatException.class b/ss2010/gdi2/java/Project2/bin/PuzzleFileFormatException.class
new file mode 100644
index 00000000..1e58fe38
Binary files /dev/null and b/ss2010/gdi2/java/Project2/bin/PuzzleFileFormatException.class differ
diff --git a/ss2010/gdi2/java/Project2/bin/PuzzleInputOutput.class b/ss2010/gdi2/java/Project2/bin/PuzzleInputOutput.class
new file mode 100644
index 00000000..39471fc5
Binary files /dev/null and b/ss2010/gdi2/java/Project2/bin/PuzzleInputOutput.class differ
diff --git a/ss2010/gdi2/java/Project2/bin/PuzzleMove.class b/ss2010/gdi2/java/Project2/bin/PuzzleMove.class
new file mode 100644
index 00000000..11ab08ce
Binary files /dev/null and b/ss2010/gdi2/java/Project2/bin/PuzzleMove.class differ
diff --git a/ss2010/gdi2/java/Project2/bin/PuzzleTest.class b/ss2010/gdi2/java/Project2/bin/PuzzleTest.class
new file mode 100644
index 00000000..50a74805
Binary files /dev/null and b/ss2010/gdi2/java/Project2/bin/PuzzleTest.class differ
diff --git a/ss2010/gdi2/java/Project2/puzzle testcases.7z b/ss2010/gdi2/java/Project2/puzzle testcases.7z
new file mode 100644
index 00000000..2489ebab
Binary files /dev/null and b/ss2010/gdi2/java/Project2/puzzle testcases.7z differ
diff --git a/ss2010/gdi2/java/Project2/src/Puzzle.java b/ss2010/gdi2/java/Project2/src/Puzzle.java
new file mode 100644
index 00000000..57331166
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/src/Puzzle.java
@@ -0,0 +1,171 @@
+import java.io.IOException;
+
+/***********************************************************************************
+ * Task / Aufgabe
+ ***********************************************************************************
+ * * Implement the A* algorithm to solve the puzzle problem known from
+ * the exercises. Use the following heuristic to calculate the distance:
+ *
+ * - The distance from start is the number of steps needed to reach the current
+ * state, e.g., the direct neighbour state has distance 1 and so on.
+ * - The distance to destination is the number of blocks on wrong positions, e.g.,
+ * 1 2 3 1 2 3
+ * 4 5 6 4 5 6
+ * 8 7 # 7 8 #
+ * (start) (destination)
+ * The distance from start to destination would be 2. (Note: start cannot be solved.)
+ * (7 and 8 are on wrong positions)
+ * Hints: When testing, be aware that some puzzle states cannot be solved.
+ * Try not to consider predecessor states, since they have already
+ * been processed.
+ *
+ * * Implementieren Sie den A* Algorithmus, um das in den Übungen behandelte Puzzle
+ * Problem zu lösen.
+ * Verwenden Sie folgende Heuristik für die Berechnung der Entfernungskosten:
+ *
+ * - Die Entfernung vom Startknoten ist die Anzahl der benötigten Schritte
+ * bis zum aktuellen Zustand, z.B. der unmittelbare Nachbarzustand hat
+ * die Entfernung 1, usw.
+ * - Die Entfernung zum Zielknoten ist die Anzahl der Puzzleteile,
+ * die an den falschen Positionen sind, z.B.
+ * 1 2 3 1 2 3
+ * 4 5 6 4 5 6
+ * 8 7 # 7 8 #
+ * (Start) (Ziel)
+ * The Entfernung zwischen Start und Ziel wäre 2.(Achtung: Start ist unlösbar.)
+ * (7 und 8 sind an falschen Positionen)
+ * Hinweise: Achten Sie beim Testen, dass bestimmte Zust�nde möglicherweise
+ * nicht lösbar sind. Versuchen Sie die Vorgängerzustände nicht zu
+ * betrachten, da sie ja schon bearbeitet wurden.
+ ***********************************************************************************/
+
+/***********************************************************************************
+ * Questions / Fragen
+ ***********************************************************************************
+ *
+ * ----------------------------------------------------------------
+ * a) Choose and implement another two heuristics to calculate the distance,
+ * e.g., one could use the heuristic introduced in the exercises or similar
+ * versions of it.
+ * Use TPTP to profile Puzzle.main() with all three heuristics.
+ * i) Which heuristic did you choose? Why? Discuss them.
+ * Which heuristic was the best?
+ * ii) What was the largest puzzle (NxN) used?
+ *
+ * Enter at least 5 different, meaningful runs in the table below.
+ *
+ * a) W�hlen und implementieren Sie zwei zus�tzliche Heuristiken f�r die
+ * Berechnung der Enfernungskosten. Sie k�nnen z.B. die in der �bung
+ * vorgestellte Heuristik verwenden, oder �hnliches.
+ * Verwenden Sie TPTP um Puzzle.main() zu profilen.
+ * i) Welche Heuristiken haben Sie gew�hlt? Wieso? Diskutieren Sie sie.
+ * Welche Heuristik war die beste?
+ * ii) Welche Gr��e(NxN) hatten die verwendeten Puzzles?
+ *
+ * Tragen Sie mindestens 5 verschiedene, aussagekr�ftige Resultate in der Tabelle ein.
+ * ----------------------------------------------------------------
+ *
+ * Heuristik 1: Anzahl der Elemente an der falschen Position
+ * O(n^2); n = puzzlesize
+ *
+ * Heuristik 2: Entfernung der einzelnen Elemente von ihrer Position zur
+ * Zielposition. Berechnet �ber ganze Felder:
+ * x-distance + y-distance.
+ * Diese Werte werden f�r alle Elemente in einem PuzzleMove
+ * aufaddiert.
+ * O(n^4); n = puzzlesize
+ *
+ * Heuristik 3: Entfernung der einzelnen Elemente von ihrer Position zur
+ * Zielposition. Berechnet �ber Pythagoras:
+ * sqrt(x-distance^2 + y-distance^2)
+ * Diese Werte werden f�r alle Elemente in einem PuzzleMove
+ * aufaddiert.
+ * O(n^4); n = puzzlesize
+ *
+ * Es hat sich herausgestellt, das Heuristik 2 trotz h�herer Komplexit�t
+ * im Vergleich zu Heuristik 1 deutlich besser ist, da die Absch�tzung
+ * genauer ist. Dadurch m�ssen weniger Schritte genommen werden um die L�sung
+ * zu finden.
+ *
+ * Heuristik 1 ist am ungenausten, ben�tigt deshalb deutlich mehr Schritte als
+ * Heuristik 2 & 3. Sie ist allerdings trozdem schneller als Heuristik3, da
+ * die Komplexit�t von Heuristik1 wesentlich besser ist als die von heuristik3
+ * O(n^2) -> O(n^4)
+ *
+ * Heuristik 3 ist genauer als Heuristik 1 aber ungenauer als Heuristik 2. Dies
+ * resultiert aus der Diagonalen-Sch�tzung, welche nicht den Spielz�gen entspricht,
+ * sondern eine rein mathematische Anschauung ist.
+ * Heuristik 3 hat sich am Zeitintensivsten erwiesen. O(n^4)
+ *
+ * Im ganzen ist Heuristik2 f�r die von uns getesten F�lle die beste Wahl,
+ * da hier in k�rzester Zeit und mit am wenigsten Schritten das Ergebnis gefunden
+ * wird trotz schlechterer Komplexit�t O(n^4).
+ * Bei kleinen oder einfachen Puzzels zeigt sich allerdings kaum ein Unterschied.
+ * Heuristik2 ist die genauste Sch�tzung (abzulesen an den genommen Schritten).
+ *
+ *
+ * | heuristic 1 | heuristic 2 | heuristic 3
+ * -------------+-------+-----------+-------+-----------+-------+--------
+ * NxN puzzle | ms | steps | ms | steps | ms | steps
+ * -------------+-------+-----------+-------+-----------+-------+--------
+ * 3x3 test_00 | 15303 8717 | 2246 1474 | 26096 3972 (Vorlage test_0.txt)
+ * 3x3 test_02 | 15383 8717 | 2165 1474 | 26022 3972 (Haus�bung)
+ * 3x3 test_03 | 2 5 | 3 5 | 2 5
+ * 4x4 test_04 | 28 143 | 49 102 | 201 134
+ * 4x4 test_05 | 2 3 | 3 3 | 2 3
+ *
+ * ms - time needed to find the solution
+ * steps - steps needed to reach the destination
+ ***********************************************************************************/
+
+/**
+ * The class from where the puzzle is loaded and prepared for processing
+ */
+
+public class Puzzle extends PuzzleAStar
+{
+ /**
+ * Initialise the puzzle states (Start and Destination)
+ *
+ * @param start
+ * @param destination
+ */
+ public Puzzle (PuzzleMove start, PuzzleMove destination)
+ {
+ setStartState(start);
+ setDestinationState(destination);
+ }
+
+ /**
+ * The main method
+ *
+ * @param args
+ * @throws IOException
+ */
+ public static void main(String[] args) throws IOException
+ {
+ // Read the PuzzleInput
+ PuzzleInputOutput pio = new PuzzleInputOutput("test_05.txt");
+
+ //Create and initialize the Puzzle
+ Puzzle puzzle = new Puzzle( new PuzzleMove(pio.getPuzzleStart() ,PuzzleMove.HEURISTIC_C),
+ new PuzzleMove(pio.getPuzzleDestination() ,PuzzleMove.HEURISTIC_C));
+ puzzle.init();
+
+ //Calculate A*
+ puzzle.findDestination();
+
+ //Print Summary
+ System.out.println("Summary:");
+ System.out.println("\nHeuristic used: "+puzzle.getDestinationState().getHeuristic());
+ System.out.println("\nStartState: ");
+ PuzzleInputOutput.printPuzzle(puzzle.getStartState().getState());
+ System.out.println("FinalState: ");
+ PuzzleInputOutput.printPuzzle(puzzle.getDestinationState().getState());
+
+ puzzle.printSolutionSummary(puzzle.getCurrentState());
+
+ //Uncomment if you want to see the Path from start to solution if there is one
+ //puzzle.printPathToSolution(puzzle.getGraph());
+ }
+}
diff --git a/ss2010/gdi2/java/Project2/src/PuzzleAStar.java b/ss2010/gdi2/java/Project2/src/PuzzleAStar.java
new file mode 100644
index 00000000..78174e4d
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/src/PuzzleAStar.java
@@ -0,0 +1,243 @@
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.jgrapht.DirectedGraph;
+import org.jgrapht.graph.SimpleDirectedWeightedGraph;
+
+/**
+ * This class represents the implementation of the A* algorithm
+ */
+
+public abstract class PuzzleAStar {
+
+ private DirectedGraph graph; // vertex: PuzzleMove
+ // edge: Integer (use an int value as a unique ID)
+ private PuzzleMove startState; // the start state of the puzzle
+ private PuzzleMove destinationState; // the destination state of the puzzle
+ private PuzzleMove currentState; // the current explored puzzle state
+ private List movesToProcess; // the number of moves not taken yet
+
+ private long startPuzzleTime; // Timing variables
+ private long endPuzzleTime;
+
+ /**
+ * Initializes PuzzleAStar
+ */
+ void init() {
+
+ //Create ArrayList for moves
+ movesToProcess = new ArrayList();
+
+ //Create graph
+ graph = new SimpleDirectedWeightedGraph(Integer.class);
+
+ //Set currentState to startState
+ this.currentState = startState;
+
+ //Add StartState to graph
+ graph.addVertex(startState);
+ }
+
+ /**
+ * This method implements the A* algorithm for the puzzle
+ */
+ public void findDestination() {
+
+ //check input data
+ if(currentState == null){
+ return;
+ }
+
+ //save the start time
+ startPuzzleTime = System.currentTimeMillis();
+
+ //integer identification for edges
+ int edgecount = 0;
+
+ //Add all possible Moves of startState to movesToProcess
+ movesToProcess.addAll(currentState.successorMoves());
+
+ //Do as long destination is not reached
+ while(!currentState.equals(destinationState))
+ {
+ PuzzleMove nextstep = null;
+
+ for(int i=0; i< movesToProcess.size(); i++)
+ {
+ //calculate distance of Move - need to be done here cuz PuzzleMove has no
+ //access to destinationState
+ movesToProcess.get(i).calculateDistance(this.destinationState);
+
+ //identify best move in movesToProcess
+ if(nextstep == null)
+ {
+ //no move found till now
+ nextstep = movesToProcess.get(i);
+ } else
+ {
+ //is move better then last identified?
+ if(nextstep.getCost() > movesToProcess.get(i).getCost())
+ {
+ nextstep = movesToProcess.get(i);
+ }
+ }
+ }
+
+ //movesToProcess is empty. There is no connection from start to destination
+ if(nextstep == null)
+ {
+ //no way found
+ break;
+ }
+
+ //try to add identified step. If not possible it is already in the graph
+ if(graph.addVertex(nextstep))
+ {
+ //Add an edge from identified step's predecessor to identified step
+ graph.addEdge(nextstep.getPredecessorMove(), nextstep,edgecount++);
+
+ //now continue with identified step
+ currentState = nextstep;
+
+ //add all successorMoves to movesToProcess
+ movesToProcess.addAll(currentState.successorMoves());
+ }
+
+ //remove the identified step from movesToProcess
+ movesToProcess.remove(nextstep);
+
+ }
+
+ //save end time
+ endPuzzleTime = System.currentTimeMillis();
+ }
+
+ /**
+ * This method prints a summary of the solution
+ *
+ * @param state The final puzzle state (Destination)
+ */
+ public void printSolutionSummary(PuzzleMove state) {
+ System.out.println("Time needed to find Destination (ms): " + (this.endPuzzleTime-this.startPuzzleTime));
+ System.out.println("Current cost at final state (Destination): " + state.getCost());
+ System.out.println("States processed so far: " + numberOfProcessedStates());
+ System.out.println("States identified for processing (not being processed): " + numberOfStatesToProcess());
+ }
+
+ /**
+ * This method prints the path to the solution
+ *
+ * Make sure you called findDestination() first.
+ * This method only works if the A* Algorithm was
+ * calculated before.
+ *
+ * Uses currentState & destinationState
+ *
+ * @param graph
+ */
+ public void printPathToSolution(DirectedGraph graph) {
+ System.out.println("\nThe steps/path needed to reach the destination:\n");
+
+ //Check if A* was successful
+ if(!currentState.equals(destinationState)){
+ System.out.println("No Path to Solution found");
+ return;
+ }
+
+ //Add String representation of destinationState
+ String result = currentState.toString();
+
+ PuzzleMove curMove = destinationState;
+
+ //Move from destination to start
+ while(!curMove.equals(startState))
+ {
+ //get incoming edges
+ Set s = graph.incomingEdgesOf(curMove);
+
+ //No or more then one edge found - something is wrong
+ if(s.size() != 1)
+ {
+ System.out.println("An Error occured: Graph destination has no or to many connections to start");
+ return;
+ }
+
+ //only look at first edge
+ Iterator it = s.iterator();
+ curMove = graph.getEdgeSource(it.next());
+
+ //Add String representation before last steps
+ result = curMove.toString() + result;
+
+ }
+
+ //print the result
+ System.out.println(result);
+ }
+
+ /**
+ * The number of states identified for processing but not processed yet
+ * @return the number of moves not taken yet
+ */
+ int numberOfStatesToProcess() {
+ return this.movesToProcess.size();
+ }
+
+ /**
+ * The number of states/puzzle moves processed so far
+ * @return the number of edges
+ */
+ int numberOfProcessedStates() {
+ return this.graph.vertexSet().size();
+ }
+
+ /**
+ * @return the graph
+ */
+ public DirectedGraph getGraph() {
+ return this.graph;
+ }
+
+ /**
+ * @return the currentState
+ */
+ public PuzzleMove getCurrentState() {
+ return this.currentState;
+ }
+
+ /**
+ * @param destinationState the destinationState to set
+ */
+ public void setDestinationState(PuzzleMove destinationState) {
+ this.destinationState = destinationState;
+ }
+
+ /**
+ * @param startState the startState to set
+ */
+ public void setStartState(PuzzleMove startState) {
+ this.startState = startState;
+ }
+
+ /**
+ * @return the startState
+ */
+ public PuzzleMove getStartState() {
+ return this.startState;
+ }
+
+ /**
+ * @return the destinationState
+ */
+ public PuzzleMove getDestinationState() {
+ return this.destinationState;
+ }
+ /**
+ * @return the movesToProcess
+ */
+ public List getMovesToProcess() {
+ return this.movesToProcess;
+ }
+}
diff --git a/ss2010/gdi2/java/Project2/src/PuzzleFileFormatException.java b/ss2010/gdi2/java/Project2/src/PuzzleFileFormatException.java
new file mode 100644
index 00000000..8a3c0cae
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/src/PuzzleFileFormatException.java
@@ -0,0 +1,16 @@
+/**
+ * PuzzleFileFormatException
+ */
+
+public class PuzzleFileFormatException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * PuzzleFileFormatException
+ * @param s the message
+ */
+ public PuzzleFileFormatException(String s) {
+ super(s);
+ }
+}
diff --git a/ss2010/gdi2/java/Project2/src/PuzzleInputOutput.java b/ss2010/gdi2/java/Project2/src/PuzzleInputOutput.java
new file mode 100644
index 00000000..aeca84b7
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/src/PuzzleInputOutput.java
@@ -0,0 +1,212 @@
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+/**
+ * Methods needed to read and write the puzzle
+ */
+
+public class PuzzleInputOutput
+{
+ private static String[][] puzzleStart;
+ private static String[][] puzzleDestination;
+
+ public final static int PARSERSTATE_LVLSIZE = 0;
+ public final static int PARSERSTATE_STARTCONFIG = 1;
+ public final static int PARSERSTATE_FINALCONFIG = 2;
+ public final static int PARSERSTATE_PARSINGEND = 3;
+
+ public final static String FORMAT_CONFIGSEPERATOR = "---";
+ public final static String FORMAT_FREEFIELD = "#";
+
+ /**
+ * This method reads the data from the file and
+ * initialises the Start and Destination states of the Puzzle
+ *
+ * @param puzzleFile
+ * @throws IOException
+ */
+ public PuzzleInputOutput(String puzzleFile) throws IOException
+ {
+ //open file
+ BufferedReader reader = new BufferedReader(new FileReader(puzzleFile));
+
+ //var to store a line temporary
+ String line;
+ //var to store size of puzzle temporary
+ int size = 0;
+ //state of the parsing
+ int state = PARSERSTATE_LVLSIZE;
+ //state of the configuration parsing
+ int config_state = 0;
+ //state which indicates if free field was seen in actual configuration
+ boolean free_field = false;
+ //do we need a linebreak?
+ boolean linebreak = true;
+ //last row in array to force a linebreak
+ int last_line = 0;
+
+ //read until fileend
+ while((line = reader.readLine()) != null)
+ {
+ //check if an linebreak was expected
+ if(!linebreak)
+ {
+ throw new PuzzleFileFormatException("Unexpected Linebreak in Puzzlefile");
+ }
+
+ linebreak = false;
+
+ //tokenize the input string
+ StringTokenizer st = new StringTokenizer(line);
+ while(st.hasMoreTokens())
+ {
+ //linbreak not found
+ if(linebreak)
+ {
+ throw new PuzzleFileFormatException("Expected Linebreak in Puzzlefile, but could not find it");
+ }
+
+ switch(state)
+ {
+ //parse levelsize
+ case PARSERSTATE_LVLSIZE:
+ {
+ //read size
+ try
+ {
+ size = Integer.valueOf(st.nextToken());
+ } catch(NumberFormatException e)
+ {
+ throw new PuzzleFileFormatException("Levelsizetoken was not a number");
+ }
+
+ //create arrays
+ puzzleStart = new String[size][size];
+ puzzleDestination = new String[size][size];
+
+ //change state of parser
+ state = PARSERSTATE_STARTCONFIG;
+
+ //expect linebreak
+ linebreak = true;
+ break;
+ }
+
+ //parse configurations
+ case PARSERSTATE_STARTCONFIG:
+ case PARSERSTATE_FINALCONFIG:
+ {
+ // still reading config?
+ if(config_state < size*size)
+ {
+ String token = st.nextToken();
+
+ //save last linenumber
+ last_line = config_state/size;
+
+ //fill in token
+ if(state == PARSERSTATE_STARTCONFIG){
+ puzzleStart[config_state/size][config_state%size] = token;
+ } else {
+ puzzleDestination[config_state/size][config_state%size] = token;
+ }
+
+ //free field?
+ if(token.equals(FORMAT_FREEFIELD))
+ {
+ //more than one free field
+ if(free_field) {
+ throw new PuzzleFileFormatException("Puzzle file contained more then one free Field in one Configuration");
+ }
+
+ free_field = true;
+ }
+
+ //next part in array
+ config_state++;
+
+ //last line
+ if(config_state/size == size)
+ {
+ //No free field?
+ if(!free_field) {
+ throw new PuzzleFileFormatException("Puzzle file contained no free Field in one Configuration");
+ }
+ }
+
+ //do we need a linebreak here?
+ if(last_line != config_state/size)
+ {
+ linebreak = true;
+ }
+ } else
+ {
+ //PuzzleFile Seperator
+ if(state == PARSERSTATE_STARTCONFIG && !st.nextToken().equals(FORMAT_CONFIGSEPERATOR)){
+ throw new PuzzleFileFormatException("Puzzle file ConfigurationSeperator was not found");
+ }
+
+ //reset vars
+ free_field = false;
+ config_state = 0;
+
+ //parse finalconfig after startconfig
+ if(state == PARSERSTATE_STARTCONFIG){
+ state = PARSERSTATE_FINALCONFIG;
+
+ linebreak = true;
+ } else {
+ //No more characters or linebreaks expected!
+ state = PARSERSTATE_PARSINGEND;
+ }
+ }
+ break;
+ }
+
+ default:
+ throw new PuzzleFileFormatException("Puzzle file contains more lines after finalconfiguration");
+ }
+ }
+ }
+ }
+ /**
+ * It prints the given puzzle state
+ *
+ * @param puzzle the puzzle
+ */
+ public static void printPuzzle(String[][] puzzle)
+ {
+ if(puzzle == null)
+ {
+ System.out.println("Puzzle given was null");
+ }
+
+ String output = new String();
+
+ for(int i=0; i < puzzle.length; i++)
+ {
+ for(int j=0; j < puzzle[i].length; j++)
+ {
+ output += puzzle[i][j] + "\t";
+ }
+ output += "\n";
+ }
+
+ System.out.println(output);
+ }
+
+ /**
+ * @return the puzzleStart
+ */
+ public String[][] getPuzzleStart() {
+ return puzzleStart;
+ }
+ /**
+ * @return the puzzleDestination
+ */
+ public String[][] getPuzzleDestination() {
+ return puzzleDestination;
+ }
+}
diff --git a/ss2010/gdi2/java/Project2/src/PuzzleMove.java b/ss2010/gdi2/java/Project2/src/PuzzleMove.java
new file mode 100644
index 00000000..a7f86114
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/src/PuzzleMove.java
@@ -0,0 +1,622 @@
+import java.awt.Point;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This class defines a puzzle move
+ */
+
+public class PuzzleMove implements Cloneable
+{
+ //---STATICS-------------------------------------------
+
+ //Heuristic Definitions
+ public final static int HEURISTIC_A = 0;
+ public final static int HEURISTIC_B = 1;
+ public final static int HEURISTIC_C = 2;
+
+ //---VARIABLES-----------------------------------------
+
+ /**
+ * distance from start; default 0
+ */
+ private int ds = 0;
+
+ /**
+ * distance to destination; default 0
+ */
+ private int dd = 0;
+
+ /**
+ * the distance cost (cost = ds + dd); default 0
+ */
+ private int cost = 0;
+
+ /**
+ * Used Heuristic; Default: HEURISTIC_A
+ *
+ * Valid values: 0-2
+ */
+ private int heuristic = HEURISTIC_A;
+
+ /**
+ * the state of the current puzzle move/state
+ */
+ private String[][] state;
+
+ /**
+ * Predecessor of this Move
+ *
+ * Is null if predecessor does not exist or is unknown
+ */
+ private PuzzleMove predecessorMove = null;
+
+
+ //---METHODS-------------------------------------------
+
+ /**
+ * Standard Constructor
+ *
+ * to make the PuzzleMove valid use
+ * setState();
+ *
+ * optional:
+ * setHeuristic() - default HEURISTIC_A
+ * setDd() - default 0
+ * setDs() - default 0
+ */
+ public PuzzleMove(){}
+
+ /**
+ * Constructor
+ *
+ * @param state PuzzleState
+ * @param heuristic Used heuristic
+ */
+ public PuzzleMove(String[][] state, int heuristic)
+ {
+ this.setState(state);
+ this.setHeuristic(heuristic);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param state PuzzleState
+ * @param heuristic Used Heuristic
+ * @param dd Distance to Destination
+ * @param ds Distance to Start
+ */
+ public PuzzleMove(String[][] state, int heuristic, int dd, int ds) {
+ this.setState(state);
+ this.setHeuristic(heuristic);
+ this.setDd(dd);
+ this.setDs(ds);
+ }
+
+ /**
+ * Find Element Position in given state which has given value
+ *
+ * @param value String
+ * @param state String[][]
+ * @return null if not found else returns a Point
+ */
+ private Point findElementPos(String value, String[][] state)
+ {
+ //Iterate over array
+ for(int i=0; i= this.state.length ||
+ free_field.y < 0 ||
+ free_field.y >= this.state.length ){
+ return null;
+ }
+
+ //create a new Point according to modificators
+ Point b = new Point(free_field.x + x_mod, free_field.y + y_mod);
+
+ //check new point
+ if( b.x < 0 ||
+ b.x >= this.state.length ||
+ b.y < 0 ||
+ b.y >= this.state.length )
+ {
+ return null;
+ }
+
+ //clone this PuzzleMove
+ PuzzleMove result = this.clone();
+
+ //Exchange the free_field and the Modification-Point
+ result.exchangeFields(free_field, b);
+
+ //Increase Ds
+ result.setDs(this.getDs()+1);
+
+ //Set Predecessor
+ result.setPredecessorMove(this);
+
+ //Return new PuzzleMove
+ return result;
+ }
+
+ /**
+ * Calculates the possible successor moves/states
+ * @return a list with the successor moves/states
+ */
+ public List successorMoves() {
+
+ //Create Result List
+ List result = new ArrayList();
+
+ //Find the free Field in state
+ Point free_field = findElementPos(PuzzleInputOutput.FORMAT_FREEFIELD);
+
+ //Temporary Variable for new Moves
+ PuzzleMove newMove;
+
+ //top-Move
+ newMove = successorMove(free_field,-1,0);
+ if(newMove != null)
+ {
+ result.add(newMove);
+ }
+
+ //bottom-Move
+ newMove = successorMove(free_field,+1,0);
+ if(newMove != null)
+ {
+ result.add(newMove);
+ }
+
+ //left-Move
+ newMove = successorMove(free_field,0,-1);
+ if(newMove != null)
+ {
+ result.add(newMove);
+ }
+
+ //right-Move
+ newMove = successorMove(free_field,0,+1);
+ if(newMove != null)
+ {
+ result.add(newMove);
+ }
+
+ return result;
+ }
+
+ /**
+ * Calculates the distance to the destination p (according to the currently chosen heuristic)
+ * @param p the destination state
+ * @return the distance of the current state to destination
+ */
+ public int calculateDistance(PuzzleMove p) {
+
+ //Simple switch and link to methodOne-Three
+ switch(this.heuristic)
+ {
+ case HEURISTIC_A:
+ return methodOne(p);
+
+ case HEURISTIC_B:
+ return methodTwo(p);
+
+ case HEURISTIC_C:
+ return methodThree(p);
+
+ default:
+ return -1;
+ }
+ }
+
+ /**
+ * Heuristic 0
+ *
+ * How many Elements are not in the right place
+ *
+ * @param p the puzzle state
+ * @return the destination cost according to this heuristic
+ */
+ private int methodOne(PuzzleMove p) {
+
+ //Check if p is valid
+ if( p == null){
+ return -1;
+ }
+
+ int dist = 0;
+
+ //Iterate over state
+ for(int i=0; i does not compare
+ * -heuristic
+ * -dd
+ * -ds
+ */
+ @Override public boolean equals(Object obj)
+ {
+ //Checks if obj is a PuzzleMove
+ if(!(obj instanceof PuzzleMove)){
+ return false; //return false - its not a puzzlemove
+ }
+
+ //cast to Puzzlemove
+ PuzzleMove p = (PuzzleMove)obj;
+
+ //Check state-length
+ if( p.getState().length != this.state.length){
+ return false;
+ }
+
+ //iterate over array
+ for(int i=0; i= HEURISTIC_A &&
+ heuristic <= HEURISTIC_C)
+ {
+ this.heuristic = heuristic;
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the Heuristic used
+ *
+ * @return integer between 0-2
+ */
+ public int getHeuristic() {
+ return heuristic;
+ }
+
+
+ /**
+ * Returns the calculated Costs for this Move
+ *
+ * @return calculated Costs
+ */
+ public int getCost() {
+ return cost;
+ }
+
+ /**
+ * Calculate new Costs, save them to cost
+ * @return new costs
+ */
+ private int calculateCosts()
+ {
+ return (cost = ds + dd);
+ }
+
+ /**
+ * @return Distance to Start
+ */
+ public int getDs() {
+ return ds;
+ }
+
+ /**
+ * Sets Distance to Start and Calculates new Costs
+ *
+ * @param ds
+ */
+ public void setDs(int ds) {
+ this.ds = ds;
+ calculateCosts();
+ }
+
+ /**
+ * @return Distance to Destination
+ */
+ public int getDd() {
+ return dd;
+ }
+
+ /**
+ * Sets Distance to Destination and Calculates new Costs
+ *
+ * @param dd
+ */
+ public void setDd(int dd) {
+ this.dd = dd;
+ calculateCosts();
+ }
+
+ /**
+ * Sets PredecessorMove
+ * @param predecessorMove PuzzleMove
+ */
+ public void setPredecessorMove(PuzzleMove predecessorMove) {
+ this.predecessorMove = predecessorMove;
+ }
+
+ /**
+ * @return PredecessorMove; can be null
+ */
+ public PuzzleMove getPredecessorMove() {
+ return predecessorMove;
+ }
+}
diff --git a/ss2010/gdi2/java/Project2/test_00.txt b/ss2010/gdi2/java/Project2/test_00.txt
new file mode 100644
index 00000000..8141d18c
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_00.txt
@@ -0,0 +1,8 @@
+3
+# 1 2
+3 4 5
+6 7 8
+---
+1 2 3
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_01.txt b/ss2010/gdi2/java/Project2/test_01.txt
new file mode 100644
index 00000000..e21352f5
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_01.txt
@@ -0,0 +1,8 @@
+3
+# 1 2
+3 4 5
+6 7 8
+---
+# 1 2
+3 4 5
+6 7 8
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_02.txt b/ss2010/gdi2/java/Project2/test_02.txt
new file mode 100644
index 00000000..8141d18c
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_02.txt
@@ -0,0 +1,8 @@
+3
+# 1 2
+3 4 5
+6 7 8
+---
+1 2 3
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_03.txt b/ss2010/gdi2/java/Project2/test_03.txt
new file mode 100644
index 00000000..444659c3
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_03.txt
@@ -0,0 +1,8 @@
+3
+# 1 2
+3 4 5
+6 7 8
+---
+1 2 5
+3 4 8
+6 7 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_04.txt b/ss2010/gdi2/java/Project2/test_04.txt
new file mode 100644
index 00000000..ec0546c6
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_04.txt
@@ -0,0 +1,10 @@
+4
+# 1 2 3
+4 5 6 7
+8 9 10 11
+12 13 14 15
+---
+6 1 2 3
+4 5 # 7
+8 9 10 11
+12 13 14 15
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_05.txt b/ss2010/gdi2/java/Project2/test_05.txt
new file mode 100644
index 00000000..42d688c9
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_05.txt
@@ -0,0 +1,10 @@
+4
+# 1 2 3
+4 5 6 7
+8 9 10 11
+12 13 14 15
+---
+1 5 2 3
+4 # 6 7
+8 9 10 11
+12 13 14 15
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_1.txt b/ss2010/gdi2/java/Project2/test_1.txt
new file mode 100644
index 00000000..5b30bd9e
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_1.txt
@@ -0,0 +1,8 @@
+4
+1 2 3
+4 5 6
+7 8 #
+---
+1 2 3
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_2.txt b/ss2010/gdi2/java/Project2/test_2.txt
new file mode 100644
index 00000000..d21395c4
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_2.txt
@@ -0,0 +1,8 @@
+3
+1 2 3 4
+4 5 6 4
+7 8 # 4
+---
+1 2 3
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_3.txt b/ss2010/gdi2/java/Project2/test_3.txt
new file mode 100644
index 00000000..85f30f27
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_3.txt
@@ -0,0 +1,9 @@
+3
+1 2 3
+4 5 6
+7 8 #
+i o l
+---
+1 2 3
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_4.txt b/ss2010/gdi2/java/Project2/test_4.txt
new file mode 100644
index 00000000..cd84f517
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_4.txt
@@ -0,0 +1,8 @@
+3
+1 2 3
+4 5 6
+7 8 #
+--
+1 2 3
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_5.txt b/ss2010/gdi2/java/Project2/test_5.txt
new file mode 100644
index 00000000..aee6516c
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_5.txt
@@ -0,0 +1,8 @@
+3
+1 2 3
+4 5 6
+7 8 #
+---
+1 2 3 4
+4 5 6
+7 8 #
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_6.txt b/ss2010/gdi2/java/Project2/test_6.txt
new file mode 100644
index 00000000..efb747a7
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_6.txt
@@ -0,0 +1,8 @@
+3
+0 1 2
+3 4 5
+6 7 8
+---
+0 1 2
+3 4 5
+6 7 8
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/test_7.txt b/ss2010/gdi2/java/Project2/test_7.txt
new file mode 100644
index 00000000..0650a26f
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/test_7.txt
@@ -0,0 +1,6 @@
+2
+# 1
+2 3
+---
+# 1
+2 4
\ No newline at end of file
diff --git a/ss2010/gdi2/java/Project2/tests/PuzzleTest.java b/ss2010/gdi2/java/Project2/tests/PuzzleTest.java
new file mode 100644
index 00000000..bda94e9f
--- /dev/null
+++ b/ss2010/gdi2/java/Project2/tests/PuzzleTest.java
@@ -0,0 +1,74 @@
+
+/**
+ * Test cases
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.jgrapht.DirectedGraph;
+import org.junit.Test;
+
+public class PuzzleTest
+{
+ @Test(expected=PuzzleFileFormatException.class)
+ public void readTest1() throws IOException
+ {
+ new PuzzleInputOutput("test_1.txt");
+ }
+ @Test(expected=PuzzleFileFormatException.class)
+ public void readTest2() throws IOException
+ {
+ new PuzzleInputOutput("test_2.txt");
+ }
+ @Test(expected=PuzzleFileFormatException.class)
+ public void readTest3() throws IOException
+ {
+ new PuzzleInputOutput("test_3.txt");
+ }
+ @Test(expected=PuzzleFileFormatException.class)
+ public void readTest4() throws IOException
+ {
+ new PuzzleInputOutput("test_4.txt");
+ }
+ @Test(expected=PuzzleFileFormatException.class)
+ public void readTest5() throws IOException
+ {
+ new PuzzleInputOutput("test_5.txt");
+ }
+ @Test
+ public void testEquals() throws IOException
+ {
+ PuzzleInputOutput pio = new PuzzleInputOutput("test_00.txt");
+ PuzzleMove start = new PuzzleMove();
+ PuzzleMove end = new PuzzleMove();
+ start.setState(pio.getPuzzleStart());
+ end.setState(pio.getPuzzleDestination());
+ Puzzle p = new Puzzle(start, end);
+ p.init();
+ p.findDestination();
+ assertEquals(p.getCurrentState(), end); // current state should be the destination
+ assertFalse("Equals is not properly implemented.", start.equals(end));
+ end = start;
+ assertTrue("Equals is not properly implemented", start.equals(end));
+ }
+ @Test
+ public void testEqualityCheck() throws IOException
+ {
+ PuzzleInputOutput pio = new PuzzleInputOutput("test_01.txt");
+ PuzzleMove start = new PuzzleMove();
+ PuzzleMove end = new PuzzleMove();
+ start.setState(pio.getPuzzleStart());
+ end.setState(pio.getPuzzleDestination());
+ Puzzle p = new Puzzle(start, end);
+ p.init();
+ p.findDestination();
+ DirectedGraph g = p.getGraph();
+ // If start and destination are the same...
+ assertFalse(p.numberOfProcessedStates() > 1); //...no need to process more than one state
+ assertFalse(g.vertexSet().size() > 1); //...the graph should have only one node
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/acm.jar b/ss2010/gdi2/java/libs/acm/acm.jar
new file mode 100644
index 00000000..0548ea26
Binary files /dev/null and b/ss2010/gdi2/java/libs/acm/acm.jar differ
diff --git a/ss2010/gdi2/java/libs/acm/demo/Add2Application.java b/ss2010/gdi2/java/libs/acm/demo/Add2Application.java
new file mode 100644
index 00000000..cf4fc5d1
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Add2Application.java
@@ -0,0 +1,25 @@
+/*
+ * File: Add2Application.java
+ * --------------------------
+ * This program adds two numbers and prints their sum. This version
+ * runs as a Java application without using the acm.program package.
+ */
+
+import acm.io.*;
+import java.awt.*;
+import javax.swing.*;
+
+public class Add2Application {
+ public static void main(String[] argv) {
+ JFrame frame = new JFrame("Add2Application");
+ IOConsole console = new IOConsole();
+ frame.getContentPane().add(BorderLayout.CENTER, console);
+ frame.setSize(500, 300);
+ frame.show();
+ console.println("This program adds two numbers.");
+ int n1 = console.readInt("Enter n1: ");
+ int n2 = console.readInt("Enter n2: ");
+ int total = n1 + n2;
+ console.println("The total is " + total + ".");
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/Add2Console.java b/ss2010/gdi2/java/libs/acm/demo/Add2Console.java
new file mode 100644
index 00000000..ef15fdee
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Add2Console.java
@@ -0,0 +1,26 @@
+/*
+ * File: Add2Console.java
+ * ----------------------
+ * This program adds two numbers and prints their sum. Because
+ * this version is a ConsoleProgram, the input and output appear
+ * on the console.
+ */
+
+import acm.program.*;
+
+public class Add2Console extends ConsoleProgram {
+ public void run() {
+ println("This program adds two numbers.");
+ int n1 = readInt("Enter n1: ");
+ int n2 = readInt("Enter n2: ");
+ int total = n1 + n2;
+ println("The total is " + total + ".");
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new Add2Console().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/Add2Dialog.java b/ss2010/gdi2/java/libs/acm/demo/Add2Dialog.java
new file mode 100644
index 00000000..67292c9c
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Add2Dialog.java
@@ -0,0 +1,26 @@
+/*
+ * File: Add2Dialog.java
+ * ---------------------
+ * This program adds two numbers and prints their sum. Because
+ * this version is a DialogProgram, the input and output appear
+ * as popup dialogs.
+ */
+
+import acm.program.*;
+
+public class Add2Dialog extends DialogProgram {
+ public void run() {
+ println("This program adds two numbers.");
+ int n1 = readInt("Enter n1: ");
+ int n2 = readInt("Enter n2: ");
+ int total = n1 + n2;
+ println("The total is " + total + ".");
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new Add2Dialog().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/Add2Program.java b/ss2010/gdi2/java/libs/acm/demo/Add2Program.java
new file mode 100644
index 00000000..adf0dda1
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Add2Program.java
@@ -0,0 +1,26 @@
+/*
+ * File: Add2Program.java
+ * ----------------------
+ * This program adds two numbers and prints their sum. Because
+ * this version is a Program, input and output are assigned to
+ * System.in and System.out.
+ */
+
+import acm.program.*;
+
+public class Add2Program extends Program {
+ public void run() {
+ println("This program adds two numbers.");
+ int n1 = readInt("Enter n1: ");
+ int n2 = readInt("Enter n2: ");
+ int total = n1 + n2;
+ println("The total is " + total + ".");
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new Add2Program().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/BouncingBall.java b/ss2010/gdi2/java/libs/acm/demo/BouncingBall.java
new file mode 100644
index 00000000..a8e096b7
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/BouncingBall.java
@@ -0,0 +1,52 @@
+/*
+ * File: BouncingBall.java
+ * -----------------------
+ * This file implements a simple bouncing ball using the run method
+ * to drive the animation.
+ */
+
+import acm.program.*;
+
+public class BouncingBall extends GraphicsProgram {
+
+/** Initialize the ball and its velocity components */
+ public void init() {
+ ball = new GBall(BALL_RADIUS);
+ add(ball, getWidth() / 2, getHeight() / 2);
+ dx = 2;
+ dy = 1;
+ }
+
+/** Run forever bouncing the ball */
+ public void run() {
+ waitForClick();
+ while (true) {
+ advanceOneTimeStep();
+ pause(PAUSE_TIME);
+ }
+ }
+
+/* Check for bounces and advance the ball */
+ private void advanceOneTimeStep() {
+ double bx = ball.getX();
+ double by = ball.getY();
+ if (bx < BALL_RADIUS || bx > getWidth() - BALL_RADIUS) dx = -dx;
+ if (by < BALL_RADIUS || by > getHeight() - BALL_RADIUS) dy = -dy;
+ ball.move(dx, dy);
+ }
+
+/* Private constants */
+ private static final double BALL_RADIUS = 10;
+ private static final int PAUSE_TIME = 20;
+
+/* Private instance variables */
+ private GBall ball; /* The ball object */
+ private double dx; /* Velocity delta in the x direction */
+ private double dy; /* Velocity delta in the y direction */
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new BouncingBall().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/BouncingBallUsingThreads.java b/ss2010/gdi2/java/libs/acm/demo/BouncingBallUsingThreads.java
new file mode 100644
index 00000000..b8a59070
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/BouncingBallUsingThreads.java
@@ -0,0 +1,37 @@
+/*
+ * File: BouncingBallUsingThreads.java
+ * -----------------------------------
+ * This file implements a simple bouncing ball by creating
+ * a RunnableBall class and executing it in its own thread.
+ */
+
+import acm.program.*;
+
+public class BouncingBallUsingThreads extends GraphicsProgram {
+
+/** Initialize the ball and its velocity components */
+ public void init() {
+ ball = new RunnableGBall(BALL_RADIUS);
+ ball.setEnclosureSize(getWidth(), getHeight());
+ ball.setVelocity(2, 1);
+ add(ball, getWidth() / 2, getHeight() / 2);
+ }
+
+/** Create a thread to bounce the ball */
+ public void run() {
+ waitForClick();
+ new Thread(ball).start();
+ }
+
+/* Private constants */
+ private static final double BALL_RADIUS = 10;
+
+/* Private instance variables */
+ private RunnableGBall ball;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new BouncingBallUsingThreads().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/BouncingBallUsingTimer.java b/ss2010/gdi2/java/libs/acm/demo/BouncingBallUsingTimer.java
new file mode 100644
index 00000000..70ca6b4c
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/BouncingBallUsingTimer.java
@@ -0,0 +1,57 @@
+/*
+ * File: BouncingBallUsingTimer.java
+ * ---------------------------------
+ * This file implements a simple bouncing ball using a Timer to
+ * implement the animation.
+ */
+
+import acm.program.*;
+import acm.util.*;
+import java.awt.event.*;
+
+public class BouncingBallUsingTimer extends GraphicsProgram {
+
+/** Initialize the ball and its velocity components */
+ public void init() {
+ ball = new GBall(BALL_RADIUS);
+ add(ball, getWidth() / 2, getHeight() / 2);
+ dx = 2;
+ dy = 1;
+ }
+
+/** Create a timer to advance the ball */
+ public void run() {
+ waitForClick();
+ ActionListener listener = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ advanceOneTimeStep();
+ }
+ };
+ SwingTimer timer = new SwingTimer(TIMER_RATE, listener);
+ timer.start();
+ }
+
+/** Check for bounces and advance the ball */
+ private void advanceOneTimeStep() {
+ double bx = ball.getX();
+ double by = ball.getY();
+ if (bx < BALL_RADIUS || bx > getWidth() - BALL_RADIUS) dx = -dx;
+ if (by < BALL_RADIUS || by > getHeight() - BALL_RADIUS) dy = -dy;
+ ball.move(dx, dy);
+ }
+
+/* Private constants */
+ private static final double BALL_RADIUS = 10;
+ private static final int TIMER_RATE = 20;
+
+/* Private instance variables */
+ private GBall ball;
+ private double dx;
+ private double dy;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new BouncingBallUsingTimer().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/CalendarDemo.java b/ss2010/gdi2/java/libs/acm/demo/CalendarDemo.java
new file mode 100644
index 00000000..aab18e26
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/CalendarDemo.java
@@ -0,0 +1,179 @@
+/*
+ * File: CalendarDemo.java
+ * -----------------------
+ * This program uses the GUI layout mechanism to create a calendar
+ * page. The program uses the features of Java's Locale class to
+ * internationalize the calendar.
+ */
+
+import acm.gui.*;
+import acm.program.*;
+import acm.util.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.text.*;
+import java.util.*;
+import javax.swing.*;
+import javax.swing.border.*;
+
+public class CalendarDemo extends Program implements ItemListener {
+
+/** Initialize the graphical user interface */
+ public void init() {
+ setBackground(Color.WHITE);
+ initCountryList();
+ localeChooser = new JComboBox(countries);
+ String country = Locale.getDefault().getDisplayCountry();
+ localeChooser.setSelectedItem(country);
+ localeChooser.addItemListener(this);
+ add(new JButton("<-"), NORTH);
+ add(localeChooser, NORTH);
+ add(new JButton("->"), NORTH);
+ currentCalendar = Calendar.getInstance();
+ itemStateChanged(null);
+ addActionListeners();
+ }
+
+/** Respond to a button action */
+ public void actionPerformed(ActionEvent e) {
+ int delta = (e.getActionCommand().equals("<-")) ? -1 : +1;
+ currentCalendar.add(Calendar.MONTH, delta);
+ updateCalendarDisplay(currentCalendar);
+ }
+
+/** Respond to a change in the locale selection */
+ public void itemStateChanged(ItemEvent e) {
+ if (e == null || e.getStateChange() == ItemEvent.SELECTED) {
+ Date time = currentCalendar.getTime();
+ Locale locale = LOCALES[localeChooser.getSelectedIndex()];
+ currentCalendar = Calendar.getInstance(locale);
+ currentCalendar.setTime(time);
+ symbols = new DateFormatSymbols(locale);
+ weekdayNames = symbols.getWeekdays();
+ monthNames = symbols.getMonths();
+ firstDayOfWeek = currentCalendar.getFirstDayOfWeek();
+ updateCalendarDisplay(currentCalendar);
+ }
+ }
+
+/* Update the calendar display when a new month is selected */
+ private void updateCalendarDisplay(Calendar calendar) {
+ removeAll();
+ setLayout(new TableLayout(0, 7, -1, -1));
+ add(createMonthLabel(calendar), "gridwidth=7 bottom=3");
+ for (int i = 0; i < 7; i++) {
+ add(createWeekdayLabel(i), "weightx=1 width=1 bottom=2");
+ }
+ int weekday = getFirstWeekdayIndex(calendar);
+ for (int i = 0; i < weekday; i++) {
+ add(createDayBox(null), "weighty=1");
+ }
+ int nDays = getDaysInMonth(calendar);
+ for (int day = 1; day <= nDays; day++) {
+ add(createDayBox("" + day), "weighty=1");
+ weekday = (weekday + 1) % 7;
+ }
+ while (weekday != 0) {
+ add(createDayBox(null), "weighty=1");
+ weekday = (weekday + 1) % 7;
+ }
+ validate();
+ }
+
+/* Generate the header label for a particular month */
+ private JLabel createMonthLabel(Calendar calendar) {
+ int month = calendar.get(Calendar.MONTH);
+ int year = calendar.get(Calendar.YEAR);
+ String monthName = capitalize(monthNames[month]);
+ JLabel label = new JLabel(monthName + " " + year);
+ label.setFont(JTFTools.decodeFont(TITLE_FONT));
+ label.setHorizontalAlignment(JLabel.CENTER);
+ return label;
+ }
+
+/* Create a label for the weekday header at the specified index */
+ private JLabel createWeekdayLabel(int index) {
+ int weekday = (firstDayOfWeek + index + 6) % 7 + 1;
+ JLabel label = new JLabel(capitalize(weekdayNames[weekday]));
+ label.setFont(JTFTools.decodeFont(LABEL_FONT));
+ label.setHorizontalAlignment(JLabel.CENTER);
+ return label;
+ }
+
+/* Compute the number of days in the current month */
+ private int getDaysInMonth(Calendar calendar) {
+ calendar = (Calendar) calendar.clone();
+ int current = calendar.get(Calendar.DAY_OF_MONTH);
+ int next = current;
+ while (next >= current) {
+ current = next;
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
+ next = calendar.get(Calendar.DAY_OF_MONTH);
+ }
+ return current;
+ }
+
+/* Compute the index of the first weekday for the current Locale */
+ private int getFirstWeekdayIndex(Calendar calendar) {
+ int day = calendar.get(Calendar.DAY_OF_MONTH);
+ int weekday = calendar.get(Calendar.DAY_OF_WEEK);
+ int weekdayIndex = (weekday + 7 - firstDayOfWeek) % 7;
+ return ((5 * 7 + 1) + weekdayIndex - day) % 7;
+ }
+
+/* Create a box for a calendar day containing the specified text */
+ private Component createDayBox(String text) {
+ VPanel vbox = new VPanel();
+ if (text== null) {
+ vbox.setBackground(EMPTY_BACKGROUND);
+ } else {
+ JLabel label = new JLabel(text);
+ label.setFont(JTFTools.decodeFont(DATE_FONT));
+ vbox.add(label, "anchor=NORTHEAST top=2 right=2");
+ vbox.setBackground(Color.WHITE);
+ }
+ vbox.setOpaque(true);
+ vbox.setBorder(new LineBorder(Color.BLACK));
+ return vbox;
+ }
+
+/* Create a list of country names from the list of Locales */
+ private void initCountryList() {
+ countries = new String[LOCALES.length];
+ for (int i = 0; i < LOCALES.length; i++) {
+ countries[i] = LOCALES[i].getDisplayCountry();
+ }
+ }
+
+/* Capitalize the first letter of a word */
+ private String capitalize(String word) {
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
+ }
+
+/* Private constants */
+ private static final Color EMPTY_BACKGROUND = new Color(0xDDDDDD);
+ private static final String TITLE_FONT = "Serif-36";
+ private static final String LABEL_FONT = "Serif-bold-14";
+ private static final String DATE_FONT = "Serif-18";
+ private static final Locale[] LOCALES = {
+ new Locale("fr", "FR", ""), new Locale("de", "DE", ""),
+ new Locale("es", "MX", ""), new Locale("it", "IT", ""),
+ new Locale("nl", "NL", ""), new Locale("es", "ES", ""),
+ new Locale("en", "GB", ""), new Locale("en", "US", "")
+ };
+
+/* Private instance variables */
+ private JComboBox localeChooser;
+ private String[] countries;
+ private Calendar currentCalendar;
+ private DateFormatSymbols symbols;
+ private String[] monthNames;
+ private String[] weekdayNames;
+ private int firstDayOfWeek;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new CalendarDemo().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/Checkerboard.java b/ss2010/gdi2/java/libs/acm/demo/Checkerboard.java
new file mode 100644
index 00000000..d8753856
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Checkerboard.java
@@ -0,0 +1,39 @@
+/*
+ * File: Checkerboard.java
+ * -----------------------
+ * This program draws a checkerboard. The dimensions of the
+ * checkerboard is specified by the constants NROWS and
+ * NCOLUMNS, and the size of the squares is chosen so
+ * that the checkerboard fills the available vertical space.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+
+public class Checkerboard extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ double sqSize = (double) getHeight() / NROWS;
+ for (int i = 0; i < NROWS; i++) {
+ for (int j = 0; j < NCOLUMNS; j++) {
+ double x = j * sqSize;
+ double y = i * sqSize;
+ GRect sq = new GRect(x, y, sqSize, sqSize);
+ sq.setFilled((i + j) % 2 != 0);
+ add(sq);
+ }
+ }
+ }
+
+/* Private constants */
+ private static final int NROWS = 8; /* Number of rows */
+ private static final int NCOLUMNS = 8; /* Number of columns */
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new Checkerboard().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/CurrConvUsingInnerClasses.java b/ss2010/gdi2/java/libs/acm/demo/CurrConvUsingInnerClasses.java
new file mode 100644
index 00000000..7748997c
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/CurrConvUsingInnerClasses.java
@@ -0,0 +1,83 @@
+/*
+ * File: CurrConvUsingInnerClasses.java
+ * ------------------------------------
+ * This program implements a simple currency converter. This version
+ * uses anonymous inner classes to specify the action listeners.
+ */
+
+import acm.gui.*;
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class CurrConvUsingInnerClasses extends Program {
+
+/** Initialize the graphical user interface */
+ public void init() {
+ setLayout(new TableLayout(3, 2));
+ currencyTable = new CurrencyTable();
+ leftChooser = new JComboBox(currencyTable.getCurrencyNames());
+ rightChooser = new JComboBox(currencyTable.getCurrencyNames());
+ leftField = new DoubleField();
+ rightField = new DoubleField();
+ JButton leftButton = new JButton("Convert ->");
+ JButton rightButton = new JButton("<- Convert");
+ ActionListener convertLeftToRight = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ double fromValue = leftField.getValue();
+ double fromRate = getRateFromChooser(leftChooser);
+ double toRate = getRateFromChooser(rightChooser);
+ double toValue = fromValue * fromRate / toRate;
+ rightField.setValue(toValue);
+ }
+ };
+ ActionListener convertRightToLeft = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ double fromValue = rightField.getValue();
+ double fromRate = getRateFromChooser(rightChooser);
+ double toRate = getRateFromChooser(leftChooser);
+ double toValue = fromValue * fromRate / toRate;
+ leftField.setValue(toValue);
+ }
+ };
+ leftChooser.setSelectedItem("US Dollar");
+ rightChooser.setSelectedItem("Euro");
+ leftField.setFormat("0.00");
+ leftField.addActionListener(convertLeftToRight);
+ rightField.setFormat("0.00");
+ rightField.addActionListener(convertRightToLeft);
+ rightField.addActionListener(this);
+ leftButton.addActionListener(convertLeftToRight);
+ rightButton.addActionListener(convertRightToLeft);
+ add(leftChooser);
+ add(rightChooser);
+ add(leftField);
+ add(rightField);
+ add(leftButton);
+ add(rightButton);
+ }
+
+/* Gets a rate from the specified chooser */
+ private double getRateFromChooser(JComboBox chooser) {
+ String currencyName = (String) chooser.getSelectedItem();
+ return currencyTable.getExchangeRate(currencyName);
+ }
+
+/* Private instance variables */
+ private CurrencyTable currencyTable;
+ private JComboBox leftChooser;
+ private JComboBox rightChooser;
+ private DoubleField leftField;
+ private DoubleField rightField;
+
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 350;
+ public static final int APPLICATION_HEIGHT = 200;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new CurrConvUsingInnerClasses().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/CurrencyConverter.java b/ss2010/gdi2/java/libs/acm/demo/CurrencyConverter.java
new file mode 100644
index 00000000..3d9a55f2
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/CurrencyConverter.java
@@ -0,0 +1,82 @@
+/*
+ * File: CurrencyConverter.java
+ * ----------------------------
+ * This program implements a simple currency converter.
+ */
+
+import acm.gui.*;
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class CurrencyConverter extends Program {
+
+/** Initialize the graphical user interface */
+ public void init() {
+ setLayout(new TableLayout(4, 2));
+ currencyTable = new CurrencyTable();
+ leftChooser = new JComboBox(currencyTable.getCurrencyNames());
+ leftChooser.setSelectedItem("US Dollar");
+ rightChooser = new JComboBox(currencyTable.getCurrencyNames());
+ rightChooser.setSelectedItem("Euro");
+ leftField = new DoubleField();
+ leftField.setFormat("0.00");
+ leftField.setActionCommand("Convert ->");
+ leftField.addActionListener(this);
+ rightField = new DoubleField();
+ rightField.setFormat("0.00");
+ rightField.setActionCommand("<- Convert");
+ rightField.addActionListener(this);
+ add(leftChooser);
+ add(rightChooser);
+ add(leftField);
+ add(rightField);
+ add(new JButton("Convert ->"));
+ add(new JButton("<- Convert"));
+ String date = "(rates from " + currencyTable.getDate() + ")";
+ add(new JLabel(date, JLabel.CENTER), "gridwidth=2");
+ addActionListeners();
+ }
+
+/** Listens for a button action */
+ public void actionPerformed(ActionEvent e) {
+ String cmd = e.getActionCommand();
+ if (cmd.equals("Convert ->")) {
+ double fromValue = leftField.getValue();
+ double fromRate = getRateFromChooser(leftChooser);
+ double toRate = getRateFromChooser(rightChooser);
+ double toValue = fromValue * fromRate / toRate;
+ rightField.setValue(toValue);
+ } else if (cmd.equals("<- Convert")) {
+ double fromValue = rightField.getValue();
+ double fromRate = getRateFromChooser(rightChooser);
+ double toRate = getRateFromChooser(leftChooser);
+ double toValue = fromValue * fromRate / toRate;
+ leftField.setValue(toValue);
+ }
+ }
+
+/* Gets a rate from the specified chooser */
+ private double getRateFromChooser(JComboBox chooser) {
+ String currencyName = (String) chooser.getSelectedItem();
+ return currencyTable.getExchangeRate(currencyName);
+ }
+
+/* Private instance variables */
+ private CurrencyTable currencyTable;
+ private JComboBox leftChooser;
+ private JComboBox rightChooser;
+ private DoubleField leftField;
+ private DoubleField rightField;
+
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 350;
+ public static final int APPLICATION_HEIGHT = 200;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new CurrencyConverter().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/CurrencyTable.java b/ss2010/gdi2/java/libs/acm/demo/CurrencyTable.java
new file mode 100644
index 00000000..5480cf43
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/CurrencyTable.java
@@ -0,0 +1,84 @@
+/*
+ * File: CurrencyTable.java
+ * ------------------------
+ * This file provides a stub implementation of the CurrencyTable
+ * class used by the CurrencyConverter example. This implementation
+ * simply returns a set of data values stored statically in the
+ * class. A more ambitious implementation could go out to the web
+ * and retrieve the actual data.
+ */
+
+import acm.util.*;
+
+/** This class implements a currency table */
+public class CurrencyTable {
+
+/** Return an array containing the names of all defined currencies */
+ public String[] getCurrencyNames() {
+ int nCurrencies = CURRENCIES.length;
+ String[] names = new String[nCurrencies];
+ for (int i = 0; i < nCurrencies; i++) {
+ names[i] = CURRENCIES[i].getName();
+ }
+ return names;
+ }
+
+/** Return the exchange rate for a named currency */
+ public double getExchangeRate(String name) {
+ for (int i = 0; i < CURRENCIES.length; i++) {
+ if (name.equalsIgnoreCase(CURRENCIES[i].getName())) {
+ return CURRENCIES[i].getRate();
+ }
+ }
+ throw new ErrorException("No currency named " + name);
+ }
+
+/** Return the date at which the exchange rate is calculated */
+ public String getDate() {
+ return TABLE_DATE;
+ }
+
+/* Currency table (Source: Interbank Rate for 22-Jul-05) */
+ private static final String TABLE_DATE = "22-Jul-05";
+ private static final CurrencyEntry[] CURRENCIES = {
+ new CurrencyEntry("Australian Dollar", 0.766),
+ new CurrencyEntry("Brazilian Real", 0.435),
+ new CurrencyEntry("British Pound", 1.754),
+ new CurrencyEntry("Canadian Dollar", 0.821),
+ new CurrencyEntry("Chinese Yuan", 0.121),
+ new CurrencyEntry("Euro", 1.218),
+ new CurrencyEntry("Japanese Yen", 0.00908),
+ new CurrencyEntry("Mexican Peso", 0.942),
+ new CurrencyEntry("South African Rand", 0.153),
+ new CurrencyEntry("Swiss Franc", 0.779),
+ new CurrencyEntry("US Dollar", 1.000)
+ };
+}
+
+/* Package class: CurrencyEntry */
+/**
+ * This class is used to store the name of a currency together with
+ * its relative value in comparison to the other currencies. The
+ * example defines the dollar as 1.0, but the code does not depend
+ * on that definition.
+ */
+
+class CurrencyEntry {
+
+ public CurrencyEntry(String name, double rate) {
+ currencyName = name;
+ exchangeRate = rate;
+ }
+
+ public String getName() {
+ return currencyName;
+ }
+
+ public double getRate() {
+ return exchangeRate;
+ }
+
+ private String currencyName;
+ private double exchangeRate;
+
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/DrawFace.java b/ss2010/gdi2/java/libs/acm/demo/DrawFace.java
new file mode 100644
index 00000000..c1a88e7e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/DrawFace.java
@@ -0,0 +1,37 @@
+/*
+ * File: DrawFace.java
+ * -------------------
+ * This program creates a GFace object.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.event.*;
+
+public class DrawFace extends GraphicsProgram {
+
+ public void run() {
+ face = new GFace(FACE_WIDTH, FACE_HEIGHT);
+ add(face, getWidth() / 2, getHeight() / 2);
+ addMouseListeners();
+ }
+
+/** Called when the mouse is moved to adjust the eyes */
+ public void mouseMoved(MouseEvent e) {
+ face.lookAt(e.getX(), e.getY());
+ }
+
+/* Constants */
+ private static final double FACE_WIDTH = 200;
+ private static final double FACE_HEIGHT = 300;
+
+/* Private instance variables */
+ private GFace face;
+ private GObject gobj;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new DrawFace().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/DrawLine.java b/ss2010/gdi2/java/libs/acm/demo/DrawLine.java
new file mode 100644
index 00000000..a68d4309
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/DrawLine.java
@@ -0,0 +1,41 @@
+/*
+ * File: DrawLine.java
+ * -------------------
+ * This program allows users to create lines on the graphics
+ * canvas by clicking and dragging with the mouse. The line
+ * is redrawn from the original point to the new endpoint, which
+ * makes it look as if it is connected with a rubber band.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.event.*;
+
+/** This class allows users to draw lines on the canvas */
+public class DrawLine extends GraphicsProgram {
+
+/** Initializes the program by enabling the mouse listeners */
+ public void init() {
+ addMouseListeners();
+ }
+
+/** Called on mouse press to create a new line */
+ public void mousePressed(MouseEvent e) {
+ line = new GLine(e.getX(), e.getY(), e.getX(), e.getY());
+ add(line);
+ }
+
+/** Called on mouse drag to reset the endpoint */
+ public void mouseDragged(MouseEvent e) {
+ line.setEndPoint(e.getX(), e.getY());
+ }
+
+/* Private instance variables */
+ private GLine line;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new DrawLine().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower1.java b/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower1.java
new file mode 100644
index 00000000..0dd3e31d
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower1.java
@@ -0,0 +1,33 @@
+/*
+ * File: DrawTurtleFlower1.java
+ * ----------------------------
+ * This program draws a turtle flower using receiver-relative
+ * invocations in a single, undecomposed run method.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+
+public class DrawTurtleFlower1 extends GraphicsProgram {
+
+/**
+ * Runs the program. This program creates a GTurtle object,
+ * puts it in the center of the screen, and then draws a flower.
+ * The flower consiste of 36 squares, with a 10-degrees rotation
+ * between each one. The squares, in turn, are drawn by drawing
+ * four line segments interspersed with 90-degree rotations.
+ */
+ public void run() {
+ GTurtle turtle = new GTurtle();
+ add(turtle, getWidth() / 2, getHeight() / 2);
+ turtle.penDown();
+ for (int i = 0; i < 36; i++) {
+ for (int j = 0; j < 4; j++) {
+ turtle.forward(100);
+ turtle.left(90);
+ }
+ turtle.left(10);
+ }
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower2.java b/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower2.java
new file mode 100644
index 00000000..6ea15b27
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower2.java
@@ -0,0 +1,45 @@
+/*
+ * File: DrawTurtleFlower2.java
+ * ----------------------------
+ * This program draws a turtle flower using receiver-relative
+ * invocations and two levels of decomposition.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+
+public class DrawTurtleFlower2 extends GraphicsProgram {
+
+/**
+ * Runs the program. This program creates a GTurtle object,
+ * puts it in the center of the screen, and then draws a flower.
+ */
+ public void run() {
+ turtle = new GTurtle();
+ add(turtle, getWidth() / 2, getHeight() / 2);
+ turtle.penDown();
+ drawFlower();
+ }
+
+/** Draws a flower with 36 squares separated by 10-degree turns. */
+ private void drawFlower() {
+ for (int i = 0; i < 36; i++) {
+ drawSquare();
+ turtle.left(10);
+ }
+ }
+
+/** Draws a square with four lines separated by 90-degree turns. */
+ private void drawSquare() {
+ for (int i = 0; i < 4; i++) {
+ turtle.forward(100);
+ turtle.left(90);
+ }
+ }
+
+/** Holds the GTurtle object as an instance variable */
+ private GTurtle turtle;
+
+}
+
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower3.java b/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower3.java
new file mode 100644
index 00000000..289a3e0c
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/DrawTurtleFlower3.java
@@ -0,0 +1,46 @@
+/*
+ * File: DrawTurtleFlower3.java
+ * ----------------------------
+ * This program draws a turtle flower using a GTurtle subclass
+ * that knows how to draw flowers.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+
+public class DrawTurtleFlower3 extends GraphicsProgram {
+
+/**
+ * Runs the program. This program creates a FlowerTurtle object,
+ * centers it in the screen, and then asks it to draw a flower.
+ */
+ public void run() {
+ FlowerTurtle turtle = new FlowerTurtle();
+ add(turtle, getWidth() / 2, getHeight() / 2);
+ turtle.penDown();
+ turtle.drawFlower();
+ }
+}
+
+/**
+ * A GTurtle subclass that knows how to draw a flower.
+ */
+
+class FlowerTurtle extends GTurtle {
+
+/** Draws a flower with 36 squares separated by 10-degree turns. */
+ public void drawFlower() {
+ for (int i = 0; i < 36; i++) {
+ drawSquare();
+ left(10);
+ }
+ }
+
+/** Draws a square with four lines separated by 90-degree turns. */
+ private void drawSquare() {
+ for (int i = 0; i < 4; i++) {
+ forward(100);
+ left(90);
+ }
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/Empty.java b/ss2010/gdi2/java/libs/acm/demo/Empty.java
new file mode 100644
index 00000000..443fb26e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Empty.java
@@ -0,0 +1,16 @@
+
+public class Empty {
+
+ public String look;
+
+ Empty () {
+ look = " ";
+ }
+
+ String show(int width){
+ String row ="";
+ for (int i=0;i<=width;i++)
+ row += look;
+ return row;
+ }
+}
\ No newline at end of file
diff --git a/ss2010/gdi2/java/libs/acm/demo/FeltBoard.java b/ss2010/gdi2/java/libs/acm/demo/FeltBoard.java
new file mode 100644
index 00000000..36c7498a
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/FeltBoard.java
@@ -0,0 +1,39 @@
+/*
+ * File: FeltBoard.java
+ * --------------------
+ * This program offers a simple example of the acm.graphics package
+ * that draws a red rectangle and a green oval. The dimensions of
+ * the rectangle are chosen so that its sides are in proportion to
+ * the "golden ratio" thought by the Greeks to represent the most
+ * aesthetically pleasing geometry.
+ */
+
+import java.awt.Color;
+
+import acm.graphics.GOval;
+import acm.graphics.GRect;
+import acm.program.GraphicsProgram;
+
+public class FeltBoard extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ GRect rect = new GRect(100, 50, 100, 100 / PHI);
+ rect.setFilled(true);
+ rect.setColor(Color.RED);
+ add(rect);
+ GOval oval = new GOval(150, 50 + 50 / PHI, 100, 100 / PHI);
+ oval.setFilled(true);
+ oval.setColor(Color.GREEN);
+ add(oval);
+ }
+
+/** Constant representing the golden ratio */
+ public static final double PHI = 1.618;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new FeltBoard().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/FeltBoard2.java b/ss2010/gdi2/java/libs/acm/demo/FeltBoard2.java
new file mode 100644
index 00000000..42b43511
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/FeltBoard2.java
@@ -0,0 +1,45 @@
+/*
+ * File: FeltBoard.java
+ * --------------------
+ * This program offers a simple example of the acm.graphics package
+ * that draws a red rectangle and a green oval. The dimensions of
+ * the rectangle are chosen so that its sides are in proportion to
+ * the "golden ratio" thought by the Greeks to represent the most
+ * aesthetically pleasing geometry.
+ */
+
+import java.awt.Color;
+
+import acm.graphics.GOval;
+import acm.graphics.GRect;
+import acm.graphics.GSquare;
+import acm.program.GraphicsProgram;
+
+public class FeltBoard2 extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ GRect rect = new GRect(100, 50, 100, 100 / PHI);
+ rect.setFilled(true);
+ rect.setColor(Color.RED);
+ add(rect);
+ GOval oval = new GOval(150, 50 + 50 / PHI, 100, 100 / PHI);
+ oval.setFilled(true);
+ oval.setColor(Color.GREEN);
+ add(oval);
+ GSquare square = new GSquare(120, 80, 60);
+ square.setColor(Color.black);
+ add(square);
+ GShadedRectangle gsr = new GShadedRectangle(60,90,100,120);
+ add(gsr);
+ }
+
+/** Constant representing the golden ratio */
+ public static final double PHI = 1.618;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new FeltBoard2().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/FeltBoard3.java b/ss2010/gdi2/java/libs/acm/demo/FeltBoard3.java
new file mode 100644
index 00000000..12f46300
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/FeltBoard3.java
@@ -0,0 +1,53 @@
+/*
+ * File: FeltBoard.java
+ * --------------------
+ * This program offers a simple example of the acm.graphics package
+ * that draws a red rectangle and a green oval. The dimensions of
+ * the rectangle are chosen so that its sides are in proportion to
+ * the "golden ratio" thought by the Greeks to represent the most
+ * aesthetically pleasing geometry.
+ */
+
+import java.awt.Color;
+
+import acm.graphics.GRect;
+import acm.graphics.GSquare2;
+import acm.graphics.GStrangeRect;
+import acm.graphics.GStringArray;
+import acm.graphics.GStringArrayCompound;
+import acm.program.GraphicsProgram;
+
+public class FeltBoard3 extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ GRect rect = new GRect(100, 50, 100, 100 / PHI);
+ rect.setFilled(true);
+ rect.setColor(Color.RED);
+ add(rect);
+ GSquare2 sq2 = new GSquare2(100,80, 80);
+ sq2.setColor(Color.GREEN);
+ add(sq2);
+ GStrangeRect rect2 = new GStrangeRect(130, 80, 100, 100 / PHI);
+ rect2.setFilled(true);
+ rect2.setColor(Color.RED);
+ add(rect2);
+ String[] demo = new String[]{"Book2","Page9","Chapter 24.10","P3", "Word 17"};
+// GStringArray array1 = new GStringArray(demo, 200, 200);
+// add(array1);
+ GStringArrayCompound array2 = new GStringArrayCompound(demo, 200, 300);
+ array2.setColor(Color.black);
+ array2.markAsComplete();
+ add(array2);
+ System.err.println(array2 +"\n "+array2.getElementCount() );
+ }
+
+/** Constant representing the golden ratio */
+ public static final double PHI = 1.618;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new FeltBoard3().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/FlowerTurtleProgram.java b/ss2010/gdi2/java/libs/acm/demo/FlowerTurtleProgram.java
new file mode 100644
index 00000000..895e2312
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/FlowerTurtleProgram.java
@@ -0,0 +1,34 @@
+/*
+ * File: FlowerTurtleProgram.java
+ * ------------------------------
+ * This program draws a turtle flower by invoking a GTurtle
+ * object as if it were a program.
+ */
+
+import acm.graphics.*;
+
+public class FlowerTurtleProgram extends GTurtle {
+
+/** Runs the program. */
+ public void run() {
+ penDown();
+ flower();
+ }
+
+/** Draws a flower with 36 squares separated by 10-degree turns. */
+ private void flower() {
+ for (int i = 0; i < 36; i++) {
+ square();
+ left(10);
+ }
+ }
+
+/** Draws a square with four lines separated by 90-degree turns. */
+ private void square() {
+ for (int i = 0; i < 4; i++) {
+ forward(100);
+ left(90);
+ }
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/GBall.java b/ss2010/gdi2/java/libs/acm/demo/GBall.java
new file mode 100644
index 00000000..d7945aa5
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/GBall.java
@@ -0,0 +1,29 @@
+/*
+ * File: GBall.java
+ * ----------------
+ * This file defines a GObject class that represents a ball.
+ */
+
+import acm.graphics.*;
+
+/**
+ * This class defines a GObject subclass that represents a ball
+ * whose reference point is the center rather than the upper
+ * left corner.
+ */
+public class GBall extends GCompound {
+
+/** Creates a new ball with radius r centered at the origin */
+ public GBall(double r) {
+ GOval ball = new GOval(2 * r, 2 * r);
+ ball.setFilled(true);
+ add(ball, -r, -r);
+ markAsComplete();
+ }
+
+/** Creates a new ball with radius r centered at (x, y) */
+ public GBall(double r, double x, double y) {
+ this(r);
+ setLocation(x, y);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/GEye.java b/ss2010/gdi2/java/libs/acm/demo/GEye.java
new file mode 100644
index 00000000..6b7e11c5
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/GEye.java
@@ -0,0 +1,40 @@
+/*
+ * File: GEye.java
+ * ---------------
+ * This file defines a GEye class that can look in a particular
+ * direction.
+ */
+
+import acm.graphics.*;
+
+public class GEye extends GCompound {
+
+/** Creates a new instance of the GEye class */
+ public GEye(double width, double height) {
+ add(new GOval(width, height), -width / 2, -height / 2);
+ r = PUPIL_RADIUS_FRACTION * Math.min(width, height);
+ pupil = new GOval(2 * r, 2 * r);
+ pupil.setFilled(true);
+ add(pupil, -r, -r);
+ }
+
+/**
+ * Shifts the eye to look at the point (x, y). Note that x
+ * and y are in the coordinate system of the canvas and not
+ * in the local coordinate space of the compound. The call
+ * to getCanvasPoint returns the coordinate of the eye shifted
+ * to the space of the canvas.
+ */
+ public void lookAt(double x, double y) {
+ GPoint pt = getCanvasPoint(0, 0);
+ pupil.setLocation(-r, -r);
+ pupil.movePolar(r, GMath.angle(x - pt.getX(), y - pt.getY()));
+ }
+
+/* Pupil radius as a function of the eye size */
+ private static final double PUPIL_RADIUS_FRACTION = 0.2;
+
+/* Instance variables */
+ private GOval pupil;
+ private double r;
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/GFace.java b/ss2010/gdi2/java/libs/acm/demo/GFace.java
new file mode 100644
index 00000000..9c6fc7fe
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/GFace.java
@@ -0,0 +1,59 @@
+/*
+ * File: GFace.java
+ * ----------------
+ * This file defines a compound GFace class.
+ */
+
+import acm.graphics.*;
+
+/**
+ * This class defines a new GObject subclass called GFace, which is
+ * a compound consisting of an outline, two eyes, a nose, and a mouth.
+ * The origin point for the face is the center of the figure.
+ */
+public class GFace extends GCompound {
+
+/** Construct a new GFace object with the specified dimensions */
+ public GFace(double width, double height) {
+ head = new GOval(width, height);
+ leftEye = new GEye(EYE_WIDTH * width, EYE_HEIGHT * height);
+ rightEye = new GEye(EYE_WIDTH * width, EYE_HEIGHT * height);
+ nose = createNose(NOSE_WIDTH * width, NOSE_HEIGHT * height);
+ mouth = new GRect(MOUTH_WIDTH * width, MOUTH_HEIGHT * height);
+ add(head, -width / 2, -height / 2);
+ add(leftEye, -0.25 * width, -0.25 * height);
+ add(rightEye, 0.25 * width, -0.25 * height);
+ add(nose, 0, 0);
+ add(mouth, -MOUTH_WIDTH * width / 2,
+ 0.25 * height - MOUTH_HEIGHT * height / 2);
+ }
+
+/* Creates a triangle for the nose */
+ private GPolygon createNose(double width, double height) {
+ GPolygon poly = new GPolygon();
+ poly.addVertex(0, -height / 2);
+ poly.addVertex(width / 2, height / 2);
+ poly.addVertex(-width / 2, height / 2);
+ return poly;
+ }
+
+/** Adjusts the eyes so they look at the point (x, y) */
+ public void lookAt(double x, double y) {
+ leftEye.lookAt(x, y);
+ rightEye.lookAt(x, y);
+ }
+
+/* Constants specifying feature size as a fraction of the head size */
+ private static final double EYE_WIDTH = 0.15;
+ private static final double EYE_HEIGHT = 0.15;
+ private static final double NOSE_WIDTH = 0.15;
+ private static final double NOSE_HEIGHT = 0.10;
+ private static final double MOUTH_WIDTH = 0.50;
+ private static final double MOUTH_HEIGHT = 0.03;
+
+/* Private instance variables */
+ private GOval head;
+ private GEye leftEye, rightEye;
+ private GPolygon nose;
+ private GRect mouth;
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/GShadedObject.java b/ss2010/gdi2/java/libs/acm/demo/GShadedObject.java
new file mode 100644
index 00000000..dbfd2655
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/GShadedObject.java
@@ -0,0 +1,29 @@
+import java.awt.Color;
+import java.awt.Graphics;
+
+import acm.graphics.GObject;
+import acm.graphics.GRoundRect;
+
+public abstract class GShadedObject extends GObject {
+
+ private GRoundRect rect;
+
+ public GShadedObject(double x, double y, double w, double h) {
+ rect = new GRoundRect(getLocation().getX()+5, getLocation().getY()+5,
+ getWidth(), getHeight());
+ rect.setFilled(true);
+ rect.setFillColor(Color.GRAY);
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ if (rect == null) {
+
+ rect = new GRoundRect(getLocation().getX(), getLocation().getY(),
+ getWidth(), getHeight());
+ rect.setFilled(true);
+ rect.setFillColor(Color.GRAY);
+ }
+ rect.paint(g);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/GShadedRectangle.java b/ss2010/gdi2/java/libs/acm/demo/GShadedRectangle.java
new file mode 100644
index 00000000..6d5a59f9
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/GShadedRectangle.java
@@ -0,0 +1,31 @@
+import java.awt.Color;
+import java.awt.Graphics;
+
+import acm.graphics.GRect;
+import acm.graphics.GRectangle;
+
+
+public class GShadedRectangle extends GShadedObject {
+
+ GRect myRect;
+
+ public GShadedRectangle(double x, double y, double w, double h) {
+ super(x, y, w, h);
+ myRect = new GRect(x, y, w, h);
+ myRect.setFilled(true);
+ myRect.setFillColor(Color.BLUE);
+ }
+ @Override
+ public GRectangle getBounds() {
+ return myRect.getBounds();
+// return new GRectangle(100, 100, 200, 200);
+// return new GRectangle(rect.getX(), rect.getY(),
+// rect.getWidth()+5, rect.getHeight()+5);
+ }
+
+ public void paint(Graphics g) {
+ super.paint(g);
+ myRect.paint(g);
+ }
+
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/GStar.java b/ss2010/gdi2/java/libs/acm/demo/GStar.java
new file mode 100644
index 00000000..02392238
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/GStar.java
@@ -0,0 +1,39 @@
+/*
+ * File: GStar.java
+ * ----------------
+ * This file illustrates the strategy of subclassing GPolygon by
+ * creating a new GObject class depicting a five-pointed star.
+ */
+
+import acm.graphics.*;
+
+public class GStar extends GPolygon {
+
+/**
+ * Creates a new GStar centered at the origin that fits inside
+ * a square of the specified size.
+ */
+ public GStar(double size) {
+ double sinTheta = GMath.sinDegrees(18);
+ double b = 0.5 * sinTheta / (1.0 + sinTheta);
+ double edge = (0.5 - b) * size;
+ addVertex(-size / 2, -b * size);
+ int angle = 0;
+ for (int i = 0; i < 5; i++) {
+ addPolarEdge(edge, angle);
+ addPolarEdge(edge, angle + 72);
+ angle -= 72;
+ }
+ markAsComplete();
+ }
+
+/**
+ * Creates a new GStar centered at the point (x, y) that fits inside
+ * a square of the specified size.
+ */
+ public GStar(double x, double y, double size) {
+ this(size);
+ setLocation(x, y);
+ }
+
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/HelloConsole.java b/ss2010/gdi2/java/libs/acm/demo/HelloConsole.java
new file mode 100644
index 00000000..ad7c8d2e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/HelloConsole.java
@@ -0,0 +1,23 @@
+/*
+ * File: HelloConsole.java
+ * -----------------------
+ * This program displays the message "hello, world" and is inspired
+ * by the first program "The C Programming Language" by Brian
+ * Kernighan and Dennis Ritchie. This version displays its message
+ * using a console window.
+ */
+
+import acm.program.ConsoleProgram;
+
+public class HelloConsole extends ConsoleProgram {
+
+ public void run() {
+ println("hello, world");
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new HelloConsole().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/HelloDialog.java b/ss2010/gdi2/java/libs/acm/demo/HelloDialog.java
new file mode 100644
index 00000000..929d9ad4
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/HelloDialog.java
@@ -0,0 +1,23 @@
+/*
+ * File: HelloDialog.java
+ * ----------------------
+ * This program displays the message "hello, world" and is inspired
+ * by the first program "The C Programming Language" by Brian
+ * Kernighan and Dennis Ritchie. This version displays the message
+ * in a dialog box.
+ */
+
+import acm.program.DialogProgram;
+
+public class HelloDialog extends DialogProgram {
+
+ public void run() {
+ println("hello, world");
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new HelloDialog().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/HelloGraphics.java b/ss2010/gdi2/java/libs/acm/demo/HelloGraphics.java
new file mode 100644
index 00000000..4ca6090f
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/HelloGraphics.java
@@ -0,0 +1,28 @@
+/*
+ * File: HelloGraphics.java
+ * ------------------------
+ * This program displays the message "hello, world" and is inspired
+ * by the first program "The C Programming Language" by Brian
+ * Kernighan and Dennis Ritchie. This version displays the message
+ * graphically.
+ */
+
+import acm.graphics.GLabel;
+import acm.program.GraphicsProgram;
+
+public class HelloGraphics extends GraphicsProgram {
+
+ public void run() {
+ GLabel label = new GLabel("hello, world");
+ label.setFont("SansSerif-100");
+ double x = (getWidth() - label.getWidth()) / 2;
+ double y = (getHeight() + label.getAscent()) / 2;
+ add(label, x, y);
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new HelloGraphics().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/KochSnowflake.java b/ss2010/gdi2/java/libs/acm/demo/KochSnowflake.java
new file mode 100644
index 00000000..83dc4711
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/KochSnowflake.java
@@ -0,0 +1,65 @@
+/*
+ * File: KochSnowflake.java
+ * ------------------------
+ * This program demonstrates the use of the GPen class by drawing
+ * a Koch fractal snowflake.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+
+public class KochSnowflake extends GraphicsProgram {
+
+/** Runs the program to create the snowflake display */
+ public void run() {
+ double width = getWidth();
+ double height = getHeight();
+ pen = new GPen();
+ add(pen, width / 2, height / 2);
+ drawKochFractal(EDGE_FRACTION * Math.min(width, height), ORDER);
+ }
+
+/*
+ * Draws a snowflake fractal centered at the current pen position.
+ * The edge parameter indicates the length of any of an edge on the
+ * order 0 fractal, which is simply a triangle. The order parameter
+ * specifies the number of levels of recursive decomposition.
+ */
+ private void drawKochFractal(double edge, int order) {
+ pen.move(-edge / 2, -edge / (2 * Math.sqrt(3)));
+ drawFractalLine(edge, 0, order);
+ drawFractalLine(edge, -120, order);
+ drawFractalLine(edge, +120, order);
+ }
+
+/*
+ * Draws a fractal line that extends r pixels in the direction theta.
+ * If order is 0, this is simply a line segment. If not, the program
+ * creates a fractal line that includes a triangular wedge at its
+ * center. Each of the line segments is drawn as a fractal line of
+ * the next lower order.
+ */
+ private void drawFractalLine(double r, int theta, int order) {
+ if (order == 0) {
+ pen.drawPolarLine(r, theta);
+ } else {
+ drawFractalLine(r / 3, theta, order - 1);
+ drawFractalLine(r / 3, theta + 60, order - 1);
+ drawFractalLine(r / 3, theta - 60, order - 1);
+ drawFractalLine(r / 3, theta, order - 1);
+ }
+ }
+
+/* Private constants */
+ private static final double EDGE_FRACTION = 0.75;
+ private static final int ORDER = 3;
+
+/* Private instance variables */
+ private GPen pen;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new KochSnowflake().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/Leafs.java b/ss2010/gdi2/java/libs/acm/demo/Leafs.java
new file mode 100644
index 00000000..dc98e934
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Leafs.java
@@ -0,0 +1,24 @@
+
+public class Leafs extends Empty{
+ Leafs () {
+ look = "*";
+ }
+
+ String show(int width){
+ String row ="";
+ Sphere blue = new Sphere();
+ if (width>=5){
+ int a = (width-3)/2;
+ int b = width - 2*a;
+ row += this.show(a)+blue.show(b)+this.show(a);
+ }else if (width>=3){
+ int a = (width-1)/2;
+ int b = width - 2*a;
+ row += this.show(a)+blue.show(b)+this.show(a);
+ }else if (width>=1){
+ row += look+this.show(width-1);
+ }
+
+ return row;
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/ProgramLayoutDemo.java b/ss2010/gdi2/java/libs/acm/demo/ProgramLayoutDemo.java
new file mode 100644
index 00000000..9eb65a6d
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/ProgramLayoutDemo.java
@@ -0,0 +1,68 @@
+/*
+ * File: ProgramLayoutDemo.java
+ * ----------------------------
+ * This program illustrates the ProgramLayout mechanism.
+ */
+
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/**
+ * This class creates a self-documenting example of the proposed
+ * ProgramLayout mechanism. In this example, the center of the
+ * window is occupied by an IOConsole, which is created by the
+ * ConsoleProgram. The constructor for this example adds several
+ * JButtons to show how ProgramLayout organizes each region.
+ */
+public class ProgramLayoutDemo extends ConsoleProgram {
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 600;
+ public static final int APPLICATION_HEIGHT = 350;
+
+/** Install the buttons for the program */
+ public ProgramLayoutDemo() {
+ add(new JButton("N1"), NORTH);
+ add(new JButton("N2"), NORTH);
+ add(new JButton("N3"), NORTH);
+ add(new JButton("W1"), WEST);
+ add(new JButton("W2"), WEST);
+ add(new JButton("E1"), EAST);
+ add(new JButton("E2"), EAST);
+ add(new JButton("S1"), SOUTH);
+ add(new JScrollBar(JScrollBar.HORIZONTAL), SOUTH, "fill=HORIZONTAL");
+ add(new JButton("S2"), SOUTH);
+ addActionListeners();
+ }
+
+/** Run the program */
+ public void run() {
+ println("This program is a simple test of the ProgramLayout");
+ println("manager. The main class extends ConsoleProgram,");
+ println("which means that an IOConsole is automatically added");
+ println("to the CENTER component. The NORTH and SOUTH regions");
+ println("use a TableLayout manager specifying a single row;");
+ println("the WEST and EAST regions use a TableLayout manager");
+ println("specifying a single column. The SOUTH region includes");
+ println("a JScrollBar along with the JButtons to show how the");
+ println("layout manager automaticaly assigns more than the");
+ println("minimum width, which would show an empty scrollbar.");
+ println();
+ println("Although this example shows interactors along all");
+ println("four edges, students will typically add interactors");
+ println("along only one edge.");
+ println();
+ }
+
+/** Respond to action events */
+ public void actionPerformed(ActionEvent e) {
+ println("Button " + e.getActionCommand() + " pressed.");
+ }
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new ProgramLayoutDemo().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/RandomShapes.java b/ss2010/gdi2/java/libs/acm/demo/RandomShapes.java
new file mode 100644
index 00000000..311b3515
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/RandomShapes.java
@@ -0,0 +1,64 @@
+/*
+ * File: RandomShapes.java
+ * -----------------------
+ * This file creates ten boxes, ovals, and stars at random locations
+ * on the screen, pausing for a suitable interval between each one.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import acm.util.*;
+
+public class RandomShapes extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ while (true) {
+ for (int i = 0; i < NOBJECTS; i++) {
+ addOneRandomShape();
+ pause(PAUSE_TIME);
+ }
+ waitForClick();
+ removeAll();
+ }
+ }
+
+/* Adds a random shape to the canvas */
+ private void addOneRandomShape() {
+ GObject gobj = createRandomShape();
+ gobj.setColor(rgen.nextColor());
+ if (gobj instanceof GFillable) ((GFillable) gobj).setFilled(true);
+ double x = rgen.nextDouble(0, getWidth() - gobj.getWidth())
+ - gobj.getBounds().getX();
+ double y = rgen.nextDouble(0, getHeight() - gobj.getHeight())
+ - gobj.getBounds().getY();
+ add(gobj, x, y);
+ }
+
+/* Generates a random shape whose reference point is the origin */
+ private GObject createRandomShape() {
+ double width = rgen.nextDouble(MIN_SIZE, MAX_SIZE);
+ double height = rgen.nextDouble(MIN_SIZE, MAX_SIZE);
+ switch (rgen.nextInt(3)) {
+ case 0: return new GRect(width, height);
+ case 1: return new GOval(width, height);
+ case 2: return new GStar(width);
+ default: throw new ErrorException("Illegal shape index");
+ }
+ }
+
+/* Private constants */
+ private static final int NOBJECTS = 10;
+ private static final int PAUSE_TIME = 1000;
+ private static final double MIN_SIZE = 25;
+ private static final double MAX_SIZE = 150;
+
+/* Private instance variables */
+ private RandomGenerator rgen = RandomGenerator.getInstance();
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new RandomShapes().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/RunnableGBall.java b/ss2010/gdi2/java/libs/acm/demo/RunnableGBall.java
new file mode 100644
index 00000000..c958863a
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/RunnableGBall.java
@@ -0,0 +1,54 @@
+/*
+ * File: RunnableGBall.java
+ * ------------------------
+ * This file defines an extension to the GBall class that is
+ * designed to run as a separate thread of control.
+ */
+
+public class RunnableGBall extends GBall implements Runnable {
+
+/** Creates a new ball with radius r centered at the origin */
+ public RunnableGBall(double r) {
+ super(r);
+ }
+
+/** Sets the size of the enclosure */
+ public void setEnclosureSize(double width, double height) {
+ enclosureWidth = width;
+ enclosureHeight = height;
+ }
+
+/** Sets the velocity of the ball */
+ public void setVelocity(double vx, double vy) {
+ dx = vx;
+ dy = vy;
+ }
+
+/** Run forever bouncing the ball */
+ public void run() {
+ while (true) {
+ advanceOneTimeStep();
+ pause(PAUSE_TIME);
+ }
+ }
+
+/** Check for bounces and advance the ball */
+ private void advanceOneTimeStep() {
+ double bx = getX();
+ double by = getY();
+ double r = getWidth() / 2;
+ if (bx < r || bx > enclosureWidth - r) dx = -dx;
+ if (by < r || by > enclosureHeight - r) dy = -dy;
+ move(dx, dy);
+ }
+
+/* Private constants */
+ private static final int PAUSE_TIME = 20;
+
+/* Private instance variables */
+ private double enclosureWidth;
+ private double enclosureHeight;
+ private double dx;
+ private double dy;
+
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/SelSort.java b/ss2010/gdi2/java/libs/acm/demo/SelSort.java
new file mode 100644
index 00000000..f5ad5c3a
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/SelSort.java
@@ -0,0 +1,32 @@
+/*
+ * Created on 19.09.2007 by Guido Roessling
+ */
+
+public class SelSort {
+ public void selection(int[] f, int n) {
+ int i, j, m, hilf;
+ for (i=n-1; i>0; i--) {
+ m = 0;
+ for (j=1; j<=i; j++)
+ if (f[j] > f[m])
+ m = j;
+ hilf = f[i];
+ f[i] = f[m];
+ f[m] = hilf;
+ }
+ }
+
+ public void printArray(int[] array) {
+ for (int i=0; i= 2){
+ row += tiny+this.show(width -2)+tiny;
+ }else if (width >= 1){
+ row += big;
+ }
+ return row;
+ }
+
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/Stoplight.java b/ss2010/gdi2/java/libs/acm/demo/Stoplight.java
new file mode 100644
index 00000000..caaf2539
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Stoplight.java
@@ -0,0 +1,82 @@
+/*
+ * File: Stoplight.java
+ * --------------------
+ * This class implements a stoplight as a compound graphical object.
+ */
+
+import acm.graphics.*;
+import acm.util.*;
+import java.awt.*;
+
+/**
+ * This class represents a graphical stoplight with its origin point
+ * at the center.
+ */
+
+public class Stoplight extends GCompound {
+
+/* Public constants for the colors */
+ public static final Color GREEN = Color.GREEN;
+ public static final Color YELLOW = Color.YELLOW;
+ public static final Color RED = Color.RED;
+
+/** Creates a new Stoplight object, which is initially red */
+ public Stoplight() {
+ GRect frame = new GRect(STOPLIGHT_WIDTH, STOPLIGHT_HEIGHT);
+ frame.setFilled(true);
+ frame.setColor(Color.DARK_GRAY);
+ add(frame, -STOPLIGHT_WIDTH / 2, -STOPLIGHT_HEIGHT / 2);
+ redLamp = createLamp(0, -STOPLIGHT_HEIGHT / 4);
+ yellowLamp = createLamp(0, 0);
+ greenLamp = createLamp(0, STOPLIGHT_HEIGHT / 4);
+ add(redLamp);
+ add(yellowLamp);
+ add(greenLamp);
+ setState(RED);
+ }
+
+/** Changes the state of the stoplight to the indicated color */
+ public void setState(Color color) {
+ state = color;
+ redLamp.setColor((state == RED) ? state : Color.GRAY);
+ yellowLamp.setColor((state == YELLOW) ? state : Color.GRAY);
+ greenLamp.setColor((state == GREEN) ? state : Color.GRAY);
+ }
+
+/** Returns the current state of the stoplight */
+ public Color getState() {
+ return state;
+ }
+
+/** Advances the stoplight to the next color */
+ public void advance() {
+ if (state == RED) {
+ setState(GREEN);
+ } else if (state == YELLOW) {
+ setState(RED);
+ } else if (state == GREEN) {
+ setState(YELLOW);
+ } else {
+ throw new ErrorException("Illegal stoplight state");
+ }
+ }
+
+/* Creates a new GOval to represent one of the three lamps */
+ private GOval createLamp(double x, double y) {
+ GOval lamp = new GOval(x - LAMP_RADIUS, y - LAMP_RADIUS,
+ 2 * LAMP_RADIUS, 2 * LAMP_RADIUS);
+ lamp.setFilled(true);
+ return lamp;
+ }
+
+/* Private constants */
+ private static final double STOPLIGHT_WIDTH = 50;
+ private static final double STOPLIGHT_HEIGHT = 100;
+ private static final double LAMP_RADIUS = 10;
+
+/* Private instance variables */
+ private Color state;
+ private GOval redLamp;
+ private GOval yellowLamp;
+ private GOval greenLamp;
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/StoplightConsole.java b/ss2010/gdi2/java/libs/acm/demo/StoplightConsole.java
new file mode 100644
index 00000000..dab2defc
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/StoplightConsole.java
@@ -0,0 +1,41 @@
+/*
+ * File: StoplightConsole.java
+ * ---------------------------
+ * This program illustrates the construction of a simple GUI.
+ */
+
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/**
+ * This class displays three buttons at the south edge of the window.
+ * The name of the button is echoed on the console each time a button
+ * is pressed.
+ */
+
+public class StoplightConsole extends ConsoleProgram {
+
+/** Initialize the GUI */
+ public void init() {
+ add(new JButton("Green"), SOUTH);
+ add(new JButton("Yellow"), SOUTH);
+ add(new JButton("Red"), SOUTH);
+ addActionListeners();
+ }
+
+/** Listen for a button action */
+ public void actionPerformed(ActionEvent e) {
+ println(e.getActionCommand());
+ }
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 350;
+ public static final int APPLICATION_HEIGHT = 250;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new StoplightConsole().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/StoplightGraphics.java b/ss2010/gdi2/java/libs/acm/demo/StoplightGraphics.java
new file mode 100644
index 00000000..1bf90ecf
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/StoplightGraphics.java
@@ -0,0 +1,57 @@
+/*
+ * File: StoplightGraphics.java
+ * ----------------------------
+ * This program illustrates the construction of a simple GUI using a
+ * GraphicsProgram as the main class.
+ */
+
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/**
+ * This class displays four buttons at the south edge of the window.
+ * Pressing a button lights the indicated lamp in the stoplight or
+ * advances the stoplight to its next configuration.
+ */
+
+public class StoplightGraphics extends GraphicsProgram {
+
+/** Initialize the buttons and create the stoplight */
+ public void init() {
+ add(new JButton("Green"), SOUTH);
+ add(new JButton("Yellow"), SOUTH);
+ add(new JButton("Red"), SOUTH);
+ add(new JButton("Advance"), SOUTH);
+ signal = new Stoplight();
+ add(signal, getWidth() / 2, getHeight() / 2);
+ addActionListeners();
+ }
+
+/** Listen for a button action */
+ public void actionPerformed(ActionEvent e) {
+ String command = e.getActionCommand();
+ if (command.equals("Advance")) {
+ signal.advance();
+ } else if (command.equals("Green")) {
+ signal.setState(Stoplight.GREEN);
+ } else if (command.equals("Yellow")) {
+ signal.setState(Stoplight.YELLOW);
+ } else if (command.equals("Red")) {
+ signal.setState(Stoplight.RED);
+ }
+ }
+
+/* Private instance variables */
+ private Stoplight signal;
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 350;
+ public static final int APPLICATION_HEIGHT = 250;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new StoplightGraphics().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/StoplightUsingInnerClasses.java b/ss2010/gdi2/java/libs/acm/demo/StoplightUsingInnerClasses.java
new file mode 100644
index 00000000..8b4f291b
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/StoplightUsingInnerClasses.java
@@ -0,0 +1,48 @@
+/*
+ * File: StoplightUsingInnerClasses.java
+ * -------------------------------------
+ * This program is identical to StoplightConsole except that the
+ * listener is specified explicitly using an anonymous inner class.
+ */
+
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/**
+ * This class displays three buttons at the south edge of the window.
+ * The name of the button is echoed on the console each time a button
+ * is pressed.
+ */
+
+public class StoplightUsingInnerClasses extends ConsoleProgram {
+
+/** Initialize the GUI */
+ public void init() {
+ ActionListener listener = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ println(e.getActionCommand());
+ }
+ };
+ JButton greenButton = new JButton("Green");
+ JButton yellowButton = new JButton("Yellow");
+ JButton redButton = new JButton("Red");
+ greenButton.addActionListener(listener);
+ yellowButton.addActionListener(listener);
+ redButton.addActionListener(listener);
+ add(greenButton, SOUTH);
+ add(yellowButton, SOUTH);
+ add(redButton, SOUTH);
+ }
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 350;
+ public static final int APPLICATION_HEIGHT = 250;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new StoplightUsingInnerClasses().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/TempConvUsingInnerClasses.java b/ss2010/gdi2/java/libs/acm/demo/TempConvUsingInnerClasses.java
new file mode 100644
index 00000000..018aaec4
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/TempConvUsingInnerClasses.java
@@ -0,0 +1,64 @@
+/*
+ * File: TempConvUsingInnerClasses.java
+ * ------------------------------------
+ * This program allows users to convert temperatures back
+ * and forth from Fahrenheit to Celsius. This version uses
+ * anonymous inner classes to specify the action listeners.
+ */
+
+import acm.gui.*;
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/** This class implements a simple temperature converter */
+public class TempConvUsingInnerClasses extends Program {
+
+/** Initialize the graphical user interface */
+ public void init() {
+ setLayout(new TableLayout(2, 3));
+ fahrenheitField = new IntField(32);
+ celsiusField = new IntField(0);
+ ActionListener convertFToC = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int f = fahrenheitField.getValue();
+ int c = (int) Math.round( (5.0 / 9.0) * (f - 32) );
+ celsiusField.setValue(c);
+ }
+ };
+ ActionListener convertCToF = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int c = celsiusField.getValue();
+ int f = (int) Math.round( (9.0 / 5.0) * c + 32 );
+ fahrenheitField.setValue(f);
+ }
+ };
+ JButton convertFToCButton = new JButton("F -> C");
+ JButton convertCToFButton = new JButton("C -> F");
+ fahrenheitField.addActionListener(convertFToC);
+ celsiusField.addActionListener(convertCToF);
+ convertFToCButton.addActionListener(convertFToC);
+ convertCToFButton.addActionListener(convertCToF);
+ add(new JLabel("Degrees Fahrenheit"));
+ add(fahrenheitField);
+ add(convertFToCButton);
+ add(new JLabel("Degrees Celsius"));
+ add(celsiusField);
+ add(convertCToFButton);
+ }
+
+/* Private instance variables */
+
+ private IntField fahrenheitField;
+ private IntField celsiusField;
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 300;
+ public static final int APPLICATION_HEIGHT = 200;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new TempConvUsingInnerClasses().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/TemperatureConverter.java b/ss2010/gdi2/java/libs/acm/demo/TemperatureConverter.java
new file mode 100644
index 00000000..0116f436
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/TemperatureConverter.java
@@ -0,0 +1,61 @@
+/*
+ * File: TemperatureConverter.java
+ * -------------------------------
+ * This program allows users to convert temperatures
+ * back and forth from Fahrenheit to Celsius.
+ */
+
+import acm.gui.*;
+import acm.program.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class TemperatureConverter extends Program {
+
+/** Initialize the graphical user interface */
+ public void init() {
+ setLayout(new TableLayout(2, 3));
+ fahrenheitField = new IntField(32);
+ fahrenheitField.setActionCommand("F -> C");
+ fahrenheitField.addActionListener(this);
+ celsiusField = new IntField(0);
+ celsiusField.setActionCommand("C -> F");
+ celsiusField.addActionListener(this);
+ add(new JLabel("Degrees Fahrenheit"));
+ add(fahrenheitField);
+ add(new JButton("F -> C"));
+ add(new JLabel("Degrees Celsius"));
+ add(celsiusField);
+ add(new JButton("C -> F"));
+ addActionListeners();
+ }
+
+/** Listen for a button action */
+ public void actionPerformed(ActionEvent e) {
+ String cmd = e.getActionCommand();
+ if (cmd.equals("F -> C")) {
+ int f = fahrenheitField.getValue();
+ int c = (int) Math.round( (5.0 / 9.0) * (f - 32) );
+ celsiusField.setValue(c);
+ } else if (cmd.equals("C -> F")) {
+ int c = celsiusField.getValue();
+ int f = (int) Math.round( (9.0 / 5.0) * c + 32 );
+ fahrenheitField.setValue(f);
+ }
+ }
+
+/* Private instance variables */
+
+ private IntField fahrenheitField;
+ private IntField celsiusField;
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 300;
+ public static final int APPLICATION_HEIGHT = 200;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new TemperatureConverter().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/TicTacToe.java b/ss2010/gdi2/java/libs/acm/demo/TicTacToe.java
new file mode 100644
index 00000000..722bc746
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/TicTacToe.java
@@ -0,0 +1,83 @@
+/*
+ * File: TicTacToe.java
+ * --------------------
+ * This application uses TableLayout to create a 3x3 array
+ * of JButtons. Clicking on an empty button changes its label
+ * to an X or an O, as appropriate.
+ */
+
+import acm.gui.*;
+import acm.program.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class TicTacToe extends Program implements ItemListener {
+
+/** Set the program dimensions */
+ public static final int APPLICATION_WIDTH = 225;
+ public static final int APPLICATION_HEIGHT = 225;
+
+/** Font to use for the buttons */
+ public static final Font BUTTON_FONT = new Font("SansSerif", Font.BOLD, 36);
+
+/** Initialize the application */
+ public void init() {
+ weightCheckBox = new JCheckBox("Use weights");
+ add(weightCheckBox, SOUTH);
+ weightCheckBox.addItemListener(this);
+ setLayout(new TableLayout(3, 3));
+ for (int i = 0; i < 9; i++) {
+ JButton button = new JButton("");
+ button.setFont(BUTTON_FONT);
+ add(button, "width=60 height=60");
+ }
+ turn = 'X';
+ addActionListeners();
+ }
+
+/** Sets whether the buttons use weights or constant widths */
+ public void setWeightFlag(boolean flag) {
+ String constraints = "fill=BOTH";
+ if (flag) {
+ constraints += " weighty=1 weightx=1";
+ } else {
+ constraints += " width=60 height=60";
+ }
+ TableLayout layout = (TableLayout) getLayout();
+ Container centerPanel = getRegionPanel(CENTER);
+ int nc = centerPanel.getComponentCount();
+ for (int i = 0; i < nc; i++) {
+ Component comp = centerPanel.getComponent(i);
+ layout.setConstraints(comp, constraints);
+ }
+ validate();
+ }
+
+/** Respond to action events by changing the button label */
+ public void actionPerformed(ActionEvent e) {
+ JButton button = (JButton) e.getSource();
+ if (button.getText().equals("")) {
+ switch (turn) {
+ case 'X': button.setText("X"); turn = 'O'; break;
+ case 'O': button.setText("O"); turn = 'X'; break;
+ }
+ }
+ }
+
+/** Respond to item events by resetting the constraint options */
+ public void itemStateChanged(ItemEvent e) {
+ JCheckBox checkBox = (JCheckBox) e.getSource();
+ setWeightFlag(checkBox.isSelected());
+ }
+
+/* Private instance variables */
+ private char turn;
+ private JCheckBox weightCheckBox;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new TicTacToe().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/TimesSquare.java b/ss2010/gdi2/java/libs/acm/demo/TimesSquare.java
new file mode 100644
index 00000000..95fdc1ef
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/TimesSquare.java
@@ -0,0 +1,47 @@
+/*
+ * File: TimesSquare.java
+ * ----------------------
+ * This program displays the text of the string HEADLINE on the
+ * screen in an animated way that moves it across the display
+ * from left to right.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+
+public class TimesSquare extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ GLabel label = new GLabel(HEADLINE);
+ label.setFont("Serif-72");
+ add(label, getWidth(), (getHeight() + label.getAscent()) / 2);
+ while (label.getX() + label.getWidth() > 0) {
+ label.move(-DELTA_X, 0);
+ pause(PAUSE_TIME);
+ }
+ }
+
+/* The number of pixels to shift the label on each cycle */
+ private static final int DELTA_X = 2;
+
+/* The number of milliseconds to pause on each cycle */
+ private static final int PAUSE_TIME = 20;
+
+/* The string to use as the value of the label */
+ private static final String HEADLINE =
+ "When in the course of human events it becomes necessary " +
+ "for one people to dissolve the political bands which " +
+ "connected them with another . . .";
+
+/* Make the graphics window long and narrow */
+ public static final int APPLICATION_WIDTH = 700;
+ public static final int APPLICATION_HEIGHT = 100;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new TimesSquare().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/acm/demo/Tree.java b/ss2010/gdi2/java/libs/acm/demo/Tree.java
new file mode 100644
index 00000000..8a797065
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Tree.java
@@ -0,0 +1,39 @@
+
+public class Tree {
+ public static void main(String[] args) {
+ int height = 5; // <- hier ändern, um größe zu variieren... alles
+ if (args.length > 0) {
+ try {
+ int val = Integer.valueOf(args[0]);
+ System.err.println("val: " + val);
+ height = val;
+ } catch (NumberFormatException nfe) {
+ System.err.println("Invocation: java Tree n"
+ +"\n where n is the tree's width as an int");
+ }
+ }
+ int width = height+1;
+ Empty air = new Empty();
+ Leafs green = new Leafs();
+ Trunk brown = new Trunk();
+
+ int i=0;
+
+ System.out.print(air.show(width));
+ System.out.println("|");
+ System.out.print(air.show(width-1));
+ System.out.println("-+-");
+
+ while (height >=0){
+ System.out.print(air.show(width-i));
+ System.out.println(green.show((i*2)+1));
+ i++;
+ height--;
+ }
+
+ for (i = 0; i<=1; i++){
+ System.out.print(air.show(width-1));
+ System.out.println(brown.show());
+ }
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/Trunk.java b/ss2010/gdi2/java/libs/acm/demo/Trunk.java
new file mode 100644
index 00000000..661bd736
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/Trunk.java
@@ -0,0 +1,12 @@
+
+public class Trunk extends Leafs{
+
+ Trunk () {
+ look = "| |";
+ }
+
+ String show(){
+ return look;
+ }
+
+}
\ No newline at end of file
diff --git a/ss2010/gdi2/java/libs/acm/demo/TwoConsoleDemo.java b/ss2010/gdi2/java/libs/acm/demo/TwoConsoleDemo.java
new file mode 100644
index 00000000..1285248a
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/TwoConsoleDemo.java
@@ -0,0 +1,110 @@
+/*
+ * File: TwoConsoleDemo.java
+ * -------------------------
+ * This program test the multithreading capabilities of the IOConsole
+ * class by building a two-console communicator.
+ */
+
+import acm.io.*;
+import acm.program.*;
+import java.awt.*;
+import java.io.*;
+import java.util.*;
+
+/**
+ * This class simulates an interactive discussion between two consoles.
+ * Its primary purpose is to test the facilities of the IOConsole
+ * class.
+ */
+
+public class TwoConsoleDemo extends Program {
+
+ public void init() {
+ TCModel model = new TCModel();
+ c1 = new TCView(model, 1);
+ c2 = new TCView(model, 2);
+ add(c1);
+ add(c2);
+ }
+
+ public void run() {
+ new Thread(c1).start();
+ new Thread(c2).start();
+ }
+
+ private TCView c1;
+ private TCView c2;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new TwoConsoleDemo().start(args);
+ }
+}
+
+class TCView extends IOConsole implements Runnable {
+
+ public TCView(TCModel model, int index) {
+ consoleIndex = index;
+ consoleModel = model;
+ consoleModel.addView(this);
+ Color inputColor = (index % 2 == 0) ? Color.MAGENTA : Color.BLUE;
+ Color errorColor = (index % 2 == 1) ? Color.MAGENTA : Color.BLUE;
+ String inputColorName = (index % 2 == 0) ? "magenta" : "blue";
+ String errorColorName = (index % 2 == 1) ? "magenta" : "blue";
+ setInputColor(inputColor);
+ setErrorColor(errorColor);
+ int r = Math.max(0xCC, inputColor.getRed());
+ int g = Math.max(0xCC, inputColor.getGreen());
+ int b = Math.max(0xCC, inputColor.getBlue());
+ setBackground(new Color(r, g, b));
+ println("Console " + index);
+ print("On this console, input appears in ");
+ setInputScript(new BufferedReader(new StringReader(inputColorName + "\n")));
+ readLine();
+ print("Output from other consoles appears in ");
+ showErrorMessage(errorColorName);
+ }
+
+ public void run() {
+ while (true) {
+ String line = readLine();
+ consoleModel.inputReceived(this, line);
+ }
+ }
+
+ public int getIndex() {
+ return consoleIndex;
+ }
+
+ public void inputReceived(String line) {
+ showErrorMessage(line);
+ }
+
+ private TCModel consoleModel;
+ private int consoleIndex;
+}
+
+class TCModel {
+
+ public TCModel() {
+ views = new ArrayList();
+ }
+
+ public void addView(TCView view) {
+ views.add(view);
+ }
+
+ public void inputReceived(TCView source, String line) {
+ int nViews = views.size();
+ for (int i = 0; i < nViews; i++) {
+ TCView view = (TCView) views.get(i);
+ if (view != source) view.inputReceived(line);
+ }
+ }
+
+ private ArrayList views;
+}
+
+
+
\ No newline at end of file
diff --git a/ss2010/gdi2/java/libs/acm/demo/USFlag.java b/ss2010/gdi2/java/libs/acm/demo/USFlag.java
new file mode 100644
index 00000000..b6b17d1d
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/USFlag.java
@@ -0,0 +1,80 @@
+/*
+ * File: USFlag.java
+ * ---------------------
+ * This program demonstrates the acm.graphics package by drawing a US flag.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.*;
+
+/* Class: USFlag */
+/**
+ * GraphicsProgram to draw a US flag. It uses a subsidiary
+ * GStar class to simplify the drawing.
+ */
+public class USFlag extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ getGCanvas().setAutoRepaintFlag(false);
+ addStripes(getWidth(), getHeight());
+ addField(FIELD_FRACTION * getWidth(), getHeight() * 7.0 / 13);
+ repaint();
+ }
+
+/* Adds the stripes */
+ private void addStripes(double width, double height) {
+ double sHeight = height / 13;
+ for (int i = 12; i >= 0; i--) {
+ GRect stripe = new GRect(0, i * sHeight, width, sHeight);
+ stripe.setFilled(true);
+ stripe.setColor((i % 2 == 0) ? Color.RED : Color.WHITE);
+ add(stripe);
+ }
+ }
+
+/* Adds the star field */
+ private void addField(double width, double height) {
+ GRect field = new GRect(0, 0, width, height);
+ field.setColor(Color.BLUE);
+ field.setFilled(true);
+ add(field);
+ double dx = width / 6;
+ double dy = height / 5;
+ double starSize = STAR_FRACTION * Math.min(dx, dy);
+ for (int row = 0; row < 5; row++) {
+ double y = (row + 0.5) * dy;
+ for (int col = 0; col < 6; col++) {
+ double x = (col + 0.5) * dx;
+ GStar star = new GStar(starSize);
+ star.setColor(Color.WHITE);
+ star.setFilled(true);
+ star.setLocation(x, y);
+ add(star);
+ }
+ }
+ for (int row = 0; row < 4; row++) {
+ double y = (row + 1) * dy;
+ for (int col = 0; col < 5; col++) {
+ double x = (col + 1) * dx;
+ GStar star = new GStar(starSize);
+ star.setColor(Color.WHITE);
+ star.setFilled(true);
+ star.setLocation(x, y);
+ add(star);
+ }
+ }
+ }
+
+/* Private constants */
+
+ private static final double FIELD_FRACTION = 0.40;
+ private static final double STAR_FRACTION = 0.40;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new USFlag().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/YarnPattern.java b/ss2010/gdi2/java/libs/acm/demo/YarnPattern.java
new file mode 100644
index 00000000..d22ef95b
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/YarnPattern.java
@@ -0,0 +1,67 @@
+/*
+ * File: YarnPattern.java
+ * ----------------------
+ * This program illustrates the use of the GLine class to simulate
+ * winding a piece of colored yarn around a set of pegs equally
+ * spaced along the edges of the canvas. At each step, the yarn is
+ * stretched from its current peg to the one DELTA pegs further on.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.*;
+import java.util.*;
+
+public class YarnPattern extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ ArrayList pegs = createPegList();
+ int thisPeg = 0;
+ int nextPeg = -1;
+ while (thisPeg != 0 || nextPeg == -1) {
+ nextPeg = (thisPeg + DELTA) % pegs.size();
+ GPoint p0 = (GPoint) pegs.get(thisPeg);
+ GPoint p1 = (GPoint) pegs.get(nextPeg);
+ GLine line = new GLine(p0.getX(), p0.getY(),
+ p1.getX(), p1.getY());
+ line.setColor(Color.MAGENTA);
+ add(line);
+ thisPeg = nextPeg;
+ }
+ }
+
+/* Create an array list containing the locations of the pegs */
+ private ArrayList createPegList() {
+ ArrayList pegs = new ArrayList();
+ for (int i = 0; i < N_ACROSS; i++) {
+ pegs.add(new GPoint(i * PEG_SEP, 0));
+ }
+ for (int i = 0; i < N_DOWN; i++) {
+ pegs.add(new GPoint(N_ACROSS * PEG_SEP, i * PEG_SEP));
+ }
+ for (int i = N_ACROSS; i > 0; i--) {
+ pegs.add(new GPoint(i * PEG_SEP, N_DOWN * PEG_SEP));
+ }
+ for (int i = N_DOWN; i > 0; i--) {
+ pegs.add(new GPoint(0, i * PEG_SEP));
+ }
+ return pegs;
+ }
+
+/* Private constants */
+ private static final int N_ACROSS = 50;
+ private static final int N_DOWN = 30;
+ private static final int PEG_SEP = 10;
+ private static final int DELTA = 67;
+
+/* Make sure that the application has the right dimensions */
+ public static final int APPLICATION_WIDTH = N_ACROSS * PEG_SEP;
+ public static final int APPLICATION_HEIGHT = N_DOWN * PEG_SEP;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new YarnPattern().start(args);
+ }
+}
diff --git a/ss2010/gdi2/java/libs/acm/demo/YinYang.java b/ss2010/gdi2/java/libs/acm/demo/YinYang.java
new file mode 100644
index 00000000..0b1c0436
--- /dev/null
+++ b/ss2010/gdi2/java/libs/acm/demo/YinYang.java
@@ -0,0 +1,43 @@
+/*
+ * File: YinYang.java
+ * ------------------
+ * This program draws the Taoist yin-yang symbol at the center of
+ * the graphics window. The height and width of the entire figure
+ * are both specified by the constant FIGURE_SIZE.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.*;
+
+public class YinYang extends GraphicsProgram {
+
+/** Runs the program */
+ public void run() {
+ double x = getWidth() / 2;
+ double y = getHeight() / 2;
+ double r = FIGURE_SIZE / 2;
+ GArc bigBlack = new GArc(x - r, y - r, 2 * r, 2 * r, -90, 180);
+ bigBlack.setFilled(true);
+ add(bigBlack);
+ GArc smallWhite = new GArc(x - r / 2, y - r, r, r, 0, 360);
+ smallWhite.setFilled(true);
+ smallWhite.setColor(Color.WHITE);
+ add(smallWhite);
+ GArc smallBlack = new GArc(x - r / 2, y, r, r, 0, 360);
+ smallBlack.setFilled(true);
+ add(smallBlack);
+ GArc outerCircle = new GArc(x - r, y - r, 2 * r, 2 * r, 0, 360);
+ add(outerCircle);
+ }
+
+/* Private constants */
+ private static final double FIGURE_SIZE = 150;
+
+/* Standard Java entry point */
+/* This method can be eliminated in most Java environments */
+ public static void main(String[] args) {
+ new YinYang().start(args);
+ }
+}
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/README.html b/ss2010/gdi2/java/libs/jgrapht/README.html
new file mode 100644
index 00000000..a160669a
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/README.html
@@ -0,0 +1,612 @@
+
+
+
+
+
+
+
+
+
+
+ JGraphT Release Notes
+
+
+
+
+
(C) Copyright 2003-2008, by Barak Naveh and Contributors. All rights
+ reserved.
+
+
Please address all contributions, suggestions, and inquiries to the
+ current project administrator, John Sichi.
+
+
Sponsorship
+
+
JGraphT is now part of The Eigenbase Project, an umbrella
+ organization which helps to support it. If you use JGraphT in your
+ application, please consider making a donation. Either visit the Eigenbase website and click
+ the donation link, or use the
+ Sourceforge donation page for JGraphT.
+
+
Introduction
+
+
JGraphT is a free Java class library that provides mathematical
+ graph-theory objects and algorithms. It runs on Java 2 Platform
+ (requires JDK 1.6 or later).
+
+
JGraphT is licensed under the terms of the GNU Lesser General Public
+ License (LGPL). A copy of the license is
+ included in the download.
+
+
Please note that JGraphT is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ Please refer to the license for details.
+
+
Contents
+
+
+
+
jgrapht-jdk1.6.jar
+
+
the compiled JGraphT library for JRE 1.6
+
+
+
+
README.html
+
+
this file
+
+
+
+
licence-LGPL.txt
+
+
GNU Lesser General Public License
+
+
+
+
javadoc/
+
+
Javadoc documentation
+
+
+
+
lib/
+
+
+ libraries required for build:
+
+
+
junit.jar
+
+
jgraph.jar
+
+
TGGraphLayout.jar
+
+
+
+
+
+
src/
+
+
source code
+
+
+
+
testsrc/
+
+
source code of unit tests
+
+
+
+
META-INF/MANIFEST.MF
+
meta information for use as an OSGi plug-in (e.g. within an Eclipse RCP application)
+
+
+
build.properties
+
describes content of OSGi plug-in export
+
+
+
+
build.xml
+
+
ant buildfile
+
+
+
+
+
Getting Started
+
+
The package org.jgrapht.demo includes small demo
+ applications to help you get started. If you spawn your own demo app and
+ think others can use it, please send it to us and we will add it to that
+ package.
+
+
Upgrading Versions
+
+
To help upgrading, JGraphT maintains a one-version-backwards
+ compatibility. While this compatibility is not a hard promise, it is generally
+ respected. (This policy was not followed for the jump from 0.6.0 to 0.7.0
+ due to the pervasive changes required for generics.) You can upgrade via:
+
+
+
+
The safe way : compile your app with the JGraphT
+ version that immediately follows your existing version and
+ follow the deprecation notes, if they exist, and modify your
+ application accordingly. Then move to the next version, and on,
+ until you're current.
+
+
+
+
The fast way : go to the latest JGraphT right away - if it
+ works, you're done.
A local copy of the Javadoc HTML files is included in this distribution.
+ The latest version of these files is also available on-line at http://www.jgrapht.org/javadoc.
+
+
Dependencies
+
+
+
JGraphT requires JDK 1.6 or later to build.
+
+
+
JUnit is a unit testing framework. You need JUnit only if you want to
+ run the unit tests. The junit.jar runtime file is included in
+ this distribution. JUnit is licensed under the terms of the IBM Common
+ Public License. You can find out more about JUnit and/or download the
+ latest version from http://www.junit.org. The JUnit tests included
+ with JGraphT have been created using JUnit 3.8.1.
+
+
+
XMLUnit extends JUnit with XML capabilities. You need XMLUnit
+ only if you want to run the unit tests. The
+ xmlunit-1.0.jar runtime file is included in this
+ distribution. XMLUnit is licensed under the terms of the BSD
+ License. You can find out more about XMLUnit and/or download the
+ latest version from http://xmlunit.sourceforge.net.
+
+
JGraph is a graph visualization and editing component. You
+ need JGraph only if you want to create graph visualizations using
+ the JGraphT-to-JGraph adapter. The jgraph.jar runtime
+ file of JGraph is included in this distribution (file
+ lib/lib-readme.txt has version information). JGraph is licensed
+ under the terms of the GNU Lesser General Public License
+ (LGPL). You can find more about JGraph and/or download the latest
+ version from http://www.sourceforge.net/projects/jgraph.
+
+
Touchgraph is a graph visualization and layout component. You
+ need Touchgraph only if you want to create graph visualizations
+ using the JGraphT-to-Touchgraph converter. The
+ TGGraphLayout.jar runtime file of Touchgraph is included
+ in this distribution (file lib/lib-readme.txt has version
+ information). Touchgraph is licensed under the terms of an Apache-style
+ License. You can find more about Touchgraph
+ and/or download the latest version from http://sourceforge.net/projects/touchgraph.
Obtain the latest version : latest version and all previous
+ versions of JGraphT are available online.
+
+
Report bugs : if you have any comments, suggestions or bugs you
+ want to report.
+
+
Get support : if you have questions or need help with
+ JGraphT.
+
+
+
There is also a wiki set up
+ for everyone in the JGraphT community to share information about the
+ project.
+
+
Your Improvements
+
+
If you add improvements to JGraphT please send them to us. We will add them
+ to the next release so that everyone can enjoy them. You might also benefit
+ from it: others may fix bugs in your source files or may continue to enhance
+ them.
+
+
History
+
+
Changes to JGraphT in each version:
+
+
+
version 0.8.1 (3-Jul-2009): Enhanced GmlExporter with
+ customized labels and ID's, contributed by Trevor Harmon. Added
+ new algorithms HamiltonianCycle, ChromaticNumber and
+ EulerianCircuit, plus new generators HyperCubeGraphGenerator,
+ StarGraphGenerator, and CompleteBipartiteGraphGenerator, all
+ contributed by Andrew Newell. Fix bug with vertices which are
+ equals but not identity-same in graphs allowing loops, spotted by
+ Michael Michaud. Fix bug in EquivalenceIsomorphismInspector,
+ reported by Tim Engler. Add toString for shortest paths wrapper,
+ spotted by Achim Beutel. Add FloydWarshallShortestPaths,
+ contributed by Tom Larkworthy. Enhance DijskstraShortestPath to
+ support GraphPath interface.
+
+
version 0.8.0 (Sept-2008): Moved to JDK 1.6. Fixed
+ problem with RandomGraphGenerator reported by Mario Rossi. Added
+ CompleteGraphGenerator, contributed by Tim Shearouse. Fixed
+ FibonacciHeap performance problem reported by Jason Lenderman.
+ Made DotExporter reject illegal vertex ID's, contributed by Holger
+ Brandl. Fixed bogus assertion for topological sort over empty
+ graph, spotted by Harris Lin. Added scale-free graph generator
+ and EdmondsKarpMaximumFlow, contributed by Ilya Razenshteyn.
+ Added DirectedAcyclicGraph, contributed by Peter Giles. Added
+ protected getWeight accessor to DefaultWeightedEdge, likewise
+ getSource and getTarget on DefaultEdge. Optimized iterators to
+ skip calling event firing routines when there are no listeners,
+ and used ArrayDeque in a number of places, per suggestion from
+ Ross Judson. Improvements to StrongConnectivityInspector and OSGi
+ bundle support contributed by Christian Soltenborn.
+
+
version 0.7.3 (Jan-2008): Patch to
+ JGraphModelAdapter.removeVertex provided by Hookahey. Added
+ ParanoidGraph. Removed obsolete ArrayUtil (spotted by Boente).
+ Added GraphPath, and used it to fix mistake in 0.7.2
+ (k-shortest-paths was returning a private data structure,
+ as discovered by numerous users). Fixed
+ EdgeReversedGraph.getAllEdges (spotted by
+ neumanns@users.sf.net). Fixed incorrect assertion in
+ TopologicalOrderIterator constructor. Enabled assertions
+ in JUnit tests. Fixed NPE in BellmanFordShortestPath.getCost.
+ Fixed a few problems spotted by findbugs.
+
+
version 0.7.2 (Sept-2007): Added
+ TransitiveClosure, contributed by Vinayak Borkar. Added
+ biconnectivity/cutpoint inspection, k-shortest-paths, and masked
+ subgraphs, all contributed by Guillaume Boulmier. Made some
+ Graphs helper methods even more generic, as suggested by JongSoo.
+ Test and fixes for (Directed)NeighborIndex submitted by Andrew
+ Berman. Added AsUnweighted(Directed)Graph and AsWeightedGraph,
+ contributed by Lucas Scharenbroich. Dropped support for retroweaver.
+
+
version 0.7.1 (March-2007): Fixed some bugs in
+ CycleDetector reported by Khanh Vu, and added more testcases for
+ it. Fixed bugs in DepthFirstIterator reported by Welson Sun, and
+ added WHITE/GRAY/BLACK states and vertexFinished listener event.
+ Exposed Subgraph.getBase(), and parameterized Subgraph on graph
+ type (per suggestion from Aaron Harnly). Added EdgeReversedView.
+ Added GmlExporter (contributed by Dimitrios Michail), plus
+ DOTExporter and GraphMLExporter (both contributed by Trevor
+ Harmon). Enhanced TopologicalOrderIterator to take an optional
+ Queue parameter for tie-breaking (per suggestion from JongSoo
+ Park). Fixed some documentation errors reported by Guillaume
+ Boulmier.
+
+
version 0.7.0 (July-2006) : Upgraded to JDK 1.5
+ (generics support added by Christian Hammer with help from Hartmut
+ Benz and John Sichi). Added (Directed)NeighborIndex and
+ MatrixExporter, contributed by Charles Fry. Added BellmanFord,
+ contributed by Guillaume Boulmier of France Telecom. Removed
+ never-used LabeledElement. Renamed package from org._3pq.jgrapht
+ to org.jgrapht. Made various breaking change to interfaces; edge
+ collections are now Sets, not Lists. Added Touchgraph converter,
+ contributed by Carl Anderson
+
+
version 0.6.0 (July-2005) : Upgraded to JDK 1.4, taking
+ advantage of its new linked hash set/map containers to make
+ edge/vertex set order-deterministic. Added support for custom edge
+ lists. Fixed various serialization and Subgraph issues. Added to
+ JGraphModelAdapter support for JGraph's "dangling"
+ edges; its constructors have slightly changed and now forbid
+ null values. Improved interface to
+ DijskstraShortestPath, and added radius support to
+ ClosestFirstIterator. Added new
+ StrongConnectivityInspector algorithm (contributed by
+ Christian Soltenborn) and TopologicalOrderIterator
+ (contributed by Marden Neubert). Deleted deprecated
+ TraverseUtils. Upgraded to JGraph 5.6.1.1.
+
+
version 0.5.3 (June-2004) : Removed Subgraph verification of
+ element's identity to base graph, upgraded to JGraph 4.0, Added the
+ VisioExporter which was contributed by Avner Linder, minor bug fixes and
+ improvements.
+
+
version 0.5.2 (March-2004) : Serialization improvements, fixes
+ to subgraphs and listenable graphs, added support for JGraph->JGraphT
+ change propagation for JGraph adapter (contributed by Erik Postma),
+ upgraded to JGraph 3.1, various bug fixes and improvements.
+
+
version 0.5.1 (November-2003) : Semantics of Graph.clone() has
+ changed, please check the documentation if you're using it. Added
+ Dijkstra's shortest path, vertex cover approximations, new graph generation
+ framework, upgraded to JGraph 3.0, various bug fixes and API
+ improvements.
+
+
version 0.5.0 (14-Aug-2003) : a new connectivity inspector
+ added, edge API refactored to be simpler, an improved ant build, an
+ improved event model, all known bugs were fixed, documentation
+ clarifications, other small improvements. API of 0.5.0 is not 100% backward
+ compatible with 0.4.1 but upgrade is simple and straightforward.
+
+
version 0.4.1 (05-Aug-2003) : A new adapter to JGraph that
+ provides graph visualizations, new depth-first and breadth-first iteration
+ algorithms, various bug fixes and refactoring, moved unit-tests to a
+ separate folder hierarchy and added more unit-tests.
+
+
version 0.4.0 (July-2003) : Initial public release.
+
+
+
Contributors
+
+
JGraphT wouldn't be the library it is today without the source
+ contributions and suggestions made by the authors:
(if we have missed your name on this list, please email us to get it
+ fixed).
+
+
Other people have also helped in different ways: reporting bugs,
+ requesting features, commenting, and by merely asking very good questions.
+ Many thanks to all of you.
+
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/build.xml b/ss2010/gdi2/java/libs/jgrapht/build.xml
new file mode 100644
index 00000000..802e1f54
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/build.xml
@@ -0,0 +1,559 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ project.version=$${${svntag}.name}
+
+
+
+
+
+
+ JAVA_HOME=${java.home}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ If you get a junit task lookup failure, you need to add the junit.jar to
+ the classpath, possibly by copying it into the ANT_HOME/lib folder.
+ See http://ant.apache.org/manual/OptionalTasks/junit.html for more.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ replaceme
+
+
+
+
+
+
+
+
+
+
+
+ Starting release build at ${checkout.dir}/${build.file.name}
+
+
+
+
+
+
+
+
+
+
+
+ Checking out files of SVN tag: ${svntag}
+
+
+
+
+
+
+
+
+
+
+
+
+ Variable $${svntag} must be specified for selected target.
+
+
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/etc/build.properties b/ss2010/gdi2/java/libs/jgrapht/etc/build.properties
new file mode 100644
index 00000000..dca682fd
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/etc/build.properties
@@ -0,0 +1,53 @@
+# ==========================================
+# JGraphT : a free Java graph-theory library
+# ==========================================
+#
+# Project Info: http://jgrapht.sourceforge.net/
+# Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+#
+# (C) Copyright 2003-2006, by Barak Naveh and Contributors.
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+#
+# ~~~~~~~~~
+# etc/build.properties
+# ~~~~~~~~~
+#
+# Original Author: John V. Sichi
+# Contributor(s): -
+#
+# $Id: build.properties.template 570 2007-09-30 01:06:39Z perfecthash $
+#
+# Changes
+# ~~~~~~~
+# 31-July-2005 : Initial revision (JVS);
+# 01-July-2006 : Update for version 0.7 (JVS);
+# ~~~~~~~
+#
+# etc/build.properties is used to customize the JGraphT build.
+# To use it, uncomment the settings below for the attributes you want
+# to customize, then change the values to your site-specifics.
+# The ant buildfile will override its own defaults with any
+# uncommented values it sees here.
+
+# NOTE: If you are building JGraphT directly from Subversion rather than from
+# a distribution, create etc/build.properties by making a copy of
+# etc/build.properties.template. (The template file should only be
+# changed by developers who are enhancing the build process
+# with customizability.)
+
+# ~~~~~~~~~~~~~~~~~
+# End build.properties
+# ~~~~~~~~~~~~~~~~~
diff --git a/ss2010/gdi2/java/libs/jgrapht/etc/build.properties.template b/ss2010/gdi2/java/libs/jgrapht/etc/build.properties.template
new file mode 100644
index 00000000..dca682fd
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/etc/build.properties.template
@@ -0,0 +1,53 @@
+# ==========================================
+# JGraphT : a free Java graph-theory library
+# ==========================================
+#
+# Project Info: http://jgrapht.sourceforge.net/
+# Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+#
+# (C) Copyright 2003-2006, by Barak Naveh and Contributors.
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+#
+# ~~~~~~~~~
+# etc/build.properties
+# ~~~~~~~~~
+#
+# Original Author: John V. Sichi
+# Contributor(s): -
+#
+# $Id: build.properties.template 570 2007-09-30 01:06:39Z perfecthash $
+#
+# Changes
+# ~~~~~~~
+# 31-July-2005 : Initial revision (JVS);
+# 01-July-2006 : Update for version 0.7 (JVS);
+# ~~~~~~~
+#
+# etc/build.properties is used to customize the JGraphT build.
+# To use it, uncomment the settings below for the attributes you want
+# to customize, then change the values to your site-specifics.
+# The ant buildfile will override its own defaults with any
+# uncommented values it sees here.
+
+# NOTE: If you are building JGraphT directly from Subversion rather than from
+# a distribution, create etc/build.properties by making a copy of
+# etc/build.properties.template. (The template file should only be
+# changed by developers who are enhancing the build process
+# with customizability.)
+
+# ~~~~~~~~~~~~~~~~~
+# End build.properties
+# ~~~~~~~~~~~~~~~~~
diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/allclasses-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/allclasses-frame.html
new file mode 100644
index 00000000..00a25e84
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/allclasses-frame.html
@@ -0,0 +1,301 @@
+
+
+
+
+
+
+All Classes (JGraphT : a free Java graph library)
+
+
+
+
+
+
+
+
+
+
+
+All Classes
+
+
+
+This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+Overview
+
+
+
+The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.
+
+Package
+
+
+
+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:
+
Interfaces (italic)
Classes
Enums
Exceptions
Errors
Annotation Types
+
+
+Class/Interface
+
+
+
+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+
Class inheritance diagram
Direct Subclasses
All Known Subinterfaces
All Known Implementing Classes
Class/interface declaration
Class/interface description
+
+
Nested Class Summary
Field Summary
Constructor Summary
Method Summary
+
+
Field Detail
Constructor Detail
Method Detail
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+
+
+Annotation Type
+
+
+
+Each annotation type has its own separate page with the following sections:
+
Annotation Type declaration
Annotation Type description
Required Element Summary
Optional Element Summary
Element Detail
+
+
+
+Enum
+
+
+
+Each enum has its own separate page with the following sections:
+
Enum declaration
Enum description
Enum Constant Summary
Enum Constant Detail
+
+
+Tree (Class Hierarchy)
+
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
+
When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
+
+
+Deprecated API
+
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+
+Index
+
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+
+Prev/Next
+These links take you to the next or previous class, interface, package, or related page.
+Frames/No Frames
+These links show and hide the HTML frames. All pages are available with or without frames.
+
+
+Serialized Form
+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
+
Adds the specified source and target vertices to the graph, if not
+ already included, and creates a new edge and adds it to the specified
+ graph similarly to the Graph.addEdge(Object, Object) method.
+
Adds the specified source and target vertices to the graph, if not
+ already included, and creates a new weighted edge and adds it to the
+ specified graph similarly to the Graph.addEdge(Object, Object)
+ method.
+
Helper for efficiently representing small sets whose elements are known to be
+ unique by construction, implying we don't need to enforce the uniqueness
+ property in the data structure itself.
This class implements Bron-Kerbosch clique detection algorithm as it is
+ described in [Samudrala R.,Moult J.:A Graph-theoretic Algorithm for
+ comparative Modeling of Protein Structure; J.Mol.
GraphMapping represents a bidirectional mapping between two graphs (called
+ graph1 and graph2), which allows the caller to obtain the matching vertex or
+ edge in either direction, from graph1 to graph2, or from graph2 to graph1.
Constructs a new GraphMLExporter object with integer name providers for
+ the vertex and edge IDs and null providers for the vertex and edge
+ labels.
+
This class will deal with finding the optimal or approximately optimal
+ minimum tour (hamiltonian cycle) or commonly known as the Traveling
+ Salesman Problem.
Creates a new topological order iterator over the directed graph
+ specified, with a user-supplied queue implementation to allow customized
+ control over tie-breaking in case of partial order.
+
Returns the "in degree" of the specified vertex. An in degree of a vertex
+ in a directed graph is the number of inward directed edges from that
+ vertex. See
+ http://mathworld.wolfram.com/Indegree.html.
+
+
+
+
+
+
Parameters:
vertex - vertex whose degree is to be calculated.
+
Returns the "out degree" of the specified vertex. An out degree of a
+ vertex in a directed graph is the number of outward directed edges from
+ that vertex. See
+ http://mathworld.wolfram.com/Outdegree.html.
+
+
+
+
+
+
Parameters:
vertex - vertex whose degree is to be calculated.
+
+The root interface in the graph hierarchy. A mathematical graph-theory graph
+ object G(V,E) contains a set V of vertices and a set
+ E of edges. Each edge e=(v1,v2) in E connects vertex v1 to vertex v2.
+ for more information about graphs and their related definitions see
+ http://mathworld.wolfram.com/Graph.html.
+
+
This library generally follows the terminology found at:
+ http://mathworld.wolfram.com/topics/GraphTheory.html. Implementation of
+ this interface can provide simple-graphs, multigraphs, pseudographs etc. The
+ package org.jgrapht.graph provides a gallery of abstract and
+ concrete graph implementations.
+
+
This library works best when vertices represent arbitrary objects and
+ edges represent the relationships between them. Vertex and edge instances may
+ be shared by more than one graph.
+
+ Through generics, a graph can be typed to specific classes for vertices
+ V and edges E<T>. Such a graph can contain
+ vertices of type V and all sub-types and Edges of type
+ E and all sub-types.
+
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ boolean
+
addVertex(V v)
+
+
+ Adds the specified vertex to this graph if not already present.
+
+
+
+ boolean
+
containsEdge(E e)
+
+
+ Returns true if this graph contains the specified edge.
+
+
+
+ boolean
+
containsEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns true if and only if this graph contains an edge going
+ from the source vertex to the target vertex.
+
+
+
+ boolean
+
containsVertex(V v)
+
+
+ Returns true if this graph contains the specified vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
getEdgeTarget(E e)
+
+
+ Returns the target vertex of an edge.
+
+
+
+ double
+
getEdgeWeight(E e)
+
+
+ Returns the weight assigned to a given edge.
+
+
+
+ boolean
+
removeAllEdges(java.util.Collection<? extends E> edges)
+
+
+ Removes all the edges in this graph that are also contained in the
+ specified edge collection.
removeAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges.
+
+
+
+ boolean
+
removeAllVertices(java.util.Collection<? extends V> vertices)
+
+
+ Removes all the vertices in this graph that are also contained in the
+ specified vertex collection.
+
+
+
+ boolean
+
removeEdge(E e)
+
+
+ Removes the specified edge from the graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ boolean
+
removeVertex(V v)
+
+
+ Removes the specified vertex from this graph including all its touching
+ edges if present.
vertexSet()
+
+
+ Returns a set of the vertices contained in this graph.
+
+
+
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+getAllEdges
+
+java.util.Set<E> getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
a set of all edges connecting source vertex to target vertex.
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
an edge connecting source vertex to target vertex.
Returns the edge factory using which this graph creates new edges. The
+ edge factory is defined when the graph is constructed and must not be
+ modified.
+
+
+
+
Returns:
the edge factory using which this graph creates new edges.
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
The newly created edge if added to the graph, otherwise
+ null.
+
Throws:
+
java.lang.IllegalArgumentException - if source or target vertices are not
+ found in the graph.
+
java.lang.NullPointerException - if any of the specified vertices is
+ null.
+boolean addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
e - edge to be added to this graph.
+
Returns:
true if this graph did not already contain the specified
+ edge.
+
Throws:
+
java.lang.IllegalArgumentException - if source or target vertices are not
+ found in the graph.
+
java.lang.ClassCastException - if the specified edge is not assignment
+ compatible with the class of edges produced by the edge factory of this
+ graph.
+
java.lang.NullPointerException - if any of the specified vertices is
+ null.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
+
+
Parameters:
v - vertex to be added to this graph.
+
Returns:
true if this graph did not already contain the specified
+ vertex.
+
Throws:
+
java.lang.NullPointerException - if the specified vertex is
+ null.
+
+
+
+
+
+containsEdge
+
+boolean containsEdge(V sourceVertex,
+ V targetVertex)
+
+
Returns true if and only if this graph contains an edge going
+ from the source vertex to the target vertex. In undirected graphs the
+ same result is obtained when source and target are inverted. If any of
+ the specified vertices does not exist in the graph, or if is
+ null, returns false.
+
Returns true if this graph contains the specified edge. More
+ formally, returns true if and only if this graph contains an
+ edge e2 such that e.equals(e2). If the
+ specified edge is null returns false.
+
+
+
Parameters:
e - edge whose presence in this graph is to be tested.
+
Returns true if this graph contains the specified vertex. More
+ formally, returns true if and only if this graph contains a
+ vertex u such that u.equals(v). If the
+ specified vertex is null returns false.
+
+
+
Parameters:
v - vertex whose presence in this graph is to be tested.
+
Returns a set of the edges contained in this graph. The set is backed by
+ the graph, so changes to the graph are reflected in the set. If the graph
+ is modified while an iteration over the set is in progress, the results
+ of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Removes all the edges in this graph that are also contained in the
+ specified edge collection. After this call returns, this graph will
+ contain no edges in common with the specified edges. This method will
+ invoke the removeEdge(Object) method.
+
+
+
Parameters:
edges - edges to be removed from this graph.
+
Returns:
true if this graph changed as a result of the call
+
Throws:
+
java.lang.NullPointerException - if the specified edge collection is
+ null.
+java.util.Set<E> removeAllEdges(V sourceVertex,
+ V targetVertex)
+
+
Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges. Returns
+ null if any of the specified vertices does not exist in the
+ graph. If both vertices exist but no edge is found, returns an empty set.
+ This method will either invoke the removeEdge(Object) method, or
+ the removeEdge(Object, Object) method.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
the removed edges, or null if no either vertex not
+ part of graph
Removes all the vertices in this graph that are also contained in the
+ specified vertex collection. After this call returns, this graph will
+ contain no vertices in common with the specified vertices. This method
+ will invoke the removeVertex(Object) method.
+
+
+
Parameters:
vertices - vertices to be removed from this graph.
+
Returns:
true if this graph changed as a result of the call
+
Throws:
+
java.lang.NullPointerException - if the specified vertex collection is
+ null.
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
If the specified edge is null returns
+ false.
+
+
+
Parameters:
e - edge to be removed from this graph, if present.
+
Returns:
true if and only if the graph contained the
+ specified edge.
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
If the specified vertex is null returns
+ false.
+
+
+
Parameters:
v - vertex to be removed from this graph, if present.
+
Returns:
true if the graph contained the specified vertex;
+ false otherwise.
Returns a set of the vertices contained in this graph. The set is backed
+ by the graph, so changes to the graph are reflected in the set. If the
+ graph is modified while an iteration over the set is in progress, the
+ results of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
+
+
+
+
Returns:
a set view of the vertices contained in this graph.
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
+GraphMapping represents a bidirectional mapping between two graphs (called
+ graph1 and graph2), which allows the caller to obtain the matching vertex or
+ edge in either direction, from graph1 to graph2, or from graph2 to graph1. It
+ does not have to always be a complete bidirectional mapping (it could return
+ null for some lookups).
+
+A GraphPath represents a
+ path in a Graph. Note that a path is defined primarily in terms
+ of edges (rather than vertices) so that multiple edges between the same pair
+ of vertices can be discriminated.
+
Returns the edges making up the path. The first edge in this path is
+ incident to the start vertex. The last edge is incident to the end
+ vertex. The vertices along the path can be obtained by traversing from
+ the start vertex, finding its opposite across the first edge, and then
+ doing the same successively across subsequent edges; Graphs.getPathVertexList(org.jgrapht.GraphPath) provides a convenience method for this.
+
+
Whether or not the returned edge list is modifiable depends on the
+ path implementation.
+
+
+
+
Returns:
list of edges traversed by the path
+
+
+
+
+
+getWeight
+
+double getWeight()
+
+
Returns the weight assigned to the path. Typically, this will be the sum
+ of the weights of the edge list entries (as defined by the containing
+ graph), but some path implementations may use other definitions.
+
addAllEdges(Graph<? super V,? super E> destination,
+ Graph<V,E> source,
+ java.util.Collection<? extends E> edges)
+
+
+ Adds a subset of the edges of the specified source graph to the specified
+ destination graph.
+
+
+
+static
+
+
+
+<V,E> boolean
+
+
+
+
addAllVertices(Graph<? super V,? super E> destination,
+ java.util.Collection<? extends V> vertices)
+
+
+ Adds all of the specified vertices to the destination graph.
+
+
+
+static
+
+
+
+<V,E> E
+
+
+
+
addEdge(Graph<V,E> g,
+ V sourceVertex,
+ V targetVertex,
+ double weight)
+
+
+ Creates a new edge and adds it to the specified graph similarly to the
+ Graph.addEdge(Object, Object) method.
+
+
+
+static
+
+
+
+<V,E> boolean
+
+
+
+
addEdgeWithVertices(Graph<V,E> targetGraph,
+ Graph<V,E> sourceGraph,
+ E edge)
+
+
+ Adds the specified edge to the graph, including its vertices if not
+ already included.
+
+
+
+static
+
+
+
+<V,E> E
+
+
+
+
addEdgeWithVertices(Graph<V,E> g,
+ V sourceVertex,
+ V targetVertex)
+
+
+ Adds the specified source and target vertices to the graph, if not
+ already included, and creates a new edge and adds it to the specified
+ graph similarly to the Graph.addEdge(Object, Object) method.
+
+
+
+static
+
+
+
+<V,E> E
+
+
+
+
addEdgeWithVertices(Graph<V,E> g,
+ V sourceVertex,
+ V targetVertex,
+ double weight)
+
+
+ Adds the specified source and target vertices to the graph, if not
+ already included, and creates a new weighted edge and adds it to the
+ specified graph similarly to the Graph.addEdge(Object, Object)
+ method.
+
+
+
+static
+
+
+
+<V,E> boolean
+
+
+
+
addGraph(Graph<? super V,? super E> destination,
+ Graph<V,E> source)
+
+
+ Adds all the vertices and all the edges of the specified source graph to
+ the specified destination graph.
+
+
+
+static
+
+
+
+<V,E> void
+
+
+
+
addGraphReversed(DirectedGraph<? super V,? super E> destination,
+ DirectedGraph<V,E> source)
+
+
+ Adds all the vertices and all the edges of the specified source digraph
+ to the specified destination digraph, reversing all of the edges.
+
+
+
+static
+
+
+
+<V,E> V
+
+
+
+
getOppositeVertex(Graph<V,E> g,
+ E e,
+ V v)
+
+
+ Gets the vertex opposite another vertex across an edge.
+public static <V,E> E addEdgeWithVertices(Graph<V,E> g,
+ V sourceVertex,
+ V targetVertex)
+
+
Adds the specified source and target vertices to the graph, if not
+ already included, and creates a new edge and adds it to the specified
+ graph similarly to the Graph.addEdge(Object, Object) method.
+
+
+
Parameters:
g - the graph for which the specified edge to be added.
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
The newly created edge if added to the graph, otherwise
+ null.
Adds the specified edge to the graph, including its vertices if not
+ already included.
+
+
+
Parameters:
targetGraph - the graph for which the specified edge to be added.
sourceGraph - the graph in which the specified edge is already
+ present
edge - edge to add
+
Returns:
true if the target graph did not already contain the
+ specified edge.
+
+
+
+
+
+addEdgeWithVertices
+
+public static <V,E> E addEdgeWithVertices(Graph<V,E> g,
+ V sourceVertex,
+ V targetVertex,
+ double weight)
+
+
Adds the specified source and target vertices to the graph, if not
+ already included, and creates a new weighted edge and adds it to the
+ specified graph similarly to the Graph.addEdge(Object, Object)
+ method.
+
+
+
Parameters:
g - the graph for which the specified edge to be added.
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
weight - weight of the edge.
+
Returns:
The newly created edge if added to the graph, otherwise
+ null.
+
+
+
+
+
+addGraph
+
+public static <V,E> boolean addGraph(Graph<? super V,? super E> destination,
+ Graph<V,E> source)
+
+
Adds all the vertices and all the edges of the specified source graph to
+ the specified destination graph. First all vertices of the source graph
+ are added to the destination graph. Then every edge of the source graph
+ is added to the destination graph. This method returns true
+ if the destination graph has been modified as a result of this operation,
+ otherwise it returns false.
+
+
The behavior of this operation is undefined if any of the specified
+ graphs is modified while operation is in progress.
+
+
+
Parameters:
destination - the graph to which vertices and edges are added.
source - the graph used as source for vertices and edges to add.
+
Returns:
true if and only if the destination graph has been
+ changed as a result of this operation.
+
+
+
+
+
+addGraphReversed
+
+public static <V,E> void addGraphReversed(DirectedGraph<? super V,? super E> destination,
+ DirectedGraph<V,E> source)
+
+
Adds all the vertices and all the edges of the specified source digraph
+ to the specified destination digraph, reversing all of the edges. If you
+ want to do this as a linked view of the source graph (rather than by
+ copying to a destination graph), use EdgeReversedGraph instead.
+
+
The behavior of this operation is undefined if any of the specified
+ graphs is modified while operation is in progress.
+
+
+
Parameters:
destination - the graph to which vertices and edges are added.
source - the graph used as source for vertices and edges to add.
+public static <V,E> boolean addAllEdges(Graph<? super V,? super E> destination,
+ Graph<V,E> source,
+ java.util.Collection<? extends E> edges)
+
+
Adds a subset of the edges of the specified source graph to the specified
+ destination graph. The behavior of this operation is undefined if either
+ of the graphs is modified while the operation is in progress. addEdgeWithVertices(org.jgrapht.Graph, V, V) is used for the transfer, so source vertexes will
+ be added automatically to the target graph.
+
+
+
Parameters:
destination - the graph to which edges are to be added
source - the graph used as a source for edges to add
edges - the edges to be added
+
Returns:
true if this graph changed as a result of the call
+
+
+
+
+
+addAllVertices
+
+public static <V,E> boolean addAllVertices(Graph<? super V,? super E> destination,
+ java.util.Collection<? extends V> vertices)
+
+
Adds all of the specified vertices to the destination graph. The behavior
+ of this operation is undefined if the specified vertex collection is
+ modified while the operation is in progress. This method will invoke the
+ Graph.addVertex(Object) method.
+
+
+
Parameters:
destination - the graph to which edges are to be added
vertices - the vertices to be added to the graph.
+
Returns:
true if graph changed as a result of the call
+
Throws:
+
java.lang.NullPointerException - if the specified vertices contains one or
+ more null vertices, or if the specified vertex collection is
+ null.
+public static <V,E> java.util.List<V> neighborListOf(Graph<V,E> g,
+ V vertex)
+
+
Returns a list of vertices that are the neighbors of a specified vertex.
+ If the graph is a multigraph vertices may appear more than once in the
+ returned list.
+
+
+
Parameters:
g - the graph to look for neighbors in.
vertex - the vertex to get the neighbors of.
+
Returns:
a list of the vertices that are the neighbors of the specified
+ vertex.
+
+
+
+
+
+predecessorListOf
+
+public static <V,E> java.util.List<V> predecessorListOf(DirectedGraph<V,E> g,
+ V vertex)
+
+
Returns a list of vertices that are the direct predecessors of a
+ specified vertex. If the graph is a multigraph, vertices may appear more
+ than once in the returned list.
+
+
+
Parameters:
g - the graph to look for predecessors in.
vertex - the vertex to get the predecessors of.
+
Returns:
a list of the vertices that are the direct predecessors of the
+ specified vertex.
+
+
+
+
+
+successorListOf
+
+public static <V,E> java.util.List<V> successorListOf(DirectedGraph<V,E> g,
+ V vertex)
+
+
Returns a list of vertices that are the direct successors of a specified
+ vertex. If the graph is a multigraph vertices may appear more than once
+ in the returned list.
+
+
+
Parameters:
g - the graph to look for successors in.
vertex - the vertex to get the successors of.
+
Returns:
a list of the vertices that are the direct successors of the
+ specified vertex.
Returns an undirected view of the specified graph. If the specified graph
+ is directed, returns an undirected view of it. If the specified graph is
+ already undirected, just returns it.
+
+
+
Parameters:
g - the graph for which an undirected view is to be returned.
+
Returns:
an undirected view of the specified graph, if it is directed, or
+ or the specified graph itself if it is already undirected.
+
Throws:
+
java.lang.IllegalArgumentException - if the graph is neither DirectedGraph
+ nor UndirectedGraph.
+A vertex factory used by graph algorithms for creating new vertices.
+ Normally, vertices are constructed by user code and added to a graph
+ explicitly, but algorithms which generate new vertices require a factory.
+
BellmanFordShortestPath(Graph<V,E> graph,
+ V startVertex)
+
+
+ Creates an object to calculate shortest paths between the start vertex
+ and others vertices using the Bellman-Ford algorithm.
+
+
+
BellmanFordShortestPath(Graph<V,E> graph,
+ V startVertex,
+ int nMaxHops)
+
+
+ Creates an object to calculate shortest paths between the start vertex
+ and others vertices using the Bellman-Ford algorithm.
+
+
+
BellmanFordShortestPath(Graph<V,E> graph,
+ V startVertex,
+ int nMaxHops,
+ double epsilon)
+
+
+ Creates an object to calculate shortest paths between the start vertex
+ and others vertices using the Bellman-Ford algorithm.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+static
+
+
+
+<V,E> java.util.List<E>
+
+
+
+
findPathBetween(Graph<V,E> graph,
+ V startVertex,
+ V endVertex)
+
+
+ Convenience method to find the shortest path via a single static method
+ call.
list of Edge, or null if no path exists between the
+ start vertex and the end vertex.
+
+
+
+
+
+findPathBetween
+
+public static <V,E> java.util.List<E> findPathBetween(Graph<V,E> graph,
+ V startVertex,
+ V endVertex)
+
+
Convenience method to find the shortest path via a single static method
+ call. If you need a more advanced search (e.g. limited by hops, or
+ computation of the path length), use the constructor instead.
+
+
+
Parameters:
graph - the graph to be searched
startVertex - the vertex at which the path should start
endVertex - the vertex at which the path should end
+
+Inspects a graph for the biconnectivity property. See BlockCutpointGraph for more information. A biconnected graph has only one
+ block (i.e. no cutpoints).
+
Returns the biconnected vertex-components containing the vertex. A
+ biconnected vertex-component contains all the vertices in the component.
+ A vertex which is not a cutpoint is contained in exactly one component. A
+ cutpoint is contained is at least 2 components.
+
+
+
Parameters:
vertex -
+
Returns:
set of all biconnected vertex-components containing the vertex.
Definition 4.5 Let G(V; E) be a connected undirected graph. The
+ block-cut point graph (BC graph) of G, denoted by GB(VB; EB), is the
+ bipartite graph defined as follows. (a) VB has one node corresponding to each
+ block and one node corresponding to each cut point of G. (b) Each edge fx; yg
+ in EB joins a block node x to a cut point y if the block corresponding to x
+ contains the cut point node corresponding to y.
+
Lemma 4.4 Let G(V; E) be a connected undirected graph. (a) Each
+ pair of blocks of G share at most one node, and that node is a cutpoint. (b)
+ The BC graph of G is a tree in which each leaf node corresponds to a block of
+ G.
+This class implements Bron-Kerbosch clique detection algorithm as it is
+ described in [Samudrala R.,Moult J.:A Graph-theoretic Algorithm for
+ comparative Modeling of Protein Structure; J.Mol. Biol. (1998); vol 279; pp.
+ 287-302]
+
Finds all maximal cliques of the graph. A clique is maximal if it is
+ impossible to enlarge it by adding another vertex from the graph. Note
+ that a maximal clique is not necessarily the biggest clique in the graph.
+
+
+
+
Returns:
Collection of cliques (each of which is represented as a Set of
+ vertices)
+Allows the
+ chromatic number of a graph to be calculated. This is the minimal number
+ of colors needed to color each vertex such that no two adjacent vertices
+ share the same color. This algorithm will not find the true chromatic number,
+ since this is an NP-complete problem. So, a greedy algorithm will find an
+ approximate chromatic number.
+
+Allows obtaining various connectivity aspects of a graph. The inspected
+ graph is specified at construction time and cannot be modified.
+ Currently, the inspector supports connected components for an undirected
+ graph and weakly connected components for a directed graph. To find strongly
+ connected components, use StrongConnectivityInspector instead.
+
+
The inspector methods work in a lazy fashion: no computation is performed
+ unless immediately necessary. Computation are done once and results and
+ cached within this class for future need.
+
+
The inspector is also a GraphListener. If added
+ as a listener to the inspected graph, the inspector will amend internal
+ cached results instead of recomputing them. It is efficient when a few
+ modifications are applied to a large graph. If many modifications are
+ expected it will not be efficient due to added overhead on graph update
+ operations. If inspector is added as listener to a graph other than the one
+ it inspects, results are undefined.
Returns a list of Set s, where each set contains all
+ vertices that are in the same maximally connected component. All graph
+ vertices occur in exactly one set. For more on maximally connected
+ component, see
+ http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html.
+
+
+
+
+
+
+
Returns:
Returns a list of Set s, where each set contains all
+ vertices that are in the same maximally connected component.
+public boolean pathExists(V sourceVertex,
+ V targetVertex)
+
+
Tests if there is a path from the specified source vertex to the
+ specified target vertices. For a directed graph, direction is ignored for
+ this interpretation of path.
+
+
Note: Future versions of this method might not ignore edge directions
+ for directed graphs.
+
+
+
+
+
+
Parameters:
sourceVertex - one end of the path.
targetVertex - another end of the path.
+
Returns:
true if and only if there is a path from the source
+ vertex to the target vertex.
+Performs cycle detection on a graph. The inspected graph is specified
+ at construction time and cannot be modified. Currently, the detector supports
+ only directed graphs.
+
Finds the vertex set for the subgraph of all cycles which contain a
+ particular vertex.
+
+
REVIEW jvs 25-Aug-2006: This implementation is not guaranteed to cover
+ all cases. If you want to be absolutely certain that you report vertices
+ from all cycles containing v, it's safer (but less efficient) to use
+ StrongConnectivityInspector instead and return the strongly connected
+ component containing v.
+
+
+
Parameters:
v - the vertex to test
+
Returns:
set of all vertices reachable from v via at least one cycle
DijkstraShortestPath(Graph<V,E> graph,
+ V startVertex,
+ V endVertex)
+
+
+ Creates and executes a new DijkstraShortestPath algorithm instance.
+
+
+
DijkstraShortestPath(Graph<V,E> graph,
+ V startVertex,
+ V endVertex,
+ double radius)
+
+
+ Creates and executes a new DijkstraShortestPath algorithm instance.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+static
+
+
+
+<V,E> java.util.List<E>
+
+
+
+
findPathBetween(Graph<V,E> graph,
+ V startVertex,
+ V endVertex)
+
+
+ Convenience method to find the shortest path via a single static method
+ call.
+public DijkstraShortestPath(Graph<V,E> graph,
+ V startVertex,
+ V endVertex)
+
+
Creates and executes a new DijkstraShortestPath algorithm instance. An
+ instance is only good for a single search; after construction, it can be
+ accessed to retrieve information about the path found.
+
+
+
Parameters:
graph - the graph to be searched
startVertex - the vertex at which the path should start
endVertex - the vertex at which the path should end
+
+
+
+
+DijkstraShortestPath
+
+public DijkstraShortestPath(Graph<V,E> graph,
+ V startVertex,
+ V endVertex,
+ double radius)
+
+
Creates and executes a new DijkstraShortestPath algorithm instance. An
+ instance is only good for a single search; after construction, it can be
+ accessed to retrieve information about the path found.
+
+
+
Parameters:
graph - the graph to be searched
startVertex - the vertex at which the path should start
endVertex - the vertex at which the path should end
radius - limit on path length, or Double.POSITIVE_INFINITY for
+ unbounded search
path length, or Double.POSITIVE_INFINITY if no path exists
+
+
+
+
+
+findPathBetween
+
+public static <V,E> java.util.List<E> findPathBetween(Graph<V,E> graph,
+ V startVertex,
+ V endVertex)
+
+
Convenience method to find the shortest path via a single static method
+ call. If you need a more advanced search (e.g. limited by radius, or
+ computation of the path length), use the constructor instead.
+
+
+
Parameters:
graph - the graph to be searched
startVertex - the vertex at which the path should start
endVertex - the vertex at which the path should end
+
+Maintains a cache of each vertex's neighbors. While lists of neighbors can be
+ obtained from Graphs, they are re-calculated at each invocation by
+ walking a vertex's incident edges, which becomes inordinately expensive when
+ performed often.
+
+
A vertex's neighbors are cached the first time they are asked for (i.e.
+ the index is built on demand). The index will only be updated automatically
+ if it is added to the associated graph as a listener. If it is added as a
+ listener to a graph other than the one it indexes, results are undefined.
Returns the set of vertices which are the predecessors of a specified
+ vertex. The returned set is backed by the index, and will be updated when
+ the graph changes as long as the index has been added as a listener to
+ the graph.
+
Returns the set of vertices which are the predecessors of a specified
+ vertex. If the graph is a multigraph, vertices may appear more than once
+ in the returned list. Because a list of predecessors can not be
+ efficiently maintained, it is reconstructed on every invocation by
+ duplicating entries in the neighbor set. It is thus more efficient to use
+ predecessorsOf(Object) unless duplicate neighbors are required.
+
Returns the set of vertices which are the successors of a specified
+ vertex. The returned set is backed by the index, and will be updated when
+ the graph changes as long as the index has been added as a listener to
+ the graph.
+
Returns the set of vertices which are the successors of a specified
+ vertex. If the graph is a multigraph, vertices may appear more than once
+ in the returned list. Because a list of successors can not be efficiently
+ maintained, it is reconstructed on every invocation by duplicating
+ entries in the neighbor set. It is thus more efficient to use successorsOf(Object) unless duplicate neighbors are required.
+
+A flow network is a
+ directed graph where each edge has a capacity and each edge receives a flow.
+ The amount of flow on an edge can not exceed the capacity of the edge (note,
+ that all capacities must be non-negative). A flow must satisfy the
+ restriction that the amount of flow into a vertex equals the amount of flow
+ out of it, except when it is a source, which "produces" flow, or sink, which
+ "consumes" flow.
+
+
This class computes maximum flow in a network using Edmonds-Karp
+ algorithm. Be careful: for large networks this algorithm may consume
+ significant amount of time (its upper-bound complexity is O(VE^2), where V -
+ amount of vertices, E - amount of edges in the network).
+
+
For more details see Andrew V. Goldberg's Combinatorial Optimization
+ (Lecture Notes).
+
calculateMaximumFlow(V source,
+ V sink)
+
+
+ Sets current source to source, current sink to sink,
+ then calculates maximum flow from source to sink.
getMaximumFlow()
+
+
+ Returns maximum flow, that was calculated during last
+ calculateMaximumFlow call, or null, if there was no
+ calculateMaximumFlow calls.
+
+
+
+ java.lang.Double
+
getMaximumFlowValue()
+
+
+ Returns maximum flow value, that was calculated during last
+ calculateMaximumFlow call, or null, if there was no
+ calculateMaximumFlow calls.
Constructs MaximumFlow instance to work with a copy of
+ network. Current source and sink are set to null. If
+ network is weighted, then capacities are weights, otherwise all
+ capacities are equal to one. Doubles are compared using
+ DEFAULT_EPSILON tolerance.
+
+
+
Parameters:
network - network, where maximum flow will be calculated
Constructs MaximumFlow instance to work with a copy of
+ network. Current source and sink are set to null. If
+ network is weighted, then capacities are weights, otherwise all
+ capacities are equal to one.
+
+
+
Parameters:
network - network, where maximum flow will be calculated
epsilon - tolerance for comparing doubles
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+calculateMaximumFlow
+
+public void calculateMaximumFlow(V source,
+ V sink)
+
+
Sets current source to source, current sink to sink,
+ then calculates maximum flow from source to sink. Note,
+ that source and sink must be vertices of the
+ network passed to the constructor, and they must be different.
+
+
+
Parameters:
source - source vertex
sink - sink vertex
+
+
+
+
+
+getMaximumFlowValue
+
+public java.lang.Double getMaximumFlowValue()
+
+
Returns maximum flow value, that was calculated during last
+ calculateMaximumFlow call, or null, if there was no
+ calculateMaximumFlow calls.
+
+This algorithm will check whether a graph is Eulerian (hence it contains an
+ Eulerian
+ circuit). Also, if a graph is Eulerian, the caller can obtain a list of
+ vertices making up the Eulerian circuit. An Eulerian circuit is a circuit
+ which traverses each edge exactly once.
+
+The
+ Floyd-Warshall algorithm finds all shortest paths (all n^2 of them) in
+ O(n^3) time. This also works out the graph diameter during the process.
+
+This class will deal with finding the optimal or approximately optimal
+ minimum tour (hamiltonian cycle) or commonly known as the Traveling
+ Salesman Problem.
+
This method will return an approximate minimal traveling salesman tour
+ (hamiltonian cycle). This algorithm requires that the graph be complete
+ and the triangle inequality exists (if x,y,z are vertices then
+ d(x,y)+d(y,z)
+
+The algorithm determines the k shortest simple paths in increasing order of
+ weight. Weights could be negative (but no negative cycle is allowed), paths
+ could be constrained by a maximum number of edges.
+
+
The algorithm is a variant of the Bellman-Ford algorithm but instead of
+ only storing the best path it stores the "k" best paths at each pass,
+ yielding a complexity of O(k*m*n) where m is the number of edges and n is the
+ number of vertices.
+
+
+
+
+
Since:
+
July 5, 2007
+
Author:
+
Guillaume Boulmier
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
KShortestPaths(Graph<V,E> graph,
+ V startVertex,
+ int k)
+
+
+ Creates an object to compute ranking shortest paths between the start
+ vertex and others vertices.
+
+
+
KShortestPaths(Graph<V,E> graph,
+ V startVertex,
+ int nPaths,
+ int nMaxHops)
+
+
+ Creates an object to calculate ranking shortest paths between the start
+ vertex and others vertices.
+Maintains a cache of each vertex's neighbors. While lists of neighbors can be
+ obtained from Graphs, they are re-calculated at each invocation by
+ walking a vertex's incident edges, which becomes inordinately expensive when
+ performed often.
+
+
Edge direction is ignored when evaluating neighbors; to take edge
+ direction into account when indexing neighbors, use DirectedNeighborIndex.
+
+
A vertex's neighbors are cached the first time they are asked for (i.e.
+ the index is built on demand). The index will only be updated automatically
+ if it is added to the associated graph as a listener. If it is added as a
+ listener to a graph other than the one it indexes, results are undefined.
+
+
+
+
+
Since:
+
Dec 13, 2005
+
Author:
+
Charles Fry
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
NeighborIndex(Graph<V,E> g)
+
+
+ Creates a neighbor index for the specified undirected graph.
Returns the set of vertices which are adjacent to a specified vertex. The
+ returned set is backed by the index, and will be updated when the graph
+ changes as long as the index has been added as a listener to the graph.
+
Returns a list of vertices which are adjacent to a specified vertex. If
+ the graph is a multigraph, vertices may appear more than once in the
+ returned list. Because a list of neighbors can not be efficiently
+ maintained, it is reconstructed on every invocation, by duplicating
+ entries in the neighbor set. It is thus more efficient to use neighborsOf(Object) unless duplicate neighbors are important.
+
Complements the ConnectivityInspector class with
+ the capability to compute the strongly connected components of a directed
+ graph. The algorithm is implemented after "Cormen et al: Introduction to
+ agorithms", Chapter 22.5. It has a running time of O(V + E).
stronglyConnectedSets()
+
+
+ Computes a List of Sets, where each set contains vertices
+ which together form a strongly connected component within the given
+ graph.
Computes a list of DirectedSubgraphs of the given graph. Each
+ subgraph will represent a strongly connected component and will contain
+ all vertices of that component. The subgraph will have an edge (u,v) iff
+ u and v are contained in the strongly connected component.
+
+
NOTE: Calling this method will first execute stronglyConnectedSets(). If you don't need
+ subgraphs, use that method.
+
+
+
+
Returns:
a list of subgraphs representing the strongly connected
+ components
+Algorithms to find a vertex cover for a graph. A vertex cover is a set of
+ vertices that touches all the edges in the graph. The graph's vertex set is a
+ trivial cover. However, a minimal vertex set (or at least an
+ approximation for it) is usually desired. Finding a true minimal vertex cover
+ is an NP-Complete problem. For more on the vertex cover problem, see
+ http://mathworld.wolfram.com/VertexCover.html
+
Finds a 2-approximation for a minimal vertex cover of the specified
+ graph. The algorithm promises a cover that is at most double the size of
+ a minimal cover. The algorithm takes O(|E|) time.
+
+
Finds a greedy approximation for a minimal vertex cover of a specified
+ graph. At each iteration, the algorithm picks the vertex with the highest
+ degree and adds it to the cover, until all edges are covered.
+
+
The algorithm works on undirected graphs, but can also work on
+ directed graphs when their edge-directions are ignored. To ignore edge
+ directions you can use Graphs.undirectedGraph(Graph)
+ or AsUndirectedGraph.
+
+
+
Parameters:
g - the graph for which vertex cover approximation is to be found.
+
Returns:
a set of vertices which is a vertex cover for the specified
+ graph.
This class implements Bron-Kerbosch clique detection algorithm as it is
+ described in [Samudrala R.,Moult J.:A Graph-theoretic Algorithm for
+ comparative Modeling of Protein Structure; J.Mol.
This class will deal with finding the optimal or approximately optimal
+ minimum tour (hamiltonian cycle) or commonly known as the Traveling
+ Salesman Problem.
VertexDegreeComparator(UndirectedGraph<V,E> g,
+ boolean ascendingOrder)
+
+
+ Creates a comparator for comparing the degrees of vertices in the
+ specified graph.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+ int
+
compare(V v1,
+ V v2)
+
+
+ Compare the degrees of v1 and v2, taking into
+ account whether ascending or descending order is used.
Creates a comparator for comparing the degrees of vertices in the
+ specified graph. The comparator compares in ascending order of degrees
+ (lowest first).
+
+
+
Parameters:
g - graph with respect to which the degree is calculated.
+A simple demo to test memory and CPU consumption on a graph with 3 million
+ elements.
+
+
NOTE: To run this demo you may need to increase the JVM max mem size. In
+ Sun's JVM it is done using the "-Xmx" switch. Specify "-Xmx300M" to set it to
+ 300MB.
+
+
WARNING: Don't run this demo as-is on machines with less than 512MB
+ memory. Your machine will start paging severely. You need to first modify it
+ to have fewer graph elements. This is easily done by changing the loop
+ counters below.
+An event which indicates that a graph edge has changed, or is about to
+ change. The event can be used either as an indication after the edge
+ has been added or removed, or before it is added. The type of the
+ event can be tested using the GraphChangeEvent.getType() method.
+
+An event which indicates that a graph vertex has changed, or is about to
+ change. The event can be used either as an indication after the vertex
+ has been added or removed, or before it is added. The type of the
+ event can be tested using the GraphChangeEvent.getType() method.
+
edgeTraversed(EdgeTraversalEvent<V,E> e)
+
+
+ Called to inform the listener that the specified edge have been visited
+ during the graph traversal.
+
+
+
+ void
+
vertexFinished(VertexTraversalEvent<V> e)
+
+
+ Called to inform the listener that the specified vertex have been
+ finished during the graph traversal.
+
+
+
+ void
+
vertexTraversed(VertexTraversalEvent<V> e)
+
+
+ Called to inform the listener that the specified vertex have been visited
+ during the graph traversal.
Called to inform the listener that the specified edge have been visited
+ during the graph traversal. Depending on the traversal algorithm, edge
+ might be visited more than once.
+
Called to inform the listener that the specified vertex have been visited
+ during the graph traversal. Depending on the traversal algorithm, vertex
+ might be visited more than once.
+
Called to inform the listener that the specified vertex have been
+ finished during the graph traversal. Exact meaning of "finish" is
+ algorithm-dependent; e.g. for DFS, it means that all vertices reachable
+ via the vertex have been visited as well.
+
edgeTraversed(EdgeTraversalEvent<V,E> e)
+
+
+ Called to inform the listener that the specified edge have been visited
+ during the graph traversal.
+
+
+
+ void
+
vertexFinished(VertexTraversalEvent<V> e)
+
+
+ Called to inform the listener that the specified vertex have been
+ finished during the graph traversal.
+
+
+
+ void
+
vertexTraversed(VertexTraversalEvent<V> e)
+
+
+ Called to inform the listener that the specified vertex have been visited
+ during the graph traversal.
Called to inform the listener that the specified edge have been visited
+ during the graph traversal. Depending on the traversal algorithm, edge
+ might be visited more than once.
+
Called to inform the listener that the specified vertex have been visited
+ during the graph traversal. Depending on the traversal algorithm, vertex
+ might be visited more than once.
+
Called to inform the listener that the specified vertex have been
+ finished during the graph traversal. Exact meaning of "finish" is
+ algorithm-dependent; e.g. for DFS, it means that all vertices reachable
+ via the vertex have been visited as well.
+
+A listener that is notified when the graph's vertex set changes. It should be
+ used when only notifications on vertex-set changes are of interest. If
+ all graph notifications are of interest better use
+ GraphListener.
+
DOTExporter()
+
+
+ Constructs a new DOTExporter object with an integer name provider for the
+ vertex IDs and null providers for the vertex and edge labels.
The objects associated with vertices and edges are exported as labels
+ using their toString() implementation. See the setPrintLabels(Integer) method. The default behavior is to export no label
+ information.
GmlExporter()
+
+
+ Creates a new GmlExporter object with integer name providers for the
+ vertex and edge IDs and null providers for the vertex and edge labels.
GraphMLExporter()
+
+
+ Constructs a new GraphMLExporter object with integer name providers for
+ the vertex and edge IDs and null providers for the vertex and edge
+ labels.
Constructs a new GraphMLExporter object with integer name providers for
+ the vertex and edge IDs and null providers for the vertex and edge
+ labels.
+
+Assigns a unique integer to represent each edge. Each instance of
+ IntegerEdgeNameProvider maintains an internal map between every edge it has
+ ever seen and the unique integer representing that edge. As a result it is
+ probably desirable to have a separate instance for each distinct graph.
+
+Assigns a unique integer to represent each vertex. Each instance of
+ IntegerNameProvider maintains an internal map between every vertex it has
+ ever seen and the unique integer representing that vertex. As a result it is
+ probably desirable to have a separate instance for each distinct graph.
+
+An adapter that reflects a JGraphT graph as a JGraph graph. This adapter is
+ useful when using JGraph in order to visualize JGraphT graphs. For more about
+ JGraph see
+ http://jgraph.sourceforge.net
+
+
Modifications made to the underlying JGraphT graph are reflected to this
+ JGraph model if and only if the underlying JGraphT graph is a ListenableGraph. If the underlying JGraphT graph is not
+ ListenableGraph, then this JGraph model represent a snapshot if the graph at
+ the time of its creation.
+
+
Changes made to this JGraph model are also reflected back to the
+ underlying JGraphT graph. To avoid confusion, variables are prefixed
+ according to the JGraph/JGraphT object(s) they are referring to.
+
+
KNOWN BUGS: There is a small issue to be aware of. JGraph allows
+ 'dangling edges' incident with just one vertex; JGraphT doesn't. Such a
+ configuration can arise when adding an edge or removing a vertex. The code
+ handles this by removing the newly-added dangling edge or removing all edges
+ incident with the vertex before actually removing the vertex, respectively.
+ This works very well, only it doesn't play all that nicely with the
+ undo-manager in the JGraph: for the second situation where you remove a
+ vertex incident with some edges, if you undo the removal, the vertex is
+ 'unremoved' but the edges aren't.
Fields inherited from class javax.swing.undo.UndoableEditSupport
+
+
+
compoundEdit, listeners, realSource, updateLevel
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
JGraphModelAdapter(Graph<V,E> jGraphTGraph)
+
+
+ Constructs a new JGraph model adapter for the specified JGraphT graph.
+
+
+
JGraphModelAdapter(Graph<V,E> jGraphTGraph,
+ org.jgraph.graph.AttributeMap defaultVertexAttributes,
+ org.jgraph.graph.AttributeMap defaultEdgeAttributes)
+
+
+ Constructs a new JGraph model adapter for the specified JGraphT graph.
+
+
+
JGraphModelAdapter(Graph<V,E> jGraphTGraph,
+ org.jgraph.graph.AttributeMap defaultVertexAttributes,
+ org.jgraph.graph.AttributeMap defaultEdgeAttributes,
+ JGraphModelAdapter.CellFactory<V,E> cellFactory)
+
+
+ Constructs a new JGraph model adapter for the specified JGraphT graph.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+static
+
+
+
+<V,E> org.jgraph.graph.AttributeMap
+
+
+
+
createDefaultEdgeAttributes(Graph<V,E> jGraphTGraph)
+
+
+ Creates and returns a map of attributes to be used as defaults for edge
+ attributes, depending on the specified graph.
+
+
+
+static org.jgraph.graph.AttributeMap
+
createDefaultVertexAttributes()
+
+
+ Creates and returns a map of attributes to be used as defaults for vertex
+ attributes.
getCellFactory()
+
+
+ Returns the cell factory used to create the JGraph cells.
+
+
+
+ org.jgraph.graph.AttributeMap
+
getDefaultEdgeAttributes()
+
+
+ Returns the default edge attributes used for creating new JGraph edges.
+
+
+
+ org.jgraph.graph.AttributeMap
+
getDefaultVertexAttributes()
+
+
+ Returns the default vertex attributes used for creating new JGraph
+ vertices.
+
+
+
+ org.jgraph.graph.DefaultEdge
+
getEdgeCell(E jGraphTEdge)
+
+
+ Returns the JGraph edge cell that corresponds to the specified JGraphT
+ edge.
+
+
+
+ org.jgraph.graph.DefaultGraphCell
+
getVertexCell(java.lang.Object jGraphTVertex)
+
+
+ Returns the JGraph vertex cell that corresponds to the specified JGraphT
+ vertex.
+
+
+
+ org.jgraph.graph.DefaultPort
+
getVertexPort(java.lang.Object jGraphTVertex)
+
+
+ Returns the JGraph port cell that corresponds to the specified JGraphT
+ vertex.
+
+
+
+ void
+
setDefaultEdgeAttributes(org.jgraph.graph.AttributeMap defaultEdgeAttributes)
+
+
+ Sets the default edge attributes used for creating new JGraph edges.
+
+
+
+ void
+
setDefaultVertexAttributes(org.jgraph.graph.AttributeMap defaultVertexAttributes)
+
+
+ Sets the default vertex attributes used for creating new JGraph vertices.
+
+
+
+
+
+
Methods inherited from class org.jgraph.graph.DefaultGraphModel
+Exports a graph to a plain text matrix format, which can be processed by
+ matrix manipulation software, such as
+ MTJ or MATLAB.
+
+
+
+
+
Author:
+
Charles Fry
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
MatrixExporter()
+
+
+ Creates a new MatrixExporter object.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+ void
+
exportAdjacencyMatrix(java.io.Writer output,
+ DirectedGraph<V,E> g)
+
+
+ Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's adjacency matrix.
+
+
+
+ void
+
exportAdjacencyMatrix(java.io.Writer output,
+ UndirectedGraph<V,E> g)
+
+
+ Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's adjacency matrix.
+
+
+
+ void
+
exportLaplacianMatrix(java.io.Writer output,
+ UndirectedGraph<V,E> g)
+
+
+ Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's Laplacian matrix.
+
+
+
+ void
+
exportNormalizedLaplacianMatrix(java.io.Writer output,
+ UndirectedGraph<V,E> g)
+
+
+ Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's normalized Laplacian matrix.
Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's adjacency matrix. The value stored
+ in each position of the matrix indicates the number of edges between two
+ vertices. With an undirected graph, the adjacency matrix is symetric.
+
+
+
Parameters:
output - the writer to which the graph to be exported.
Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's adjacency matrix. The value stored
+ in each position of the matrix indicates the number of directed edges
+ going from one vertex to another.
+
+
+
Parameters:
output - the writer to which the graph to be exported.
Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's Laplacian matrix. Laplacian matrices
+ are only defined for simple graphs, so edge direction, multiple edges,
+ loops, and weights are all ignored when creating the Laplacian matrix. If
+ you're unsure about Laplacian matrices, see:
+ http://mathworld.wolfram.com/LaplacianMatrix.html.
+
+
+
Parameters:
output - the writer to which the graph is to be exported.
Exports the specified graph into a plain text file format containing a
+ sparse representation of the graph's normalized Laplacian matrix.
+ Laplacian matrices are only defined for simple graphs, so edge direction,
+ multiple edges, loops, and weights are all ignored when creating the
+ Laplacian matrix. If you're unsure about normalized Laplacian matrices,
+ see:
+ http://mathworld.wolfram.com/LaplacianMatrix.html.
+
+
+
Parameters:
output - the writer to which the graph is to be exported.
+Generates edge names by invoking Object.toString() on them. This assumes
+ that the edge's Object.toString() method returns a unique String
+ representation for each edge.
+
+Generates vertex names by invoking Object.toString() on them. This assumes
+ that the vertex's Object.toString() method returns a unique String
+ representation for each vertex.
+
Returns a unique name for a vertex. This is useful when exporting a a
+ graph, as it ensures that all vertices are assigned simple, consistant
+ names.
+
+Generates a complete
+ bipartite graph of any size. This is a graph with two partitions; two
+ vertices will contain an edge if and only if they belong to different
+ partitions.
+
+
+
+
+
Since:
+
Dec 21, 2008
+
Author:
+
Andrew Newell
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
CompleteBipartiteGraphGenerator(int partitionOne,
+ int partitionTwo)
+
+
+ Creates a new CompleteBipartiteGraphGenerator object.
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+Generates a complete graph of any size. A complete graph is a graph where
+ every vertex shares an edge with every other vertex. If it is a directed
+ graph, then edges must always exist in both directions. On a side note, a
+ complete graph is the least efficient possible graph in terms of memory and
+ cpu usage. Note: This contructor was designed for a simple undirected or
+ directed graph. It will act strangely when used with certain graph types,
+ such as undirected multigraphs. Note, though, that a complete undirected
+ multigraph is rather senseless -- you can keep adding edges and the graph is
+ never truly complete.
+
Generate a graph structure. The topology of the generated graph is
+ dependent on the implementation. For graphs in which not all vertices
+ share the same automorphism equivalence class, the generator may produce
+ a labeling indicating the roles played by generated elements. This is the
+ purpose of the resultMap parameter. For example, a generator for a wheel
+ graph would designate a hub vertex. Role names used as keys in resultMap
+ should be declared as public static final Strings by implementation
+ classes.
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
Generate a graph structure. The topology of the generated graph is
+ dependent on the implementation. For graphs in which not all vertices
+ share the same automorphism equivalence class, the generator may produce
+ a labeling indicating the roles played by generated elements. This is the
+ purpose of the resultMap parameter. For example, a generator for a wheel
+ graph would designate a hub vertex. Role names used as keys in resultMap
+ should be declared as public static final Strings by implementation
+ classes.
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
Generate a graph structure. The topology of the generated graph is
+ dependent on the implementation. For graphs in which not all vertices
+ share the same automorphism equivalence class, the generator may produce
+ a labeling indicating the roles played by generated elements. This is the
+ purpose of the resultMap parameter. For example, a generator for a wheel
+ graph would designate a hub vertex. Role names used as keys in resultMap
+ should be declared as public static final Strings by implementation
+ classes.
+
+
+
Parameters:
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+Generates a hyper
+ cube graph of any size. This is a graph that can be represented by bit
+ strings, so for an n-dimensial hypercube each vertex resembles an n-length
+ bit string. Then, two vertices are adjacent if and only if their bitstring
+ differ by exactly one element.
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
Generate a graph structure. The topology of the generated graph is
+ dependent on the implementation. For graphs in which not all vertices
+ share the same automorphism equivalence class, the generator may produce
+ a labeling indicating the roles played by generated elements. This is the
+ purpose of the resultMap parameter. For example, a generator for a wheel
+ graph would designate a hub vertex. Role names used as keys in resultMap
+ should be declared as public static final Strings by implementation
+ classes.
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+Default implementation of the EdgeTopologyFactory interface. randomly
+ chooses an edge and tries to add it. If the add fails from any reason
+ (like: self edge / multiple edges in unpermitted graph type) it will just
+ choose another and try again. Performance:
+
when the number of possible edges becomes slim , this class will have
+ a very poor performance , cause it will not use gready methods to choose
+ them. for example : In simple graph , if #V = N (#x = number Of x) and we
+ want full mesh #edges= N*(N-1)/2 , the first added edges will do so
+ quickly (O(1) , the last will take O(N^2). So , do not use it in this
+ kind of graphs.
+
If the numberOfEdges is bigger than what the graph can add, there
+ will be an infinite loop here. It is not tested.
+
createEdges(Graph<VV,EE> targetGraph,
+ java.util.Map<java.lang.Integer,VV> orderToVertexMap,
+ int numberOfEdges,
+ java.util.Random randomizer)
+
+
+ Two different calls to the createEdges() with the same parameters
+ must result in the generation of the same.
isNumberOfEdgesValid(Graph<VV,EE> targetGraph,
+ int numberOfEdges)
+
+
+ checks if the numOfEdges is smaller than the Max edges according to
+ the following table:
Two different calls to the createEdges() with the same parameters
+ must result in the generation of the same. But if the randomizer is
+ different, it should, usually, create different edge topology.
+
public static interface RandomGraphGenerator.EdgeTopologyFactory<VV,EE>
+
+
+
+This class is used to generate the edge topology for a graph.
+
+
+
+
+
Since:
+
Aug 6, 2005
+
Author:
+
Assaf
+
+
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+ void
+
createEdges(Graph<VV,EE> targetGraph,
+ java.util.Map<java.lang.Integer,VV> orderToVertexMap,
+ int numberOfEdges,
+ java.util.Random randomizer)
+
+
+ Two different calls to the createEdges() with the same parameters
+ must result in the generation of the same.
+
+
+
+ boolean
+
isNumberOfEdgesValid(Graph<VV,EE> targetGraph,
+ int numberOfEdges)
+
+
+ Checks if the graph can contain the givven numberOfEdges according to
+ the graph type restrictions.
Two different calls to the createEdges() with the same parameters
+ must result in the generation of the same. But if the randomizer is
+ different, it should, usually, create different edge topology.
+
+
+
Parameters:
targetGraph - - guranteed to start with zero edges.
orderToVertexMap - - key=Integer of vertex order . between zero
+ to numOfVertexes (exclusive). value = vertex from the graph. unique.
numberOfEdges - - to create in the graph
randomizer -
+
+
+
+
+
+isNumberOfEdgesValid
+
+boolean isNumberOfEdgesValid(Graph<VV,EE> targetGraph,
+ int numberOfEdges)
+
+
Checks if the graph can contain the givven numberOfEdges according to
+ the graph type restrictions. For example: #V means number of
+ vertexes in graph
+
a Simple Graph, can have max of #V*(#V-1)/2 edges. etc
+
+This Generator creates a random-topology graph of a specified number of
+ vertexes and edges. An instance of this generator will always return the same
+ graph-topology in calls to generateGraph(). The vertexes can be different
+ (depends on the VertexFactory implementation)
+
+
However, two instances which use the same constructor parameters will
+ produce two different random graphs (note: as with any random generator,
+ there is always a small possibility that two instances will create the same
+ results).
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+
Throws:
+
java.lang.IllegalArgumentException - if the aNumOfEdges passed in the
+ constructor, cannot be created on a graph of the concrete type with
+ aNumOfVertexes.
+ org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory#isNumberOfEdgesValid(org.jgrapht.Graph,
+ int)
+Generates a ring graph of any size. A ring graph is a graph that contains a
+ single cycle that passes through all its vertices exactly once. For a
+ directed graph, the generated edges are oriented consistently around the
+ ring.
+
Generate a graph structure. The topology of the generated graph is
+ dependent on the implementation. For graphs in which not all vertices
+ share the same automorphism equivalence class, the generator may produce
+ a labeling indicating the roles played by generated elements. This is the
+ purpose of the resultMap parameter. For example, a generator for a wheel
+ graph would designate a hub vertex. Role names used as keys in resultMap
+ should be declared as public static final Strings by implementation
+ classes.
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+Generates directed or undirected scale-free network
+ of any size. Scale-free network is a connected graph, where degrees of
+ vertices are distributed in unusual way. There are many vertices with small
+ degrees and only small amount of vertices with big degrees.
+
Generates scale-free network with size passed to the
+ constructor. Each call of this method produces identical output (but if
+ target is an undirected graph, the directions of edges will be
+ lost).
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
StarGraphGenerator(int order)
+
+
+ Creates a new StarGraphGenerator object.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+ void
+
generateGraph(Graph<V,E> target,
+ VertexFactory<V> vertexFactory,
+ java.util.Map<java.lang.String,V> resultMap)
+
+
+ Generates a star graph with the designated order from the constructor
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+Generates a wheel
+ graph of any size. Reminding a bicycle wheel, a wheel graph has a hub
+ vertex in the center and a rim of vertices around it that are connected to
+ each other (as a ring). The rim vertices are also connected to the hub with
+ edges that are called "spokes".
+
Creates a new WheelGraphGenerator object. This constructor is more
+ suitable for undirected graphs, where spokes' direction is meaningless.
+ In the directed case, spokes will be oriented from rim to hub.
+
Generate a graph structure. The topology of the generated graph is
+ dependent on the implementation. For graphs in which not all vertices
+ share the same automorphism equivalence class, the generator may produce
+ a labeling indicating the roles played by generated elements. This is the
+ purpose of the resultMap parameter. For example, a generator for a wheel
+ graph would designate a hub vertex. Role names used as keys in resultMap
+ should be declared as public static final Strings by implementation
+ classes.
+
target - receives the generated edges and vertices; if this is
+ non-empty on entry, the result will be a disconnected graph since
+ generated elements will not be connected to existing elements
vertexFactory - called to produce new vertices
resultMap - if non-null, receives implementation-specific mappings
+ from String roles to graph elements (or collections of graph elements)
+The most general implementation of the Graph interface.
+ Its subclasses add various restrictions to get more specific graphs. The
+ decision whether it is directed or undirected is decided at construction time
+ and cannot be later modified (see constructor for details).
+
+
This graph implementation guarantees deterministic vertex and edge set
+ ordering (via LinkedHashMap and LinkedHashSet).
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ boolean
+
addVertex(V v)
+
+
+ Adds the specified vertex to this graph if not already present.
+
+
+
+ java.lang.Object
+
clone()
+
+
+ Returns a shallow copy of this graph instance.
+
+
+
+ boolean
+
containsEdge(E e)
+
+
+ Returns true if this graph contains the specified edge.
+
+
+
+ boolean
+
containsVertex(V v)
+
+
+ Returns true if this graph contains the specified vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ boolean
+
removeVertex(V v)
+
+
+ Removes the specified vertex from this graph including all its touching
+ edges if present.
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
Returns true if and only if self-loops are allowed in this
+ graph. A self loop is an edge that its source and target vertices are the
+ same.
+
+
+
+
+
+
+
Returns:
true if and only if graph loops are allowed.
+
+
+
+
+
+isAllowingMultipleEdges
+
+public boolean isAllowingMultipleEdges()
+
+
Returns true if and only if multiple edges are allowed in
+ this graph. The meaning of multiple edges is that there can be many edges
+ going from vertex v1 to vertex v2.
+
+
+
+
+
+
+
Returns:
true if and only if multiple edges are allowed.
+
+
+
+
+
+getEdge
+
+public EgetEdge(V sourceVertex,
+ V targetVertex)
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
Returns the edge factory using which this graph creates new edges. The
+ edge factory is defined when the graph is constructed and must not be
+ modified.
+
Set the EdgeSetFactory to use for this graph. Initially, a graph
+ is created with a default implementation which always supplies an ArrayList with capacity 1.
+
+
+
+
+
+
Parameters:
edgeSetFactory - factory to use for subsequently created edge sets
+ (this call has no effect on existing edge sets)
+
+
+
+
+
+addEdge
+
+public EaddEdge(V sourceVertex,
+ V targetVertex)
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns true if this graph contains the specified edge. More
+ formally, returns true if and only if this graph contains an
+ edge e2 such that e.equals(e2). If the
+ specified edge is null returns false.
+
Returns true if this graph contains the specified vertex. More
+ formally, returns true if and only if this graph contains a
+ vertex u such that u.equals(v). If the
+ specified vertex is null returns false.
+
Returns a set of the edges contained in this graph. The set is backed by
+ the graph, so changes to the graph are reflected in the set. If the graph
+ is modified while an iteration over the set is in progress, the results
+ of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
Returns a set of the vertices contained in this graph. The set is backed
+ by the graph, so changes to the graph are reflected in the set. If the
+ graph is modified while an iteration over the set is in progress, the
+ results of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
+A skeletal implementation of the Graph interface, to minimize the
+ effort required to implement graph interfaces. This implementation is
+ applicable to both: directed graphs and undirected graphs.
+
AbstractGraph()
+
+
+ Construct a new empty graph object.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+protected boolean
+
assertVertexExist(V v)
+
+
+ Ensures that the specified vertex exists in this graph, or else throws
+ exception.
+
+
+
+ boolean
+
containsEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns true if and only if this graph contains an edge going
+ from the source vertex to the target vertex.
+
+
+
+ boolean
+
removeAllEdges(java.util.Collection<? extends E> edges)
+
+
+ Removes all the edges in this graph that are also contained in the
+ specified edge collection.
+
+
+
+protected boolean
+
removeAllEdges(E[] edges)
+
+
+ Removes all the edges in this graph that are also contained in the
+ specified edge array.
removeAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges.
+
+
+
+ boolean
+
removeAllVertices(java.util.Collection<? extends V> vertices)
+
+
+ Removes all the vertices in this graph that are also contained in the
+ specified vertex collection.
+
+
+
+ java.lang.String
+
toString()
+
+
+ Returns a string of the parenthesized pair (V, E) representing this
+ G=(V,E) graph.
Returns true if and only if this graph contains an edge going
+ from the source vertex to the target vertex. In undirected graphs the
+ same result is obtained when source and target are inverted. If any of
+ the specified vertices does not exist in the graph, or if is
+ null, returns false.
+
Removes all the edges in this graph that are also contained in the
+ specified edge collection. After this call returns, this graph will
+ contain no edges in common with the specified edges. This method will
+ invoke the Graph.removeEdge(Object) method.
+
Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges. Returns
+ null if any of the specified vertices does not exist in the
+ graph. If both vertices exist but no edge is found, returns an empty set.
+ This method will either invoke the Graph.removeEdge(Object) method, or
+ the Graph.removeEdge(Object, Object) method.
+
Removes all the vertices in this graph that are also contained in the
+ specified vertex collection. After this call returns, this graph will
+ contain no vertices in common with the specified vertices. This method
+ will invoke the Graph.removeVertex(Object) method.
+
Returns a string of the parenthesized pair (V, E) representing this
+ G=(V,E) graph. 'V' is the string representation of the vertex set, and
+ 'E' is the string representation of the edge set.
+
Removes all the edges in this graph that are also contained in the
+ specified edge array. After this call returns, this graph will contain no
+ edges in common with the specified edges. This method will invoke the
+ Graph.removeEdge(Object) method.
+
+
+
+
+
+
Parameters:
edges - edges to be removed from this graph.
+
Returns:
true if this graph changed as a result of the call.
+An undirected view of the backing directed graph specified in the
+ constructor. This graph allows modules to apply algorithms designed for
+ undirected graphs to a directed graph by simply ignoring edge direction. If
+ the backing directed graph is an oriented graph,
+ then the view will be a simple graph; otherwise, it will be a multigraph.
+ Query operations on this graph "read through" to the backing graph. Attempts
+ to add edges will result in an UnsupportedOperationException,
+ but vertex addition/removal and edge removal are all supported (and
+ immediately reflected in the backing graph).
+
+
Note that edges returned by this graph's accessors are really just the
+ edges of the underlying directed graph. Since there is no interface
+ distinction between directed and undirected edges, this detail should be
+ irrelevant to algorithms.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods. This graph will be serializable if the backing
+ graph is serializable.
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ int
+
degreeOf(V vertex)
+
+
+ Returns the degree of the specified vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Returns a string of the parenthesized pair (V, E) representing this
+ G=(V,E) graph. 'V' is the string representation of the vertex set, and
+ 'E' is the string representation of the edge set.
+
+An unweighted view of the backing weighted graph specified in the
+ constructor. This graph allows modules to apply algorithms designed for
+ unweighted graphs to a weighted graph by simply ignoring edge weights. Query
+ operations on this graph "read through" to the backing graph. Vertex
+ addition/removal and edge addition/removal are all supported (and immediately
+ reflected in the backing graph).
+
+
Note that edges returned by this graph's accessors are really just the
+ edges of the underlying directed graph.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods. This graph will be serializable if the backing
+ graph is serializable.
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
+An unweighted view of the backing weighted graph specified in the
+ constructor. This graph allows modules to apply algorithms designed for
+ unweighted graphs to a weighted graph by simply ignoring edge weights. Query
+ operations on this graph "read through" to the backing graph. Vertex
+ addition/removal and edge addition/removal are all supported (and immediately
+ reflected in the backing graph).
+
+
Note that edges returned by this graph's accessors are really just the
+ edges of the underlying directed graph.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods. This graph will be serializable if the backing
+ graph is serializable.
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
A weighted view of the backing graph specified in the constructor. This
+ graph allows modules to apply algorithms designed for weighted graphs to an
+ unweighted graph by providing an explicit edge weight mapping. The
+ implementation also allows for "masking" weights for a subset of the edges in
+ an existing weighted graph.
+
+
Query operations on this graph "read through" to the backing graph. Vertex
+ addition/removal and edge addition/removal are all supported (and immediately
+ reflected in the backing graph). Setting an edge weight will pass the
+ operation to the backing graph as well if the backing graph implements the
+ WeightedGraph interface. Setting an edge weight will modify the weight map in
+ order to maintain a consistent graph.
+
+
Note that edges returned by this graph's accessors are really just the
+ edges of the underlying directed graph.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods. This graph will be serializable if the backing
+ graph is serializable.
g - the backing graph over which a weighted view is to be created.
weightMap - A mapping of edges to weights. If an edge is not present
+ in the weight map, the edge weight for the underlying graph is returned.
+ Note that a live reference to this map is retained, so if the caller
+ changes the map after construction, the changes will affect the
+ AsWeightedGraph instance as well.
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
+A directed graph. A default directed graph is a non-simple directed graph in
+ which multiple edges between any two vertices are not permitted, but
+ loops are.
+
+
prefixed 'Default' to avoid name collision with the DirectedGraph
+ interface.
+A directed weighted graph. A directed weighted graph is a non-simple directed
+ graph in which multiple edges between any two vertices are not
+ permitted, but loops are. The graph has weights on its edges.
+
+Implementation of the GraphMapping interface. The performance of
+ getVertex/EdgeCorrespondence is based on the performance of the
+ concrete Map class which is passed in the constructor. For example, using
+ hashmaps will provide O(1) performence.
+
The maps themselves are used. There is no defensive-copy. Assumption: The
+ key and value in the mappings are of valid graph objects. It is not
+ checked.
+
+A graph backed by the the graph specified at the constructor, which can be
+ listened by GraphListener s and by
+ VertexSetListener s. Operations on this graph "pass through" to the to
+ the backing graph. Any modification made to this graph or the backing graph
+ is reflected by the other.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods.
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
setReuseEvents(boolean reuseEvents)
+
+
+ If the reuseEvents flag is set to true this
+ class will reuse previously fired events and will not create a new object
+ for each event.
+
+
+
+
+
+
Methods inherited from class org.jgrapht.graph.GraphDelegator
Creates a new listenable graph. If the reuseEvents flag is
+ set to true this class will reuse previously fired events
+ and will not create a new object for each event. This option increases
+ performance but should be used with care, especially in multithreaded
+ environment.
+
+
+
Parameters:
g - the backing graph.
reuseEvents - whether to reuse previously fired event objects
+ instead of creating a new event object for each event.
+
Throws:
+
java.lang.IllegalArgumentException - if the backing graph is already a
+ listenable graph.
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+setReuseEvents
+
+public void setReuseEvents(boolean reuseEvents)
+
+
If the reuseEvents flag is set to true this
+ class will reuse previously fired events and will not create a new object
+ for each event. This option increases performance but should be used with
+ care, especially in multithreaded environment.
+
+
+
+
+
+
Parameters:
reuseEvents - whether to reuse previously fired event objects
+ instead of creating a new event object for each event.
+
+
+
+
+
+isReuseEvents
+
+public boolean isReuseEvents()
+
+
Tests whether the reuseEvents flag is set. If the flag is
+ set to true this class will reuse previously fired events
+ and will not create a new object for each event. This option increases
+ performance but should be used with care, especially in multithreaded
+ environment.
+
+
+
+
+
+
+
Returns:
the value of the reuseEvents flag.
+
+
+
+
+
+addEdge
+
+public EaddEdge(V sourceVertex,
+ V targetVertex)
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
+A default implementation for edges in a WeightedGraph. All access to
+ the weight of an edge must go through the graph interface, which is why this
+ class doesn't expose any public methods.
+
Returns the "in degree" of the specified vertex. An in degree of a vertex
+ in a directed graph is the number of inward directed edges from that
+ vertex. See
+ http://mathworld.wolfram.com/Indegree.html.
+
Returns the "out degree" of the specified vertex. An out degree of a
+ vertex in a directed graph is the number of outward directed edges from
+ that vertex. See
+ http://mathworld.wolfram.com/Outdegree.html.
+
+A directed multigraph. A directed multigraph is a non-simple directed graph
+ in which loops and multiple edges between any two vertices are permitted.
+
+A directed pseudograph. A directed pseudograph is a non-simple directed graph
+ in which both graph loops and multiple edges are permitted. If you're unsure
+ about pseudographs, see:
+ http://mathworld.wolfram.com/Pseudograph.html.
+
Returns the "in degree" of the specified vertex. An in degree of a vertex
+ in a directed graph is the number of inward directed edges from that
+ vertex. See
+ http://mathworld.wolfram.com/Indegree.html.
+
Returns the "out degree" of the specified vertex. An out degree of a
+ vertex in a directed graph is the number of outward directed edges from
+ that vertex. See
+ http://mathworld.wolfram.com/Outdegree.html.
+
+A directed weighted multigraph. A directed weighted multigraph is a
+ non-simple directed graph in which loops and multiple edges between any two
+ vertices are permitted, and edges have weights.
+
+Provides an edge-reversed view g' of a directed graph g. The vertex sets for
+ the two graphs are the same, but g' contains an edge (v2, v1) iff g contains
+ an edge (v1, v2). g' is backed by g, so changes to g are reflected in g', and
+ vice versa.
+
+
This class allows you to use a directed graph algorithm in reverse. For
+ example, suppose you have a directed graph representing a tree, with edges
+ from parent to child, and you want to find all of the parents of a node. To
+ do this, simply create an edge-reversed graph and pass that as input to
+ DepthFirstIterator.
+
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ java.lang.String
+
toString()
+
+
+ Returns a string of the parenthesized pair (V, E) representing this
+ G=(V,E) graph.
+
+
+
+
+
+
Methods inherited from class org.jgrapht.graph.GraphDelegator
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Returns the "in degree" of the specified vertex. An in degree of a vertex
+ in a directed graph is the number of inward directed edges from that
+ vertex. See
+ http://mathworld.wolfram.com/Indegree.html.
+
Returns the "out degree" of the specified vertex. An out degree of a
+ vertex in a directed graph is the number of outward directed edges from
+ that vertex. See
+ http://mathworld.wolfram.com/Outdegree.html.
+
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns a string of the parenthesized pair (V, E) representing this
+ G=(V,E) graph. 'V' is the string representation of the vertex set, and
+ 'E' is the string representation of the edge set.
+
+A factory for edge sets. This interface allows the creator of a graph to
+ choose the Set implementation used internally by the graph
+ to maintain sets of edges. This provides control over performance tradeoffs
+ between memory and CPU usage.
+
vertex - the vertex for which the edge set is being created;
+ sophisticated factories may be able to use this information to choose an
+ optimal set representation (e.g. ArrayUnenforcedSet for a vertex expected
+ to have low degree, and LinkedHashSet for a vertex expected to have high
+ degree)
+
+A graph backed by the the graph specified at the constructor, which delegates
+ all its methods to the backing graph. Operations on this graph "pass through"
+ to the to the backing graph. Any modification made to this graph or the
+ backing graph is reflected by the other.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods.
+
+
This class is mostly used as a base for extending subclasses.
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ boolean
+
addVertex(V v)
+
+
+ Adds the specified vertex to this graph if not already present.
+
+
+
+ boolean
+
containsEdge(E e)
+
+
+ Returns true if this graph contains the specified edge.
+
+
+
+ boolean
+
containsVertex(V v)
+
+
+ Returns true if this graph contains the specified vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ boolean
+
removeVertex(V v)
+
+
+ Removes the specified vertex from this graph including all its touching
+ edges if present.
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
Returns the edge factory using which this graph creates new edges. The
+ edge factory is defined when the graph is constructed and must not be
+ modified.
+
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
Returns true if this graph contains the specified edge. More
+ formally, returns true if and only if this graph contains an
+ edge e2 such that e.equals(e2). If the
+ specified edge is null returns false.
+
Returns true if this graph contains the specified vertex. More
+ formally, returns true if and only if this graph contains a
+ vertex u such that u.equals(v). If the
+ specified vertex is null returns false.
+
Returns a set of the edges contained in this graph. The set is backed by
+ the graph, so changes to the graph are reflected in the set. If the graph
+ is modified while an iteration over the set is in progress, the results
+ of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
Returns a string of the parenthesized pair (V, E) representing this
+ G=(V,E) graph. 'V' is the string representation of the vertex set, and
+ 'E' is the string representation of the edge set.
+
Returns a set of the vertices contained in this graph. The set is backed
+ by the graph, so changes to the graph are reflected in the set. If the
+ graph is modified while an iteration over the set is in progress, the
+ results of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
Returns the edges making up the path. The first edge in this path is
+ incident to the start vertex. The last edge is incident to the end
+ vertex. The vertices along the path can be obtained by traversing from
+ the start vertex, finding its opposite across the first edge, and then
+ doing the same successively across subsequent edges; Graphs.getPathVertexList(org.jgrapht.GraphPath) provides a convenience method for this.
+
+
Whether or not the returned edge list is modifiable depends on the
+ path implementation.
+
Returns the weight assigned to the path. Typically, this will be the sum
+ of the weights of the edge list entries (as defined by the containing
+ graph), but some path implementations may use other definitions.
+
Read-only union of two graphs: G1 and G2. If
+ G1 = (V1, E1) and G2 =
+ (V2, E2) then their union G = (V, E), where V is the
+ union of V1 and V2, and E is the union of E1
+ and E1.
+
+
GraphUnion implements Graph interface.
+ GraphUnion uses WeightCombiner to choose policy for calculating
+ edge weight.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
Returns true if this graph contains the specified edge. More
+ formally, returns true if and only if this graph contains an
+ edge e2 such that e.equals(e2). If the
+ specified edge is null returns false.
+
Returns true if this graph contains the specified vertex. More
+ formally, returns true if and only if this graph contains a
+ vertex u such that u.equals(v). If the
+ specified vertex is null returns false.
+
Returns a set of the edges contained in this graph. The set is backed by
+ the graph, so changes to the graph are reflected in the set. If the graph
+ is modified while an iteration over the set is in progress, the results
+ of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Returns a set of the vertices contained in this graph. The set is backed
+ by the graph, so changes to the graph are reflected in the set. If the
+ graph is modified while an iteration over the set is in progress, the
+ results of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
+An unmodifiable subgraph induced by a vertex/edge masking function. The
+ subgraph will keep track of edges being added to its vertex subset as well as
+ deletion of edges and vertices. When iterating over the vertices/edges, it
+ will iterate over the vertices/edges of the base graph and discard
+ vertices/edges that are masked (an edge with a masked extremity vertex is
+ discarded as well).
+
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E edge)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ boolean
+
addVertex(V v)
+
+
+ Adds the specified vertex to this graph if not already present.
+
+
+
+ boolean
+
containsEdge(E e)
+
+
+ Returns true if this graph contains the specified edge.
+
+
+
+ boolean
+
containsVertex(V v)
+
+
+ Returns true if this graph contains the specified vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
removeAllEdges(java.util.Collection<? extends E> edges)
+
+
+ Removes all the edges in this graph that are also contained in the
+ specified edge collection.
removeAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges.
+
+
+
+ boolean
+
removeAllVertices(java.util.Collection<? extends V> vertices)
+
+
+ Removes all the vertices in this graph that are also contained in the
+ specified vertex collection.
+
+
+
+ boolean
+
removeEdge(E e)
+
+
+ Removes the specified edge from the graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ boolean
+
removeVertex(V v)
+
+
+ Removes the specified vertex from this graph including all its touching
+ edges if present.
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
The newly created edge if added to the graph, otherwise
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
edge - edge to be added to this graph.
+
Returns:
true if this graph did not already contain the specified
+ edge.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
+
+
Parameters:
v - vertex to be added to this graph.
+
Returns:
true if this graph did not already contain the specified
+ vertex.
Returns true if this graph contains the specified edge. More
+ formally, returns true if and only if this graph contains an
+ edge e2 such that e.equals(e2). If the
+ specified edge is null returns false.
+
+
+
Parameters:
e - edge whose presence in this graph is to be tested.
+
Returns true if this graph contains the specified vertex. More
+ formally, returns true if and only if this graph contains a
+ vertex u such that u.equals(v). If the
+ specified vertex is null returns false.
+
+
+
Parameters:
v - vertex whose presence in this graph is to be tested.
+
Returns a set of the edges contained in this graph. The set is backed by
+ the graph, so changes to the graph are reflected in the set. If the graph
+ is modified while an iteration over the set is in progress, the results
+ of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
a set of all edges connecting source vertex to target vertex.
+
+
+
+
+
+getEdge
+
+public EgetEdge(V sourceVertex,
+ V targetVertex)
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
+
+
+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge.
+
Returns:
an edge connecting source vertex to target vertex.
Returns the edge factory using which this graph creates new edges. The
+ edge factory is defined when the graph is constructed and must not be
+ modified.
+
+
+
+
Returns:
the edge factory using which this graph creates new edges.
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
Removes all the edges in this graph that are also contained in the
+ specified edge collection. After this call returns, this graph will
+ contain no edges in common with the specified edges. This method will
+ invoke the Graph.removeEdge(Object) method.
+
Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges. Returns
+ null if any of the specified vertices does not exist in the
+ graph. If both vertices exist but no edge is found, returns an empty set.
+ This method will either invoke the Graph.removeEdge(Object) method, or
+ the Graph.removeEdge(Object, Object) method.
+
Removes all the vertices in this graph that are also contained in the
+ specified vertex collection. After this call returns, this graph will
+ contain no vertices in common with the specified vertices. This method
+ will invoke the Graph.removeVertex(Object) method.
+
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
If the specified edge is null returns
+ false.
+
+
+
Parameters:
e - edge to be removed from this graph, if present.
+
Returns:
true if and only if the graph contained the
+ specified edge.
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
If the specified vertex is null returns
+ false.
+
+
+
Parameters:
v - vertex to be removed from this graph, if present.
+
Returns:
true if the graph contained the specified vertex;
+ false otherwise.
Returns a set of the vertices contained in this graph. The set is backed
+ by the graph, so changes to the graph are reflected in the set. If the
+ graph is modified while an iteration over the set is in progress, the
+ results of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
+
+
+
+
Returns:
a set view of the vertices contained in this graph.
+A multigraph. A multigraph is a non-simple undirected graph in which no loops
+ are permitted, but multiple edges between any two vertices are. If you're
+ unsure about multigraphs, see:
+ http://mathworld.wolfram.com/Multigraph.html.
+
+ParanoidGraph provides a way to verify that objects added to a graph obey the
+ standard equals/hashCode contract. It can be used to wrap an underlying graph
+ to be verified. Note that the verification is very expensive, so
+ ParanoidGraph should only be used during debugging.
+
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
+A pseudograph. A pseudograph is a non-simple undirected graph in which both
+ graph loops and multiple edges are permitted. If you're unsure about
+ pseudographs, see:
+ http://mathworld.wolfram.com/Pseudograph.html.
+
+A simple directed graph. A simple directed graph is a directed graph in which
+ neither multiple edges between any two vertices nor loops are permitted.
+
+A simple graph. A simple graph is an undirected graph for which at most one
+ edge connects any two vertices, and loops are not permitted. If you're unsure
+ about simple graphs, see:
+ http://mathworld.wolfram.com/SimpleGraph.html.
+
+A subgraph is a graph that has a subset of vertices and a subset of edges
+ with respect to some base graph. More formally, a subgraph G(V,E) that is
+ based on a base graph Gb(Vb,Eb) satisfies the following subgraph
+ property: V is a subset of Vb and E is a subset of Eb. Other than
+ this property, a subgraph is a graph with any respect and fully complies with
+ the Graph interface.
+
+
If the base graph is a ListenableGraph, the subgraph
+ listens on the base graph and guarantees the subgraph property. If an edge or
+ a vertex is removed from the base graph, it is automatically removed from the
+ subgraph. Subgraph listeners are informed on such removal only if it results
+ in a cascaded removal from the subgraph. If the subgraph has been created as
+ an induced subgraph it also keeps track of edges being added to its vertices.
+ If vertices are added to the base graph, the subgraph remains unaffected.
+
+
If the base graph is not a ListenableGraph, then the subgraph
+ property cannot be guaranteed. If edges or vertices are removed from the base
+ graph, they are not removed from the subgraph.
+
+
Modifications to Subgraph are allowed as long as the subgraph property is
+ maintained. Addition of vertices or edges are allowed as long as they also
+ exist in the base graph. Removal of vertices or edges is always allowed. The
+ base graph is never affected by any modification made to the
+ subgraph.
+
+
A subgraph may provide a "live-window" on a base graph, so that changes
+ made to its vertices or edges are immediately reflected in the base graph,
+ and vice versa. For that to happen, vertices and edges added to the subgraph
+ must be identical (that is, reference-equal and not only value-equal)
+ to their respective ones in the base graph. Previous versions of this class
+ enforced such identity, at a severe performance cost. Currently it is no
+ longer enforced. If you want to achieve a "live-window"functionality, your
+ safest tactics would be to NOT override the equals() methods of
+ your vertices and edges. If you use a class that has already overridden the
+ equals() method, such as String, than you can use a
+ wrapper around it, or else use it directly but exercise a great care to avoid
+ having different-but-equal instances in the subgraph and the base graph.
+
+
This graph implementation guarantees deterministic vertex and edge set
+ ordering (via LinkedHashSet).
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ boolean
+
addVertex(V v)
+
+
+ Adds the specified vertex to this subgraph.
+
+
+
+ boolean
+
containsEdge(E e)
+
+
+ Returns true if this graph contains the specified edge.
+
+
+
+ boolean
+
containsVertex(V v)
+
+
+ Returns true if this graph contains the specified vertex.
getAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph.
getEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ boolean
+
removeVertex(V v)
+
+
+ Removes the specified vertex from this graph including all its touching
+ edges if present.
Creates a new induced Subgraph. The subgraph will keep track of edges
+ being added to its vertex subset as well as deletion of edges and
+ vertices. If base it not listenable, this is identical to the call
+ Subgraph(base, vertexSubset, null) .
+
+
+
Parameters:
base - the base (backing) graph on which the subgraph will be based.
vertexSubset - vertices to include in the subgraph. If
+ null then all vertices are included.
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+getAllEdges
+
+public java.util.Set<E> getAllEdges(V sourceVertex,
+ V targetVertex)
Returns a set of all edges connecting source vertex to target vertex if
+ such vertices exist in this graph. If any of the vertices does not exist
+ or is null, returns null. If both vertices
+ exist but no edges found, returns an empty set.
+
+
In undirected graphs, some of the returned edges may have their source
+ and target vertices in the opposite order. In simple graphs the returned
+ set is either singleton set or empty set.
Returns an edge connecting source vertex to target vertex if such
+ vertices and such edge exist in this graph. Otherwise returns
+ null. If any of the specified vertices is null
+ returns null
+
+
In undirected graphs, the returned edge may have its source and target
+ vertices in the opposite order.
Returns the edge factory using which this graph creates new edges. The
+ edge factory is defined when the graph is constructed and must not be
+ modified.
+
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Returns true if this graph contains the specified edge. More
+ formally, returns true if and only if this graph contains an
+ edge e2 such that e.equals(e2). If the
+ specified edge is null returns false.
+
Returns true if this graph contains the specified vertex. More
+ formally, returns true if and only if this graph contains a
+ vertex u such that u.equals(v). If the
+ specified vertex is null returns false.
+
Returns a set of the edges contained in this graph. The set is backed by
+ the graph, so changes to the graph are reflected in the set. If the graph
+ is modified while an iteration over the set is in progress, the results
+ of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
Returns a set of the vertices contained in this graph. The set is backed
+ by the graph, so changes to the graph are reflected in the set. If the
+ graph is modified while an iteration over the set is in progress, the
+ results of the iteration are undefined.
+
+
The graph implementation may maintain a particular set ordering (e.g.
+ via LinkedHashSet) for deterministic iteration, but
+ this is not required. It is the responsibility of callers who rely on
+ this behavior to only use graph implementations which support it.
Returns the source vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the target vertex of an edge. For an undirected graph, source and
+ target are distinguishable designations (but without any mathematical
+ meaning).
+
Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ (as defined by WeightedGraph.DEFAULT_EDGE_WEIGHT), allowing
+ weighted-graph algorithms to apply to them where meaningful.
+
+An unmodifiable view of the backing graph specified in the constructor. This
+ graph allows modules to provide users with "read-only" access to internal
+ graphs. Query operations on this graph "read through" to the backing graph,
+ and attempts to modify this graph result in an
+ UnsupportedOperationException.
+
+
This graph does not pass the hashCode and equals operations through
+ to the backing graph, but relies on Object's equals and
+ hashCode methods. This graph will be serializable if the backing
+ graph is serializable.
addEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge.
+
+
+
+ boolean
+
addEdge(V sourceVertex,
+ V targetVertex,
+ E e)
+
+
+ Adds the specified edge to this graph, going from the source vertex to
+ the target vertex.
+
+
+
+ boolean
+
addVertex(V v)
+
+
+ Adds the specified vertex to this graph if not already present.
+
+
+
+ boolean
+
removeAllEdges(java.util.Collection<? extends E> edges)
+
+
+ Removes all the edges in this graph that are also contained in the
+ specified edge collection.
removeAllEdges(V sourceVertex,
+ V targetVertex)
+
+
+ Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges.
+
+
+
+ boolean
+
removeAllVertices(java.util.Collection<? extends V> vertices)
+
+
+ Removes all the vertices in this graph that are also contained in the
+ specified vertex collection.
+
+
+
+ boolean
+
removeEdge(E e)
+
+
+ Removes the specified edge from the graph.
removeEdge(V sourceVertex,
+ V targetVertex)
+
+
+ Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph.
+
+
+
+ boolean
+
removeVertex(V v)
+
+
+ Removes the specified vertex from this graph including all its touching
+ edges if present.
+
+
+
+
+
+
Methods inherited from class org.jgrapht.graph.GraphDelegator
Creates a new edge in this graph, going from the source vertex to the
+ target vertex, and returns the created edge. Some graphs do not allow
+ edge-multiplicity. In such cases, if the graph already contains an edge
+ from the specified source to the specified target, than this method does
+ not change the graph and returns null.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
+
+
This method creates the new edge e using this graph's
+ EdgeFactory. For the new edge to be added e
+ must not be equal to any other edge the graph (even if the graph
+ allows edge-multiplicity). More formally, the graph must not contain any
+ edge e2 such that e2.equals(e). If such
+ e2 is found then the newly created edge e is
+ abandoned, the method leaves this graph unchanged returns
+ null.
Adds the specified edge to this graph, going from the source vertex to
+ the target vertex. More formally, adds the specified edge,
+ e, to this graph if this graph contains no edge e2
+ such that e2.equals(e). If this graph already contains such
+ an edge, the call leaves this graph unchanged and returns false.
+ Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ already contains an edge from the specified source to the specified
+ target, than this method does not change the graph and returns
+ false. If the edge was added to the graph, returns
+ true.
+
+
The source and target vertices must already be contained in this
+ graph. If they are not found in graph IllegalArgumentException is
+ thrown.
Adds the specified vertex to this graph if not already present. More
+ formally, adds the specified vertex, v, to this graph if
+ this graph contains no vertex u such that
+ u.equals(v). If this graph already contains such vertex, the call
+ leaves this graph unchanged and returns false. In combination
+ with the restriction on constructors, this ensures that graphs never
+ contain duplicate vertices.
+
Removes all the edges in this graph that are also contained in the
+ specified edge collection. After this call returns, this graph will
+ contain no edges in common with the specified edges. This method will
+ invoke the Graph.removeEdge(Object) method.
+
Removes all the edges going from the specified source vertex to the
+ specified target vertex, and returns a set of all removed edges. Returns
+ null if any of the specified vertices does not exist in the
+ graph. If both vertices exist but no edge is found, returns an empty set.
+ This method will either invoke the Graph.removeEdge(Object) method, or
+ the Graph.removeEdge(Object, Object) method.
+
Removes all the vertices in this graph that are also contained in the
+ specified vertex collection. After this call returns, this graph will
+ contain no vertices in common with the specified vertices. This method
+ will invoke the Graph.removeVertex(Object) method.
+
Removes the specified edge from the graph. Removes the specified edge
+ from this graph if it is present. More formally, removes an edge
+ e2 such that e2.equals(e), if the graph contains such
+ edge. Returns true if the graph contained the specified edge.
+ (The graph will not contain the specified edge once the call returns).
+
+
Removes an edge going from source vertex to target vertex, if such
+ vertices and such edge exist in this graph. Returns the edge if removed
+ or null otherwise.
+
Removes the specified vertex from this graph including all its touching
+ edges if present. More formally, if the graph contains a vertex
+ u such that u.equals(v), the call removes all edges
+ that touch u and then removes u itself. If no
+ such u is found, the call leaves the graph unchanged.
+ Returns true if the graph contained the specified vertex. (The
+ graph will not contain the specified vertex once the call returns).
+
+
+A weighted multigraph. A weighted multigraph is a non-simple undirected graph
+ in which no loops are permitted, but multiple edges between any two vertices
+ are. The edges of a weighted multigraph have weights. If you're unsure about
+ multigraphs, see:
+ http://mathworld.wolfram.com/Multigraph.html.
+
+A weighted pseudograph. A weighted pseudograph is a non-simple undirected
+ graph in which both graph loops and multiple edges are permitted. The edges
+ of a weighted pseudograph have weights. If you're unsure about pseudographs,
+ see:
+ http://mathworld.wolfram.com/Pseudograph.html.
+
GraphMapping represents a bidirectional mapping between two graphs (called
+ graph1 and graph2), which allows the caller to obtain the matching vertex or
+ edge in either direction, from graph1 to graph2, or from graph2 to graph1.
setCrossComponentTraversal(boolean crossComponentTraversal)
+
+
+ Sets the cross component traversal flag - indicates whether to traverse
+ the graph across connected components.
+
+
+
+ void
+
setReuseEvents(boolean reuseEvents)
+
+
+ Sets a value the reuseEvents flag.
Sets a value the reuseEvents flag. If the
+ reuseEvents flag is set to true this class will reuse
+ previously fired events and will not create a new object for each event.
+ This option increases performance but should be used with care,
+ especially in multithreaded environment.
+
Tests whether the reuseEvents flag is set. If the flag is
+ set to true this class will reuse previously fired events
+ and will not create a new object for each event. This option increases
+ performance but should be used with care, especially in multithreaded
+ environment.
+
+A breadth-first iterator for a directed and an undirected graph. For this
+ iterator to work correctly the graph must not be modified during iteration.
+ Currently there are no means to ensure that, nor to fail-fast. The results of
+ such modifications are undefined.
+
+
+
+
+
Since:
+
Jul 19, 2003
+
Author:
+
Barak Naveh
+
+
+
+
+
+
+
+
+
+
+Nested Class Summary
+
+
+
+
+
+
Nested classes/interfaces inherited from class org.jgrapht.traverse.CrossComponentIterator
BreadthFirstIterator(Graph<V,E> g,
+ V startVertex)
+
+
+ Creates a new breadth-first iterator for the specified graph.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+protected void
+
encounterVertex(V vertex,
+ E edge)
+
+
+ Update data structures the first time we see a vertex.
+
+
+
+protected void
+
encounterVertexAgain(V vertex,
+ E edge)
+
+
+ Called whenever we re-encounter a vertex.
+
+
+
+protected boolean
+
isConnectedComponentExhausted()
+
+
+ Returns true if there are no more uniterated vertices in the
+ currently iterated connected component; false otherwise.
Creates a new breadth-first iterator for the specified graph.
+
+
+
Parameters:
g - the graph to be iterated.
+
+
+
+
+BreadthFirstIterator
+
+public BreadthFirstIterator(Graph<V,E> g,
+ V startVertex)
+
+
Creates a new breadth-first iterator for the specified graph. Iteration
+ will start at the specified start vertex and will be limited to the
+ connected component that includes that vertex. If the specified start
+ vertex is null, iteration will start at an arbitrary vertex
+ and will not be limited, that is, will be able to traverse all the graph.
+
+A closest-first iterator for a directed or undirected graph. For this
+ iterator to work correctly the graph must not be modified during iteration.
+ Currently there are no means to ensure that, nor to fail-fast. The results of
+ such modifications are undefined.
+
+
The metric for closest here is the path length from a start vertex.
+ Graph.getEdgeWeight(Edge) is summed to calculate path length. Negative edge
+ weights will result in an IllegalArgumentException. Optionally, path length
+ may be bounded by a finite radius.
+
+
+
+
+
Since:
+
Sep 2, 2003
+
Author:
+
John V. Sichi
+
+
+
+
+
+
+
+
+
+
+Nested Class Summary
+
+
+
+
+
+
Nested classes/interfaces inherited from class org.jgrapht.traverse.CrossComponentIterator
ClosestFirstIterator(Graph<V,E> g,
+ V startVertex)
+
+
+ Creates a new closest-first iterator for the specified graph.
+
+
+
ClosestFirstIterator(Graph<V,E> g,
+ V startVertex,
+ double radius)
+
+
+ Creates a new radius-bounded closest-first iterator for the specified
+ graph.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+protected void
+
encounterVertex(V vertex,
+ E edge)
+
+
+ Update data structures the first time we see a vertex.
getSpanningTreeEdge(V vertex)
+
+
+ Get the spanning tree edge reaching a vertex which has been seen already
+ in this traversal.
+
+
+
+protected boolean
+
isConnectedComponentExhausted()
+
+
+ Returns true if there are no more uniterated vertices in the
+ currently iterated connected component; false otherwise.
provideNextVertex()
+
+
+ Returns the vertex to be returned in the following call to the iterator
+ next method.
+
+
+
+ void
+
setCrossComponentTraversal(boolean crossComponentTraversal)
+
+
+ Sets the cross component traversal flag - indicates whether to traverse
+ the graph across connected components.
Creates a new closest-first iterator for the specified graph.
+
+
+
Parameters:
g - the graph to be iterated.
+
+
+
+
+ClosestFirstIterator
+
+public ClosestFirstIterator(Graph<V,E> g,
+ V startVertex)
+
+
Creates a new closest-first iterator for the specified graph. Iteration
+ will start at the specified start vertex and will be limited to the
+ connected component that includes that vertex. If the specified start
+ vertex is null, iteration will start at an arbitrary vertex
+ and will not be limited, that is, will be able to traverse all the graph.
+
+
+
Parameters:
g - the graph to be iterated.
startVertex - the vertex iteration to be started.
+
+
+
+
+ClosestFirstIterator
+
+public ClosestFirstIterator(Graph<V,E> g,
+ V startVertex,
+ double radius)
+
+
Creates a new radius-bounded closest-first iterator for the specified
+ graph. Iteration will start at the specified start vertex and will be
+ limited to the subset of the connected component which includes that
+ vertex and is reachable via paths of length less than or equal to the
+ specified radius. The specified start vertex may not be
+ null.
+
+
+
Parameters:
g - the graph to be iterated.
startVertex - the vertex iteration to be started.
radius - limit on path length, or Double.POSITIVE_INFINITY for
+ unbounded search.
Get the length of the shortest path known to the given vertex. If the
+ vertex has already been visited, then it is truly the shortest path
+ length; otherwise, it is the best known upper bound.
+
+
+
Parameters:
vertex - vertex being sought from start vertex
+
Returns:
length of shortest path known, or Double.POSITIVE_INFINITY if no
+ path found yet
Get the spanning tree edge reaching a vertex which has been seen already
+ in this traversal. This edge is the last link in the shortest known path
+ between the start vertex and the requested vertex. If the vertex has
+ already been visited, then it is truly the minimum spanning tree edge;
+ otherwise, it is the best candidate seen so far.
+
+
+
Parameters:
vertex - the spanned vertex.
+
Returns:
the spanning tree edge, or null if the vertex either has not been
+ seen yet or is the start vertex.
Returns an array containing the constants of this enum type, in
+the order they are declared. This method may be used to iterate
+over the constants as follows:
+
+for (CrossComponentIterator.VisitColor c : CrossComponentIterator.VisitColor.values())
+ System.out.println(c);
+
+
+
+
+
Returns:
an array containing the constants of this enum type, in
+the order they are declared
Returns the enum constant of this type with the specified name.
+The string must match exactly an identifier used to declare an
+enum constant in this type. (Extraneous whitespace characters are
+not permitted.)
+
+
+
Parameters:
name - the name of the enum constant to be returned.
+
Returns:
the enum constant with the specified name
+
Throws:
+
java.lang.IllegalArgumentException - if this enum type has no constant
+with the specified name
+
java.lang.NullPointerException - if the argument is null
isConnectedComponentExhausted()
+
+
+ Returns true if there are no more uniterated vertices in the
+ currently iterated connected component; false otherwise.
+
+
+
+protected boolean
+
isSeenVertex(java.lang.Object vertex)
+
+
+ Determines whether a vertex has been seen yet by this traversal.
+public CrossComponentIterator(Graph<V,E> g,
+ V startVertex)
+
+
Creates a new iterator for the specified graph. Iteration will start at
+ the specified start vertex. If the specified start vertex is
+ null, Iteration will start at an arbitrary graph vertex.
+
+
+
Parameters:
g - the graph to be iterated.
startVertex - the vertex iteration to be started.
+
Throws:
+
java.lang.IllegalArgumentException - if g==null or does not
+ contain startVertex
data associated with the seen vertex or null if no
+ data was associated with the vertex. A null return can also
+ indicate that the vertex was explicitly associated with
+ null.
Stores iterator-dependent data for a vertex that has been seen.
+
+
+
Parameters:
vertex - a vertex which has been seen.
data - data to be associated with the seen vertex.
+
Returns:
previous value associated with specified vertex or
+ null if no data was associated with the vertex. A
+ null return can also indicate that the vertex was explicitly
+ associated with null.
+A depth-first iterator for a directed and an undirected graph. For this
+ iterator to work correctly the graph must not be modified during iteration.
+ Currently there are no means to ensure that, nor to fail-fast. The results of
+ such modifications are undefined.
+
+
+
+
+
Since:
+
Jul 29, 2003
+
Author:
+
Liviu Rau, Barak Naveh
+
+
+
+
+
+
+
+
+
+
+Nested Class Summary
+
+
+
+
+
+
Nested classes/interfaces inherited from class org.jgrapht.traverse.CrossComponentIterator
DepthFirstIterator(Graph<V,E> g,
+ V startVertex)
+
+
+ Creates a new depth-first iterator for the specified graph.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+protected void
+
encounterVertex(V vertex,
+ E edge)
+
+
+ Update data structures the first time we see a vertex.
+
+
+
+protected void
+
encounterVertexAgain(V vertex,
+ E edge)
+
+
+ Called whenever we re-encounter a vertex.
+
+
+
+ java.util.Deque<java.lang.Object>
+
getStack()
+
+
+ Retrieves the LIFO stack of vertices which have been encountered but not
+ yet visited (WHITE).
+
+
+
+protected boolean
+
isConnectedComponentExhausted()
+
+
+ Returns true if there are no more uniterated vertices in the
+ currently iterated connected component; false otherwise.
Sentinel object. Unfortunately, we can't use null, because ArrayDeque
+ won't accept those. And we don't want to rely on the caller to provide a
+ sentinel object for us. So we have to play typecasting games.
+
Creates a new depth-first iterator for the specified graph.
+
+
+
Parameters:
g - the graph to be iterated.
+
+
+
+
+DepthFirstIterator
+
+public DepthFirstIterator(Graph<V,E> g,
+ V startVertex)
+
+
Creates a new depth-first iterator for the specified graph. Iteration
+ will start at the specified start vertex and will be limited to the
+ connected component that includes that vertex. If the specified start
+ vertex is null, iteration will start at an arbitrary vertex
+ and will not be limited, that is, will be able to traverse all the graph.
+
Retrieves the LIFO stack of vertices which have been encountered but not
+ yet visited (WHITE). This stack also contains sentinel entries
+ representing vertices which have been visited but are still GRAY. A
+ sentinel entry is a sequence (v, SENTINEL), whereas a non-sentinel entry
+ is just (v).
+
setReuseEvents(boolean reuseEvents)
+
+
+ Sets a value the reuseEvents flag.
+
+
+
+
+
+
Methods inherited from interface java.util.Iterator
+
+
+
hasNext, next
+
+
+
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+isCrossComponentTraversal
+
+boolean isCrossComponentTraversal()
+
+
Test whether this iterator is set to traverse the grpah across connected
+ components.
+
+
+
+
+
+
+
Returns:
true if traverses across connected components,
+ otherwise false.
+
+
+
+
+
+setReuseEvents
+
+void setReuseEvents(boolean reuseEvents)
+
+
Sets a value the reuseEvents flag. If the
+ reuseEvents flag is set to true this class will reuse
+ previously fired events and will not create a new object for each event.
+ This option increases performance but should be used with care,
+ especially in multithreaded environment.
+
+
+
+
+
+
Parameters:
reuseEvents - whether to reuse previously fired event objects
+ instead of creating a new event object for each event.
+
+
+
+
+
+isReuseEvents
+
+boolean isReuseEvents()
+
+
Tests whether the reuseEvents flag is set. If the flag is
+ set to true this class will reuse previously fired events
+ and will not create a new object for each event. This option increases
+ performance but should be used with care, especially in multithreaded
+ environment.
+
+Implements topological order traversal for a directed acyclic graph. A
+ topological sort is a permutation p of the vertices of a graph such
+ that an edge (i,j) implies that i appears before j
+ in p (Skiena 1990, p. 208). See also
+ http://mathworld.wolfram.com/TopologicalSort.html.
+
+
See "Algorithms in Java, Third Edition, Part 5: Graph Algorithms" by
+ Robert Sedgewick and "Data Structures and Algorithms with Object-Oriented
+ Design Patterns in Java" by Bruno R. Preiss for implementation alternatives.
+ The latter can be found online at
+ http://www.brpreiss.com/books/opus5/
+
+
For this iterator to work correctly the graph must be acyclic, and must
+ not be modified during iteration. Currently there are no means to ensure
+ that, nor to fail-fast; the results with cyclic input (including self-loops)
+ or concurrent modifications are undefined. To precheck a graph for cycles,
+ consider using CycleDetector or StrongConnectivityInspector.
+
+
+
+
+
Since:
+
Dec 18, 2004
+
Author:
+
Marden Neubert
+
+
+
+
+
+
+
+
+
+
+Nested Class Summary
+
+
+
+
+
+
Nested classes/interfaces inherited from class org.jgrapht.traverse.CrossComponentIterator
TopologicalOrderIterator(DirectedGraph<V,E> dg)
+
+
+ Creates a new topological order iterator over the directed graph
+ specified, with arbitrary tie-breaking in case of partial order.
+
+
+
TopologicalOrderIterator(DirectedGraph<V,E> dg,
+ java.util.Queue<V> queue)
+
+
+ Creates a new topological order iterator over the directed graph
+ specified, with a user-supplied queue implementation to allow customized
+ control over tie-breaking in case of partial order.
+
+
+
+
+
+
+
+
+
+Method Summary
+
+
+
+protected void
+
encounterVertex(V vertex,
+ E edge)
+
+
+ Update data structures the first time we see a vertex.
+
+
+
+protected void
+
encounterVertexAgain(V vertex,
+ E edge)
+
+
+ Called whenever we re-encounter a vertex.
+
+
+
+protected boolean
+
isConnectedComponentExhausted()
+
+
+ Returns true if there are no more uniterated vertices in the
+ currently iterated connected component; false otherwise.
Creates a new topological order iterator over the directed graph
+ specified, with arbitrary tie-breaking in case of partial order.
+ Traversal will start at one of the graph's sources. See the
+ definition of source at
+ http://mathworld.wolfram.com/Source.html.
+
Creates a new topological order iterator over the directed graph
+ specified, with a user-supplied queue implementation to allow customized
+ control over tie-breaking in case of partial order. Traversal will start
+ at one of the graph's sources. See the definition of source at
+ http://mathworld.wolfram.com/Source.html.
+
+
+
Parameters:
dg - the directed graph to be iterated.
queue - queue to use for tie-break in case of partial order (e.g. a
+ PriorityQueue can be used to break ties according to vertex priority);
+ must be initially empty
+Helper for efficiently representing small sets whose elements are known to be
+ unique by construction, implying we don't need to enforce the uniqueness
+ property in the data structure itself. Use with caution.
+
+
Note that for equals/hashCode, the class implements the Set behavior
+ (unordered), not the list behavior (ordered); the fact that it subclasses
+ ArrayList should be considered an implementation detail.
+
+This class implements a Fibonacci heap data structure. Much of the code in
+ this class is based on the algorithms in the "Introduction to Algorithms"by
+ Cormen, Leiserson, and Rivest in Chapter 21. The amortized running time of
+ most of these methods is O(1), making it a very fast data structure. Several
+ have an actual running time of O(1). removeMin() and delete() have O(log n)
+ amortized running times because they do the heap consolidation. If you
+ attempt to store nodes in this heap with key values of -Infinity
+ (Double.NEGATIVE_INFINITY) the delete() operation may fail to
+ remove the correct element.
+
+
Note that this implementation is not synchronized. If multiple
+ threads access a set concurrently, and at least one of the threads modifies
+ the set, it must be synchronized externally. This is typically
+ accomplished by synchronizing on some object that naturally encapsulates the
+ set.
+
+
This class was originally developed by Nathan Fiedler for the GraphMaker
+ project. It was imported to JGraphT with permission, courtesy of Nathan
+ Fiedler.
+
+
+
+
+
Author:
+
Nathan Fiedler
+
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+
+
FibonacciHeap()
+
+
+ Constructs a FibonacciHeap object that contains no elements.
Deletes a node from the heap given the reference to the node. The trees
+ in the heap will be consolidated, if necessary. This operation may fail
+ to remove the correct element if there are nodes with key value
+ -Infinity.
+
+
Inserts a new data element into the heap. No heap consolidation is
+ performed at this time, the new node is simply inserted into the root
+ list of this heap.
+
+
+Implements a node of the Fibonacci heap. It holds the information necessary
+ for maintaining the structure of the heap. It also holds the reference to the
+ key value (which is used to determine the heap structure).
+
+The ModifiableInteger class wraps a value of the primitive type
+ int in an object, similarly to Integer. An
+ object of type ModifiableInteger contains a single field whose
+ type is int.
+
+
Unlike java.lang.Integer, the int value which the
+ ModifiableInteger represents can be modified. It becomes useful when used
+ together with the collection framework. For example, if you want to have a
+ List of counters. You could use Integer but
+ that would have became wasteful and inefficient if you frequently had to
+ update the counters.
+
+
WARNING: Because instances of this class are mutable, great care must be
+ exercised if used as keys of a Map or as values in a Set in a manner that affects equals comparisons while the
+ instances are keys in the map (or values in the set). For more see
+ documentation of Map and Set.
This constructor is for the use of java.beans.XMLDecoder
+ deserialization. The constructor is marked as 'deprecated' to indicate to
+ the programmer against using it by mistake.
+
+
+
+
+
+ModifiableInteger
+
+public ModifiableInteger(int value)
+
+
Constructs a newly allocated ModifiableInteger object that
+ represents the specified int value.
+
+
+
Parameters:
value - the value to be represented by the
+ ModifiableInteger object.
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+setValue
+
+public void setValue(int value)
+
+
Sets a new value for this modifiable integer.
+
+
+
+
+
+
Parameters:
value - the new value to set.
+
+
+
+
+
+getValue
+
+public int getValue()
+
+
Returns the value of this object, similarly to intValue(). This
+ getter is NOT redundant. It is used for serialization by
+ java.beans.XMLEncoder.
+
+
+
+
+
+
+
Returns:
the value.
+
+
+
+
+
+increment
+
+public void increment()
+
+
Adds one to the value of this modifiable integer.
+
+
+
+
+
+
+
+
+
+
+
+decrement
+
+public void decrement()
+
+
Subtracts one from the value of this modifiable integer.
+
Compares two ModifiableInteger objects numerically.
+
+
+
+
+
+
Parameters:
anotherInteger - the ModifiableInteger to be compared.
+
Returns:
the value 0 if this ModifiableInteger
+ is equal to the argument ModifiableInteger; a value less
+ than 0 if this ModifiableInteger is numerically
+ less than the argument ModifiableInteger; and a value
+ greater than 0 if this ModifiableInteger is
+ numerically greater than the argument ModifiableInteger
+ (signed comparison).
+
+
+
+
+
+compareTo
+
+public int compareTo(java.lang.Object o)
+
+
Compares this ModifiableInteger object to another object. If
+ the object is an ModifiableInteger, this function behaves
+ like compareTo(Integer). Otherwise, it throws a
+ ClassCastException (as ModifiableInteger objects are
+ only comparable to other ModifiableInteger objects).
+
+
+
Specified by:
compareTo in interface java.lang.Comparable
+
+
+
Parameters:
o - the Object to be compared.
+
Returns:
the value 0 if the argument is a
+ ModifiableInteger numerically equal to this
+ ModifiableInteger; a value less than 0 if the
+ argument is a ModifiableInteger numerically greater than
+ this ModifiableInteger; and a value greater than
+ 0 if the argument is a ModifiableInteger numerically
+ less than this ModifiableInteger.
See Also:
Comparable.compareTo(java.lang.Object)
+
+
+
+
+
+doubleValue
+
+public double doubleValue()
+
+
+
Specified by:
doubleValue in class java.lang.Number
+
+
+
See Also:
Number.doubleValue()
+
+
+
+
+
+equals
+
+public boolean equals(java.lang.Object o)
+
+
Compares this object to the specified object. The result is
+ true if and only if the argument is not null and is
+ an ModifiableInteger object that contains the same
+ int value as this object.
+
+
+
Overrides:
equals in class java.lang.Object
+
+
+
Parameters:
o - the object to compare with.
+
Returns:
true if the objects are the same; false
+ otherwise.
+
+
+
+
+
+floatValue
+
+public float floatValue()
+
+
+
Specified by:
floatValue in class java.lang.Number
+
+
+
See Also:
Number.floatValue()
+
+
+
+
+
+hashCode
+
+public int hashCode()
+
+
Returns a hash code for this ModifiableInteger.
+
+
+
Overrides:
hashCode in class java.lang.Object
+
+
+
+
Returns:
a hash code value for this object, equal to the primitive
+ int value represented by this ModifiableInteger
+ object.
+
+
+
+
+
+intValue
+
+public int intValue()
+
+
+
Specified by:
intValue in class java.lang.Number
+
+
+
See Also:
Number.intValue()
+
+
+
+
+
+longValue
+
+public long longValue()
+
+
+
Specified by:
longValue in class java.lang.Number
+
+
+
See Also:
Number.longValue()
+
+
+
+
+
+toInteger
+
+public java.lang.Integer toInteger()
+
+
Returns an Integer object representing this
+ ModifiableInteger's value.
+
+
+
+
+
+
+
Returns:
an Integer representation of the value of this
+ object.
+
+
+
+
+
+toString
+
+public java.lang.String toString()
+
+
Returns a String object representing this
+ ModifiableInteger's value. The value is converted to signed
+ decimal representation and returned as a string, exactly as if the
+ integer value were given as an argument to the Integer.toString(int) method.
+
+
+
Overrides:
toString in class java.lang.Object
+
+
+
+
Returns:
a string representation of the value of this object in
+ base 10.
+Utility class to help implement an iterator/enumerator in which the hasNext()
+ method needs to calculate the next elements ahead of time.
+
+
Many classes which implement an iterator face a common problem: if there
+ is no easy way to calculate hasNext() other than to call getNext(), then they
+ save the result for fetching in the next call to getNext(). This utility
+ helps in doing just that.
+
+
Usage: The new iterator class will hold this class as a member
+ variable and forward the hasNext() and next() to it. When creating an
+ instance of this class, you supply it with a functor that is doing the real
+ job of calculating the next element.
+
+
+ //This class supllies enumeration of integer till 100.
+ public class IteratorExample implements Enumeration{
+ private int counter=0;
+ private PrefetchIterator nextSupplier;
+
+ IteratorExample()
+ {
+ nextSupplier = new PrefetchIterator(new PrefetchIterator.NextElementFunctor(){
+
+ public Object nextElement() throws NoSuchElementException {
+ counter++;
+ if (counter>=100)
+ throw new NoSuchElementException();
+ else
+ return new Integer(counter);
+ }
+
+ });
+ }
+ //forwarding to nextSupplier and return its returned value
+ public boolean hasMoreElements() {
+ return this.nextSupplier.hasMoreElements();
+ }
+ // forwarding to nextSupplier and return its returned value
+ public Object nextElement() {
+ return this.nextSupplier.nextElement();
+ }
+ }
1. Retrieves the saved value or calculates it if it does not exist 2.
+ Changes isGetNextLastResultUpToDate to false. (Because it does not save
+ the NEXT element now; it saves the current one!)
+
If (isGetNextLastResultUpToDate==true) returns true else 1. calculates
+ getNext() and saves it 2. sets isGetNextLastResultUpToDate to true.
+
+
+
Specified by:
hasMoreElements in interface java.util.Enumeration<E>
+
+
+
+
+
+
+
+
+isEnumerationStartedEmpty
+
+public boolean isEnumerationStartedEmpty()
+
+
Tests whether the enumeration started as an empty one. It does not matter
+ if it hasMoreElements() now, only at initialization time. Efficiency: if
+ nextElements(), hasMoreElements() were never used, it activates the
+ hasMoreElements() once. Else it is immediately(O(1))
+
Helper for efficiently representing small sets whose elements are known to be
+ unique by construction, implying we don't need to enforce the uniqueness
+ property in the data structure itself.
Non-graph-specific data structures, algorithms, and utilities used by
+JGraphT.
+
+
+
+
+
+
+JGraphT is a free Java class library that provides mathematical graph-theory
+objects and algorithms. This is an open-source java graph library that supports a
+rich gallery of graphs and is designed to be powerful, extensible and easy to use.
+
The following (jCells|jtElement)Being(Added|Removed) sets are used to
+ prevent bouncing of events between the JGraph and JGraphT listeners. They
+ ensure that their respective add/remove operations are done exactly once.
+ Here is an example of how jCellsBeingAdded is used when an edge is added
+ to a JGraph graph:
+
+
+ 1. First, we add the desired edge to jCellsBeingAdded to indicate
+ that the edge is being inserted internally.
+ 2. Then we invoke the JGraph 'insert' operation.
+ 3. The JGraph listener will detect the newly inserted edge.
+ 4. It checks if the edge is contained in jCellsBeingAdded.
+ 5. If yes,
+ it just removes it and does nothing else.
+ if no,
+ it knows that the edge was inserted externally and performs
+ the insertion.
+ 6. Lastly, we remove the edge from the jCellsBeingAdded.
+
+
+
Step 6 is not always required but we do it anyway as a safeguard
+ against the rare case where the edge to be added is already contained in
+ the graph and thus NO event will be fired. If 6 is not done, a junk edge
+ will remain in the jCellsBeingAdded set.
+
+
The other sets are used in a similar manner to the above. Apparently,
+ All that complication could be eliminated if JGraph and JGraphT had both
+ allowed operations that do not inform listeners...
+
+
+
+
+
+
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/stylesheet.css b/ss2010/gdi2/java/libs/jgrapht/javadoc/stylesheet.css
new file mode 100644
index 00000000..6ea9e516
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/stylesheet.css
@@ -0,0 +1,29 @@
+/* Javadoc style sheet */
+
+/* Define colors, fonts and other style attributes here to override the defaults */
+
+/* Page background color */
+body { background-color: #FFFFFF; color:#000000 }
+
+/* Headings */
+h1 { font-size: 145% }
+
+/* Table colors */
+.TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */
+.TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */
+.TableRowColor { background: #FFFFFF; color:#000000 } /* White */
+
+/* Font used in left-hand frame lists */
+.FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
+.FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
+.FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 }
+
+/* Navigation bar fonts and colors */
+.NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */
+.NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */
+.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;}
+.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;}
+
+.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
+.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000}
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/jgrapht-jdk1.6.jar b/ss2010/gdi2/java/libs/jgrapht/jgrapht-jdk1.6.jar
new file mode 100644
index 00000000..48543766
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/jgrapht-jdk1.6.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/TGGraphLayout.jar b/ss2010/gdi2/java/libs/jgrapht/lib/TGGraphLayout.jar
new file mode 100644
index 00000000..0131e899
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/lib/TGGraphLayout.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/jgraph.jar b/ss2010/gdi2/java/libs/jgrapht/lib/jgraph.jar
new file mode 100644
index 00000000..05c7c9c9
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/lib/jgraph.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/junit.jar b/ss2010/gdi2/java/libs/jgrapht/lib/junit.jar
new file mode 100644
index 00000000..674d71e8
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/lib/junit.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/lib-readme.txt b/ss2010/gdi2/java/libs/jgrapht/lib/lib-readme.txt
new file mode 100644
index 00000000..3f612600
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/lib/lib-readme.txt
@@ -0,0 +1,58 @@
+ ==================
+ Library Folder
+ ==================
+
+This folder contains jar files of libraries used by JGraphT:
+
+-----------------------------------
+jgraph.jar (version 5.8.3.2-Munich)
+-----------------------------------
+
+The runtime library of the JGraph project. The JGraph library is licensed under
+the terms of the GNU Lesser General Public License (LGPL), as with JGraphT.
+
+You can find out more about JGraph and/or download the latest version from
+http://www.jgraph.com. You will also find there the source code of the
+JGraph library.
+
+Note: the JGraph jar in this folder is the build for Java 1.4.
+
+-------------------------
+junit.jar (version 3.8.1)
+-------------------------
+
+The runtime library of the JUnit testing framework. The JUnit library is
+licensed under the terms of the IBM Common Public License.
+
+You can find out more about JUnit and/or download the latest version from
+http://www.junit.org. You will also find there the source code of the JUnit
+library.
+
+--------------------------------
+TGGraphLayout.jar (version 1.22)
+--------------------------------
+
+The layout library of the Touchgraph project. The Touchgraph library is
+licensed under an Apache-style license; see TG-APACHE-LICENSE.txt.
+
+You can find out more about Touchgraph and/or download the latest version from
+http://www.touchgraph.com. You can find the source code of the
+Touchgraph library at http://sourceforge.net/projects/touchgraph.
+
+------------------------
+svn*.jar (version 1.0.0)
+------------------------
+
+The svn ant task from http://subclipse.tigris.org/svnant/svn.html
+
+----------------------------
+xmlunit1.0.jar (version 1.0)
+----------------------------
+
+The runtime library for the XMLUnit extension to JUnit. The XMLUnit
+library is licensed under the terms of the BSD License.
+
+You can find out more about XMLUnit and/or download the latest version
+from http://xmlunit.sourceforge.net. You will also find there the
+source code of the xmlunit library.
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/svnClientAdapter.jar b/ss2010/gdi2/java/libs/jgrapht/lib/svnClientAdapter.jar
new file mode 100644
index 00000000..a6ce6dff
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/lib/svnClientAdapter.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/svnant.jar b/ss2010/gdi2/java/libs/jgrapht/lib/svnant.jar
new file mode 100644
index 00000000..ef9563a7
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/lib/svnant.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/lib/xmlunit1.0.jar b/ss2010/gdi2/java/libs/jgrapht/lib/xmlunit1.0.jar
new file mode 100644
index 00000000..6e8ed584
Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/lib/xmlunit1.0.jar differ
diff --git a/ss2010/gdi2/java/libs/jgrapht/license-LGPL.txt b/ss2010/gdi2/java/libs/jgrapht/license-LGPL.txt
new file mode 100644
index 00000000..b1e3f5a2
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/license-LGPL.txt
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/DirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/DirectedGraph.java
new file mode 100644
index 00000000..b5a3103e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/DirectedGraph.java
@@ -0,0 +1,108 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ------------------
+ * DirectedGraph.java
+ * ------------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ *
+ * $Id: DirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Jul-2003 : Initial revision (BN);
+ * 11-Mar-2004 : Made generic (CH);
+ * 07-May-2006 : Changed from List to Set (JVS);
+ *
+ */
+package org.jgrapht;
+
+import java.util.*;
+
+
+/**
+ * A graph whose all edges are directed. This is the root interface of all
+ * directed graphs.
+ *
+ *
+ *
+ * @author Barak Naveh
+ * @since Jul 14, 2003
+ */
+public interface DirectedGraph
+ extends Graph
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the "in degree" of the specified vertex. An in degree of a vertex
+ * in a directed graph is the number of inward directed edges from that
+ * vertex. See
+ * http://mathworld.wolfram.com/Indegree.html.
+ *
+ * @param vertex vertex whose degree is to be calculated.
+ *
+ * @return the degree of the specified vertex.
+ */
+ public int inDegreeOf(V vertex);
+
+ /**
+ * Returns a set of all edges incoming into the specified vertex.
+ *
+ * @param vertex the vertex for which the list of incoming edges to be
+ * returned.
+ *
+ * @return a set of all edges incoming into the specified vertex.
+ */
+ public Set incomingEdgesOf(V vertex);
+
+ /**
+ * Returns the "out degree" of the specified vertex. An out degree of a
+ * vertex in a directed graph is the number of outward directed edges from
+ * that vertex. See
+ * http://mathworld.wolfram.com/Outdegree.html.
+ *
+ * @param vertex vertex whose degree is to be calculated.
+ *
+ * @return the degree of the specified vertex.
+ */
+ public int outDegreeOf(V vertex);
+
+ /**
+ * Returns a set of all edges outgoing from the specified vertex.
+ *
+ * @param vertex the vertex for which the list of outgoing edges to be
+ * returned.
+ *
+ * @return a set of all edges outgoing from the specified vertex.
+ */
+ public Set outgoingEdgesOf(V vertex);
+}
+
+// End DirectedGraph.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/EdgeFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/EdgeFactory.java
new file mode 100644
index 00000000..5ed0f1d2
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/EdgeFactory.java
@@ -0,0 +1,66 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ----------------
+ * EdgeFactory.java
+ * ----------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ *
+ * $Id: EdgeFactory.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Jul-2003 : Initial revision (BN);
+ * 11-Mar-2004 : Made generic (CH);
+ *
+ */
+package org.jgrapht;
+
+/**
+ * An edge factory used by graphs for creating new edges.
+ *
+ * @author Barak Naveh
+ * @since Jul 14, 2003
+ */
+public interface EdgeFactory
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Creates a new edge whose endpoints are the specified source and target
+ * vertices.
+ *
+ * @param sourceVertex the source vertex.
+ * @param targetVertex the target vertex.
+ *
+ * @return a new edge whose endpoints are the specified source and target
+ * vertices.
+ */
+ public E createEdge(V sourceVertex, V targetVertex);
+}
+
+// End EdgeFactory.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/Graph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/Graph.java
new file mode 100644
index 00000000..6a7657b8
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/Graph.java
@@ -0,0 +1,431 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ----------
+ * Graph.java
+ * ----------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): John V. Sichi
+ * Christian Hammer
+ *
+ * $Id: Graph.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Jul-2003 : Initial revision (BN);
+ * 06-Nov-2003 : Change edge sharing semantics (JVS);
+ * 11-Mar-2004 : Made generic (CH);
+ * 07-May-2006 : Changed from List to Set (JVS);
+ * 28-May-2006 : Moved connectivity info from edge to graph (JVS);
+ *
+ */
+package org.jgrapht;
+
+import java.util.*;
+
+
+/**
+ * The root interface in the graph hierarchy. A mathematical graph-theory graph
+ * object G(V,E) contains a set V of vertices and a set
+ * E of edges. Each edge e=(v1,v2) in E connects vertex v1 to vertex v2.
+ * for more information about graphs and their related definitions see
+ * http://mathworld.wolfram.com/Graph.html.
+ *
+ *
This library generally follows the terminology found at:
+ * http://mathworld.wolfram.com/topics/GraphTheory.html. Implementation of
+ * this interface can provide simple-graphs, multigraphs, pseudographs etc. The
+ * package org.jgrapht.graph provides a gallery of abstract and
+ * concrete graph implementations.
+ *
+ *
This library works best when vertices represent arbitrary objects and
+ * edges represent the relationships between them. Vertex and edge instances may
+ * be shared by more than one graph.
+ *
+ * Through generics, a graph can be typed to specific classes for vertices
+ * V and edges E<T>. Such a graph can contain
+ * vertices of type V and all sub-types and Edges of type
+ * E and all sub-types.
+ *
+ * @author Barak Naveh
+ * @since Jul 14, 2003
+ */
+public interface Graph
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns a set of all edges connecting source vertex to target vertex if
+ * such vertices exist in this graph. If any of the vertices does not exist
+ * or is null, returns null. If both vertices
+ * exist but no edges found, returns an empty set.
+ *
+ *
In undirected graphs, some of the returned edges may have their source
+ * and target vertices in the opposite order. In simple graphs the returned
+ * set is either singleton set or empty set.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return a set of all edges connecting source vertex to target vertex.
+ */
+ public Set getAllEdges(V sourceVertex, V targetVertex);
+
+ /**
+ * Returns an edge connecting source vertex to target vertex if such
+ * vertices and such edge exist in this graph. Otherwise returns
+ * null. If any of the specified vertices is null
+ * returns null
+ *
+ *
In undirected graphs, the returned edge may have its source and target
+ * vertices in the opposite order.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return an edge connecting source vertex to target vertex.
+ */
+ public E getEdge(V sourceVertex, V targetVertex);
+
+ /**
+ * Returns the edge factory using which this graph creates new edges. The
+ * edge factory is defined when the graph is constructed and must not be
+ * modified.
+ *
+ * @return the edge factory using which this graph creates new edges.
+ */
+ public EdgeFactory getEdgeFactory();
+
+ /**
+ * Creates a new edge in this graph, going from the source vertex to the
+ * target vertex, and returns the created edge. Some graphs do not allow
+ * edge-multiplicity. In such cases, if the graph already contains an edge
+ * from the specified source to the specified target, than this method does
+ * not change the graph and returns null.
+ *
+ *
The source and target vertices must already be contained in this
+ * graph. If they are not found in graph IllegalArgumentException is
+ * thrown.
+ *
+ *
This method creates the new edge e using this graph's
+ * EdgeFactory. For the new edge to be added e
+ * must not be equal to any other edge the graph (even if the graph
+ * allows edge-multiplicity). More formally, the graph must not contain any
+ * edge e2 such that e2.equals(e). If such
+ * e2 is found then the newly created edge e is
+ * abandoned, the method leaves this graph unchanged returns
+ * null.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return The newly created edge if added to the graph, otherwise
+ * null.
+ *
+ * @throws IllegalArgumentException if source or target vertices are not
+ * found in the graph.
+ * @throws NullPointerException if any of the specified vertices is
+ * null.
+ *
+ * @see #getEdgeFactory()
+ */
+ public E addEdge(V sourceVertex, V targetVertex);
+
+ /**
+ * Adds the specified edge to this graph, going from the source vertex to
+ * the target vertex. More formally, adds the specified edge,
+ * e, to this graph if this graph contains no edge e2
+ * such that e2.equals(e). If this graph already contains such
+ * an edge, the call leaves this graph unchanged and returns false.
+ * Some graphs do not allow edge-multiplicity. In such cases, if the graph
+ * already contains an edge from the specified source to the specified
+ * target, than this method does not change the graph and returns
+ * false. If the edge was added to the graph, returns
+ * true.
+ *
+ *
The source and target vertices must already be contained in this
+ * graph. If they are not found in graph IllegalArgumentException is
+ * thrown.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ * @param e edge to be added to this graph.
+ *
+ * @return true if this graph did not already contain the specified
+ * edge.
+ *
+ * @throws IllegalArgumentException if source or target vertices are not
+ * found in the graph.
+ * @throws ClassCastException if the specified edge is not assignment
+ * compatible with the class of edges produced by the edge factory of this
+ * graph.
+ * @throws NullPointerException if any of the specified vertices is
+ * null.
+ *
+ * @see #addEdge(Object, Object)
+ * @see #getEdgeFactory()
+ */
+ public boolean addEdge(V sourceVertex, V targetVertex, E e);
+
+ /**
+ * Adds the specified vertex to this graph if not already present. More
+ * formally, adds the specified vertex, v, to this graph if
+ * this graph contains no vertex u such that
+ * u.equals(v). If this graph already contains such vertex, the call
+ * leaves this graph unchanged and returns false. In combination
+ * with the restriction on constructors, this ensures that graphs never
+ * contain duplicate vertices.
+ *
+ * @param v vertex to be added to this graph.
+ *
+ * @return true if this graph did not already contain the specified
+ * vertex.
+ *
+ * @throws NullPointerException if the specified vertex is
+ * null.
+ */
+ public boolean addVertex(V v);
+
+ /**
+ * Returns true if and only if this graph contains an edge going
+ * from the source vertex to the target vertex. In undirected graphs the
+ * same result is obtained when source and target are inverted. If any of
+ * the specified vertices does not exist in the graph, or if is
+ * null, returns false.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return true if this graph contains the specified edge.
+ */
+ public boolean containsEdge(V sourceVertex, V targetVertex);
+
+ /**
+ * Returns true if this graph contains the specified edge. More
+ * formally, returns true if and only if this graph contains an
+ * edge e2 such that e.equals(e2). If the
+ * specified edge is null returns false.
+ *
+ * @param e edge whose presence in this graph is to be tested.
+ *
+ * @return true if this graph contains the specified edge.
+ */
+ public boolean containsEdge(E e);
+
+ /**
+ * Returns true if this graph contains the specified vertex. More
+ * formally, returns true if and only if this graph contains a
+ * vertex u such that u.equals(v). If the
+ * specified vertex is null returns false.
+ *
+ * @param v vertex whose presence in this graph is to be tested.
+ *
+ * @return true if this graph contains the specified vertex.
+ */
+ public boolean containsVertex(V v);
+
+ /**
+ * Returns a set of the edges contained in this graph. The set is backed by
+ * the graph, so changes to the graph are reflected in the set. If the graph
+ * is modified while an iteration over the set is in progress, the results
+ * of the iteration are undefined.
+ *
+ *
The graph implementation may maintain a particular set ordering (e.g.
+ * via {@link java.util.LinkedHashSet}) for deterministic iteration, but
+ * this is not required. It is the responsibility of callers who rely on
+ * this behavior to only use graph implementations which support it.
+ *
+ * @return a set of the edges contained in this graph.
+ */
+ public Set edgeSet();
+
+ /**
+ * Returns a set of all edges touching the specified vertex. If no edges are
+ * touching the specified vertex returns an empty set.
+ *
+ * @param vertex the vertex for which a set of touching edges is to be
+ * returned.
+ *
+ * @return a set of all edges touching the specified vertex.
+ *
+ * @throws IllegalArgumentException if vertex is not found in the graph.
+ * @throws NullPointerException if vertex is null.
+ */
+ public Set edgesOf(V vertex);
+
+ /**
+ * Removes all the edges in this graph that are also contained in the
+ * specified edge collection. After this call returns, this graph will
+ * contain no edges in common with the specified edges. This method will
+ * invoke the {@link #removeEdge(Object)} method.
+ *
+ * @param edges edges to be removed from this graph.
+ *
+ * @return true if this graph changed as a result of the call
+ *
+ * @throws NullPointerException if the specified edge collection is
+ * null.
+ *
+ * @see #removeEdge(Object)
+ * @see #containsEdge(Object)
+ */
+ public boolean removeAllEdges(Collection extends E> edges);
+
+ /**
+ * Removes all the edges going from the specified source vertex to the
+ * specified target vertex, and returns a set of all removed edges. Returns
+ * null if any of the specified vertices does not exist in the
+ * graph. If both vertices exist but no edge is found, returns an empty set.
+ * This method will either invoke the {@link #removeEdge(Object)} method, or
+ * the {@link #removeEdge(Object, Object)} method.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return the removed edges, or null if no either vertex not
+ * part of graph
+ */
+ public Set removeAllEdges(V sourceVertex, V targetVertex);
+
+ /**
+ * Removes all the vertices in this graph that are also contained in the
+ * specified vertex collection. After this call returns, this graph will
+ * contain no vertices in common with the specified vertices. This method
+ * will invoke the {@link #removeVertex(Object)} method.
+ *
+ * @param vertices vertices to be removed from this graph.
+ *
+ * @return true if this graph changed as a result of the call
+ *
+ * @throws NullPointerException if the specified vertex collection is
+ * null.
+ *
+ * @see #removeVertex(Object)
+ * @see #containsVertex(Object)
+ */
+ public boolean removeAllVertices(Collection extends V> vertices);
+
+ /**
+ * Removes an edge going from source vertex to target vertex, if such
+ * vertices and such edge exist in this graph. Returns the edge if removed
+ * or null otherwise.
+ *
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return The removed edge, or null if no edge removed.
+ */
+ public E removeEdge(V sourceVertex, V targetVertex);
+
+ /**
+ * Removes the specified edge from the graph. Removes the specified edge
+ * from this graph if it is present. More formally, removes an edge
+ * e2 such that e2.equals(e), if the graph contains such
+ * edge. Returns true if the graph contained the specified edge.
+ * (The graph will not contain the specified edge once the call returns).
+ *
+ *
If the specified edge is null returns
+ * false.
+ *
+ * @param e edge to be removed from this graph, if present.
+ *
+ * @return true if and only if the graph contained the
+ * specified edge.
+ */
+ public boolean removeEdge(E e);
+
+ /**
+ * Removes the specified vertex from this graph including all its touching
+ * edges if present. More formally, if the graph contains a vertex
+ * u such that u.equals(v), the call removes all edges
+ * that touch u and then removes u itself. If no
+ * such u is found, the call leaves the graph unchanged.
+ * Returns true if the graph contained the specified vertex. (The
+ * graph will not contain the specified vertex once the call returns).
+ *
+ *
If the specified vertex is null returns
+ * false.
+ *
+ * @param v vertex to be removed from this graph, if present.
+ *
+ * @return true if the graph contained the specified vertex;
+ * false otherwise.
+ */
+ public boolean removeVertex(V v);
+
+ /**
+ * Returns a set of the vertices contained in this graph. The set is backed
+ * by the graph, so changes to the graph are reflected in the set. If the
+ * graph is modified while an iteration over the set is in progress, the
+ * results of the iteration are undefined.
+ *
+ *
The graph implementation may maintain a particular set ordering (e.g.
+ * via {@link java.util.LinkedHashSet}) for deterministic iteration, but
+ * this is not required. It is the responsibility of callers who rely on
+ * this behavior to only use graph implementations which support it.
+ *
+ * @return a set view of the vertices contained in this graph.
+ */
+ public Set vertexSet();
+
+ /**
+ * Returns the source vertex of an edge. For an undirected graph, source and
+ * target are distinguishable designations (but without any mathematical
+ * meaning).
+ *
+ * @param e edge of interest
+ *
+ * @return source vertex
+ */
+ public V getEdgeSource(E e);
+
+ /**
+ * Returns the target vertex of an edge. For an undirected graph, source and
+ * target are distinguishable designations (but without any mathematical
+ * meaning).
+ *
+ * @param e edge of interest
+ *
+ * @return target vertex
+ */
+ public V getEdgeTarget(E e);
+
+ /**
+ * Returns the weight assigned to a given edge. Unweighted graphs return 1.0
+ * (as defined by {@link WeightedGraph#DEFAULT_EDGE_WEIGHT}), allowing
+ * weighted-graph algorithms to apply to them where meaningful.
+ *
+ * @param e edge of interest
+ *
+ * @return edge weight
+ *
+ * @see WeightedGraph
+ */
+ public double getEdgeWeight(E e);
+}
+
+// End Graph.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphHelper.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphHelper.java
new file mode 100644
index 00000000..ba04a892
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphHelper.java
@@ -0,0 +1,59 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ----------------
+ * GraphHelper.java
+ * ----------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ * Mikael Hansen
+ *
+ * $Id: GraphHelper.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 10-Jul-2003 : Initial revision (BN);
+ * 06-Nov-2003 : Change edge sharing semantics (JVS);
+ * 11-Mar-2004 : Made generic (CH);
+ * 07-May-2006 : Changed from List to Set (JVS);
+ * 28-May-2006 : Moved connectivity info from edge to graph (JVS);
+ *
+ */
+package org.jgrapht;
+
+/**
+ * A collection of utilities to assist the working with graphs.
+ *
+ * @author Barak Naveh
+ * @since Jul 31, 2003
+ * @deprecated Use {@link Graphs} instead.
+ */
+@Deprecated public abstract class GraphHelper
+ extends Graphs
+{
+}
+
+// End GraphHelper.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphMapping.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphMapping.java
new file mode 100644
index 00000000..1f70b58e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphMapping.java
@@ -0,0 +1,75 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -----------------
+ * GraphMapping.java
+ * -----------------
+ * (C) Copyright 2005-2008, by Assaf Lehr and Contributors.
+ *
+ * Original Author: Assaf Lehr
+ * Contributor(s): John V. Sichi
+ *
+ * Changes
+ * -------
+ */
+package org.jgrapht;
+
+/**
+ * GraphMapping represents a bidirectional mapping between two graphs (called
+ * graph1 and graph2), which allows the caller to obtain the matching vertex or
+ * edge in either direction, from graph1 to graph2, or from graph2 to graph1. It
+ * does not have to always be a complete bidirectional mapping (it could return
+ * null for some lookups).
+ *
+ * @author Assaf Lehr
+ * @since Jul 30, 2005
+ */
+public interface GraphMapping
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Gets the mapped value where the key is vertex
+ *
+ * @param vertex vertex in one of the graphs
+ * @param forward if true, uses mapping from graph1 to graph2; if false, use
+ * mapping from graph2 to graph1
+ *
+ * @return corresponding vertex in other graph, or null if none
+ */
+ public V getVertexCorrespondence(V vertex, boolean forward);
+
+ /**
+ * Gets the mapped value where the key is edge
+ *
+ * @param edge edge in one of the graphs
+ * @param forward if true, uses mapping from graph1 to graph2; if false, use
+ * mapping from graph2 to graph1
+ *
+ * @return corresponding edge in other graph, or null if none
+ */
+ public E getEdgeCorrespondence(E edge, boolean forward);
+}
+
+// End GraphMapping.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphPath.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphPath.java
new file mode 100644
index 00000000..6bcb6715
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/GraphPath.java
@@ -0,0 +1,105 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ----------
+ * Graph.java
+ * ----------
+ * (C) Copyright 2008-2008, by John V. Sichi and Contributors.
+ *
+ * Original Author: John V. Sichi
+ * Contributor(s): -
+ *
+ * $Id: GraphPath.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 1-Jan-2008 : Initial revision (JVS);
+ *
+ */
+package org.jgrapht;
+
+import java.util.*;
+
+
+/**
+ * A GraphPath represents a
+ * path in a {@link Graph}. Note that a path is defined primarily in terms
+ * of edges (rather than vertices) so that multiple edges between the same pair
+ * of vertices can be discriminated.
+ *
+ * @author John Sichi
+ * @since Jan 1, 2008
+ */
+public interface GraphPath
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the graph over which this path is defined. The path may also be
+ * valid with respect to other graphs.
+ *
+ * @return the containing graph
+ */
+ public Graph getGraph();
+
+ /**
+ * Returns the start vertex in the path.
+ *
+ * @return the start vertex
+ */
+ public V getStartVertex();
+
+ /**
+ * Returns the end vertex in the path.
+ *
+ * @return the end vertex
+ */
+ public V getEndVertex();
+
+ /**
+ * Returns the edges making up the path. The first edge in this path is
+ * incident to the start vertex. The last edge is incident to the end
+ * vertex. The vertices along the path can be obtained by traversing from
+ * the start vertex, finding its opposite across the first edge, and then
+ * doing the same successively across subsequent edges; {@link
+ * Graphs#getPathVertexList} provides a convenience method for this.
+ *
+ *
Whether or not the returned edge list is modifiable depends on the
+ * path implementation.
+ *
+ * @return list of edges traversed by the path
+ */
+ public List getEdgeList();
+
+ /**
+ * Returns the weight assigned to the path. Typically, this will be the sum
+ * of the weights of the edge list entries (as defined by the containing
+ * graph), but some path implementations may use other definitions.
+ *
+ * @return the weight of the path
+ */
+ public double getWeight();
+}
+
+// End GraphPath.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/Graphs.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/Graphs.java
new file mode 100644
index 00000000..fe8c204b
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/Graphs.java
@@ -0,0 +1,442 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ----------------
+ * Graphs.java
+ * ----------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ * Mikael Hansen
+ *
+ * $Id: Graphs.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 10-Jul-2003 : Initial revision (BN);
+ * 06-Nov-2003 : Change edge sharing semantics (JVS);
+ * 11-Mar-2004 : Made generic (CH);
+ * 07-May-2006 : Changed from List to Set (JVS);
+ * 28-May-2006 : Moved connectivity info from edge to graph (JVS);
+ *
+ */
+package org.jgrapht;
+
+import java.util.*;
+
+import org.jgrapht.graph.*;
+
+
+/**
+ * A collection of utilities to assist with graph manipulation.
+ *
+ * @author Barak Naveh
+ * @since Jul 31, 2003
+ */
+public abstract class Graphs
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Creates a new edge and adds it to the specified graph similarly to the
+ * {@link Graph#addEdge(Object, Object)} method.
+ *
+ * @param g the graph for which the edge to be added.
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ * @param weight weight of the edge.
+ *
+ * @return The newly created edge if added to the graph, otherwise
+ * null.
+ *
+ * @see Graph#addEdge(Object, Object)
+ */
+ public static E addEdge(
+ Graph g,
+ V sourceVertex,
+ V targetVertex,
+ double weight)
+ {
+ EdgeFactory ef = g.getEdgeFactory();
+ E e = ef.createEdge(sourceVertex, targetVertex);
+
+ // we first create the edge and set the weight to make sure that
+ // listeners will see the correct weight upon addEdge.
+
+ assert (g instanceof WeightedGraph) : g.getClass();
+ ((WeightedGraph) g).setEdgeWeight(e, weight);
+
+ return g.addEdge(sourceVertex, targetVertex, e) ? e : null;
+ }
+
+ /**
+ * Adds the specified source and target vertices to the graph, if not
+ * already included, and creates a new edge and adds it to the specified
+ * graph similarly to the {@link Graph#addEdge(Object, Object)} method.
+ *
+ * @param g the graph for which the specified edge to be added.
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ *
+ * @return The newly created edge if added to the graph, otherwise
+ * null.
+ */
+ public static E addEdgeWithVertices(
+ Graph g,
+ V sourceVertex,
+ V targetVertex)
+ {
+ g.addVertex(sourceVertex);
+ g.addVertex(targetVertex);
+
+ return g.addEdge(sourceVertex, targetVertex);
+ }
+
+ /**
+ * Adds the specified edge to the graph, including its vertices if not
+ * already included.
+ *
+ * @param targetGraph the graph for which the specified edge to be added.
+ * @param sourceGraph the graph in which the specified edge is already
+ * present
+ * @param edge edge to add
+ *
+ * @return true if the target graph did not already contain the
+ * specified edge.
+ */
+ public static boolean addEdgeWithVertices(
+ Graph targetGraph,
+ Graph sourceGraph,
+ E edge)
+ {
+ V sourceVertex = sourceGraph.getEdgeSource(edge);
+ V targetVertex = sourceGraph.getEdgeTarget(edge);
+
+ targetGraph.addVertex(sourceVertex);
+ targetGraph.addVertex(targetVertex);
+
+ return targetGraph.addEdge(sourceVertex, targetVertex, edge);
+ }
+
+ /**
+ * Adds the specified source and target vertices to the graph, if not
+ * already included, and creates a new weighted edge and adds it to the
+ * specified graph similarly to the {@link Graph#addEdge(Object, Object)}
+ * method.
+ *
+ * @param g the graph for which the specified edge to be added.
+ * @param sourceVertex source vertex of the edge.
+ * @param targetVertex target vertex of the edge.
+ * @param weight weight of the edge.
+ *
+ * @return The newly created edge if added to the graph, otherwise
+ * null.
+ */
+ public static E addEdgeWithVertices(
+ Graph g,
+ V sourceVertex,
+ V targetVertex,
+ double weight)
+ {
+ g.addVertex(sourceVertex);
+ g.addVertex(targetVertex);
+
+ return addEdge(g, sourceVertex, targetVertex, weight);
+ }
+
+ /**
+ * Adds all the vertices and all the edges of the specified source graph to
+ * the specified destination graph. First all vertices of the source graph
+ * are added to the destination graph. Then every edge of the source graph
+ * is added to the destination graph. This method returns true
+ * if the destination graph has been modified as a result of this operation,
+ * otherwise it returns false.
+ *
+ *
The behavior of this operation is undefined if any of the specified
+ * graphs is modified while operation is in progress.
+ *
+ * @param destination the graph to which vertices and edges are added.
+ * @param source the graph used as source for vertices and edges to add.
+ *
+ * @return true if and only if the destination graph has been
+ * changed as a result of this operation.
+ */
+ public static boolean addGraph(
+ Graph super V, ? super E> destination,
+ Graph source)
+ {
+ boolean modified = addAllVertices(destination, source.vertexSet());
+ modified |= addAllEdges(destination, source, source.edgeSet());
+
+ return modified;
+ }
+
+ /**
+ * Adds all the vertices and all the edges of the specified source digraph
+ * to the specified destination digraph, reversing all of the edges. If you
+ * want to do this as a linked view of the source graph (rather than by
+ * copying to a destination graph), use {@link EdgeReversedGraph} instead.
+ *
+ *
The behavior of this operation is undefined if any of the specified
+ * graphs is modified while operation is in progress.
+ *
+ * @param destination the graph to which vertices and edges are added.
+ * @param source the graph used as source for vertices and edges to add.
+ *
+ * @see EdgeReversedGraph
+ */
+ public static void addGraphReversed(
+ DirectedGraph super V, ? super E> destination,
+ DirectedGraph source)
+ {
+ addAllVertices(destination, source.vertexSet());
+
+ for (E edge : source.edgeSet()) {
+ destination.addEdge(
+ source.getEdgeTarget(edge),
+ source.getEdgeSource(edge));
+ }
+ }
+
+ /**
+ * Adds a subset of the edges of the specified source graph to the specified
+ * destination graph. The behavior of this operation is undefined if either
+ * of the graphs is modified while the operation is in progress. {@link
+ * #addEdgeWithVertices} is used for the transfer, so source vertexes will
+ * be added automatically to the target graph.
+ *
+ * @param destination the graph to which edges are to be added
+ * @param source the graph used as a source for edges to add
+ * @param edges the edges to be added
+ *
+ * @return true if this graph changed as a result of the call
+ */
+ public static boolean addAllEdges(
+ Graph super V, ? super E> destination,
+ Graph source,
+ Collection extends E> edges)
+ {
+ boolean modified = false;
+
+ for (E e : edges) {
+ V s = source.getEdgeSource(e);
+ V t = source.getEdgeTarget(e);
+ destination.addVertex(s);
+ destination.addVertex(t);
+ modified |= destination.addEdge(s, t, e);
+ }
+
+ return modified;
+ }
+
+ /**
+ * Adds all of the specified vertices to the destination graph. The behavior
+ * of this operation is undefined if the specified vertex collection is
+ * modified while the operation is in progress. This method will invoke the
+ * {@link Graph#addVertex(Object)} method.
+ *
+ * @param destination the graph to which edges are to be added
+ * @param vertices the vertices to be added to the graph.
+ *
+ * @return true if graph changed as a result of the call
+ *
+ * @throws NullPointerException if the specified vertices contains one or
+ * more null vertices, or if the specified vertex collection is
+ * null.
+ *
+ * @see Graph#addVertex(Object)
+ */
+ public static boolean addAllVertices(
+ Graph super V, ? super E> destination,
+ Collection extends V> vertices)
+ {
+ boolean modified = false;
+
+ for (V v : vertices) {
+ modified |= destination.addVertex(v);
+ }
+
+ return modified;
+ }
+
+ /**
+ * Returns a list of vertices that are the neighbors of a specified vertex.
+ * If the graph is a multigraph vertices may appear more than once in the
+ * returned list.
+ *
+ * @param g the graph to look for neighbors in.
+ * @param vertex the vertex to get the neighbors of.
+ *
+ * @return a list of the vertices that are the neighbors of the specified
+ * vertex.
+ */
+ public static List neighborListOf(Graph g,
+ V vertex)
+ {
+ List neighbors = new ArrayList();
+
+ for (E e : g.edgesOf(vertex)) {
+ neighbors.add(getOppositeVertex(g, e, vertex));
+ }
+
+ return neighbors;
+ }
+
+ /**
+ * Returns a list of vertices that are the direct predecessors of a
+ * specified vertex. If the graph is a multigraph, vertices may appear more
+ * than once in the returned list.
+ *
+ * @param g the graph to look for predecessors in.
+ * @param vertex the vertex to get the predecessors of.
+ *
+ * @return a list of the vertices that are the direct predecessors of the
+ * specified vertex.
+ */
+ public static List predecessorListOf(
+ DirectedGraph g,
+ V vertex)
+ {
+ List predecessors = new ArrayList();
+ Set extends E> edges = g.incomingEdgesOf(vertex);
+
+ for (E e : edges) {
+ predecessors.add(getOppositeVertex(g, e, vertex));
+ }
+
+ return predecessors;
+ }
+
+ /**
+ * Returns a list of vertices that are the direct successors of a specified
+ * vertex. If the graph is a multigraph vertices may appear more than once
+ * in the returned list.
+ *
+ * @param g the graph to look for successors in.
+ * @param vertex the vertex to get the successors of.
+ *
+ * @return a list of the vertices that are the direct successors of the
+ * specified vertex.
+ */
+ public static List successorListOf(
+ DirectedGraph g,
+ V vertex)
+ {
+ List successors = new ArrayList();
+ Set extends E> edges = g.outgoingEdgesOf(vertex);
+
+ for (E e : edges) {
+ successors.add(getOppositeVertex(g, e, vertex));
+ }
+
+ return successors;
+ }
+
+ /**
+ * Returns an undirected view of the specified graph. If the specified graph
+ * is directed, returns an undirected view of it. If the specified graph is
+ * already undirected, just returns it.
+ *
+ * @param g the graph for which an undirected view is to be returned.
+ *
+ * @return an undirected view of the specified graph, if it is directed, or
+ * or the specified graph itself if it is already undirected.
+ *
+ * @throws IllegalArgumentException if the graph is neither DirectedGraph
+ * nor UndirectedGraph.
+ *
+ * @see AsUndirectedGraph
+ */
+ public static UndirectedGraph undirectedGraph(Graph g)
+ {
+ if (g instanceof DirectedGraph) {
+ return new AsUndirectedGraph((DirectedGraph) g);
+ } else if (g instanceof UndirectedGraph) {
+ return (UndirectedGraph) g;
+ } else {
+ throw new IllegalArgumentException(
+ "Graph must be either DirectedGraph or UndirectedGraph");
+ }
+ }
+
+ /**
+ * Tests whether an edge is incident to a vertex.
+ *
+ * @param g graph containing e and v
+ * @param e edge in g
+ * @param v vertex in g
+ *
+ * @return true iff e is incident on v
+ */
+ public static boolean testIncidence(Graph g, E e, V v)
+ {
+ return (g.getEdgeSource(e).equals(v))
+ || (g.getEdgeTarget(e).equals(v));
+ }
+
+ /**
+ * Gets the vertex opposite another vertex across an edge.
+ *
+ * @param g graph containing e and v
+ * @param e edge in g
+ * @param v vertex in g
+ *
+ * @return vertex opposite to v across e
+ */
+ public static V getOppositeVertex(Graph g, E e, V v)
+ {
+ V source = g.getEdgeSource(e);
+ V target = g.getEdgeTarget(e);
+ if (v.equals(source)) {
+ return target;
+ } else if (v.equals(target)) {
+ return source;
+ } else {
+ throw new IllegalArgumentException("no such vertex");
+ }
+ }
+
+ /**
+ * Gets the list of vertices visited by a path.
+ *
+ * @param path path of interest
+ *
+ * @return corresponding vertex list
+ */
+ public static List getPathVertexList(GraphPath path)
+ {
+ Graph g = path.getGraph();
+ List list = new ArrayList();
+ V v = path.getStartVertex();
+ list.add(v);
+ for (E e : path.getEdgeList()) {
+ v = getOppositeVertex(g, e, v);
+ list.add(v);
+ }
+ return list;
+ }
+}
+
+// End Graphs.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ListenableGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ListenableGraph.java
new file mode 100644
index 00000000..d8d01f84
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ListenableGraph.java
@@ -0,0 +1,90 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* --------------------
+ * ListenableGraph.java
+ * --------------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ *
+ * $Id: ListenableGraph.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Jul-2003 : Initial revision (BN);
+ * 10-Aug-2003 : Adaptation to new event model (BN);
+ * 11-Mar-2004 : Made generic (CH);
+ *
+ */
+package org.jgrapht;
+
+import org.jgrapht.event.*;
+
+
+/**
+ * A graph that supports listeners on structural change events.
+ *
+ * @author Barak Naveh
+ * @see GraphListener
+ * @see VertexSetListener
+ * @since Jul 20, 2003
+ */
+public interface ListenableGraph
+ extends Graph
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Adds the specified graph listener to this graph, if not already present.
+ *
+ * @param l the listener to be added.
+ */
+ public void addGraphListener(GraphListener l);
+
+ /**
+ * Adds the specified vertex set listener to this graph, if not already
+ * present.
+ *
+ * @param l the listener to be added.
+ */
+ public void addVertexSetListener(VertexSetListener l);
+
+ /**
+ * Removes the specified graph listener from this graph, if present.
+ *
+ * @param l the listener to be removed.
+ */
+ public void removeGraphListener(GraphListener l);
+
+ /**
+ * Removes the specified vertex set listener from this graph, if present.
+ *
+ * @param l the listener to be removed.
+ */
+ public void removeVertexSetListener(VertexSetListener l);
+}
+
+// End ListenableGraph.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/UndirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/UndirectedGraph.java
new file mode 100644
index 00000000..94f65707
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/UndirectedGraph.java
@@ -0,0 +1,70 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* --------------------
+ * UndirectedGraph.java
+ * --------------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ *
+ * $Id: UndirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Jul-2003 : Initial revision (BN);
+ * 11-Mar-2004 : Made generic (CH);
+ *
+ */
+package org.jgrapht;
+
+/**
+ * A graph whose all edges are undirected. This is the root interface of all
+ * undirected graphs.
+ *
+ *
+ *
+ * @author Barak Naveh
+ * @since Jul 14, 2003
+ */
+public interface UndirectedGraph
+ extends Graph
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the degree of the specified vertex. A degree of a vertex in an
+ * undirected graph is the number of edges touching that vertex.
+ *
+ * @param vertex vertex whose degree is to be calculated.
+ *
+ * @return the degree of the specified vertex.
+ */
+ public int degreeOf(V vertex);
+}
+
+// End UndirectedGraph.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/VertexFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/VertexFactory.java
new file mode 100644
index 00000000..274758d7
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/VertexFactory.java
@@ -0,0 +1,63 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ------------------
+ * VertexFactory.java
+ * ------------------
+ * (C) Copyright 2003-2008, by John V. Sichi and Contributors.
+ *
+ * Original Author: John V. Sichi
+ * Contributor(s): Christian Hammer
+ *
+ * $Id: VertexFactory.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 16-Sep-2003 : Initial revision (JVS);
+ * 11-Mar-2004 : Made generic (CH);
+ *
+ */
+package org.jgrapht;
+
+/**
+ * A vertex factory used by graph algorithms for creating new vertices.
+ * Normally, vertices are constructed by user code and added to a graph
+ * explicitly, but algorithms which generate new vertices require a factory.
+ *
+ * @author John V. Sichi
+ * @since Sep 16, 2003
+ */
+public interface VertexFactory
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Creates a new vertex.
+ *
+ * @return the new vertex
+ */
+ public V createVertex();
+}
+
+// End VertexFactory.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/WeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/WeightedGraph.java
new file mode 100644
index 00000000..f2dae25e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/WeightedGraph.java
@@ -0,0 +1,71 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* ------------------
+ * WeightedGraph.java
+ * ------------------
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * Original Author: Barak Naveh
+ * Contributor(s): Christian Hammer
+ *
+ * $Id: WeightedGraph.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Jul-2003 : Initial revision (BN);
+ * 13-Aug-2003 : Included weight methods in Edge interface (BN);
+ * 11-Mar-2004 : Made generic (CH);
+ *
+ */
+package org.jgrapht;
+
+/**
+ * An interface for a graph whose edges have non-uniform weights.
+ *
+ * @author Barak Naveh
+ * @since Jul 23, 2003
+ */
+public interface WeightedGraph
+ extends Graph
+{
+ //~ Static fields/initializers ---------------------------------------------
+
+ /**
+ * The default weight for an edge.
+ */
+ public static double DEFAULT_EDGE_WEIGHT = 1.0;
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Assigns a weight to an edge.
+ *
+ * @param e edge on which to set weight
+ * @param weight new weight for edge
+ */
+ public void setEdgeWeight(E e, double weight);
+}
+
+// End WeightedGraph.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/AbstractPathElement.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/AbstractPathElement.java
new file mode 100644
index 00000000..30a8c56e
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/AbstractPathElement.java
@@ -0,0 +1,202 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * AbstractPathElement.java
+ * -------------------------
+ * (C) Copyright 2006-2008, by France Telecom
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: AbstractPathElement.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jan-2006 : Initial revision (GB);
+ * 14-Jan-2006 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+
+
+/**
+ * A new path is created from a path concatenated to an edge. It's like a linked
+ * list.
+ * The empty path is composed only of one vertex.
+ * In this case the path has no previous path element.
+ * .
+ *
+ *
NOTE jvs 1-Jan-2008: This is an internal data structure for use in
+ * algorithms. For returning paths to callers, use the public {@link GraphPath}
+ * interface instead.
+ *
+ * @author Guillaume Boulmier
+ * @since July 5, 2007
+ */
+abstract class AbstractPathElement
+{
+ //~ Instance fields --------------------------------------------------------
+
+ /**
+ * Number of hops of the path.
+ */
+ protected int nHops;
+
+ /**
+ * Edge reaching the target vertex of the path.
+ */
+ protected E prevEdge;
+
+ /**
+ * Previous path element.
+ */
+ protected AbstractPathElement prevPathElement;
+
+ /**
+ * Target vertex.
+ */
+ private V vertex;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Creates a path element by concatenation of an edge to a path element.
+ *
+ * @param pathElement
+ * @param edge edge reaching the end vertex of the path element created.
+ */
+ protected AbstractPathElement(
+ Graph graph,
+ AbstractPathElement pathElement,
+ E edge)
+ {
+ this.vertex =
+ Graphs.getOppositeVertex(
+ graph,
+ edge,
+ pathElement.getVertex());
+ this.prevEdge = edge;
+ this.prevPathElement = pathElement;
+
+ this.nHops = pathElement.getHopCount() + 1;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param original source to copy from
+ */
+ protected AbstractPathElement(AbstractPathElement original)
+ {
+ this.nHops = original.nHops;
+ this.prevEdge = original.prevEdge;
+ this.prevPathElement = original.prevPathElement;
+ this.vertex = original.vertex;
+ }
+
+ /**
+ * Creates an empty path element.
+ *
+ * @param vertex end vertex of the path element.
+ */
+ protected AbstractPathElement(V vertex)
+ {
+ this.vertex = vertex;
+ this.prevEdge = null;
+ this.prevPathElement = null;
+
+ this.nHops = 0;
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the path as a list of edges.
+ *
+ * @return list of Edge.
+ */
+ public List createEdgeListPath()
+ {
+ List path = new ArrayList();
+ AbstractPathElement pathElement = this;
+
+ // while start vertex is not reached.
+ while (pathElement.getPrevEdge() != null) {
+ path.add(pathElement.getPrevEdge());
+
+ pathElement = pathElement.getPrevPathElement();
+ }
+
+ Collections.reverse(path);
+
+ return path;
+ }
+
+ /**
+ * Returns the number of hops (or number of edges) of the path.
+ *
+ * @return .
+ */
+ public int getHopCount()
+ {
+ return this.nHops;
+ }
+
+ /**
+ * Returns the edge reaching the target vertex of the path.
+ *
+ * @return null if the path is empty.
+ */
+ public E getPrevEdge()
+ {
+ return this.prevEdge;
+ }
+
+ /**
+ * Returns the previous path element.
+ *
+ * @return null is the path is empty.
+ */
+ public AbstractPathElement getPrevPathElement()
+ {
+ return this.prevPathElement;
+ }
+
+ /**
+ * Returns the target vertex of the path.
+ *
+ * @return .
+ */
+ public V getVertex()
+ {
+ return this.vertex;
+ }
+}
+
+// End AbstractPathElement.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/AbstractPathElementList.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/AbstractPathElementList.java
new file mode 100644
index 00000000..1a30c15d
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/AbstractPathElementList.java
@@ -0,0 +1,185 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * AbstractPathElementList.java
+ * -------------------------
+ * (C) Copyright 2007-2008, by France Telecom
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: AbstractPathElementList.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jun-2007 : Initial revision (GB);
+ * 05-Jul-2007 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+
+
+/**
+ * List of paths AbstractPathElement with same target vertex.
+ *
+ * @author Guillaume Boulmier
+ * @since July 5, 2007
+ */
+abstract class AbstractPathElementList>
+ extends AbstractList
+ implements Cloneable
+{
+ //~ Instance fields --------------------------------------------------------
+
+ protected Graph graph;
+
+ /**
+ * Max number of stored paths.
+ */
+ protected int maxSize;
+
+ /**
+ * Stored paths, list of AbstractPathElement.
+ */
+ protected ArrayList pathElements = new ArrayList();
+
+ /**
+ * Target vertex of the paths.
+ */
+ protected V vertex;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Creates a list with an empty path. The list size is 1.
+ *
+ * @param maxSize maximum number of paths the list is able to store.
+ *
+ * @throws NullPointerException if the specified path-element is
+ * null.
+ * @throws IllegalArgumentException if maxSize is negative or
+ * 0.
+ */
+ protected AbstractPathElementList(
+ Graph graph,
+ int maxSize,
+ T pathElement)
+ {
+ if (maxSize <= 0) {
+ throw new IllegalArgumentException("maxSize is negative or 0");
+ }
+ if (pathElement == null) {
+ throw new NullPointerException("pathElement is null");
+ }
+
+ this.graph = graph;
+ this.maxSize = maxSize;
+ this.vertex = pathElement.getVertex();
+
+ this.pathElements.add(pathElement);
+ }
+
+ /**
+ * Creates paths obtained by concatenating the specified edge to the
+ * specified paths.
+ *
+ * @param maxSize maximum number of paths the list is able to store.
+ * @param elementList paths, list of AbstractPathElement.
+ * @param edge edge reaching the end vertex of the created paths.
+ *
+ * @throws NullPointerException if the specified prevPathElementList or edge
+ * is null.
+ * @throws IllegalArgumentException if maxSize is negative or
+ * 0.
+ */
+ protected AbstractPathElementList(
+ Graph graph,
+ int maxSize,
+ AbstractPathElementList elementList,
+ E edge)
+ {
+ if (maxSize <= 0) {
+ throw new IllegalArgumentException("maxSize is negative or 0");
+ }
+ if (elementList == null) {
+ throw new NullPointerException("elementList is null");
+ }
+ if (edge == null) {
+ throw new NullPointerException("edge is null");
+ }
+
+ this.graph = graph;
+ this.maxSize = maxSize;
+ this.vertex =
+ Graphs.getOppositeVertex(graph, edge, elementList.getVertex());
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param original source to copy from
+ */
+ protected AbstractPathElementList(AbstractPathElementList original)
+ {
+ this.graph = original.graph;
+ this.maxSize = original.maxSize;
+ this.pathElements.addAll(original.pathElements);
+ this.vertex = original.vertex;
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns path AbstractPathElement stored at the specified
+ * index.
+ */
+ public T get(int index)
+ {
+ return this.pathElements.get(index);
+ }
+
+ /**
+ * Returns target vertex.
+ */
+ public V getVertex()
+ {
+ return this.vertex;
+ }
+
+ /**
+ * Returns the number of paths stored in the list.
+ */
+ public int size()
+ {
+ return this.pathElements.size();
+ }
+}
+
+// End AbstractPathElementList.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordIterator.java
new file mode 100644
index 00000000..d1cd6e64
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordIterator.java
@@ -0,0 +1,448 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * BellmanFordIterator.java
+ * -------------------------
+ * (C) Copyright 2006-2008, by France Telecom and Contributors.
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: BellmanFordIterator.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jan-2006 : Initial revision (GB);
+ * 14-Jan-2006 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+
+
+/**
+ * Helper class for {@link BellmanFordShortestPath}; not intended for general
+ * use.
+ */
+class BellmanFordIterator
+ implements Iterator>
+{
+ //~ Static fields/initializers ---------------------------------------------
+
+ /**
+ * Error message.
+ */
+ protected final static String NEGATIVE_UNDIRECTED_EDGE =
+ "Negative"
+ + "edge-weights are not allowed in an unidrected graph!";
+
+ //~ Instance fields --------------------------------------------------------
+
+ /**
+ * Graph on which shortest paths are searched.
+ */
+ protected Graph graph;
+
+ /**
+ * Start vertex.
+ */
+ protected V startVertex;
+
+ /**
+ * Vertices whose shortest path cost have been improved during the previous
+ * pass.
+ */
+ private List prevImprovedVertices = new ArrayList();
+
+ private Map> prevVertexData;
+
+ private boolean startVertexEncountered = false;
+
+ /**
+ * Stores the vertices that have been seen during iteration and (optionally)
+ * some additional traversal info regarding each vertex.
+ */
+ private Map> vertexData;
+
+ private double epsilon;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * @param graph
+ * @param startVertex start vertex.
+ * @param epsilon tolerance factor.
+ */
+ protected BellmanFordIterator(
+ Graph graph,
+ V startVertex,
+ double epsilon)
+ {
+ assertBellmanFordIterator(graph, startVertex);
+
+ this.graph = graph;
+ this.startVertex = startVertex;
+ this.epsilon = epsilon;
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the path element of the shortest path with less than
+ * nMaxHops edges between the start vertex and the end vertex.
+ *
+ * @param endVertex end vertex.
+ *
+ * @return .
+ */
+ public BellmanFordPathElement getPathElement(V endVertex)
+ {
+ return getSeenData(endVertex);
+ }
+
+ /**
+ * @return true if at least one path has been improved during
+ * the previous pass, false otherwise.
+ */
+ public boolean hasNext()
+ {
+ if (!this.startVertexEncountered) {
+ encounterStartVertex();
+ }
+
+ return !(this.prevImprovedVertices.isEmpty());
+ }
+
+ /**
+ * Returns the list Collection of vertices whose path has been
+ * improved during the current pass.
+ *
+ * @see java.util.Iterator#next()
+ */
+ public List next()
+ {
+ if (!this.startVertexEncountered) {
+ encounterStartVertex();
+ }
+
+ if (hasNext()) {
+ List improvedVertices = new ArrayList();
+ for (int i = this.prevImprovedVertices.size() - 1; i >= 0; i--) {
+ V vertex = this.prevImprovedVertices.get(i);
+ for (
+ Iterator extends E> iter = edgesOfIterator(vertex);
+ iter.hasNext();)
+ {
+ E edge = iter.next();
+ V oppositeVertex =
+ Graphs.getOppositeVertex(
+ graph,
+ edge,
+ vertex);
+ if (getPathElement(oppositeVertex) != null) {
+ boolean relaxed =
+ relaxVertexAgain(oppositeVertex, edge);
+ if (relaxed) {
+ improvedVertices.add(oppositeVertex);
+ }
+ } else {
+ relaxVertex(oppositeVertex, edge);
+ improvedVertices.add(oppositeVertex);
+ }
+ }
+ }
+
+ savePassData(improvedVertices);
+
+ return improvedVertices;
+ }
+
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * Unsupported
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @param edge
+ *
+ * @throws IllegalArgumentException if the graph is undirected and the
+ * edge-weight is negative.
+ */
+ protected void assertValidEdge(E edge)
+ {
+ if (this.graph instanceof UndirectedGraph) {
+ if (graph.getEdgeWeight(edge) < 0) {
+ throw new IllegalArgumentException(NEGATIVE_UNDIRECTED_EDGE);
+ }
+ }
+ }
+
+ /**
+ * Costs taken into account are the weights stored in Edge
+ * objects.
+ *
+ * @param vertex a vertex which has just been encountered.
+ * @param edge the edge via which the vertex was encountered.
+ *
+ * @return the cost obtained by concatenation.
+ *
+ * @see Graph#getEdgeWeight(E)
+ */
+ protected double calculatePathCost(V vertex, E edge)
+ {
+ V oppositeVertex = Graphs.getOppositeVertex(graph, edge, vertex);
+
+ // we get the data of the previous pass.
+ BellmanFordPathElement oppositePrevData =
+ getPrevSeenData(oppositeVertex);
+
+ double pathCost = graph.getEdgeWeight(edge);
+
+ if (!oppositePrevData.getVertex().equals(this.startVertex)) {
+ // if it's not the start vertex, we add the cost of the previous
+ // pass.
+ pathCost += oppositePrevData.getCost();
+ }
+
+ return pathCost;
+ }
+
+ /**
+ * Returns an iterator to loop over outgoing edges Edge of the
+ * vertex.
+ *
+ * @param vertex
+ *
+ * @return .
+ */
+ protected Iterator edgesOfIterator(V vertex)
+ {
+ if (this.graph instanceof DirectedGraph) {
+ return ((DirectedGraph) this.graph).outgoingEdgesOf(vertex)
+ .iterator();
+ } else {
+ return this.graph.edgesOf(vertex).iterator();
+ }
+ }
+
+ /**
+ * Access the data stored for a seen vertex in the previous pass.
+ *
+ * @param vertex a vertex which has already been seen.
+ *
+ * @return data associated with the seen vertex or null if no
+ * data was associated with the vertex.
+ */
+ protected BellmanFordPathElement getPrevSeenData(V vertex)
+ {
+ return this.prevVertexData.get(vertex);
+ }
+
+ /**
+ * Access the data stored for a seen vertex in the current pass.
+ *
+ * @param vertex a vertex which has already been seen.
+ *
+ * @return data associated with the seen vertex or null if no
+ * data was associated with the vertex.
+ */
+ protected BellmanFordPathElement getSeenData(V vertex)
+ {
+ return this.vertexData.get(vertex);
+ }
+
+ /**
+ * Determines whether a vertex has been seen yet by this traversal.
+ *
+ * @param vertex vertex in question.
+ *
+ * @return true if vertex has already been seen.
+ */
+ protected boolean isSeenVertex(V vertex)
+ {
+ return this.vertexData.containsKey(vertex);
+ }
+
+ /**
+ * @param vertex
+ * @param data
+ *
+ * @return .
+ */
+ protected BellmanFordPathElement putPrevSeenData(
+ V vertex,
+ BellmanFordPathElement data)
+ {
+ if (this.prevVertexData == null) {
+ this.prevVertexData =
+ new HashMap>();
+ }
+
+ return this.prevVertexData.put(vertex, data);
+ }
+
+ /**
+ * Stores iterator-dependent data for a vertex that has been seen during the
+ * current pass.
+ *
+ * @param vertex a vertex which has been seen.
+ * @param data data to be associated with the seen vertex.
+ *
+ * @return previous value associated with specified vertex or
+ * null if no data was associated with the vertex.
+ */
+ protected BellmanFordPathElement putSeenData(
+ V vertex,
+ BellmanFordPathElement data)
+ {
+ if (this.vertexData == null) {
+ this.vertexData = new HashMap>();
+ }
+
+ return this.vertexData.put(vertex, data);
+ }
+
+ private void assertBellmanFordIterator(Graph graph, V startVertex)
+ {
+ if (!(graph.containsVertex(startVertex))) {
+ throw new IllegalArgumentException(
+ "Graph must contain the start vertex!");
+ }
+ }
+
+ /**
+ * The first time we see a vertex, make up a new entry for it.
+ *
+ * @param vertex a vertex which has just been encountered.
+ * @param edge the edge via which the vertex was encountered.
+ * @param cost cost of the created path element.
+ *
+ * @return the new entry.
+ */
+ private BellmanFordPathElement createSeenData(
+ V vertex,
+ E edge,
+ double cost)
+ {
+ BellmanFordPathElement prevPathElement =
+ getPrevSeenData(
+ Graphs.getOppositeVertex(graph, edge, vertex));
+
+ BellmanFordPathElement data =
+ new BellmanFordPathElement(
+ graph,
+ prevPathElement,
+ edge,
+ cost,
+ epsilon);
+
+ return data;
+ }
+
+ private void encounterStartVertex()
+ {
+ BellmanFordPathElement data =
+ new BellmanFordPathElement(
+ this.startVertex,
+ epsilon);
+
+ // first the only vertex considered as improved is the start vertex.
+ this.prevImprovedVertices.add(this.startVertex);
+
+ putSeenData(this.startVertex, data);
+ putPrevSeenData(this.startVertex, data);
+
+ this.startVertexEncountered = true;
+ }
+
+ /**
+ * Upates data first time a vertex is reached by a path.
+ *
+ * @param vertex a vertex which has just been encountered.
+ * @param edge the edge via which the vertex was encountered.
+ */
+ private void relaxVertex(V vertex, E edge)
+ {
+ assertValidEdge(edge);
+
+ double shortestPathCost = calculatePathCost(vertex, edge);
+
+ BellmanFordPathElement data =
+ createSeenData(vertex, edge,
+ shortestPathCost);
+
+ putSeenData(vertex, data);
+ }
+
+ /**
+ * Check if the cost of the best path so far reaching the specified vertex
+ * could be improved if the vertex is reached through the specified edge.
+ *
+ * @param vertex a vertex which has just been encountered.
+ * @param edge the edge via which the vertex was encountered.
+ *
+ * @return true if the cost has been improved,
+ * false otherwise.
+ */
+ private boolean relaxVertexAgain(V vertex, E edge)
+ {
+ assertValidEdge(edge);
+
+ double candidateCost = calculatePathCost(vertex, edge);
+
+ // we get the data of the previous pass.
+ BellmanFordPathElement oppositePrevData =
+ getPrevSeenData(
+ Graphs.getOppositeVertex(graph, edge, vertex));
+
+ BellmanFordPathElement pathElement = getSeenData(vertex);
+ return pathElement.improve(oppositePrevData, edge, candidateCost);
+ }
+
+ private void savePassData(List improvedVertices)
+ {
+ for (V vertex : improvedVertices) {
+ BellmanFordPathElement orig = getSeenData(vertex);
+ BellmanFordPathElement clonedData =
+ new BellmanFordPathElement(orig);
+ putPrevSeenData(vertex, clonedData);
+ }
+
+ this.prevImprovedVertices = improvedVertices;
+ }
+}
+
+// End BellmanFordIterator.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordPathElement.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordPathElement.java
new file mode 100644
index 00000000..61493210
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordPathElement.java
@@ -0,0 +1,150 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * BellmanFordPathElement.java
+ * -------------------------
+ * (C) Copyright 2006-2008, by France Telecom and Contributors.
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: BellmanFordPathElement.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jan-2006 : Initial revision (GB);
+ * 14-Jan-2006 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import org.jgrapht.*;
+
+
+/**
+ * Helper class for {@link BellmanFordShortestPath}; not intended for general
+ * use.
+ */
+final class BellmanFordPathElement
+ extends AbstractPathElement
+{
+ //~ Instance fields --------------------------------------------------------
+
+ private double cost = 0;
+ private double epsilon;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Creates a path element by concatenation of an edge to a path element.
+ *
+ * @param pathElement
+ * @param edge edge reaching the end vertex of the path element created.
+ * @param cost total cost of the created path element.
+ * @param epsilon tolerance factor.
+ */
+ protected BellmanFordPathElement(
+ Graph graph,
+ BellmanFordPathElement pathElement,
+ E edge,
+ double cost,
+ double epsilon)
+ {
+ super(graph, pathElement, edge);
+
+ this.cost = cost;
+ this.epsilon = epsilon;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param original source to copy from
+ */
+ BellmanFordPathElement(BellmanFordPathElement original)
+ {
+ super(original);
+ this.cost = original.cost;
+ this.epsilon = original.epsilon;
+ }
+
+ /**
+ * Creates an empty path element.
+ *
+ * @param vertex end vertex of the path element.
+ * @param epsilon tolerance factor.
+ */
+ protected BellmanFordPathElement(V vertex, double epsilon)
+ {
+ super(vertex);
+
+ this.cost = 0;
+ this.epsilon = epsilon;
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the total cost of the path element.
+ *
+ * @return .
+ */
+ public double getCost()
+ {
+ return this.cost;
+ }
+
+ /**
+ * Returns true if the path has been improved,
+ * false otherwise. We use an "epsilon" precision to check whether
+ * the cost has been improved (because of many roundings, a formula equal to
+ * 0 could unfortunately be evaluated to 10^-14).
+ *
+ * @param candidatePrevPathElement
+ * @param candidateEdge
+ * @param candidateCost
+ *
+ * @return .
+ */
+ protected boolean improve(
+ BellmanFordPathElement candidatePrevPathElement,
+ E candidateEdge,
+ double candidateCost)
+ {
+ // to avoid improvement only due to rounding errors.
+ if (candidateCost < (getCost() - epsilon)) {
+ this.prevPathElement = candidatePrevPathElement;
+ this.prevEdge = candidateEdge;
+ this.cost = candidateCost;
+ this.nHops = candidatePrevPathElement.getHopCount() + 1;
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
+// End BellmanFordPathElement.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordShortestPath.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordShortestPath.java
new file mode 100644
index 00000000..a96639b1
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BellmanFordShortestPath.java
@@ -0,0 +1,239 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * BellmanFordShortestPath.java
+ * -------------------------
+ * (C) Copyright 2006-2008, by France Telecom and Contributors.
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: BellmanFordShortestPath.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jan-2006 : Initial revision (GB);
+ * 14-Jan-2006 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+
+
+/**
+ * Bellman-Ford
+ * algorithm: weights could be negative, paths could be constrained by a
+ * maximum number of edges.
+ */
+public class BellmanFordShortestPath
+{
+ //~ Static fields/initializers ---------------------------------------------
+
+ private static final double DEFAULT_EPSILON = 0.000000001;
+
+ //~ Instance fields --------------------------------------------------------
+
+ /**
+ * Graph on which shortest paths are searched.
+ */
+ protected Graph graph;
+
+ /**
+ * Start vertex.
+ */
+ protected V startVertex;
+
+ private BellmanFordIterator iter;
+
+ /**
+ * Maximum number of edges of the calculated paths.
+ */
+ private int nMaxHops;
+
+ private int passNumber;
+
+ private double epsilon;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Creates an object to calculate shortest paths between the start vertex
+ * and others vertices using the Bellman-Ford algorithm.
+ *
+ * @param graph
+ * @param startVertex
+ */
+ public BellmanFordShortestPath(Graph graph, V startVertex)
+ {
+ this(graph, startVertex, graph.vertexSet().size() - 1);
+ }
+
+ /**
+ * Creates an object to calculate shortest paths between the start vertex
+ * and others vertices using the Bellman-Ford algorithm.
+ *
+ * @param graph
+ * @param startVertex
+ * @param nMaxHops maximum number of edges of the calculated paths.
+ */
+ public BellmanFordShortestPath(
+ Graph graph,
+ V startVertex,
+ int nMaxHops)
+ {
+ this(graph, startVertex, nMaxHops, DEFAULT_EPSILON);
+ }
+
+ /**
+ * Creates an object to calculate shortest paths between the start vertex
+ * and others vertices using the Bellman-Ford algorithm.
+ *
+ * @param graph
+ * @param startVertex
+ * @param nMaxHops maximum number of edges of the calculated paths.
+ * @param epsilon tolerance factor.
+ */
+ public BellmanFordShortestPath(
+ Graph graph,
+ V startVertex,
+ int nMaxHops,
+ double epsilon)
+ {
+ this.startVertex = startVertex;
+ this.nMaxHops = nMaxHops;
+ this.graph = graph;
+ this.passNumber = 1;
+ this.epsilon = epsilon;
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @param endVertex end vertex.
+ *
+ * @return the cost of the shortest path between the start vertex and the
+ * end vertex.
+ */
+ public double getCost(V endVertex)
+ {
+ assertGetPath(endVertex);
+
+ lazyCalculate();
+
+ BellmanFordPathElement pathElement =
+ this.iter.getPathElement(endVertex);
+
+ if (pathElement == null) {
+ return Double.POSITIVE_INFINITY;
+ }
+
+ return pathElement.getCost();
+ }
+
+ /**
+ * @param endVertex end vertex.
+ *
+ * @return list of Edge, or null if no path exists between the
+ * start vertex and the end vertex.
+ */
+ public List getPathEdgeList(V endVertex)
+ {
+ assertGetPath(endVertex);
+
+ lazyCalculate();
+
+ BellmanFordPathElement pathElement =
+ this.iter.getPathElement(endVertex);
+
+ if (pathElement == null) {
+ return null;
+ }
+
+ return pathElement.createEdgeListPath();
+ }
+
+ private void assertGetPath(V endVertex)
+ {
+ if (endVertex.equals(this.startVertex)) {
+ throw new IllegalArgumentException(
+ "The end vertex is the same as the start vertex!");
+ }
+
+ if (!this.graph.containsVertex(endVertex)) {
+ throw new IllegalArgumentException(
+ "Graph must contain the end vertex!");
+ }
+ }
+
+ private void lazyCalculate()
+ {
+ if (this.iter == null) {
+ this.iter =
+ new BellmanFordIterator(
+ this.graph,
+ this.startVertex,
+ epsilon);
+ }
+
+ // at the i-th pass the shortest paths with less (or equal) than i edges
+ // are calculated.
+ for (
+ ;
+ (this.passNumber <= this.nMaxHops) && this.iter.hasNext();
+ this.passNumber++)
+ {
+ this.iter.next();
+ }
+ }
+
+ /**
+ * Convenience method to find the shortest path via a single static method
+ * call. If you need a more advanced search (e.g. limited by hops, or
+ * computation of the path length), use the constructor instead.
+ *
+ * @param graph the graph to be searched
+ * @param startVertex the vertex at which the path should start
+ * @param endVertex the vertex at which the path should end
+ *
+ * @return List of Edges, or null if no path exists
+ */
+ public static List findPathBetween(
+ Graph graph,
+ V startVertex,
+ V endVertex)
+ {
+ BellmanFordShortestPath alg =
+ new BellmanFordShortestPath(
+ graph,
+ startVertex);
+
+ return alg.getPathEdgeList(endVertex);
+ }
+}
+
+// End BellmanFordShortestPath.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BiconnectivityInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BiconnectivityInspector.java
new file mode 100644
index 00000000..3ce83184
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BiconnectivityInspector.java
@@ -0,0 +1,138 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * BiconnectivityInspector.java
+ * -------------------------
+ * (C) Copyright 2007-2008, by France Telecom
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: BiconnectivityInspector.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jun-2007 : Initial revision (GB);
+ * 05-Jul-2007 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+
+
+/**
+ * Inspects a graph for the biconnectivity property. See {@link
+ * BlockCutpointGraph} for more information. A biconnected graph has only one
+ * block (i.e. no cutpoints).
+ *
+ * @author Guillaume Boulmier
+ * @since July 5, 2007
+ */
+public class BiconnectivityInspector
+{
+ //~ Instance fields --------------------------------------------------------
+
+ private BlockCutpointGraph blockCutpointGraph;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Running time = O(m) where m is the number of edges.
+ */
+ public BiconnectivityInspector(UndirectedGraph graph)
+ {
+ super();
+ this.blockCutpointGraph = new BlockCutpointGraph(graph);
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the biconnected vertex-components of the graph.
+ */
+ public Set> getBiconnectedVertexComponents()
+ {
+ Set> biconnectedVertexComponents = new HashSet>();
+ for (
+ Iterator> iter =
+ this.blockCutpointGraph.vertexSet().iterator();
+ iter.hasNext();)
+ {
+ UndirectedGraph subgraph = iter.next();
+ if (!subgraph.edgeSet().isEmpty()) {
+ biconnectedVertexComponents.add(subgraph.vertexSet());
+ }
+ }
+
+ return biconnectedVertexComponents;
+ }
+
+ /**
+ * Returns the biconnected vertex-components containing the vertex. A
+ * biconnected vertex-component contains all the vertices in the component.
+ * A vertex which is not a cutpoint is contained in exactly one component. A
+ * cutpoint is contained is at least 2 components.
+ *
+ * @param vertex
+ *
+ * @return set of all biconnected vertex-components containing the vertex.
+ */
+ public Set> getBiconnectedVertexComponents(V vertex)
+ {
+ Set> vertexComponents = new HashSet>();
+ for (
+ Iterator> iter = getBiconnectedVertexComponents().iterator();
+ iter.hasNext();)
+ {
+ Set vertexComponent = iter.next();
+ if (vertexComponent.contains(vertex)) {
+ vertexComponents.add(vertexComponent);
+ }
+ }
+ return vertexComponents;
+ }
+
+ /**
+ * Returns the cutpoints of the graph.
+ */
+ public Set getCutpoints()
+ {
+ return this.blockCutpointGraph.getCutpoints();
+ }
+
+ /**
+ * Returns true if the graph is biconnected (no cutpoint),
+ * false otherwise.
+ */
+ public boolean isBiconnected()
+ {
+ return this.blockCutpointGraph.vertexSet().size() == 1;
+ }
+}
+
+// End BiconnectivityInspector.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BlockCutpointGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BlockCutpointGraph.java
new file mode 100644
index 00000000..37e7e3f5
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BlockCutpointGraph.java
@@ -0,0 +1,365 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------------
+ * BlockCutpointGraph.java
+ * -------------------------
+ * (C) Copyright 2007-2008, by France Telecom
+ *
+ * Original Author: Guillaume Boulmier and Contributors.
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: BlockCutpointGraph.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 05-Jun-2007 : Initial revision (GB);
+ * 05-Jul-2007 : Added support for generics (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+import org.jgrapht.graph.*;
+
+
+/**
+ * Definition of a block of a
+ * graph in MathWorld.
+ * Definition and lemma taken from the article
+ * Structure-Based Resilience Metrics for Service-Oriented Networks:
+ *
+ *
+ *
Definition 4.5 Let G(V; E) be a connected undirected graph. The
+ * block-cut point graph (BC graph) of G, denoted by GB(VB; EB), is the
+ * bipartite graph defined as follows. (a) VB has one node corresponding to each
+ * block and one node corresponding to each cut point of G. (b) Each edge fx; yg
+ * in EB joins a block node x to a cut point y if the block corresponding to x
+ * contains the cut point node corresponding to y.
+ *
Lemma 4.4 Let G(V; E) be a connected undirected graph. (a) Each
+ * pair of blocks of G share at most one node, and that node is a cutpoint. (b)
+ * The BC graph of G is a tree in which each leaf node corresponds to a block of
+ * G.
+ *
+ *
+ * @author Guillaume Boulmier
+ * @since July 5, 2007
+ */
+public class BlockCutpointGraph
+ extends SimpleGraph, DefaultEdge>
+{
+ //~ Static fields/initializers ---------------------------------------------
+
+ /**
+ */
+ private static final long serialVersionUID = -9101341117013163934L;
+
+ //~ Instance fields --------------------------------------------------------
+
+ private Set cutpoints = new HashSet();
+
+ /**
+ * DFS (Depth-First-Search) tree.
+ */
+ private DirectedGraph dfsTree;
+
+ private UndirectedGraph graph;
+
+ private int numOrder;
+
+ private Deque stack = new ArrayDeque();
+
+ private Map>> vertex2biconnectedSubgraphs =
+ new HashMap>>();
+
+ private Map> vertex2block =
+ new HashMap>();
+
+ private Map vertex2numOrder = new HashMap();
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Running time = O(m) where m is the number of edges.
+ */
+ public BlockCutpointGraph(UndirectedGraph graph)
+ {
+ super(DefaultEdge.class);
+ this.graph = graph;
+
+ this.dfsTree =
+ new SimpleDirectedGraph(
+ DefaultEdge.class);
+ V s = graph.vertexSet().iterator().next();
+ this.dfsTree.addVertex(s);
+ dfsVisit(s, s);
+
+ if (this.dfsTree.edgesOf(s).size() > 1) {
+ this.cutpoints.add(s);
+ } else {
+ this.cutpoints.remove(s);
+ }
+
+ for (Iterator iter = this.cutpoints.iterator(); iter.hasNext();) {
+ V cutpoint = iter.next();
+ UndirectedGraph subgraph =
+ new SimpleGraph(this.graph.getEdgeFactory());
+ subgraph.addVertex(cutpoint);
+ this.vertex2block.put(cutpoint, subgraph);
+ addVertex(subgraph);
+ Set> biconnectedSubgraphs =
+ getBiconnectedSubgraphs(cutpoint);
+ for (
+ Iterator> iterator =
+ biconnectedSubgraphs.iterator();
+ iterator.hasNext();)
+ {
+ UndirectedGraph biconnectedSubgraph = iterator.next();
+ assert (vertexSet().contains(biconnectedSubgraph));
+ addEdge(subgraph, biconnectedSubgraph);
+ }
+ }
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Returns the vertex if vertex is a cutpoint, and otherwise returns the
+ * block (biconnected component) containing the vertex.
+ *
+ * @param vertex vertex in the initial graph.
+ */
+ public UndirectedGraph getBlock(V vertex)
+ {
+ if (!this.graph.vertexSet().contains(vertex)) {
+ throw new IllegalArgumentException("No such vertex in the graph!");
+ }
+
+ return this.vertex2block.get(vertex);
+ }
+
+ /**
+ * Returns the cutpoints of the initial graph.
+ */
+ public Set getCutpoints()
+ {
+ return this.cutpoints;
+ }
+
+ /**
+ * Returns true if the vertex is a cutpoint, false
+ * otherwise.
+ *
+ * @param vertex vertex in the initial graph.
+ */
+ public boolean isCutpoint(V vertex)
+ {
+ if (!this.graph.vertexSet().contains(vertex)) {
+ throw new IllegalArgumentException("No such vertex in the graph!");
+ }
+
+ return this.cutpoints.contains(vertex);
+ }
+
+ private void biconnectedComponentFinished(V s, V n)
+ {
+ this.cutpoints.add(s);
+
+ Set vertexComponent = new HashSet();
+ Set edgeComponent = new HashSet();
+ BCGEdge edge = this.stack.removeLast();
+ while (
+ (getNumOrder(edge.getSource()) >= getNumOrder(n))
+ && !this.stack.isEmpty())
+ {
+ edgeComponent.add(edge);
+
+ vertexComponent.add(edge.getSource());
+ vertexComponent.add(edge.getTarget());
+
+ edge = this.stack.removeLast();
+ }
+ edgeComponent.add(edge);
+ // edgeComponent is an equivalence class.
+
+ vertexComponent.add(edge.getSource());
+ vertexComponent.add(edge.getTarget());
+
+ VertexComponentForbiddenFunction mask =
+ new VertexComponentForbiddenFunction(
+ vertexComponent);
+ UndirectedGraph biconnectedSubgraph =
+ new UndirectedMaskSubgraph(
+ this.graph,
+ mask);
+ for (Iterator iter = vertexComponent.iterator(); iter.hasNext();) {
+ V vertex = iter.next();
+ this.vertex2block.put(vertex, biconnectedSubgraph);
+ getBiconnectedSubgraphs(vertex).add(biconnectedSubgraph);
+ }
+ addVertex(biconnectedSubgraph);
+ }
+
+ private int dfsVisit(V s, V father)
+ {
+ this.numOrder++;
+ int minS = this.numOrder;
+ setNumOrder(s, this.numOrder);
+
+ for (
+ Iterator iter = this.graph.edgesOf(s).iterator();
+ iter.hasNext();)
+ {
+ E edge = iter.next();
+ V n = Graphs.getOppositeVertex(this.graph, edge, s);
+ if (getNumOrder(n) == 0) {
+ this.dfsTree.addVertex(n);
+ BCGEdge dfsEdge = new BCGEdge(s, n);
+ this.dfsTree.addEdge(s, n, dfsEdge);
+
+ this.stack.add(dfsEdge);
+
+ // minimum of the traverse orders of the "attach points" of
+ // the vertex n.
+ int minN = dfsVisit(n, s);
+ minS = Math.min(minN, minS);
+ if (minN >= getNumOrder(s)) {
+ // s is a cutpoint.
+ // it has a son whose "attach depth" is greater or equal.
+ biconnectedComponentFinished(s, n);
+ }
+ } else if ((getNumOrder(n) < getNumOrder(s)) && !n.equals(father)) {
+ BCGEdge backwardEdge = new BCGEdge(s, n);
+ this.stack.add(backwardEdge);
+
+ // n is an "attach point" of s. {s->n} is a backward edge.
+ minS = Math.min(getNumOrder(n), minS);
+ }
+ }
+
+ // minimum of the traverse orders of the "attach points" of
+ // the vertex s.
+ return minS;
+ }
+
+ /**
+ * Returns the biconnected components containing the vertex. A vertex which
+ * is not a cutpoint is contained in exactly one component. A cutpoint is
+ * contained is at least 2 components.
+ *
+ * @param vertex vertex in the initial graph.
+ */
+ private Set> getBiconnectedSubgraphs(V vertex)
+ {
+ Set> biconnectedSubgraphs =
+ this.vertex2biconnectedSubgraphs.get(vertex);
+ if (biconnectedSubgraphs == null) {
+ biconnectedSubgraphs = new HashSet>();
+ this.vertex2biconnectedSubgraphs.put(vertex, biconnectedSubgraphs);
+ }
+ return biconnectedSubgraphs;
+ }
+
+ /**
+ * Returns the traverse order of the vertex in the DFS.
+ */
+ private int getNumOrder(V vertex)
+ {
+ assert (vertex != null);
+
+ Integer numOrder = this.vertex2numOrder.get(vertex);
+ if (numOrder == null) {
+ return 0;
+ } else {
+ return numOrder.intValue();
+ }
+ }
+
+ private void setNumOrder(V vertex, int numOrder)
+ {
+ this.vertex2numOrder.put(vertex, Integer.valueOf(numOrder));
+ }
+
+ //~ Inner Classes ----------------------------------------------------------
+
+ private class BCGEdge
+ extends DefaultEdge
+ {
+ /**
+ */
+ private static final long serialVersionUID = -5115006161815760059L;
+
+ private V source;
+
+ private V target;
+
+ public BCGEdge(V source, V target)
+ {
+ super();
+ this.source = source;
+ this.target = target;
+ }
+
+ public V getSource()
+ {
+ return this.source;
+ }
+
+ public V getTarget()
+ {
+ return this.target;
+ }
+ }
+
+ private class VertexComponentForbiddenFunction
+ implements MaskFunctor
+ {
+ private Set vertexComponent;
+
+ public VertexComponentForbiddenFunction(Set vertexComponent)
+ {
+ this.vertexComponent = vertexComponent;
+ }
+
+ public boolean isEdgeMasked(E edge)
+ {
+ return false;
+ }
+
+ public boolean isVertexMasked(V vertex)
+ {
+ if (this.vertexComponent.contains(vertex)) {
+ // vertex belongs to component then we do not mask it.
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+}
+
+// End BlockCutpointGraph.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BronKerboschCliqueFinder.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BronKerboschCliqueFinder.java
new file mode 100644
index 00000000..e78999ef
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/BronKerboschCliqueFinder.java
@@ -0,0 +1,198 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------
+ * BronKerboschCliqueFinder.java
+ * -------------------
+ * (C) Copyright 2005-2008, by Ewgenij Proschak and Contributors.
+ *
+ * Original Author: Ewgenij Proschak
+ * Contributor(s): John V. Sichi
+ *
+ * $Id: BronKerboschCliqueFinder.java 645 2008-09-30 19:44:48Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 21-Jul-2005 : Initial revision (EP);
+ * 26-Jul-2005 : Cleaned up and checked in (JVS);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+
+
+/**
+ * This class implements Bron-Kerbosch clique detection algorithm as it is
+ * described in [Samudrala R.,Moult J.:A Graph-theoretic Algorithm for
+ * comparative Modeling of Protein Structure; J.Mol. Biol. (1998); vol 279; pp.
+ * 287-302]
+ *
+ * @author Ewgenij Proschak
+ */
+public class BronKerboschCliqueFinder
+{
+ //~ Instance fields --------------------------------------------------------
+
+ private final Graph graph;
+
+ private Collection> cliques;
+
+ //~ Constructors -----------------------------------------------------------
+
+ /**
+ * Creates a new clique finder.
+ *
+ * @param graph the graph in which cliques are to be found; graph must be
+ * simple
+ */
+ public BronKerboschCliqueFinder(Graph graph)
+ {
+ this.graph = graph;
+ }
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Finds all maximal cliques of the graph. A clique is maximal if it is
+ * impossible to enlarge it by adding another vertex from the graph. Note
+ * that a maximal clique is not necessarily the biggest clique in the graph.
+ *
+ * @return Collection of cliques (each of which is represented as a Set of
+ * vertices)
+ */
+ public Collection> getAllMaximalCliques()
+ {
+ // TODO jvs 26-July-2005: assert that graph is simple
+
+ cliques = new ArrayList>();
+ List potential_clique = new ArrayList();
+ List candidates = new ArrayList();
+ List already_found = new ArrayList();
+ candidates.addAll(graph.vertexSet());
+ findCliques(potential_clique, candidates, already_found);
+ return cliques;
+ }
+
+ /**
+ * Finds the biggest maximal cliques of the graph.
+ *
+ * @return Collection of cliques (each of which is represented as a Set of
+ * vertices)
+ */
+ public Collection> getBiggestMaximalCliques()
+ {
+ // first, find all cliques
+ getAllMaximalCliques();
+
+ int maximum = 0;
+ Collection> biggest_cliques = new ArrayList>();
+ for (Set clique : cliques) {
+ if (maximum < clique.size()) {
+ maximum = clique.size();
+ }
+ }
+ for (Set clique : cliques) {
+ if (maximum == clique.size()) {
+ biggest_cliques.add(clique);
+ }
+ }
+ return biggest_cliques;
+ }
+
+ private void findCliques(
+ List potential_clique,
+ List candidates,
+ List already_found)
+ {
+ List candidates_array = new ArrayList(candidates);
+ if (!end(candidates, already_found)) {
+ // for each candidate_node in candidates do
+ for (V candidate : candidates_array) {
+ List new_candidates = new ArrayList();
+ List new_already_found = new ArrayList();
+
+ // move candidate node to potential_clique
+ potential_clique.add(candidate);
+ candidates.remove(candidate);
+
+ // create new_candidates by removing nodes in candidates not
+ // connected to candidate node
+ for (V new_candidate : candidates) {
+ if (graph.containsEdge(candidate, new_candidate)) {
+ new_candidates.add(new_candidate);
+ } // of if
+ } // of for
+
+ // create new_already_found by removing nodes in already_found
+ // not connected to candidate node
+ for (V new_found : already_found) {
+ if (graph.containsEdge(candidate, new_found)) {
+ new_already_found.add(new_found);
+ } // of if
+ } // of for
+
+ // if new_candidates and new_already_found are empty
+ if (new_candidates.isEmpty() && new_already_found.isEmpty()) {
+ // potential_clique is maximal_clique
+ cliques.add(new HashSet(potential_clique));
+ } // of if
+ else {
+ // recursive call
+ findCliques(
+ potential_clique,
+ new_candidates,
+ new_already_found);
+ } // of else
+
+ // move candidate_node from potential_clique to already_found;
+ already_found.add(candidate);
+ potential_clique.remove(candidate);
+ } // of for
+ } // of if
+ }
+
+ private boolean end(List candidates, List already_found)
+ {
+ // if a node in already_found is connected to all nodes in candidates
+ boolean end = false;
+ int edgecounter;
+ for (V found : already_found) {
+ edgecounter = 0;
+ for (V candidate : candidates) {
+ if (graph.containsEdge(found, candidate)) {
+ edgecounter++;
+ } // of if
+ } // of for
+ if (edgecounter == candidates.size()) {
+ end = true;
+ }
+ } // of for
+ return end;
+ }
+}
+
+// End BronKerboschCliqueFinder.java
diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/ChromaticNumber.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/ChromaticNumber.java
new file mode 100644
index 00000000..00dbee15
--- /dev/null
+++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/ChromaticNumber.java
@@ -0,0 +1,128 @@
+/* ==========================================
+ * JGraphT : a free Java graph-theory library
+ * ==========================================
+ *
+ * Project Info: http://jgrapht.sourceforge.net/
+ * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
+ *
+ * (C) Copyright 2003-2008, by Barak Naveh and Contributors.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+/* -------------------
+ * ChromaticNumber.java
+ * -------------------
+ * (C) Copyright 2008-2008, by Andrew Newell and Contributors.
+ *
+ * Original Author: Andrew Newell
+ * Contributor(s): -
+ *
+ * $Id: ChromaticNumber.java 680 2009-05-25 05:55:31Z perfecthash $
+ *
+ * Changes
+ * -------
+ * 24-Dec-2008 : Initial revision (AN);
+ *
+ */
+package org.jgrapht.alg;
+
+import java.util.*;
+
+import org.jgrapht.*;
+import org.jgrapht.alg.util.*;
+import org.jgrapht.graph.*;
+
+
+/**
+ * Allows the
+ * chromatic number of a graph to be calculated. This is the minimal number
+ * of colors needed to color each vertex such that no two adjacent vertices
+ * share the same color. This algorithm will not find the true chromatic number,
+ * since this is an NP-complete problem. So, a greedy algorithm will find an
+ * approximate chromatic number.
+ *
+ * @author Andrew Newell
+ * @since Dec 21, 2008
+ */
+public abstract class ChromaticNumber
+{
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Finds the number of colors required for a greedy coloring of the graph.
+ *
+ * @param g an undirected graph to find the chromatic number of
+ *
+ * @return integer the approximate chromatic number from the greedy
+ * algorithm
+ */
+ public static int findGreedyChromaticNumber(UndirectedGraph g)
+ {
+ // A copy of the graph is made, so that elements of the graph may be
+ // removed to carry out the algorithm
+ UndirectedGraph sg = new UndirectedSubgraph(g, null, null);
+
+ // The Vertices will be sorted in decreasing order by degree, so that
+ // higher degree vertices have priority to be colored first
+ VertexDegreeComparator comp =
+ new VertexDegreeComparator