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 + + + + +


JGraphT  0.7.3
+  

  + +

Released: September, 2008

+ +

Written by Barak Naveh (barak_naveh@users.sourceforge.net) + and Contributors.

+ +

(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.jarthe compiled JGraphT library for JRE 1.6
README.htmlthis file
licence-LGPL.txtGNU 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.MFmeta information for use as an OSGi plug-in (e.g. within an Eclipse RCP application)
build.propertiesdescribes content of OSGi plug-in export
build.xmlant 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.

    +
  • +
+ +

Reading the change history is always + recommended.

+ +

Documentation

+ +

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.
  • +
+ +

Online Resources

+ +

The JGraphT website is at: http://www.jgrapht.org. You can + use this site to:

+ +
    +
  • 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.

+ +

Regards,
+ Barak Naveh
+ JGraphT Project Creator

+ John Sichi
+ JGraphT Project Administrator

+ +

 

+
+ + + + + + + + + +
Valid HTML 4.01!© Copyright 2003-2008, by Barak + Naveh and Contributors. All rights reserved. +Get JGraphT at SourceForge.net. Fast, secure and Free Open Source software downloads +

+ + 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 +
+ + + + + +
AbstractBaseGraph +
+AbstractGraph +
+AbstractGraphIterator +
+ArrayUnenforcedSet +
+AsUndirectedGraph +
+AsUnweightedDirectedGraph +
+AsUnweightedGraph +
+AsWeightedGraph +
+BellmanFordShortestPath +
+BiconnectivityInspector +
+BlockCutpointGraph +
+BreadthFirstIterator +
+BronKerboschCliqueFinder +
+ChromaticNumber +
+ClassBasedEdgeFactory +
+ClassBasedVertexFactory +
+ClosestFirstIterator +
+CompleteBipartiteGraphGenerator +
+CompleteGraphDemo +
+CompleteGraphGenerator +
+ConnectedComponentTraversalEvent +
+ConnectivityInspector +
+CrossComponentIterator +
+CrossComponentIterator.VisitColor +
+CycleDetector +
+DefaultDirectedGraph +
+DefaultDirectedWeightedGraph +
+DefaultEdge +
+DefaultGraphMapping +
+DefaultListenableGraph +
+DefaultWeightedEdge +
+DepthFirstIterator +
+DijkstraShortestPath +
+DirectedGraph +
+DirectedGraphUnion +
+DirectedMaskSubgraph +
+DirectedMultigraph +
+DirectedNeighborIndex +
+DirectedPseudograph +
+DirectedSubgraph +
+DirectedWeightedMultigraph +
+DirectedWeightedSubgraph +
+DOTExporter +
+EdgeFactory +
+EdgeNameProvider +
+EdgeReversedGraph +
+EdgeSetFactory +
+EdgeTraversalEvent +
+EdmondsKarpMaximumFlow +
+EmptyGraphGenerator +
+EulerianCircuit +
+FibonacciHeap +
+FibonacciHeapNode +
+FloydWarshallShortestPaths +
+GmlExporter +
+Graph +
+GraphChangeEvent +
+GraphDelegator +
+GraphEdgeChangeEvent +
+GraphGenerator +
+GraphHelper +
+GraphIterator +
+GraphListener +
+GraphMapping +
+GraphMLExporter +
+GraphPath +
+GraphPathImpl +
+Graphs +
+GraphUnion +
+GraphVertexChangeEvent +
+HamiltonianCycle +
+HelloJGraphT +
+HyperCubeGraphGenerator +
+IntegerEdgeNameProvider +
+IntegerNameProvider +
+JGraphAdapterDemo +
+JGraphModelAdapter +
+JGraphModelAdapter.CellFactory +
+JGraphModelAdapter.DefaultCellFactory +
+KShortestPaths +
+LinearGraphGenerator +
+ListenableDirectedGraph +
+ListenableDirectedWeightedGraph +
+ListenableGraph +
+ListenableUndirectedGraph +
+ListenableUndirectedWeightedGraph +
+MaskFunctor +
+MaskSubgraph +
+MathUtil +
+MatrixExporter +
+ModifiableInteger +
+Multigraph +
+NeighborIndex +
+ParanoidGraph +
+PerformanceDemo +
+PrefetchIterator +
+PrefetchIterator.NextElementFunctor +
+Pseudograph +
+RandomGraphGenerator +
+RandomGraphGenerator.EdgeTopologyFactory +
+RingGraphGenerator +
+ScaleFreeGraphGenerator +
+SimpleDirectedGraph +
+SimpleDirectedWeightedGraph +
+SimpleGraph +
+SimpleWeightedGraph +
+StarGraphGenerator +
+StringEdgeNameProvider +
+StringNameProvider +
+StrongConnectivityInspector +
+Subgraph +
+TopologicalOrderIterator +
+TransitiveClosure +
+TraversalListener +
+TraversalListenerAdapter +
+TypeUtil +
+UndirectedGraph +
+UndirectedGraphUnion +
+UndirectedMaskSubgraph +
+UndirectedSubgraph +
+UndirectedWeightedSubgraph +
+UnmodifiableDirectedGraph +
+UnmodifiableGraph +
+UnmodifiableUndirectedGraph +
+VertexCovers +
+VertexDegreeComparator +
+VertexFactory +
+VertexNameProvider +
+VertexSetListener +
+VertexTraversalEvent +
+VisioExporter +
+WeightCombiner +
+WeightedGraph +
+WeightedMultigraph +
+WeightedPseudograph +
+WheelGraphGenerator +
+
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/allclasses-noframe.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/allclasses-noframe.html new file mode 100644 index 00000000..df52fcf3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/allclasses-noframe.html @@ -0,0 +1,301 @@ + + + + + + +All Classes (JGraphT : a free Java graph library) + + + + + + + + + + + +All Classes +
+ + + + + +
AbstractBaseGraph +
+AbstractGraph +
+AbstractGraphIterator +
+ArrayUnenforcedSet +
+AsUndirectedGraph +
+AsUnweightedDirectedGraph +
+AsUnweightedGraph +
+AsWeightedGraph +
+BellmanFordShortestPath +
+BiconnectivityInspector +
+BlockCutpointGraph +
+BreadthFirstIterator +
+BronKerboschCliqueFinder +
+ChromaticNumber +
+ClassBasedEdgeFactory +
+ClassBasedVertexFactory +
+ClosestFirstIterator +
+CompleteBipartiteGraphGenerator +
+CompleteGraphDemo +
+CompleteGraphGenerator +
+ConnectedComponentTraversalEvent +
+ConnectivityInspector +
+CrossComponentIterator +
+CrossComponentIterator.VisitColor +
+CycleDetector +
+DefaultDirectedGraph +
+DefaultDirectedWeightedGraph +
+DefaultEdge +
+DefaultGraphMapping +
+DefaultListenableGraph +
+DefaultWeightedEdge +
+DepthFirstIterator +
+DijkstraShortestPath +
+DirectedGraph +
+DirectedGraphUnion +
+DirectedMaskSubgraph +
+DirectedMultigraph +
+DirectedNeighborIndex +
+DirectedPseudograph +
+DirectedSubgraph +
+DirectedWeightedMultigraph +
+DirectedWeightedSubgraph +
+DOTExporter +
+EdgeFactory +
+EdgeNameProvider +
+EdgeReversedGraph +
+EdgeSetFactory +
+EdgeTraversalEvent +
+EdmondsKarpMaximumFlow +
+EmptyGraphGenerator +
+EulerianCircuit +
+FibonacciHeap +
+FibonacciHeapNode +
+FloydWarshallShortestPaths +
+GmlExporter +
+Graph +
+GraphChangeEvent +
+GraphDelegator +
+GraphEdgeChangeEvent +
+GraphGenerator +
+GraphHelper +
+GraphIterator +
+GraphListener +
+GraphMapping +
+GraphMLExporter +
+GraphPath +
+GraphPathImpl +
+Graphs +
+GraphUnion +
+GraphVertexChangeEvent +
+HamiltonianCycle +
+HelloJGraphT +
+HyperCubeGraphGenerator +
+IntegerEdgeNameProvider +
+IntegerNameProvider +
+JGraphAdapterDemo +
+JGraphModelAdapter +
+JGraphModelAdapter.CellFactory +
+JGraphModelAdapter.DefaultCellFactory +
+KShortestPaths +
+LinearGraphGenerator +
+ListenableDirectedGraph +
+ListenableDirectedWeightedGraph +
+ListenableGraph +
+ListenableUndirectedGraph +
+ListenableUndirectedWeightedGraph +
+MaskFunctor +
+MaskSubgraph +
+MathUtil +
+MatrixExporter +
+ModifiableInteger +
+Multigraph +
+NeighborIndex +
+ParanoidGraph +
+PerformanceDemo +
+PrefetchIterator +
+PrefetchIterator.NextElementFunctor +
+Pseudograph +
+RandomGraphGenerator +
+RandomGraphGenerator.EdgeTopologyFactory +
+RingGraphGenerator +
+ScaleFreeGraphGenerator +
+SimpleDirectedGraph +
+SimpleDirectedWeightedGraph +
+SimpleGraph +
+SimpleWeightedGraph +
+StarGraphGenerator +
+StringEdgeNameProvider +
+StringNameProvider +
+StrongConnectivityInspector +
+Subgraph +
+TopologicalOrderIterator +
+TransitiveClosure +
+TraversalListener +
+TraversalListenerAdapter +
+TypeUtil +
+UndirectedGraph +
+UndirectedGraphUnion +
+UndirectedMaskSubgraph +
+UndirectedSubgraph +
+UndirectedWeightedSubgraph +
+UnmodifiableDirectedGraph +
+UnmodifiableGraph +
+UnmodifiableUndirectedGraph +
+VertexCovers +
+VertexDegreeComparator +
+VertexFactory +
+VertexNameProvider +
+VertexSetListener +
+VertexTraversalEvent +
+VisioExporter +
+WeightCombiner +
+WeightedGraph +
+WeightedMultigraph +
+WeightedPseudograph +
+WheelGraphGenerator +
+
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/constant-values.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/constant-values.html new file mode 100644 index 00000000..665a4aca --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/constant-values.html @@ -0,0 +1,346 @@ + + + + + + +Constant Field Values (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Constant Field Values

+
+
+Contents + + + + + + +
+org.jgrapht.*
+ +

+ + + + + + + + + + + + +
org.jgrapht.WeightedGraph<V,E>
+public static final doubleDEFAULT_EDGE_WEIGHT1.0
+ +

+ +

+ + + + + + + + + + + + +
org.jgrapht.alg.EdmondsKarpMaximumFlow<V,E>
+public static final doubleDEFAULT_EPSILON1.0E-9
+ +

+ +

+ + + + + + + + + + + + + + + + + +
org.jgrapht.event.ConnectedComponentTraversalEvent
+public static final intCONNECTED_COMPONENT_FINISHED32
+public static final intCONNECTED_COMPONENT_STARTED31
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
org.jgrapht.event.GraphEdgeChangeEvent<V,E>
+public static final intBEFORE_EDGE_ADDED21
+public static final intBEFORE_EDGE_REMOVED22
+public static final intEDGE_ADDED23
+public static final intEDGE_REMOVED24
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
org.jgrapht.event.GraphVertexChangeEvent<V>
+public static final intBEFORE_VERTEX_ADDED11
+public static final intBEFORE_VERTEX_REMOVED12
+public static final intVERTEX_ADDED13
+public static final intVERTEX_REMOVED14
+ +

+ +

+ + + + + + + + + + + + + + + + + +
org.jgrapht.generate.LinearGraphGenerator<V,E>
+public static final java.lang.StringEND_VERTEX"End Vertex"
+public static final java.lang.StringSTART_VERTEX"Start Vertex"
+ +

+ +

+ + + + + + + + + + + + +
org.jgrapht.generate.StarGraphGenerator<V,E>
+public static final java.lang.StringCENTER_VERTEX"Center Vertex"
+ +

+ +

+ + + + + + + + + + + + +
org.jgrapht.generate.WheelGraphGenerator<V,E>
+public static final java.lang.StringHUB_VERTEX"Hub Vertex"
+ +

+ +

+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/deprecated-list.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/deprecated-list.html new file mode 100644 index 00000000..fdfb3ae8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/deprecated-list.html @@ -0,0 +1,174 @@ + + + + + + +Deprecated List (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Deprecated API

+
+
+Contents + + + + + + + + + +
+Deprecated Classes
org.jgrapht.GraphHelper +
+          Use Graphs instead. 
+  +

+ + + + + + + + +
+Deprecated Constructors
org.jgrapht.util.ModifiableInteger() +
+          not really deprecated, just marked so to avoid mistaken use. 
+  +

+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/help-doc.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/help-doc.html new file mode 100644 index 00000000..c9abec52 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/help-doc.html @@ -0,0 +1,217 @@ + + + + + + +API Help (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+How This API Document Is Organized

+
+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. +

+

+Constant Field Values

+The Constant Field Values page lists the static final fields and their values. +

+ + +This help file applies to API documentation generated using the standard doclet. + +
+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/index-all.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/index-all.html new file mode 100644 index 00000000..f891f098 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/index-all.html @@ -0,0 +1,2485 @@ + + + + + + +Index (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +A B C D E F G H I J K L M N O P R S T U V W
+

+A

+
+
AbstractBaseGraph<V,E> - Class in org.jgrapht.graph
The most general implementation of the Graph interface.
AbstractBaseGraph(EdgeFactory<V, E>, boolean, boolean) - +Constructor for class org.jgrapht.graph.AbstractBaseGraph +
Construct a new pseudograph. +
AbstractGraph<V,E> - Class in org.jgrapht.graph
A skeletal implementation of the Graph interface, to minimize the + effort required to implement graph interfaces.
AbstractGraph() - +Constructor for class org.jgrapht.graph.AbstractGraph +
Construct a new empty graph object. +
AbstractGraphIterator<V,E> - Class in org.jgrapht.traverse
An empty implementation of a graph iterator to minimize the effort required + to implement graph iterators.
AbstractGraphIterator() - +Constructor for class org.jgrapht.traverse.AbstractGraphIterator +
  +
addAllEdges(Graph<? super V, ? super E>, Graph<V, E>, Collection<? extends E>) - +Static method in class org.jgrapht.Graphs +
Adds a subset of the edges of the specified source graph to the specified + destination graph. +
addAllVertices(Graph<? super V, ? super E>, Collection<? extends V>) - +Static method in class org.jgrapht.Graphs +
Adds all of the specified vertices to the destination graph. +
addEdge(V, V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
addEdge(V, V) - +Method in interface org.jgrapht.Graph +
Creates a new edge in this graph, going from the source vertex to the + target vertex, and returns the created edge. +
addEdge(V, V, E) - +Method in interface org.jgrapht.Graph +
Adds the specified edge to this graph, going from the source vertex to + the target vertex. +
addEdge(V, V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
addEdge(V, V) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
addEdge(V, V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
addEdge(V, V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
addEdge(V, V) - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
addEdge(V, V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.ParanoidGraph +
  +
addEdge(V, V) - +Method in class org.jgrapht.graph.Subgraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.Subgraph +
  +
addEdge(V, V) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
addEdge(V, V, E) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
addEdge(Graph<V, E>, V, V, double) - +Static method in class org.jgrapht.Graphs +
Creates a new edge and adds it to the specified graph similarly to the + Graph.addEdge(Object, Object) method. +
addEdgeWithVertices(Graph<V, E>, V, V) - +Static method in class org.jgrapht.Graphs +
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. +
addEdgeWithVertices(Graph<V, E>, Graph<V, E>, E) - +Static method in class org.jgrapht.Graphs +
Adds the specified edge to the graph, including its vertices if not + already included. +
addEdgeWithVertices(Graph<V, E>, V, V, double) - +Static method in class org.jgrapht.Graphs +
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. +
addGraph(Graph<? super V, ? super E>, Graph<V, E>) - +Static method in class org.jgrapht.Graphs +
Adds all the vertices and all the edges of the specified source graph to + the specified destination graph. +
addGraphListener(GraphListener<V, E>) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
addGraphListener(GraphListener<V, E>) - +Method in interface org.jgrapht.ListenableGraph +
Adds the specified graph listener to this graph, if not already present. +
addGraphReversed(DirectedGraph<? super V, ? super E>, DirectedGraph<V, E>) - +Static method in class org.jgrapht.Graphs +
Adds all the vertices and all the edges of the specified source digraph + to the specified destination digraph, reversing all of the edges. +
addTraversalListener(TraversalListener<V, E>) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Adds the specified traversal listener to this iterator. +
addTraversalListener(TraversalListener<V, E>) - +Method in interface org.jgrapht.traverse.GraphIterator +
Adds the specified traversal listener to this iterator. +
addVertex(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
addVertex(V) - +Method in interface org.jgrapht.Graph +
Adds the specified vertex to this graph if not already present. +
addVertex(V) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
addVertex(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
addVertex(V) - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
addVertex(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
addVertex(V) - +Method in class org.jgrapht.graph.ParanoidGraph +
  +
addVertex(V) - +Method in class org.jgrapht.graph.Subgraph +
Adds the specified vertex to this subgraph. +
addVertex(V) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
addVertexSetListener(VertexSetListener<V>) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
addVertexSetListener(VertexSetListener<V>) - +Method in interface org.jgrapht.ListenableGraph +
Adds the specified vertex set listener to this graph, if not already + present. +
ArrayUnenforcedSet<E> - Class in org.jgrapht.util
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.
ArrayUnenforcedSet() - +Constructor for class org.jgrapht.util.ArrayUnenforcedSet +
  +
ArrayUnenforcedSet(Collection<? extends E>) - +Constructor for class org.jgrapht.util.ArrayUnenforcedSet +
  +
ArrayUnenforcedSet(int) - +Constructor for class org.jgrapht.util.ArrayUnenforcedSet +
  +
assertVertexExist(V) - +Method in class org.jgrapht.graph.AbstractGraph +
Ensures that the specified vertex exists in this graph, or else throws + exception. +
AsUndirectedGraph<V,E> - Class in org.jgrapht.graph
An undirected view of the backing directed graph specified in the + constructor.
AsUndirectedGraph(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.AsUndirectedGraph +
Constructor for AsUndirectedGraph. +
AsUnweightedDirectedGraph<V,E> - Class in org.jgrapht.graph
An unweighted view of the backing weighted graph specified in the + constructor.
AsUnweightedDirectedGraph(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.AsUnweightedDirectedGraph +
Constructor for AsUnweightedGraph. +
AsUnweightedGraph<V,E> - Class in org.jgrapht.graph
An unweighted view of the backing weighted graph specified in the + constructor.
AsUnweightedGraph(Graph<V, E>) - +Constructor for class org.jgrapht.graph.AsUnweightedGraph +
Constructor for AsUnweightedGraph. +
AsWeightedGraph<V,E> - Class in org.jgrapht.graph
A weighted view of the backing graph specified in the constructor.
AsWeightedGraph(Graph<V, E>, Map<E, Double>) - +Constructor for class org.jgrapht.graph.AsWeightedGraph +
Constructor for AsWeightedGraph. +
+
+

+B

+
+
BEFORE_EDGE_ADDED - +Static variable in class org.jgrapht.event.GraphEdgeChangeEvent +
Before edge added event. +
BEFORE_EDGE_REMOVED - +Static variable in class org.jgrapht.event.GraphEdgeChangeEvent +
Before edge removed event. +
BEFORE_VERTEX_ADDED - +Static variable in class org.jgrapht.event.GraphVertexChangeEvent +
Before vertex added event. +
BEFORE_VERTEX_REMOVED - +Static variable in class org.jgrapht.event.GraphVertexChangeEvent +
Before vertex removed event. +
BellmanFordShortestPath<V,E> - Class in org.jgrapht.alg
Bellman-Ford + algorithm: weights could be negative, paths could be constrained by a + maximum number of edges.
BellmanFordShortestPath(Graph<V, E>, V) - +Constructor for class org.jgrapht.alg.BellmanFordShortestPath +
Creates an object to calculate shortest paths between the start vertex + and others vertices using the Bellman-Ford algorithm. +
BellmanFordShortestPath(Graph<V, E>, V, int) - +Constructor for class org.jgrapht.alg.BellmanFordShortestPath +
Creates an object to calculate shortest paths between the start vertex + and others vertices using the Bellman-Ford algorithm. +
BellmanFordShortestPath(Graph<V, E>, V, int, double) - +Constructor for class org.jgrapht.alg.BellmanFordShortestPath +
Creates an object to calculate shortest paths between the start vertex + and others vertices using the Bellman-Ford algorithm. +
BiconnectivityInspector<V,E> - Class in org.jgrapht.alg
Inspects a graph for the biconnectivity property.
BiconnectivityInspector(UndirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.BiconnectivityInspector +
Running time = O(m) where m is the number of edges. +
BlockCutpointGraph<V,E> - Class in org.jgrapht.alg
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.
BlockCutpointGraph(UndirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.BlockCutpointGraph +
Running time = O(m) where m is the number of edges. +
BreadthFirstIterator<V,E> - Class in org.jgrapht.traverse
A breadth-first iterator for a directed and an undirected graph.
BreadthFirstIterator(Graph<V, E>) - +Constructor for class org.jgrapht.traverse.BreadthFirstIterator +
Creates a new breadth-first iterator for the specified graph. +
BreadthFirstIterator(Graph<V, E>, V) - +Constructor for class org.jgrapht.traverse.BreadthFirstIterator +
Creates a new breadth-first iterator for the specified graph. +
BronKerboschCliqueFinder<V,E> - Class in org.jgrapht.alg
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.
BronKerboschCliqueFinder(Graph<V, E>) - +Constructor for class org.jgrapht.alg.BronKerboschCliqueFinder +
Creates a new clique finder. +
+
+

+C

+
+
calculateMaximumFlow(V, V) - +Method in class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Sets current source to source, current sink to sink, + then calculates maximum flow from source to sink. +
cascadingCut(FibonacciHeapNode<T>) - +Method in class org.jgrapht.util.FibonacciHeap +
Performs a cascading cut operation. +
CENTER_VERTEX - +Static variable in class org.jgrapht.generate.StarGraphGenerator +
  +
ChromaticNumber - Class in org.jgrapht.alg
Allows the + chromatic number of a graph to be calculated.
ChromaticNumber() - +Constructor for class org.jgrapht.alg.ChromaticNumber +
  +
ClassBasedEdgeFactory<V,E> - Class in org.jgrapht.graph
An EdgeFactory for producing edges by using a class as a factory.
ClassBasedEdgeFactory(Class<? extends E>) - +Constructor for class org.jgrapht.graph.ClassBasedEdgeFactory +
  +
ClassBasedVertexFactory<V> - Class in org.jgrapht.graph
A VertexFactory for producing vertices by using a class as a factory.
ClassBasedVertexFactory(Class<? extends V>) - +Constructor for class org.jgrapht.graph.ClassBasedVertexFactory +
  +
clear() - +Method in class org.jgrapht.ext.IntegerEdgeNameProvider +
Clears all cached identifiers, and resets the unique identifier counter. +
clear() - +Method in class org.jgrapht.ext.IntegerNameProvider +
Clears all cached identifiers, and resets the unique identifier counter. +
clear() - +Method in class org.jgrapht.util.FibonacciHeap +
Removes all elements from this heap. +
clone() - +Method in class org.jgrapht.graph.AbstractBaseGraph +
Returns a shallow copy of this graph instance. +
clone() - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
closeSimpleDirectedGraph(SimpleDirectedGraph<V, E>) - +Method in class org.jgrapht.alg.TransitiveClosure +
Computes the transitive closure of the given graph. +
ClosestFirstIterator<V,E> - Class in org.jgrapht.traverse
A closest-first iterator for a directed or undirected graph.
ClosestFirstIterator(Graph<V, E>) - +Constructor for class org.jgrapht.traverse.ClosestFirstIterator +
Creates a new closest-first iterator for the specified graph. +
ClosestFirstIterator(Graph<V, E>, V) - +Constructor for class org.jgrapht.traverse.ClosestFirstIterator +
Creates a new closest-first iterator for the specified graph. +
ClosestFirstIterator(Graph<V, E>, V, double) - +Constructor for class org.jgrapht.traverse.ClosestFirstIterator +
Creates a new radius-bounded closest-first iterator for the specified + graph. +
combine(double, double) - +Method in interface org.jgrapht.util.WeightCombiner +
Combines two weights. +
compare(V, V) - +Method in class org.jgrapht.alg.util.VertexDegreeComparator +
Compare the degrees of v1 and v2, taking into + account whether ascending or descending order is used. +
compareTo(ModifiableInteger) - +Method in class org.jgrapht.util.ModifiableInteger +
Compares two ModifiableInteger objects numerically. +
compareTo(Object) - +Method in class org.jgrapht.util.ModifiableInteger +
Compares this ModifiableInteger object to another object. +
CompleteBipartiteGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a complete + bipartite graph of any size.
CompleteBipartiteGraphGenerator(int, int) - +Constructor for class org.jgrapht.generate.CompleteBipartiteGraphGenerator +
Creates a new CompleteBipartiteGraphGenerator object. +
CompleteGraphDemo - Class in org.jgrapht.demo
 
CompleteGraphDemo() - +Constructor for class org.jgrapht.demo.CompleteGraphDemo +
  +
CompleteGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a complete graph of any size.
CompleteGraphGenerator(int) - +Constructor for class org.jgrapht.generate.CompleteGraphGenerator +
Construct a new CompleteGraphGenerator. +
CONNECTED_COMPONENT_FINISHED - +Static variable in class org.jgrapht.event.ConnectedComponentTraversalEvent +
Connected component traversal finished event. +
CONNECTED_COMPONENT_STARTED - +Static variable in class org.jgrapht.event.ConnectedComponentTraversalEvent +
Connected component traversal started event. +
connectedComponentFinished(ConnectedComponentTraversalEvent) - +Method in interface org.jgrapht.event.TraversalListener +
Called to inform listeners that the traversal of the current connected + component has finished. +
connectedComponentFinished(ConnectedComponentTraversalEvent) - +Method in class org.jgrapht.event.TraversalListenerAdapter +
  +
connectedComponentStarted(ConnectedComponentTraversalEvent) - +Method in interface org.jgrapht.event.TraversalListener +
Called to inform listeners that a traversal of a new connected component + has started. +
connectedComponentStarted(ConnectedComponentTraversalEvent) - +Method in class org.jgrapht.event.TraversalListenerAdapter +
  +
ConnectedComponentTraversalEvent - Class in org.jgrapht.event
A traversal event with respect to a connected component.
ConnectedComponentTraversalEvent(Object, int) - +Constructor for class org.jgrapht.event.ConnectedComponentTraversalEvent +
Creates a new ConnectedComponentTraversalEvent. +
connectedSetOf(V) - +Method in class org.jgrapht.alg.ConnectivityInspector +
Returns a set of all vertices that are in the maximally connected + component together with the specified vertex. +
connectedSets() - +Method in class org.jgrapht.alg.ConnectivityInspector +
Returns a list of Set s, where each set contains all + vertices that are in the same maximally connected component. +
ConnectivityInspector<V,E> - Class in org.jgrapht.alg
Allows obtaining various connectivity aspects of a graph.
ConnectivityInspector(UndirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.ConnectivityInspector +
Creates a connectivity inspector for the specified undirected graph. +
ConnectivityInspector(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.ConnectivityInspector +
Creates a connectivity inspector for the specified directed graph. +
consolidate() - +Method in class org.jgrapht.util.FibonacciHeap +
  +
containsEdge(E) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
containsEdge(V, V) - +Method in class org.jgrapht.graph.AbstractGraph +
  +
containsEdge(V, V) - +Method in interface org.jgrapht.Graph +
Returns true if and only if this graph contains an edge going + from the source vertex to the target vertex. +
containsEdge(E) - +Method in interface org.jgrapht.Graph +
Returns true if this graph contains the specified edge. +
containsEdge(E) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
containsEdge(E) - +Method in class org.jgrapht.graph.GraphUnion +
  +
containsEdge(E) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
containsEdge(E) - +Method in class org.jgrapht.graph.Subgraph +
  +
containsVertex(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
containsVertex(V) - +Method in interface org.jgrapht.Graph +
Returns true if this graph contains the specified vertex. +
containsVertex(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
containsVertex(V) - +Method in class org.jgrapht.graph.GraphUnion +
  +
containsVertex(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
containsVertex(V) - +Method in class org.jgrapht.graph.Subgraph +
  +
createDefaultEdgeAttributes(Graph<V, E>) - +Static method in class org.jgrapht.ext.JGraphModelAdapter +
Creates and returns a map of attributes to be used as defaults for edge + attributes, depending on the specified graph. +
createDefaultVertexAttributes() - +Static method in class org.jgrapht.ext.JGraphModelAdapter +
Creates and returns a map of attributes to be used as defaults for vertex + attributes. +
createEdge(V, V) - +Method in interface org.jgrapht.EdgeFactory +
Creates a new edge whose endpoints are the specified source and target + vertices. +
createEdge(V, V) - +Method in class org.jgrapht.graph.ClassBasedEdgeFactory +
  +
createEdgeCell(EE) - +Method in interface org.jgrapht.ext.JGraphModelAdapter.CellFactory +
Creates an edge cell that contains its respective JGraphT edge. +
createEdgeCell(EE) - +Method in class org.jgrapht.ext.JGraphModelAdapter.DefaultCellFactory +
  +
createEdges(Graph<VV, EE>, Map<Integer, VV>, int, Random) - +Method in class org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory +
  +
createEdges(Graph<VV, EE>, Map<Integer, VV>, int, Random) - +Method in interface org.jgrapht.generate.RandomGraphGenerator.EdgeTopologyFactory +
Two different calls to the createEdges() with the same parameters + must result in the generation of the same. +
createEdgeSet(V) - +Method in interface org.jgrapht.graph.EdgeSetFactory +
Create a new edge set for a particular vertex. +
createVertex() - +Method in class org.jgrapht.graph.ClassBasedVertexFactory +
  +
createVertex() - +Method in interface org.jgrapht.VertexFactory +
Creates a new vertex. +
createVertexCell(VV) - +Method in interface org.jgrapht.ext.JGraphModelAdapter.CellFactory +
Creates a vertex cell that contains its respective JGraphT vertex. +
createVertexCell(VV) - +Method in class org.jgrapht.ext.JGraphModelAdapter.DefaultCellFactory +
  +
CrossComponentIterator<V,E,D> - Class in org.jgrapht.traverse
Provides a cross-connected-component traversal functionality for iterator + subclasses.
CrossComponentIterator(Graph<V, E>, V) - +Constructor for class org.jgrapht.traverse.CrossComponentIterator +
Creates a new iterator for the specified graph. +
CrossComponentIterator.VisitColor - Enum in org.jgrapht.traverse
Standard vertex visit state enumeration.
cut(FibonacciHeapNode<T>, FibonacciHeapNode<T>) - +Method in class org.jgrapht.util.FibonacciHeap +
The reverse of the link operation: removes x from the child list of y. +
CycleDetector<V,E> - Class in org.jgrapht.alg
Performs cycle detection on a graph.
CycleDetector(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.CycleDetector +
Creates a cycle detector for the specified graph. +
+
+

+D

+
+
decreaseKey(FibonacciHeapNode<T>, double) - +Method in class org.jgrapht.util.FibonacciHeap +
Decreases the key value for a heap node, given the new value to take on. +
decrement() - +Method in class org.jgrapht.util.ModifiableInteger +
Subtracts one from the value of this modifiable integer. +
DEFAULT_EDGE_WEIGHT - +Static variable in interface org.jgrapht.WeightedGraph +
The default weight for an edge. +
DEFAULT_EPSILON - +Static variable in class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Default tolerance. +
DefaultDirectedGraph<V,E> - Class in org.jgrapht.graph
A directed graph.
DefaultDirectedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.DefaultDirectedGraph +
Creates a new directed graph. +
DefaultDirectedGraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.DefaultDirectedGraph +
Creates a new directed graph with the specified edge factory. +
DefaultDirectedWeightedGraph<V,E> - Class in org.jgrapht.graph
A directed weighted graph.
DefaultDirectedWeightedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.DefaultDirectedWeightedGraph +
Creates a new directed weighted graph. +
DefaultDirectedWeightedGraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.DefaultDirectedWeightedGraph +
Creates a new directed weighted graph with the specified edge factory. +
DefaultEdge - Class in org.jgrapht.graph
A default implementation for edges in a Graph.
DefaultEdge() - +Constructor for class org.jgrapht.graph.DefaultEdge +
  +
DefaultGraphMapping<V,E> - Class in org.jgrapht.graph
Implementation of the GraphMapping interface.
DefaultGraphMapping(Map<V, V>, Map<V, V>, Graph<V, E>, Graph<V, E>) - +Constructor for class org.jgrapht.graph.DefaultGraphMapping +
The maps themselves are used. +
DefaultListenableGraph<V,E> - Class in org.jgrapht.graph
A graph backed by the the graph specified at the constructor, which can be + listened by GraphListener s and by + VertexSetListener s.
DefaultListenableGraph(Graph<V, E>) - +Constructor for class org.jgrapht.graph.DefaultListenableGraph +
Creates a new listenable graph. +
DefaultListenableGraph(Graph<V, E>, boolean) - +Constructor for class org.jgrapht.graph.DefaultListenableGraph +
Creates a new listenable graph. +
DefaultWeightedEdge - Class in org.jgrapht.graph
A default implementation for edges in a WeightedGraph.
DefaultWeightedEdge() - +Constructor for class org.jgrapht.graph.DefaultWeightedEdge +
  +
degreeOf(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
degreeOf(V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
degreeOf(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
degreeOf(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
degreeOf(V) - +Method in class org.jgrapht.graph.UndirectedGraphUnion +
  +
degreeOf(V) - +Method in class org.jgrapht.graph.UndirectedSubgraph +
  +
degreeOf(V) - +Method in interface org.jgrapht.UndirectedGraph +
Returns the degree of the specified vertex. +
delete(FibonacciHeapNode<T>) - +Method in class org.jgrapht.util.FibonacciHeap +
Deletes a node from the heap given the reference to the node. +
DepthFirstIterator<V,E> - Class in org.jgrapht.traverse
A depth-first iterator for a directed and an undirected graph.
DepthFirstIterator(Graph<V, E>) - +Constructor for class org.jgrapht.traverse.DepthFirstIterator +
Creates a new depth-first iterator for the specified graph. +
DepthFirstIterator(Graph<V, E>, V) - +Constructor for class org.jgrapht.traverse.DepthFirstIterator +
Creates a new depth-first iterator for the specified graph. +
detectCycles() - +Method in class org.jgrapht.alg.CycleDetector +
Performs yes/no cycle detection on the entire graph. +
detectCyclesContainingVertex(V) - +Method in class org.jgrapht.alg.CycleDetector +
Performs yes/no cycle detection on an individual vertex. +
DijkstraShortestPath<V,E> - Class in org.jgrapht.alg
An implementation of Dijkstra's + shortest path algorithm using ClosestFirstIterator.
DijkstraShortestPath(Graph<V, E>, V, V) - +Constructor for class org.jgrapht.alg.DijkstraShortestPath +
Creates and executes a new DijkstraShortestPath algorithm instance. +
DijkstraShortestPath(Graph<V, E>, V, V, double) - +Constructor for class org.jgrapht.alg.DijkstraShortestPath +
Creates and executes a new DijkstraShortestPath algorithm instance. +
DirectedGraph<V,E> - Interface in org.jgrapht
A graph whose all edges are directed.
DirectedGraphUnion<V,E> - Class in org.jgrapht.graph
 
DirectedMaskSubgraph<V,E> - Class in org.jgrapht.graph
A directed graph that is a MaskSubgraph on another graph.
DirectedMaskSubgraph(DirectedGraph<V, E>, MaskFunctor<V, E>) - +Constructor for class org.jgrapht.graph.DirectedMaskSubgraph +
  +
DirectedMultigraph<V,E> - Class in org.jgrapht.graph
A directed multigraph.
DirectedMultigraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.DirectedMultigraph +
Creates a new directed multigraph. +
DirectedMultigraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.DirectedMultigraph +
Creates a new directed multigraph with the specified edge factory. +
DirectedNeighborIndex<V,E> - Class in org.jgrapht.alg
Maintains a cache of each vertex's neighbors.
DirectedNeighborIndex(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.DirectedNeighborIndex +
Creates a neighbor index for the specified directed graph. +
DirectedPseudograph<V,E> - Class in org.jgrapht.graph
A directed pseudograph.
DirectedPseudograph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.DirectedPseudograph +
  +
DirectedPseudograph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.DirectedPseudograph +
  +
DirectedSubgraph<V,E> - Class in org.jgrapht.graph
A directed graph that is a subgraph on other graph.
DirectedSubgraph(DirectedGraph<V, E>, Set<V>, Set<E>) - +Constructor for class org.jgrapht.graph.DirectedSubgraph +
Creates a new directed subgraph. +
DirectedWeightedMultigraph<V,E> - Class in org.jgrapht.graph
A directed weighted multigraph.
DirectedWeightedMultigraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.DirectedWeightedMultigraph +
Creates a new directed weighted multigraph. +
DirectedWeightedMultigraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.DirectedWeightedMultigraph +
Creates a new directed weighted multigraph with the specified edge + factory. +
DirectedWeightedSubgraph<V,E> - Class in org.jgrapht.graph
A directed weighted graph that is a subgraph on other graph.
DirectedWeightedSubgraph(WeightedGraph<V, E>, Set<V>, Set<E>) - +Constructor for class org.jgrapht.graph.DirectedWeightedSubgraph +
Creates a new weighted directed subgraph. +
DOTExporter<V,E> - Class in org.jgrapht.ext
Exports a graph into a DOT file.
DOTExporter() - +Constructor for class org.jgrapht.ext.DOTExporter +
Constructs a new DOTExporter object with an integer name provider for the + vertex IDs and null providers for the vertex and edge labels. +
DOTExporter(VertexNameProvider<V>, VertexNameProvider<V>, EdgeNameProvider<E>) - +Constructor for class org.jgrapht.ext.DOTExporter +
Constructs a new DOTExporter object with the given ID and label + providers. +
doubleValue() - +Method in class org.jgrapht.util.ModifiableInteger +
  +
+
+

+E

+
+
edge - +Variable in class org.jgrapht.event.EdgeTraversalEvent +
The traversed edge. +
edge - +Variable in class org.jgrapht.event.GraphEdgeChangeEvent +
The edge that this event is related to. +
EDGE_ADDED - +Static variable in class org.jgrapht.event.GraphEdgeChangeEvent +
Edge added event. +
EDGE_REMOVED - +Static variable in class org.jgrapht.event.GraphEdgeChangeEvent +
Edge removed event. +
edgeAdded(GraphEdgeChangeEvent<V, E>) - +Method in class org.jgrapht.alg.ConnectivityInspector +
  +
edgeAdded(GraphEdgeChangeEvent<V, E>) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
  +
edgeAdded(GraphEdgeChangeEvent<V, E>) - +Method in class org.jgrapht.alg.NeighborIndex +
  +
edgeAdded(GraphEdgeChangeEvent<V, E>) - +Method in interface org.jgrapht.event.GraphListener +
Notifies that an edge has been added to the graph. +
EdgeFactory<V,E> - Interface in org.jgrapht
An edge factory used by graphs for creating new edges.
EdgeNameProvider<E> - Interface in org.jgrapht.ext
Assigns a display name for each of the graph edes.
edgeRemoved(GraphEdgeChangeEvent<V, E>) - +Method in class org.jgrapht.alg.ConnectivityInspector +
  +
edgeRemoved(GraphEdgeChangeEvent<V, E>) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
  +
edgeRemoved(GraphEdgeChangeEvent<V, E>) - +Method in class org.jgrapht.alg.NeighborIndex +
  +
edgeRemoved(GraphEdgeChangeEvent<V, E>) - +Method in interface org.jgrapht.event.GraphListener +
Notifies that an edge has been removed from the graph. +
EdgeReversedGraph<V,E> - Class in org.jgrapht.graph
Provides an edge-reversed view g' of a directed graph g.
EdgeReversedGraph(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.EdgeReversedGraph +
Creates a new EdgeReversedGraph. +
edgeSet() - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
edgeSet() - +Method in interface org.jgrapht.Graph +
Returns a set of the edges contained in this graph. +
edgeSet() - +Method in class org.jgrapht.graph.GraphDelegator +
  +
edgeSet() - +Method in class org.jgrapht.graph.GraphUnion +
  +
edgeSet() - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
edgeSet() - +Method in class org.jgrapht.graph.Subgraph +
  +
EdgeSetFactory<V,E> - Interface in org.jgrapht.graph
A factory for edge sets.
edgesOf(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
edgesOf(V) - +Method in interface org.jgrapht.Graph +
Returns a set of all edges touching the specified vertex. +
edgesOf(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
edgesOf(V) - +Method in class org.jgrapht.graph.GraphUnion +
  +
edgesOf(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
edgesOf(V) - +Method in class org.jgrapht.graph.Subgraph +
  +
EdgeTraversalEvent<V,E> - Class in org.jgrapht.event
A traversal event for a graph edge.
EdgeTraversalEvent(Object, E) - +Constructor for class org.jgrapht.event.EdgeTraversalEvent +
Creates a new EdgeTraversalEvent. +
edgeTraversed(EdgeTraversalEvent<V, E>) - +Method in interface org.jgrapht.event.TraversalListener +
Called to inform the listener that the specified edge have been visited + during the graph traversal. +
edgeTraversed(EdgeTraversalEvent<V, E>) - +Method in class org.jgrapht.event.TraversalListenerAdapter +
  +
EdmondsKarpMaximumFlow<V,E> - Class in org.jgrapht.alg
A flow network is a + directed graph where each edge has a capacity and each edge receives a flow.
EdmondsKarpMaximumFlow(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Constructs MaximumFlow instance to work with a copy of + network. +
EdmondsKarpMaximumFlow(DirectedGraph<V, E>, double) - +Constructor for class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Constructs MaximumFlow instance to work with a copy of + network. +
EmptyGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates an empty + graph of any size.
EmptyGraphGenerator(int) - +Constructor for class org.jgrapht.generate.EmptyGraphGenerator +
Construct a new EmptyGraphGenerator. +
encounterVertex(V, E) - +Method in class org.jgrapht.traverse.BreadthFirstIterator +
  +
encounterVertex(V, E) - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
  +
encounterVertex(V, E) - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Update data structures the first time we see a vertex. +
encounterVertex(V, E) - +Method in class org.jgrapht.traverse.DepthFirstIterator +
  +
encounterVertex(V, E) - +Method in class org.jgrapht.traverse.TopologicalOrderIterator +
  +
encounterVertexAgain(V, E) - +Method in class org.jgrapht.traverse.BreadthFirstIterator +
  +
encounterVertexAgain(V, E) - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
Override superclass. +
encounterVertexAgain(V, E) - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Called whenever we re-encounter a vertex. +
encounterVertexAgain(V, E) - +Method in class org.jgrapht.traverse.DepthFirstIterator +
  +
encounterVertexAgain(V, E) - +Method in class org.jgrapht.traverse.TopologicalOrderIterator +
  +
END_VERTEX - +Static variable in class org.jgrapht.generate.LinearGraphGenerator +
Role for the last vertex generated. +
equals(Object) - +Method in class org.jgrapht.util.ArrayUnenforcedSet +
  +
equals(Object) - +Method in class org.jgrapht.util.ModifiableInteger +
Compares this object to the specified object. +
EulerianCircuit - Class in org.jgrapht.alg
This algorithm will check whether a graph is Eulerian (hence it contains an + Eulerian + circuit).
EulerianCircuit() - +Constructor for class org.jgrapht.alg.EulerianCircuit +
  +
export(Writer, Graph<V, E>) - +Method in class org.jgrapht.ext.DOTExporter +
Exports a graph into a plain text file in DOT format. +
export(Writer, UndirectedGraph<V, E>) - +Method in class org.jgrapht.ext.GmlExporter +
Exports an undirected graph into a plain text file in GML format. +
export(Writer, DirectedGraph<V, E>) - +Method in class org.jgrapht.ext.GmlExporter +
Exports a directed graph into a plain text file in GML format. +
export(Writer, Graph<V, E>) - +Method in class org.jgrapht.ext.GraphMLExporter +
Exports a graph into a plain text file in GraphML format. +
export(OutputStream, Graph<V, E>) - +Method in class org.jgrapht.ext.VisioExporter +
Exports the specified graph into a Visio csv file format. +
exportAdjacencyMatrix(Writer, UndirectedGraph<V, E>) - +Method in class org.jgrapht.ext.MatrixExporter +
Exports the specified graph into a plain text file format containing a + sparse representation of the graph's adjacency matrix. +
exportAdjacencyMatrix(Writer, DirectedGraph<V, E>) - +Method in class org.jgrapht.ext.MatrixExporter +
Exports the specified graph into a plain text file format containing a + sparse representation of the graph's adjacency matrix. +
exportLaplacianMatrix(Writer, UndirectedGraph<V, E>) - +Method in class org.jgrapht.ext.MatrixExporter +
Exports the specified graph into a plain text file format containing a + sparse representation of the graph's Laplacian matrix. +
exportNormalizedLaplacianMatrix(Writer, UndirectedGraph<V, E>) - +Method in class org.jgrapht.ext.MatrixExporter +
Exports the specified graph into a plain text file format containing a + sparse representation of the graph's normalized Laplacian matrix. +
+
+

+F

+
+
factorial(int) - +Static method in class org.jgrapht.util.MathUtil +
  +
FibonacciHeap<T> - Class in org.jgrapht.util
This class implements a Fibonacci heap data structure.
FibonacciHeap() - +Constructor for class org.jgrapht.util.FibonacciHeap +
Constructs a FibonacciHeap object that contains no elements. +
FibonacciHeapNode<T> - Class in org.jgrapht.util
Implements a node of the Fibonacci heap.
FibonacciHeapNode(T, double) - +Constructor for class org.jgrapht.util.FibonacciHeapNode +
Default constructor. +
find2ApproximationCover(Graph<V, E>) - +Static method in class org.jgrapht.alg.VertexCovers +
Finds a 2-approximation for a minimal vertex cover of the specified + graph. +
findCycles() - +Method in class org.jgrapht.alg.CycleDetector +
Finds the vertex set for the subgraph of all cycles. +
findCyclesContainingVertex(V) - +Method in class org.jgrapht.alg.CycleDetector +
Finds the vertex set for the subgraph of all cycles which contain a + particular vertex. +
findGreedyChromaticNumber(UndirectedGraph<V, E>) - +Static method in class org.jgrapht.alg.ChromaticNumber +
Finds the number of colors required for a greedy coloring of the graph. +
findGreedyCover(UndirectedGraph<V, E>) - +Static method in class org.jgrapht.alg.VertexCovers +
Finds a greedy approximation for a minimal vertex cover of a specified + graph. +
findPathBetween(Graph<V, E>, V, V) - +Static method in class org.jgrapht.alg.BellmanFordShortestPath +
Convenience method to find the shortest path via a single static method + call. +
findPathBetween(Graph<V, E>, V, V) - +Static method in class org.jgrapht.alg.DijkstraShortestPath +
Convenience method to find the shortest path via a single static method + call. +
finishVertex(V) - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Called when a vertex has been finished (meaning is dependent on traversal + represented by subclass). +
fireConnectedComponentFinished(ConnectedComponentTraversalEvent) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Informs all listeners that the traversal of the current connected + component finished. +
fireConnectedComponentStarted(ConnectedComponentTraversalEvent) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Informs all listeners that a traversal of a new connected component has + started. +
fireEdgeAdded(E) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
Notify listeners that the specified edge was added. +
fireEdgeRemoved(E) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
Notify listeners that the specified edge was removed. +
fireEdgeTraversed(EdgeTraversalEvent<V, E>) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Informs all listeners that a the specified edge was visited. +
fireVertexAdded(V) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
Notify listeners that the specified vertex was added. +
fireVertexFinished(VertexTraversalEvent<V>) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Informs all listeners that a the specified vertex was finished. +
fireVertexRemoved(V) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
Notify listeners that the specified vertex was removed. +
fireVertexTraversed(VertexTraversalEvent<V>) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Informs all listeners that a the specified vertex was visited. +
FIRST - +Static variable in interface org.jgrapht.util.WeightCombiner +
First weight. +
floatValue() - +Method in class org.jgrapht.util.ModifiableInteger +
  +
FloydWarshallShortestPaths<V,E> - Class in org.jgrapht.alg
The + Floyd-Warshall algorithm finds all shortest paths (all n^2 of them) in + O(n^3) time.
FloydWarshallShortestPaths(Graph<V, E>) - +Constructor for class org.jgrapht.alg.FloydWarshallShortestPaths +
Constructs the shortest path array for the given graph. +
+
+

+G

+
+
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.CompleteBipartiteGraphGenerator +
Construct a complete bipartite graph +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.CompleteGraphGenerator +
Generate a graph structure. +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.EmptyGraphGenerator +
Generate a graph structure. +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, T>) - +Method in interface org.jgrapht.generate.GraphGenerator +
Generate a graph structure. +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.HyperCubeGraphGenerator +
This will generate the hypercube graph +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.LinearGraphGenerator +
Generate a graph structure. +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.RandomGraphGenerator +
(non-Javadoc) +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.RingGraphGenerator +
Generate a graph structure. +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.ScaleFreeGraphGenerator +
Generates scale-free network with size passed to the + constructor. +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.StarGraphGenerator +
Generates a star graph with the designated order from the constructor +
generateGraph(Graph<V, E>, VertexFactory<V>, Map<String, V>) - +Method in class org.jgrapht.generate.WheelGraphGenerator +
Generate a graph structure. +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
getAllEdges(V, V) - +Method in interface org.jgrapht.Graph +
Returns a set of all edges connecting source vertex to target vertex if + such vertices exist in this graph. +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.GraphUnion +
  +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
getAllEdges(V, V) - +Method in class org.jgrapht.graph.Subgraph +
  +
getAllMaximalCliques() - +Method in class org.jgrapht.alg.BronKerboschCliqueFinder +
Finds all maximal cliques of the graph. +
getApproximateOptimalForCompleteGraph(SimpleWeightedGraph<V, E>) - +Static method in class org.jgrapht.alg.HamiltonianCycle +
This method will return an approximate minimal traveling salesman tour + (hamiltonian cycle). +
getBase() - +Method in class org.jgrapht.graph.Subgraph +
  +
getBiconnectedVertexComponents() - +Method in class org.jgrapht.alg.BiconnectivityInspector +
Returns the biconnected vertex-components of the graph. +
getBiconnectedVertexComponents(V) - +Method in class org.jgrapht.alg.BiconnectivityInspector +
Returns the biconnected vertex-components containing the vertex. +
getBiggestMaximalCliques() - +Method in class org.jgrapht.alg.BronKerboschCliqueFinder +
Finds the biggest maximal cliques of the graph. +
getBlock(V) - +Method in class org.jgrapht.alg.BlockCutpointGraph +
Returns the vertex if vertex is a cutpoint, and otherwise returns the + block (biconnected component) containing the vertex. +
getCellFactory() - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Returns the cell factory used to create the JGraph cells. +
getCost(V) - +Method in class org.jgrapht.alg.BellmanFordShortestPath +
  +
getCurrentSink() - +Method in class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Returns current sink vertex, or null if there was no + calculateMaximumFlow calls. +
getCurrentSource() - +Method in class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Returns current source vertex, or null if there was no + calculateMaximumFlow calls. +
getCutpoints() - +Method in class org.jgrapht.alg.BiconnectivityInspector +
Returns the cutpoints of the graph. +
getCutpoints() - +Method in class org.jgrapht.alg.BlockCutpointGraph +
Returns the cutpoints of the initial graph. +
getData() - +Method in class org.jgrapht.util.FibonacciHeapNode +
Obtain the data for this node. +
getDefaultEdgeAttributes() - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Returns the default edge attributes used for creating new JGraph edges. +
getDefaultVertexAttributes() - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Returns the default vertex attributes used for creating new JGraph + vertices. +
getDiameter() - +Method in class org.jgrapht.alg.FloydWarshallShortestPaths +
  +
getEdge() - +Method in class org.jgrapht.event.EdgeTraversalEvent +
Returns the traversed edge. +
getEdge() - +Method in class org.jgrapht.event.GraphEdgeChangeEvent +
Returns the edge that this event is related to. +
getEdge(V, V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
getEdge(V, V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
getEdge(V, V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
getEdge(V, V) - +Method in interface org.jgrapht.Graph +
Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph. +
getEdge(V, V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
getEdge(V, V) - +Method in class org.jgrapht.graph.GraphUnion +
  +
getEdge(V, V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
getEdge(V, V) - +Method in class org.jgrapht.graph.Subgraph +
  +
getEdgeCell(E) - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Returns the JGraph edge cell that corresponds to the specified JGraphT + edge. +
getEdgeCorrespondence(E, boolean) - +Method in class org.jgrapht.graph.DefaultGraphMapping +
  +
getEdgeCorrespondence(E, boolean) - +Method in interface org.jgrapht.GraphMapping +
Gets the mapped value where the key is edge +
getEdgeFactory() - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
getEdgeFactory() - +Method in interface org.jgrapht.Graph +
Returns the edge factory using which this graph creates new edges. +
getEdgeFactory() - +Method in class org.jgrapht.graph.GraphDelegator +
  +
getEdgeFactory() - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
getEdgeFactory() - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
getEdgeFactory() - +Method in class org.jgrapht.graph.Subgraph +
  +
getEdgeList() - +Method in class org.jgrapht.graph.GraphPathImpl +
  +
getEdgeList() - +Method in interface org.jgrapht.GraphPath +
Returns the edges making up the path. +
getEdgeName(E) - +Method in interface org.jgrapht.ext.EdgeNameProvider +
Returns a unique name for an edge. +
getEdgeName(E) - +Method in class org.jgrapht.ext.IntegerEdgeNameProvider +
Returns the String representation of an edge. +
getEdgeName(E) - +Method in class org.jgrapht.ext.StringEdgeNameProvider +
Returns the String representation an edge. +
getEdgeSource(E) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
getEdgeSource(E) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
getEdgeSource(E) - +Method in interface org.jgrapht.Graph +
Returns the source vertex of an edge. +
getEdgeSource(E) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
getEdgeSource(E) - +Method in class org.jgrapht.graph.GraphUnion +
  +
getEdgeSource(E) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
getEdgeSource(E) - +Method in class org.jgrapht.graph.Subgraph +
  +
getEdgeTarget(E) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
getEdgeTarget(E) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
getEdgeTarget(E) - +Method in interface org.jgrapht.Graph +
Returns the target vertex of an edge. +
getEdgeTarget(E) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
getEdgeTarget(E) - +Method in class org.jgrapht.graph.GraphUnion +
  +
getEdgeTarget(E) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
getEdgeTarget(E) - +Method in class org.jgrapht.graph.Subgraph +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.AsUnweightedDirectedGraph +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.AsUnweightedGraph +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.AsWeightedGraph +
  +
getEdgeWeight(E) - +Method in interface org.jgrapht.Graph +
Returns the weight assigned to a given edge. +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.GraphUnion +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
getEdgeWeight(E) - +Method in class org.jgrapht.graph.Subgraph +
  +
getEndVertex() - +Method in class org.jgrapht.graph.GraphPathImpl +
  +
getEndVertex() - +Method in interface org.jgrapht.GraphPath +
Returns the end vertex in the path. +
getEulerianCircuitVertices(UndirectedGraph<V, E>) - +Static method in class org.jgrapht.alg.EulerianCircuit +
This method will return a list of vertices which represents the Eulerian + circuit of the graph. +
getG1() - +Method in class org.jgrapht.graph.GraphUnion +
  +
getG2() - +Method in class org.jgrapht.graph.GraphUnion +
  +
getGraph() - +Method in class org.jgrapht.alg.StrongConnectivityInspector +
Returns the graph inspected by the StrongConnectivityInspector. +
getGraph() - +Method in class org.jgrapht.graph.GraphPathImpl +
  +
getGraph() - +Method in interface org.jgrapht.GraphPath +
Returns the graph over which this path is defined. +
getGraph() - +Method in class org.jgrapht.traverse.CrossComponentIterator +
  +
getKey() - +Method in class org.jgrapht.util.FibonacciHeapNode +
Obtain the key for this node. +
getMaxEdgesForVertexNum(Graph<VV, EE>) - +Method in class org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory +
Return max edges for that graph. +
getMaximumFlow() - +Method in class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Returns maximum flow, that was calculated during last + calculateMaximumFlow call, or null, if there was no + calculateMaximumFlow calls. +
getMaximumFlowValue() - +Method in class org.jgrapht.alg.EdmondsKarpMaximumFlow +
Returns maximum flow value, that was calculated during last + calculateMaximumFlow call, or null, if there was no + calculateMaximumFlow calls. +
getOppositeVertex(Graph<V, E>, E, V) - +Static method in class org.jgrapht.Graphs +
Gets the vertex opposite another vertex across an edge. +
getPath() - +Method in class org.jgrapht.alg.DijkstraShortestPath +
Return the path found. +
getPathEdgeList(V) - +Method in class org.jgrapht.alg.BellmanFordShortestPath +
  +
getPathEdgeList() - +Method in class org.jgrapht.alg.DijkstraShortestPath +
Return the edges making up the path found. +
getPathLength() - +Method in class org.jgrapht.alg.DijkstraShortestPath +
Return the length of the path found. +
getPaths(V) - +Method in class org.jgrapht.alg.KShortestPaths +
Returns the k shortest simple paths in increasing order of weight. +
getPathVertexList(GraphPath<V, E>) - +Static method in class org.jgrapht.Graphs +
Gets the list of vertices visited by a path. +
getPrintLabels() - +Method in class org.jgrapht.ext.GmlExporter +
Get whether to export the vertex and edge labels. +
getSeenData(V) - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Access the data stored for a seen vertex. +
getShortestPathLength(V) - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
Get the length of the shortest path known to the given vertex. +
getSource() - +Method in class org.jgrapht.graph.DefaultEdge +
Retrieves the source of this edge. +
getSpanningTreeEdge(V) - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
Get the spanning tree edge reaching a vertex which has been seen already + in this traversal. +
getStack() - +Method in class org.jgrapht.traverse.DepthFirstIterator +
Retrieves the LIFO stack of vertices which have been encountered but not + yet visited (WHITE). +
getStartVertex() - +Method in class org.jgrapht.graph.GraphPathImpl +
  +
getStartVertex() - +Method in interface org.jgrapht.GraphPath +
Returns the start vertex in the path. +
getTarget() - +Method in class org.jgrapht.graph.DefaultEdge +
Retrieves the target of this edge. +
getType() - +Method in class org.jgrapht.event.ConnectedComponentTraversalEvent +
Returns the event type. +
getType() - +Method in class org.jgrapht.event.GraphChangeEvent +
Returns the event type. +
getValue() - +Method in class org.jgrapht.util.ModifiableInteger +
Returns the value of this object, similarly to ModifiableInteger.intValue(). +
getVertex() - +Method in class org.jgrapht.event.GraphVertexChangeEvent +
Returns the vertex that this event is related to. +
getVertex() - +Method in class org.jgrapht.event.VertexTraversalEvent +
Returns the traversed vertex. +
getVertexCell(Object) - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Returns the JGraph vertex cell that corresponds to the specified JGraphT + vertex. +
getVertexCorrespondence(V, boolean) - +Method in class org.jgrapht.graph.DefaultGraphMapping +
  +
getVertexCorrespondence(V, boolean) - +Method in interface org.jgrapht.GraphMapping +
Gets the mapped value where the key is vertex +
getVertexName(V) - +Method in class org.jgrapht.ext.IntegerNameProvider +
Returns the String representation of the unique integer representing a + vertex. +
getVertexName(V) - +Method in class org.jgrapht.ext.StringNameProvider +
Returns the String representation of the unique integer representing a + vertex. +
getVertexName(V) - +Method in interface org.jgrapht.ext.VertexNameProvider +
Returns a unique name for a vertex. +
getVertexPort(Object) - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Returns the JGraph port cell that corresponds to the specified JGraphT + vertex. +
getWeight() - +Method in class org.jgrapht.graph.DefaultWeightedEdge +
Retrieves the weight of this edge. +
getWeight() - +Method in class org.jgrapht.graph.GraphPathImpl +
  +
getWeight() - +Method in interface org.jgrapht.GraphPath +
Returns the weight assigned to the path. +
GmlExporter<V,E> - Class in org.jgrapht.ext
Exports a graph into a GML file (Graph Modelling Language).
GmlExporter() - +Constructor for class org.jgrapht.ext.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. +
GmlExporter(VertexNameProvider<V>, VertexNameProvider<V>, EdgeNameProvider<E>, EdgeNameProvider<E>) - +Constructor for class org.jgrapht.ext.GmlExporter +
Constructs a new GmlExporter object with the given ID and label + providers. +
graph - +Variable in class org.jgrapht.alg.BellmanFordShortestPath +
Graph on which shortest paths are searched. +
Graph<V,E> - Interface in org.jgrapht
The root interface in the graph hierarchy.
GraphChangeEvent - Class in org.jgrapht.event
An event which indicates that a graph has changed.
GraphChangeEvent(Object, int) - +Constructor for class org.jgrapht.event.GraphChangeEvent +
Creates a new graph change event. +
GraphDelegator<V,E> - Class in org.jgrapht.graph
A graph backed by the the graph specified at the constructor, which delegates + all its methods to the backing graph.
GraphDelegator(Graph<V, E>) - +Constructor for class org.jgrapht.graph.GraphDelegator +
Constructor for GraphDelegator. +
GraphEdgeChangeEvent<V,E> - Class in org.jgrapht.event
An event which indicates that a graph edge has changed, or is about to + change.
GraphEdgeChangeEvent(Object, int, E) - +Constructor for class org.jgrapht.event.GraphEdgeChangeEvent +
Constructor for GraphEdgeChangeEvent. +
GraphGenerator<V,E,T> - Interface in org.jgrapht.generate
GraphGenerator defines an interface for generating new graph structures.
GraphHelper - Class in org.jgrapht
Deprecated. Use Graphs instead.
GraphHelper() - +Constructor for class org.jgrapht.GraphHelper +
Deprecated.   +
GraphIterator<V,E> - Interface in org.jgrapht.traverse
A graph iterator.
GraphListener<V,E> - Interface in org.jgrapht.event
A listener that is notified when the graph changes.
GraphMapping<V,E> - Interface in 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.
GraphMLExporter<V,E> - Class in org.jgrapht.ext
Exports a graph into a GraphML file.
GraphMLExporter() - +Constructor for class org.jgrapht.ext.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. +
GraphMLExporter(VertexNameProvider<V>, VertexNameProvider<V>, EdgeNameProvider<E>, EdgeNameProvider<E>) - +Constructor for class org.jgrapht.ext.GraphMLExporter +
Constructs a new GraphMLExporter object with the given ID and label + providers. +
GraphPath<V,E> - Interface in org.jgrapht
A GraphPath represents a + path in a Graph.
GraphPathImpl<V,E> - Class in org.jgrapht.graph
GraphPathImpl is a default implementation of GraphPath.
GraphPathImpl(Graph<V, E>, V, V, List<E>, double) - +Constructor for class org.jgrapht.graph.GraphPathImpl +
  +
Graphs - Class in org.jgrapht
A collection of utilities to assist with graph manipulation.
Graphs() - +Constructor for class org.jgrapht.Graphs +
  +
GraphUnion<V,E,G extends Graph<V,E>> - Class in org.jgrapht.graph
Read-only union of two graphs: G1 and G2.
GraphUnion(G, G, WeightCombiner) - +Constructor for class org.jgrapht.graph.GraphUnion +
  +
GraphUnion(G, G) - +Constructor for class org.jgrapht.graph.GraphUnion +
  +
GraphVertexChangeEvent<V> - Class in org.jgrapht.event
An event which indicates that a graph vertex has changed, or is about to + change.
GraphVertexChangeEvent(Object, int, V) - +Constructor for class org.jgrapht.event.GraphVertexChangeEvent +
Creates a new GraphVertexChangeEvent object. +
+
+

+H

+
+
HamiltonianCycle - Class in org.jgrapht.alg
This class will deal with finding the optimal or approximately optimal + minimum tour (hamiltonian cycle) or commonly known as the Traveling + Salesman Problem.
HamiltonianCycle() - +Constructor for class org.jgrapht.alg.HamiltonianCycle +
  +
hashCode() - +Method in class org.jgrapht.util.ArrayUnenforcedSet +
  +
hashCode() - +Method in class org.jgrapht.util.ModifiableInteger +
Returns a hash code for this ModifiableInteger. +
hasMoreElements() - +Method in class org.jgrapht.util.PrefetchIterator +
If (isGetNextLastResultUpToDate==true) returns true else 1. +
hasNext() - +Method in class org.jgrapht.traverse.CrossComponentIterator +
  +
hasNext() - +Method in class org.jgrapht.util.PrefetchIterator +
  +
HelloJGraphT - Class in org.jgrapht.demo
A simple introduction to using JGraphT.
HUB_VERTEX - +Static variable in class org.jgrapht.generate.WheelGraphGenerator +
Role for the hub vertex. +
HyperCubeGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a hyper + cube graph of any size.
HyperCubeGraphGenerator(int) - +Constructor for class org.jgrapht.generate.HyperCubeGraphGenerator +
Creates a new HyperCubeGraphGenerator object. +
+
+

+I

+
+
incomingEdgesOf(V) - +Method in interface org.jgrapht.DirectedGraph +
Returns a set of all edges incoming into the specified vertex. +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.DirectedGraphUnion +
  +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.DirectedSubgraph +
  +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
incomingEdgesOf(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
increment() - +Method in class org.jgrapht.util.ModifiableInteger +
Adds one to the value of this modifiable integer. +
inDegreeOf(V) - +Method in interface org.jgrapht.DirectedGraph +
Returns the "in degree" of the specified vertex. +
inDegreeOf(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
inDegreeOf(V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
inDegreeOf(V) - +Method in class org.jgrapht.graph.DirectedGraphUnion +
  +
inDegreeOf(V) - +Method in class org.jgrapht.graph.DirectedSubgraph +
  +
inDegreeOf(V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
inDegreeOf(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
inDegreeOf(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
init() - +Method in class org.jgrapht.demo.JGraphAdapterDemo +
+
insert(FibonacciHeapNode<T>, double) - +Method in class org.jgrapht.util.FibonacciHeap +
Inserts a new data element into the heap. +
INSTANCE - +Static variable in class org.jgrapht.alg.TransitiveClosure +
Singleton instance. +
IntegerEdgeNameProvider<E> - Class in org.jgrapht.ext
Assigns a unique integer to represent each edge.
IntegerEdgeNameProvider() - +Constructor for class org.jgrapht.ext.IntegerEdgeNameProvider +
  +
IntegerNameProvider<V> - Class in org.jgrapht.ext
Assigns a unique integer to represent each vertex.
IntegerNameProvider() - +Constructor for class org.jgrapht.ext.IntegerNameProvider +
  +
intValue() - +Method in class org.jgrapht.util.ModifiableInteger +
  +
isAllowingLoops() - +Method in class org.jgrapht.graph.AbstractBaseGraph +
Returns true if and only if self-loops are allowed in this + graph. +
isAllowingMultipleEdges() - +Method in class org.jgrapht.graph.AbstractBaseGraph +
Returns true if and only if multiple edges are allowed in + this graph. +
isBiconnected() - +Method in class org.jgrapht.alg.BiconnectivityInspector +
Returns true if the graph is biconnected (no cutpoint), + false otherwise. +
isConnectedComponentExhausted() - +Method in class org.jgrapht.traverse.BreadthFirstIterator +
  +
isConnectedComponentExhausted() - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
  +
isConnectedComponentExhausted() - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise. +
isConnectedComponentExhausted() - +Method in class org.jgrapht.traverse.DepthFirstIterator +
  +
isConnectedComponentExhausted() - +Method in class org.jgrapht.traverse.TopologicalOrderIterator +
  +
isCrossComponentTraversal() - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Test whether this iterator is set to traverse the graph across connected + components. +
isCrossComponentTraversal() - +Method in interface org.jgrapht.traverse.GraphIterator +
Test whether this iterator is set to traverse the grpah across connected + components. +
isCutpoint(V) - +Method in class org.jgrapht.alg.BlockCutpointGraph +
Returns true if the vertex is a cutpoint, false + otherwise. +
isEdgeMasked(E) - +Method in interface org.jgrapht.graph.MaskFunctor +
Returns true if the edge is masked, false + otherwise. +
isEmpty() - +Method in class org.jgrapht.util.FibonacciHeap +
Tests if the Fibonacci heap is empty or not. +
isEnumerationStartedEmpty() - +Method in class org.jgrapht.util.PrefetchIterator +
Tests whether the enumeration started as an empty one. +
isEulerian(UndirectedGraph<V, E>) - +Static method in class org.jgrapht.alg.EulerianCircuit +
This method will check whether the graph passed in is Eulerian or not. +
isGraphConnected() - +Method in class org.jgrapht.alg.ConnectivityInspector +
Test if the inspected graph is connected. +
isNumberOfEdgesValid(Graph<VV, EE>, int) - +Method in class org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory +
checks if the numOfEdges is smaller than the Max edges according to + the following table: +
isNumberOfEdgesValid(Graph<VV, EE>, int) - +Method in interface org.jgrapht.generate.RandomGraphGenerator.EdgeTopologyFactory +
Checks if the graph can contain the givven numberOfEdges according to + the graph type restrictions. +
isReuseEvents() - +Method in class org.jgrapht.graph.DefaultListenableGraph +
Tests whether the reuseEvents flag is set. +
isReuseEvents() - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
  +
isReuseEvents() - +Method in interface org.jgrapht.traverse.GraphIterator +
Tests whether the reuseEvents flag is set. +
isSeenVertex(Object) - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Determines whether a vertex has been seen yet by this traversal. +
isStronglyConnected() - +Method in class org.jgrapht.alg.StrongConnectivityInspector +
Returns true if the graph of this + StronglyConnectivityInspector instance is strongly connected. +
isVertexMasked(V) - +Method in interface org.jgrapht.graph.MaskFunctor +
Returns true if the vertex is masked, false + otherwise. +
+
+

+J

+
+
JGraphAdapterDemo - Class in org.jgrapht.demo
A demo applet that shows how to use JGraph to visualize JGraphT graphs.
JGraphAdapterDemo() - +Constructor for class org.jgrapht.demo.JGraphAdapterDemo +
  +
JGraphModelAdapter<V,E> - Class in org.jgrapht.ext
An adapter that reflects a JGraphT graph as a JGraph graph.
JGraphModelAdapter(Graph<V, E>) - +Constructor for class org.jgrapht.ext.JGraphModelAdapter +
Constructs a new JGraph model adapter for the specified JGraphT graph. +
JGraphModelAdapter(Graph<V, E>, AttributeMap, AttributeMap) - +Constructor for class org.jgrapht.ext.JGraphModelAdapter +
Constructs a new JGraph model adapter for the specified JGraphT graph. +
JGraphModelAdapter(Graph<V, E>, AttributeMap, AttributeMap, JGraphModelAdapter.CellFactory<V, E>) - +Constructor for class org.jgrapht.ext.JGraphModelAdapter +
Constructs a new JGraph model adapter for the specified JGraphT graph. +
JGraphModelAdapter.CellFactory<VV,EE> - Interface in org.jgrapht.ext
Creates the JGraph cells that reflect the respective JGraphT elements.
JGraphModelAdapter.DefaultCellFactory<VV,EE> - Class in org.jgrapht.ext
A simple default cell factory.
JGraphModelAdapter.DefaultCellFactory() - +Constructor for class org.jgrapht.ext.JGraphModelAdapter.DefaultCellFactory +
  +
+
+

+K

+
+
KShortestPaths<V,E> - Class in org.jgrapht.alg
The algorithm determines the k shortest simple paths in increasing order of + weight.
KShortestPaths(Graph<V, E>, V, int) - +Constructor for class org.jgrapht.alg.KShortestPaths +
Creates an object to compute ranking shortest paths between the start + vertex and others vertices. +
KShortestPaths(Graph<V, E>, V, int, int) - +Constructor for class org.jgrapht.alg.KShortestPaths +
Creates an object to calculate ranking shortest paths between the start + vertex and others vertices. +
+
+

+L

+
+
LinearGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a linear graph of any size.
LinearGraphGenerator(int) - +Constructor for class org.jgrapht.generate.LinearGraphGenerator +
Construct a new LinearGraphGenerator. +
link(FibonacciHeapNode<T>, FibonacciHeapNode<T>) - +Method in class org.jgrapht.util.FibonacciHeap +
Make node y a child of node x. +
ListenableDirectedGraph<V,E> - Class in org.jgrapht.graph
A directed graph which is also ListenableGraph.
ListenableDirectedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.ListenableDirectedGraph +
Creates a new listenable directed graph. +
ListenableDirectedGraph(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.ListenableDirectedGraph +
Creates a new listenable directed graph. +
ListenableDirectedWeightedGraph<V,E> - Class in org.jgrapht.graph
A directed weighted graph which is also ListenableGraph.
ListenableDirectedWeightedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.ListenableDirectedWeightedGraph +
Creates a new listenable directed weighted graph. +
ListenableDirectedWeightedGraph(WeightedGraph<V, E>) - +Constructor for class org.jgrapht.graph.ListenableDirectedWeightedGraph +
Creates a new listenable directed weighted graph. +
ListenableGraph<V,E> - Interface in org.jgrapht
A graph that supports listeners on structural change events.
ListenableUndirectedGraph<V,E> - Class in org.jgrapht.graph
An undirected graph which is also ListenableGraph.
ListenableUndirectedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.ListenableUndirectedGraph +
Creates a new listenable undirected simple graph. +
ListenableUndirectedGraph(UndirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.ListenableUndirectedGraph +
Creates a new listenable undirected graph. +
ListenableUndirectedWeightedGraph<V,E> - Class in org.jgrapht.graph
An undirected weighted graph which is also ListenableGraph.
ListenableUndirectedWeightedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.ListenableUndirectedWeightedGraph +
Creates a new listenable undirected weighted graph. +
ListenableUndirectedWeightedGraph(WeightedGraph<V, E>) - +Constructor for class org.jgrapht.graph.ListenableUndirectedWeightedGraph +
Creates a new listenable undirected weighted graph. +
longValue() - +Method in class org.jgrapht.util.ModifiableInteger +
  +
+
+

+M

+
+
main(String[]) - +Static method in class org.jgrapht.demo.CompleteGraphDemo +
  +
main(String[]) - +Static method in class org.jgrapht.demo.HelloJGraphT +
The starting point for the demo. +
main(String[]) - +Static method in class org.jgrapht.demo.JGraphAdapterDemo +
An alternative starting point for this demo, to also allow running this + applet as an application. +
main(String[]) - +Static method in class org.jgrapht.demo.PerformanceDemo +
The starting point for the demo. +
MaskFunctor<V,E> - Interface in org.jgrapht.graph
A functor interface for masking out vertices and edges of a graph.
MaskSubgraph<V,E> - Class in org.jgrapht.graph
An unmodifiable subgraph induced by a vertex/edge masking function.
MaskSubgraph(Graph<V, E>, MaskFunctor<V, E>) - +Constructor for class org.jgrapht.graph.MaskSubgraph +
Creates a new induced subgraph. +
MathUtil - Class in org.jgrapht.util
Math Utilities.
MathUtil() - +Constructor for class org.jgrapht.util.MathUtil +
  +
MatrixExporter<V,E> - Class in org.jgrapht.ext
Exports a graph to a plain text matrix format, which can be processed by + matrix manipulation software, such as + MTJ or MATLAB.
MatrixExporter() - +Constructor for class org.jgrapht.ext.MatrixExporter +
Creates a new MatrixExporter object. +
MAX - +Static variable in interface org.jgrapht.util.WeightCombiner +
Maximum weight. +
min() - +Method in class org.jgrapht.util.FibonacciHeap +
Returns the smallest element in the heap. +
MIN - +Static variable in interface org.jgrapht.util.WeightCombiner +
Minimum weight. +
ModifiableInteger - Class in org.jgrapht.util
The ModifiableInteger class wraps a value of the primitive type + int in an object, similarly to Integer.
ModifiableInteger() - +Constructor for class org.jgrapht.util.ModifiableInteger +
Deprecated. not really deprecated, just marked so to avoid mistaken use. +
ModifiableInteger(int) - +Constructor for class org.jgrapht.util.ModifiableInteger +
Constructs a newly allocated ModifiableInteger object that + represents the specified int value. +
Multigraph<V,E> - Class in org.jgrapht.graph
A multigraph.
Multigraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.Multigraph +
Creates a new multigraph. +
Multigraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.Multigraph +
Creates a new multigraph with the specified edge factory. +
+
+

+N

+
+
NeighborIndex<V,E> - Class in org.jgrapht.alg
Maintains a cache of each vertex's neighbors.
NeighborIndex(Graph<V, E>) - +Constructor for class org.jgrapht.alg.NeighborIndex +
Creates a neighbor index for the specified undirected graph. +
neighborListOf(V) - +Method in class org.jgrapht.alg.NeighborIndex +
Returns a list of vertices which are adjacent to a specified vertex. +
neighborListOf(Graph<V, E>, V) - +Static method in class org.jgrapht.Graphs +
Returns a list of vertices that are the neighbors of a specified vertex. +
neighborsOf(V) - +Method in class org.jgrapht.alg.NeighborIndex +
Returns the set of vertices which are adjacent to a specified vertex. +
next() - +Method in class org.jgrapht.traverse.CrossComponentIterator +
  +
next() - +Method in class org.jgrapht.util.PrefetchIterator +
  +
nextElement() - +Method in class org.jgrapht.util.PrefetchIterator +
1. +
nextElement() - +Method in interface org.jgrapht.util.PrefetchIterator.NextElementFunctor +
You must implement that NoSuchElementException is thrown on + nextElement() if it is out of bound. +
nListeners - +Variable in class org.jgrapht.traverse.AbstractGraphIterator +
  +
numOfEdges - +Variable in class org.jgrapht.generate.RandomGraphGenerator +
  +
numOfVertexes - +Variable in class org.jgrapht.generate.RandomGraphGenerator +
  +
+
+

+O

+
+
org.jgrapht - package org.jgrapht
The front-end API's interfaces and classes, including Graph, +DirectedGraph and UndirectedGraph.
org.jgrapht.alg - package org.jgrapht.alg
Algorithms provided with JGraphT.
org.jgrapht.alg.util - package org.jgrapht.alg.util
Utilities used by JGraphT algorithms.
org.jgrapht.demo - package org.jgrapht.demo
Demo programs that help to get started with JGraphT.
org.jgrapht.event - package org.jgrapht.event
Event classes and listener interfaces, used to provide a change +notification mechanism on graph modification events.
org.jgrapht.ext - package org.jgrapht.ext
+Extensions and integration means to other products.
org.jgrapht.generate - package org.jgrapht.generate
Generators for graphs of various topologies.
org.jgrapht.graph - package org.jgrapht.graph
Implementations of various graphs.
org.jgrapht.traverse - package org.jgrapht.traverse
Graph traversal means.
org.jgrapht.util - package org.jgrapht.util
Non-graph-specific data structures, algorithms, and utilities used by +JGraphT.
outDegreeOf(V) - +Method in interface org.jgrapht.DirectedGraph +
Returns the "out degree" of the specified vertex. +
outDegreeOf(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
outDegreeOf(V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
outDegreeOf(V) - +Method in class org.jgrapht.graph.DirectedGraphUnion +
  +
outDegreeOf(V) - +Method in class org.jgrapht.graph.DirectedSubgraph +
  +
outDegreeOf(V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
outDegreeOf(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
outDegreeOf(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
outgoingEdgesOf(V) - +Method in interface org.jgrapht.DirectedGraph +
Returns a set of all edges outgoing from the specified vertex. +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.DirectedGraphUnion +
  +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.DirectedSubgraph +
  +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
outgoingEdgesOf(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
+
+

+P

+
+
ParanoidGraph<V,E> - Class in org.jgrapht.graph
ParanoidGraph provides a way to verify that objects added to a graph obey the + standard equals/hashCode contract.
ParanoidGraph(Graph<V, E>) - +Constructor for class org.jgrapht.graph.ParanoidGraph +
  +
pathExists(V, V) - +Method in class org.jgrapht.alg.ConnectivityInspector +
Tests if there is a path from the specified source vertex to the + specified target vertices. +
PerformanceDemo - Class in org.jgrapht.demo
A simple demo to test memory and CPU consumption on a graph with 3 million + elements.
PerformanceDemo() - +Constructor for class org.jgrapht.demo.PerformanceDemo +
  +
predecessorListOf(V) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
Returns the set of vertices which are the predecessors of a specified + vertex. +
predecessorListOf(DirectedGraph<V, E>, V) - +Static method in class org.jgrapht.Graphs +
Returns a list of vertices that are the direct predecessors of a + specified vertex. +
predecessorsOf(V) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
Returns the set of vertices which are the predecessors of a specified + vertex. +
PrefetchIterator<E> - Class in org.jgrapht.util
Utility class to help implement an iterator/enumerator in which the hasNext() + method needs to calculate the next elements ahead of time.
PrefetchIterator(PrefetchIterator.NextElementFunctor<E>) - +Constructor for class org.jgrapht.util.PrefetchIterator +
  +
PrefetchIterator.NextElementFunctor<EE> - Interface in org.jgrapht.util
 
PRINT_EDGE_LABELS - +Static variable in class org.jgrapht.ext.GmlExporter +
Option to export only the edge labels. +
PRINT_EDGE_VERTEX_LABELS - +Static variable in class org.jgrapht.ext.GmlExporter +
Option to export both edge and vertex labels. +
PRINT_NO_LABELS - +Static variable in class org.jgrapht.ext.GmlExporter +
Option to export no vertex or edge labels. +
PRINT_VERTEX_LABELS - +Static variable in class org.jgrapht.ext.GmlExporter +
Option to export only the vertex labels. +
provideNextVertex() - +Method in class org.jgrapht.traverse.BreadthFirstIterator +
  +
provideNextVertex() - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
  +
provideNextVertex() - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Returns the vertex to be returned in the following call to the iterator + next method. +
provideNextVertex() - +Method in class org.jgrapht.traverse.DepthFirstIterator +
  +
provideNextVertex() - +Method in class org.jgrapht.traverse.TopologicalOrderIterator +
  +
Pseudograph<V,E> - Class in org.jgrapht.graph
A pseudograph.
Pseudograph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.Pseudograph +
Creates a new pseudograph. +
Pseudograph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.Pseudograph +
Creates a new pseudograph with the specified edge factory. +
putSeenData(V, D) - +Method in class org.jgrapht.traverse.CrossComponentIterator +
Stores iterator-dependent data for a vertex that has been seen. +
+
+

+R

+
+
RandomGraphGenerator<V,E> - Class in org.jgrapht.generate
This Generator creates a random-topology graph of a specified number of + vertexes and edges.
RandomGraphGenerator(int, int) - +Constructor for class org.jgrapht.generate.RandomGraphGenerator +
  +
RandomGraphGenerator.DefaultEdgeTopologyFactory<VV,EE> - Class in org.jgrapht.generate
Default implementation of the EdgeTopologyFactory interface.
RandomGraphGenerator.DefaultEdgeTopologyFactory() - +Constructor for class org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory +
  +
RandomGraphGenerator.EdgeTopologyFactory<VV,EE> - Interface in org.jgrapht.generate
This class is used to generate the edge topology for a graph.
randomizer - +Variable in class org.jgrapht.generate.RandomGraphGenerator +
  +
remove() - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Unsupported. +
remove() - +Method in interface org.jgrapht.traverse.GraphIterator +
Unsupported. +
remove() - +Method in class org.jgrapht.util.PrefetchIterator +
Always throws UnsupportedOperationException. +
removeAllEdges(Collection<? extends E>) - +Method in class org.jgrapht.graph.AbstractGraph +
  +
removeAllEdges(V, V) - +Method in class org.jgrapht.graph.AbstractGraph +
  +
removeAllEdges(E[]) - +Method in class org.jgrapht.graph.AbstractGraph +
Removes all the edges in this graph that are also contained in the + specified edge array. +
removeAllEdges(Collection<? extends E>) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
removeAllEdges(V, V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
removeAllEdges(Collection<? extends E>) - +Method in interface org.jgrapht.Graph +
Removes all the edges in this graph that are also contained in the + specified edge collection. +
removeAllEdges(V, V) - +Method in interface org.jgrapht.Graph +
Removes all the edges going from the specified source vertex to the + specified target vertex, and returns a set of all removed edges. +
removeAllEdges(Collection<? extends E>) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
removeAllEdges(V, V) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
removeAllVertices(Collection<? extends V>) - +Method in class org.jgrapht.graph.AbstractGraph +
  +
removeAllVertices(Collection<? extends V>) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
removeAllVertices(Collection<? extends V>) - +Method in interface org.jgrapht.Graph +
Removes all the vertices in this graph that are also contained in the + specified vertex collection. +
removeAllVertices(Collection<? extends V>) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
removeEdge(E) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
removeEdge(E) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
removeEdge(E) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
removeEdge(E) - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
removeEdge(E) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
removeEdge(V, V) - +Method in interface org.jgrapht.Graph +
Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph. +
removeEdge(E) - +Method in interface org.jgrapht.Graph +
Removes the specified edge from the graph. +
removeEdge(E) - +Method in class org.jgrapht.graph.Subgraph +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.Subgraph +
  +
removeEdge(E) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
removeEdge(V, V) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
removeGraphListener(GraphListener<V, E>) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
removeGraphListener(GraphListener<V, E>) - +Method in interface org.jgrapht.ListenableGraph +
Removes the specified graph listener from this graph, if present. +
removeMin() - +Method in class org.jgrapht.util.FibonacciHeap +
Removes the smallest element from the heap. +
removeTraversalListener(TraversalListener<V, E>) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Removes the specified traversal listener from this iterator. +
removeTraversalListener(TraversalListener<V, E>) - +Method in interface org.jgrapht.traverse.GraphIterator +
Removes the specified traversal listener from this iterator. +
removeVertex(V) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
removeVertex(V) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
removeVertex(V) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
removeVertex(V) - +Method in class org.jgrapht.graph.GraphUnion +
Throws UnsupportedOperationException, because + GraphUnion is read-only. +
removeVertex(V) - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
removeVertex(V) - +Method in interface org.jgrapht.Graph +
Removes the specified vertex from this graph including all its touching + edges if present. +
removeVertex(V) - +Method in class org.jgrapht.graph.Subgraph +
  +
removeVertex(V) - +Method in class org.jgrapht.graph.UnmodifiableGraph +
  +
removeVertexSetListener(VertexSetListener<V>) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
  +
removeVertexSetListener(VertexSetListener<V>) - +Method in interface org.jgrapht.ListenableGraph +
Removes the specified vertex set listener from this graph, if present. +
replaceVertex(Object, Object) - +Static method in class org.jgrapht.demo.CompleteGraphDemo +
  +
RingGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a ring graph of any size.
RingGraphGenerator(int) - +Constructor for class org.jgrapht.generate.RingGraphGenerator +
Construct a new RingGraphGenerator. +
+
+

+S

+
+
ScaleFreeGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates directed or undirected scale-free network + of any size.
ScaleFreeGraphGenerator(int) - +Constructor for class org.jgrapht.generate.ScaleFreeGraphGenerator +
Constructs a new ScaleFreeGraphGenerator. +
ScaleFreeGraphGenerator(int, long) - +Constructor for class org.jgrapht.generate.ScaleFreeGraphGenerator +
Constructs a new ScaleFreeGraphGenerator using fixed + seed for the random generator. +
SECOND - +Static variable in interface org.jgrapht.util.WeightCombiner +
Second weight. +
SENTINEL - +Static variable in class org.jgrapht.traverse.DepthFirstIterator +
Sentinel object. +
setCrossComponentTraversal(boolean) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
Sets the cross component traversal flag - indicates whether to traverse + the graph across connected components. +
setCrossComponentTraversal(boolean) - +Method in class org.jgrapht.traverse.ClosestFirstIterator +
  +
setDefaultEdgeAttributes(AttributeMap) - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Sets the default edge attributes used for creating new JGraph edges. +
setDefaultVertexAttributes(AttributeMap) - +Method in class org.jgrapht.ext.JGraphModelAdapter +
Sets the default vertex attributes used for creating new JGraph vertices. +
setEdgeSetFactory(EdgeSetFactory<V, E>) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
Set the EdgeSetFactory to use for this graph. +
setEdgeWeight(E, double) - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
setEdgeWeight(E, double) - +Method in class org.jgrapht.graph.AsWeightedGraph +
  +
setEdgeWeight(E, double) - +Method in class org.jgrapht.graph.GraphDelegator +
  +
setEdgeWeight(E, double) - +Method in class org.jgrapht.graph.Subgraph +
  +
setEdgeWeight(E, double) - +Method in interface org.jgrapht.WeightedGraph +
Assigns a weight to an edge. +
setPrintLabels(Integer) - +Method in class org.jgrapht.ext.GmlExporter +
Set whether to export the vertex and edge labels. +
setReuseEvents(boolean) - +Method in class org.jgrapht.graph.DefaultListenableGraph +
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. +
setReuseEvents(boolean) - +Method in class org.jgrapht.traverse.AbstractGraphIterator +
  +
setReuseEvents(boolean) - +Method in interface org.jgrapht.traverse.GraphIterator +
Sets a value the reuseEvents flag. +
setValue(int) - +Method in class org.jgrapht.util.ModifiableInteger +
Sets a new value for this modifiable integer. +
shortestDistance(V, V) - +Method in class org.jgrapht.alg.FloydWarshallShortestPaths +
Retrieves the shortest distance between two vertices. +
SimpleDirectedGraph<V,E> - Class in org.jgrapht.graph
A simple directed graph.
SimpleDirectedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.SimpleDirectedGraph +
Creates a new simple directed graph. +
SimpleDirectedGraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.SimpleDirectedGraph +
Creates a new simple directed graph with the specified edge factory. +
SimpleDirectedWeightedGraph<V,E> - Class in org.jgrapht.graph
A simple directed weighted graph.
SimpleDirectedWeightedGraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.SimpleDirectedWeightedGraph +
Creates a new simple directed weighted graph with the specified edge + factory. +
SimpleDirectedWeightedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.SimpleDirectedWeightedGraph +
Creates a new simple directed weighted graph. +
SimpleGraph<V,E> - Class in org.jgrapht.graph
A simple graph.
SimpleGraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.SimpleGraph +
Creates a new simple graph with the specified edge factory. +
SimpleGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.SimpleGraph +
Creates a new simple graph. +
SimpleWeightedGraph<V,E> - Class in org.jgrapht.graph
A simple weighted graph.
SimpleWeightedGraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.SimpleWeightedGraph +
Creates a new simple weighted graph with the specified edge factory. +
SimpleWeightedGraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.SimpleWeightedGraph +
Creates a new simple weighted graph. +
size() - +Method in class org.jgrapht.util.FibonacciHeap +
Returns the size of the heap which is measured in the number of elements + contained in the heap. +
StarGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a star + graph of any size.
StarGraphGenerator(int) - +Constructor for class org.jgrapht.generate.StarGraphGenerator +
Creates a new StarGraphGenerator object. +
START_VERTEX - +Static variable in class org.jgrapht.generate.LinearGraphGenerator +
Role for the first vertex generated. +
startVertex - +Variable in class org.jgrapht.alg.BellmanFordShortestPath +
Start vertex. +
StringEdgeNameProvider<E> - Class in org.jgrapht.ext
Generates edge names by invoking Object.toString() on them.
StringEdgeNameProvider() - +Constructor for class org.jgrapht.ext.StringEdgeNameProvider +
  +
StringNameProvider<V> - Class in org.jgrapht.ext
Generates vertex names by invoking Object.toString() on them.
StringNameProvider() - +Constructor for class org.jgrapht.ext.StringNameProvider +
  +
StrongConnectivityInspector<V,E> - Class in org.jgrapht.alg
Complements the ConnectivityInspector class with + the capability to compute the strongly connected components of a directed + graph.
StrongConnectivityInspector(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.StrongConnectivityInspector +
The constructor of the StrongConnectivityInspector class. +
stronglyConnectedSets() - +Method in class org.jgrapht.alg.StrongConnectivityInspector +
Computes a List of Sets, where each set contains vertices + which together form a strongly connected component within the given + graph. +
stronglyConnectedSubgraphs() - +Method in class org.jgrapht.alg.StrongConnectivityInspector +
Computes a list of DirectedSubgraphs of the given graph. +
Subgraph<V,E,G extends Graph<V,E>> - Class in org.jgrapht.graph
A subgraph is a graph that has a subset of vertices and a subset of edges + with respect to some base graph.
Subgraph(G, Set<V>, Set<E>) - +Constructor for class org.jgrapht.graph.Subgraph +
Creates a new Subgraph. +
Subgraph(G, Set<V>) - +Constructor for class org.jgrapht.graph.Subgraph +
Creates a new induced Subgraph. +
successorListOf(V) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
Returns the set of vertices which are the successors of a specified + vertex. +
successorListOf(DirectedGraph<V, E>, V) - +Static method in class org.jgrapht.Graphs +
Returns a list of vertices that are the direct successors of a specified + vertex. +
successorsOf(V) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
Returns the set of vertices which are the successors of a specified + vertex. +
SUM - +Static variable in interface org.jgrapht.util.WeightCombiner +
Sum of weights. +
+
+

+T

+
+
testIncidence(Graph<V, E>, E, V) - +Static method in class org.jgrapht.Graphs +
Tests whether an edge is incident to a vertex. +
toInteger() - +Method in class org.jgrapht.util.ModifiableInteger +
Returns an Integer object representing this + ModifiableInteger's value. +
TopologicalOrderIterator<V,E> - Class in org.jgrapht.traverse
Implements topological order traversal for a directed acyclic graph.
TopologicalOrderIterator(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.traverse.TopologicalOrderIterator +
Creates a new topological order iterator over the directed graph + specified, with arbitrary tie-breaking in case of partial order. +
TopologicalOrderIterator(DirectedGraph<V, E>, Queue<V>) - +Constructor for class org.jgrapht.traverse.TopologicalOrderIterator +
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. +
toString() - +Method in class org.jgrapht.graph.AbstractGraph +
Returns a string of the parenthesized pair (V, E) representing this + G=(V,E) graph. +
toString() - +Method in class org.jgrapht.graph.AsUndirectedGraph +
  +
toString() - +Method in class org.jgrapht.graph.DefaultEdge +
  +
toString() - +Method in class org.jgrapht.graph.EdgeReversedGraph +
  +
toString() - +Method in class org.jgrapht.graph.GraphDelegator +
  +
toString() - +Method in class org.jgrapht.graph.GraphPathImpl +
  +
toString() - +Method in class org.jgrapht.util.FibonacciHeap +
Creates a String representation of this Fibonacci heap. +
toString() - +Method in class org.jgrapht.util.FibonacciHeapNode +
Return the string representation of this object. +
toString() - +Method in class org.jgrapht.util.ModifiableInteger +
Returns a String object representing this + ModifiableInteger's value. +
toStringFromSets(Collection<? extends V>, Collection<? extends E>, boolean) - +Method in class org.jgrapht.graph.AbstractGraph +
Helper for subclass implementations of toString( ). +
TransitiveClosure - Class in org.jgrapht.alg
Constructs the transitive closure of the input graph.
TraversalListener<V,E> - Interface in org.jgrapht.event
A listener on graph iterator or on a graph traverser.
TraversalListenerAdapter<V,E> - Class in org.jgrapht.event
An empty do-nothing implementation of the TraversalListener interface + used for subclasses.
TraversalListenerAdapter() - +Constructor for class org.jgrapht.event.TraversalListenerAdapter +
  +
type - +Variable in class org.jgrapht.event.GraphChangeEvent +
The type of graph change this event indicates. +
TypeUtil<T> - Class in org.jgrapht.util
TypeUtil isolates type-unsafety so that code that which uses it for + legitimate reasons can stay warning-free.
TypeUtil() - +Constructor for class org.jgrapht.util.TypeUtil +
  +
+
+

+U

+
+
uncheckedCast(Object, TypeUtil<T>) - +Static method in class org.jgrapht.util.TypeUtil +
Casts an object to a type. +
undirectedGraph(Graph<V, E>) - +Static method in class org.jgrapht.Graphs +
Returns an undirected view of the specified graph. +
UndirectedGraph<V,E> - Interface in org.jgrapht
A graph whose all edges are undirected.
UndirectedGraphUnion<V,E> - Class in org.jgrapht.graph
 
UndirectedMaskSubgraph<V,E> - Class in org.jgrapht.graph
An undirected graph that is a MaskSubgraph on another graph.
UndirectedMaskSubgraph(UndirectedGraph<V, E>, MaskFunctor<V, E>) - +Constructor for class org.jgrapht.graph.UndirectedMaskSubgraph +
  +
UndirectedSubgraph<V,E> - Class in org.jgrapht.graph
An undirected graph that is a subgraph on other graph.
UndirectedSubgraph(UndirectedGraph<V, E>, Set<V>, Set<E>) - +Constructor for class org.jgrapht.graph.UndirectedSubgraph +
Creates a new undirected subgraph. +
UndirectedWeightedSubgraph<V,E> - Class in org.jgrapht.graph
An undirected weighted graph that is a subgraph on other graph.
UndirectedWeightedSubgraph(WeightedGraph<V, E>, Set<V>, Set<E>) - +Constructor for class org.jgrapht.graph.UndirectedWeightedSubgraph +
Creates a new undirected weighted subgraph. +
union(FibonacciHeap<T>, FibonacciHeap<T>) - +Static method in class org.jgrapht.util.FibonacciHeap +
Joins two Fibonacci heaps into a new one. +
UnmodifiableDirectedGraph<V,E> - Class in org.jgrapht.graph
A directed graph that cannot be modified.
UnmodifiableDirectedGraph(DirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.UnmodifiableDirectedGraph +
Creates a new unmodifiable directed graph based on the specified backing + graph. +
UnmodifiableGraph<V,E> - Class in org.jgrapht.graph
An unmodifiable view of the backing graph specified in the constructor.
UnmodifiableGraph(Graph<V, E>) - +Constructor for class org.jgrapht.graph.UnmodifiableGraph +
Creates a new unmodifiable graph based on the specified backing graph. +
UnmodifiableUndirectedGraph<V,E> - Class in org.jgrapht.graph
An undirected graph that cannot be modified.
UnmodifiableUndirectedGraph(UndirectedGraph<V, E>) - +Constructor for class org.jgrapht.graph.UnmodifiableUndirectedGraph +
Creates a new unmodifiable undirected graph based on the specified + backing graph. +
+
+

+V

+
+
value - +Variable in class org.jgrapht.util.ModifiableInteger +
The int value represented by this ModifiableInteger. +
valueOf(String) - +Static method in enum org.jgrapht.traverse.CrossComponentIterator.VisitColor +
Returns the enum constant of this type with the specified name. +
values() - +Static method in enum org.jgrapht.traverse.CrossComponentIterator.VisitColor +
Returns an array containing the constants of this enum type, in +the order they are declared. +
vertex - +Variable in class org.jgrapht.event.GraphVertexChangeEvent +
The vertex that this event is related to. +
vertex - +Variable in class org.jgrapht.event.VertexTraversalEvent +
The traversed vertex. +
VERTEX_ADDED - +Static variable in class org.jgrapht.event.GraphVertexChangeEvent +
Vertex added event. +
VERTEX_REMOVED - +Static variable in class org.jgrapht.event.GraphVertexChangeEvent +
Vertex removed event. +
vertexAdded(GraphVertexChangeEvent<V>) - +Method in class org.jgrapht.alg.ConnectivityInspector +
  +
vertexAdded(GraphVertexChangeEvent<V>) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
  +
vertexAdded(GraphVertexChangeEvent<V>) - +Method in class org.jgrapht.alg.NeighborIndex +
  +
vertexAdded(GraphVertexChangeEvent<V>) - +Method in interface org.jgrapht.event.VertexSetListener +
Notifies that a vertex has been added to the graph. +
VertexCovers - Class in org.jgrapht.alg
Algorithms to find a vertex cover for a graph.
VertexCovers() - +Constructor for class org.jgrapht.alg.VertexCovers +
  +
VertexDegreeComparator<V,E> - Class in org.jgrapht.alg.util
Compares two vertices based on their degree.
VertexDegreeComparator(UndirectedGraph<V, E>) - +Constructor for class org.jgrapht.alg.util.VertexDegreeComparator +
Creates a comparator for comparing the degrees of vertices in the + specified graph. +
VertexDegreeComparator(UndirectedGraph<V, E>, boolean) - +Constructor for class org.jgrapht.alg.util.VertexDegreeComparator +
Creates a comparator for comparing the degrees of vertices in the + specified graph. +
VertexFactory<V> - Interface in org.jgrapht
A vertex factory used by graph algorithms for creating new vertices.
vertexFinished(VertexTraversalEvent<V>) - +Method in interface org.jgrapht.event.TraversalListener +
Called to inform the listener that the specified vertex have been + finished during the graph traversal. +
vertexFinished(VertexTraversalEvent<V>) - +Method in class org.jgrapht.event.TraversalListenerAdapter +
  +
VertexNameProvider<V> - Interface in org.jgrapht.ext
Assigns a display name for each of the graph vertices.
vertexRemoved(GraphVertexChangeEvent<V>) - +Method in class org.jgrapht.alg.ConnectivityInspector +
  +
vertexRemoved(GraphVertexChangeEvent<V>) - +Method in class org.jgrapht.alg.DirectedNeighborIndex +
  +
vertexRemoved(GraphVertexChangeEvent<V>) - +Method in class org.jgrapht.alg.NeighborIndex +
  +
vertexRemoved(GraphVertexChangeEvent<V>) - +Method in interface org.jgrapht.event.VertexSetListener +
Notifies that a vertex has been removed from the graph. +
vertexSet() - +Method in class org.jgrapht.graph.AbstractBaseGraph +
  +
vertexSet() - +Method in class org.jgrapht.graph.GraphDelegator +
  +
vertexSet() - +Method in class org.jgrapht.graph.GraphUnion +
  +
vertexSet() - +Method in class org.jgrapht.graph.MaskSubgraph +
  +
vertexSet() - +Method in class org.jgrapht.graph.Subgraph +
  +
vertexSet() - +Method in interface org.jgrapht.Graph +
Returns a set of the vertices contained in this graph. +
VertexSetListener<V> - Interface in org.jgrapht.event
A listener that is notified when the graph's vertex set changes.
VertexTraversalEvent<V> - Class in org.jgrapht.event
A traversal event for a graph vertex.
VertexTraversalEvent(Object, V) - +Constructor for class org.jgrapht.event.VertexTraversalEvent +
Creates a new VertexTraversalEvent. +
vertexTraversed(VertexTraversalEvent<V>) - +Method in interface org.jgrapht.event.TraversalListener +
Called to inform the listener that the specified vertex have been visited + during the graph traversal. +
vertexTraversed(VertexTraversalEvent<V>) - +Method in class org.jgrapht.event.TraversalListenerAdapter +
  +
VisioExporter<V,E> - Class in org.jgrapht.ext
Exports a graph to a csv format that can be imported into MS Visio.
VisioExporter(VertexNameProvider<V>) - +Constructor for class org.jgrapht.ext.VisioExporter +
Creates a new VisioExporter object with the specified naming policy. +
VisioExporter() - +Constructor for class org.jgrapht.ext.VisioExporter +
Creates a new VisioExporter object. +
+
+

+W

+
+
WeightCombiner - Interface in org.jgrapht.util
Binary operator for edge weights.
WeightedGraph<V,E> - Interface in org.jgrapht
An interface for a graph whose edges have non-uniform weights.
WeightedMultigraph<V,E> - Class in org.jgrapht.graph
A weighted multigraph.
WeightedMultigraph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.WeightedMultigraph +
Creates a new weighted multigraph with the specified edge factory. +
WeightedMultigraph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.WeightedMultigraph +
Creates a new weighted multigraph. +
WeightedPseudograph<V,E> - Class in org.jgrapht.graph
A weighted pseudograph.
WeightedPseudograph(EdgeFactory<V, E>) - +Constructor for class org.jgrapht.graph.WeightedPseudograph +
Creates a new weighted pseudograph with the specified edge factory. +
WeightedPseudograph(Class<? extends E>) - +Constructor for class org.jgrapht.graph.WeightedPseudograph +
Creates a new weighted pseudograph. +
weightMap - +Variable in class org.jgrapht.graph.AsWeightedGraph +
  +
WheelGraphGenerator<V,E> - Class in org.jgrapht.generate
Generates a wheel + graph of any size.
WheelGraphGenerator(int) - +Constructor for class org.jgrapht.generate.WheelGraphGenerator +
Creates a new WheelGraphGenerator object. +
WheelGraphGenerator(int, boolean) - +Constructor for class org.jgrapht.generate.WheelGraphGenerator +
Construct a new WheelGraphGenerator. +
+
+A B C D E F G H I J K L M N O P R S T U V W + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/index.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/index.html new file mode 100644 index 00000000..e320901f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/index.html @@ -0,0 +1,39 @@ + + + + + + +JGraphT : a free Java graph library + + + + + + + + + + + +<H2> +Frame Alert</H2> + +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. +<BR> +Link to<A HREF="overview-summary.html">Non-frame version.</A> + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/DirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/DirectedGraph.html new file mode 100644 index 00000000..02ba15bf --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/DirectedGraph.html @@ -0,0 +1,323 @@ + + + + + + +DirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface DirectedGraph<V,E>

+
+
All Superinterfaces:
Graph<V,E>
+
+
+
All Known Implementing Classes:
AsUnweightedDirectedGraph, DefaultDirectedGraph, DefaultDirectedWeightedGraph, DirectedGraphUnion, DirectedMaskSubgraph, DirectedMultigraph, DirectedPseudograph, DirectedSubgraph, DirectedWeightedMultigraph, DirectedWeightedSubgraph, EdgeReversedGraph, ListenableDirectedGraph, ListenableDirectedWeightedGraph, SimpleDirectedGraph, SimpleDirectedWeightedGraph, UnmodifiableDirectedGraph
+
+
+
+
public interface DirectedGraph<V,E>
extends Graph<V,E>
+ + +

+A graph whose all edges are directed. This is the root interface of all + directed graphs. + +

See + http://mathworld.wolfram.com/DirectedGraph.html for more on directed + graphs.

+

+ +

+

+
Since:
+
Jul 14, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.util.Set<E>incomingEdgesOf(V vertex) + +
+          Returns a set of all edges incoming into the specified vertex.
+ intinDegreeOf(V vertex) + +
+          Returns the "in degree" of the specified vertex.
+ intoutDegreeOf(V vertex) + +
+          Returns the "out degree" of the specified vertex.
+ java.util.Set<E>outgoingEdgesOf(V vertex) + +
+          Returns a set of all edges outgoing from the specified vertex.
+ + + + + + + +
Methods inherited from interface org.jgrapht.Graph
addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
+  +

+ + + + + + + + +
+Method Detail
+ +

+inDegreeOf

+
+int inDegreeOf(V vertex)
+
+
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 degree of the specified vertex.
+
+
+
+ +

+incomingEdgesOf

+
+java.util.Set<E> incomingEdgesOf(V vertex)
+
+
Returns a set of all edges incoming into the specified vertex. +

+

+
+
+
+
Parameters:
vertex - the vertex for which the list of incoming edges to be + returned. +
Returns:
a set of all edges incoming into the specified vertex.
+
+
+
+ +

+outDegreeOf

+
+int outDegreeOf(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. +

+

+
+
+
+
Parameters:
vertex - vertex whose degree is to be calculated. +
Returns:
the degree of the specified vertex.
+
+
+
+ +

+outgoingEdgesOf

+
+java.util.Set<E> outgoingEdgesOf(V vertex)
+
+
Returns a set of all edges outgoing from the specified vertex. +

+

+
+
+
+
Parameters:
vertex - the vertex for which the list of outgoing edges to be + returned. +
Returns:
a set of all edges outgoing from the specified vertex.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/EdgeFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/EdgeFactory.html new file mode 100644 index 00000000..ab1d7288 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/EdgeFactory.html @@ -0,0 +1,225 @@ + + + + + + +EdgeFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface EdgeFactory<V,E>

+
+
All Known Implementing Classes:
ClassBasedEdgeFactory
+
+
+
+
public interface EdgeFactory<V,E>
+ + +

+An edge factory used by graphs for creating new edges. +

+ +

+

+
Since:
+
Jul 14, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + +
+Method Summary
+ EcreateEdge(V sourceVertex, + V targetVertex) + +
+          Creates a new edge whose endpoints are the specified source and target + vertices.
+  +

+ + + + + + + + +
+Method Detail
+ +

+createEdge

+
+E createEdge(V sourceVertex,
+             V targetVertex)
+
+
Creates a new edge whose endpoints are the specified source and target + vertices. +

+

+
Parameters:
sourceVertex - the source vertex.
targetVertex - the target vertex. +
Returns:
a new edge whose endpoints are the specified source and target + vertices.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/Graph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/Graph.html new file mode 100644 index 00000000..8c8a97b4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/Graph.html @@ -0,0 +1,858 @@ + + + + + + +Graph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface Graph<V,E>

+
+
All Known Subinterfaces:
DirectedGraph<V,E>, ListenableGraph<V,E>, UndirectedGraph<V,E>, WeightedGraph<V,E>
+
+
+
All Known Implementing Classes:
AbstractBaseGraph, AbstractGraph, AsUndirectedGraph, AsUnweightedDirectedGraph, AsUnweightedGraph, AsWeightedGraph, BlockCutpointGraph, DefaultDirectedGraph, DefaultDirectedWeightedGraph, DefaultListenableGraph, DirectedGraphUnion, DirectedMaskSubgraph, DirectedMultigraph, DirectedPseudograph, DirectedSubgraph, DirectedWeightedMultigraph, DirectedWeightedSubgraph, EdgeReversedGraph, GraphDelegator, GraphUnion, ListenableDirectedGraph, ListenableDirectedWeightedGraph, ListenableUndirectedGraph, ListenableUndirectedWeightedGraph, MaskSubgraph, Multigraph, ParanoidGraph, Pseudograph, SimpleDirectedGraph, SimpleDirectedWeightedGraph, SimpleGraph, SimpleWeightedGraph, Subgraph, UndirectedGraphUnion, UndirectedMaskSubgraph, UndirectedSubgraph, UndirectedWeightedSubgraph, UnmodifiableDirectedGraph, UnmodifiableGraph, UnmodifiableUndirectedGraph, WeightedMultigraph, WeightedPseudograph
+
+
+
+
public interface Graph<V,E>
+ + +

+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. +

+ +

+

+
Since:
+
Jul 14, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ 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.
+ booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
+          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
+ booleanaddVertex(V v) + +
+          Adds the specified vertex to this graph if not already present.
+ booleancontainsEdge(E e) + +
+          Returns true if this graph contains the specified edge.
+ booleancontainsEdge(V sourceVertex, + V targetVertex) + +
+          Returns true if and only if this graph contains an edge going + from the source vertex to the target vertex.
+ booleancontainsVertex(V v) + +
+          Returns true if this graph contains the specified vertex.
+ java.util.Set<E>edgeSet() + +
+          Returns a set of the edges contained in this graph.
+ java.util.Set<E>edgesOf(V vertex) + +
+          Returns a set of all edges touching the specified vertex.
+ 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.
+ EgetEdge(V sourceVertex, + V targetVertex) + +
+          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
+ EdgeFactory<V,E>getEdgeFactory() + +
+          Returns the edge factory using which this graph creates new edges.
+ VgetEdgeSource(E e) + +
+          Returns the source vertex of an edge.
+ VgetEdgeTarget(E e) + +
+          Returns the target vertex of an edge.
+ doublegetEdgeWeight(E e) + +
+          Returns the weight assigned to a given edge.
+ booleanremoveAllEdges(java.util.Collection<? extends E> edges) + +
+          Removes all the edges in this graph that are also contained in the + specified edge collection.
+ 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.
+ booleanremoveAllVertices(java.util.Collection<? extends V> vertices) + +
+          Removes all the vertices in this graph that are also contained in the + specified vertex collection.
+ booleanremoveEdge(E e) + +
+          Removes the specified edge from the graph.
+ EremoveEdge(V sourceVertex, + V targetVertex) + +
+          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
+ booleanremoveVertex(V v) + +
+          Removes the specified vertex from this graph including all its touching + edges if present.
+ java.util.Set<V>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.
+
+
+
+ +

+getEdge

+
+E getEdge(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.
+
+
+
+ +

+getEdgeFactory

+
+EdgeFactory<V,E> getEdgeFactory()
+
+
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.
+
+
+
+ +

+addEdge

+
+E 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. 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.
See Also:
getEdgeFactory()
+
+
+
+ +

+addEdge

+
+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.
See Also:
addEdge(Object, Object), +getEdgeFactory()
+
+
+
+ +

+addVertex

+
+boolean addVertex(V v)
+
+
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. +

+

+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge. +
Returns:
true if this graph contains the specified edge.
+
+
+
+ +

+containsEdge

+
+boolean containsEdge(E e)
+
+
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 edge.
+
+
+
+ +

+containsVertex

+
+boolean containsVertex(V v)
+
+
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:
true if this graph contains the specified vertex.
+
+
+
+ +

+edgeSet

+
+java.util.Set<E> edgeSet()
+
+
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 edges contained in this graph.
+
+
+
+ +

+edgesOf

+
+java.util.Set<E> edgesOf(V vertex)
+
+
Returns a set of all edges touching the specified vertex. If no edges are + touching the specified vertex returns an empty set. +

+

+
Parameters:
vertex - the vertex for which a set of touching edges is to be + returned. +
Returns:
a set of all edges touching the specified vertex. +
Throws: +
java.lang.IllegalArgumentException - if vertex is not found in the graph. +
java.lang.NullPointerException - if vertex is null.
+
+
+
+ +

+removeAllEdges

+
+boolean removeAllEdges(java.util.Collection<? extends E> edges)
+
+
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.
See Also:
removeEdge(Object), +containsEdge(Object)
+
+
+
+ +

+removeAllEdges

+
+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
+
+
+
+ +

+removeAllVertices

+
+boolean removeAllVertices(java.util.Collection<? extends V> vertices)
+
+
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.
See Also:
removeVertex(Object), +containsVertex(Object)
+
+
+
+ +

+removeEdge

+
+E 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. Returns the edge if removed + or null otherwise. +

+

+
Parameters:
sourceVertex - source vertex of the edge.
targetVertex - target vertex of the edge. +
Returns:
The removed edge, or null if no edge removed.
+
+
+
+ +

+removeEdge

+
+boolean removeEdge(E e)
+
+
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.
+
+
+
+ +

+removeVertex

+
+boolean removeVertex(V v)
+
+
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.
+
+
+
+ +

+vertexSet

+
+java.util.Set<V> vertexSet()
+
+
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.
+
+
+
+ +

+getEdgeSource

+
+V getEdgeSource(E e)
+
+
Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

+

+
Parameters:
e - edge of interest +
Returns:
source vertex
+
+
+
+ +

+getEdgeTarget

+
+V getEdgeTarget(E e)
+
+
Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

+

+
Parameters:
e - edge of interest +
Returns:
target vertex
+
+
+
+ +

+getEdgeWeight

+
+double getEdgeWeight(E e)
+
+
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. +

+

+
Parameters:
e - edge of interest +
Returns:
edge weight
See Also:
WeightedGraph
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphHelper.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphHelper.html new file mode 100644 index 00000000..1dfb5d35 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphHelper.html @@ -0,0 +1,245 @@ + + + + + + +GraphHelper (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Class GraphHelper

+
+java.lang.Object
+  extended by org.jgrapht.Graphs
+      extended by org.jgrapht.GraphHelper
+
+
+Deprecated. Use Graphs instead. +

+

+
@Deprecated
+public abstract class GraphHelper
extends Graphs
+ + +

+A collection of utilities to assist the working with graphs. +

+ +

+

+
Since:
+
Jul 31, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
GraphHelper() + +
+          Deprecated.  
+  + + + + + + + +
+Method Summary
+ + + + + + + +
Methods inherited from class org.jgrapht.Graphs
addAllEdges, addAllVertices, addEdge, addEdgeWithVertices, addEdgeWithVertices, addEdgeWithVertices, addGraph, addGraphReversed, getOppositeVertex, getPathVertexList, neighborListOf, predecessorListOf, successorListOf, testIncidence, undirectedGraph
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+GraphHelper

+
+public GraphHelper()
+
+
Deprecated. 
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphMapping.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphMapping.html new file mode 100644 index 00000000..cc9ec134 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphMapping.html @@ -0,0 +1,252 @@ + + + + + + +GraphMapping (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface GraphMapping<V,E>

+
+
All Known Implementing Classes:
DefaultGraphMapping
+
+
+
+
public interface GraphMapping<V,E>
+ + +

+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). +

+ +

+

+
Since:
+
Jul 30, 2005
+
Author:
+
Assaf Lehr
+
+
+ +

+ + + + + + + + + + + + + + + + +
+Method Summary
+ EgetEdgeCorrespondence(E edge, + boolean forward) + +
+          Gets the mapped value where the key is edge
+ VgetVertexCorrespondence(V vertex, + boolean forward) + +
+          Gets the mapped value where the key is vertex
+  +

+ + + + + + + + +
+Method Detail
+ +

+getVertexCorrespondence

+
+V getVertexCorrespondence(V vertex,
+                          boolean forward)
+
+
Gets the mapped value where the key is vertex +

+

+
Parameters:
vertex - vertex in one of the graphs
forward - if true, uses mapping from graph1 to graph2; if false, use + mapping from graph2 to graph1 +
Returns:
corresponding vertex in other graph, or null if none
+
+
+
+ +

+getEdgeCorrespondence

+
+E getEdgeCorrespondence(E edge,
+                        boolean forward)
+
+
Gets the mapped value where the key is edge +

+

+
Parameters:
edge - edge in one of the graphs
forward - if true, uses mapping from graph1 to graph2; if false, use + mapping from graph2 to graph1 +
Returns:
corresponding edge in other graph, or null if none
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphPath.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphPath.html new file mode 100644 index 00000000..498bf56a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/GraphPath.html @@ -0,0 +1,321 @@ + + + + + + +GraphPath (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface GraphPath<V,E>

+
+
All Known Implementing Classes:
GraphPathImpl
+
+
+
+
public interface GraphPath<V,E>
+ + +

+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. +

+ +

+

+
Since:
+
Jan 1, 2008
+
Author:
+
John Sichi
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.util.List<E>getEdgeList() + +
+          Returns the edges making up the path.
+ VgetEndVertex() + +
+          Returns the end vertex in the path.
+ Graph<V,E>getGraph() + +
+          Returns the graph over which this path is defined.
+ VgetStartVertex() + +
+          Returns the start vertex in the path.
+ doublegetWeight() + +
+          Returns the weight assigned to the path.
+  +

+ + + + + + + + +
+Method Detail
+ +

+getGraph

+
+Graph<V,E> getGraph()
+
+
Returns the graph over which this path is defined. The path may also be + valid with respect to other graphs. +

+

+ +
Returns:
the containing graph
+
+
+
+ +

+getStartVertex

+
+V getStartVertex()
+
+
Returns the start vertex in the path. +

+

+ +
Returns:
the start vertex
+
+
+
+ +

+getEndVertex

+
+V getEndVertex()
+
+
Returns the end vertex in the path. +

+

+ +
Returns:
the end vertex
+
+
+
+ +

+getEdgeList

+
+java.util.List<E> getEdgeList()
+
+
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. +

+

+ +
Returns:
the weight of the path
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/Graphs.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/Graphs.html new file mode 100644 index 00000000..30b463f0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/Graphs.html @@ -0,0 +1,786 @@ + + + + + + +Graphs (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Class Graphs

+
+java.lang.Object
+  extended by org.jgrapht.Graphs
+
+
+
Direct Known Subclasses:
GraphHelper
+
+
+
+
public abstract class Graphs
extends java.lang.Object
+ + +

+A collection of utilities to assist with graph manipulation. +

+ +

+

+
Since:
+
Jul 31, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
Graphs() + +
+           
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+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.
+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.
+static + + + + +
+<V,E> java.util.List<V>
+
getPathVertexList(GraphPath<V,E> path) + +
+          Gets the list of vertices visited by a path.
+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.
+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.
+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.
+static + + + + +
+<V,E> boolean
+
testIncidence(Graph<V,E> g, + E e, + V v) + +
+          Tests whether an edge is incident to a vertex.
+static + + + + +
+<V,E> UndirectedGraph<V,E>
+
undirectedGraph(Graph<V,E> g) + +
+          Returns an undirected view of the specified graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+Graphs

+
+public Graphs()
+
+
+ + + + + + + + +
+Method Detail
+ +

+addEdge

+
+public 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. +

+

+
Parameters:
g - the graph for which the 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.
See Also:
Graph.addEdge(Object, Object)
+
+
+
+ +

+addEdgeWithVertices

+
+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.
+
+
+
+ +

+addEdgeWithVertices

+
+public 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. +

+

+
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.
See Also:
EdgeReversedGraph
+
+
+
+ +

+addAllEdges

+
+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.
See Also:
Graph.addVertex(Object)
+
+
+
+ +

+neighborListOf

+
+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.
+
+
+
+ +

+undirectedGraph

+
+public static <V,E> UndirectedGraph<V,E> undirectedGraph(Graph<V,E> g)
+
+
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.
See Also:
AsUndirectedGraph
+
+
+
+ +

+testIncidence

+
+public static <V,E> boolean testIncidence(Graph<V,E> g,
+                                          E e,
+                                          V v)
+
+
Tests whether an edge is incident to a vertex. +

+

+
Parameters:
g - graph containing e and v
e - edge in g
v - vertex in g +
Returns:
true iff e is incident on v
+
+
+
+ +

+getOppositeVertex

+
+public static <V,E> V getOppositeVertex(Graph<V,E> g,
+                                        E e,
+                                        V v)
+
+
Gets the vertex opposite another vertex across an edge. +

+

+
Parameters:
g - graph containing e and v
e - edge in g
v - vertex in g +
Returns:
vertex opposite to v across e
+
+
+
+ +

+getPathVertexList

+
+public static <V,E> java.util.List<V> getPathVertexList(GraphPath<V,E> path)
+
+
Gets the list of vertices visited by a path. +

+

+
Parameters:
path - path of interest +
Returns:
corresponding vertex list
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ListenableGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ListenableGraph.html new file mode 100644 index 00000000..151fe830 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ListenableGraph.html @@ -0,0 +1,309 @@ + + + + + + +ListenableGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface ListenableGraph<V,E>

+
+
All Superinterfaces:
Graph<V,E>
+
+
+
All Known Implementing Classes:
DefaultListenableGraph, ListenableDirectedGraph, ListenableDirectedWeightedGraph, ListenableUndirectedGraph, ListenableUndirectedWeightedGraph
+
+
+
+
public interface ListenableGraph<V,E>
extends Graph<V,E>
+ + +

+A graph that supports listeners on structural change events. +

+ +

+

+
Since:
+
Jul 20, 2003
+
Author:
+
Barak Naveh
+
See Also:
GraphListener, +VertexSetListener
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidaddGraphListener(GraphListener<V,E> l) + +
+          Adds the specified graph listener to this graph, if not already present.
+ voidaddVertexSetListener(VertexSetListener<V> l) + +
+          Adds the specified vertex set listener to this graph, if not already + present.
+ voidremoveGraphListener(GraphListener<V,E> l) + +
+          Removes the specified graph listener from this graph, if present.
+ voidremoveVertexSetListener(VertexSetListener<V> l) + +
+          Removes the specified vertex set listener from this graph, if present.
+ + + + + + + +
Methods inherited from interface org.jgrapht.Graph
addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
+  +

+ + + + + + + + +
+Method Detail
+ +

+addGraphListener

+
+void addGraphListener(GraphListener<V,E> l)
+
+
Adds the specified graph listener to this graph, if not already present. +

+

+
+
+
+
Parameters:
l - the listener to be added.
+
+
+
+ +

+addVertexSetListener

+
+void addVertexSetListener(VertexSetListener<V> l)
+
+
Adds the specified vertex set listener to this graph, if not already + present. +

+

+
+
+
+
Parameters:
l - the listener to be added.
+
+
+
+ +

+removeGraphListener

+
+void removeGraphListener(GraphListener<V,E> l)
+
+
Removes the specified graph listener from this graph, if present. +

+

+
+
+
+
Parameters:
l - the listener to be removed.
+
+
+
+ +

+removeVertexSetListener

+
+void removeVertexSetListener(VertexSetListener<V> l)
+
+
Removes the specified vertex set listener from this graph, if present. +

+

+
+
+
+
Parameters:
l - the listener to be removed.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/UndirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/UndirectedGraph.html new file mode 100644 index 00000000..7a801135 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/UndirectedGraph.html @@ -0,0 +1,241 @@ + + + + + + +UndirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface UndirectedGraph<V,E>

+
+
All Superinterfaces:
Graph<V,E>
+
+
+
All Known Implementing Classes:
AsUndirectedGraph, BlockCutpointGraph, ListenableUndirectedGraph, ListenableUndirectedWeightedGraph, Multigraph, Pseudograph, SimpleGraph, SimpleWeightedGraph, UndirectedGraphUnion, UndirectedMaskSubgraph, UndirectedSubgraph, UndirectedWeightedSubgraph, UnmodifiableUndirectedGraph, WeightedMultigraph, WeightedPseudograph
+
+
+
+
public interface UndirectedGraph<V,E>
extends Graph<V,E>
+ + +

+A graph whose all edges are undirected. This is the root interface of all + undirected graphs. + +

See + http://mathworld.wolfram.com/Graph.html for more on undirected and on + directed graphs.

+

+ +

+

+
Since:
+
Jul 14, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + +
+Method Summary
+ intdegreeOf(V vertex) + +
+          Returns the degree of the specified vertex.
+ + + + + + + +
Methods inherited from interface org.jgrapht.Graph
addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
+  +

+ + + + + + + + +
+Method Detail
+ +

+degreeOf

+
+int degreeOf(V vertex)
+
+
Returns the degree of the specified vertex. A degree of a vertex in an + undirected graph is the number of edges touching that vertex. +

+

+
+
+
+
Parameters:
vertex - vertex whose degree is to be calculated. +
Returns:
the degree of the specified vertex.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/VertexFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/VertexFactory.html new file mode 100644 index 00000000..c918cf77 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/VertexFactory.html @@ -0,0 +1,222 @@ + + + + + + +VertexFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface VertexFactory<V>

+
+
All Known Implementing Classes:
ClassBasedVertexFactory
+
+
+
+
public interface VertexFactory<V>
+ + +

+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. +

+ +

+

+
Since:
+
Sep 16, 2003
+
Author:
+
John V. Sichi
+
+
+ +

+ + + + + + + + + + + + +
+Method Summary
+ VcreateVertex() + +
+          Creates a new vertex.
+  +

+ + + + + + + + +
+Method Detail
+ +

+createVertex

+
+V createVertex()
+
+
Creates a new vertex. +

+

+ +
Returns:
the new vertex
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/WeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/WeightedGraph.html new file mode 100644 index 00000000..8cc67c63 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/WeightedGraph.html @@ -0,0 +1,274 @@ + + + + + + +WeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht +
+Interface WeightedGraph<V,E>

+
+
All Superinterfaces:
Graph<V,E>
+
+
+
All Known Implementing Classes:
AsWeightedGraph, DefaultDirectedWeightedGraph, DirectedWeightedMultigraph, DirectedWeightedSubgraph, ListenableDirectedWeightedGraph, ListenableUndirectedWeightedGraph, SimpleDirectedWeightedGraph, SimpleWeightedGraph, UndirectedWeightedSubgraph, WeightedMultigraph, WeightedPseudograph
+
+
+
+
public interface WeightedGraph<V,E>
extends Graph<V,E>
+ + +

+An interface for a graph whose edges have non-uniform weights. +

+ +

+

+
Since:
+
Jul 23, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + +
+Field Summary
+static doubleDEFAULT_EDGE_WEIGHT + +
+          The default weight for an edge.
+  + + + + + + + + + + + +
+Method Summary
+ voidsetEdgeWeight(E e, + double weight) + +
+          Assigns a weight to an edge.
+ + + + + + + +
Methods inherited from interface org.jgrapht.Graph
addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
+  +

+ + + + + + + + +
+Field Detail
+ +

+DEFAULT_EDGE_WEIGHT

+
+static final double DEFAULT_EDGE_WEIGHT
+
+
The default weight for an edge. +

+

+
See Also:
Constant Field Values
+
+ + + + + + + + +
+Method Detail
+ +

+setEdgeWeight

+
+void setEdgeWeight(E e,
+                   double weight)
+
+
Assigns a weight to an edge. +

+

+
+
+
+
Parameters:
e - edge on which to set weight
weight - new weight for edge
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BellmanFordShortestPath.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BellmanFordShortestPath.html new file mode 100644 index 00000000..2124e778 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BellmanFordShortestPath.html @@ -0,0 +1,431 @@ + + + + + + +BellmanFordShortestPath (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class BellmanFordShortestPath<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.BellmanFordShortestPath<V,E>
+
+
+
+
public class BellmanFordShortestPath<V,E>
extends java.lang.Object
+ + +

+Bellman-Ford + algorithm: weights could be negative, paths could be constrained by a + maximum number of edges. +

+ +

+


+ +

+ + + + + + + + + + + + + + + +
+Field Summary
+protected  Graph<V,E>graph + +
+          Graph on which shortest paths are searched.
+protected  VstartVertex + +
+          Start vertex.
+  + + + + + + + + + + + + + + + + +
+Constructor Summary
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.
+ doublegetCost(V endVertex) + +
+           
+ java.util.List<E>getPathEdgeList(V endVertex) + +
+           
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+graph

+
+protected Graph<V,E> graph
+
+
Graph on which shortest paths are searched. +

+

+
+
+
+ +

+startVertex

+
+protected V startVertex
+
+
Start vertex. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+BellmanFordShortestPath

+
+public 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. +

+

+
Parameters:
graph -
startVertex -
+
+
+ +

+BellmanFordShortestPath

+
+public 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. +

+

+
Parameters:
graph -
startVertex -
nMaxHops - maximum number of edges of the calculated paths.
+
+
+ +

+BellmanFordShortestPath

+
+public 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. +

+

+
Parameters:
graph -
startVertex -
nMaxHops - maximum number of edges of the calculated paths.
epsilon - tolerance factor.
+
+ + + + + + + + +
+Method Detail
+ +

+getCost

+
+public double getCost(V endVertex)
+
+
+
Parameters:
endVertex - end vertex. +
Returns:
the cost of the shortest path between the start vertex and the + end vertex.
+
+
+
+ +

+getPathEdgeList

+
+public java.util.List<E> getPathEdgeList(V endVertex)
+
+
+
Parameters:
endVertex - end vertex. +
Returns:
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 +
Returns:
List of Edges, or null if no path exists
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BiconnectivityInspector.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BiconnectivityInspector.html new file mode 100644 index 00000000..87ad1328 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BiconnectivityInspector.html @@ -0,0 +1,334 @@ + + + + + + +BiconnectivityInspector (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class BiconnectivityInspector<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.BiconnectivityInspector<V,E>
+
+
+
+
public class BiconnectivityInspector<V,E>
extends java.lang.Object
+ + +

+Inspects a graph for the biconnectivity property. See BlockCutpointGraph for more information. A biconnected graph has only one + block (i.e. no cutpoints). +

+ +

+

+
Since:
+
July 5, 2007
+
Author:
+
Guillaume Boulmier
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
BiconnectivityInspector(UndirectedGraph<V,E> graph) + +
+          Running time = O(m) where m is the number of edges.
+  + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.util.Set<java.util.Set<V>>getBiconnectedVertexComponents() + +
+          Returns the biconnected vertex-components of the graph.
+ java.util.Set<java.util.Set<V>>getBiconnectedVertexComponents(V vertex) + +
+          Returns the biconnected vertex-components containing the vertex.
+ java.util.Set<V>getCutpoints() + +
+          Returns the cutpoints of the graph.
+ booleanisBiconnected() + +
+          Returns true if the graph is biconnected (no cutpoint), + false otherwise.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+BiconnectivityInspector

+
+public BiconnectivityInspector(UndirectedGraph<V,E> graph)
+
+
Running time = O(m) where m is the number of edges. +

+

+ + + + + + + + +
+Method Detail
+ +

+getBiconnectedVertexComponents

+
+public java.util.Set<java.util.Set<V>> getBiconnectedVertexComponents()
+
+
Returns the biconnected vertex-components of the graph. +

+

+
+
+
+
+ +

+getBiconnectedVertexComponents

+
+public java.util.Set<java.util.Set<V>> getBiconnectedVertexComponents(V vertex)
+
+
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.
+
+
+
+ +

+getCutpoints

+
+public java.util.Set<V> getCutpoints()
+
+
Returns the cutpoints of the graph. +

+

+
+
+
+
+ +

+isBiconnected

+
+public boolean isBiconnected()
+
+
Returns true if the graph is biconnected (no cutpoint), + false otherwise. +

+

+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BlockCutpointGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BlockCutpointGraph.html new file mode 100644 index 00000000..a62e20e5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BlockCutpointGraph.html @@ -0,0 +1,369 @@ + + + + + + +BlockCutpointGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class BlockCutpointGraph<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.graph.AbstractGraph<V,E>
+      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
+          extended by org.jgrapht.graph.SimpleGraph<UndirectedGraph<V,E>,DefaultEdge>
+              extended by org.jgrapht.alg.BlockCutpointGraph<V,E>
+
+
+
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Graph<UndirectedGraph<V,E>,DefaultEdge>, UndirectedGraph<UndirectedGraph<V,E>,DefaultEdge>
+
+
+
+
public class BlockCutpointGraph<V,E>
extends SimpleGraph<UndirectedGraph<V,E>,DefaultEdge>
+ + +

+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.
  • +
+

+ +

+

+
Since:
+
July 5, 2007
+
Author:
+
Guillaume Boulmier
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
BlockCutpointGraph(UndirectedGraph<V,E> graph) + +
+          Running time = O(m) where m is the number of edges.
+  + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ UndirectedGraph<V,E>getBlock(V vertex) + +
+          Returns the vertex if vertex is a cutpoint, and otherwise returns the + block (biconnected component) containing the vertex.
+ java.util.Set<V>getCutpoints() + +
+          Returns the cutpoints of the initial graph.
+ booleanisCutpoint(V vertex) + +
+          Returns true if the vertex is a cutpoint, false + otherwise.
+ + + + + + + +
Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
+ + + + + + + +
Methods inherited from class org.jgrapht.graph.AbstractGraph
assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+ + + + + + + +
Methods inherited from interface org.jgrapht.UndirectedGraph
degreeOf
+ + + + + + + +
Methods inherited from interface org.jgrapht.Graph
addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+BlockCutpointGraph

+
+public BlockCutpointGraph(UndirectedGraph<V,E> graph)
+
+
Running time = O(m) where m is the number of edges. +

+

+ + + + + + + + +
+Method Detail
+ +

+getBlock

+
+public UndirectedGraph<V,E> getBlock(V vertex)
+
+
Returns the vertex if vertex is a cutpoint, and otherwise returns the + block (biconnected component) containing the vertex. +

+

+
Parameters:
vertex - vertex in the initial graph.
+
+
+
+ +

+getCutpoints

+
+public java.util.Set<V> getCutpoints()
+
+
Returns the cutpoints of the initial graph. +

+

+
+
+
+
+ +

+isCutpoint

+
+public boolean isCutpoint(V vertex)
+
+
Returns true if the vertex is a cutpoint, false + otherwise. +

+

+
Parameters:
vertex - vertex in the initial graph.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BronKerboschCliqueFinder.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BronKerboschCliqueFinder.html new file mode 100644 index 00000000..63b9aac3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/BronKerboschCliqueFinder.html @@ -0,0 +1,295 @@ + + + + + + +BronKerboschCliqueFinder (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class BronKerboschCliqueFinder<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.BronKerboschCliqueFinder<V,E>
+
+
+
+
public class BronKerboschCliqueFinder<V,E>
extends java.lang.Object
+ + +

+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
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
BronKerboschCliqueFinder(Graph<V,E> graph) + +
+          Creates a new clique finder.
+  + + + + + + + + + + + + + + + +
+Method Summary
+ java.util.Collection<java.util.Set<V>>getAllMaximalCliques() + +
+          Finds all maximal cliques of the graph.
+ java.util.Collection<java.util.Set<V>>getBiggestMaximalCliques() + +
+          Finds the biggest maximal cliques of the graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+BronKerboschCliqueFinder

+
+public BronKerboschCliqueFinder(Graph<V,E> graph)
+
+
Creates a new clique finder. +

+

+
Parameters:
graph - the graph in which cliques are to be found; graph must be + simple
+
+ + + + + + + + +
+Method Detail
+ +

+getAllMaximalCliques

+
+public java.util.Collection<java.util.Set<V>> getAllMaximalCliques()
+
+
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)
+
+
+
+ +

+getBiggestMaximalCliques

+
+public java.util.Collection<java.util.Set<V>> getBiggestMaximalCliques()
+
+
Finds the biggest maximal cliques of the graph. +

+

+ +
Returns:
Collection of cliques (each of which is represented as a Set of + vertices)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/ChromaticNumber.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/ChromaticNumber.html new file mode 100644 index 00000000..502e82c2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/ChromaticNumber.html @@ -0,0 +1,276 @@ + + + + + + +ChromaticNumber (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class ChromaticNumber

+
+java.lang.Object
+  extended by org.jgrapht.alg.ChromaticNumber
+
+
+
+
public abstract class ChromaticNumber
extends java.lang.Object
+ + +

+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. +

+ +

+

+
Since:
+
Dec 21, 2008
+
Author:
+
Andrew Newell
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
ChromaticNumber() + +
+           
+  + + + + + + + + + + + +
+Method Summary
+static + + + + +
+<V,E> int
+
findGreedyChromaticNumber(UndirectedGraph<V,E> g) + +
+          Finds the number of colors required for a greedy coloring of the graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+ChromaticNumber

+
+public ChromaticNumber()
+
+
+ + + + + + + + +
+Method Detail
+ +

+findGreedyChromaticNumber

+
+public static <V,E> int findGreedyChromaticNumber(UndirectedGraph<V,E> g)
+
+
Finds the number of colors required for a greedy coloring of the graph. +

+

+
Parameters:
g - an undirected graph to find the chromatic number of +
Returns:
integer the approximate chromatic number from the greedy + algorithm
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/ConnectivityInspector.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/ConnectivityInspector.html new file mode 100644 index 00000000..47ea74e4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/ConnectivityInspector.html @@ -0,0 +1,505 @@ + + + + + + +ConnectivityInspector (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class ConnectivityInspector<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.ConnectivityInspector<V,E>
+
+
+
All Implemented Interfaces:
java.util.EventListener, GraphListener<V,E>, VertexSetListener<V>
+
+
+
+
public class ConnectivityInspector<V,E>
extends java.lang.Object
implements GraphListener<V,E>
+ + +

+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.

+

+ +

+

+
Since:
+
Aug 6, 2003
+
Author:
+
Barak Naveh, John V. Sichi
+
+
+ +

+ + + + + + + + + + + + + + +
+Constructor Summary
ConnectivityInspector(DirectedGraph<V,E> g) + +
+          Creates a connectivity inspector for the specified directed graph.
ConnectivityInspector(UndirectedGraph<V,E> g) + +
+          Creates a connectivity inspector for the specified undirected graph.
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.util.Set<V>connectedSetOf(V vertex) + +
+          Returns a set of all vertices that are in the maximally connected + component together with the specified vertex.
+ java.util.List<java.util.Set<V>>connectedSets() + +
+          Returns a list of Set s, where each set contains all + vertices that are in the same maximally connected component.
+ voidedgeAdded(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been added to the graph.
+ voidedgeRemoved(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been removed from the graph.
+ booleanisGraphConnected() + +
+          Test if the inspected graph is connected.
+ booleanpathExists(V sourceVertex, + V targetVertex) + +
+          Tests if there is a path from the specified source vertex to the + specified target vertices.
+ voidvertexAdded(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been added to the graph.
+ voidvertexRemoved(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been removed from the graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+ConnectivityInspector

+
+public ConnectivityInspector(UndirectedGraph<V,E> g)
+
+
Creates a connectivity inspector for the specified undirected graph. +

+

+
Parameters:
g - the graph for which a connectivity inspector to be created.
+
+
+ +

+ConnectivityInspector

+
+public ConnectivityInspector(DirectedGraph<V,E> g)
+
+
Creates a connectivity inspector for the specified directed graph. +

+

+
Parameters:
g - the graph for which a connectivity inspector to be created.
+
+ + + + + + + + +
+Method Detail
+ +

+isGraphConnected

+
+public boolean isGraphConnected()
+
+
Test if the inspected graph is connected. An empty graph is not + considered connected. +

+

+
+
+
+ +
Returns:
true if and only if inspected graph is connected.
+
+
+
+ +

+connectedSetOf

+
+public java.util.Set<V> connectedSetOf(V vertex)
+
+
Returns a set of all vertices that are in the maximally connected + component together with the specified vertex. For more on maximally + connected component, see + http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html. +

+

+
+
+
+
Parameters:
vertex - the vertex for which the connected set to be returned. +
Returns:
a set of all vertices that are in the maximally connected + component together with the specified vertex.
+
+
+
+ +

+connectedSets

+
+public java.util.List<java.util.Set<V>> connectedSets()
+
+
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.
+
+
+
+ +

+edgeAdded

+
+public void edgeAdded(GraphEdgeChangeEvent<V,E> e)
+
+
Description copied from interface: GraphListener
+
Notifies that an edge has been added to the graph. +

+

+
Specified by:
edgeAdded in interface GraphListener<V,E>
+
+
+
Parameters:
e - the edge event.
See Also:
GraphListener.edgeAdded(GraphEdgeChangeEvent)
+
+
+
+ +

+edgeRemoved

+
+public void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
+
+
Description copied from interface: GraphListener
+
Notifies that an edge has been removed from the graph. +

+

+
Specified by:
edgeRemoved in interface GraphListener<V,E>
+
+
+
Parameters:
e - the edge event.
See Also:
GraphListener.edgeRemoved(GraphEdgeChangeEvent)
+
+
+
+ +

+pathExists

+
+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.
+
+
+
+ +

+vertexAdded

+
+public void vertexAdded(GraphVertexChangeEvent<V> e)
+
+
Description copied from interface: VertexSetListener
+
Notifies that a vertex has been added to the graph. +

+

+
Specified by:
vertexAdded in interface VertexSetListener<V>
+
+
+
Parameters:
e - the vertex event.
See Also:
VertexSetListener.vertexAdded(GraphVertexChangeEvent)
+
+
+
+ +

+vertexRemoved

+
+public void vertexRemoved(GraphVertexChangeEvent<V> e)
+
+
Description copied from interface: VertexSetListener
+
Notifies that a vertex has been removed from the graph. +

+

+
Specified by:
vertexRemoved in interface VertexSetListener<V>
+
+
+
Parameters:
e - the vertex event.
See Also:
VertexSetListener.vertexRemoved(GraphVertexChangeEvent)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/CycleDetector.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/CycleDetector.html new file mode 100644 index 00000000..fa926996 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/CycleDetector.html @@ -0,0 +1,345 @@ + + + + + + +CycleDetector (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class CycleDetector<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.CycleDetector<V,E>
+
+
+
+
public class CycleDetector<V,E>
extends java.lang.Object
+ + +

+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. +

+ +

+

+
Since:
+
Sept 16, 2004
+
Author:
+
John V. Sichi
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
CycleDetector(DirectedGraph<V,E> graph) + +
+          Creates a cycle detector for the specified graph.
+  + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ booleandetectCycles() + +
+          Performs yes/no cycle detection on the entire graph.
+ booleandetectCyclesContainingVertex(V v) + +
+          Performs yes/no cycle detection on an individual vertex.
+ java.util.Set<V>findCycles() + +
+          Finds the vertex set for the subgraph of all cycles.
+ java.util.Set<V>findCyclesContainingVertex(V v) + +
+          Finds the vertex set for the subgraph of all cycles which contain a + particular vertex.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+CycleDetector

+
+public CycleDetector(DirectedGraph<V,E> graph)
+
+
Creates a cycle detector for the specified graph. Currently only directed + graphs are supported. +

+

+
Parameters:
graph - the DirectedGraph in which to detect cycles
+
+ + + + + + + + +
+Method Detail
+ +

+detectCycles

+
+public boolean detectCycles()
+
+
Performs yes/no cycle detection on the entire graph. +

+

+ +
Returns:
true iff the graph contains at least one cycle
+
+
+
+ +

+detectCyclesContainingVertex

+
+public boolean detectCyclesContainingVertex(V v)
+
+
Performs yes/no cycle detection on an individual vertex. +

+

+
Parameters:
v - the vertex to test +
Returns:
true if v is on at least one cycle
+
+
+
+ +

+findCycles

+
+public java.util.Set<V> findCycles()
+
+
Finds the vertex set for the subgraph of all cycles. +

+

+ +
Returns:
set of all vertices which participate in at least one cycle in + this graph
+
+
+
+ +

+findCyclesContainingVertex

+
+public java.util.Set<V> findCyclesContainingVertex(V v)
+
+
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
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/DijkstraShortestPath.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/DijkstraShortestPath.html new file mode 100644 index 00000000..2be80ca1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/DijkstraShortestPath.html @@ -0,0 +1,382 @@ + + + + + + +DijkstraShortestPath (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class DijkstraShortestPath<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.DijkstraShortestPath<V,E>
+
+
+
+
public final class DijkstraShortestPath<V,E>
extends java.lang.Object
+ + +

+An implementation of Dijkstra's + shortest path algorithm using ClosestFirstIterator. +

+ +

+

+
Since:
+
Sep 2, 2003
+
Author:
+
John V. Sichi
+
+
+ +

+ + + + + + + + + + + + + + +
+Constructor Summary
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.
+ GraphPath<V,E>getPath() + +
+          Return the path found.
+ java.util.List<E>getPathEdgeList() + +
+          Return the edges making up the path found.
+ doublegetPathLength() + +
+          Return the length of the path found.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+DijkstraShortestPath

+
+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
+
+ + + + + + + + +
+Method Detail
+ +

+getPathEdgeList

+
+public java.util.List<E> getPathEdgeList()
+
+
Return the edges making up the path found. +

+

+ +
Returns:
List of Edges, or null if no path exists
+
+
+
+ +

+getPath

+
+public GraphPath<V,E> getPath()
+
+
Return the path found. +

+

+ +
Returns:
path representation, or null if no path exists
+
+
+
+ +

+getPathLength

+
+public double getPathLength()
+
+
Return the length of the path found. +

+

+ +
Returns:
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 +
Returns:
List of Edges, or null if no path exists
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/DirectedNeighborIndex.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/DirectedNeighborIndex.html new file mode 100644 index 00000000..8bb8c2b9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/DirectedNeighborIndex.html @@ -0,0 +1,475 @@ + + + + + + +DirectedNeighborIndex (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class DirectedNeighborIndex<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.DirectedNeighborIndex<V,E>
+
+
+
All Implemented Interfaces:
java.util.EventListener, GraphListener<V,E>, VertexSetListener<V>
+
+
+
+
public class DirectedNeighborIndex<V,E>
extends java.lang.Object
implements GraphListener<V,E>
+ + +

+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.

+

+ +

+

+
Since:
+
Dec 13, 2005
+
Author:
+
Charles Fry
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
DirectedNeighborIndex(DirectedGraph<V,E> g) + +
+          Creates a neighbor index for the specified directed graph.
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidedgeAdded(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been added to the graph.
+ voidedgeRemoved(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been removed from the graph.
+ java.util.List<V>predecessorListOf(V v) + +
+          Returns the set of vertices which are the predecessors of a specified + vertex.
+ java.util.Set<V>predecessorsOf(V v) + +
+          Returns the set of vertices which are the predecessors of a specified + vertex.
+ java.util.List<V>successorListOf(V v) + +
+          Returns the set of vertices which are the successors of a specified + vertex.
+ java.util.Set<V>successorsOf(V v) + +
+          Returns the set of vertices which are the successors of a specified + vertex.
+ voidvertexAdded(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been added to the graph.
+ voidvertexRemoved(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been removed from the graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+DirectedNeighborIndex

+
+public DirectedNeighborIndex(DirectedGraph<V,E> g)
+
+
Creates a neighbor index for the specified directed graph. +

+

+
Parameters:
g - the graph for which a neighbor index is to be created.
+
+ + + + + + + + +
+Method Detail
+ +

+predecessorsOf

+
+public java.util.Set<V> predecessorsOf(V v)
+
+
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. +

+

+
+
+
+
Parameters:
v - the vertex whose predecessors are desired +
Returns:
all unique predecessors of the specified vertex
+
+
+
+ +

+predecessorListOf

+
+public java.util.List<V> predecessorListOf(V v)
+
+
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. +

+

+
+
+
+
Parameters:
v - the vertex whose predecessors are desired +
Returns:
all predecessors of the specified vertex
+
+
+
+ +

+successorsOf

+
+public java.util.Set<V> successorsOf(V v)
+
+
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. +

+

+
+
+
+
Parameters:
v - the vertex whose successors are desired +
Returns:
all unique successors of the specified vertex
+
+
+
+ +

+successorListOf

+
+public java.util.List<V> successorListOf(V v)
+
+
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. +

+

+
+
+
+
Parameters:
v - the vertex whose successors are desired +
Returns:
all successors of the specified vertex
+
+
+
+ +

+edgeAdded

+
+public void edgeAdded(GraphEdgeChangeEvent<V,E> e)
+
+
Description copied from interface: GraphListener
+
Notifies that an edge has been added to the graph. +

+

+
Specified by:
edgeAdded in interface GraphListener<V,E>
+
+
+
Parameters:
e - the edge event.
See Also:
GraphListener.edgeAdded(GraphEdgeChangeEvent)
+
+
+
+ +

+edgeRemoved

+
+public void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
+
+
Description copied from interface: GraphListener
+
Notifies that an edge has been removed from the graph. +

+

+
Specified by:
edgeRemoved in interface GraphListener<V,E>
+
+
+
Parameters:
e - the edge event.
See Also:
GraphListener.edgeRemoved(GraphEdgeChangeEvent)
+
+
+
+ +

+vertexAdded

+
+public void vertexAdded(GraphVertexChangeEvent<V> e)
+
+
Description copied from interface: VertexSetListener
+
Notifies that a vertex has been added to the graph. +

+

+
Specified by:
vertexAdded in interface VertexSetListener<V>
+
+
+
Parameters:
e - the vertex event.
See Also:
VertexSetListener.vertexAdded(GraphVertexChangeEvent)
+
+
+
+ +

+vertexRemoved

+
+public void vertexRemoved(GraphVertexChangeEvent<V> e)
+
+
Description copied from interface: VertexSetListener
+
Notifies that a vertex has been removed from the graph. +

+

+
Specified by:
vertexRemoved in interface VertexSetListener<V>
+
+
+
Parameters:
e - the vertex event.
See Also:
VertexSetListener.vertexRemoved(GraphVertexChangeEvent)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/EdmondsKarpMaximumFlow.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/EdmondsKarpMaximumFlow.html new file mode 100644 index 00000000..357e230b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/EdmondsKarpMaximumFlow.html @@ -0,0 +1,448 @@ + + + + + + +EdmondsKarpMaximumFlow (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class EdmondsKarpMaximumFlow<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.EdmondsKarpMaximumFlow<V,E>
+
+
+
+
public final class EdmondsKarpMaximumFlow<V,E>
extends java.lang.Object
+ + +

+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). +

+ +

+


+ +

+ + + + + + + + + + + +
+Field Summary
+static doubleDEFAULT_EPSILON + +
+          Default tolerance.
+  + + + + + + + + + + + + + +
+Constructor Summary
EdmondsKarpMaximumFlow(DirectedGraph<V,E> network) + +
+          Constructs MaximumFlow instance to work with a copy of + network.
EdmondsKarpMaximumFlow(DirectedGraph<V,E> network, + double epsilon) + +
+          Constructs MaximumFlow instance to work with a copy of + network.
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidcalculateMaximumFlow(V source, + V sink) + +
+          Sets current source to source, current sink to sink, + then calculates maximum flow from source to sink.
+ VgetCurrentSink() + +
+          Returns current sink vertex, or null if there was no + calculateMaximumFlow calls.
+ VgetCurrentSource() + +
+          Returns current source vertex, or null if there was no + calculateMaximumFlow calls.
+ java.util.Map<E,java.lang.Double>getMaximumFlow() + +
+          Returns maximum flow, that was calculated during last + calculateMaximumFlow call, or null, if there was no + calculateMaximumFlow calls.
+ java.lang.DoublegetMaximumFlowValue() + +
+          Returns maximum flow value, that was calculated during last + calculateMaximumFlow call, or null, if there was no + calculateMaximumFlow calls.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+DEFAULT_EPSILON

+
+public static final double DEFAULT_EPSILON
+
+
Default tolerance. +

+

+
See Also:
Constant Field Values
+
+ + + + + + + + +
+Constructor Detail
+ +

+EdmondsKarpMaximumFlow

+
+public EdmondsKarpMaximumFlow(DirectedGraph<V,E> network)
+
+
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
+
+
+ +

+EdmondsKarpMaximumFlow

+
+public EdmondsKarpMaximumFlow(DirectedGraph<V,E> network,
+                              double epsilon)
+
+
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. +

+

+ +
Returns:
maximum flow value
+
+
+
+ +

+getMaximumFlow

+
+public java.util.Map<E,java.lang.Double> getMaximumFlow()
+
+
Returns maximum flow, that was calculated during last + calculateMaximumFlow call, or null, if there was no + calculateMaximumFlow calls. +

+

+ +
Returns:
read-only mapping from edges to doubles - flow values
+
+
+
+ +

+getCurrentSource

+
+public V getCurrentSource()
+
+
Returns current source vertex, or null if there was no + calculateMaximumFlow calls. +

+

+ +
Returns:
current source
+
+
+
+ +

+getCurrentSink

+
+public V getCurrentSink()
+
+
Returns current sink vertex, or null if there was no + calculateMaximumFlow calls. +

+

+ +
Returns:
current sink
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/EulerianCircuit.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/EulerianCircuit.html new file mode 100644 index 00000000..3c1b70e5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/EulerianCircuit.html @@ -0,0 +1,306 @@ + + + + + + +EulerianCircuit (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class EulerianCircuit

+
+java.lang.Object
+  extended by org.jgrapht.alg.EulerianCircuit
+
+
+
+
public abstract class EulerianCircuit
extends java.lang.Object
+ + +

+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. +

+ +

+

+
Since:
+
Dec 21, 2008
+
Author:
+
Andrew Newell
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
EulerianCircuit() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+static + + + + +
+<V,E> java.util.List<V>
+
getEulerianCircuitVertices(UndirectedGraph<V,E> g) + +
+          This method will return a list of vertices which represents the Eulerian + circuit of the graph.
+static + + + + +
+<V,E> boolean
+
isEulerian(UndirectedGraph<V,E> g) + +
+          This method will check whether the graph passed in is Eulerian or not.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+EulerianCircuit

+
+public EulerianCircuit()
+
+
+ + + + + + + + +
+Method Detail
+ +

+isEulerian

+
+public static <V,E> boolean isEulerian(UndirectedGraph<V,E> g)
+
+
This method will check whether the graph passed in is Eulerian or not. +

+

+
Parameters:
g - The graph to be checked +
Returns:
true for Eulerian and false for non-Eulerian
+
+
+
+ +

+getEulerianCircuitVertices

+
+public static <V,E> java.util.List<V> getEulerianCircuitVertices(UndirectedGraph<V,E> g)
+
+
This method will return a list of vertices which represents the Eulerian + circuit of the graph. +

+

+
Parameters:
g - The graph to find an Eulerian circuit +
Returns:
null if no Eulerian circuit exists, or a list of vertices + representing the Eulerian circuit if one does exist
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/FloydWarshallShortestPaths.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/FloydWarshallShortestPaths.html new file mode 100644 index 00000000..b93ebbb0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/FloydWarshallShortestPaths.html @@ -0,0 +1,289 @@ + + + + + + +FloydWarshallShortestPaths (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class FloydWarshallShortestPaths<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.FloydWarshallShortestPaths<V,E>
+
+
+
+
public class FloydWarshallShortestPaths<V,E>
extends java.lang.Object
+ + +

+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. +

+ +

+

+
Author:
+
Tom Larkworthy
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
FloydWarshallShortestPaths(Graph<V,E> g) + +
+          Constructs the shortest path array for the given graph.
+  + + + + + + + + + + + + + + + +
+Method Summary
+ doublegetDiameter() + +
+           
+ doubleshortestDistance(V v1, + V v2) + +
+          Retrieves the shortest distance between two vertices.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+FloydWarshallShortestPaths

+
+public FloydWarshallShortestPaths(Graph<V,E> g)
+
+
Constructs the shortest path array for the given graph. +

+

+
Parameters:
g - input graph
+
+ + + + + + + + +
+Method Detail
+ +

+shortestDistance

+
+public double shortestDistance(V v1,
+                               V v2)
+
+
Retrieves the shortest distance between two vertices. +

+

+
Parameters:
v1 - first vertex
v2 - second vertex +
Returns:
distance, or positive infinity if no path
+
+
+
+ +

+getDiameter

+
+public double getDiameter()
+
+
+ +
Returns:
diameter computed for the graph
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/HamiltonianCycle.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/HamiltonianCycle.html new file mode 100644 index 00000000..4c2c9cb0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/HamiltonianCycle.html @@ -0,0 +1,279 @@ + + + + + + +HamiltonianCycle (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class HamiltonianCycle

+
+java.lang.Object
+  extended by org.jgrapht.alg.HamiltonianCycle
+
+
+
+
public class HamiltonianCycle
extends java.lang.Object
+ + +

+This class will deal with finding the optimal or approximately optimal + minimum tour (hamiltonian cycle) or commonly known as the Traveling + Salesman Problem. +

+ +

+

+
Author:
+
Andrew Newell
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
HamiltonianCycle() + +
+           
+  + + + + + + + + + + + +
+Method Summary
+static + + + + +
+<V,E> java.util.List<V>
+
getApproximateOptimalForCompleteGraph(SimpleWeightedGraph<V,E> g) + +
+          This method will return an approximate minimal traveling salesman tour + (hamiltonian cycle).
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+HamiltonianCycle

+
+public HamiltonianCycle()
+
+
+ + + + + + + + +
+Method Detail
+ +

+getApproximateOptimalForCompleteGraph

+
+public static <V,E> java.util.List<V> getApproximateOptimalForCompleteGraph(SimpleWeightedGraph<V,E> g)
+
+
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) +
+
Type Parameters:
V -
E -
Parameters:
g - is the graph to find the optimal tour for. +
Returns:
The optimal tour as a list of vertices.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/KShortestPaths.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/KShortestPaths.html new file mode 100644 index 00000000..7a778e2a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/KShortestPaths.html @@ -0,0 +1,313 @@ + + + + + + +KShortestPaths (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class KShortestPaths<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.KShortestPaths<V,E>
+
+
+
+
public class KShortestPaths<V,E>
extends java.lang.Object
+ + +

+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.
+  + + + + + + + + + + + +
+Method Summary
+ java.util.List<GraphPath<V,E>>getPaths(V endVertex) + +
+          Returns the k shortest simple paths in increasing order of weight.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+KShortestPaths

+
+public KShortestPaths(Graph<V,E> graph,
+                      V startVertex,
+                      int k)
+
+
Creates an object to compute ranking shortest paths between the start + vertex and others vertices. +

+

+
Parameters:
graph -
startVertex -
k - number of paths to be computed.
+
+
+ +

+KShortestPaths

+
+public 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. +

+

+
Parameters:
graph - graph on which shortest paths are searched.
startVertex - start vertex of the calculated paths.
nPaths - number of ranking paths between the start vertex and an end + vertex.
nMaxHops - maximum number of edges of the calculated paths. +
Throws: +
java.lang.NullPointerException - if the specified graph or startVertex is + null. +
java.lang.IllegalArgumentException - if nPaths is negative or 0. +
java.lang.IllegalArgumentException - if nMaxHops is negative or 0.
+
+ + + + + + + + +
+Method Detail
+ +

+getPaths

+
+public java.util.List<GraphPath<V,E>> getPaths(V endVertex)
+
+
Returns the k shortest simple paths in increasing order of weight. +

+

+
Parameters:
endVertex - target vertex of the calculated paths. +
Returns:
list of paths, or null if no path exists between the + start vertex and the end vertex.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/NeighborIndex.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/NeighborIndex.html new file mode 100644 index 00000000..ea6fab0e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/NeighborIndex.html @@ -0,0 +1,415 @@ + + + + + + +NeighborIndex (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class NeighborIndex<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.NeighborIndex<V,E>
+
+
+
All Implemented Interfaces:
java.util.EventListener, GraphListener<V,E>, VertexSetListener<V>
+
+
+
+
public class NeighborIndex<V,E>
extends java.lang.Object
implements GraphListener<V,E>
+ + +

+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.
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidedgeAdded(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been added to the graph.
+ voidedgeRemoved(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been removed from the graph.
+ java.util.List<V>neighborListOf(V v) + +
+          Returns a list of vertices which are adjacent to a specified vertex.
+ java.util.Set<V>neighborsOf(V v) + +
+          Returns the set of vertices which are adjacent to a specified vertex.
+ voidvertexAdded(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been added to the graph.
+ voidvertexRemoved(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been removed from the graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+NeighborIndex

+
+public NeighborIndex(Graph<V,E> g)
+
+
Creates a neighbor index for the specified undirected graph. +

+

+
Parameters:
g - the graph for which a neighbor index is to be created.
+
+ + + + + + + + +
+Method Detail
+ +

+neighborsOf

+
+public java.util.Set<V> neighborsOf(V v)
+
+
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. +

+

+
+
+
+
Parameters:
v - the vertex whose neighbors are desired +
Returns:
all unique neighbors of the specified vertex
+
+
+
+ +

+neighborListOf

+
+public java.util.List<V> neighborListOf(V v)
+
+
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. +

+

+
+
+
+
Parameters:
v - the vertex whose neighbors are desired +
Returns:
all neighbors of the specified vertex
+
+
+
+ +

+edgeAdded

+
+public void edgeAdded(GraphEdgeChangeEvent<V,E> e)
+
+
Description copied from interface: GraphListener
+
Notifies that an edge has been added to the graph. +

+

+
Specified by:
edgeAdded in interface GraphListener<V,E>
+
+
+
Parameters:
e - the edge event.
See Also:
GraphListener.edgeAdded(GraphEdgeChangeEvent)
+
+
+
+ +

+edgeRemoved

+
+public void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
+
+
Description copied from interface: GraphListener
+
Notifies that an edge has been removed from the graph. +

+

+
Specified by:
edgeRemoved in interface GraphListener<V,E>
+
+
+
Parameters:
e - the edge event.
See Also:
GraphListener.edgeRemoved(GraphEdgeChangeEvent)
+
+
+
+ +

+vertexAdded

+
+public void vertexAdded(GraphVertexChangeEvent<V> e)
+
+
Description copied from interface: VertexSetListener
+
Notifies that a vertex has been added to the graph. +

+

+
Specified by:
vertexAdded in interface VertexSetListener<V>
+
+
+
Parameters:
e - the vertex event.
See Also:
VertexSetListener.vertexAdded(GraphVertexChangeEvent)
+
+
+
+ +

+vertexRemoved

+
+public void vertexRemoved(GraphVertexChangeEvent<V> e)
+
+
Description copied from interface: VertexSetListener
+
Notifies that a vertex has been removed from the graph. +

+

+
Specified by:
vertexRemoved in interface VertexSetListener<V>
+
+
+
Parameters:
e - the vertex event.
See Also:
VertexSetListener.vertexRemoved(GraphVertexChangeEvent)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/StrongConnectivityInspector.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/StrongConnectivityInspector.html new file mode 100644 index 00000000..8cb4ba35 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/StrongConnectivityInspector.html @@ -0,0 +1,356 @@ + + + + + + +StrongConnectivityInspector (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class StrongConnectivityInspector<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.StrongConnectivityInspector<V,E>
+
+
+
+
public class StrongConnectivityInspector<V,E>
extends java.lang.Object
+ + +

+

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).

+ +

Unlike ConnectivityInspector, this class does not + implement incremental inspection. The full algorithm is executed at the first + call of stronglyConnectedSets() or isStronglyConnected().

+

+ +

+

+
Since:
+
Feb 2, 2005
+
Author:
+
Christian Soltenborn, Christian Hammer
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
StrongConnectivityInspector(DirectedGraph<V,E> directedGraph) + +
+          The constructor of the StrongConnectivityInspector class.
+  + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ DirectedGraph<V,E>getGraph() + +
+          Returns the graph inspected by the StrongConnectivityInspector.
+ booleanisStronglyConnected() + +
+          Returns true if the graph of this + StronglyConnectivityInspector instance is strongly connected.
+ java.util.List<java.util.Set<V>>stronglyConnectedSets() + +
+          Computes a List of Sets, where each set contains vertices + which together form a strongly connected component within the given + graph.
+ java.util.List<DirectedSubgraph<V,E>>stronglyConnectedSubgraphs() + +
+          Computes a list of DirectedSubgraphs of the given graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+StrongConnectivityInspector

+
+public StrongConnectivityInspector(DirectedGraph<V,E> directedGraph)
+
+
The constructor of the StrongConnectivityInspector class. +

+

+
Parameters:
directedGraph - the graph to inspect +
Throws: +
java.lang.IllegalArgumentException
+
+ + + + + + + + +
+Method Detail
+ +

+getGraph

+
+public DirectedGraph<V,E> getGraph()
+
+
Returns the graph inspected by the StrongConnectivityInspector. +

+

+ +
Returns:
the graph inspected by this StrongConnectivityInspector
+
+
+
+ +

+isStronglyConnected

+
+public boolean isStronglyConnected()
+
+
Returns true if the graph of this + StronglyConnectivityInspector instance is strongly connected. +

+

+ +
Returns:
true if the graph is strongly connected, false otherwise
+
+
+
+ +

+stronglyConnectedSets

+
+public java.util.List<java.util.Set<V>> stronglyConnectedSets()
+
+
Computes a List of Sets, where each set contains vertices + which together form a strongly connected component within the given + graph. +

+

+ +
Returns:
List of Set s containing the strongly + connected components
+
+
+
+ +

+stronglyConnectedSubgraphs

+
+public java.util.List<DirectedSubgraph<V,E>> stronglyConnectedSubgraphs()
+
+

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
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/TransitiveClosure.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/TransitiveClosure.html new file mode 100644 index 00000000..a37adb43 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/TransitiveClosure.html @@ -0,0 +1,274 @@ + + + + + + +TransitiveClosure (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class TransitiveClosure

+
+java.lang.Object
+  extended by org.jgrapht.alg.TransitiveClosure
+
+
+
+
public class TransitiveClosure
extends java.lang.Object
+ + +

+Constructs the transitive closure of the input graph. +

+ +

+

+
Since:
+
May 5, 2007
+
Author:
+
Vinayak R. Borkar
+
+
+ +

+ + + + + + + + + + + +
+Field Summary
+static TransitiveClosureINSTANCE + +
+          Singleton instance.
+  + + + + + + + + + + + +
+Method Summary
+ + + + + +
+<V,E> void
+
closeSimpleDirectedGraph(SimpleDirectedGraph<V,E> graph) + +
+          Computes the transitive closure of the given graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+INSTANCE

+
+public static final TransitiveClosure INSTANCE
+
+
Singleton instance. +

+

+
+
+ + + + + + + + +
+Method Detail
+ +

+closeSimpleDirectedGraph

+
+public <V,E> void closeSimpleDirectedGraph(SimpleDirectedGraph<V,E> graph)
+
+
Computes the transitive closure of the given graph. +

+

+
Parameters:
graph - - Graph to compute transitive closure for.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/VertexCovers.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/VertexCovers.html new file mode 100644 index 00000000..412c7998 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/VertexCovers.html @@ -0,0 +1,324 @@ + + + + + + +VertexCovers (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg +
+Class VertexCovers

+
+java.lang.Object
+  extended by org.jgrapht.alg.VertexCovers
+
+
+
+
public abstract class VertexCovers
extends java.lang.Object
+ + +

+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 +

+ +

+

+
Since:
+
Nov 6, 2003
+
Author:
+
Linda Buisman
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
VertexCovers() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+static + + + + +
+<V,E> java.util.Set<V>
+
find2ApproximationCover(Graph<V,E> g) + +
+          Finds a 2-approximation for a minimal vertex cover of the specified + graph.
+static + + + + +
+<V,E> java.util.Set<V>
+
findGreedyCover(UndirectedGraph<V,E> g) + +
+          Finds a greedy approximation for a minimal vertex cover of a specified + graph.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+VertexCovers

+
+public VertexCovers()
+
+
+ + + + + + + + +
+Method Detail
+ +

+find2ApproximationCover

+
+public static <V,E> java.util.Set<V> find2ApproximationCover(Graph<V,E> g)
+
+
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. + +

For more details see Jenny Walter, CMPU-240: Lecture notes for + Language Theory and Computation, Fall 2002, Vassar College, + http://www.cs.vassar.edu/~walter/cs241index/lectures/PDF/approx.pdf. +

+

+

+
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.
+
+
+
+ +

+findGreedyCover

+
+public static <V,E> java.util.Set<V> findGreedyCover(UndirectedGraph<V,E> g)
+
+
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.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-frame.html new file mode 100644 index 00000000..2aec5db2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-frame.html @@ -0,0 +1,66 @@ + + + + + + +org.jgrapht.alg (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.alg + + + + +
+Classes  + +
+BellmanFordShortestPath +
+BiconnectivityInspector +
+BlockCutpointGraph +
+BronKerboschCliqueFinder +
+ChromaticNumber +
+ConnectivityInspector +
+CycleDetector +
+DijkstraShortestPath +
+DirectedNeighborIndex +
+EdmondsKarpMaximumFlow +
+EulerianCircuit +
+FloydWarshallShortestPaths +
+HamiltonianCycle +
+KShortestPaths +
+NeighborIndex +
+StrongConnectivityInspector +
+TransitiveClosure +
+VertexCovers
+ + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-summary.html new file mode 100644 index 00000000..bf022fac --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-summary.html @@ -0,0 +1,263 @@ + + + + + + +org.jgrapht.alg (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package org.jgrapht.alg +

+Algorithms provided with JGraphT. +

+See: +
+          Description +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class Summary
BellmanFordShortestPath<V,E>Bellman-Ford + algorithm: weights could be negative, paths could be constrained by a + maximum number of edges.
BiconnectivityInspector<V,E>Inspects a graph for the biconnectivity property.
BlockCutpointGraph<V,E>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.
BronKerboschCliqueFinder<V,E>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.
ChromaticNumberAllows the + chromatic number of a graph to be calculated.
ConnectivityInspector<V,E>Allows obtaining various connectivity aspects of a graph.
CycleDetector<V,E>Performs cycle detection on a graph.
DijkstraShortestPath<V,E>An implementation of Dijkstra's + shortest path algorithm using ClosestFirstIterator.
DirectedNeighborIndex<V,E>Maintains a cache of each vertex's neighbors.
EdmondsKarpMaximumFlow<V,E>A flow network is a + directed graph where each edge has a capacity and each edge receives a flow.
EulerianCircuitThis algorithm will check whether a graph is Eulerian (hence it contains an + Eulerian + circuit).
FloydWarshallShortestPaths<V,E>The + Floyd-Warshall algorithm finds all shortest paths (all n^2 of them) in + O(n^3) time.
HamiltonianCycleThis class will deal with finding the optimal or approximately optimal + minimum tour (hamiltonian cycle) or commonly known as the Traveling + Salesman Problem.
KShortestPaths<V,E>The algorithm determines the k shortest simple paths in increasing order of + weight.
NeighborIndex<V,E>Maintains a cache of each vertex's neighbors.
StrongConnectivityInspector<V,E>Complements the ConnectivityInspector class with + the capability to compute the strongly connected components of a directed + graph.
TransitiveClosureConstructs the transitive closure of the input graph.
VertexCoversAlgorithms to find a vertex cover for a graph.
+  + +

+

+Package org.jgrapht.alg Description +

+ +

+Algorithms provided with JGraphT. +

+ +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-tree.html new file mode 100644 index 00000000..59708ff4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/package-tree.html @@ -0,0 +1,163 @@ + + + + + + +org.jgrapht.alg Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package org.jgrapht.alg +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/VertexDegreeComparator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/VertexDegreeComparator.html new file mode 100644 index 00000000..529217fb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/VertexDegreeComparator.html @@ -0,0 +1,317 @@ + + + + + + +VertexDegreeComparator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.alg.util +
+Class VertexDegreeComparator<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.alg.util.VertexDegreeComparator<V,E>
+
+
+
All Implemented Interfaces:
java.util.Comparator<V>
+
+
+
+
public class VertexDegreeComparator<V,E>
extends java.lang.Object
implements java.util.Comparator<V>
+ + +

+Compares two vertices based on their degree. + +

Used by greedy algorithms that need to sort vertices by their degree. Two + vertices are considered equal if their degrees are equal.

+

+ +

+

+
Since:
+
Nov 6, 2003
+
Author:
+
Linda Buisman
+
+
+ +

+ + + + + + + + + + + + + + +
+Constructor Summary
VertexDegreeComparator(UndirectedGraph<V,E> g) + +
+          Creates a comparator for comparing the degrees of vertices in the + specified graph.
VertexDegreeComparator(UndirectedGraph<V,E> g, + boolean ascendingOrder) + +
+          Creates a comparator for comparing the degrees of vertices in the + specified graph.
+  + + + + + + + + + + + +
+Method Summary
+ intcompare(V v1, + V v2) + +
+          Compare the degrees of v1 and v2, taking into + account whether ascending or descending order is used.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+ + + + + + + +
Methods inherited from interface java.util.Comparator
equals
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+VertexDegreeComparator

+
+public VertexDegreeComparator(UndirectedGraph<V,E> g)
+
+
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.
+
+
+ +

+VertexDegreeComparator

+
+public VertexDegreeComparator(UndirectedGraph<V,E> g,
+                              boolean ascendingOrder)
+
+
Creates a comparator for comparing the degrees of vertices in the + specified graph. +

+

+
Parameters:
g - graph with respect to which the degree is calculated.
ascendingOrder - true - compares in ascending order of degrees + (lowest first), false - compares in descending order of degrees (highest + first).
+
+ + + + + + + + +
+Method Detail
+ +

+compare

+
+public int compare(V v1,
+                   V v2)
+
+
Compare the degrees of v1 and v2, taking into + account whether ascending or descending order is used. +

+

+
Specified by:
compare in interface java.util.Comparator<V>
+
+
+
Parameters:
v1 - the first vertex to be compared.
v2 - the second vertex to be compared. +
Returns:
-1 if v1 comes before v2, +1 if + v1 comes after v2, 0 if equal.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-frame.html new file mode 100644 index 00000000..292f2c50 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-frame.html @@ -0,0 +1,32 @@ + + + + + + +org.jgrapht.alg.util (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.alg.util + + + + +
+Classes  + +
+VertexDegreeComparator
+ + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-summary.html new file mode 100644 index 00000000..d11b6f4b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-summary.html @@ -0,0 +1,170 @@ + + + + + + +org.jgrapht.alg.util (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package org.jgrapht.alg.util +

+Utilities used by JGraphT algorithms. +

+See: +
+          Description +

+ + + + + + + + + +
+Class Summary
VertexDegreeComparator<V,E>Compares two vertices based on their degree.
+  + +

+

+Package org.jgrapht.alg.util Description +

+ +

+Utilities used by JGraphT algorithms. +

+ +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-tree.html new file mode 100644 index 00000000..e4897b09 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/alg/util/package-tree.html @@ -0,0 +1,152 @@ + + + + + + +org.jgrapht.alg.util Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package org.jgrapht.alg.util +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/CompleteGraphDemo.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/CompleteGraphDemo.html new file mode 100644 index 00000000..1efa4e6c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/CompleteGraphDemo.html @@ -0,0 +1,271 @@ + + + + + + +CompleteGraphDemo (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.demo +
+Class CompleteGraphDemo

+
+java.lang.Object
+  extended by org.jgrapht.demo.CompleteGraphDemo
+
+
+
+
public final class CompleteGraphDemo
extends java.lang.Object
+ + +

+


+ +

+ + + + + + + + + + + +
+Constructor Summary
CompleteGraphDemo() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+static voidmain(java.lang.String[] args) + +
+           
+static booleanreplaceVertex(java.lang.Object oldVertex, + java.lang.Object newVertex) + +
+           
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+CompleteGraphDemo

+
+public CompleteGraphDemo()
+
+
+ + + + + + + + +
+Method Detail
+ +

+main

+
+public static void main(java.lang.String[] args)
+
+
+
+
+
+
+ +

+replaceVertex

+
+public static boolean replaceVertex(java.lang.Object oldVertex,
+                                    java.lang.Object newVertex)
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/HelloJGraphT.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/HelloJGraphT.html new file mode 100644 index 00000000..0185c3ad --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/HelloJGraphT.html @@ -0,0 +1,229 @@ + + + + + + +HelloJGraphT (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.demo +
+Class HelloJGraphT

+
+java.lang.Object
+  extended by org.jgrapht.demo.HelloJGraphT
+
+
+
+
public final class HelloJGraphT
extends java.lang.Object
+ + +

+A simple introduction to using JGraphT. +

+ +

+

+
Since:
+
Jul 27, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + +
+Method Summary
+static voidmain(java.lang.String[] args) + +
+          The starting point for the demo.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Method Detail
+ +

+main

+
+public static void main(java.lang.String[] args)
+
+
The starting point for the demo. +

+

+
Parameters:
args - ignored.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/JGraphAdapterDemo.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/JGraphAdapterDemo.html new file mode 100644 index 00000000..52f9d196 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/JGraphAdapterDemo.html @@ -0,0 +1,436 @@ + + + + + + +JGraphAdapterDemo (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.demo +
+Class JGraphAdapterDemo

+
+java.lang.Object
+  extended by java.awt.Component
+      extended by java.awt.Container
+          extended by java.awt.Panel
+              extended by java.applet.Applet
+                  extended by javax.swing.JApplet
+                      extended by org.jgrapht.demo.JGraphAdapterDemo
+
+
+
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer
+
+
+
+
public class JGraphAdapterDemo
extends javax.swing.JApplet
+ + +

+A demo applet that shows how to use JGraph to visualize JGraphT graphs. +

+ +

+

+
Since:
+
Aug 3, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + +
+Nested Class Summary
+ + + + + + + +
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
+  + + + + + + + + +
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
+  + + + + + + + + +
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
+  + + + + + + + + +
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
+  + + + + + + + + +
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
+  + + + + + + + +
+Field Summary
+ + + + + + + +
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
+ + + + + + + +
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
+ + + + + + + +
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
+  + + + + + + + + + + +
+Constructor Summary
JGraphAdapterDemo() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+ voidinit() + +
+          
+static voidmain(java.lang.String[] args) + +
+          An alternative starting point for this demo, to also allow running this + applet as an application.
+ + + + + + + +
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
+ + + + + + + +
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
+ + + + + + + +
Methods inherited from class java.awt.Panel
addNotify
+ + + + + + + +
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
+ + + + + + + +
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+JGraphAdapterDemo

+
+public JGraphAdapterDemo()
+
+
+ + + + + + + + +
+Method Detail
+ +

+main

+
+public static void main(java.lang.String[] args)
+
+
An alternative starting point for this demo, to also allow running this + applet as an application. +

+

+
Parameters:
args - ignored.
+
+
+
+ +

+init

+
+public void init()
+
+
+

+

+
Overrides:
init in class java.applet.Applet
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/PerformanceDemo.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/PerformanceDemo.html new file mode 100644 index 00000000..fc07430b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/PerformanceDemo.html @@ -0,0 +1,272 @@ + + + + + + +PerformanceDemo (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.demo +
+Class PerformanceDemo

+
+java.lang.Object
+  extended by org.jgrapht.demo.PerformanceDemo
+
+
+
+
public final class PerformanceDemo
extends java.lang.Object
+ + +

+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.

+

+ +

+

+
Since:
+
Aug 10, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
PerformanceDemo() + +
+           
+  + + + + + + + + + + + +
+Method Summary
+static voidmain(java.lang.String[] args) + +
+          The starting point for the demo.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+PerformanceDemo

+
+public PerformanceDemo()
+
+
+ + + + + + + + +
+Method Detail
+ +

+main

+
+public static void main(java.lang.String[] args)
+
+
The starting point for the demo. +

+

+
Parameters:
args - ignored.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-frame.html new file mode 100644 index 00000000..05982d0e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-frame.html @@ -0,0 +1,38 @@ + + + + + + +org.jgrapht.demo (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.demo + + + + +
+Classes  + +
+CompleteGraphDemo +
+HelloJGraphT +
+JGraphAdapterDemo +
+PerformanceDemo
+ + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-summary.html new file mode 100644 index 00000000..be92c423 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-summary.html @@ -0,0 +1,183 @@ + + + + + + +org.jgrapht.demo (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package org.jgrapht.demo +

+Demo programs that help to get started with JGraphT. +

+See: +
+          Description +

+ + + + + + + + + + + + + + + + + + + + + +
+Class Summary
CompleteGraphDemo 
HelloJGraphTA simple introduction to using JGraphT.
JGraphAdapterDemoA demo applet that shows how to use JGraph to visualize JGraphT graphs.
PerformanceDemoA simple demo to test memory and CPU consumption on a graph with 3 million + elements.
+  + +

+

+Package org.jgrapht.demo Description +

+ +

+Demo programs that help to get started with JGraphT. +

+ +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-tree.html new file mode 100644 index 00000000..0e61ec6c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/demo/package-tree.html @@ -0,0 +1,164 @@ + + + + + + +org.jgrapht.demo Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package org.jgrapht.demo +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+
    +
  • java.lang.Object
      +
    • org.jgrapht.demo.CompleteGraphDemo
    • java.awt.Component (implements java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable) +
        +
      • java.awt.Container
          +
        • java.awt.Panel (implements javax.accessibility.Accessible) +
            +
          • java.applet.Applet
              +
            • javax.swing.JApplet (implements javax.accessibility.Accessible, javax.swing.RootPaneContainer) + +
            +
          +
        +
      +
    • org.jgrapht.demo.HelloJGraphT
    • org.jgrapht.demo.PerformanceDemo
    +
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/ConnectedComponentTraversalEvent.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/ConnectedComponentTraversalEvent.html new file mode 100644 index 00000000..c6640de6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/ConnectedComponentTraversalEvent.html @@ -0,0 +1,349 @@ + + + + + + +ConnectedComponentTraversalEvent (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class ConnectedComponentTraversalEvent

+
+java.lang.Object
+  extended by java.util.EventObject
+      extended by org.jgrapht.event.ConnectedComponentTraversalEvent
+
+
+
All Implemented Interfaces:
java.io.Serializable
+
+
+
+
public class ConnectedComponentTraversalEvent
extends java.util.EventObject
+ + +

+A traversal event with respect to a connected component. +

+ +

+

+
Since:
+
Aug 11, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + + + + + +
+Field Summary
+static intCONNECTED_COMPONENT_FINISHED + +
+          Connected component traversal finished event.
+static intCONNECTED_COMPONENT_STARTED + +
+          Connected component traversal started event.
+ + + + + + + +
Fields inherited from class java.util.EventObject
source
+  + + + + + + + + + + +
+Constructor Summary
ConnectedComponentTraversalEvent(java.lang.Object eventSource, + int type) + +
+          Creates a new ConnectedComponentTraversalEvent.
+  + + + + + + + + + + + +
+Method Summary
+ intgetType() + +
+          Returns the event type.
+ + + + + + + +
Methods inherited from class java.util.EventObject
getSource, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+CONNECTED_COMPONENT_STARTED

+
+public static final int CONNECTED_COMPONENT_STARTED
+
+
Connected component traversal started event. +

+

+
See Also:
Constant Field Values
+
+
+ +

+CONNECTED_COMPONENT_FINISHED

+
+public static final int CONNECTED_COMPONENT_FINISHED
+
+
Connected component traversal finished event. +

+

+
See Also:
Constant Field Values
+
+ + + + + + + + +
+Constructor Detail
+ +

+ConnectedComponentTraversalEvent

+
+public ConnectedComponentTraversalEvent(java.lang.Object eventSource,
+                                        int type)
+
+
Creates a new ConnectedComponentTraversalEvent. +

+

+
Parameters:
eventSource - the source of the event.
type - the type of event.
+
+ + + + + + + + +
+Method Detail
+ +

+getType

+
+public int getType()
+
+
Returns the event type. +

+

+ +
Returns:
the event type.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/EdgeTraversalEvent.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/EdgeTraversalEvent.html new file mode 100644 index 00000000..d9d856e4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/EdgeTraversalEvent.html @@ -0,0 +1,329 @@ + + + + + + +EdgeTraversalEvent (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class EdgeTraversalEvent<V,E>

+
+java.lang.Object
+  extended by java.util.EventObject
+      extended by org.jgrapht.event.EdgeTraversalEvent<V,E>
+
+
+
All Implemented Interfaces:
java.io.Serializable
+
+
+
+
public class EdgeTraversalEvent<V,E>
extends java.util.EventObject
+ + +

+A traversal event for a graph edge. +

+ +

+

+
Since:
+
Aug 11, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + +
+Field Summary
+protected  Eedge + +
+          The traversed edge.
+ + + + + + + +
Fields inherited from class java.util.EventObject
source
+  + + + + + + + + + + +
+Constructor Summary
EdgeTraversalEvent(java.lang.Object eventSource, + E edge) + +
+          Creates a new EdgeTraversalEvent.
+  + + + + + + + + + + + +
+Method Summary
+ EgetEdge() + +
+          Returns the traversed edge.
+ + + + + + + +
Methods inherited from class java.util.EventObject
getSource, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+edge

+
+protected E edge
+
+
The traversed edge. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+EdgeTraversalEvent

+
+public EdgeTraversalEvent(java.lang.Object eventSource,
+                          E edge)
+
+
Creates a new EdgeTraversalEvent. +

+

+
Parameters:
eventSource - the source of the event.
edge - the traversed edge.
+
+ + + + + + + + +
+Method Detail
+ +

+getEdge

+
+public E getEdge()
+
+
Returns the traversed edge. +

+

+ +
Returns:
the traversed edge.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphChangeEvent.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphChangeEvent.html new file mode 100644 index 00000000..306ad4e5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphChangeEvent.html @@ -0,0 +1,333 @@ + + + + + + +GraphChangeEvent (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class GraphChangeEvent

+
+java.lang.Object
+  extended by java.util.EventObject
+      extended by org.jgrapht.event.GraphChangeEvent
+
+
+
All Implemented Interfaces:
java.io.Serializable
+
+
+
Direct Known Subclasses:
GraphEdgeChangeEvent, GraphVertexChangeEvent
+
+
+
+
public class GraphChangeEvent
extends java.util.EventObject
+ + +

+An event which indicates that a graph has changed. This class is a root for + graph change events. +

+ +

+

+
Since:
+
Aug 10, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + +
+Field Summary
+protected  inttype + +
+          The type of graph change this event indicates.
+ + + + + + + +
Fields inherited from class java.util.EventObject
source
+  + + + + + + + + + + +
+Constructor Summary
GraphChangeEvent(java.lang.Object eventSource, + int type) + +
+          Creates a new graph change event.
+  + + + + + + + + + + + +
+Method Summary
+ intgetType() + +
+          Returns the event type.
+ + + + + + + +
Methods inherited from class java.util.EventObject
getSource, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+type

+
+protected int type
+
+
The type of graph change this event indicates. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+GraphChangeEvent

+
+public GraphChangeEvent(java.lang.Object eventSource,
+                        int type)
+
+
Creates a new graph change event. +

+

+
Parameters:
eventSource - the source of the event.
type - the type of event.
+
+ + + + + + + + +
+Method Detail
+ +

+getType

+
+public int getType()
+
+
Returns the event type. +

+

+ +
Returns:
the event type.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphEdgeChangeEvent.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphEdgeChangeEvent.html new file mode 100644 index 00000000..4806ffea --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphEdgeChangeEvent.html @@ -0,0 +1,436 @@ + + + + + + +GraphEdgeChangeEvent (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class GraphEdgeChangeEvent<V,E>

+
+java.lang.Object
+  extended by java.util.EventObject
+      extended by org.jgrapht.event.GraphChangeEvent
+          extended by org.jgrapht.event.GraphEdgeChangeEvent<V,E>
+
+
+
All Implemented Interfaces:
java.io.Serializable
+
+
+
+
public class GraphEdgeChangeEvent<V,E>
extends GraphChangeEvent
+ + +

+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. +

+ +

+

+
Since:
+
Aug 10, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Field Summary
+static intBEFORE_EDGE_ADDED + +
+          Before edge added event.
+static intBEFORE_EDGE_REMOVED + +
+          Before edge removed event.
+protected  Eedge + +
+          The edge that this event is related to.
+static intEDGE_ADDED + +
+          Edge added event.
+static intEDGE_REMOVED + +
+          Edge removed event.
+ + + + + + + +
Fields inherited from class org.jgrapht.event.GraphChangeEvent
type
+ + + + + + + +
Fields inherited from class java.util.EventObject
source
+  + + + + + + + + + + +
+Constructor Summary
GraphEdgeChangeEvent(java.lang.Object eventSource, + int type, + E e) + +
+          Constructor for GraphEdgeChangeEvent.
+  + + + + + + + + + + + +
+Method Summary
+ EgetEdge() + +
+          Returns the edge that this event is related to.
+ + + + + + + +
Methods inherited from class org.jgrapht.event.GraphChangeEvent
getType
+ + + + + + + +
Methods inherited from class java.util.EventObject
getSource, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+BEFORE_EDGE_ADDED

+
+public static final int BEFORE_EDGE_ADDED
+
+
Before edge added event. This event is fired before an edge is added to a + graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+BEFORE_EDGE_REMOVED

+
+public static final int BEFORE_EDGE_REMOVED
+
+
Before edge removed event. This event is fired before an edge is removed + from a graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+EDGE_ADDED

+
+public static final int EDGE_ADDED
+
+
Edge added event. This event is fired after an edge is added to a graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+EDGE_REMOVED

+
+public static final int EDGE_REMOVED
+
+
Edge removed event. This event is fired after an edge is removed from a + graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+edge

+
+protected E edge
+
+
The edge that this event is related to. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+GraphEdgeChangeEvent

+
+public GraphEdgeChangeEvent(java.lang.Object eventSource,
+                            int type,
+                            E e)
+
+
Constructor for GraphEdgeChangeEvent. +

+

+
Parameters:
eventSource - the source of this event.
type - the event type of this event.
e - the edge that this event is related to.
+
+ + + + + + + + +
+Method Detail
+ +

+getEdge

+
+public E getEdge()
+
+
Returns the edge that this event is related to. +

+

+ +
Returns:
the edge that this event is related to.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphListener.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphListener.html new file mode 100644 index 00000000..871d2c4d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphListener.html @@ -0,0 +1,261 @@ + + + + + + +GraphListener (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Interface GraphListener<V,E>

+
+
All Superinterfaces:
java.util.EventListener, VertexSetListener<V>
+
+
+
All Known Implementing Classes:
ConnectivityInspector, DirectedNeighborIndex, NeighborIndex
+
+
+
+
public interface GraphListener<V,E>
extends VertexSetListener<V>
+ + +

+A listener that is notified when the graph changes. + +

If only notifications on vertex set changes are required it is more + efficient to use the VertexSetListener.

+

+ +

+

+
Since:
+
Jul 18, 2003
+
Author:
+
Barak Naveh
+
See Also:
VertexSetListener
+
+ +

+ + + + + + + + + + + + + + + + +
+Method Summary
+ voidedgeAdded(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been added to the graph.
+ voidedgeRemoved(GraphEdgeChangeEvent<V,E> e) + +
+          Notifies that an edge has been removed from the graph.
+ + + + + + + +
Methods inherited from interface org.jgrapht.event.VertexSetListener
vertexAdded, vertexRemoved
+  +

+ + + + + + + + +
+Method Detail
+ +

+edgeAdded

+
+void edgeAdded(GraphEdgeChangeEvent<V,E> e)
+
+
Notifies that an edge has been added to the graph. +

+

+
+
+
+
Parameters:
e - the edge event.
+
+
+
+ +

+edgeRemoved

+
+void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
+
+
Notifies that an edge has been removed from the graph. +

+

+
+
+
+
Parameters:
e - the edge event.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphVertexChangeEvent.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphVertexChangeEvent.html new file mode 100644 index 00000000..4e1b453f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/GraphVertexChangeEvent.html @@ -0,0 +1,437 @@ + + + + + + +GraphVertexChangeEvent (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class GraphVertexChangeEvent<V>

+
+java.lang.Object
+  extended by java.util.EventObject
+      extended by org.jgrapht.event.GraphChangeEvent
+          extended by org.jgrapht.event.GraphVertexChangeEvent<V>
+
+
+
All Implemented Interfaces:
java.io.Serializable
+
+
+
+
public class GraphVertexChangeEvent<V>
extends GraphChangeEvent
+ + +

+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. +

+ +

+

+
Since:
+
Aug 10, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Field Summary
+static intBEFORE_VERTEX_ADDED + +
+          Before vertex added event.
+static intBEFORE_VERTEX_REMOVED + +
+          Before vertex removed event.
+protected  Vvertex + +
+          The vertex that this event is related to.
+static intVERTEX_ADDED + +
+          Vertex added event.
+static intVERTEX_REMOVED + +
+          Vertex removed event.
+ + + + + + + +
Fields inherited from class org.jgrapht.event.GraphChangeEvent
type
+ + + + + + + +
Fields inherited from class java.util.EventObject
source
+  + + + + + + + + + + +
+Constructor Summary
GraphVertexChangeEvent(java.lang.Object eventSource, + int type, + V vertex) + +
+          Creates a new GraphVertexChangeEvent object.
+  + + + + + + + + + + + +
+Method Summary
+ VgetVertex() + +
+          Returns the vertex that this event is related to.
+ + + + + + + +
Methods inherited from class org.jgrapht.event.GraphChangeEvent
getType
+ + + + + + + +
Methods inherited from class java.util.EventObject
getSource, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+BEFORE_VERTEX_ADDED

+
+public static final int BEFORE_VERTEX_ADDED
+
+
Before vertex added event. This event is fired before a vertex is added + to a graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+BEFORE_VERTEX_REMOVED

+
+public static final int BEFORE_VERTEX_REMOVED
+
+
Before vertex removed event. This event is fired before a vertex is + removed from a graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+VERTEX_ADDED

+
+public static final int VERTEX_ADDED
+
+
Vertex added event. This event is fired after a vertex is added to a + graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+VERTEX_REMOVED

+
+public static final int VERTEX_REMOVED
+
+
Vertex removed event. This event is fired after a vertex is removed from + a graph. +

+

+
See Also:
Constant Field Values
+
+
+ +

+vertex

+
+protected V vertex
+
+
The vertex that this event is related to. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+GraphVertexChangeEvent

+
+public GraphVertexChangeEvent(java.lang.Object eventSource,
+                              int type,
+                              V vertex)
+
+
Creates a new GraphVertexChangeEvent object. +

+

+
Parameters:
eventSource - the source of the event.
type - the type of the event.
vertex - the vertex that the event is related to.
+
+ + + + + + + + +
+Method Detail
+ +

+getVertex

+
+public V getVertex()
+
+
Returns the vertex that this event is related to. +

+

+ +
Returns:
the vertex that this event is related to.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/TraversalListener.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/TraversalListener.html new file mode 100644 index 00000000..6258e2ca --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/TraversalListener.html @@ -0,0 +1,317 @@ + + + + + + +TraversalListener (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Interface TraversalListener<V,E>

+
+
All Known Implementing Classes:
TraversalListenerAdapter
+
+
+
+
public interface TraversalListener<V,E>
+ + +

+A listener on graph iterator or on a graph traverser. +

+ +

+

+
Since:
+
Jul 19, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidconnectedComponentFinished(ConnectedComponentTraversalEvent e) + +
+          Called to inform listeners that the traversal of the current connected + component has finished.
+ voidconnectedComponentStarted(ConnectedComponentTraversalEvent e) + +
+          Called to inform listeners that a traversal of a new connected component + has started.
+ voidedgeTraversed(EdgeTraversalEvent<V,E> e) + +
+          Called to inform the listener that the specified edge have been visited + during the graph traversal.
+ voidvertexFinished(VertexTraversalEvent<V> e) + +
+          Called to inform the listener that the specified vertex have been + finished during the graph traversal.
+ voidvertexTraversed(VertexTraversalEvent<V> e) + +
+          Called to inform the listener that the specified vertex have been visited + during the graph traversal.
+  +

+ + + + + + + + +
+Method Detail
+ +

+connectedComponentFinished

+
+void connectedComponentFinished(ConnectedComponentTraversalEvent e)
+
+
Called to inform listeners that the traversal of the current connected + component has finished. +

+

+
Parameters:
e - the traversal event.
+
+
+
+ +

+connectedComponentStarted

+
+void connectedComponentStarted(ConnectedComponentTraversalEvent e)
+
+
Called to inform listeners that a traversal of a new connected component + has started. +

+

+
Parameters:
e - the traversal event.
+
+
+
+ +

+edgeTraversed

+
+void edgeTraversed(EdgeTraversalEvent<V,E> e)
+
+
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. +

+

+
Parameters:
e - the edge traversal event.
+
+
+
+ +

+vertexTraversed

+
+void vertexTraversed(VertexTraversalEvent<V> e)
+
+
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. +

+

+
Parameters:
e - the vertex traversal event.
+
+
+
+ +

+vertexFinished

+
+void vertexFinished(VertexTraversalEvent<V> e)
+
+
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. +

+

+
Parameters:
e - the vertex traversal event.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/TraversalListenerAdapter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/TraversalListenerAdapter.html new file mode 100644 index 00000000..d68b0935 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/TraversalListenerAdapter.html @@ -0,0 +1,384 @@ + + + + + + +TraversalListenerAdapter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class TraversalListenerAdapter<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.event.TraversalListenerAdapter<V,E>
+
+
+
All Implemented Interfaces:
TraversalListener<V,E>
+
+
+
+
public class TraversalListenerAdapter<V,E>
extends java.lang.Object
implements TraversalListener<V,E>
+ + +

+An empty do-nothing implementation of the TraversalListener interface + used for subclasses. +

+ +

+

+
Since:
+
Aug 6, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
TraversalListenerAdapter() + +
+           
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidconnectedComponentFinished(ConnectedComponentTraversalEvent e) + +
+          Called to inform listeners that the traversal of the current connected + component has finished.
+ voidconnectedComponentStarted(ConnectedComponentTraversalEvent e) + +
+          Called to inform listeners that a traversal of a new connected component + has started.
+ voidedgeTraversed(EdgeTraversalEvent<V,E> e) + +
+          Called to inform the listener that the specified edge have been visited + during the graph traversal.
+ voidvertexFinished(VertexTraversalEvent<V> e) + +
+          Called to inform the listener that the specified vertex have been + finished during the graph traversal.
+ voidvertexTraversed(VertexTraversalEvent<V> e) + +
+          Called to inform the listener that the specified vertex have been visited + during the graph traversal.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+TraversalListenerAdapter

+
+public TraversalListenerAdapter()
+
+
+ + + + + + + + +
+Method Detail
+ +

+connectedComponentFinished

+
+public void connectedComponentFinished(ConnectedComponentTraversalEvent e)
+
+
Description copied from interface: TraversalListener
+
Called to inform listeners that the traversal of the current connected + component has finished. +

+

+
Specified by:
connectedComponentFinished in interface TraversalListener<V,E>
+
+
+
Parameters:
e - the traversal event.
See Also:
TraversalListener.connectedComponentFinished(ConnectedComponentTraversalEvent)
+
+
+
+ +

+connectedComponentStarted

+
+public void connectedComponentStarted(ConnectedComponentTraversalEvent e)
+
+
Description copied from interface: TraversalListener
+
Called to inform listeners that a traversal of a new connected component + has started. +

+

+
Specified by:
connectedComponentStarted in interface TraversalListener<V,E>
+
+
+
Parameters:
e - the traversal event.
See Also:
TraversalListener.connectedComponentStarted(ConnectedComponentTraversalEvent)
+
+
+
+ +

+edgeTraversed

+
+public void edgeTraversed(EdgeTraversalEvent<V,E> e)
+
+
Description copied from interface: TraversalListener
+
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. +

+

+
Specified by:
edgeTraversed in interface TraversalListener<V,E>
+
+
+
Parameters:
e - the edge traversal event.
See Also:
TraversalListener.edgeTraversed(EdgeTraversalEvent)
+
+
+
+ +

+vertexTraversed

+
+public void vertexTraversed(VertexTraversalEvent<V> e)
+
+
Description copied from interface: TraversalListener
+
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. +

+

+
Specified by:
vertexTraversed in interface TraversalListener<V,E>
+
+
+
Parameters:
e - the vertex traversal event.
See Also:
TraversalListener.vertexTraversed(VertexTraversalEvent)
+
+
+
+ +

+vertexFinished

+
+public void vertexFinished(VertexTraversalEvent<V> e)
+
+
Description copied from interface: TraversalListener
+
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. +

+

+
Specified by:
vertexFinished in interface TraversalListener<V,E>
+
+
+
Parameters:
e - the vertex traversal event.
See Also:
TraversalListener.vertexFinished(VertexTraversalEvent)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/VertexSetListener.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/VertexSetListener.html new file mode 100644 index 00000000..7c057469 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/VertexSetListener.html @@ -0,0 +1,255 @@ + + + + + + +VertexSetListener (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Interface VertexSetListener<V>

+
+
All Superinterfaces:
java.util.EventListener
+
+
+
All Known Subinterfaces:
GraphListener<V,E>
+
+
+
All Known Implementing Classes:
ConnectivityInspector, DirectedNeighborIndex, NeighborIndex
+
+
+
+
public interface VertexSetListener<V>
extends java.util.EventListener
+ + +

+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. +

+ +

+

+
Since:
+
Jul 18, 2003
+
Author:
+
Barak Naveh
+
See Also:
GraphListener
+
+ +

+ + + + + + + + + + + + + + + + +
+Method Summary
+ voidvertexAdded(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been added to the graph.
+ voidvertexRemoved(GraphVertexChangeEvent<V> e) + +
+          Notifies that a vertex has been removed from the graph.
+  +

+ + + + + + + + +
+Method Detail
+ +

+vertexAdded

+
+void vertexAdded(GraphVertexChangeEvent<V> e)
+
+
Notifies that a vertex has been added to the graph. +

+

+
+
+
+
Parameters:
e - the vertex event.
+
+
+
+ +

+vertexRemoved

+
+void vertexRemoved(GraphVertexChangeEvent<V> e)
+
+
Notifies that a vertex has been removed from the graph. +

+

+
+
+
+
Parameters:
e - the vertex event.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/VertexTraversalEvent.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/VertexTraversalEvent.html new file mode 100644 index 00000000..f8a0ce3f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/VertexTraversalEvent.html @@ -0,0 +1,329 @@ + + + + + + +VertexTraversalEvent (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.event +
+Class VertexTraversalEvent<V>

+
+java.lang.Object
+  extended by java.util.EventObject
+      extended by org.jgrapht.event.VertexTraversalEvent<V>
+
+
+
All Implemented Interfaces:
java.io.Serializable
+
+
+
+
public class VertexTraversalEvent<V>
extends java.util.EventObject
+ + +

+A traversal event for a graph vertex. +

+ +

+

+
Since:
+
Aug 11, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + +
+Field Summary
+protected  Vvertex + +
+          The traversed vertex.
+ + + + + + + +
Fields inherited from class java.util.EventObject
source
+  + + + + + + + + + + +
+Constructor Summary
VertexTraversalEvent(java.lang.Object eventSource, + V vertex) + +
+          Creates a new VertexTraversalEvent.
+  + + + + + + + + + + + +
+Method Summary
+ VgetVertex() + +
+          Returns the traversed vertex.
+ + + + + + + +
Methods inherited from class java.util.EventObject
getSource, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+vertex

+
+protected V vertex
+
+
The traversed vertex. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+VertexTraversalEvent

+
+public VertexTraversalEvent(java.lang.Object eventSource,
+                            V vertex)
+
+
Creates a new VertexTraversalEvent. +

+

+
Parameters:
eventSource - the source of the event.
vertex - the traversed vertex.
+
+ + + + + + + + +
+Method Detail
+ +

+getVertex

+
+public V getVertex()
+
+
Returns the traversed vertex. +

+

+ +
Returns:
the traversed vertex.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-frame.html new file mode 100644 index 00000000..802f8cd4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-frame.html @@ -0,0 +1,59 @@ + + + + + + +org.jgrapht.event (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.event + + + + +
+Interfaces  + +
+GraphListener +
+TraversalListener +
+VertexSetListener
+ + + + + + +
+Classes  + +
+ConnectedComponentTraversalEvent +
+EdgeTraversalEvent +
+GraphChangeEvent +
+GraphEdgeChangeEvent +
+GraphVertexChangeEvent +
+TraversalListenerAdapter +
+VertexTraversalEvent
+ + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-summary.html new file mode 100644 index 00000000..76ff7421 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-summary.html @@ -0,0 +1,221 @@ + + + + + + +org.jgrapht.event (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package org.jgrapht.event +

+Event classes and listener interfaces, used to provide a change +notification mechanism on graph modification events. +

+See: +
+          Description +

+ + + + + + + + + + + + + + + + + +
+Interface Summary
GraphListener<V,E>A listener that is notified when the graph changes.
TraversalListener<V,E>A listener on graph iterator or on a graph traverser.
VertexSetListener<V>A listener that is notified when the graph's vertex set changes.
+  + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class Summary
ConnectedComponentTraversalEventA traversal event with respect to a connected component.
EdgeTraversalEvent<V,E>A traversal event for a graph edge.
GraphChangeEventAn event which indicates that a graph has changed.
GraphEdgeChangeEvent<V,E>An event which indicates that a graph edge has changed, or is about to + change.
GraphVertexChangeEvent<V>An event which indicates that a graph vertex has changed, or is about to + change.
TraversalListenerAdapter<V,E>An empty do-nothing implementation of the TraversalListener interface + used for subclasses.
VertexTraversalEvent<V>A traversal event for a graph vertex.
+  + +

+

+Package org.jgrapht.event Description +

+ +

+Event classes and listener interfaces, used to provide a change +notification mechanism on graph modification events. +

+ +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-tree.html new file mode 100644 index 00000000..23ce67e0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/event/package-tree.html @@ -0,0 +1,166 @@ + + + + + + +org.jgrapht.event Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package org.jgrapht.event +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +

+Interface Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/DOTExporter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/DOTExporter.html new file mode 100644 index 00000000..4b78089c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/DOTExporter.html @@ -0,0 +1,296 @@ + + + + + + +DOTExporter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class DOTExporter<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.DOTExporter<V,E>
+
+
+
+
public class DOTExporter<V,E>
extends java.lang.Object
+ + +

+Exports a graph into a DOT file. + +

For a description of the format see + http://en.wikipedia.org/wiki/DOT_language.

+

+ +

+

+
Author:
+
Trevor Harmon
+
+
+ +

+ + + + + + + + + + + + + + +
+Constructor Summary
DOTExporter() + +
+          Constructs a new DOTExporter object with an integer name provider for the + vertex IDs and null providers for the vertex and edge labels.
DOTExporter(VertexNameProvider<V> vertexIDProvider, + VertexNameProvider<V> vertexLabelProvider, + EdgeNameProvider<E> edgeLabelProvider) + +
+          Constructs a new DOTExporter object with the given ID and label + providers.
+  + + + + + + + + + + + +
+Method Summary
+ voidexport(java.io.Writer writer, + Graph<V,E> g) + +
+          Exports a graph into a plain text file in DOT format.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+DOTExporter

+
+public DOTExporter()
+
+
Constructs a new DOTExporter object with an integer name provider for the + vertex IDs and null providers for the vertex and edge labels. +

+

+
+ +

+DOTExporter

+
+public DOTExporter(VertexNameProvider<V> vertexIDProvider,
+                   VertexNameProvider<V> vertexLabelProvider,
+                   EdgeNameProvider<E> edgeLabelProvider)
+
+
Constructs a new DOTExporter object with the given ID and label + providers. +

+

+
Parameters:
vertexIDProvider - for generating vertex IDs. Must not be null.
vertexLabelProvider - for generating vertex labels. If null, vertex + labels will not be written to the file.
edgeLabelProvider - for generating edge labels. If null, edge labels + will not be written to the file.
+
+ + + + + + + + +
+Method Detail
+ +

+export

+
+public void export(java.io.Writer writer,
+                   Graph<V,E> g)
+
+
Exports a graph into a plain text file in DOT format. +

+

+
Parameters:
writer - the writer to which the graph to be exported
g - the graph to be exported
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/EdgeNameProvider.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/EdgeNameProvider.html new file mode 100644 index 00000000..3d8a251b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/EdgeNameProvider.html @@ -0,0 +1,215 @@ + + + + + + +EdgeNameProvider (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Interface EdgeNameProvider<E>

+
+
All Known Implementing Classes:
IntegerEdgeNameProvider, StringEdgeNameProvider
+
+
+
+
public interface EdgeNameProvider<E>
+ + +

+Assigns a display name for each of the graph edes. +

+ +

+


+ +

+ + + + + + + + + + + + +
+Method Summary
+ java.lang.StringgetEdgeName(E edge) + +
+          Returns a unique name for an edge.
+  +

+ + + + + + + + +
+Method Detail
+ +

+getEdgeName

+
+java.lang.String getEdgeName(E edge)
+
+
Returns a unique name for an edge. This is useful when exporting a graph, + as it ensures that all edges are assigned simple, consistent names. +

+

+
Parameters:
edge - the edge to be named +
Returns:
the name of the edge
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/GmlExporter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/GmlExporter.html new file mode 100644 index 00000000..6725fc78 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/GmlExporter.html @@ -0,0 +1,474 @@ + + + + + + +GmlExporter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class GmlExporter<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.GmlExporter<V,E>
+
+
+
+
public class GmlExporter<V,E>
extends java.lang.Object
+ + +

+Exports a graph into a GML file (Graph Modelling Language). + +

For a description of the format see + http://www.infosun.fmi.uni-passau.de/Graphlet/GML/.

+ +

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.

+

+ +

+

+
Author:
+
Dimitrios Michail
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + +
+Field Summary
+static java.lang.IntegerPRINT_EDGE_LABELS + +
+          Option to export only the edge labels.
+static java.lang.IntegerPRINT_EDGE_VERTEX_LABELS + +
+          Option to export both edge and vertex labels.
+static java.lang.IntegerPRINT_NO_LABELS + +
+          Option to export no vertex or edge labels.
+static java.lang.IntegerPRINT_VERTEX_LABELS + +
+          Option to export only the vertex labels.
+  + + + + + + + + + + + + + +
+Constructor Summary
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.
GmlExporter(VertexNameProvider<V> vertexIDProvider, + VertexNameProvider<V> vertexLabelProvider, + EdgeNameProvider<E> edgeIDProvider, + EdgeNameProvider<E> edgeLabelProvider) + +
+          Constructs a new GmlExporter object with the given ID and label + providers.
+  + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidexport(java.io.Writer output, + DirectedGraph<V,E> g) + +
+          Exports a directed graph into a plain text file in GML format.
+ voidexport(java.io.Writer output, + UndirectedGraph<V,E> g) + +
+          Exports an undirected graph into a plain text file in GML format.
+ java.lang.IntegergetPrintLabels() + +
+          Get whether to export the vertex and edge labels.
+ voidsetPrintLabels(java.lang.Integer i) + +
+          Set whether to export the vertex and edge labels.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+PRINT_NO_LABELS

+
+public static final java.lang.Integer PRINT_NO_LABELS
+
+
Option to export no vertex or edge labels. +

+

+
+
+
+ +

+PRINT_EDGE_LABELS

+
+public static final java.lang.Integer PRINT_EDGE_LABELS
+
+
Option to export only the edge labels. +

+

+
+
+
+ +

+PRINT_EDGE_VERTEX_LABELS

+
+public static final java.lang.Integer PRINT_EDGE_VERTEX_LABELS
+
+
Option to export both edge and vertex labels. +

+

+
+
+
+ +

+PRINT_VERTEX_LABELS

+
+public static final java.lang.Integer PRINT_VERTEX_LABELS
+
+
Option to export only the vertex labels. +

+

+
+
+ + + + + + + + +
+Constructor Detail
+ +

+GmlExporter

+
+public 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. +

+

+
+ +

+GmlExporter

+
+public GmlExporter(VertexNameProvider<V> vertexIDProvider,
+                   VertexNameProvider<V> vertexLabelProvider,
+                   EdgeNameProvider<E> edgeIDProvider,
+                   EdgeNameProvider<E> edgeLabelProvider)
+
+
Constructs a new GmlExporter object with the given ID and label + providers. +

+

+
Parameters:
vertexIDProvider - for generating vertex IDs. Must not be null.
vertexLabelProvider - for generating vertex labels. If null, vertex + labels will be generated using the toString() method of the vertex + object.
edgeIDProvider - for generating vertex IDs. Must not be null.
edgeLabelProvider - for generating edge labels. If null, edge labels + will be generated using the toString() method of the edge object.
+
+ + + + + + + + +
+Method Detail
+ +

+export

+
+public void export(java.io.Writer output,
+                   UndirectedGraph<V,E> g)
+
+
Exports an undirected graph into a plain text file in GML format. +

+

+
Parameters:
output - the writer to which the graph to be exported
g - the undirected graph to be exported
+
+
+
+ +

+export

+
+public void export(java.io.Writer output,
+                   DirectedGraph<V,E> g)
+
+
Exports a directed graph into a plain text file in GML format. +

+

+
Parameters:
output - the writer to which the graph to be exported
g - the directed graph to be exported
+
+
+
+ +

+setPrintLabels

+
+public void setPrintLabels(java.lang.Integer i)
+
+
Set whether to export the vertex and edge labels. The default behavior is + to export no vertex or edge labels. +

+

+
Parameters:
i - What labels to export. Valid options are PRINT_NO_LABELS, PRINT_EDGE_LABELS, PRINT_EDGE_VERTEX_LABELS, and PRINT_VERTEX_LABELS. +
Throws: +
java.lang.IllegalArgumentException - if a non-supported value is used
See Also:
PRINT_NO_LABELS, +PRINT_EDGE_LABELS, +PRINT_EDGE_VERTEX_LABELS, +PRINT_VERTEX_LABELS
+
+
+
+ +

+getPrintLabels

+
+public java.lang.Integer getPrintLabels()
+
+
Get whether to export the vertex and edge labels. +

+

+ +
Returns:
One of the PRINT_NO_LABELS, PRINT_EDGE_LABELS, + PRINT_EDGE_VERTEX_LABELS, or PRINT_VERTEX_LABELS.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/GraphMLExporter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/GraphMLExporter.html new file mode 100644 index 00000000..be6a9c42 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/GraphMLExporter.html @@ -0,0 +1,305 @@ + + + + + + +GraphMLExporter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class GraphMLExporter<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.GraphMLExporter<V,E>
+
+
+
+
public class GraphMLExporter<V,E>
extends java.lang.Object
+ + +

+Exports a graph into a GraphML file. + +

For a description of the format see + http://en.wikipedia.org/wiki/GraphML.

+

+ +

+

+
Author:
+
Trevor Harmon
+
+
+ +

+ + + + + + + + + + + + + + +
+Constructor Summary
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.
GraphMLExporter(VertexNameProvider<V> vertexIDProvider, + VertexNameProvider<V> vertexLabelProvider, + EdgeNameProvider<E> edgeIDProvider, + EdgeNameProvider<E> edgeLabelProvider) + +
+          Constructs a new GraphMLExporter object with the given ID and label + providers.
+  + + + + + + + + + + + +
+Method Summary
+ voidexport(java.io.Writer writer, + Graph<V,E> g) + +
+          Exports a graph into a plain text file in GraphML format.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+GraphMLExporter

+
+public 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. +

+

+
+ +

+GraphMLExporter

+
+public GraphMLExporter(VertexNameProvider<V> vertexIDProvider,
+                       VertexNameProvider<V> vertexLabelProvider,
+                       EdgeNameProvider<E> edgeIDProvider,
+                       EdgeNameProvider<E> edgeLabelProvider)
+
+
Constructs a new GraphMLExporter object with the given ID and label + providers. +

+

+
Parameters:
vertexIDProvider - for generating vertex IDs. Must not be null.
vertexLabelProvider - for generating vertex labels. If null, vertex + labels will not be written to the file.
edgeIDProvider - for generating vertex IDs. Must not be null.
edgeLabelProvider - for generating edge labels. If null, edge labels + will not be written to the file.
+
+ + + + + + + + +
+Method Detail
+ +

+export

+
+public void export(java.io.Writer writer,
+                   Graph<V,E> g)
+            throws org.xml.sax.SAXException,
+                   javax.xml.transform.TransformerConfigurationException
+
+
Exports a graph into a plain text file in GraphML format. +

+

+
Parameters:
writer - the writer to which the graph to be exported
g - the graph to be exported +
Throws: +
org.xml.sax.SAXException +
javax.xml.transform.TransformerConfigurationException
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/IntegerEdgeNameProvider.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/IntegerEdgeNameProvider.html new file mode 100644 index 00000000..90af64fe --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/IntegerEdgeNameProvider.html @@ -0,0 +1,294 @@ + + + + + + +IntegerEdgeNameProvider (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class IntegerEdgeNameProvider<E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.IntegerEdgeNameProvider<E>
+
+
+
All Implemented Interfaces:
EdgeNameProvider<E>
+
+
+
+
public class IntegerEdgeNameProvider<E>
extends java.lang.Object
implements EdgeNameProvider<E>
+ + +

+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. +

+ +

+

+
Author:
+
Trevor Harmon
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
IntegerEdgeNameProvider() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+ voidclear() + +
+          Clears all cached identifiers, and resets the unique identifier counter.
+ java.lang.StringgetEdgeName(E edge) + +
+          Returns the String representation of an edge.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+IntegerEdgeNameProvider

+
+public IntegerEdgeNameProvider()
+
+
+ + + + + + + + +
+Method Detail
+ +

+clear

+
+public void clear()
+
+
Clears all cached identifiers, and resets the unique identifier counter. +

+

+
+
+
+
+
+
+
+ +

+getEdgeName

+
+public java.lang.String getEdgeName(E edge)
+
+
Returns the String representation of an edge. +

+

+
Specified by:
getEdgeName in interface EdgeNameProvider<E>
+
+
+
Parameters:
edge - the edge to be named +
Returns:
the name of the edge
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/IntegerNameProvider.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/IntegerNameProvider.html new file mode 100644 index 00000000..12f8de2f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/IntegerNameProvider.html @@ -0,0 +1,296 @@ + + + + + + +IntegerNameProvider (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class IntegerNameProvider<V>

+
+java.lang.Object
+  extended by org.jgrapht.ext.IntegerNameProvider<V>
+
+
+
All Implemented Interfaces:
VertexNameProvider<V>
+
+
+
+
public class IntegerNameProvider<V>
extends java.lang.Object
implements VertexNameProvider<V>
+ + +

+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. +

+ +

+

+
Author:
+
Charles Fry
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
IntegerNameProvider() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+ voidclear() + +
+          Clears all cached identifiers, and resets the unique identifier counter.
+ java.lang.StringgetVertexName(V vertex) + +
+          Returns the String representation of the unique integer representing a + vertex.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+IntegerNameProvider

+
+public IntegerNameProvider()
+
+
+ + + + + + + + +
+Method Detail
+ +

+clear

+
+public void clear()
+
+
Clears all cached identifiers, and resets the unique identifier counter. +

+

+
+
+
+
+
+
+
+ +

+getVertexName

+
+public java.lang.String getVertexName(V vertex)
+
+
Returns the String representation of the unique integer representing a + vertex. +

+

+
Specified by:
getVertexName in interface VertexNameProvider<V>
+
+
+
Parameters:
vertex - the vertex to be named +
Returns:
the name of
See Also:
GraphListener.edgeAdded(GraphEdgeChangeEvent)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.CellFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.CellFactory.html new file mode 100644 index 00000000..6e28a0dc --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.CellFactory.html @@ -0,0 +1,245 @@ + + + + + + +JGraphModelAdapter.CellFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Interface JGraphModelAdapter.CellFactory<VV,EE>

+
+
All Known Implementing Classes:
JGraphModelAdapter.DefaultCellFactory
+
+
+
Enclosing class:
JGraphModelAdapter<V,E>
+
+
+
+
public static interface JGraphModelAdapter.CellFactory<VV,EE>
+ + +

+Creates the JGraph cells that reflect the respective JGraphT elements. +

+ +

+

+
Since:
+
Dec 12, 2003
+
Author:
+
Barak Naveh
+
+
+ +

+ + + + + + + + + + + + + + + + +
+Method Summary
+ org.jgraph.graph.DefaultEdgecreateEdgeCell(EE jGraphTEdge) + +
+          Creates an edge cell that contains its respective JGraphT edge.
+ org.jgraph.graph.DefaultGraphCellcreateVertexCell(VV jGraphTVertex) + +
+          Creates a vertex cell that contains its respective JGraphT vertex.
+  +

+ + + + + + + + +
+Method Detail
+ +

+createEdgeCell

+
+org.jgraph.graph.DefaultEdge createEdgeCell(EE jGraphTEdge)
+
+
Creates an edge cell that contains its respective JGraphT edge. +

+

+
Parameters:
jGraphTEdge - a JGraphT edge to be contained. +
Returns:
an edge cell that contains its respective JGraphT edge.
+
+
+
+ +

+createVertexCell

+
+org.jgraph.graph.DefaultGraphCell createVertexCell(VV jGraphTVertex)
+
+
Creates a vertex cell that contains its respective JGraphT vertex. +

+

+
Parameters:
jGraphTVertex - a JGraphT vertex to be contained. +
Returns:
a vertex cell that contains its respective JGraphT vertex.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.DefaultCellFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.DefaultCellFactory.html new file mode 100644 index 00000000..af87f86f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.DefaultCellFactory.html @@ -0,0 +1,299 @@ + + + + + + +JGraphModelAdapter.DefaultCellFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class JGraphModelAdapter.DefaultCellFactory<VV,EE>

+
+java.lang.Object
+  extended by org.jgrapht.ext.JGraphModelAdapter.DefaultCellFactory<VV,EE>
+
+
+
All Implemented Interfaces:
java.io.Serializable, JGraphModelAdapter.CellFactory<VV,EE>
+
+
+
Enclosing class:
JGraphModelAdapter<V,E>
+
+
+
+
public static class JGraphModelAdapter.DefaultCellFactory<VV,EE>
extends java.lang.Object
implements JGraphModelAdapter.CellFactory<VV,EE>, java.io.Serializable
+ + +

+A simple default cell factory. +

+ +

+

+
Since:
+
Dec 12, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
JGraphModelAdapter.DefaultCellFactory() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+ org.jgraph.graph.DefaultEdgecreateEdgeCell(EE jGraphTEdge) + +
+          Creates an edge cell that contains its respective JGraphT edge.
+ org.jgraph.graph.DefaultGraphCellcreateVertexCell(VV jGraphTVertex) + +
+          Creates a vertex cell that contains its respective JGraphT vertex.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+JGraphModelAdapter.DefaultCellFactory

+
+public JGraphModelAdapter.DefaultCellFactory()
+
+
+ + + + + + + + +
+Method Detail
+ +

+createEdgeCell

+
+public org.jgraph.graph.DefaultEdge createEdgeCell(EE jGraphTEdge)
+
+
Description copied from interface: JGraphModelAdapter.CellFactory
+
Creates an edge cell that contains its respective JGraphT edge. +

+

+
Specified by:
createEdgeCell in interface JGraphModelAdapter.CellFactory<VV,EE>
+
+
+
Parameters:
jGraphTEdge - a JGraphT edge to be contained. +
Returns:
an edge cell that contains its respective JGraphT edge.
See Also:
JGraphModelAdapter.CellFactory.createEdgeCell(Object)
+
+
+
+ +

+createVertexCell

+
+public org.jgraph.graph.DefaultGraphCell createVertexCell(VV jGraphTVertex)
+
+
Description copied from interface: JGraphModelAdapter.CellFactory
+
Creates a vertex cell that contains its respective JGraphT vertex. +

+

+
Specified by:
createVertexCell in interface JGraphModelAdapter.CellFactory<VV,EE>
+
+
+
Parameters:
jGraphTVertex - a JGraphT vertex to be contained. +
Returns:
a vertex cell that contains its respective JGraphT vertex.
See Also:
JGraphModelAdapter.CellFactory.createVertexCell(Object)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.html new file mode 100644 index 00000000..ff16543c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/JGraphModelAdapter.html @@ -0,0 +1,659 @@ + + + + + + +JGraphModelAdapter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class JGraphModelAdapter<V,E>

+
+java.lang.Object
+  extended by javax.swing.undo.UndoableEditSupport
+      extended by org.jgraph.graph.DefaultGraphModel
+          extended by org.jgrapht.ext.JGraphModelAdapter<V,E>
+
+
+
All Implemented Interfaces:
java.io.Serializable, org.jgraph.graph.GraphModel
+
+
+
+
public class JGraphModelAdapter<V,E>
extends org.jgraph.graph.DefaultGraphModel
+ + +

+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.

+

+ +

+

+
Since:
+
Aug 2, 2003
+
Author:
+
Barak Naveh
+
See Also:
Serialized Form
+
+ +

+ + + + + + + + + + + + + + + +
+Nested Class Summary
+static interfaceJGraphModelAdapter.CellFactory<VV,EE> + +
+          Creates the JGraph cells that reflect the respective JGraphT elements.
+static classJGraphModelAdapter.DefaultCellFactory<VV,EE> + +
+          A simple default cell factory.
+ + + + + + + +
Nested classes/interfaces inherited from class org.jgraph.graph.DefaultGraphModel
org.jgraph.graph.DefaultGraphModel.EmptyIterator, org.jgraph.graph.DefaultGraphModel.GraphModelEdit, org.jgraph.graph.DefaultGraphModel.GraphModelLayerEdit
+  + + + + + + + +
+Field Summary
+ + + + + + + +
Fields inherited from class org.jgraph.graph.DefaultGraphModel
asksAllowsChildren, attributes, emptyIterator, listenerList, roots
+ + + + + + + +
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.AttributeMapcreateDefaultVertexAttributes() + +
+          Creates and returns a map of attributes to be used as defaults for vertex + attributes.
+ JGraphModelAdapter.CellFactory<V,E>getCellFactory() + +
+          Returns the cell factory used to create the JGraph cells.
+ org.jgraph.graph.AttributeMapgetDefaultEdgeAttributes() + +
+          Returns the default edge attributes used for creating new JGraph edges.
+ org.jgraph.graph.AttributeMapgetDefaultVertexAttributes() + +
+          Returns the default vertex attributes used for creating new JGraph + vertices.
+ org.jgraph.graph.DefaultEdgegetEdgeCell(E jGraphTEdge) + +
+          Returns the JGraph edge cell that corresponds to the specified JGraphT + edge.
+ org.jgraph.graph.DefaultGraphCellgetVertexCell(java.lang.Object jGraphTVertex) + +
+          Returns the JGraph vertex cell that corresponds to the specified JGraphT + vertex.
+ org.jgraph.graph.DefaultPortgetVertexPort(java.lang.Object jGraphTVertex) + +
+          Returns the JGraph port cell that corresponds to the specified JGraphT + vertex.
+ voidsetDefaultEdgeAttributes(org.jgraph.graph.AttributeMap defaultEdgeAttributes) + +
+          Sets the default edge attributes used for creating new JGraph edges.
+ voidsetDefaultVertexAttributes(org.jgraph.graph.AttributeMap defaultVertexAttributes) + +
+          Sets the default vertex attributes used for creating new JGraph vertices.
+ + + + + + + +
Methods inherited from class org.jgraph.graph.DefaultGraphModel
acceptsSource, acceptsTarget, addGraphModelListener, cellsChanged, cloneCell, cloneCell, cloneCell, cloneCells, cloneUserObject, connect, contains, containsEdgeBetween, createEdit, createLayerEdit, createRemoveEdit, edges, edit, edit, fireGraphChanged, getAll, getAttributes, getAttributes, getChild, getChildCount, getConnectionSet, getDescendants, getEdges, getEdges, getEdgesBetween, getGraphModelListeners, getIncomingEdges, getIndexOfChild, getIndexOfRoot, getOpposite, getOutgoingEdges, getParent, getRootAt, getRootCount, getRoots, getRoots, getRoots, getSource, getSourceVertex, getTarget, getTargetVertex, getTopmostCells, getUserObject, getValue, handleAttributes, handleConnection, handleConnectionSet, handleInsert, handleParentMap, handleRemove, hasAncestorIn, insert, isEdge, isGroup, isLeaf, isPort, isVertex, order, remove, removeGraphModelListener, setParent, setSourcePort, setTargetPort, toBack, toFront, valueForCellChanged
+ + + + + + + +
Methods inherited from class javax.swing.undo.UndoableEditSupport
_postEdit, addUndoableEditListener, beginUpdate, createCompoundEdit, endUpdate, getUndoableEditListeners, getUpdateLevel, postEdit, removeUndoableEditListener, toString
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
+ + + + + + + +
Methods inherited from interface org.jgraph.graph.GraphModel
addUndoableEditListener, removeUndoableEditListener
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+JGraphModelAdapter

+
+public JGraphModelAdapter(Graph<V,E> jGraphTGraph)
+
+
Constructs a new JGraph model adapter for the specified JGraphT graph. +

+

+
Parameters:
jGraphTGraph - the JGraphT graph for which JGraph model adapter to + be created. null is NOT permitted.
+
+
+ +

+JGraphModelAdapter

+
+public 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. +

+

+
Parameters:
jGraphTGraph - the JGraphT graph for which JGraph model adapter to + be created. null is NOT permitted.
defaultVertexAttributes - a default map of JGraph attributes to + format vertices. null is NOT permitted.
defaultEdgeAttributes - a default map of JGraph attributes to format + edges. null is NOT permitted.
+
+
+ +

+JGraphModelAdapter

+
+public 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. +

+

+
Parameters:
jGraphTGraph - the JGraphT graph for which JGraph model adapter to + be created. null is NOT permitted.
defaultVertexAttributes - a default map of JGraph attributes to + format vertices. null is NOT permitted.
defaultEdgeAttributes - a default map of JGraph attributes to format + edges. null is NOT permitted.
cellFactory - a JGraphModelAdapter.CellFactory to be used to create the JGraph + cells. null is NOT permitted. +
Throws: +
java.lang.IllegalArgumentException
+
+ + + + + + + + +
+Method Detail
+ +

+createDefaultEdgeAttributes

+
+public 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. +

+

+
Parameters:
jGraphTGraph - the graph for which default edge attributes to be + created. +
Returns:
a map of attributes to be used as default for edge attributes.
+
+
+
+ +

+createDefaultVertexAttributes

+
+public static org.jgraph.graph.AttributeMap createDefaultVertexAttributes()
+
+
Creates and returns a map of attributes to be used as defaults for vertex + attributes. +

+

+ +
Returns:
a map of attributes to be used as defaults for vertex attributes.
+
+
+
+ +

+getCellFactory

+
+public JGraphModelAdapter.CellFactory<V,E> getCellFactory()
+
+
Returns the cell factory used to create the JGraph cells. +

+

+ +
Returns:
the cell factory used to create the JGraph cells.
+
+
+
+ +

+setDefaultEdgeAttributes

+
+public void setDefaultEdgeAttributes(org.jgraph.graph.AttributeMap defaultEdgeAttributes)
+
+
Sets the default edge attributes used for creating new JGraph edges. +

+

+
Parameters:
defaultEdgeAttributes - the default edge attributes to set.
+
+
+
+ +

+getDefaultEdgeAttributes

+
+public org.jgraph.graph.AttributeMap getDefaultEdgeAttributes()
+
+
Returns the default edge attributes used for creating new JGraph edges. +

+

+ +
Returns:
the default edge attributes used for creating new JGraph edges.
+
+
+
+ +

+setDefaultVertexAttributes

+
+public void setDefaultVertexAttributes(org.jgraph.graph.AttributeMap defaultVertexAttributes)
+
+
Sets the default vertex attributes used for creating new JGraph vertices. +

+

+
Parameters:
defaultVertexAttributes - the default vertex attributes to set.
+
+
+
+ +

+getDefaultVertexAttributes

+
+public org.jgraph.graph.AttributeMap getDefaultVertexAttributes()
+
+
Returns the default vertex attributes used for creating new JGraph + vertices. +

+

+ +
Returns:
the default vertex attributes used for creating new JGraph + vertices.
+
+
+
+ +

+getEdgeCell

+
+public org.jgraph.graph.DefaultEdge getEdgeCell(E jGraphTEdge)
+
+
Returns the JGraph edge cell that corresponds to the specified JGraphT + edge. If no corresponding cell found, returns null. +

+

+
Parameters:
jGraphTEdge - a JGraphT edge of the JGraphT graph. +
Returns:
the JGraph edge cell that corresponds to the specified JGraphT + edge, or null if no corresponding cell found.
+
+
+
+ +

+getVertexCell

+
+public org.jgraph.graph.DefaultGraphCell getVertexCell(java.lang.Object jGraphTVertex)
+
+
Returns the JGraph vertex cell that corresponds to the specified JGraphT + vertex. If no corresponding cell found, returns null. +

+

+
Parameters:
jGraphTVertex - a JGraphT vertex of the JGraphT graph. +
Returns:
the JGraph vertex cell that corresponds to the specified JGraphT + vertex, or null if no corresponding cell found.
+
+
+
+ +

+getVertexPort

+
+public org.jgraph.graph.DefaultPort getVertexPort(java.lang.Object jGraphTVertex)
+
+
Returns the JGraph port cell that corresponds to the specified JGraphT + vertex. If no corresponding port found, returns null. +

+

+
Parameters:
jGraphTVertex - a JGraphT vertex of the JGraphT graph. +
Returns:
the JGraph port cell that corresponds to the specified JGraphT + vertex, or null if no corresponding cell found.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/MatrixExporter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/MatrixExporter.html new file mode 100644 index 00000000..d9388c14 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/MatrixExporter.html @@ -0,0 +1,357 @@ + + + + + + +MatrixExporter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class MatrixExporter<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.MatrixExporter<V,E>
+
+
+
+
public class MatrixExporter<V,E>
extends java.lang.Object
+ + +

+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
+ voidexportAdjacencyMatrix(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.
+ voidexportAdjacencyMatrix(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.
+ voidexportLaplacianMatrix(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.
+ voidexportNormalizedLaplacianMatrix(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.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+MatrixExporter

+
+public MatrixExporter()
+
+
Creates a new MatrixExporter object. +

+

+ + + + + + + + +
+Method Detail
+ +

+exportAdjacencyMatrix

+
+public 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. 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.
g - the graph to be exported.
+
+
+
+ +

+exportAdjacencyMatrix

+
+public 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. 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.
g - the graph to be exported.
+
+
+
+ +

+exportLaplacianMatrix

+
+public 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. 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.
g - the graph to be exported.
+
+
+
+ +

+exportNormalizedLaplacianMatrix

+
+public 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. + 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.
g - the graph to be exported.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/StringEdgeNameProvider.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/StringEdgeNameProvider.html new file mode 100644 index 00000000..be4c45d3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/StringEdgeNameProvider.html @@ -0,0 +1,269 @@ + + + + + + +StringEdgeNameProvider (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class StringEdgeNameProvider<E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.StringEdgeNameProvider<E>
+
+
+
All Implemented Interfaces:
EdgeNameProvider<E>
+
+
+
+
public class StringEdgeNameProvider<E>
extends java.lang.Object
implements EdgeNameProvider<E>
+ + +

+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. +

+ +

+

+
Author:
+
Trevor Harmon
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
StringEdgeNameProvider() + +
+           
+  + + + + + + + + + + + +
+Method Summary
+ java.lang.StringgetEdgeName(E edge) + +
+          Returns the String representation an edge.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+StringEdgeNameProvider

+
+public StringEdgeNameProvider()
+
+
+ + + + + + + + +
+Method Detail
+ +

+getEdgeName

+
+public java.lang.String getEdgeName(E edge)
+
+
Returns the String representation an edge. +

+

+
Specified by:
getEdgeName in interface EdgeNameProvider<E>
+
+
+
Parameters:
edge - the edge to be named +
Returns:
the name of the edge
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/StringNameProvider.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/StringNameProvider.html new file mode 100644 index 00000000..15461fe5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/StringNameProvider.html @@ -0,0 +1,271 @@ + + + + + + +StringNameProvider (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class StringNameProvider<V>

+
+java.lang.Object
+  extended by org.jgrapht.ext.StringNameProvider<V>
+
+
+
All Implemented Interfaces:
VertexNameProvider<V>
+
+
+
+
public class StringNameProvider<V>
extends java.lang.Object
implements VertexNameProvider<V>
+ + +

+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. +

+ +

+

+
Author:
+
Charles Fry
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
StringNameProvider() + +
+           
+  + + + + + + + + + + + +
+Method Summary
+ java.lang.StringgetVertexName(V vertex) + +
+          Returns the String representation of the unique integer representing a + vertex.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+StringNameProvider

+
+public StringNameProvider()
+
+
+ + + + + + + + +
+Method Detail
+ +

+getVertexName

+
+public java.lang.String getVertexName(V vertex)
+
+
Returns the String representation of the unique integer representing a + vertex. +

+

+
Specified by:
getVertexName in interface VertexNameProvider<V>
+
+
+
Parameters:
vertex - the vertex to be named +
Returns:
the name of
See Also:
GraphListener.edgeAdded(GraphEdgeChangeEvent)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/VertexNameProvider.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/VertexNameProvider.html new file mode 100644 index 00000000..a0d009cd --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/VertexNameProvider.html @@ -0,0 +1,216 @@ + + + + + + +VertexNameProvider (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Interface VertexNameProvider<V>

+
+
All Known Implementing Classes:
IntegerNameProvider, StringNameProvider
+
+
+
+
public interface VertexNameProvider<V>
+ + +

+Assigns a display name for each of the graph vertices. +

+ +

+


+ +

+ + + + + + + + + + + + +
+Method Summary
+ java.lang.StringgetVertexName(V vertex) + +
+          Returns a unique name for a vertex.
+  +

+ + + + + + + + +
+Method Detail
+ +

+getVertexName

+
+java.lang.String getVertexName(V 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. +

+

+
Parameters:
vertex - the vertex to be named +
Returns:
the name of the vertex
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/VisioExporter.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/VisioExporter.html new file mode 100644 index 00000000..e09f9f5d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/VisioExporter.html @@ -0,0 +1,294 @@ + + + + + + +VisioExporter (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.ext +
+Class VisioExporter<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.ext.VisioExporter<V,E>
+
+
+
+
public class VisioExporter<V,E>
extends java.lang.Object
+ + +

+Exports a graph to a csv format that can be imported into MS Visio. + +

Tip: By default, the exported graph doesn't show link directions. + To show link directions:
+ +

    +
  1. Select All (Ctrl-A)
  2. +
  3. Right Click the selected items
  4. +
  5. Format/Line...
  6. +
  7. Line ends: End: (choose an arrow)
  8. +
+

+

+ +

+

+
Author:
+
Avner Linder
+
+
+ +

+ + + + + + + + + + + + + + +
+Constructor Summary
VisioExporter() + +
+          Creates a new VisioExporter object.
VisioExporter(VertexNameProvider<V> vertexNameProvider) + +
+          Creates a new VisioExporter object with the specified naming policy.
+  + + + + + + + + + + + +
+Method Summary
+ voidexport(java.io.OutputStream output, + Graph<V,E> g) + +
+          Exports the specified graph into a Visio csv file format.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+VisioExporter

+
+public VisioExporter(VertexNameProvider<V> vertexNameProvider)
+
+
Creates a new VisioExporter object with the specified naming policy. +

+

+
Parameters:
vertexNameProvider - the vertex name provider to be used for naming + the Visio shapes.
+
+
+ +

+VisioExporter

+
+public VisioExporter()
+
+
Creates a new VisioExporter object. +

+

+ + + + + + + + +
+Method Detail
+ +

+export

+
+public void export(java.io.OutputStream output,
+                   Graph<V,E> g)
+
+
Exports the specified graph into a Visio csv file format. +

+

+
Parameters:
output - the print stream to which the graph to be exported.
g - the graph to be exported.
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-frame.html new file mode 100644 index 00000000..099ceb0c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-frame.html @@ -0,0 +1,67 @@ + + + + + + +org.jgrapht.ext (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.ext + + + + +
+Interfaces  + +
+EdgeNameProvider +
+JGraphModelAdapter.CellFactory +
+VertexNameProvider
+ + + + + + +
+Classes  + +
+DOTExporter +
+GmlExporter +
+GraphMLExporter +
+IntegerEdgeNameProvider +
+IntegerNameProvider +
+JGraphModelAdapter +
+JGraphModelAdapter.DefaultCellFactory +
+MatrixExporter +
+StringEdgeNameProvider +
+StringNameProvider +
+VisioExporter
+ + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-summary.html new file mode 100644 index 00000000..9a735e3e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-summary.html @@ -0,0 +1,237 @@ + + + + + + +org.jgrapht.ext (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package org.jgrapht.ext +

+ +Extensions and integration means to other products. +

+See: +
+          Description +

+ + + + + + + + + + + + + + + + + +
+Interface Summary
EdgeNameProvider<E>Assigns a display name for each of the graph edes.
JGraphModelAdapter.CellFactory<VV,EE>Creates the JGraph cells that reflect the respective JGraphT elements.
VertexNameProvider<V>Assigns a display name for each of the graph vertices.
+  + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Class Summary
DOTExporter<V,E>Exports a graph into a DOT file.
GmlExporter<V,E>Exports a graph into a GML file (Graph Modelling Language).
GraphMLExporter<V,E>Exports a graph into a GraphML file.
IntegerEdgeNameProvider<E>Assigns a unique integer to represent each edge.
IntegerNameProvider<V>Assigns a unique integer to represent each vertex.
JGraphModelAdapter<V,E>An adapter that reflects a JGraphT graph as a JGraph graph.
JGraphModelAdapter.DefaultCellFactory<VV,EE>A simple default cell factory.
MatrixExporter<V,E>Exports a graph to a plain text matrix format, which can be processed by + matrix manipulation software, such as + MTJ or MATLAB.
StringEdgeNameProvider<E>Generates edge names by invoking Object.toString() on them.
StringNameProvider<V>Generates vertex names by invoking Object.toString() on them.
VisioExporter<V,E>Exports a graph to a csv format that can be imported into MS Visio.
+  + +

+

+Package org.jgrapht.ext Description +

+ +

+

+Extensions and integration means to other products. +

+

+ +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-tree.html new file mode 100644 index 00000000..2646b657 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/ext/package-tree.html @@ -0,0 +1,166 @@ + + + + + + +org.jgrapht.ext Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package org.jgrapht.ext +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +

+Interface Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/CompleteBipartiteGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/CompleteBipartiteGraphGenerator.html new file mode 100644 index 00000000..a92f115b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/CompleteBipartiteGraphGenerator.html @@ -0,0 +1,285 @@ + + + + + + +CompleteBipartiteGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Class CompleteBipartiteGraphGenerator<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.generate.CompleteBipartiteGraphGenerator<V,E>
+
+
+
All Implemented Interfaces:
GraphGenerator<V,E,V>
+
+
+
+
public class CompleteBipartiteGraphGenerator<V,E>
extends java.lang.Object
implements GraphGenerator<V,E,V>
+ + +

+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.
+  + + + + + + + + + + + +
+Method Summary
+ voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
+          Construct a complete bipartite graph
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+CompleteBipartiteGraphGenerator

+
+public CompleteBipartiteGraphGenerator(int partitionOne,
+                                       int partitionTwo)
+
+
Creates a new CompleteBipartiteGraphGenerator object. +

+

+
Parameters:
partitionOne - This is the number of vertices in the first partition
partitionTwo - This is the number of vertices in the second parition
+
+ + + + + + + + +
+Method Detail
+ +

+generateGraph

+
+public void generateGraph(Graph<V,E> target,
+                          VertexFactory<V> vertexFactory,
+                          java.util.Map<java.lang.String,V> resultMap)
+
+
Construct a complete bipartite graph +

+

+
Specified by:
generateGraph in interface GraphGenerator<V,E,V>
+
+
+
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)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/CompleteGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/CompleteGraphGenerator.html new file mode 100644 index 00000000..e83d3db0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/CompleteGraphGenerator.html @@ -0,0 +1,296 @@ + + + + + + +CompleteGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Class CompleteGraphGenerator<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.generate.CompleteGraphGenerator<V,E>
+
+
+
All Implemented Interfaces:
GraphGenerator<V,E,V>
+
+
+
+
public class CompleteGraphGenerator<V,E>
extends java.lang.Object
implements GraphGenerator<V,E,V>
+ + +

+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. +

+ +

+

+
Since:
+
Nov 02, 2008
+
Author:
+
Tim Shearouse
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
CompleteGraphGenerator(int size) + +
+          Construct a new CompleteGraphGenerator.
+  + + + + + + + + + + + +
+Method Summary
+ voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
+          Generate a graph structure.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+CompleteGraphGenerator

+
+public CompleteGraphGenerator(int size)
+
+
Construct a new CompleteGraphGenerator. +

+

+
Parameters:
size - number of vertices to be generated +
Throws: +
java.lang.IllegalArgumentException - if the specified size is negative.
+
+ + + + + + + + +
+Method Detail
+ +

+generateGraph

+
+public void generateGraph(Graph<V,E> target,
+                          VertexFactory<V> vertexFactory,
+                          java.util.Map<java.lang.String,V> resultMap)
+
+
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. +

+

+
Specified by:
generateGraph in interface GraphGenerator<V,E,V>
+
+
+
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)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/EmptyGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/EmptyGraphGenerator.html new file mode 100644 index 00000000..758db2d7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/EmptyGraphGenerator.html @@ -0,0 +1,289 @@ + + + + + + +EmptyGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Class EmptyGraphGenerator<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.generate.EmptyGraphGenerator<V,E>
+
+
+
All Implemented Interfaces:
GraphGenerator<V,E,V>
+
+
+
+
public class EmptyGraphGenerator<V,E>
extends java.lang.Object
implements GraphGenerator<V,E,V>
+ + +

+Generates an empty + graph of any size. An empty graph is a graph that has no edges. +

+ +

+

+
Since:
+
Sep 16, 2003
+
Author:
+
John V. Sichi
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
EmptyGraphGenerator(int size) + +
+          Construct a new EmptyGraphGenerator.
+  + + + + + + + + + + + +
+Method Summary
+ voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
+          Generate a graph structure.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+EmptyGraphGenerator

+
+public EmptyGraphGenerator(int size)
+
+
Construct a new EmptyGraphGenerator. +

+

+
Parameters:
size - number of vertices to be generated +
Throws: +
java.lang.IllegalArgumentException - if the specified size is negative.
+
+ + + + + + + + +
+Method Detail
+ +

+generateGraph

+
+public void generateGraph(Graph<V,E> target,
+                          VertexFactory<V> vertexFactory,
+                          java.util.Map<java.lang.String,V> resultMap)
+
+
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. +

+

+
Specified by:
generateGraph in interface GraphGenerator<V,E,V>
+
+
+
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)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/GraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/GraphGenerator.html new file mode 100644 index 00000000..7c5bc0ce --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/GraphGenerator.html @@ -0,0 +1,233 @@ + + + + + + +GraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Interface GraphGenerator<V,E,T>

+
+
All Known Implementing Classes:
CompleteBipartiteGraphGenerator, CompleteGraphGenerator, EmptyGraphGenerator, HyperCubeGraphGenerator, LinearGraphGenerator, RandomGraphGenerator, RingGraphGenerator, ScaleFreeGraphGenerator, StarGraphGenerator, WheelGraphGenerator
+
+
+
+
public interface GraphGenerator<V,E,T>
+ + +

+GraphGenerator defines an interface for generating new graph structures. +

+ +

+

+
Since:
+
Sep 16, 2003
+
Author:
+
John V. Sichi
+
+
+ +

+ + + + + + + + + + + + +
+Method Summary
+ voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,T> resultMap) + +
+          Generate a graph structure.
+  +

+ + + + + + + + +
+Method Detail
+ +

+generateGraph

+
+void generateGraph(Graph<V,E> target,
+                   VertexFactory<V> vertexFactory,
+                   java.util.Map<java.lang.String,T> resultMap)
+
+
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)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/HyperCubeGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/HyperCubeGraphGenerator.html new file mode 100644 index 00000000..a47fc8a9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/HyperCubeGraphGenerator.html @@ -0,0 +1,283 @@ + + + + + + +HyperCubeGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Class HyperCubeGraphGenerator<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.generate.HyperCubeGraphGenerator<V,E>
+
+
+
All Implemented Interfaces:
GraphGenerator<V,E,V>
+
+
+
+
public class HyperCubeGraphGenerator<V,E>
extends java.lang.Object
implements GraphGenerator<V,E,V>
+ + +

+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. +

+ +

+

+
Since:
+
Dec 21, 2008
+
Author:
+
Andrew Newell
+
+
+ +

+ + + + + + + + + + + +
+Constructor Summary
HyperCubeGraphGenerator(int dim) + +
+          Creates a new HyperCubeGraphGenerator object.
+  + + + + + + + + + + + +
+Method Summary
+ voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
+          This will generate the hypercube graph
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+HyperCubeGraphGenerator

+
+public HyperCubeGraphGenerator(int dim)
+
+
Creates a new HyperCubeGraphGenerator object. +

+

+
Parameters:
dim - This is the dimension of the hypercube.
+
+ + + + + + + + +
+Method Detail
+ +

+generateGraph

+
+public void generateGraph(Graph<V,E> target,
+                          VertexFactory<V> vertexFactory,
+                          java.util.Map<java.lang.String,V> resultMap)
+
+
This will generate the hypercube graph +

+

+
Specified by:
generateGraph in interface GraphGenerator<V,E,V>
+
+
+
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)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/LinearGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/LinearGraphGenerator.html new file mode 100644 index 00000000..08aa0f7e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/LinearGraphGenerator.html @@ -0,0 +1,347 @@ + + + + + + +LinearGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Class LinearGraphGenerator<V,E>

+
+java.lang.Object
+  extended by org.jgrapht.generate.LinearGraphGenerator<V,E>
+
+
+
All Implemented Interfaces:
GraphGenerator<V,E,V>
+
+
+
+
public class LinearGraphGenerator<V,E>
extends java.lang.Object
implements GraphGenerator<V,E,V>
+ + +

+Generates a linear graph of any size. For a directed graph, the edges are + oriented from START_VERTEX to END_VERTEX. +

+ +

+

+
Since:
+
Sep 16, 2003
+
Author:
+
John V. Sichi
+
+
+ +

+ + + + + + + + + + + + + + + +
+Field Summary
+static java.lang.StringEND_VERTEX + +
+          Role for the last vertex generated.
+static java.lang.StringSTART_VERTEX + +
+          Role for the first vertex generated.
+  + + + + + + + + + + +
+Constructor Summary
LinearGraphGenerator(int size) + +
+          Construct a new LinearGraphGenerator.
+  + + + + + + + + + + + +
+Method Summary
+ voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
+          Generate a graph structure.
+ + + + + + + +
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+START_VERTEX

+
+public static final java.lang.String START_VERTEX
+
+
Role for the first vertex generated. +

+

+
See Also:
Constant Field Values
+
+
+ +

+END_VERTEX

+
+public static final java.lang.String END_VERTEX
+
+
Role for the last vertex generated. +

+

+
See Also:
Constant Field Values
+
+ + + + + + + + +
+Constructor Detail
+ +

+LinearGraphGenerator

+
+public LinearGraphGenerator(int size)
+
+
Construct a new LinearGraphGenerator. +

+

+
Parameters:
size - number of vertices to be generated +
Throws: +
java.lang.IllegalArgumentException - if the specified size is negative.
+
+ + + + + + + + +
+Method Detail
+ +

+generateGraph

+
+public void generateGraph(Graph<V,E> target,
+                          VertexFactory<V> vertexFactory,
+                          java.util.Map<java.lang.String,V> resultMap)
+
+
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. +

+

+
Specified by:
generateGraph in interface GraphGenerator<V,E,V>
+
+
+
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)
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.DefaultEdgeTopologyFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.DefaultEdgeTopologyFactory.html new file mode 100644 index 00000000..108090df --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.DefaultEdgeTopologyFactory.html @@ -0,0 +1,399 @@ + + + + + + +RandomGraphGenerator.DefaultEdgeTopologyFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +org.jgrapht.generate +
+Class RandomGraphGenerator.DefaultEdgeTopologyFactory<VV,EE>

+
+java.lang.Object
+  extended by org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory<VV,EE>
+
+
+
All Implemented Interfaces:
RandomGraphGenerator.EdgeTopologyFactory<VV,EE>
+
+
+
Enclosing class:
RandomGraphGenerator<V,E>
+
+
+
+
public class RandomGraphGenerator.DefaultEdgeTopologyFactory<VV,EE>
extends java.lang.Object
implements RandomGraphGenerator.EdgeTopologyFactory<VV,EE>
+ + +

+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. +

    + +

    +

    +
    Since:
    +
    Aug 6, 2005
    +
    Author:
    +
    Assaf
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    RandomGraphGenerator.DefaultEdgeTopologyFactory() + +
    +           
    +  + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + voidcreateEdges(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.
    + intgetMaxEdgesForVertexNum(Graph<VV,EE> targetGraph) + +
    +          Return max edges for that graph.
    + booleanisNumberOfEdgesValid(Graph<VV,EE> targetGraph, + int numberOfEdges) + +
    +          checks if the numOfEdges is smaller than the Max edges according to + the following table:
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +RandomGraphGenerator.DefaultEdgeTopologyFactory

    +
    +public RandomGraphGenerator.DefaultEdgeTopologyFactory()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +createEdges

    +
    +public void createEdges(Graph<VV,EE> targetGraph,
    +                        java.util.Map<java.lang.Integer,VV> orderToVertexMap,
    +                        int numberOfEdges,
    +                        java.util.Random randomizer)
    +
    +
    Description copied from interface: RandomGraphGenerator.EdgeTopologyFactory
    +
    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. +

    +

    +
    Specified by:
    createEdges in interface RandomGraphGenerator.EdgeTopologyFactory<VV,EE>
    +
    +
    +
    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
    +
    +
    +
    + +

    +isNumberOfEdgesValid

    +
    +public boolean isNumberOfEdgesValid(Graph<VV,EE> targetGraph,
    +                                    int numberOfEdges)
    +
    +
    checks if the numOfEdges is smaller than the Max edges according to + the following table: + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Graph TypeDirected / UnDirectedmultiple edgesloopsMax Edges
    SimpleGraphUnDirected--N(N-1)/2
    MultigraphUnDirected+-Infinite
    PseudographUnDirected++Infinite
    SimpleDirectedGraphDirected--N (N-1)
    DefaultDirectedGraphDirected-+N*(N-1)+ N = N^2
    DirectedMultigraphDirected++Infinite
    +

    +

    +
    Specified by:
    isNumberOfEdgesValid in interface RandomGraphGenerator.EdgeTopologyFactory<VV,EE>
    +
    +
    +
    Parameters:
    targetGraph - guranteed to start with zero edges.
    See Also:
    RandomGraphGenerator.EdgeTopologyFactory.isNumberOfEdgesValid(Graph, + int)
    +
    +
    +
    + +

    +getMaxEdgesForVertexNum

    +
    +public int getMaxEdgesForVertexNum(Graph<VV,EE> targetGraph)
    +
    +
    Return max edges for that graph. If it is infinite return -1 instead. +

    +

    +
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.EdgeTopologyFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.EdgeTopologyFactory.html new file mode 100644 index 00000000..dc0ba5a7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.EdgeTopologyFactory.html @@ -0,0 +1,259 @@ + + + + + + +RandomGraphGenerator.EdgeTopologyFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.generate +
    +Interface RandomGraphGenerator.EdgeTopologyFactory<VV,EE>

    +
    +
    All Known Implementing Classes:
    RandomGraphGenerator.DefaultEdgeTopologyFactory
    +
    +
    +
    Enclosing class:
    RandomGraphGenerator<V,E>
    +
    +
    +
    +
    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
    + voidcreateEdges(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.
    + booleanisNumberOfEdgesValid(Graph<VV,EE> targetGraph, + int numberOfEdges) + +
    +          Checks if the graph can contain the givven numberOfEdges according to + the graph type restrictions.
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +createEdges

    +
    +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. 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 +

    +

    +
    Parameters:
    targetGraph - guranteed to start with zero edges.
    numberOfEdges -
    +
    +
  • + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.html new file mode 100644 index 00000000..374f2a96 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RandomGraphGenerator.html @@ -0,0 +1,388 @@ + + + + + + +RandomGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.generate +
    +Class RandomGraphGenerator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.generate.RandomGraphGenerator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphGenerator<V,E,V>
    +
    +
    +
    +
    public class RandomGraphGenerator<V,E>
    extends java.lang.Object
    implements GraphGenerator<V,E,V>
    + + +

    +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). +

    + +

    +

    +
    Since:
    +
    Aug 6, 2005
    +
    Author:
    +
    Assaf Lehr
    +
    +
    + +

    + + + + + + + + + + + + + + + +
    +Nested Class Summary
    + classRandomGraphGenerator.DefaultEdgeTopologyFactory<VV,EE> + +
    +          Default implementation of the EdgeTopologyFactory interface.
    +static interfaceRandomGraphGenerator.EdgeTopologyFactory<VV,EE> + +
    +          This class is used to generate the edge topology for a graph.
    + + + + + + + + + + + + + + + + + + +
    +Field Summary
    +protected  intnumOfEdges + +
    +           
    +protected  intnumOfVertexes + +
    +           
    +protected  java.util.Randomrandomizer + +
    +           
    +  + + + + + + + + + + +
    +Constructor Summary
    RandomGraphGenerator(int aNumOfVertexes, + int aNumOfEdges) + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    + voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
    +          (non-Javadoc)
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +numOfVertexes

    +
    +protected int numOfVertexes
    +
    +
    +
    +
    +
    + +

    +numOfEdges

    +
    +protected int numOfEdges
    +
    +
    +
    +
    +
    + +

    +randomizer

    +
    +protected java.util.Random randomizer
    +
    +
    +
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +RandomGraphGenerator

    +
    +public RandomGraphGenerator(int aNumOfVertexes,
    +                            int aNumOfEdges)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +generateGraph

    +
    +public void generateGraph(Graph<V,E> target,
    +                          VertexFactory<V> vertexFactory,
    +                          java.util.Map<java.lang.String,V> resultMap)
    +
    +
    (non-Javadoc) +

    +

    +
    Specified by:
    generateGraph in interface GraphGenerator<V,E,V>
    +
    +
    +
    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) +
    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)
    See Also:
    GraphGenerator.generateGraph(Graph, VertexFactory, Map)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RingGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RingGraphGenerator.html new file mode 100644 index 00000000..9cb0f5ac --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/RingGraphGenerator.html @@ -0,0 +1,291 @@ + + + + + + +RingGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.generate +
    +Class RingGraphGenerator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.generate.RingGraphGenerator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphGenerator<V,E,V>
    +
    +
    +
    +
    public class RingGraphGenerator<V,E>
    extends java.lang.Object
    implements GraphGenerator<V,E,V>
    + + +

    +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. +

    + +

    +

    +
    Since:
    +
    Sep 16, 2003
    +
    Author:
    +
    John V. Sichi
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    RingGraphGenerator(int size) + +
    +          Construct a new RingGraphGenerator.
    +  + + + + + + + + + + + +
    +Method Summary
    + voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
    +          Generate a graph structure.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +RingGraphGenerator

    +
    +public RingGraphGenerator(int size)
    +
    +
    Construct a new RingGraphGenerator. +

    +

    +
    Parameters:
    size - number of vertices to be generated +
    Throws: +
    java.lang.IllegalArgumentException - if the specified size is negative.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +generateGraph

    +
    +public void generateGraph(Graph<V,E> target,
    +                          VertexFactory<V> vertexFactory,
    +                          java.util.Map<java.lang.String,V> resultMap)
    +
    +
    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. +

    +

    +
    Specified by:
    generateGraph in interface GraphGenerator<V,E,V>
    +
    +
    +
    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)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/ScaleFreeGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/ScaleFreeGraphGenerator.html new file mode 100644 index 00000000..3effa42b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/ScaleFreeGraphGenerator.html @@ -0,0 +1,306 @@ + + + + + + +ScaleFreeGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.generate +
    +Class ScaleFreeGraphGenerator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.generate.ScaleFreeGraphGenerator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphGenerator<V,E,V>
    +
    +
    +
    +
    public class ScaleFreeGraphGenerator<V,E>
    extends java.lang.Object
    implements GraphGenerator<V,E,V>
    + + +

    +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. +

    + +

    +

    +
    Author:
    +
    Ilya Razenshteyn
    +
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    ScaleFreeGraphGenerator(int size) + +
    +          Constructs a new ScaleFreeGraphGenerator.
    ScaleFreeGraphGenerator(int size, + long seed) + +
    +          Constructs a new ScaleFreeGraphGenerator using fixed + seed for the random generator.
    +  + + + + + + + + + + + +
    +Method Summary
    + voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
    +          Generates scale-free network with size passed to the + constructor.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ScaleFreeGraphGenerator

    +
    +public ScaleFreeGraphGenerator(int size)
    +
    +
    Constructs a new ScaleFreeGraphGenerator. +

    +

    +
    Parameters:
    size - number of vertices to be generated
    +
    +
    + +

    +ScaleFreeGraphGenerator

    +
    +public ScaleFreeGraphGenerator(int size,
    +                               long seed)
    +
    +
    Constructs a new ScaleFreeGraphGenerator using fixed + seed for the random generator. +

    +

    +
    Parameters:
    size - number of vertices to be generated
    seed - initial seed for the random generator
    +
    + + + + + + + + +
    +Method Detail
    + +

    +generateGraph

    +
    +public void generateGraph(Graph<V,E> target,
    +                          VertexFactory<V> vertexFactory,
    +                          java.util.Map<java.lang.String,V> resultMap)
    +
    +
    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). +

    +

    +
    Specified by:
    generateGraph in interface GraphGenerator<V,E,V>
    +
    +
    +
    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 - unused parameter
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/StarGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/StarGraphGenerator.html new file mode 100644 index 00000000..ed80f90d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/StarGraphGenerator.html @@ -0,0 +1,317 @@ + + + + + + +StarGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.generate +
    +Class StarGraphGenerator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.generate.StarGraphGenerator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphGenerator<V,E,V>
    +
    +
    +
    +
    public class StarGraphGenerator<V,E>
    extends java.lang.Object
    implements GraphGenerator<V,E,V>
    + + +

    +Generates a star + graph of any size. This is a graph where every vertex has exactly one + edge with a center vertex. +

    + +

    +

    +
    Since:
    +
    Dec 21, 2008
    +
    Author:
    +
    Andrew Newell
    +
    +
    + +

    + + + + + + + + + + + +
    +Field Summary
    +static java.lang.StringCENTER_VERTEX + +
    +           
    +  + + + + + + + + + + +
    +Constructor Summary
    StarGraphGenerator(int order) + +
    +          Creates a new StarGraphGenerator object.
    +  + + + + + + + + + + + +
    +Method Summary
    + voidgenerateGraph(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
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +CENTER_VERTEX

    +
    +public static final java.lang.String CENTER_VERTEX
    +
    +
    +
    See Also:
    Constant Field Values
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +StarGraphGenerator

    +
    +public StarGraphGenerator(int order)
    +
    +
    Creates a new StarGraphGenerator object. +

    +

    +
    Parameters:
    order - number of total vertices including the center vertex
    +
    + + + + + + + + +
    +Method Detail
    + +

    +generateGraph

    +
    +public 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 +

    +

    +
    Specified by:
    generateGraph in interface GraphGenerator<V,E,V>
    +
    +
    +
    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)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/WheelGraphGenerator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/WheelGraphGenerator.html new file mode 100644 index 00000000..fa65dec2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/WheelGraphGenerator.html @@ -0,0 +1,353 @@ + + + + + + +WheelGraphGenerator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.generate +
    +Class WheelGraphGenerator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.generate.WheelGraphGenerator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphGenerator<V,E,V>
    +
    +
    +
    +
    public class WheelGraphGenerator<V,E>
    extends java.lang.Object
    implements GraphGenerator<V,E,V>
    + + +

    +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". +

    + +

    +

    +
    Since:
    +
    Sep 16, 2003
    +
    Author:
    +
    John V. Sichi
    +
    +
    + +

    + + + + + + + + + + + +
    +Field Summary
    +static java.lang.StringHUB_VERTEX + +
    +          Role for the hub vertex.
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    WheelGraphGenerator(int size) + +
    +          Creates a new WheelGraphGenerator object.
    WheelGraphGenerator(int size, + boolean inwardSpokes) + +
    +          Construct a new WheelGraphGenerator.
    +  + + + + + + + + + + + +
    +Method Summary
    + voidgenerateGraph(Graph<V,E> target, + VertexFactory<V> vertexFactory, + java.util.Map<java.lang.String,V> resultMap) + +
    +          Generate a graph structure.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +HUB_VERTEX

    +
    +public static final java.lang.String HUB_VERTEX
    +
    +
    Role for the hub vertex. +

    +

    +
    See Also:
    Constant Field Values
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +WheelGraphGenerator

    +
    +public WheelGraphGenerator(int size)
    +
    +
    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. +

    +

    +
    Parameters:
    size - number of vertices to be generated.
    +
    +
    + +

    +WheelGraphGenerator

    +
    +public WheelGraphGenerator(int size,
    +                           boolean inwardSpokes)
    +
    +
    Construct a new WheelGraphGenerator. +

    +

    +
    Parameters:
    size - number of vertices to be generated.
    inwardSpokes - if true and graph is directed, spokes + are oriented from rim to hub; else from hub to rim. +
    Throws: +
    java.lang.IllegalArgumentException
    +
    + + + + + + + + +
    +Method Detail
    + +

    +generateGraph

    +
    +public void generateGraph(Graph<V,E> target,
    +                          VertexFactory<V> vertexFactory,
    +                          java.util.Map<java.lang.String,V> resultMap)
    +
    +
    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. +

    +

    +
    Specified by:
    generateGraph in interface GraphGenerator<V,E,V>
    +
    +
    +
    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)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-frame.html new file mode 100644 index 00000000..0746d903 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-frame.html @@ -0,0 +1,63 @@ + + + + + + +org.jgrapht.generate (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.generate + + + + +
    +Interfaces  + +
    +GraphGenerator +
    +RandomGraphGenerator.EdgeTopologyFactory
    + + + + + + +
    +Classes  + +
    +CompleteBipartiteGraphGenerator +
    +CompleteGraphGenerator +
    +EmptyGraphGenerator +
    +HyperCubeGraphGenerator +
    +LinearGraphGenerator +
    +RandomGraphGenerator +
    +RingGraphGenerator +
    +ScaleFreeGraphGenerator +
    +StarGraphGenerator +
    +WheelGraphGenerator
    + + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-summary.html new file mode 100644 index 00000000..f4aeee26 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-summary.html @@ -0,0 +1,233 @@ + + + + + + +org.jgrapht.generate (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package org.jgrapht.generate +

    +Generators for graphs of various topologies. +

    +See: +
    +          Description +

    + + + + + + + + + + + + + +
    +Interface Summary
    GraphGenerator<V,E,T>GraphGenerator defines an interface for generating new graph structures.
    RandomGraphGenerator.EdgeTopologyFactory<VV,EE>This class is used to generate the edge topology for a graph.
    +  + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Class Summary
    CompleteBipartiteGraphGenerator<V,E>Generates a complete + bipartite graph of any size.
    CompleteGraphGenerator<V,E>Generates a complete graph of any size.
    EmptyGraphGenerator<V,E>Generates an empty + graph of any size.
    HyperCubeGraphGenerator<V,E>Generates a hyper + cube graph of any size.
    LinearGraphGenerator<V,E>Generates a linear graph of any size.
    RandomGraphGenerator<V,E>This Generator creates a random-topology graph of a specified number of + vertexes and edges.
    RingGraphGenerator<V,E>Generates a ring graph of any size.
    ScaleFreeGraphGenerator<V,E>Generates directed or undirected scale-free network + of any size.
    StarGraphGenerator<V,E>Generates a star + graph of any size.
    WheelGraphGenerator<V,E>Generates a wheel + graph of any size.
    +  + +

    +

    +Package org.jgrapht.generate Description +

    + +

    +Generators for graphs of various topologies. +

    + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-tree.html new file mode 100644 index 00000000..69ca20c7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/generate/package-tree.html @@ -0,0 +1,167 @@ + + + + + + +org.jgrapht.generate Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package org.jgrapht.generate +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AbstractBaseGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AbstractBaseGraph.html new file mode 100644 index 00000000..86e96b18 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AbstractBaseGraph.html @@ -0,0 +1,1092 @@ + + + + + + +AbstractBaseGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class AbstractBaseGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DefaultDirectedGraph, DirectedMultigraph, DirectedPseudograph, Multigraph, Pseudograph, SimpleDirectedGraph, SimpleGraph
    +
    +
    +
    +
    public abstract class AbstractBaseGraph<V,E>
    extends AbstractGraph<V,E>
    implements Graph<V,E>, java.lang.Cloneable, java.io.Serializable
    + + +

    +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).

    +

    + +

    +

    +
    Since:
    +
    Jul 24, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    AbstractBaseGraph(EdgeFactory<V,E> ef, + boolean allowMultipleEdges, + boolean allowLoops) + +
    +          Construct a new pseudograph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this graph if not already present.
    + java.lang.Objectclone() + +
    +          Returns a shallow copy of this graph instance.
    + booleancontainsEdge(E e) + +
    +          Returns true if this graph contains the specified edge.
    + booleancontainsVertex(V v) + +
    +          Returns true if this graph contains the specified vertex.
    + intdegreeOf(V vertex) + +
    +           
    + java.util.Set<E>edgeSet() + +
    +          Returns a set of the edges contained in this graph.
    + java.util.Set<E>edgesOf(V vertex) + +
    +          Returns a set of all edges touching the specified vertex.
    + 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.
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + EdgeFactory<V,E>getEdgeFactory() + +
    +          Returns the edge factory using which this graph creates new edges.
    + VgetEdgeSource(E e) + +
    +          Returns the source vertex of an edge.
    + VgetEdgeTarget(E e) + +
    +          Returns the target vertex of an edge.
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +           
    + intinDegreeOf(V vertex) + +
    +           
    + booleanisAllowingLoops() + +
    +          Returns true if and only if self-loops are allowed in this + graph.
    + booleanisAllowingMultipleEdges() + +
    +          Returns true if and only if multiple edges are allowed in + this graph.
    + intoutDegreeOf(V vertex) + +
    +           
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +           
    + booleanremoveEdge(E e) + +
    +          Removes the specified edge from the graph.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
    + booleanremoveVertex(V v) + +
    +          Removes the specified vertex from this graph including all its touching + edges if present.
    + voidsetEdgeSetFactory(EdgeSetFactory<V,E> edgeSetFactory) + +
    +          Set the EdgeSetFactory to use for this graph.
    + voidsetEdgeWeight(E e, + double weight) + +
    +           
    + java.util.Set<V>vertexSet() + +
    +          Returns a set of the vertices contained in this graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    containsEdge, removeAllEdges, removeAllEdges, removeAllVertices
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +AbstractBaseGraph

    +
    +public AbstractBaseGraph(EdgeFactory<V,E> ef,
    +                         boolean allowMultipleEdges,
    +                         boolean allowLoops)
    +
    +
    Construct a new pseudograph. The pseudograph can either be directed or + undirected, depending on the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    allowMultipleEdges - whether to allow multiple edges or not.
    allowLoops - whether to allow edges that are self-loops or not. +
    Throws: +
    java.lang.NullPointerException - if the specified edge factory is + null.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getAllEdges

    +
    +public java.util.Set<E> getAllEdges(V sourceVertex,
    +                                    V targetVertex)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    Specified by:
    getAllEdges in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.getAllEdges(Object, Object)
    +
    +
    +
    + +

    +isAllowingLoops

    +
    +public boolean isAllowingLoops()
    +
    +
    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 E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    getEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    an edge connecting source vertex to target vertex.
    See Also:
    Graph.getEdge(Object, Object)
    +
    +
    +
    + +

    +getEdgeFactory

    +
    +public EdgeFactory<V,E> getEdgeFactory()
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeFactory in interface Graph<V,E>
    +
    +
    + +
    Returns:
    the edge factory using which this graph creates new edges.
    See Also:
    Graph.getEdgeFactory()
    +
    +
    +
    + +

    +setEdgeSetFactory

    +
    +public void setEdgeSetFactory(EdgeSetFactory<V,E> edgeSetFactory)
    +
    +
    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 E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be added to this graph. +
    Returns:
    true if this graph did not already contain the specified + vertex.
    See Also:
    Graph.addVertex(Object)
    +
    +
    +
    + +

    +getEdgeSource

    +
    +public V getEdgeSource(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeSource in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    source vertex
    See Also:
    Graph.getEdgeSource(Object)
    +
    +
    +
    + +

    +getEdgeTarget

    +
    +public V getEdgeTarget(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeTarget in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    target vertex
    See Also:
    Graph.getEdgeTarget(Object)
    +
    +
    +
    + +

    +clone

    +
    +public java.lang.Object clone()
    +
    +
    Returns a shallow copy of this graph instance. Neither edges nor vertices + are cloned. +

    +

    +
    Overrides:
    clone in class java.lang.Object
    +
    +
    + +
    Returns:
    a shallow copy of this set. +
    Throws: +
    java.lang.RuntimeException
    See Also:
    Object.clone()
    +
    +
    +
    + +

    +containsEdge

    +
    +public boolean containsEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified edge.
    See Also:
    Graph.containsEdge(Object)
    +
    +
    +
    + +

    +containsVertex

    +
    +public boolean containsVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified vertex.
    See Also:
    Graph.containsVertex(Object)
    +
    +
    +
    + +

    +degreeOf

    +
    +public int degreeOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    UndirectedGraph.degreeOf(Object)
    +
    +
    +
    + +

    +edgeSet

    +
    +public java.util.Set<E> edgeSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    edgeSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set of the edges contained in this graph.
    See Also:
    Graph.edgeSet()
    +
    +
    +
    + +

    +edgesOf

    +
    +public java.util.Set<E> edgesOf(V vertex)
    +
    +
    Description copied from interface: Graph
    +
    Returns a set of all edges touching the specified vertex. If no edges are + touching the specified vertex returns an empty set. +

    +

    +
    Specified by:
    edgesOf in interface Graph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which a set of touching edges is to be + returned. +
    Returns:
    a set of all edges touching the specified vertex.
    See Also:
    Graph.edgesOf(Object)
    +
    +
    +
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.inDegreeOf(Object)
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.incomingEdgesOf(Object)
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.outDegreeOf(Object)
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.outgoingEdgesOf(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge to be removed from this graph, if present. +
    Returns:
    true if and only if the graph contained the + specified edge.
    See Also:
    Graph.removeEdge(Object)
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be removed from this graph, if present. +
    Returns:
    true if the graph contained the specified vertex; + false otherwise.
    See Also:
    Graph.removeVertex(Object)
    +
    +
    +
    + +

    +vertexSet

    +
    +public java.util.Set<V> vertexSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    vertexSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set view of the vertices contained in this graph.
    See Also:
    Graph.vertexSet()
    +
    +
    +
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    Graph.getEdgeWeight(Object)
    +
    +
    +
    + +

    +setEdgeWeight

    +
    +public void setEdgeWeight(E e,
    +                          double weight)
    +
    +
    +
    +
    +
    +
    See Also:
    WeightedGraph.setEdgeWeight(Object, double)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AbstractGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AbstractGraph.html new file mode 100644 index 00000000..961eab38 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AbstractGraph.html @@ -0,0 +1,507 @@ + + + + + + +AbstractGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class AbstractGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    AbstractBaseGraph, GraphDelegator, GraphUnion, MaskSubgraph, Subgraph
    +
    +
    +
    +
    public abstract class AbstractGraph<V,E>
    extends java.lang.Object
    implements Graph<V,E>
    + + +

    +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. +

    + +

    +

    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Graph, +DirectedGraph, +UndirectedGraph
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    AbstractGraph() + +
    +          Construct a new empty graph object.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    +protected  booleanassertVertexExist(V v) + +
    +          Ensures that the specified vertex exists in this graph, or else throws + exception.
    + booleancontainsEdge(V sourceVertex, + V targetVertex) + +
    +          Returns true if and only if this graph contains an edge going + from the source vertex to the target vertex.
    + booleanremoveAllEdges(java.util.Collection<? extends E> edges) + +
    +          Removes all the edges in this graph that are also contained in the + specified edge collection.
    +protected  booleanremoveAllEdges(E[] edges) + +
    +          Removes all the edges in this graph that are also contained in the + specified edge array.
    + 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.
    + booleanremoveAllVertices(java.util.Collection<? extends V> vertices) + +
    +          Removes all the vertices in this graph that are also contained in the + specified vertex collection.
    + java.lang.StringtoString() + +
    +          Returns a string of the parenthesized pair (V, E) representing this + G=(V,E) graph.
    +protected  java.lang.StringtoStringFromSets(java.util.Collection<? extends V> vertexSet, + java.util.Collection<? extends E> edgeSet, + boolean directed) + +
    +          Helper for subclass implementations of toString( ).
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +AbstractGraph

    +
    +public AbstractGraph()
    +
    +
    Construct a new empty graph object. +

    +

    + + + + + + + + +
    +Method Detail
    + +

    +containsEdge

    +
    +public boolean containsEdge(V sourceVertex,
    +                            V targetVertex)
    +
    +
    Description copied from interface: 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. +

    +

    +
    Specified by:
    containsEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    true if this graph contains the specified edge.
    See Also:
    Graph.containsEdge(Object, Object)
    +
    +
    +
    + +

    +removeAllEdges

    +
    +public boolean removeAllEdges(java.util.Collection<? extends E> edges)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeAllEdges in interface Graph<V,E>
    +
    +
    +
    Parameters:
    edges - edges to be removed from this graph. +
    Returns:
    true if this graph changed as a result of the call
    See Also:
    Graph.removeAllEdges(Collection)
    +
    +
    +
    + +

    +removeAllEdges

    +
    +public java.util.Set<E> removeAllEdges(V sourceVertex,
    +                                       V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeAllEdges in interface Graph<V,E>
    +
    +
    +
    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
    See Also:
    Graph.removeAllEdges(Object, Object)
    +
    +
    +
    + +

    +removeAllVertices

    +
    +public boolean removeAllVertices(java.util.Collection<? extends V> vertices)
    +
    +
    Description copied from interface: 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 Graph.removeVertex(Object) method. +

    +

    +
    Specified by:
    removeAllVertices in interface Graph<V,E>
    +
    +
    +
    Parameters:
    vertices - vertices to be removed from this graph. +
    Returns:
    true if this graph changed as a result of the call
    See Also:
    Graph.removeAllVertices(Collection)
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    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. +

    +

    +
    Overrides:
    toString in class java.lang.Object
    +
    +
    + +
    Returns:
    a string representation of this graph.
    +
    +
    +
    + +

    +assertVertexExist

    +
    +protected boolean assertVertexExist(V v)
    +
    +
    Ensures that the specified vertex exists in this graph, or else throws + exception. +

    +

    +
    +
    +
    +
    Parameters:
    v - vertex +
    Returns:
    true if this assertion holds. +
    Throws: +
    java.lang.NullPointerException - if specified vertex is null. +
    java.lang.IllegalArgumentException - if specified vertex does not exist in + this graph.
    +
    +
    +
    + +

    +removeAllEdges

    +
    +protected boolean removeAllEdges(E[] edges)
    +
    +
    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.
    See Also:
    Graph.removeEdge(Object), +Graph.containsEdge(Object)
    +
    +
    +
    + +

    +toStringFromSets

    +
    +protected java.lang.String toStringFromSets(java.util.Collection<? extends V> vertexSet,
    +                                            java.util.Collection<? extends E> edgeSet,
    +                                            boolean directed)
    +
    +
    Helper for subclass implementations of toString( ). +

    +

    +
    +
    +
    +
    Parameters:
    vertexSet - the vertex set V to be printed
    edgeSet - the edge set E to be printed
    directed - true to use parens for each edge (representing directed); + false to use curly braces (representing undirected) +
    Returns:
    a string representation of (V,E)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUndirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUndirectedGraph.html new file mode 100644 index 00000000..2c95351a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUndirectedGraph.html @@ -0,0 +1,604 @@ + + + + + + +AsUndirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class AsUndirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.AsUndirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    +
    public class AsUndirectedGraph<V,E>
    extends GraphDelegator<V,E>
    implements java.io.Serializable, UndirectedGraph<V,E>
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    Aug 14, 2003
    +
    Author:
    +
    John V. Sichi
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    AsUndirectedGraph(DirectedGraph<V,E> g) + +
    +          Constructor for AsUndirectedGraph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + intdegreeOf(V vertex) + +
    +          Returns the degree of the specified vertex.
    + 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.
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +           
    + intinDegreeOf(V vertex) + +
    +           
    + intoutDegreeOf(V vertex) + +
    +           
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +           
    + java.lang.StringtoString() + +
    +          Returns a string of the parenthesized pair (V, E) representing this + G=(V,E) graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +AsUndirectedGraph

    +
    +public AsUndirectedGraph(DirectedGraph<V,E> g)
    +
    +
    Constructor for AsUndirectedGraph. +

    +

    +
    Parameters:
    g - the backing directed graph over which an undirected view is to + be created.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getAllEdges

    +
    +public java.util.Set<E> getAllEdges(V sourceVertex,
    +                                    V targetVertex)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    Specified by:
    getAllEdges in interface Graph<V,E>
    Overrides:
    getAllEdges in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.getAllEdges(Object, Object)
    +
    +
    +
    + +

    +getEdge

    +
    +public E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    getEdge in interface Graph<V,E>
    Overrides:
    getEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    an edge connecting source vertex to target vertex.
    See Also:
    Graph.getEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +degreeOf

    +
    +public int degreeOf(V vertex)
    +
    +
    Description copied from interface: UndirectedGraph
    +
    Returns the degree of the specified vertex. A degree of a vertex in an + undirected graph is the number of edges touching that vertex. +

    +

    +
    Specified by:
    degreeOf in interface UndirectedGraph<V,E>
    Overrides:
    degreeOf in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    See Also:
    UndirectedGraph.degreeOf(Object)
    +
    +
    +
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    +
    Overrides:
    inDegreeOf in class GraphDelegator<V,E>
    +
    +
    +
    See Also:
    DirectedGraph.inDegreeOf(Object)
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    +
    Overrides:
    incomingEdgesOf in class GraphDelegator<V,E>
    +
    +
    +
    See Also:
    DirectedGraph.incomingEdgesOf(Object)
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    +
    Overrides:
    outDegreeOf in class GraphDelegator<V,E>
    +
    +
    +
    See Also:
    DirectedGraph.outDegreeOf(Object)
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    +
    Overrides:
    outgoingEdgesOf in class GraphDelegator<V,E>
    +
    +
    +
    See Also:
    DirectedGraph.outgoingEdgesOf(Object)
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    Description copied from class: AbstractGraph
    +
    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. +

    +

    +
    Overrides:
    toString in class GraphDelegator<V,E>
    +
    +
    + +
    Returns:
    a string representation of this graph.
    See Also:
    AbstractGraph.toString()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUnweightedDirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUnweightedDirectedGraph.html new file mode 100644 index 00000000..572ccdc2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUnweightedDirectedGraph.html @@ -0,0 +1,328 @@ + + + + + + +AsUnweightedDirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class AsUnweightedDirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.AsUnweightedDirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    +
    public class AsUnweightedDirectedGraph<V,E>
    extends GraphDelegator<V,E>
    implements java.io.Serializable, DirectedGraph<V,E>
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    Sep 7, 2007
    +
    Author:
    +
    Lucas J. Scharenbroich
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    AsUnweightedDirectedGraph(DirectedGraph<V,E> g) + +
    +          Constructor for AsUnweightedGraph.
    +  + + + + + + + + + + + +
    +Method Summary
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +AsUnweightedDirectedGraph

    +
    +public AsUnweightedDirectedGraph(DirectedGraph<V,E> g)
    +
    +
    Constructor for AsUnweightedGraph. +

    +

    +
    Parameters:
    g - the backing graph over which an unweighted view is to be + created.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    Overrides:
    getEdgeWeight in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    Graph.getEdgeWeight(E)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUnweightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUnweightedGraph.html new file mode 100644 index 00000000..e5317eb9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsUnweightedGraph.html @@ -0,0 +1,319 @@ + + + + + + +AsUnweightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class AsUnweightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.AsUnweightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>
    +
    +
    +
    +
    public class AsUnweightedGraph<V,E>
    extends GraphDelegator<V,E>
    implements java.io.Serializable
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    Sep 7, 2007
    +
    Author:
    +
    Lucas J. Scharenbroich
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    AsUnweightedGraph(Graph<V,E> g) + +
    +          Constructor for AsUnweightedGraph.
    +  + + + + + + + + + + + +
    +Method Summary
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    containsEdge, removeAllEdges, removeAllEdges, removeAllVertices
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +AsUnweightedGraph

    +
    +public AsUnweightedGraph(Graph<V,E> g)
    +
    +
    Constructor for AsUnweightedGraph. +

    +

    +
    Parameters:
    g - the backing graph over which an unweighted view is to be + created.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    Overrides:
    getEdgeWeight in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    Graph.getEdgeWeight(E)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsWeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsWeightedGraph.html new file mode 100644 index 00000000..154e2f7c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/AsWeightedGraph.html @@ -0,0 +1,402 @@ + + + + + + +AsWeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class AsWeightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.AsWeightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class AsWeightedGraph<V,E>
    extends GraphDelegator<V,E>
    implements java.io.Serializable, WeightedGraph<V,E>
    + + +

    +

    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.

    +

    + +

    +

    +
    Since:
    +
    Sep 10, 2007
    +
    Author:
    +
    Lucas J. Scharenbroich
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Field Summary
    +protected  java.util.Map<E,java.lang.Double>weightMap + +
    +           
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + +
    +Constructor Summary
    AsWeightedGraph(Graph<V,E> g, + java.util.Map<E,java.lang.Double> weightMap) + +
    +          Constructor for AsWeightedGraph.
    +  + + + + + + + + + + + + + + + +
    +Method Summary
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + voidsetEdgeWeight(E e, + double weight) + +
    +          Assigns a weight to an edge.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +weightMap

    +
    +protected final java.util.Map<E,java.lang.Double> weightMap
    +
    +
    +
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +AsWeightedGraph

    +
    +public AsWeightedGraph(Graph<V,E> g,
    +                       java.util.Map<E,java.lang.Double> weightMap)
    +
    +
    Constructor for AsWeightedGraph. +

    +

    +
    Parameters:
    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.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +setEdgeWeight

    +
    +public void setEdgeWeight(E e,
    +                          double weight)
    +
    +
    Description copied from interface: WeightedGraph
    +
    Assigns a weight to an edge. +

    +

    +
    Specified by:
    setEdgeWeight in interface WeightedGraph<V,E>
    Overrides:
    setEdgeWeight in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge on which to set weight
    weight - new weight for edge
    See Also:
    WeightedGraph.setEdgeWeight(E, double)
    +
    +
    +
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    Overrides:
    getEdgeWeight in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    Graph.getEdgeWeight(E)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ClassBasedEdgeFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ClassBasedEdgeFactory.html new file mode 100644 index 00000000..f5873512 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ClassBasedEdgeFactory.html @@ -0,0 +1,275 @@ + + + + + + +ClassBasedEdgeFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ClassBasedEdgeFactory<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.ClassBasedEdgeFactory<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, EdgeFactory<V,E>
    +
    +
    +
    +
    public class ClassBasedEdgeFactory<V,E>
    extends java.lang.Object
    implements EdgeFactory<V,E>, java.io.Serializable
    + + +

    +An EdgeFactory for producing edges by using a class as a factory. +

    + +

    +

    +
    Since:
    +
    Jul 14, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    ClassBasedEdgeFactory(java.lang.Class<? extends E> edgeClass) + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    + EcreateEdge(V source, + V target) + +
    +          Creates a new edge whose endpoints are the specified source and target + vertices.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ClassBasedEdgeFactory

    +
    +public ClassBasedEdgeFactory(java.lang.Class<? extends E> edgeClass)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +createEdge

    +
    +public E createEdge(V source,
    +                    V target)
    +
    +
    Description copied from interface: EdgeFactory
    +
    Creates a new edge whose endpoints are the specified source and target + vertices. +

    +

    +
    Specified by:
    createEdge in interface EdgeFactory<V,E>
    +
    +
    +
    Parameters:
    source - the source vertex.
    target - the target vertex. +
    Returns:
    a new edge whose endpoints are the specified source and target + vertices.
    See Also:
    EdgeFactory.createEdge(Object, Object)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ClassBasedVertexFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ClassBasedVertexFactory.html new file mode 100644 index 00000000..1eaff05b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ClassBasedVertexFactory.html @@ -0,0 +1,270 @@ + + + + + + +ClassBasedVertexFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ClassBasedVertexFactory<V>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.ClassBasedVertexFactory<V>
    +
    +
    +
    All Implemented Interfaces:
    VertexFactory<V>
    +
    +
    +
    +
    public class ClassBasedVertexFactory<V>
    extends java.lang.Object
    implements VertexFactory<V>
    + + +

    +A VertexFactory for producing vertices by using a class as a factory. +

    + +

    +

    +
    Since:
    +
    July 5, 2007
    +
    Author:
    +
    Guillaume Boulmier
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    ClassBasedVertexFactory(java.lang.Class<? extends V> vertexClass) + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    + VcreateVertex() + +
    +          Creates a new vertex.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ClassBasedVertexFactory

    +
    +public ClassBasedVertexFactory(java.lang.Class<? extends V> vertexClass)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +createVertex

    +
    +public V createVertex()
    +
    +
    Description copied from interface: VertexFactory
    +
    Creates a new vertex. +

    +

    +
    Specified by:
    createVertex in interface VertexFactory<V>
    +
    +
    + +
    Returns:
    the new vertex
    See Also:
    VertexFactory.createVertex()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultDirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultDirectedGraph.html new file mode 100644 index 00000000..dc6fdcd9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultDirectedGraph.html @@ -0,0 +1,299 @@ + + + + + + +DefaultDirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DefaultDirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.DefaultDirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DefaultDirectedWeightedGraph
    +
    +
    +
    +
    public class DefaultDirectedGraph<V,E>
    extends AbstractBaseGraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +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.

    +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    DefaultDirectedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new directed graph.
    DefaultDirectedGraph(EdgeFactory<V,E> ef) + +
    +          Creates a new directed graph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DefaultDirectedGraph

    +
    +public DefaultDirectedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new directed graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +DefaultDirectedGraph

    +
    +public DefaultDirectedGraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new directed graph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultDirectedWeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultDirectedWeightedGraph.html new file mode 100644 index 00000000..792ba4de --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultDirectedWeightedGraph.html @@ -0,0 +1,322 @@ + + + + + + +DefaultDirectedWeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DefaultDirectedWeightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.DefaultDirectedGraph<V,E>
    +              extended by org.jgrapht.graph.DefaultDirectedWeightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class DefaultDirectedWeightedGraph<V,E>
    extends DefaultDirectedGraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    DefaultDirectedGraph, +Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    DefaultDirectedWeightedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new directed weighted graph.
    DefaultDirectedWeightedGraph(EdgeFactory<V,E> ef) + +
    +          Creates a new directed weighted graph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DefaultDirectedWeightedGraph

    +
    +public DefaultDirectedWeightedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new directed weighted graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +DefaultDirectedWeightedGraph

    +
    +public DefaultDirectedWeightedGraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new directed weighted graph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultEdge.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultEdge.html new file mode 100644 index 00000000..f58861dc --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultEdge.html @@ -0,0 +1,337 @@ + + + + + + +DefaultEdge (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DefaultEdge

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.DefaultEdge
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    +
    +
    +
    Direct Known Subclasses:
    DefaultWeightedEdge
    +
    +
    +
    +
    public class DefaultEdge
    extends java.lang.Object
    + + +

    +A default implementation for edges in a Graph. +

    + +

    +

    +
    Since:
    +
    Jul 14, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    DefaultEdge() + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + java.lang.Objectclone() + +
    +           
    +protected  java.lang.ObjectgetSource() + +
    +          Retrieves the source of this edge.
    +protected  java.lang.ObjectgetTarget() + +
    +          Retrieves the target of this edge.
    + java.lang.StringtoString() + +
    +           
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DefaultEdge

    +
    +public DefaultEdge()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getSource

    +
    +protected java.lang.Object getSource()
    +
    +
    Retrieves the source of this edge. This is protected, for use by + subclasses only (e.g. for implementing toString). +

    +

    + +
    Returns:
    source of this edge
    +
    +
    +
    + +

    +getTarget

    +
    +protected java.lang.Object getTarget()
    +
    +
    Retrieves the target of this edge. This is protected, for use by + subclasses only (e.g. for implementing toString). +

    +

    + +
    Returns:
    target of this edge
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    +
    Overrides:
    toString in class java.lang.Object
    +
    +
    +
    +
    +
    +
    + +

    +clone

    +
    +public java.lang.Object clone()
    +
    +
    +
    Overrides:
    clone in class java.lang.Object
    +
    +
    +
    See Also:
    Object.clone()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultGraphMapping.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultGraphMapping.html new file mode 100644 index 00000000..39e59275 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultGraphMapping.html @@ -0,0 +1,317 @@ + + + + + + +DefaultGraphMapping (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DefaultGraphMapping<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.DefaultGraphMapping<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphMapping<V,E>
    +
    +
    +
    +
    public class DefaultGraphMapping<V,E>
    extends java.lang.Object
    implements GraphMapping<V,E>
    + + +

    +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. +

    + +

    +

    +
    Since:
    +
    Jul 30, 2005
    +
    Author:
    +
    Assaf
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    DefaultGraphMapping(java.util.Map<V,V> g1ToG2, + java.util.Map<V,V> g2ToG1, + Graph<V,E> g1, + Graph<V,E> g2) + +
    +          The maps themselves are used.
    +  + + + + + + + + + + + + + + + +
    +Method Summary
    + EgetEdgeCorrespondence(E currEdge, + boolean forward) + +
    +          Gets the mapped value where the key is edge
    + VgetVertexCorrespondence(V keyVertex, + boolean forward) + +
    +          Gets the mapped value where the key is vertex
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DefaultGraphMapping

    +
    +public DefaultGraphMapping(java.util.Map<V,V> g1ToG2,
    +                           java.util.Map<V,V> g2ToG1,
    +                           Graph<V,E> g1,
    +                           Graph<V,E> g2)
    +
    +
    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. +

    +

    +
    Parameters:
    g1ToG2 -
    g2ToG1 -
    g1 -
    g2 -
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getEdgeCorrespondence

    +
    +public E getEdgeCorrespondence(E currEdge,
    +                               boolean forward)
    +
    +
    Description copied from interface: GraphMapping
    +
    Gets the mapped value where the key is edge +

    +

    +
    Specified by:
    getEdgeCorrespondence in interface GraphMapping<V,E>
    +
    +
    +
    Parameters:
    currEdge - edge in one of the graphs
    forward - if true, uses mapping from graph1 to graph2; if false, use + mapping from graph2 to graph1 +
    Returns:
    corresponding edge in other graph, or null if none
    +
    +
    +
    + +

    +getVertexCorrespondence

    +
    +public V getVertexCorrespondence(V keyVertex,
    +                                 boolean forward)
    +
    +
    Description copied from interface: GraphMapping
    +
    Gets the mapped value where the key is vertex +

    +

    +
    Specified by:
    getVertexCorrespondence in interface GraphMapping<V,E>
    +
    +
    +
    Parameters:
    keyVertex - vertex in one of the graphs
    forward - if true, uses mapping from graph1 to graph2; if false, use + mapping from graph2 to graph1 +
    Returns:
    corresponding vertex in other graph, or null if none
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultListenableGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultListenableGraph.html new file mode 100644 index 00000000..fa7b014e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultListenableGraph.html @@ -0,0 +1,824 @@ + + + + + + +DefaultListenableGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DefaultListenableGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.DefaultListenableGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, ListenableGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    ListenableDirectedGraph, ListenableUndirectedGraph
    +
    +
    +
    +
    public class DefaultListenableGraph<V,E>
    extends GraphDelegator<V,E>
    implements ListenableGraph<V,E>, java.lang.Cloneable
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    Jul 20, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    GraphListener, +VertexSetListener, +Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    DefaultListenableGraph(Graph<V,E> g) + +
    +          Creates a new listenable graph.
    DefaultListenableGraph(Graph<V,E> g, + boolean reuseEvents) + +
    +          Creates a new listenable graph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + voidaddGraphListener(GraphListener<V,E> l) + +
    +          Adds the specified graph listener to this graph, if not already present.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this graph if not already present.
    + voidaddVertexSetListener(VertexSetListener<V> l) + +
    +          Adds the specified vertex set listener to this graph, if not already + present.
    + java.lang.Objectclone() + +
    +           
    +protected  voidfireEdgeAdded(E edge) + +
    +          Notify listeners that the specified edge was added.
    +protected  voidfireEdgeRemoved(E edge) + +
    +          Notify listeners that the specified edge was removed.
    +protected  voidfireVertexAdded(V vertex) + +
    +          Notify listeners that the specified vertex was added.
    +protected  voidfireVertexRemoved(V vertex) + +
    +          Notify listeners that the specified vertex was removed.
    + booleanisReuseEvents() + +
    +          Tests whether the reuseEvents flag is set.
    + booleanremoveEdge(E e) + +
    +          Removes the specified edge from the graph.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
    + voidremoveGraphListener(GraphListener<V,E> l) + +
    +          Removes the specified graph listener from this graph, if present.
    + booleanremoveVertex(V v) + +
    +          Removes the specified vertex from this graph including all its touching + edges if present.
    + voidremoveVertexSetListener(VertexSetListener<V> l) + +
    +          Removes the specified vertex set listener from this graph, if present.
    + voidsetReuseEvents(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
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DefaultListenableGraph

    +
    +public DefaultListenableGraph(Graph<V,E> g)
    +
    +
    Creates a new listenable graph. +

    +

    +
    Parameters:
    g - the backing graph.
    +
    +
    + +

    +DefaultListenableGraph

    +
    +public DefaultListenableGraph(Graph<V,E> g,
    +                              boolean reuseEvents)
    +
    +
    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 E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +addGraphListener

    +
    +public void addGraphListener(GraphListener<V,E> l)
    +
    +
    Description copied from interface: ListenableGraph
    +
    Adds the specified graph listener to this graph, if not already present. +

    +

    +
    Specified by:
    addGraphListener in interface ListenableGraph<V,E>
    +
    +
    +
    Parameters:
    l - the listener to be added.
    See Also:
    ListenableGraph.addGraphListener(GraphListener)
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    Overrides:
    addVertex in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be added to this graph. +
    Returns:
    true if this graph did not already contain the specified + vertex.
    See Also:
    Graph.addVertex(Object)
    +
    +
    +
    + +

    +addVertexSetListener

    +
    +public void addVertexSetListener(VertexSetListener<V> l)
    +
    +
    Description copied from interface: ListenableGraph
    +
    Adds the specified vertex set listener to this graph, if not already + present. +

    +

    +
    Specified by:
    addVertexSetListener in interface ListenableGraph<V,E>
    +
    +
    +
    Parameters:
    l - the listener to be added.
    See Also:
    ListenableGraph.addVertexSetListener(VertexSetListener)
    +
    +
    +
    + +

    +clone

    +
    +public java.lang.Object clone()
    +
    +
    +
    Overrides:
    clone in class java.lang.Object
    +
    +
    +
    See Also:
    Object.clone()
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    Overrides:
    removeEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    Overrides:
    removeEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge to be removed from this graph, if present. +
    Returns:
    true if and only if the graph contained the + specified edge.
    See Also:
    Graph.removeEdge(Object)
    +
    +
    +
    + +

    +removeGraphListener

    +
    +public void removeGraphListener(GraphListener<V,E> l)
    +
    +
    Description copied from interface: ListenableGraph
    +
    Removes the specified graph listener from this graph, if present. +

    +

    +
    Specified by:
    removeGraphListener in interface ListenableGraph<V,E>
    +
    +
    +
    Parameters:
    l - the listener to be removed.
    See Also:
    ListenableGraph.removeGraphListener(GraphListener)
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeVertex in interface Graph<V,E>
    Overrides:
    removeVertex in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be removed from this graph, if present. +
    Returns:
    true if the graph contained the specified vertex; + false otherwise.
    See Also:
    Graph.removeVertex(Object)
    +
    +
    +
    + +

    +removeVertexSetListener

    +
    +public void removeVertexSetListener(VertexSetListener<V> l)
    +
    +
    Description copied from interface: ListenableGraph
    +
    Removes the specified vertex set listener from this graph, if present. +

    +

    +
    Specified by:
    removeVertexSetListener in interface ListenableGraph<V,E>
    +
    +
    +
    Parameters:
    l - the listener to be removed.
    See Also:
    ListenableGraph.removeVertexSetListener(VertexSetListener)
    +
    +
    +
    + +

    +fireEdgeAdded

    +
    +protected void fireEdgeAdded(E edge)
    +
    +
    Notify listeners that the specified edge was added. +

    +

    +
    +
    +
    +
    Parameters:
    edge - the edge that was added.
    +
    +
    +
    + +

    +fireEdgeRemoved

    +
    +protected void fireEdgeRemoved(E edge)
    +
    +
    Notify listeners that the specified edge was removed. +

    +

    +
    +
    +
    +
    Parameters:
    edge - the edge that was removed.
    +
    +
    +
    + +

    +fireVertexAdded

    +
    +protected void fireVertexAdded(V vertex)
    +
    +
    Notify listeners that the specified vertex was added. +

    +

    +
    +
    +
    +
    Parameters:
    vertex - the vertex that was added.
    +
    +
    +
    + +

    +fireVertexRemoved

    +
    +protected void fireVertexRemoved(V vertex)
    +
    +
    Notify listeners that the specified vertex was removed. +

    +

    +
    +
    +
    +
    Parameters:
    vertex - the vertex that was removed.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultWeightedEdge.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultWeightedEdge.html new file mode 100644 index 00000000..dc0e9843 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DefaultWeightedEdge.html @@ -0,0 +1,299 @@ + + + + + + +DefaultWeightedEdge (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DefaultWeightedEdge

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.DefaultEdge
    +      extended by org.jgrapht.graph.DefaultWeightedEdge
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    +
    +
    +
    +
    public class DefaultWeightedEdge
    extends DefaultEdge
    + + +

    +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. +

    + +

    +

    +
    Author:
    +
    John V. Sichi
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    DefaultWeightedEdge() + +
    +           
    +  + + + + + + + + + + + + + + + +
    +Method Summary
    + java.lang.Objectclone() + +
    +           
    +protected  doublegetWeight() + +
    +          Retrieves the weight of this edge.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.DefaultEdge
    getSource, getTarget, toString
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DefaultWeightedEdge

    +
    +public DefaultWeightedEdge()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getWeight

    +
    +protected double getWeight()
    +
    +
    Retrieves the weight of this edge. This is protected, for use by + subclasses only (e.g. for implementing toString). +

    +

    + +
    Returns:
    weight of this edge
    +
    +
    +
    + +

    +clone

    +
    +public java.lang.Object clone()
    +
    +
    +
    Overrides:
    clone in class java.lang.Object
    +
    +
    +
    See Also:
    Object.clone()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedGraphUnion.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedGraphUnion.html new file mode 100644 index 00000000..4384fa7b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedGraphUnion.html @@ -0,0 +1,344 @@ + + + + + + +DirectedGraphUnion (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedGraphUnion<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphUnion<V,E,DirectedGraph<V,E>>
    +          extended by org.jgrapht.graph.DirectedGraphUnion<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    +
    public class DirectedGraphUnion<V,E>
    extends GraphUnion<V,E,DirectedGraph<V,E>>
    implements DirectedGraph<V,E>
    + + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +          Returns a set of all edges incoming into the specified vertex.
    + intinDegreeOf(V vertex) + +
    +          Returns the "in degree" of the specified vertex.
    + intoutDegreeOf(V vertex) + +
    +          Returns the "out degree" of the specified vertex.
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +          Returns a set of all edges outgoing from the specified vertex.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphUnion
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, getG1, getG2, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    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. +

    +

    +
    Specified by:
    inDegreeOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    Returns a set of all edges incoming into the specified vertex. +

    +

    +
    Specified by:
    incomingEdgesOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which the list of incoming edges to be + returned. +
    Returns:
    a set of all edges incoming into the specified vertex.
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    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. +

    +

    +
    Specified by:
    outDegreeOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    Returns a set of all edges outgoing from the specified vertex. +

    +

    +
    Specified by:
    outgoingEdgesOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which the list of outgoing edges to be + returned. +
    Returns:
    a set of all edges outgoing from the specified vertex.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedMaskSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedMaskSubgraph.html new file mode 100644 index 00000000..b7d3b721 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedMaskSubgraph.html @@ -0,0 +1,275 @@ + + + + + + +DirectedMaskSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedMaskSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.MaskSubgraph<V,E>
    +          extended by org.jgrapht.graph.DirectedMaskSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    +
    public class DirectedMaskSubgraph<V,E>
    extends MaskSubgraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +A directed graph that is a MaskSubgraph on another graph. +

    + +

    +

    +
    Since:
    +
    July 5, 2007
    +
    Author:
    +
    Guillaume Boulmier
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    DirectedMaskSubgraph(DirectedGraph<V,E> base, + MaskFunctor<V,E> mask) + +
    +           
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.MaskSubgraph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DirectedMaskSubgraph

    +
    +public DirectedMaskSubgraph(DirectedGraph<V,E> base,
    +                            MaskFunctor<V,E> mask)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedMultigraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedMultigraph.html new file mode 100644 index 00000000..436778c8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedMultigraph.html @@ -0,0 +1,295 @@ + + + + + + +DirectedMultigraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedMultigraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.DirectedMultigraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DirectedWeightedMultigraph
    +
    +
    +
    +
    public class DirectedMultigraph<V,E>
    extends AbstractBaseGraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +A directed multigraph. A directed multigraph is a non-simple directed graph + in which loops and multiple edges between any two vertices are permitted. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    DirectedMultigraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new directed multigraph.
    DirectedMultigraph(EdgeFactory<V,E> ef) + +
    +          Creates a new directed multigraph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DirectedMultigraph

    +
    +public DirectedMultigraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new directed multigraph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +DirectedMultigraph

    +
    +public DirectedMultigraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new directed multigraph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedPseudograph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedPseudograph.html new file mode 100644 index 00000000..7968561d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedPseudograph.html @@ -0,0 +1,291 @@ + + + + + + +DirectedPseudograph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedPseudograph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.DirectedPseudograph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    +
    public class DirectedPseudograph<V,E>
    extends AbstractBaseGraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    DirectedPseudograph(java.lang.Class<? extends E> edgeClass) + +
    +           
    DirectedPseudograph(EdgeFactory<V,E> ef) + +
    +           
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DirectedPseudograph

    +
    +public DirectedPseudograph(java.lang.Class<? extends E> edgeClass)
    +
    +
    +
    See Also:
    AbstractBaseGraph
    +
    +
    + +

    +DirectedPseudograph

    +
    +public DirectedPseudograph(EdgeFactory<V,E> ef)
    +
    +
    +
    See Also:
    AbstractBaseGraph
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedSubgraph.html new file mode 100644 index 00000000..1ad25d98 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedSubgraph.html @@ -0,0 +1,396 @@ + + + + + + +DirectedSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.Subgraph<V,E,DirectedGraph<V,E>>
    +          extended by org.jgrapht.graph.DirectedSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DirectedWeightedSubgraph
    +
    +
    +
    +
    public class DirectedSubgraph<V,E>
    extends Subgraph<V,E,DirectedGraph<V,E>>
    implements DirectedGraph<V,E>
    + + +

    +A directed graph that is a subgraph on other graph. +

    + +

    +

    +
    See Also:
    Subgraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    DirectedSubgraph(DirectedGraph<V,E> base, + java.util.Set<V> vertexSubset, + java.util.Set<E> edgeSubset) + +
    +          Creates a new directed subgraph.
    +  + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +          Returns a set of all edges incoming into the specified vertex.
    + intinDegreeOf(V vertex) + +
    +          Returns the "in degree" of the specified vertex.
    + intoutDegreeOf(V vertex) + +
    +          Returns the "out degree" of the specified vertex.
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +          Returns a set of all edges outgoing from the specified vertex.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.Subgraph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getBase, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DirectedSubgraph

    +
    +public DirectedSubgraph(DirectedGraph<V,E> base,
    +                        java.util.Set<V> vertexSubset,
    +                        java.util.Set<E> edgeSubset)
    +
    +
    Creates a new directed subgraph. +

    +

    +
    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.
    edgeSubset - edges to in include in the subgraph. If + null then all the edges whose vertices found in the graph are + included.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    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. +

    +

    +
    Specified by:
    inDegreeOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    See Also:
    DirectedGraph.inDegreeOf(Object)
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    Returns a set of all edges incoming into the specified vertex. +

    +

    +
    Specified by:
    incomingEdgesOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which the list of incoming edges to be + returned. +
    Returns:
    a set of all edges incoming into the specified vertex.
    See Also:
    DirectedGraph.incomingEdgesOf(Object)
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    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. +

    +

    +
    Specified by:
    outDegreeOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    See Also:
    DirectedGraph.outDegreeOf(Object)
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    Returns a set of all edges outgoing from the specified vertex. +

    +

    +
    Specified by:
    outgoingEdgesOf in interface DirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which the list of outgoing edges to be + returned. +
    Returns:
    a set of all edges outgoing from the specified vertex.
    See Also:
    DirectedGraph.outgoingEdgesOf(Object)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedWeightedMultigraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedWeightedMultigraph.html new file mode 100644 index 00000000..6771ab2b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedWeightedMultigraph.html @@ -0,0 +1,323 @@ + + + + + + +DirectedWeightedMultigraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedWeightedMultigraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.DirectedMultigraph<V,E>
    +              extended by org.jgrapht.graph.DirectedWeightedMultigraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class DirectedWeightedMultigraph<V,E>
    extends DirectedMultigraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    DirectedWeightedMultigraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new directed weighted multigraph.
    DirectedWeightedMultigraph(EdgeFactory<V,E> ef) + +
    +          Creates a new directed weighted multigraph with the specified edge + factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DirectedWeightedMultigraph

    +
    +public DirectedWeightedMultigraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new directed weighted multigraph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +DirectedWeightedMultigraph

    +
    +public DirectedWeightedMultigraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new directed weighted multigraph with the specified edge + factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedWeightedSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedWeightedSubgraph.html new file mode 100644 index 00000000..16613eae --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/DirectedWeightedSubgraph.html @@ -0,0 +1,309 @@ + + + + + + +DirectedWeightedSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class DirectedWeightedSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.Subgraph<V,E,DirectedGraph<V,E>>
    +          extended by org.jgrapht.graph.DirectedSubgraph<V,E>
    +              extended by org.jgrapht.graph.DirectedWeightedSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, DirectedGraph<V,E>, Graph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class DirectedWeightedSubgraph<V,E>
    extends DirectedSubgraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +A directed weighted graph that is a subgraph on other graph. +

    + +

    +

    +
    See Also:
    Subgraph, +Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + +
    +Constructor Summary
    DirectedWeightedSubgraph(WeightedGraph<V,E> base, + java.util.Set<V> vertexSubset, + java.util.Set<E> edgeSubset) + +
    +          Creates a new weighted directed subgraph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.DirectedSubgraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.Subgraph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getBase, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +DirectedWeightedSubgraph

    +
    +public DirectedWeightedSubgraph(WeightedGraph<V,E> base,
    +                                java.util.Set<V> vertexSubset,
    +                                java.util.Set<E> edgeSubset)
    +
    +
    Creates a new weighted directed subgraph. +

    +

    +
    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.
    edgeSubset - edges to in include in the subgraph. If + null then all the edges whose vertices found in the graph are + included.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/EdgeReversedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/EdgeReversedGraph.html new file mode 100644 index 00000000..690f4449 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/EdgeReversedGraph.html @@ -0,0 +1,677 @@ + + + + + + +EdgeReversedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class EdgeReversedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.EdgeReversedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    +
    public class EdgeReversedGraph<V,E>
    extends GraphDelegator<V,E>
    implements DirectedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    Author:
    +
    John V. Sichi
    +
    See Also:
    AsUndirectedGraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    EdgeReversedGraph(DirectedGraph<V,E> g) + +
    +          Creates a new EdgeReversedGraph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + 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.
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + VgetEdgeSource(E e) + +
    +          Returns the source vertex of an edge.
    + VgetEdgeTarget(E e) + +
    +          Returns the target vertex of an edge.
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +          Returns a set of all edges incoming into the specified vertex.
    + intinDegreeOf(V vertex) + +
    +          Returns the "in degree" of the specified vertex.
    + intoutDegreeOf(V vertex) + +
    +          Returns the "out degree" of the specified vertex.
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +          Returns a set of all edges outgoing from the specified vertex.
    + EremoveEdge(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.StringtoString() + +
    +          Returns a string of the parenthesized pair (V, E) representing this + G=(V,E) graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getEdgeFactory, getEdgeWeight, removeEdge, removeVertex, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getEdgeFactory, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +EdgeReversedGraph

    +
    +public EdgeReversedGraph(DirectedGraph<V,E> g)
    +
    +
    Creates a new EdgeReversedGraph. +

    +

    +
    Parameters:
    g - the base (backing) graph on which the edge-reversed view will be + based.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getEdge

    +
    +public E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    getEdge in interface Graph<V,E>
    Overrides:
    getEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    an edge connecting source vertex to target vertex.
    See Also:
    Graph.getEdge(Object, Object)
    +
    +
    +
    + +

    +getAllEdges

    +
    +public java.util.Set<E> getAllEdges(V sourceVertex,
    +                                    V targetVertex)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    Specified by:
    getAllEdges in interface Graph<V,E>
    Overrides:
    getAllEdges in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.getAllEdges(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    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. +

    +

    +
    Specified by:
    inDegreeOf in interface DirectedGraph<V,E>
    Overrides:
    inDegreeOf in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    See Also:
    DirectedGraph.inDegreeOf(Object)
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    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. +

    +

    +
    Specified by:
    outDegreeOf in interface DirectedGraph<V,E>
    Overrides:
    outDegreeOf in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    See Also:
    DirectedGraph.outDegreeOf(Object)
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    Returns a set of all edges incoming into the specified vertex. +

    +

    +
    Specified by:
    incomingEdgesOf in interface DirectedGraph<V,E>
    Overrides:
    incomingEdgesOf in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which the list of incoming edges to be + returned. +
    Returns:
    a set of all edges incoming into the specified vertex.
    See Also:
    DirectedGraph.incomingEdgesOf(Object)
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    Description copied from interface: DirectedGraph
    +
    Returns a set of all edges outgoing from the specified vertex. +

    +

    +
    Specified by:
    outgoingEdgesOf in interface DirectedGraph<V,E>
    Overrides:
    outgoingEdgesOf in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which the list of outgoing edges to be + returned. +
    Returns:
    a set of all edges outgoing from the specified vertex.
    See Also:
    DirectedGraph.outgoingEdgesOf(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    Overrides:
    removeEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +getEdgeSource

    +
    +public V getEdgeSource(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeSource in interface Graph<V,E>
    Overrides:
    getEdgeSource in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    source vertex
    See Also:
    Graph.getEdgeSource(Object)
    +
    +
    +
    + +

    +getEdgeTarget

    +
    +public V getEdgeTarget(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeTarget in interface Graph<V,E>
    Overrides:
    getEdgeTarget in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    target vertex
    See Also:
    Graph.getEdgeTarget(Object)
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    Description copied from class: AbstractGraph
    +
    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. +

    +

    +
    Overrides:
    toString in class GraphDelegator<V,E>
    +
    +
    + +
    Returns:
    a string representation of this graph.
    See Also:
    Object.toString()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/EdgeSetFactory.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/EdgeSetFactory.html new file mode 100644 index 00000000..ca6dccc1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/EdgeSetFactory.html @@ -0,0 +1,222 @@ + + + + + + +EdgeSetFactory (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Interface EdgeSetFactory<V,E>

    +
    +
    +
    public interface EdgeSetFactory<V,E>
    + + +

    +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. +

    + +

    +

    +
    Author:
    +
    John V. Sichi
    +
    +
    + +

    + + + + + + + + + + + + +
    +Method Summary
    + java.util.Set<E>createEdgeSet(V vertex) + +
    +          Create a new edge set for a particular vertex.
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +createEdgeSet

    +
    +java.util.Set<E> createEdgeSet(V vertex)
    +
    +
    Create a new edge set for a particular vertex. +

    +

    +
    Parameters:
    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) +
    Returns:
    new set
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphDelegator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphDelegator.html new file mode 100644 index 00000000..73f7f861 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphDelegator.html @@ -0,0 +1,1008 @@ + + + + + + +GraphDelegator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class GraphDelegator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    AsUndirectedGraph, AsUnweightedDirectedGraph, AsUnweightedGraph, AsWeightedGraph, DefaultListenableGraph, EdgeReversedGraph, ParanoidGraph, UnmodifiableGraph
    +
    +
    +
    +
    public class GraphDelegator<V,E>
    extends AbstractGraph<V,E>
    implements Graph<V,E>, java.io.Serializable
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    Jul 20, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    GraphDelegator(Graph<V,E> g) + +
    +          Constructor for GraphDelegator.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this graph if not already present.
    + booleancontainsEdge(E e) + +
    +          Returns true if this graph contains the specified edge.
    + booleancontainsVertex(V v) + +
    +          Returns true if this graph contains the specified vertex.
    + intdegreeOf(V vertex) + +
    +           
    + java.util.Set<E>edgeSet() + +
    +          Returns a set of the edges contained in this graph.
    + java.util.Set<E>edgesOf(V vertex) + +
    +          Returns a set of all edges touching the specified vertex.
    + 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.
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + EdgeFactory<V,E>getEdgeFactory() + +
    +          Returns the edge factory using which this graph creates new edges.
    + VgetEdgeSource(E e) + +
    +          Returns the source vertex of an edge.
    + VgetEdgeTarget(E e) + +
    +          Returns the target vertex of an edge.
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +           
    + intinDegreeOf(V vertex) + +
    +           
    + intoutDegreeOf(V vertex) + +
    +           
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +           
    + booleanremoveEdge(E e) + +
    +          Removes the specified edge from the graph.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
    + booleanremoveVertex(V v) + +
    +          Removes the specified vertex from this graph including all its touching + edges if present.
    + voidsetEdgeWeight(E e, + double weight) + +
    +           
    + java.lang.StringtoString() + +
    +          Returns a string of the parenthesized pair (V, E) representing this + G=(V,E) graph.
    + java.util.Set<V>vertexSet() + +
    +          Returns a set of the vertices contained in this graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    containsEdge, removeAllEdges, removeAllEdges, removeAllVertices
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +GraphDelegator

    +
    +public GraphDelegator(Graph<V,E> g)
    +
    +
    Constructor for GraphDelegator. +

    +

    +
    Parameters:
    g - the backing graph (the delegate). +
    Throws: +
    java.lang.IllegalArgumentException - iff g==null
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getAllEdges

    +
    +public java.util.Set<E> getAllEdges(V sourceVertex,
    +                                    V targetVertex)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    Specified by:
    getAllEdges in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.getAllEdges(Object, Object)
    +
    +
    +
    + +

    +getEdge

    +
    +public E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    getEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    an edge connecting source vertex to target vertex.
    See Also:
    Graph.getEdge(Object, Object)
    +
    +
    +
    + +

    +getEdgeFactory

    +
    +public EdgeFactory<V,E> getEdgeFactory()
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeFactory in interface Graph<V,E>
    +
    +
    + +
    Returns:
    the edge factory using which this graph creates new edges.
    See Also:
    Graph.getEdgeFactory()
    +
    +
    +
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be added to this graph. +
    Returns:
    true if this graph did not already contain the specified + vertex.
    See Also:
    Graph.addVertex(Object)
    +
    +
    +
    + +

    +containsEdge

    +
    +public boolean containsEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified edge.
    See Also:
    Graph.containsEdge(Object)
    +
    +
    +
    + +

    +containsVertex

    +
    +public boolean containsVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified vertex.
    See Also:
    Graph.containsVertex(Object)
    +
    +
    +
    + +

    +degreeOf

    +
    +public int degreeOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    UndirectedGraph.degreeOf(Object)
    +
    +
    +
    + +

    +edgeSet

    +
    +public java.util.Set<E> edgeSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    edgeSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set of the edges contained in this graph.
    See Also:
    Graph.edgeSet()
    +
    +
    +
    + +

    +edgesOf

    +
    +public java.util.Set<E> edgesOf(V vertex)
    +
    +
    Description copied from interface: Graph
    +
    Returns a set of all edges touching the specified vertex. If no edges are + touching the specified vertex returns an empty set. +

    +

    +
    Specified by:
    edgesOf in interface Graph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which a set of touching edges is to be + returned. +
    Returns:
    a set of all edges touching the specified vertex.
    See Also:
    Graph.edgesOf(Object)
    +
    +
    +
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.inDegreeOf(Object)
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.incomingEdgesOf(Object)
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.outDegreeOf(Object)
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    +
    +
    +
    +
    See Also:
    DirectedGraph.outgoingEdgesOf(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge to be removed from this graph, if present. +
    Returns:
    true if and only if the graph contained the + specified edge.
    See Also:
    Graph.removeEdge(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be removed from this graph, if present. +
    Returns:
    true if the graph contained the specified vertex; + false otherwise.
    See Also:
    Graph.removeVertex(Object)
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    Description copied from class: AbstractGraph
    +
    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. +

    +

    +
    Overrides:
    toString in class AbstractGraph<V,E>
    +
    +
    + +
    Returns:
    a string representation of this graph.
    See Also:
    Object.toString()
    +
    +
    +
    + +

    +vertexSet

    +
    +public java.util.Set<V> vertexSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    vertexSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set view of the vertices contained in this graph.
    See Also:
    Graph.vertexSet()
    +
    +
    +
    + +

    +getEdgeSource

    +
    +public V getEdgeSource(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeSource in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    source vertex
    See Also:
    Graph.getEdgeSource(Object)
    +
    +
    +
    + +

    +getEdgeTarget

    +
    +public V getEdgeTarget(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeTarget in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    target vertex
    See Also:
    Graph.getEdgeTarget(Object)
    +
    +
    +
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    Graph.getEdgeWeight(Object)
    +
    +
    +
    + +

    +setEdgeWeight

    +
    +public void setEdgeWeight(E e,
    +                          double weight)
    +
    +
    +
    +
    +
    +
    See Also:
    WeightedGraph.setEdgeWeight(Object, double)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphPathImpl.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphPathImpl.html new file mode 100644 index 00000000..d493d2df --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphPathImpl.html @@ -0,0 +1,414 @@ + + + + + + +GraphPathImpl (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class GraphPathImpl<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.GraphPathImpl<V,E>
    +
    +
    +
    All Implemented Interfaces:
    GraphPath<V,E>
    +
    +
    +
    +
    public class GraphPathImpl<V,E>
    extends java.lang.Object
    implements GraphPath<V,E>
    + + +

    +GraphPathImpl is a default implementation of GraphPath. +

    + +

    +

    +
    Version:
    +
    $Id: GraphPathImpl.java 689 2009-07-04 06:40:29Z perfecthash $
    +
    Author:
    +
    John Sichi
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    GraphPathImpl(Graph<V,E> graph, + V startVertex, + V endVertex, + java.util.List<E> edgeList, + double weight) + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + java.util.List<E>getEdgeList() + +
    +          Returns the edges making up the path.
    + VgetEndVertex() + +
    +          Returns the end vertex in the path.
    + Graph<V,E>getGraph() + +
    +          Returns the graph over which this path is defined.
    + VgetStartVertex() + +
    +          Returns the start vertex in the path.
    + doublegetWeight() + +
    +          Returns the weight assigned to the path.
    + java.lang.StringtoString() + +
    +           
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +GraphPathImpl

    +
    +public GraphPathImpl(Graph<V,E> graph,
    +                     V startVertex,
    +                     V endVertex,
    +                     java.util.List<E> edgeList,
    +                     double weight)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getGraph

    +
    +public Graph<V,E> getGraph()
    +
    +
    Description copied from interface: GraphPath
    +
    Returns the graph over which this path is defined. The path may also be + valid with respect to other graphs. +

    +

    +
    Specified by:
    getGraph in interface GraphPath<V,E>
    +
    +
    + +
    Returns:
    the containing graph
    +
    +
    +
    + +

    +getStartVertex

    +
    +public V getStartVertex()
    +
    +
    Description copied from interface: GraphPath
    +
    Returns the start vertex in the path. +

    +

    +
    Specified by:
    getStartVertex in interface GraphPath<V,E>
    +
    +
    + +
    Returns:
    the start vertex
    +
    +
    +
    + +

    +getEndVertex

    +
    +public V getEndVertex()
    +
    +
    Description copied from interface: GraphPath
    +
    Returns the end vertex in the path. +

    +

    +
    Specified by:
    getEndVertex in interface GraphPath<V,E>
    +
    +
    + +
    Returns:
    the end vertex
    +
    +
    +
    + +

    +getEdgeList

    +
    +public java.util.List<E> getEdgeList()
    +
    +
    Description copied from interface: GraphPath
    +
    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. +

    +

    +
    Specified by:
    getEdgeList in interface GraphPath<V,E>
    +
    +
    + +
    Returns:
    list of edges traversed by the path
    +
    +
    +
    + +

    +getWeight

    +
    +public double getWeight()
    +
    +
    Description copied from interface: GraphPath
    +
    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. +

    +

    +
    Specified by:
    getWeight in interface GraphPath<V,E>
    +
    +
    + +
    Returns:
    the weight of the path
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    +
    Overrides:
    toString in class java.lang.Object
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphUnion.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphUnion.html new file mode 100644 index 00000000..3f774eb6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/GraphUnion.html @@ -0,0 +1,839 @@ + + + + + + +GraphUnion (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class GraphUnion<V,E,G extends Graph<V,E>>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphUnion<V,E,G>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DirectedGraphUnion, UndirectedGraphUnion
    +
    +
    +
    +
    public class GraphUnion<V,E,G extends Graph<V,E>>
    extends AbstractGraph<V,E>
    implements java.io.Serializable
    + + +

    +

    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.

    +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    GraphUnion(G g1, + G g2) + +
    +           
    GraphUnion(G g1, + G g2, + WeightCombiner operator) + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + EaddEdge(V sourceVertex, + V targetVertex) + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + booleanaddVertex(V v) + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + booleancontainsEdge(E e) + +
    +          Returns true if this graph contains the specified edge.
    + booleancontainsVertex(V v) + +
    +          Returns true if this graph contains the specified vertex.
    + java.util.Set<E>edgeSet() + +
    +          Returns a set of the edges contained in this graph.
    + java.util.Set<E>edgesOf(V vertex) + +
    +          Returns a set of all edges touching the specified vertex.
    + 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.
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + EdgeFactory<V,E>getEdgeFactory() + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + VgetEdgeSource(E e) + +
    +          Returns the source vertex of an edge.
    + VgetEdgeTarget(E e) + +
    +          Returns the target vertex of an edge.
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + GgetG1() + +
    +           
    + GgetG2() + +
    +           
    + booleanremoveEdge(E e) + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + booleanremoveVertex(V v) + +
    +          Throws UnsupportedOperationException, because + GraphUnion is read-only.
    + java.util.Set<V>vertexSet() + +
    +          Returns a set of the vertices contained in this graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +GraphUnion

    +
    +public GraphUnion(G g1,
    +                  G g2,
    +                  WeightCombiner operator)
    +
    +
    +
    + +

    +GraphUnion

    +
    +public GraphUnion(G g1,
    +                  G g2)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getAllEdges

    +
    +public java.util.Set<E> getAllEdges(V sourceVertex,
    +                                    V targetVertex)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    Specified by:
    getAllEdges in interface Graph<V,E>
    +
    +
    +
    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 E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    getEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    an edge connecting source vertex to target vertex.
    +
    +
    +
    + +

    +getEdgeFactory

    +
    +public EdgeFactory<V,E> getEdgeFactory()
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    getEdgeFactory in interface Graph<V,E>
    +
    +
    + +
    Returns:
    the edge factory using which this graph creates new edges.
    +
    +
    +
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.getEdgeFactory()
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object), +Graph.getEdgeFactory()
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be added to this graph. +
    Returns:
    true if this graph did not already contain the specified + vertex.
    +
    +
    +
    + +

    +containsEdge

    +
    +public boolean containsEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified edge.
    +
    +
    +
    + +

    +containsVertex

    +
    +public boolean containsVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified vertex.
    +
    +
    +
    + +

    +edgeSet

    +
    +public java.util.Set<E> edgeSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    edgeSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set of the edges contained in this graph.
    +
    +
    +
    + +

    +edgesOf

    +
    +public java.util.Set<E> edgesOf(V vertex)
    +
    +
    Description copied from interface: Graph
    +
    Returns a set of all edges touching the specified vertex. If no edges are + touching the specified vertex returns an empty set. +

    +

    +
    Specified by:
    edgesOf in interface Graph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which a set of touching edges is to be + returned. +
    Returns:
    a set of all edges touching the specified vertex.
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge to be removed from this graph, if present. +
    Returns:
    true if and only if the graph contained the + specified edge.
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Throws UnsupportedOperationException, because + GraphUnion is read-only. +

    +

    +
    Specified by:
    removeVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be removed from this graph, if present. +
    Returns:
    true if the graph contained the specified vertex; + false otherwise.
    +
    +
    +
    + +

    +vertexSet

    +
    +public java.util.Set<V> vertexSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    vertexSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set view of the vertices contained in this graph.
    +
    +
    +
    + +

    +getEdgeSource

    +
    +public V getEdgeSource(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeSource in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    source vertex
    +
    +
    +
    + +

    +getEdgeTarget

    +
    +public V getEdgeTarget(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeTarget in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    target vertex
    +
    +
    +
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    WeightedGraph
    +
    +
    +
    + +

    +getG1

    +
    +public G getG1()
    +
    +
    +
    +
    +
    + +
    Returns:
    G1
    +
    +
    +
    + +

    +getG2

    +
    +public G getG2()
    +
    +
    +
    +
    +
    + +
    Returns:
    G2
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableDirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableDirectedGraph.html new file mode 100644 index 00000000..24d4fc5e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableDirectedGraph.html @@ -0,0 +1,305 @@ + + + + + + +ListenableDirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ListenableDirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.DefaultListenableGraph<V,E>
    +              extended by org.jgrapht.graph.ListenableDirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>, ListenableGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    ListenableDirectedWeightedGraph
    +
    +
    +
    +
    public class ListenableDirectedGraph<V,E>
    extends DefaultListenableGraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +A directed graph which is also ListenableGraph. +

    + +

    +

    +
    See Also:
    DefaultListenableGraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    ListenableDirectedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new listenable directed graph.
    ListenableDirectedGraph(DirectedGraph<V,E> base) + +
    +          Creates a new listenable directed graph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.DefaultListenableGraph
    addEdge, addEdge, addGraphListener, addVertex, addVertexSetListener, clone, fireEdgeAdded, fireEdgeRemoved, fireVertexAdded, fireVertexRemoved, isReuseEvents, removeEdge, removeEdge, removeGraphListener, removeVertex, removeVertexSetListener, setReuseEvents
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ListenableDirectedGraph

    +
    +public ListenableDirectedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new listenable directed graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +ListenableDirectedGraph

    +
    +public ListenableDirectedGraph(DirectedGraph<V,E> base)
    +
    +
    Creates a new listenable directed graph. +

    +

    +
    Parameters:
    base - the backing graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableDirectedWeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableDirectedWeightedGraph.html new file mode 100644 index 00000000..489a8452 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableDirectedWeightedGraph.html @@ -0,0 +1,330 @@ + + + + + + +ListenableDirectedWeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ListenableDirectedWeightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.DefaultListenableGraph<V,E>
    +              extended by org.jgrapht.graph.ListenableDirectedGraph<V,E>
    +                  extended by org.jgrapht.graph.ListenableDirectedWeightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>, ListenableGraph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class ListenableDirectedWeightedGraph<V,E>
    extends ListenableDirectedGraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +A directed weighted graph which is also ListenableGraph. +

    + +

    +

    +
    See Also:
    DefaultListenableGraph, +Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    ListenableDirectedWeightedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new listenable directed weighted graph.
    ListenableDirectedWeightedGraph(WeightedGraph<V,E> base) + +
    +          Creates a new listenable directed weighted graph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.DefaultListenableGraph
    addEdge, addEdge, addGraphListener, addVertex, addVertexSetListener, clone, fireEdgeAdded, fireEdgeRemoved, fireVertexAdded, fireVertexRemoved, isReuseEvents, removeEdge, removeEdge, removeGraphListener, removeVertex, removeVertexSetListener, setReuseEvents
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ListenableDirectedWeightedGraph

    +
    +public ListenableDirectedWeightedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new listenable directed weighted graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +ListenableDirectedWeightedGraph

    +
    +public ListenableDirectedWeightedGraph(WeightedGraph<V,E> base)
    +
    +
    Creates a new listenable directed weighted graph. +

    +

    +
    Parameters:
    base - the backing graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableUndirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableUndirectedGraph.html new file mode 100644 index 00000000..9973efc3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableUndirectedGraph.html @@ -0,0 +1,305 @@ + + + + + + +ListenableUndirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ListenableUndirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.DefaultListenableGraph<V,E>
    +              extended by org.jgrapht.graph.ListenableUndirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, ListenableGraph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    ListenableUndirectedWeightedGraph
    +
    +
    +
    +
    public class ListenableUndirectedGraph<V,E>
    extends DefaultListenableGraph<V,E>
    implements UndirectedGraph<V,E>
    + + +

    +An undirected graph which is also ListenableGraph. +

    + +

    +

    +
    See Also:
    DefaultListenableGraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    ListenableUndirectedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new listenable undirected simple graph.
    ListenableUndirectedGraph(UndirectedGraph<V,E> base) + +
    +          Creates a new listenable undirected graph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.DefaultListenableGraph
    addEdge, addEdge, addGraphListener, addVertex, addVertexSetListener, clone, fireEdgeAdded, fireEdgeRemoved, fireVertexAdded, fireVertexRemoved, isReuseEvents, removeEdge, removeEdge, removeGraphListener, removeVertex, removeVertexSetListener, setReuseEvents
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ListenableUndirectedGraph

    +
    +public ListenableUndirectedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new listenable undirected simple graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +ListenableUndirectedGraph

    +
    +public ListenableUndirectedGraph(UndirectedGraph<V,E> base)
    +
    +
    Creates a new listenable undirected graph. +

    +

    +
    Parameters:
    base - the backing graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableUndirectedWeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableUndirectedWeightedGraph.html new file mode 100644 index 00000000..b9300ad7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ListenableUndirectedWeightedGraph.html @@ -0,0 +1,330 @@ + + + + + + +ListenableUndirectedWeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ListenableUndirectedWeightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.DefaultListenableGraph<V,E>
    +              extended by org.jgrapht.graph.ListenableUndirectedGraph<V,E>
    +                  extended by org.jgrapht.graph.ListenableUndirectedWeightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, ListenableGraph<V,E>, UndirectedGraph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class ListenableUndirectedWeightedGraph<V,E>
    extends ListenableUndirectedGraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +An undirected weighted graph which is also ListenableGraph. +

    + +

    +

    +
    See Also:
    DefaultListenableGraph, +Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    ListenableUndirectedWeightedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new listenable undirected weighted graph.
    ListenableUndirectedWeightedGraph(WeightedGraph<V,E> base) + +
    +          Creates a new listenable undirected weighted graph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.DefaultListenableGraph
    addEdge, addEdge, addGraphListener, addVertex, addVertexSetListener, clone, fireEdgeAdded, fireEdgeRemoved, fireVertexAdded, fireVertexRemoved, isReuseEvents, removeEdge, removeEdge, removeGraphListener, removeVertex, removeVertexSetListener, setReuseEvents
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ListenableUndirectedWeightedGraph

    +
    +public ListenableUndirectedWeightedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new listenable undirected weighted graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +ListenableUndirectedWeightedGraph

    +
    +public ListenableUndirectedWeightedGraph(WeightedGraph<V,E> base)
    +
    +
    Creates a new listenable undirected weighted graph. +

    +

    +
    Parameters:
    base - the backing graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/MaskFunctor.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/MaskFunctor.html new file mode 100644 index 00000000..decd44e1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/MaskFunctor.html @@ -0,0 +1,243 @@ + + + + + + +MaskFunctor (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Interface MaskFunctor<V,E>

    +
    +
    +
    public interface MaskFunctor<V,E>
    + + +

    +A functor interface for masking out vertices and edges of a graph. +

    + +

    +

    +
    Since:
    +
    July 5, 2007
    +
    Author:
    +
    Guillaume Boulmier
    +
    +
    + +

    + + + + + + + + + + + + + + + + +
    +Method Summary
    + booleanisEdgeMasked(E edge) + +
    +          Returns true if the edge is masked, false + otherwise.
    + booleanisVertexMasked(V vertex) + +
    +          Returns true if the vertex is masked, false + otherwise.
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +isEdgeMasked

    +
    +boolean isEdgeMasked(E edge)
    +
    +
    Returns true if the edge is masked, false + otherwise. +

    +

    +
    Parameters:
    edge - edge. +
    Returns:
    .
    +
    +
    +
    + +

    +isVertexMasked

    +
    +boolean isVertexMasked(V vertex)
    +
    +
    Returns true if the vertex is masked, false + otherwise. +

    +

    +
    Parameters:
    vertex - vertex. +
    Returns:
    .
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/MaskSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/MaskSubgraph.html new file mode 100644 index 00000000..d562fd3b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/MaskSubgraph.html @@ -0,0 +1,973 @@ + + + + + + +MaskSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class MaskSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.MaskSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DirectedMaskSubgraph, UndirectedMaskSubgraph
    +
    +
    +
    +
    public class MaskSubgraph<V,E>
    extends AbstractGraph<V,E>
    + + +

    +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). +

    + +

    +

    +
    Since:
    +
    July 5, 2007
    +
    Author:
    +
    Guillaume Boulmier
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    MaskSubgraph(Graph<V,E> base, + MaskFunctor<V,E> mask) + +
    +          Creates a new induced subgraph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E edge) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this graph if not already present.
    + booleancontainsEdge(E e) + +
    +          Returns true if this graph contains the specified edge.
    + booleancontainsVertex(V v) + +
    +          Returns true if this graph contains the specified vertex.
    + intdegreeOf(V vertex) + +
    +           
    + java.util.Set<E>edgeSet() + +
    +          Returns a set of the edges contained in this graph.
    + java.util.Set<E>edgesOf(V vertex) + +
    +          Returns a set of all edges touching the specified vertex.
    + 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.
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + EdgeFactory<V,E>getEdgeFactory() + +
    +          Returns the edge factory using which this graph creates new edges.
    + VgetEdgeSource(E edge) + +
    +          Returns the source vertex of an edge.
    + VgetEdgeTarget(E edge) + +
    +          Returns the target vertex of an edge.
    + doublegetEdgeWeight(E edge) + +
    +          Returns the weight assigned to a given edge.
    + java.util.Set<E>incomingEdgesOf(V vertex) + +
    +           
    + intinDegreeOf(V vertex) + +
    +           
    + intoutDegreeOf(V vertex) + +
    +           
    + java.util.Set<E>outgoingEdgesOf(V vertex) + +
    +           
    + booleanremoveAllEdges(java.util.Collection<? extends E> edges) + +
    +          Removes all the edges in this graph that are also contained in the + specified edge collection.
    + 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.
    + booleanremoveAllVertices(java.util.Collection<? extends V> vertices) + +
    +          Removes all the vertices in this graph that are also contained in the + specified vertex collection.
    + booleanremoveEdge(E e) + +
    +          Removes the specified edge from the graph.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
    + booleanremoveVertex(V v) + +
    +          Removes the specified vertex from this graph including all its touching + edges if present.
    + java.util.Set<V>vertexSet() + +
    +          Returns a set of the vertices contained in this graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +MaskSubgraph

    +
    +public MaskSubgraph(Graph<V,E> base,
    +                    MaskFunctor<V,E> mask)
    +
    +
    Creates a new induced subgraph. Running-time = O(1). +

    +

    +
    Parameters:
    base - the base (backing) graph on which the subgraph will be based.
    mask - vertices and edges to exclude in the subgraph. If a + vertex/edge is masked, it is as if it is not in the subgraph.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E edge)
    +
    +
    Description copied from interface: Graph
    +
    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.
    See Also:
    Graph.addEdge(Object, Object), +Graph.getEdgeFactory()
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.
    See Also:
    Graph.addVertex(Object)
    +
    +
    +
    + +

    +containsEdge

    +
    +public boolean containsEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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 edge.
    +
    +
    +
    + +

    +containsVertex

    +
    +public boolean containsVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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:
    true if this graph contains the specified vertex.
    +
    +
    +
    + +

    +degreeOf

    +
    +public int degreeOf(V vertex)
    +
    +
    +
    See Also:
    UndirectedGraph.degreeOf(Object)
    +
    +
    +
    + +

    +edgeSet

    +
    +public java.util.Set<E> edgeSet()
    +
    +
    Description copied from interface: Graph
    +
    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 edges contained in this graph.
    +
    +
    +
    + +

    +edgesOf

    +
    +public java.util.Set<E> edgesOf(V vertex)
    +
    +
    Description copied from interface: Graph
    +
    Returns a set of all edges touching the specified vertex. If no edges are + touching the specified vertex returns an empty set. +

    +

    +
    Parameters:
    vertex - the vertex for which a set of touching edges is to be + returned. +
    Returns:
    a set of all edges touching the specified vertex.
    +
    +
    +
    + +

    +getAllEdges

    +
    +public java.util.Set<E> getAllEdges(V sourceVertex,
    +                                    V targetVertex)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    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 E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.
    +
    +
    +
    + +

    +getEdgeFactory

    +
    +public EdgeFactory<V,E> getEdgeFactory()
    +
    +
    Description copied from interface: Graph
    +
    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.
    +
    +
    +
    + +

    +getEdgeSource

    +
    +public V getEdgeSource(E edge)
    +
    +
    Description copied from interface: Graph
    +
    Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Parameters:
    edge - edge of interest +
    Returns:
    source vertex
    +
    +
    +
    + +

    +getEdgeTarget

    +
    +public V getEdgeTarget(E edge)
    +
    +
    Description copied from interface: Graph
    +
    Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Parameters:
    edge - edge of interest +
    Returns:
    target vertex
    +
    +
    +
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E edge)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Parameters:
    edge - edge of interest +
    Returns:
    edge weight
    See Also:
    WeightedGraph
    +
    +
    +
    + +

    +incomingEdgesOf

    +
    +public java.util.Set<E> incomingEdgesOf(V vertex)
    +
    +
    +
    See Also:
    DirectedGraph.incomingEdgesOf(Object)
    +
    +
    +
    + +

    +inDegreeOf

    +
    +public int inDegreeOf(V vertex)
    +
    +
    +
    See Also:
    DirectedGraph.inDegreeOf(Object)
    +
    +
    +
    + +

    +outDegreeOf

    +
    +public int outDegreeOf(V vertex)
    +
    +
    +
    See Also:
    DirectedGraph.outDegreeOf(Object)
    +
    +
    +
    + +

    +outgoingEdgesOf

    +
    +public java.util.Set<E> outgoingEdgesOf(V vertex)
    +
    +
    +
    See Also:
    DirectedGraph.outgoingEdgesOf(Object)
    +
    +
    +
    + +

    +removeAllEdges

    +
    +public boolean removeAllEdges(java.util.Collection<? extends E> edges)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeAllEdges in interface Graph<V,E>
    Overrides:
    removeAllEdges in class AbstractGraph<V,E>
    +
    +
    +
    Parameters:
    edges - edges to be removed from this graph. +
    Returns:
    true if this graph changed as a result of the call
    See Also:
    Graph.removeAllEdges(Collection)
    +
    +
    +
    + +

    +removeAllEdges

    +
    +public java.util.Set<E> removeAllEdges(V sourceVertex,
    +                                       V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeAllEdges in interface Graph<V,E>
    Overrides:
    removeAllEdges in class AbstractGraph<V,E>
    +
    +
    +
    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
    See Also:
    Graph.removeAllEdges(Object, Object)
    +
    +
    +
    + +

    +removeAllVertices

    +
    +public boolean removeAllVertices(java.util.Collection<? extends V> vertices)
    +
    +
    Description copied from interface: 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 Graph.removeVertex(Object) method. +

    +

    +
    Specified by:
    removeAllVertices in interface Graph<V,E>
    Overrides:
    removeAllVertices in class AbstractGraph<V,E>
    +
    +
    +
    Parameters:
    vertices - vertices to be removed from this graph. +
    Returns:
    true if this graph changed as a result of the call
    See Also:
    Graph.removeAllVertices(Collection)
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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.
    See Also:
    Graph.removeEdge(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.
    See Also:
    Graph.removeVertex(Object)
    +
    +
    +
    + +

    +vertexSet

    +
    +public java.util.Set<V> vertexSet()
    +
    +
    Description copied from interface: Graph
    +
    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.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Multigraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Multigraph.html new file mode 100644 index 00000000..bb176cfe --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Multigraph.html @@ -0,0 +1,298 @@ + + + + + + +Multigraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class Multigraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.Multigraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    WeightedMultigraph
    +
    +
    +
    +
    public class Multigraph<V,E>
    extends AbstractBaseGraph<V,E>
    implements UndirectedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    Multigraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new multigraph.
    Multigraph(EdgeFactory<V,E> ef) + +
    +          Creates a new multigraph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +Multigraph

    +
    +public Multigraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new multigraph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +Multigraph

    +
    +public Multigraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new multigraph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ParanoidGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ParanoidGraph.html new file mode 100644 index 00000000..564a20c4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/ParanoidGraph.html @@ -0,0 +1,354 @@ + + + + + + +ParanoidGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class ParanoidGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.ParanoidGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>
    +
    +
    +
    +
    public class ParanoidGraph<V,E>
    extends GraphDelegator<V,E>
    + + +

    +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. +

    + +

    +

    +
    Version:
    +
    $Id: ParanoidGraph.java 645 2008-09-30 19:44:48Z perfecthash $
    +
    Author:
    +
    John Sichi
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    ParanoidGraph(Graph<V,E> g) + +
    +           
    +  + + + + + + + + + + + + + + + +
    +Method Summary
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this graph if not already present.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    addEdge, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    containsEdge, removeAllEdges, removeAllEdges, removeAllVertices
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ParanoidGraph

    +
    +public ParanoidGraph(Graph<V,E> g)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    Overrides:
    addVertex in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be added to this graph. +
    Returns:
    true if this graph did not already contain the specified + vertex.
    See Also:
    Graph.addVertex(Object)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Pseudograph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Pseudograph.html new file mode 100644 index 00000000..d57807f5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Pseudograph.html @@ -0,0 +1,297 @@ + + + + + + +Pseudograph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class Pseudograph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.Pseudograph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    WeightedPseudograph
    +
    +
    +
    +
    public class Pseudograph<V,E>
    extends AbstractBaseGraph<V,E>
    implements UndirectedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    Pseudograph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new pseudograph.
    Pseudograph(EdgeFactory<V,E> ef) + +
    +          Creates a new pseudograph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +Pseudograph

    +
    +public Pseudograph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new pseudograph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +Pseudograph

    +
    +public Pseudograph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new pseudograph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleDirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleDirectedGraph.html new file mode 100644 index 00000000..a1f2f7ac --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleDirectedGraph.html @@ -0,0 +1,295 @@ + + + + + + +SimpleDirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class SimpleDirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.SimpleDirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    SimpleDirectedWeightedGraph
    +
    +
    +
    +
    public class SimpleDirectedGraph<V,E>
    extends AbstractBaseGraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    SimpleDirectedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new simple directed graph.
    SimpleDirectedGraph(EdgeFactory<V,E> ef) + +
    +          Creates a new simple directed graph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +SimpleDirectedGraph

    +
    +public SimpleDirectedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new simple directed graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    +
    + +

    +SimpleDirectedGraph

    +
    +public SimpleDirectedGraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new simple directed graph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleDirectedWeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleDirectedWeightedGraph.html new file mode 100644 index 00000000..11c1890f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleDirectedWeightedGraph.html @@ -0,0 +1,322 @@ + + + + + + +SimpleDirectedWeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class SimpleDirectedWeightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.SimpleDirectedGraph<V,E>
    +              extended by org.jgrapht.graph.SimpleDirectedWeightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, DirectedGraph<V,E>, Graph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class SimpleDirectedWeightedGraph<V,E>
    extends SimpleDirectedGraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +A simple directed weighted graph. A simple directed weighted graph is a + simple directed graph for which edges are assigned weights. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    SimpleDirectedWeightedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new simple directed weighted graph.
    SimpleDirectedWeightedGraph(EdgeFactory<V,E> ef) + +
    +          Creates a new simple directed weighted graph with the specified edge + factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +SimpleDirectedWeightedGraph

    +
    +public SimpleDirectedWeightedGraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new simple directed weighted graph with the specified edge + factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    +
    + +

    +SimpleDirectedWeightedGraph

    +
    +public SimpleDirectedWeightedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new simple directed weighted graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleGraph.html new file mode 100644 index 00000000..53b0264c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleGraph.html @@ -0,0 +1,298 @@ + + + + + + +SimpleGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class SimpleGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.SimpleGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    BlockCutpointGraph, SimpleWeightedGraph
    +
    +
    +
    +
    public class SimpleGraph<V,E>
    extends AbstractBaseGraph<V,E>
    implements UndirectedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    SimpleGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new simple graph.
    SimpleGraph(EdgeFactory<V,E> ef) + +
    +          Creates a new simple graph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +SimpleGraph

    +
    +public SimpleGraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new simple graph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    +
    + +

    +SimpleGraph

    +
    +public SimpleGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new simple graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleWeightedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleWeightedGraph.html new file mode 100644 index 00000000..9db52d98 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/SimpleWeightedGraph.html @@ -0,0 +1,320 @@ + + + + + + +SimpleWeightedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class SimpleWeightedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.SimpleGraph<V,E>
    +              extended by org.jgrapht.graph.SimpleWeightedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, UndirectedGraph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class SimpleWeightedGraph<V,E>
    extends SimpleGraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +A simple weighted graph. A simple weighted graph is a simple graph for which + edges are assigned weights. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    SimpleWeightedGraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new simple weighted graph.
    SimpleWeightedGraph(EdgeFactory<V,E> ef) + +
    +          Creates a new simple weighted graph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +SimpleWeightedGraph

    +
    +public SimpleWeightedGraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new simple weighted graph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    +
    + +

    +SimpleWeightedGraph

    +
    +public SimpleWeightedGraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new simple weighted graph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Subgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Subgraph.html new file mode 100644 index 00000000..b27aef17 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/Subgraph.html @@ -0,0 +1,940 @@ + + + + + + +Subgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class Subgraph<V,E,G extends Graph<V,E>>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.Subgraph<V,E,G>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    DirectedSubgraph, UndirectedSubgraph
    +
    +
    +
    +
    public class Subgraph<V,E,G extends Graph<V,E>>
    extends AbstractGraph<V,E>
    implements java.io.Serializable
    + + +

    +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).

    +

    + +

    +

    +
    Since:
    +
    Jul 18, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Graph, +Set, +Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    Subgraph(G base, + java.util.Set<V> vertexSubset) + +
    +          Creates a new induced Subgraph.
    Subgraph(G base, + java.util.Set<V> vertexSubset, + java.util.Set<E> edgeSubset) + +
    +          Creates a new Subgraph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this subgraph.
    + booleancontainsEdge(E e) + +
    +          Returns true if this graph contains the specified edge.
    + booleancontainsVertex(V v) + +
    +          Returns true if this graph contains the specified vertex.
    + java.util.Set<E>edgeSet() + +
    +          Returns a set of the edges contained in this graph.
    + java.util.Set<E>edgesOf(V vertex) + +
    +          Returns a set of all edges touching the specified vertex.
    + 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.
    + GgetBase() + +
    +           
    + EgetEdge(V sourceVertex, + V targetVertex) + +
    +          Returns an edge connecting source vertex to target vertex if such + vertices and such edge exist in this graph.
    + EdgeFactory<V,E>getEdgeFactory() + +
    +          Returns the edge factory using which this graph creates new edges.
    + VgetEdgeSource(E e) + +
    +          Returns the source vertex of an edge.
    + VgetEdgeTarget(E e) + +
    +          Returns the target vertex of an edge.
    + doublegetEdgeWeight(E e) + +
    +          Returns the weight assigned to a given edge.
    + booleanremoveEdge(E e) + +
    +          Removes the specified edge from the graph.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
    + booleanremoveVertex(V v) + +
    +          Removes the specified vertex from this graph including all its touching + edges if present.
    + voidsetEdgeWeight(E e, + double weight) + +
    +           
    + java.util.Set<V>vertexSet() + +
    +          Returns a set of the vertices contained in this graph.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +Subgraph

    +
    +public Subgraph(G base,
    +                java.util.Set<V> vertexSubset,
    +                java.util.Set<E> edgeSubset)
    +
    +
    Creates a new Subgraph. +

    +

    +
    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.
    edgeSubset - edges to in include in the subgraph. If + null then all the edges whose vertices found in the graph are + included.
    +
    +
    + +

    +Subgraph

    +
    +public Subgraph(G base,
    +                java.util.Set<V> vertexSubset)
    +
    +
    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)
    +
    +
    Description copied from interface: 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.

    +

    +

    +
    Specified by:
    getAllEdges in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.getAllEdges(Object, Object)
    +
    +
    +
    + +

    +getEdge

    +
    +public E getEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    getEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    an edge connecting source vertex to target vertex.
    See Also:
    Graph.getEdge(Object, Object)
    +
    +
    +
    + +

    +getEdgeFactory

    +
    +public EdgeFactory<V,E> getEdgeFactory()
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeFactory in interface Graph<V,E>
    +
    +
    + +
    Returns:
    the edge factory using which this graph creates new edges.
    See Also:
    Graph.getEdgeFactory()
    +
    +
    +
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Adds the specified vertex to this subgraph. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - the vertex to be added. +
    Returns:
    true if the vertex was added, otherwise + false. +
    Throws: +
    java.lang.NullPointerException +
    java.lang.IllegalArgumentException
    See Also:
    Subgraph, +Graph.addVertex(Object)
    +
    +
    +
    + +

    +containsEdge

    +
    +public boolean containsEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified edge.
    See Also:
    Graph.containsEdge(Object)
    +
    +
    +
    + +

    +containsVertex

    +
    +public boolean containsVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    containsVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex whose presence in this graph is to be tested. +
    Returns:
    true if this graph contains the specified vertex.
    See Also:
    Graph.containsVertex(Object)
    +
    +
    +
    + +

    +edgeSet

    +
    +public java.util.Set<E> edgeSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    edgeSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set of the edges contained in this graph.
    See Also:
    Graph.edgeSet()
    +
    +
    +
    + +

    +edgesOf

    +
    +public java.util.Set<E> edgesOf(V vertex)
    +
    +
    Description copied from interface: Graph
    +
    Returns a set of all edges touching the specified vertex. If no edges are + touching the specified vertex returns an empty set. +

    +

    +
    Specified by:
    edgesOf in interface Graph<V,E>
    +
    +
    +
    Parameters:
    vertex - the vertex for which a set of touching edges is to be + returned. +
    Returns:
    a set of all edges touching the specified vertex.
    See Also:
    Graph.edgesOf(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge to be removed from this graph, if present. +
    Returns:
    true if and only if the graph contained the + specified edge.
    See Also:
    Graph.removeEdge(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeVertex in interface Graph<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be removed from this graph, if present. +
    Returns:
    true if the graph contained the specified vertex; + false otherwise.
    See Also:
    Graph.removeVertex(Object)
    +
    +
    +
    + +

    +vertexSet

    +
    +public java.util.Set<V> vertexSet()
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    vertexSet in interface Graph<V,E>
    +
    +
    + +
    Returns:
    a set view of the vertices contained in this graph.
    See Also:
    Graph.vertexSet()
    +
    +
    +
    + +

    +getEdgeSource

    +
    +public V getEdgeSource(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the source vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeSource in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    source vertex
    See Also:
    Graph.getEdgeSource(Object)
    +
    +
    +
    + +

    +getEdgeTarget

    +
    +public V getEdgeTarget(E e)
    +
    +
    Description copied from interface: Graph
    +
    Returns the target vertex of an edge. For an undirected graph, source and + target are distinguishable designations (but without any mathematical + meaning). +

    +

    +
    Specified by:
    getEdgeTarget in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    target vertex
    See Also:
    Graph.getEdgeTarget(Object)
    +
    +
    +
    + +

    +getBase

    +
    +public G getBase()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    +getEdgeWeight

    +
    +public double getEdgeWeight(E e)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    getEdgeWeight in interface Graph<V,E>
    +
    +
    +
    Parameters:
    e - edge of interest +
    Returns:
    edge weight
    See Also:
    Graph.getEdgeWeight(Object)
    +
    +
    +
    + +

    +setEdgeWeight

    +
    +public void setEdgeWeight(E e,
    +                          double weight)
    +
    +
    +
    +
    +
    +
    See Also:
    WeightedGraph.setEdgeWeight(Object, double)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedGraphUnion.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedGraphUnion.html new file mode 100644 index 00000000..4dadbcca --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedGraphUnion.html @@ -0,0 +1,259 @@ + + + + + + +UndirectedGraphUnion (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UndirectedGraphUnion<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphUnion<V,E,UndirectedGraph<V,E>>
    +          extended by org.jgrapht.graph.UndirectedGraphUnion<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    +
    public class UndirectedGraphUnion<V,E>
    extends GraphUnion<V,E,UndirectedGraph<V,E>>
    implements UndirectedGraph<V,E>
    + + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + +
    +Method Summary
    + intdegreeOf(V vertex) + +
    +          Returns the degree of the specified vertex.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphUnion
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, getG1, getG2, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +degreeOf

    +
    +public int degreeOf(V vertex)
    +
    +
    Description copied from interface: UndirectedGraph
    +
    Returns the degree of the specified vertex. A degree of a vertex in an + undirected graph is the number of edges touching that vertex. +

    +

    +
    Specified by:
    degreeOf in interface UndirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedMaskSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedMaskSubgraph.html new file mode 100644 index 00000000..b6d0f0e3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedMaskSubgraph.html @@ -0,0 +1,275 @@ + + + + + + +UndirectedMaskSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UndirectedMaskSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.MaskSubgraph<V,E>
    +          extended by org.jgrapht.graph.UndirectedMaskSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    +
    public class UndirectedMaskSubgraph<V,E>
    extends MaskSubgraph<V,E>
    implements UndirectedGraph<V,E>
    + + +

    +An undirected graph that is a MaskSubgraph on another graph. +

    + +

    +

    +
    Since:
    +
    July 5, 2007
    +
    Author:
    +
    Guillaume Boulmier
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    UndirectedMaskSubgraph(UndirectedGraph<V,E> base, + MaskFunctor<V,E> mask) + +
    +           
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.MaskSubgraph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +UndirectedMaskSubgraph

    +
    +public UndirectedMaskSubgraph(UndirectedGraph<V,E> base,
    +                              MaskFunctor<V,E> mask)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedSubgraph.html new file mode 100644 index 00000000..4036a002 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedSubgraph.html @@ -0,0 +1,311 @@ + + + + + + +UndirectedSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UndirectedSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.Subgraph<V,E,UndirectedGraph<V,E>>
    +          extended by org.jgrapht.graph.UndirectedSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    UndirectedWeightedSubgraph
    +
    +
    +
    +
    public class UndirectedSubgraph<V,E>
    extends Subgraph<V,E,UndirectedGraph<V,E>>
    implements UndirectedGraph<V,E>
    + + +

    +An undirected graph that is a subgraph on other graph. +

    + +

    +

    +
    See Also:
    Subgraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    UndirectedSubgraph(UndirectedGraph<V,E> base, + java.util.Set<V> vertexSubset, + java.util.Set<E> edgeSubset) + +
    +          Creates a new undirected subgraph.
    +  + + + + + + + + + + + +
    +Method Summary
    + intdegreeOf(V vertex) + +
    +          Returns the degree of the specified vertex.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.Subgraph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getBase, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +UndirectedSubgraph

    +
    +public UndirectedSubgraph(UndirectedGraph<V,E> base,
    +                          java.util.Set<V> vertexSubset,
    +                          java.util.Set<E> edgeSubset)
    +
    +
    Creates a new undirected subgraph. +

    +

    +
    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.
    edgeSubset - edges to in include in the subgraph. If + null then all the edges whose vertices found in the graph are + included.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +degreeOf

    +
    +public int degreeOf(V vertex)
    +
    +
    Description copied from interface: UndirectedGraph
    +
    Returns the degree of the specified vertex. A degree of a vertex in an + undirected graph is the number of edges touching that vertex. +

    +

    +
    Specified by:
    degreeOf in interface UndirectedGraph<V,E>
    +
    +
    +
    Parameters:
    vertex - vertex whose degree is to be calculated. +
    Returns:
    the degree of the specified vertex.
    See Also:
    UndirectedGraph.degreeOf(Object)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedWeightedSubgraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedWeightedSubgraph.html new file mode 100644 index 00000000..f4a89fae --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UndirectedWeightedSubgraph.html @@ -0,0 +1,309 @@ + + + + + + +UndirectedWeightedSubgraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UndirectedWeightedSubgraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.Subgraph<V,E,UndirectedGraph<V,E>>
    +          extended by org.jgrapht.graph.UndirectedSubgraph<V,E>
    +              extended by org.jgrapht.graph.UndirectedWeightedSubgraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>, UndirectedGraph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class UndirectedWeightedSubgraph<V,E>
    extends UndirectedSubgraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +An undirected weighted graph that is a subgraph on other graph. +

    + +

    +

    +
    See Also:
    Subgraph, +Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + +
    +Constructor Summary
    UndirectedWeightedSubgraph(WeightedGraph<V,E> base, + java.util.Set<V> vertexSubset, + java.util.Set<E> edgeSubset) + +
    +          Creates a new undirected weighted subgraph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.UndirectedSubgraph
    degreeOf
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.Subgraph
    addEdge, addEdge, addVertex, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getBase, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +UndirectedWeightedSubgraph

    +
    +public UndirectedWeightedSubgraph(WeightedGraph<V,E> base,
    +                                  java.util.Set<V> vertexSubset,
    +                                  java.util.Set<E> edgeSubset)
    +
    +
    Creates a new undirected weighted subgraph. +

    +

    +
    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.
    edgeSubset - edges to in include in the subgraph. If + null then all the edges whose vertices found in the graph are + included.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableDirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableDirectedGraph.html new file mode 100644 index 00000000..4e589b01 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableDirectedGraph.html @@ -0,0 +1,287 @@ + + + + + + +UnmodifiableDirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UnmodifiableDirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.UnmodifiableGraph<V,E>
    +              extended by org.jgrapht.graph.UnmodifiableDirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, DirectedGraph<V,E>, Graph<V,E>
    +
    +
    +
    +
    public class UnmodifiableDirectedGraph<V,E>
    extends UnmodifiableGraph<V,E>
    implements DirectedGraph<V,E>
    + + +

    +A directed graph that cannot be modified. +

    + +

    +

    +
    See Also:
    UnmodifiableGraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    UnmodifiableDirectedGraph(DirectedGraph<V,E> g) + +
    +          Creates a new unmodifiable directed graph based on the specified backing + graph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.UnmodifiableGraph
    addEdge, addEdge, addVertex, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.DirectedGraph
    incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +UnmodifiableDirectedGraph

    +
    +public UnmodifiableDirectedGraph(DirectedGraph<V,E> g)
    +
    +
    Creates a new unmodifiable directed graph based on the specified backing + graph. +

    +

    +
    Parameters:
    g - the backing graph on which an unmodifiable graph is to be + created.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableGraph.html new file mode 100644 index 00000000..c355556b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableGraph.html @@ -0,0 +1,612 @@ + + + + + + +UnmodifiableGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UnmodifiableGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.UnmodifiableGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>
    +
    +
    +
    Direct Known Subclasses:
    UnmodifiableDirectedGraph, UnmodifiableUndirectedGraph
    +
    +
    +
    +
    public class UnmodifiableGraph<V,E>
    extends GraphDelegator<V,E>
    implements java.io.Serializable
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    Jul 24, 2003
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    UnmodifiableGraph(Graph<V,E> g) + +
    +          Creates a new unmodifiable graph based on the specified backing graph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + 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.
    + booleanaddEdge(V sourceVertex, + V targetVertex, + E e) + +
    +          Adds the specified edge to this graph, going from the source vertex to + the target vertex.
    + booleanaddVertex(V v) + +
    +          Adds the specified vertex to this graph if not already present.
    + booleanremoveAllEdges(java.util.Collection<? extends E> edges) + +
    +          Removes all the edges in this graph that are also contained in the + specified edge collection.
    + 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.
    + booleanremoveAllVertices(java.util.Collection<? extends V> vertices) + +
    +          Removes all the vertices in this graph that are also contained in the + specified vertex collection.
    + booleanremoveEdge(E e) + +
    +          Removes the specified edge from the graph.
    + EremoveEdge(V sourceVertex, + V targetVertex) + +
    +          Removes an edge going from source vertex to target vertex, if such + vertices and such edge exist in this graph.
    + booleanremoveVertex(V v) + +
    +          Removes the specified vertex from this graph including all its touching + edges if present.
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    containsEdge
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +UnmodifiableGraph

    +
    +public UnmodifiableGraph(Graph<V,E> g)
    +
    +
    Creates a new unmodifiable graph based on the specified backing graph. +

    +

    +
    Parameters:
    g - the backing graph on which an unmodifiable graph is to be + created.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +addEdge

    +
    +public E addEdge(V sourceVertex,
    +                 V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object)
    +
    +
    +
    + +

    +addEdge

    +
    +public boolean addEdge(V sourceVertex,
    +                       V targetVertex,
    +                       E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    addEdge in interface Graph<V,E>
    Overrides:
    addEdge in class GraphDelegator<V,E>
    +
    +
    +
    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.
    See Also:
    Graph.addEdge(Object, Object, Object)
    +
    +
    +
    + +

    +addVertex

    +
    +public boolean addVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    addVertex in interface Graph<V,E>
    Overrides:
    addVertex in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be added to this graph. +
    Returns:
    true if this graph did not already contain the specified + vertex.
    See Also:
    Graph.addVertex(Object)
    +
    +
    +
    + +

    +removeAllEdges

    +
    +public boolean removeAllEdges(java.util.Collection<? extends E> edges)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeAllEdges in interface Graph<V,E>
    Overrides:
    removeAllEdges in class AbstractGraph<V,E>
    +
    +
    +
    Parameters:
    edges - edges to be removed from this graph. +
    Returns:
    true if this graph changed as a result of the call
    See Also:
    Graph.removeAllEdges(Collection)
    +
    +
    +
    + +

    +removeAllEdges

    +
    +public java.util.Set<E> removeAllEdges(V sourceVertex,
    +                                       V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeAllEdges in interface Graph<V,E>
    Overrides:
    removeAllEdges in class AbstractGraph<V,E>
    +
    +
    +
    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
    See Also:
    Graph.removeAllEdges(Object, Object)
    +
    +
    +
    + +

    +removeAllVertices

    +
    +public boolean removeAllVertices(java.util.Collection<? extends V> vertices)
    +
    +
    Description copied from interface: 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 Graph.removeVertex(Object) method. +

    +

    +
    Specified by:
    removeAllVertices in interface Graph<V,E>
    Overrides:
    removeAllVertices in class AbstractGraph<V,E>
    +
    +
    +
    Parameters:
    vertices - vertices to be removed from this graph. +
    Returns:
    true if this graph changed as a result of the call
    See Also:
    Graph.removeAllVertices(Collection)
    +
    +
    +
    + +

    +removeEdge

    +
    +public boolean removeEdge(E e)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    Overrides:
    removeEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    e - edge to be removed from this graph, if present. +
    Returns:
    true if and only if the graph contained the + specified edge.
    See Also:
    Graph.removeEdge(Object)
    +
    +
    +
    + +

    +removeEdge

    +
    +public E removeEdge(V sourceVertex,
    +                    V targetVertex)
    +
    +
    Description copied from interface: Graph
    +
    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. +

    +

    +
    Specified by:
    removeEdge in interface Graph<V,E>
    Overrides:
    removeEdge in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    sourceVertex - source vertex of the edge.
    targetVertex - target vertex of the edge. +
    Returns:
    The removed edge, or null if no edge removed.
    See Also:
    Graph.removeEdge(Object, Object)
    +
    +
    +
    + +

    +removeVertex

    +
    +public boolean removeVertex(V v)
    +
    +
    Description copied from interface: Graph
    +
    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.

    +

    +

    +
    Specified by:
    removeVertex in interface Graph<V,E>
    Overrides:
    removeVertex in class GraphDelegator<V,E>
    +
    +
    +
    Parameters:
    v - vertex to be removed from this graph, if present. +
    Returns:
    true if the graph contained the specified vertex; + false otherwise.
    See Also:
    Graph.removeVertex(Object)
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableUndirectedGraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableUndirectedGraph.html new file mode 100644 index 00000000..f76e4cbb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/UnmodifiableUndirectedGraph.html @@ -0,0 +1,287 @@ + + + + + + +UnmodifiableUndirectedGraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class UnmodifiableUndirectedGraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.GraphDelegator<V,E>
    +          extended by org.jgrapht.graph.UnmodifiableGraph<V,E>
    +              extended by org.jgrapht.graph.UnmodifiableUndirectedGraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, Graph<V,E>, UndirectedGraph<V,E>
    +
    +
    +
    +
    public class UnmodifiableUndirectedGraph<V,E>
    extends UnmodifiableGraph<V,E>
    implements UndirectedGraph<V,E>
    + + +

    +An undirected graph that cannot be modified. +

    + +

    +

    +
    See Also:
    UnmodifiableGraph, +Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    UnmodifiableUndirectedGraph(UndirectedGraph<V,E> g) + +
    +          Creates a new unmodifiable undirected graph based on the specified + backing graph.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.UnmodifiableGraph
    addEdge, addEdge, addVertex, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.GraphDelegator
    containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeWeight, toString, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +UnmodifiableUndirectedGraph

    +
    +public UnmodifiableUndirectedGraph(UndirectedGraph<V,E> g)
    +
    +
    Creates a new unmodifiable undirected graph based on the specified + backing graph. +

    +

    +
    Parameters:
    g - the backing graph on which an unmodifiable graph is to be + created.
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/WeightedMultigraph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/WeightedMultigraph.html new file mode 100644 index 00000000..9987741d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/WeightedMultigraph.html @@ -0,0 +1,323 @@ + + + + + + +WeightedMultigraph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class WeightedMultigraph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.Multigraph<V,E>
    +              extended by org.jgrapht.graph.WeightedMultigraph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, UndirectedGraph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class WeightedMultigraph<V,E>
    extends Multigraph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    WeightedMultigraph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new weighted multigraph.
    WeightedMultigraph(EdgeFactory<V,E> ef) + +
    +          Creates a new weighted multigraph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +WeightedMultigraph

    +
    +public WeightedMultigraph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new weighted multigraph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    +
    + +

    +WeightedMultigraph

    +
    +public WeightedMultigraph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new weighted multigraph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/WeightedPseudograph.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/WeightedPseudograph.html new file mode 100644 index 00000000..44097e70 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/WeightedPseudograph.html @@ -0,0 +1,323 @@ + + + + + + +WeightedPseudograph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.graph +
    +Class WeightedPseudograph<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.graph.AbstractGraph<V,E>
    +      extended by org.jgrapht.graph.AbstractBaseGraph<V,E>
    +          extended by org.jgrapht.graph.Pseudograph<V,E>
    +              extended by org.jgrapht.graph.WeightedPseudograph<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Graph<V,E>, UndirectedGraph<V,E>, WeightedGraph<V,E>
    +
    +
    +
    +
    public class WeightedPseudograph<V,E>
    extends Pseudograph<V,E>
    implements WeightedGraph<V,E>
    + + +

    +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. +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from interface org.jgrapht.WeightedGraph
    DEFAULT_EDGE_WEIGHT
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    WeightedPseudograph(java.lang.Class<? extends E> edgeClass) + +
    +          Creates a new weighted pseudograph.
    WeightedPseudograph(EdgeFactory<V,E> ef) + +
    +          Creates a new weighted pseudograph with the specified edge factory.
    +  + + + + + + + +
    +Method Summary
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractBaseGraph
    addEdge, addEdge, addVertex, clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, incomingEdgesOf, inDegreeOf, isAllowingLoops, isAllowingMultipleEdges, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSetFactory, setEdgeWeight, vertexSet
    + + + + + + + +
    Methods inherited from class org.jgrapht.graph.AbstractGraph
    assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
    + + + + + + + +
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface org.jgrapht.WeightedGraph
    setEdgeWeight
    + + + + + + + +
    Methods inherited from interface org.jgrapht.Graph
    addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, getEdgeWeight, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet
    + + + + + + + +
    Methods inherited from interface org.jgrapht.UndirectedGraph
    degreeOf
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +WeightedPseudograph

    +
    +public WeightedPseudograph(EdgeFactory<V,E> ef)
    +
    +
    Creates a new weighted pseudograph with the specified edge factory. +

    +

    +
    Parameters:
    ef - the edge factory of the new graph.
    +
    +
    + +

    +WeightedPseudograph

    +
    +public WeightedPseudograph(java.lang.Class<? extends E> edgeClass)
    +
    +
    Creates a new weighted pseudograph. +

    +

    +
    Parameters:
    edgeClass - class on which to base factory for edges
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-frame.html new file mode 100644 index 00000000..65d38463 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-frame.html @@ -0,0 +1,137 @@ + + + + + + +org.jgrapht.graph (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.graph + + + + +
    +Interfaces  + +
    +EdgeSetFactory +
    +MaskFunctor
    + + + + + + +
    +Classes  + +
    +AbstractBaseGraph +
    +AbstractGraph +
    +AsUndirectedGraph +
    +AsUnweightedDirectedGraph +
    +AsUnweightedGraph +
    +AsWeightedGraph +
    +ClassBasedEdgeFactory +
    +ClassBasedVertexFactory +
    +DefaultDirectedGraph +
    +DefaultDirectedWeightedGraph +
    +DefaultEdge +
    +DefaultGraphMapping +
    +DefaultListenableGraph +
    +DefaultWeightedEdge +
    +DirectedGraphUnion +
    +DirectedMaskSubgraph +
    +DirectedMultigraph +
    +DirectedPseudograph +
    +DirectedSubgraph +
    +DirectedWeightedMultigraph +
    +DirectedWeightedSubgraph +
    +EdgeReversedGraph +
    +GraphDelegator +
    +GraphPathImpl +
    +GraphUnion +
    +ListenableDirectedGraph +
    +ListenableDirectedWeightedGraph +
    +ListenableUndirectedGraph +
    +ListenableUndirectedWeightedGraph +
    +MaskSubgraph +
    +Multigraph +
    +ParanoidGraph +
    +Pseudograph +
    +SimpleDirectedGraph +
    +SimpleDirectedWeightedGraph +
    +SimpleGraph +
    +SimpleWeightedGraph +
    +Subgraph +
    +UndirectedGraphUnion +
    +UndirectedMaskSubgraph +
    +UndirectedSubgraph +
    +UndirectedWeightedSubgraph +
    +UnmodifiableDirectedGraph +
    +UnmodifiableGraph +
    +UnmodifiableUndirectedGraph +
    +WeightedMultigraph +
    +WeightedPseudograph
    + + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-summary.html new file mode 100644 index 00000000..27cdf311 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-summary.html @@ -0,0 +1,381 @@ + + + + + + +org.jgrapht.graph (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package org.jgrapht.graph +

    +Implementations of various graphs. +

    +See: +
    +          Description +

    + + + + + + + + + + + + + +
    +Interface Summary
    EdgeSetFactory<V,E>A factory for edge sets.
    MaskFunctor<V,E>A functor interface for masking out vertices and edges of a graph.
    +  + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Class Summary
    AbstractBaseGraph<V,E>The most general implementation of the Graph interface.
    AbstractGraph<V,E>A skeletal implementation of the Graph interface, to minimize the + effort required to implement graph interfaces.
    AsUndirectedGraph<V,E>An undirected view of the backing directed graph specified in the + constructor.
    AsUnweightedDirectedGraph<V,E>An unweighted view of the backing weighted graph specified in the + constructor.
    AsUnweightedGraph<V,E>An unweighted view of the backing weighted graph specified in the + constructor.
    AsWeightedGraph<V,E>A weighted view of the backing graph specified in the constructor.
    ClassBasedEdgeFactory<V,E>An EdgeFactory for producing edges by using a class as a factory.
    ClassBasedVertexFactory<V>A VertexFactory for producing vertices by using a class as a factory.
    DefaultDirectedGraph<V,E>A directed graph.
    DefaultDirectedWeightedGraph<V,E>A directed weighted graph.
    DefaultEdgeA default implementation for edges in a Graph.
    DefaultGraphMapping<V,E>Implementation of the GraphMapping interface.
    DefaultListenableGraph<V,E>A graph backed by the the graph specified at the constructor, which can be + listened by GraphListener s and by + VertexSetListener s.
    DefaultWeightedEdgeA default implementation for edges in a WeightedGraph.
    DirectedGraphUnion<V,E> 
    DirectedMaskSubgraph<V,E>A directed graph that is a MaskSubgraph on another graph.
    DirectedMultigraph<V,E>A directed multigraph.
    DirectedPseudograph<V,E>A directed pseudograph.
    DirectedSubgraph<V,E>A directed graph that is a subgraph on other graph.
    DirectedWeightedMultigraph<V,E>A directed weighted multigraph.
    DirectedWeightedSubgraph<V,E>A directed weighted graph that is a subgraph on other graph.
    EdgeReversedGraph<V,E>Provides an edge-reversed view g' of a directed graph g.
    GraphDelegator<V,E>A graph backed by the the graph specified at the constructor, which delegates + all its methods to the backing graph.
    GraphPathImpl<V,E>GraphPathImpl is a default implementation of GraphPath.
    GraphUnion<V,E,G extends Graph<V,E>>Read-only union of two graphs: G1 and G2.
    ListenableDirectedGraph<V,E>A directed graph which is also ListenableGraph.
    ListenableDirectedWeightedGraph<V,E>A directed weighted graph which is also ListenableGraph.
    ListenableUndirectedGraph<V,E>An undirected graph which is also ListenableGraph.
    ListenableUndirectedWeightedGraph<V,E>An undirected weighted graph which is also ListenableGraph.
    MaskSubgraph<V,E>An unmodifiable subgraph induced by a vertex/edge masking function.
    Multigraph<V,E>A multigraph.
    ParanoidGraph<V,E>ParanoidGraph provides a way to verify that objects added to a graph obey the + standard equals/hashCode contract.
    Pseudograph<V,E>A pseudograph.
    SimpleDirectedGraph<V,E>A simple directed graph.
    SimpleDirectedWeightedGraph<V,E>A simple directed weighted graph.
    SimpleGraph<V,E>A simple graph.
    SimpleWeightedGraph<V,E>A simple weighted graph.
    Subgraph<V,E,G extends Graph<V,E>>A subgraph is a graph that has a subset of vertices and a subset of edges + with respect to some base graph.
    UndirectedGraphUnion<V,E> 
    UndirectedMaskSubgraph<V,E>An undirected graph that is a MaskSubgraph on another graph.
    UndirectedSubgraph<V,E>An undirected graph that is a subgraph on other graph.
    UndirectedWeightedSubgraph<V,E>An undirected weighted graph that is a subgraph on other graph.
    UnmodifiableDirectedGraph<V,E>A directed graph that cannot be modified.
    UnmodifiableGraph<V,E>An unmodifiable view of the backing graph specified in the constructor.
    UnmodifiableUndirectedGraph<V,E>An undirected graph that cannot be modified.
    WeightedMultigraph<V,E>A weighted multigraph.
    WeightedPseudograph<V,E>A weighted pseudograph.
    +  + +

    +

    +Package org.jgrapht.graph Description +

    + +

    +Implementations of various graphs. +

    + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-tree.html new file mode 100644 index 00000000..43f6653b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/graph/package-tree.html @@ -0,0 +1,237 @@ + + + + + + +org.jgrapht.graph Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package org.jgrapht.graph +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-frame.html new file mode 100644 index 00000000..60e3dee6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-frame.html @@ -0,0 +1,61 @@ + + + + + + +org.jgrapht (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht + + + + +
    +Interfaces  + +
    +DirectedGraph +
    +EdgeFactory +
    +Graph +
    +GraphMapping +
    +GraphPath +
    +ListenableGraph +
    +UndirectedGraph +
    +VertexFactory +
    +WeightedGraph
    + + + + + + +
    +Classes  + +
    +GraphHelper +
    +Graphs
    + + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-summary.html new file mode 100644 index 00000000..5dcb6e6e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-summary.html @@ -0,0 +1,225 @@ + + + + + + +org.jgrapht (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package org.jgrapht +

    +The front-end API's interfaces and classes, including Graph, +DirectedGraph and UndirectedGraph. +

    +See: +
    +          Description +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Interface Summary
    DirectedGraph<V,E>A graph whose all edges are directed.
    EdgeFactory<V,E>An edge factory used by graphs for creating new edges.
    Graph<V,E>The root interface in the graph hierarchy.
    GraphMapping<V,E>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.
    GraphPath<V,E>A GraphPath represents a + path in a Graph.
    ListenableGraph<V,E>A graph that supports listeners on structural change events.
    UndirectedGraph<V,E>A graph whose all edges are undirected.
    VertexFactory<V>A vertex factory used by graph algorithms for creating new vertices.
    WeightedGraph<V,E>An interface for a graph whose edges have non-uniform weights.
    +  + +

    + + + + + + + + + + + + + +
    +Class Summary
    GraphHelperDeprecated. Use Graphs instead.
    GraphsA collection of utilities to assist with graph manipulation.
    +  + +

    +

    +Package org.jgrapht Description +

    + +

    +The front-end API's interfaces and classes, including Graph, +DirectedGraph and UndirectedGraph. +

    + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-tree.html new file mode 100644 index 00000000..cc88c5b6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/package-tree.html @@ -0,0 +1,160 @@ + + + + + + +org.jgrapht Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package org.jgrapht +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/AbstractGraphIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/AbstractGraphIterator.html new file mode 100644 index 00000000..b2cd7313 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/AbstractGraphIterator.html @@ -0,0 +1,606 @@ + + + + + + +AbstractGraphIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Class AbstractGraphIterator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.traverse.AbstractGraphIterator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.util.Iterator<V>, GraphIterator<V,E>
    +
    +
    +
    Direct Known Subclasses:
    CrossComponentIterator
    +
    +
    +
    +
    public abstract class AbstractGraphIterator<V,E>
    extends java.lang.Object
    implements GraphIterator<V,E>
    + + +

    +An empty implementation of a graph iterator to minimize the effort required + to implement graph iterators. +

    + +

    +

    +
    Since:
    +
    Jul 19, 2003
    +
    Author:
    +
    Barak Naveh
    +
    +
    + +

    + + + + + + + + + + + +
    +Field Summary
    +protected  intnListeners + +
    +           
    +  + + + + + + + + + + +
    +Constructor Summary
    AbstractGraphIterator() + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + voidaddTraversalListener(TraversalListener<V,E> l) + +
    +          Adds the specified traversal listener to this iterator.
    +protected  voidfireConnectedComponentFinished(ConnectedComponentTraversalEvent e) + +
    +          Informs all listeners that the traversal of the current connected + component finished.
    +protected  voidfireConnectedComponentStarted(ConnectedComponentTraversalEvent e) + +
    +          Informs all listeners that a traversal of a new connected component has + started.
    +protected  voidfireEdgeTraversed(EdgeTraversalEvent<V,E> e) + +
    +          Informs all listeners that a the specified edge was visited.
    +protected  voidfireVertexFinished(VertexTraversalEvent<V> e) + +
    +          Informs all listeners that a the specified vertex was finished.
    +protected  voidfireVertexTraversed(VertexTraversalEvent<V> e) + +
    +          Informs all listeners that a the specified vertex was visited.
    + booleanisCrossComponentTraversal() + +
    +          Test whether this iterator is set to traverse the graph across connected + components.
    + booleanisReuseEvents() + +
    +          Tests whether the reuseEvents flag is set.
    + voidremove() + +
    +          Unsupported.
    + voidremoveTraversalListener(TraversalListener<V,E> l) + +
    +          Removes the specified traversal listener from this iterator.
    + voidsetCrossComponentTraversal(boolean crossComponentTraversal) + +
    +          Sets the cross component traversal flag - indicates whether to traverse + the graph across connected components.
    + voidsetReuseEvents(boolean reuseEvents) + +
    +          Sets a value the reuseEvents flag.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface java.util.Iterator
    hasNext, next
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +nListeners

    +
    +protected int nListeners
    +
    +
    +
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +AbstractGraphIterator

    +
    +public AbstractGraphIterator()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +setCrossComponentTraversal

    +
    +public void setCrossComponentTraversal(boolean crossComponentTraversal)
    +
    +
    Sets the cross component traversal flag - indicates whether to traverse + the graph across connected components. +

    +

    +
    +
    +
    +
    Parameters:
    crossComponentTraversal - if true traverses across + connected components.
    +
    +
    +
    + +

    +isCrossComponentTraversal

    +
    +public boolean isCrossComponentTraversal()
    +
    +
    Test whether this iterator is set to traverse the graph across connected + components. +

    +

    +
    Specified by:
    isCrossComponentTraversal in interface GraphIterator<V,E>
    +
    +
    + +
    Returns:
    true if traverses across connected components, + otherwise false.
    +
    +
    +
    + +

    +setReuseEvents

    +
    +public void setReuseEvents(boolean reuseEvents)
    +
    +
    Description copied from interface: GraphIterator
    +
    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. +

    +

    +
    Specified by:
    setReuseEvents in interface GraphIterator<V,E>
    +
    +
    +
    Parameters:
    reuseEvents - whether to reuse previously fired event objects + instead of creating a new event object for each event.
    See Also:
    GraphIterator.setReuseEvents(boolean)
    +
    +
    +
    + +

    +isReuseEvents

    +
    +public boolean isReuseEvents()
    +
    +
    Description copied from interface: GraphIterator
    +
    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. +

    +

    +
    Specified by:
    isReuseEvents in interface GraphIterator<V,E>
    +
    +
    + +
    Returns:
    the value of the reuseEvents flag.
    See Also:
    GraphIterator.isReuseEvents()
    +
    +
    +
    + +

    +addTraversalListener

    +
    +public void addTraversalListener(TraversalListener<V,E> l)
    +
    +
    Adds the specified traversal listener to this iterator. +

    +

    +
    Specified by:
    addTraversalListener in interface GraphIterator<V,E>
    +
    +
    +
    Parameters:
    l - the traversal listener to be added.
    +
    +
    +
    + +

    +remove

    +
    +public void remove()
    +
    +
    Unsupported. +

    +

    +
    Specified by:
    remove in interface java.util.Iterator<V>
    Specified by:
    remove in interface GraphIterator<V,E>
    +
    +
    + +
    Throws: +
    java.lang.UnsupportedOperationException
    +
    +
    +
    + +

    +removeTraversalListener

    +
    +public void removeTraversalListener(TraversalListener<V,E> l)
    +
    +
    Removes the specified traversal listener from this iterator. +

    +

    +
    Specified by:
    removeTraversalListener in interface GraphIterator<V,E>
    +
    +
    +
    Parameters:
    l - the traversal listener to be removed.
    +
    +
    +
    + +

    +fireConnectedComponentFinished

    +
    +protected void fireConnectedComponentFinished(ConnectedComponentTraversalEvent e)
    +
    +
    Informs all listeners that the traversal of the current connected + component finished. +

    +

    +
    +
    +
    +
    Parameters:
    e - the connected component finished event.
    +
    +
    +
    + +

    +fireConnectedComponentStarted

    +
    +protected void fireConnectedComponentStarted(ConnectedComponentTraversalEvent e)
    +
    +
    Informs all listeners that a traversal of a new connected component has + started. +

    +

    +
    +
    +
    +
    Parameters:
    e - the connected component started event.
    +
    +
    +
    + +

    +fireEdgeTraversed

    +
    +protected void fireEdgeTraversed(EdgeTraversalEvent<V,E> e)
    +
    +
    Informs all listeners that a the specified edge was visited. +

    +

    +
    +
    +
    +
    Parameters:
    e - the edge traversal event.
    +
    +
    +
    + +

    +fireVertexTraversed

    +
    +protected void fireVertexTraversed(VertexTraversalEvent<V> e)
    +
    +
    Informs all listeners that a the specified vertex was visited. +

    +

    +
    +
    +
    +
    Parameters:
    e - the vertex traversal event.
    +
    +
    +
    + +

    +fireVertexFinished

    +
    +protected void fireVertexFinished(VertexTraversalEvent<V> e)
    +
    +
    Informs all listeners that a the specified vertex was finished. +

    +

    +
    +
    +
    +
    Parameters:
    e - the vertex traversal event.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/BreadthFirstIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/BreadthFirstIterator.html new file mode 100644 index 00000000..b910a3b1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/BreadthFirstIterator.html @@ -0,0 +1,445 @@ + + + + + + +BreadthFirstIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Class BreadthFirstIterator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.traverse.AbstractGraphIterator<V,E>
    +      extended by org.jgrapht.traverse.CrossComponentIterator<V,E,java.lang.Object>
    +          extended by org.jgrapht.traverse.BreadthFirstIterator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.util.Iterator<V>, GraphIterator<V,E>
    +
    +
    +
    +
    public class BreadthFirstIterator<V,E>
    extends CrossComponentIterator<V,E,java.lang.Object>
    + + +

    +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
    CrossComponentIterator.VisitColor
    +  + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator
    nListeners
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    BreadthFirstIterator(Graph<V,E> g) + +
    +          Creates a new breadth-first iterator for the specified graph.
    BreadthFirstIterator(Graph<V,E> g, + V startVertex) + +
    +          Creates a new breadth-first iterator for the specified graph.
    +  + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    +protected  voidencounterVertex(V vertex, + E edge) + +
    +          Update data structures the first time we see a vertex.
    +protected  voidencounterVertexAgain(V vertex, + E edge) + +
    +          Called whenever we re-encounter a vertex.
    +protected  booleanisConnectedComponentExhausted() + +
    +          Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    +protected  VprovideNextVertex() + +
    +          Returns the vertex to be returned in the following call to the iterator + next method.
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.CrossComponentIterator
    finishVertex, getGraph, getSeenData, hasNext, isSeenVertex, next, putSeenData
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator
    addTraversalListener, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEvents
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +BreadthFirstIterator

    +
    +public BreadthFirstIterator(Graph<V,E> g)
    +
    +
    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. +

    +

    +
    Parameters:
    g - the graph to be iterated.
    startVertex - the vertex iteration to be started.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +isConnectedComponentExhausted

    +
    +protected boolean isConnectedComponentExhausted()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise. +

    +

    +
    Specified by:
    isConnectedComponentExhausted in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    + +
    Returns:
    true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    See Also:
    CrossComponentIterator.isConnectedComponentExhausted()
    +
    +
    +
    + +

    +encounterVertex

    +
    +protected void encounterVertex(V vertex,
    +                               E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Update data structures the first time we see a vertex. +

    +

    +
    Specified by:
    encounterVertex in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    +
    Parameters:
    vertex - the vertex encountered
    edge - the edge via which the vertex was encountered, or null if the + vertex is a starting point
    See Also:
    CrossComponentIterator.encounterVertex(Object, Object)
    +
    +
    +
    + +

    +encounterVertexAgain

    +
    +protected void encounterVertexAgain(V vertex,
    +                                    E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Called whenever we re-encounter a vertex. The default implementation does + nothing. +

    +

    +
    Specified by:
    encounterVertexAgain in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    +
    Parameters:
    vertex - the vertex re-encountered
    edge - the edge via which the vertex was re-encountered
    See Also:
    CrossComponentIterator.encounterVertexAgain(Object, Object)
    +
    +
    +
    + +

    +provideNextVertex

    +
    +protected V provideNextVertex()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns the vertex to be returned in the following call to the iterator + next method. +

    +

    +
    Specified by:
    provideNextVertex in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    + +
    Returns:
    the next vertex to be returned by this iterator.
    See Also:
    CrossComponentIterator.provideNextVertex()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/ClosestFirstIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/ClosestFirstIterator.html new file mode 100644 index 00000000..42815a4d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/ClosestFirstIterator.html @@ -0,0 +1,559 @@ + + + + + + +ClosestFirstIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Class ClosestFirstIterator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.traverse.AbstractGraphIterator<V,E>
    +      extended by org.jgrapht.traverse.CrossComponentIterator<V,E,FibonacciHeapNode<org.jgrapht.traverse.ClosestFirstIterator.QueueEntry<V,E>>>
    +          extended by org.jgrapht.traverse.ClosestFirstIterator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.util.Iterator<V>, GraphIterator<V,E>
    +
    +
    +
    +
    public class ClosestFirstIterator<V,E>
    extends CrossComponentIterator<V,E,FibonacciHeapNode<org.jgrapht.traverse.ClosestFirstIterator.QueueEntry<V,E>>>
    + + +

    +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
    CrossComponentIterator.VisitColor
    +  + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator
    nListeners
    +  + + + + + + + + + + + + + + + + +
    +Constructor Summary
    ClosestFirstIterator(Graph<V,E> g) + +
    +          Creates a new closest-first iterator for the specified graph.
    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  voidencounterVertex(V vertex, + E edge) + +
    +          Update data structures the first time we see a vertex.
    +protected  voidencounterVertexAgain(V vertex, + E edge) + +
    +          Override superclass.
    + doublegetShortestPathLength(V vertex) + +
    +          Get the length of the shortest path known to the given vertex.
    + EgetSpanningTreeEdge(V vertex) + +
    +          Get the spanning tree edge reaching a vertex which has been seen already + in this traversal.
    +protected  booleanisConnectedComponentExhausted() + +
    +          Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    +protected  VprovideNextVertex() + +
    +          Returns the vertex to be returned in the following call to the iterator + next method.
    + voidsetCrossComponentTraversal(boolean crossComponentTraversal) + +
    +          Sets the cross component traversal flag - indicates whether to traverse + the graph across connected components.
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.CrossComponentIterator
    finishVertex, getGraph, getSeenData, hasNext, isSeenVertex, next, putSeenData
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator
    addTraversalListener, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setReuseEvents
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ClosestFirstIterator

    +
    +public ClosestFirstIterator(Graph<V,E> g)
    +
    +
    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.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +setCrossComponentTraversal

    +
    +public void setCrossComponentTraversal(boolean crossComponentTraversal)
    +
    +
    Description copied from class: AbstractGraphIterator
    +
    Sets the cross component traversal flag - indicates whether to traverse + the graph across connected components. +

    +

    +
    Overrides:
    setCrossComponentTraversal in class AbstractGraphIterator<V,E>
    +
    +
    +
    Parameters:
    crossComponentTraversal - if true traverses across + connected components.
    +
    +
    +
    + +

    +getShortestPathLength

    +
    +public double getShortestPathLength(V vertex)
    +
    +
    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
    +
    +
    +
    + +

    +getSpanningTreeEdge

    +
    +public E getSpanningTreeEdge(V vertex)
    +
    +
    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.
    +
    +
    +
    + +

    +isConnectedComponentExhausted

    +
    +protected boolean isConnectedComponentExhausted()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise. +

    +

    +
    Specified by:
    isConnectedComponentExhausted in class CrossComponentIterator<V,E,FibonacciHeapNode<org.jgrapht.traverse.ClosestFirstIterator.QueueEntry<V,E>>>
    +
    +
    + +
    Returns:
    true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    See Also:
    CrossComponentIterator.isConnectedComponentExhausted()
    +
    +
    +
    + +

    +encounterVertex

    +
    +protected void encounterVertex(V vertex,
    +                               E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Update data structures the first time we see a vertex. +

    +

    +
    Specified by:
    encounterVertex in class CrossComponentIterator<V,E,FibonacciHeapNode<org.jgrapht.traverse.ClosestFirstIterator.QueueEntry<V,E>>>
    +
    +
    +
    Parameters:
    vertex - the vertex encountered
    edge - the edge via which the vertex was encountered, or null if the + vertex is a starting point
    See Also:
    CrossComponentIterator.encounterVertex(Object, Object)
    +
    +
    +
    + +

    +encounterVertexAgain

    +
    +protected void encounterVertexAgain(V vertex,
    +                                    E edge)
    +
    +
    Override superclass. When we see a vertex again, we need to see if the + new edge provides a shorter path than the old edge. +

    +

    +
    Specified by:
    encounterVertexAgain in class CrossComponentIterator<V,E,FibonacciHeapNode<org.jgrapht.traverse.ClosestFirstIterator.QueueEntry<V,E>>>
    +
    +
    +
    Parameters:
    vertex - the vertex re-encountered
    edge - the edge via which the vertex was re-encountered
    +
    +
    +
    + +

    +provideNextVertex

    +
    +protected V provideNextVertex()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns the vertex to be returned in the following call to the iterator + next method. +

    +

    +
    Specified by:
    provideNextVertex in class CrossComponentIterator<V,E,FibonacciHeapNode<org.jgrapht.traverse.ClosestFirstIterator.QueueEntry<V,E>>>
    +
    +
    + +
    Returns:
    the next vertex to be returned by this iterator.
    See Also:
    CrossComponentIterator.provideNextVertex()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/CrossComponentIterator.VisitColor.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/CrossComponentIterator.VisitColor.html new file mode 100644 index 00000000..4eb74d79 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/CrossComponentIterator.VisitColor.html @@ -0,0 +1,353 @@ + + + + + + +CrossComponentIterator.VisitColor (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Enum CrossComponentIterator.VisitColor

    +
    +java.lang.Object
    +  extended by java.lang.Enum<CrossComponentIterator.VisitColor>
    +      extended by org.jgrapht.traverse.CrossComponentIterator.VisitColor
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<CrossComponentIterator.VisitColor>
    +
    +
    +
    Enclosing class:
    CrossComponentIterator<V,E,D>
    +
    +
    +
    +
    protected static enum CrossComponentIterator.VisitColor
    extends java.lang.Enum<CrossComponentIterator.VisitColor>
    + + +

    +Standard vertex visit state enumeration. +

    + +

    +


    + +

    + + + + + + + + + + + + + + + + +
    +Enum Constant Summary
    BLACK + +
    +          Vertex has been returned via iterator, and we're done with all of its + out-edges.
    GRAY + +
    +          Vertex has been returned via iterator, but we're not done with all of + its out-edges yet.
    WHITE + +
    +          Vertex has not been returned via iterator yet.
    +  + + + + + + + + + + + + + + + +
    +Method Summary
    +static CrossComponentIterator.VisitColorvalueOf(java.lang.String name) + +
    +          Returns the enum constant of this type with the specified name.
    +static CrossComponentIterator.VisitColor[]values() + +
    +          Returns an array containing the constants of this enum type, in +the order they are declared.
    + + + + + + + +
    Methods inherited from class java.lang.Enum
    clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
    + + + + + + + +
    Methods inherited from class java.lang.Object
    getClass, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Enum Constant Detail
    + +

    +WHITE

    +
    +public static final CrossComponentIterator.VisitColor WHITE
    +
    +
    Vertex has not been returned via iterator yet. +

    +

    +
    +
    +
    + +

    +GRAY

    +
    +public static final CrossComponentIterator.VisitColor GRAY
    +
    +
    Vertex has been returned via iterator, but we're not done with all of + its out-edges yet. +

    +

    +
    +
    +
    + +

    +BLACK

    +
    +public static final CrossComponentIterator.VisitColor BLACK
    +
    +
    Vertex has been returned via iterator, and we're done with all of its + out-edges. +

    +

    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +values

    +
    +public static CrossComponentIterator.VisitColor[] values()
    +
    +
    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
    +
    +
    +
    + +

    +valueOf

    +
    +public static CrossComponentIterator.VisitColor valueOf(java.lang.String name)
    +
    +
    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
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/CrossComponentIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/CrossComponentIterator.html new file mode 100644 index 00000000..5d2d9b59 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/CrossComponentIterator.html @@ -0,0 +1,558 @@ + + + + + + +CrossComponentIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Class CrossComponentIterator<V,E,D>

    +
    +java.lang.Object
    +  extended by org.jgrapht.traverse.AbstractGraphIterator<V,E>
    +      extended by org.jgrapht.traverse.CrossComponentIterator<V,E,D>
    +
    +
    +
    Type Parameters:
    V - vertex type
    E - edge type
    D - type of data associated to seen vertices
    +
    +
    All Implemented Interfaces:
    java.util.Iterator<V>, GraphIterator<V,E>
    +
    +
    +
    Direct Known Subclasses:
    BreadthFirstIterator, ClosestFirstIterator, DepthFirstIterator, TopologicalOrderIterator
    +
    +
    +
    +
    public abstract class CrossComponentIterator<V,E,D>
    extends AbstractGraphIterator<V,E>
    + + +

    +Provides a cross-connected-component traversal functionality for iterator + subclasses. +

    + +

    +

    +
    Since:
    +
    Jan 31, 2004
    +
    Author:
    +
    Barak Naveh
    +
    +
    + +

    + + + + + + + + + + + +
    +Nested Class Summary
    +protected static classCrossComponentIterator.VisitColor + +
    +          Standard vertex visit state enumeration.
    + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator
    nListeners
    +  + + + + + + + + + + +
    +Constructor Summary
    CrossComponentIterator(Graph<V,E> g, + V startVertex) + +
    +          Creates a new iterator for the specified graph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    +protected abstract  voidencounterVertex(V vertex, + E edge) + +
    +          Update data structures the first time we see a vertex.
    +protected abstract  voidencounterVertexAgain(V vertex, + E edge) + +
    +          Called whenever we re-encounter a vertex.
    +protected  voidfinishVertex(V vertex) + +
    +          Called when a vertex has been finished (meaning is dependent on traversal + represented by subclass).
    + Graph<V,E>getGraph() + +
    +           
    +protected  DgetSeenData(V vertex) + +
    +          Access the data stored for a seen vertex.
    + booleanhasNext() + +
    +           
    +protected abstract  booleanisConnectedComponentExhausted() + +
    +          Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    +protected  booleanisSeenVertex(java.lang.Object vertex) + +
    +          Determines whether a vertex has been seen yet by this traversal.
    + Vnext() + +
    +           
    +protected abstract  VprovideNextVertex() + +
    +          Returns the vertex to be returned in the following call to the iterator + next method.
    +protected  DputSeenData(V vertex, + D data) + +
    +          Stores iterator-dependent data for a vertex that has been seen.
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator
    addTraversalListener, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEvents
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +CrossComponentIterator

    +
    +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
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getGraph

    +
    +public Graph<V,E> getGraph()
    +
    +
    + +
    Returns:
    the graph being traversed
    +
    +
    +
    + +

    +hasNext

    +
    +public boolean hasNext()
    +
    +
    +
    See Also:
    Iterator.hasNext()
    +
    +
    +
    + +

    +next

    +
    +public V next()
    +
    +
    +
    See Also:
    Iterator.next()
    +
    +
    +
    + +

    +isConnectedComponentExhausted

    +
    +protected abstract boolean isConnectedComponentExhausted()
    +
    +
    Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise. +

    +

    + +
    Returns:
    true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    +
    +
    +
    + +

    +encounterVertex

    +
    +protected abstract void encounterVertex(V vertex,
    +                                        E edge)
    +
    +
    Update data structures the first time we see a vertex. +

    +

    +
    Parameters:
    vertex - the vertex encountered
    edge - the edge via which the vertex was encountered, or null if the + vertex is a starting point
    +
    +
    +
    + +

    +provideNextVertex

    +
    +protected abstract V provideNextVertex()
    +
    +
    Returns the vertex to be returned in the following call to the iterator + next method. +

    +

    + +
    Returns:
    the next vertex to be returned by this iterator.
    +
    +
    +
    + +

    +getSeenData

    +
    +protected D getSeenData(V vertex)
    +
    +
    Access the data stored for a seen vertex. +

    +

    +
    Parameters:
    vertex - a vertex which has already been seen. +
    Returns:
    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.
    +
    +
    +
    + +

    +isSeenVertex

    +
    +protected boolean isSeenVertex(java.lang.Object vertex)
    +
    +
    Determines whether a vertex has been seen yet by this traversal. +

    +

    +
    Parameters:
    vertex - vertex in question +
    Returns:
    true if vertex has already been seen
    +
    +
    +
    + +

    +encounterVertexAgain

    +
    +protected abstract void encounterVertexAgain(V vertex,
    +                                             E edge)
    +
    +
    Called whenever we re-encounter a vertex. The default implementation does + nothing. +

    +

    +
    Parameters:
    vertex - the vertex re-encountered
    edge - the edge via which the vertex was re-encountered
    +
    +
    +
    + +

    +putSeenData

    +
    +protected D putSeenData(V vertex,
    +                        D data)
    +
    +
    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.
    +
    +
    +
    + +

    +finishVertex

    +
    +protected void finishVertex(V vertex)
    +
    +
    Called when a vertex has been finished (meaning is dependent on traversal + represented by subclass). +

    +

    +
    Parameters:
    vertex - vertex which has been finished
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/DepthFirstIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/DepthFirstIterator.html new file mode 100644 index 00000000..dde69842 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/DepthFirstIterator.html @@ -0,0 +1,503 @@ + + + + + + +DepthFirstIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Class DepthFirstIterator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.traverse.AbstractGraphIterator<V,E>
    +      extended by org.jgrapht.traverse.CrossComponentIterator<V,E,CrossComponentIterator.VisitColor>
    +          extended by org.jgrapht.traverse.DepthFirstIterator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.util.Iterator<V>, GraphIterator<V,E>
    +
    +
    +
    +
    public class DepthFirstIterator<V,E>
    extends CrossComponentIterator<V,E,CrossComponentIterator.VisitColor>
    + + +

    +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
    CrossComponentIterator.VisitColor
    +  + + + + + + + + + + + +
    +Field Summary
    +static java.lang.ObjectSENTINEL + +
    +          Sentinel object.
    + + + + + + + +
    Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator
    nListeners
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    DepthFirstIterator(Graph<V,E> g) + +
    +          Creates a new depth-first iterator for the specified graph.
    DepthFirstIterator(Graph<V,E> g, + V startVertex) + +
    +          Creates a new depth-first iterator for the specified graph.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    +protected  voidencounterVertex(V vertex, + E edge) + +
    +          Update data structures the first time we see a vertex.
    +protected  voidencounterVertexAgain(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  booleanisConnectedComponentExhausted() + +
    +          Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    +protected  VprovideNextVertex() + +
    +          Returns the vertex to be returned in the following call to the iterator + next method.
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.CrossComponentIterator
    finishVertex, getGraph, getSeenData, hasNext, isSeenVertex, next, putSeenData
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator
    addTraversalListener, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEvents
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +SENTINEL

    +
    +public static final java.lang.Object SENTINEL
    +
    +
    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. +

    +

    +
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +DepthFirstIterator

    +
    +public DepthFirstIterator(Graph<V,E> g)
    +
    +
    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. +

    +

    +
    Parameters:
    g - the graph to be iterated.
    startVertex - the vertex iteration to be started.
    +
    + + + + + + + + +
    +Method Detail
    + +

    +isConnectedComponentExhausted

    +
    +protected boolean isConnectedComponentExhausted()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise. +

    +

    +
    Specified by:
    isConnectedComponentExhausted in class CrossComponentIterator<V,E,CrossComponentIterator.VisitColor>
    +
    +
    + +
    Returns:
    true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    See Also:
    CrossComponentIterator.isConnectedComponentExhausted()
    +
    +
    +
    + +

    +encounterVertex

    +
    +protected void encounterVertex(V vertex,
    +                               E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Update data structures the first time we see a vertex. +

    +

    +
    Specified by:
    encounterVertex in class CrossComponentIterator<V,E,CrossComponentIterator.VisitColor>
    +
    +
    +
    Parameters:
    vertex - the vertex encountered
    edge - the edge via which the vertex was encountered, or null if the + vertex is a starting point
    See Also:
    CrossComponentIterator.encounterVertex(Object, Object)
    +
    +
    +
    + +

    +encounterVertexAgain

    +
    +protected void encounterVertexAgain(V vertex,
    +                                    E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Called whenever we re-encounter a vertex. The default implementation does + nothing. +

    +

    +
    Specified by:
    encounterVertexAgain in class CrossComponentIterator<V,E,CrossComponentIterator.VisitColor>
    +
    +
    +
    Parameters:
    vertex - the vertex re-encountered
    edge - the edge via which the vertex was re-encountered
    See Also:
    CrossComponentIterator.encounterVertexAgain(Object, Object)
    +
    +
    +
    + +

    +provideNextVertex

    +
    +protected V provideNextVertex()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns the vertex to be returned in the following call to the iterator + next method. +

    +

    +
    Specified by:
    provideNextVertex in class CrossComponentIterator<V,E,CrossComponentIterator.VisitColor>
    +
    +
    + +
    Returns:
    the next vertex to be returned by this iterator.
    See Also:
    CrossComponentIterator.provideNextVertex()
    +
    +
    +
    + +

    +getStack

    +
    +public java.util.Deque<java.lang.Object> getStack()
    +
    +
    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). +

    +

    + +
    Returns:
    stack
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/GraphIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/GraphIterator.html new file mode 100644 index 00000000..11ea06b8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/GraphIterator.html @@ -0,0 +1,370 @@ + + + + + + +GraphIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Interface GraphIterator<V,E>

    +
    +
    All Superinterfaces:
    java.util.Iterator<V>
    +
    +
    +
    All Known Implementing Classes:
    AbstractGraphIterator, BreadthFirstIterator, ClosestFirstIterator, CrossComponentIterator, DepthFirstIterator, TopologicalOrderIterator
    +
    +
    +
    +
    public interface GraphIterator<V,E>
    extends java.util.Iterator<V>
    + + +

    +A graph iterator. +

    + +

    +

    +
    Since:
    +
    Jul 31, 2003
    +
    Author:
    +
    Barak Naveh
    +
    +
    + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + voidaddTraversalListener(TraversalListener<V,E> l) + +
    +          Adds the specified traversal listener to this iterator.
    + booleanisCrossComponentTraversal() + +
    +          Test whether this iterator is set to traverse the grpah across connected + components.
    + booleanisReuseEvents() + +
    +          Tests whether the reuseEvents flag is set.
    + voidremove() + +
    +          Unsupported.
    + voidremoveTraversalListener(TraversalListener<V,E> l) + +
    +          Removes the specified traversal listener from this iterator.
    + voidsetReuseEvents(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. +

    +

    +
    +
    +
    + +
    Returns:
    the value of the reuseEvents flag.
    +
    +
    +
    + +

    +addTraversalListener

    +
    +void addTraversalListener(TraversalListener<V,E> l)
    +
    +
    Adds the specified traversal listener to this iterator. +

    +

    +
    +
    +
    +
    Parameters:
    l - the traversal listener to be added.
    +
    +
    +
    + +

    +remove

    +
    +void remove()
    +
    +
    Unsupported. +

    +

    +
    Specified by:
    remove in interface java.util.Iterator<V>
    +
    +
    + +
    Throws: +
    java.lang.UnsupportedOperationException
    +
    +
    +
    + +

    +removeTraversalListener

    +
    +void removeTraversalListener(TraversalListener<V,E> l)
    +
    +
    Removes the specified traversal listener from this iterator. +

    +

    +
    +
    +
    +
    Parameters:
    l - the traversal listener to be removed.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/TopologicalOrderIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/TopologicalOrderIterator.html new file mode 100644 index 00000000..9e443d5a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/TopologicalOrderIterator.html @@ -0,0 +1,471 @@ + + + + + + +TopologicalOrderIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.traverse +
    +Class TopologicalOrderIterator<V,E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.traverse.AbstractGraphIterator<V,E>
    +      extended by org.jgrapht.traverse.CrossComponentIterator<V,E,java.lang.Object>
    +          extended by org.jgrapht.traverse.TopologicalOrderIterator<V,E>
    +
    +
    +
    All Implemented Interfaces:
    java.util.Iterator<V>, GraphIterator<V,E>
    +
    +
    +
    +
    public class TopologicalOrderIterator<V,E>
    extends CrossComponentIterator<V,E,java.lang.Object>
    + + +

    +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
    CrossComponentIterator.VisitColor
    +  + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator
    nListeners
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    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  voidencounterVertex(V vertex, + E edge) + +
    +          Update data structures the first time we see a vertex.
    +protected  voidencounterVertexAgain(V vertex, + E edge) + +
    +          Called whenever we re-encounter a vertex.
    +protected  booleanisConnectedComponentExhausted() + +
    +          Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    +protected  VprovideNextVertex() + +
    +          Returns the vertex to be returned in the following call to the iterator + next method.
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.CrossComponentIterator
    finishVertex, getGraph, getSeenData, hasNext, isSeenVertex, next, putSeenData
    + + + + + + + +
    Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator
    addTraversalListener, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEvents
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +TopologicalOrderIterator

    +
    +public 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. + 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.
    +
    +
    + +

    +TopologicalOrderIterator

    +
    +public 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. 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
    +
    + + + + + + + + +
    +Method Detail
    + +

    +isConnectedComponentExhausted

    +
    +protected boolean isConnectedComponentExhausted()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise. +

    +

    +
    Specified by:
    isConnectedComponentExhausted in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    + +
    Returns:
    true if there are no more uniterated vertices in the + currently iterated connected component; false otherwise.
    See Also:
    CrossComponentIterator.isConnectedComponentExhausted()
    +
    +
    +
    + +

    +encounterVertex

    +
    +protected void encounterVertex(V vertex,
    +                               E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Update data structures the first time we see a vertex. +

    +

    +
    Specified by:
    encounterVertex in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    +
    Parameters:
    vertex - the vertex encountered
    edge - the edge via which the vertex was encountered, or null if the + vertex is a starting point
    See Also:
    CrossComponentIterator.encounterVertex(Object, Object)
    +
    +
    +
    + +

    +encounterVertexAgain

    +
    +protected void encounterVertexAgain(V vertex,
    +                                    E edge)
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Called whenever we re-encounter a vertex. The default implementation does + nothing. +

    +

    +
    Specified by:
    encounterVertexAgain in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    +
    Parameters:
    vertex - the vertex re-encountered
    edge - the edge via which the vertex was re-encountered
    See Also:
    CrossComponentIterator.encounterVertexAgain(Object, Object)
    +
    +
    +
    + +

    +provideNextVertex

    +
    +protected V provideNextVertex()
    +
    +
    Description copied from class: CrossComponentIterator
    +
    Returns the vertex to be returned in the following call to the iterator + next method. +

    +

    +
    Specified by:
    provideNextVertex in class CrossComponentIterator<V,E,java.lang.Object>
    +
    +
    + +
    Returns:
    the next vertex to be returned by this iterator.
    See Also:
    CrossComponentIterator.provideNextVertex()
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-frame.html new file mode 100644 index 00000000..de81ab0f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-frame.html @@ -0,0 +1,64 @@ + + + + + + +org.jgrapht.traverse (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.traverse + + + + +
    +Interfaces  + +
    +GraphIterator
    + + + + + + +
    +Classes  + +
    +AbstractGraphIterator +
    +BreadthFirstIterator +
    +ClosestFirstIterator +
    +CrossComponentIterator +
    +DepthFirstIterator +
    +TopologicalOrderIterator
    + + + + + + +
    +Enums  + +
    +CrossComponentIterator.VisitColor
    + + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-summary.html new file mode 100644 index 00000000..f27cf3fe --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-summary.html @@ -0,0 +1,220 @@ + + + + + + +org.jgrapht.traverse (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package org.jgrapht.traverse +

    +Graph traversal means. +

    +See: +
    +          Description +

    + + + + + + + + + +
    +Interface Summary
    GraphIterator<V,E>A graph iterator.
    +  + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Class Summary
    AbstractGraphIterator<V,E>An empty implementation of a graph iterator to minimize the effort required + to implement graph iterators.
    BreadthFirstIterator<V,E>A breadth-first iterator for a directed and an undirected graph.
    ClosestFirstIterator<V,E>A closest-first iterator for a directed or undirected graph.
    CrossComponentIterator<V,E,D>Provides a cross-connected-component traversal functionality for iterator + subclasses.
    DepthFirstIterator<V,E>A depth-first iterator for a directed and an undirected graph.
    TopologicalOrderIterator<V,E>Implements topological order traversal for a directed acyclic graph.
    +  + +

    + + + + + + + + + +
    +Enum Summary
    CrossComponentIterator.VisitColorStandard vertex visit state enumeration.
    +  + +

    +

    +Package org.jgrapht.traverse Description +

    + +

    +Graph traversal means. +

    + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-tree.html new file mode 100644 index 00000000..5cde3527 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/traverse/package-tree.html @@ -0,0 +1,173 @@ + + + + + + +org.jgrapht.traverse Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package org.jgrapht.traverse +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    +
      +
    • java.util.Iterator<E> +
    +

    +Enum Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/ArrayUnenforcedSet.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/ArrayUnenforcedSet.html new file mode 100644 index 00000000..46418720 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/ArrayUnenforcedSet.html @@ -0,0 +1,386 @@ + + + + + + +ArrayUnenforcedSet (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class ArrayUnenforcedSet<E>

    +
    +java.lang.Object
    +  extended by java.util.AbstractCollection<E>
    +      extended by java.util.AbstractList<E>
    +          extended by java.util.ArrayList<E>
    +              extended by org.jgrapht.util.ArrayUnenforcedSet<E>
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, java.util.Set<E>
    +
    +
    +
    +
    public class ArrayUnenforcedSet<E>
    extends java.util.ArrayList<E>
    implements java.util.Set<E>
    + + +

    +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. +

    + +

    +

    +
    Author:
    +
    John V. Sichi
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from class java.util.AbstractList
    modCount
    +  + + + + + + + + + + + + + + + + +
    +Constructor Summary
    ArrayUnenforcedSet() + +
    +           
    ArrayUnenforcedSet(java.util.Collection<? extends E> c) + +
    +           
    ArrayUnenforcedSet(int n) + +
    +           
    +  + + + + + + + + + + + + + + + +
    +Method Summary
    + booleanequals(java.lang.Object o) + +
    +           
    + inthashCode() + +
    +           
    + + + + + + + +
    Methods inherited from class java.util.ArrayList
    add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
    + + + + + + + +
    Methods inherited from class java.util.AbstractList
    iterator, listIterator, listIterator, subList
    + + + + + + + +
    Methods inherited from class java.util.AbstractCollection
    containsAll, removeAll, retainAll, toString
    + + + + + + + +
    Methods inherited from class java.lang.Object
    finalize, getClass, notify, notifyAll, wait, wait, wait
    + + + + + + + +
    Methods inherited from interface java.util.Set
    add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
    + + + + + + + +
    Methods inherited from interface java.util.List
    containsAll, iterator, listIterator, listIterator, removeAll, retainAll, subList
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +ArrayUnenforcedSet

    +
    +public ArrayUnenforcedSet()
    +
    +
    +
    + +

    +ArrayUnenforcedSet

    +
    +public ArrayUnenforcedSet(java.util.Collection<? extends E> c)
    +
    +
    +
    + +

    +ArrayUnenforcedSet

    +
    +public ArrayUnenforcedSet(int n)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +equals

    +
    +public boolean equals(java.lang.Object o)
    +
    +
    +
    Specified by:
    equals in interface java.util.Collection<E>
    Specified by:
    equals in interface java.util.List<E>
    Specified by:
    equals in interface java.util.Set<E>
    Overrides:
    equals in class java.util.AbstractList<E>
    +
    +
    +
    +
    +
    +
    + +

    +hashCode

    +
    +public int hashCode()
    +
    +
    +
    Specified by:
    hashCode in interface java.util.Collection<E>
    Specified by:
    hashCode in interface java.util.List<E>
    Specified by:
    hashCode in interface java.util.Set<E>
    Overrides:
    hashCode in class java.util.AbstractList<E>
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/FibonacciHeap.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/FibonacciHeap.html new file mode 100644 index 00000000..8b7bd15c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/FibonacciHeap.html @@ -0,0 +1,616 @@ + + + + + + +FibonacciHeap (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class FibonacciHeap<T>

    +
    +java.lang.Object
    +  extended by org.jgrapht.util.FibonacciHeap<T>
    +
    +
    +
    +
    public class FibonacciHeap<T>
    extends java.lang.Object
    + + +

    +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.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    +protected  voidcascadingCut(FibonacciHeapNode<T> y) + +
    +          Performs a cascading cut operation.
    + voidclear() + +
    +          Removes all elements from this heap.
    +protected  voidconsolidate() + +
    +           
    +protected  voidcut(FibonacciHeapNode<T> x, + FibonacciHeapNode<T> y) + +
    +          The reverse of the link operation: removes x from the child list of y.
    + voiddecreaseKey(FibonacciHeapNode<T> x, + double k) + +
    +          Decreases the key value for a heap node, given the new value to take on.
    + voiddelete(FibonacciHeapNode<T> x) + +
    +          Deletes a node from the heap given the reference to the node.
    + voidinsert(FibonacciHeapNode<T> node, + double key) + +
    +          Inserts a new data element into the heap.
    + booleanisEmpty() + +
    +          Tests if the Fibonacci heap is empty or not.
    +protected  voidlink(FibonacciHeapNode<T> y, + FibonacciHeapNode<T> x) + +
    +          Make node y a child of node x.
    + FibonacciHeapNode<T>min() + +
    +          Returns the smallest element in the heap.
    + FibonacciHeapNode<T>removeMin() + +
    +          Removes the smallest element from the heap.
    + intsize() + +
    +          Returns the size of the heap which is measured in the number of elements + contained in the heap.
    + java.lang.StringtoString() + +
    +          Creates a String representation of this Fibonacci heap.
    +static + + + + +
    +<T> FibonacciHeap<T>
    +
    union(FibonacciHeap<T> h1, + FibonacciHeap<T> h2) + +
    +          Joins two Fibonacci heaps into a new one.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +FibonacciHeap

    +
    +public FibonacciHeap()
    +
    +
    Constructs a FibonacciHeap object that contains no elements. +

    +

    + + + + + + + + +
    +Method Detail
    + +

    +isEmpty

    +
    +public boolean isEmpty()
    +
    +
    Tests if the Fibonacci heap is empty or not. Returns true if the heap is + empty, false otherwise. + +

    Running time: O(1) actual

    +

    +

    + +
    Returns:
    true if the heap is empty, false otherwise
    +
    +
    +
    + +

    +clear

    +
    +public void clear()
    +
    +
    Removes all elements from this heap. +

    +

    +
    +
    +
    +
    + +

    +decreaseKey

    +
    +public void decreaseKey(FibonacciHeapNode<T> x,
    +                        double k)
    +
    +
    Decreases the key value for a heap node, given the new value to take on. + The structure of the heap may be changed and will not be consolidated. + +

    Running time: O(1) amortized

    +

    +

    +
    Parameters:
    x - node to decrease the key of
    k - new key value for node x +
    Throws: +
    java.lang.IllegalArgumentException - Thrown if k is larger than x.key + value.
    +
    +
    +
    + +

    +delete

    +
    +public void delete(FibonacciHeapNode<T> x)
    +
    +
    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. + +

    Running time: O(log n) amortized

    +

    +

    +
    Parameters:
    x - node to remove from heap
    +
    +
    +
    + +

    +insert

    +
    +public void insert(FibonacciHeapNode<T> node,
    +                   double key)
    +
    +
    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. + +

    Running time: O(1) actual

    +

    +

    +
    Parameters:
    node - new node to insert into heap
    key - key value associated with data object
    +
    +
    +
    + +

    +min

    +
    +public FibonacciHeapNode<T> min()
    +
    +
    Returns the smallest element in the heap. This smallest element is the + one with the minimum key value. + +

    Running time: O(1) actual

    +

    +

    + +
    Returns:
    heap node with the smallest key
    +
    +
    +
    + +

    +removeMin

    +
    +public FibonacciHeapNode<T> removeMin()
    +
    +
    Removes the smallest element from the heap. This will cause the trees in + the heap to be consolidated, if necessary. + +

    Running time: O(log n) amortized

    +

    +

    + +
    Returns:
    node with the smallest key
    +
    +
    +
    + +

    +size

    +
    +public int size()
    +
    +
    Returns the size of the heap which is measured in the number of elements + contained in the heap. + +

    Running time: O(1) actual

    +

    +

    + +
    Returns:
    number of elements in the heap
    +
    +
    +
    + +

    +union

    +
    +public static <T> FibonacciHeap<T> union(FibonacciHeap<T> h1,
    +                                         FibonacciHeap<T> h2)
    +
    +
    Joins two Fibonacci heaps into a new one. No heap consolidation is + performed at this time. The two root lists are simply joined together. + +

    Running time: O(1) actual

    +

    +

    +
    Parameters:
    h1 - first heap
    h2 - second heap +
    Returns:
    new heap containing h1 and h2
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    Creates a String representation of this Fibonacci heap. +

    +

    +
    Overrides:
    toString in class java.lang.Object
    +
    +
    + +
    Returns:
    String of this.
    +
    +
    +
    + +

    +cascadingCut

    +
    +protected void cascadingCut(FibonacciHeapNode<T> y)
    +
    +
    Performs a cascading cut operation. This cuts y from its parent and then + does the same for its parent, and so on up the tree. + +

    Running time: O(log n); O(1) excluding the recursion

    +

    +

    +
    Parameters:
    y - node to perform cascading cut on
    +
    +
    +
    + +

    +consolidate

    +
    +protected void consolidate()
    +
    +
    +
    +
    +
    +
    + +

    +cut

    +
    +protected void cut(FibonacciHeapNode<T> x,
    +                   FibonacciHeapNode<T> y)
    +
    +
    The reverse of the link operation: removes x from the child list of y. + This method assumes that min is non-null. + +

    Running time: O(1)

    +

    +

    +
    Parameters:
    x - child of y to be removed from y's child list
    y - parent of x about to lose a child
    +
    +
    +
    + +

    +link

    +
    +protected void link(FibonacciHeapNode<T> y,
    +                    FibonacciHeapNode<T> x)
    +
    +
    Make node y a child of node x. + +

    Running time: O(1) actual

    +

    +

    +
    Parameters:
    y - node to become child
    x - node to become parent
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/FibonacciHeapNode.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/FibonacciHeapNode.html new file mode 100644 index 00000000..856f36fb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/FibonacciHeapNode.html @@ -0,0 +1,316 @@ + + + + + + +FibonacciHeapNode (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class FibonacciHeapNode<T>

    +
    +java.lang.Object
    +  extended by org.jgrapht.util.FibonacciHeapNode<T>
    +
    +
    +
    +
    public class FibonacciHeapNode<T>
    extends java.lang.Object
    + + +

    +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). +

    + +

    +

    +
    Author:
    +
    Nathan Fiedler
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    FibonacciHeapNode(T data, + double key) + +
    +          Default constructor.
    +  + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + TgetData() + +
    +          Obtain the data for this node.
    + doublegetKey() + +
    +          Obtain the key for this node.
    + java.lang.StringtoString() + +
    +          Return the string representation of this object.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +FibonacciHeapNode

    +
    +public FibonacciHeapNode(T data,
    +                         double key)
    +
    +
    Default constructor. Initializes the right and left pointers, making this + a circular doubly-linked list. +

    +

    +
    Parameters:
    data - data for this node
    key - initial key for node
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getKey

    +
    +public final double getKey()
    +
    +
    Obtain the key for this node. +

    +

    + +
    Returns:
    the key
    +
    +
    +
    + +

    +getData

    +
    +public final T getData()
    +
    +
    Obtain the data for this node. +

    +

    +
    +
    +
    +
    + +

    +toString

    +
    +public java.lang.String toString()
    +
    +
    Return the string representation of this object. +

    +

    +
    Overrides:
    toString in class java.lang.Object
    +
    +
    + +
    Returns:
    string representing this object
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/MathUtil.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/MathUtil.html new file mode 100644 index 00000000..85bfe19e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/MathUtil.html @@ -0,0 +1,261 @@ + + + + + + +MathUtil (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class MathUtil

    +
    +java.lang.Object
    +  extended by org.jgrapht.util.MathUtil
    +
    +
    +
    +
    public class MathUtil
    extends java.lang.Object
    + + +

    +Math Utilities. Currently contains the following: +

  • factorial(int N) - caclulate the factorial of N (aka N!) +

    + +

    +

    +
    Since:
    +
    May 30, 2005
    +
    Author:
    +
    Assaf
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    MathUtil() + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    +static longfactorial(int N) + +
    +           
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +MathUtil

    +
    +public MathUtil()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +factorial

    +
    +public static long factorial(int N)
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/ModifiableInteger.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/ModifiableInteger.html new file mode 100644 index 00000000..075ab756 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/ModifiableInteger.html @@ -0,0 +1,705 @@ + + + + + + +ModifiableInteger (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class ModifiableInteger

    +
    +java.lang.Object
    +  extended by java.lang.Number
    +      extended by org.jgrapht.util.ModifiableInteger
    +
    +
    +
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable
    +
    +
    +
    +
    public class ModifiableInteger
    extends java.lang.Number
    implements java.lang.Comparable
    + + +

    +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.

    +

    + +

    +

    +
    Since:
    +
    May 27, 2004
    +
    Author:
    +
    Barak Naveh
    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + +
    +Field Summary
    + intvalue + +
    +          The int value represented by this ModifiableInteger.
    +  + + + + + + + + + + + + + +
    +Constructor Summary
    ModifiableInteger() + +
    +          Deprecated. not really deprecated, just marked so to avoid mistaken use.
    ModifiableInteger(int value) + +
    +          Constructs a newly allocated ModifiableInteger object that + represents the specified int value.
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + intcompareTo(ModifiableInteger anotherInteger) + +
    +          Compares two ModifiableInteger objects numerically.
    + intcompareTo(java.lang.Object o) + +
    +          Compares this ModifiableInteger object to another object.
    + voiddecrement() + +
    +          Subtracts one from the value of this modifiable integer.
    + doubledoubleValue() + +
    +           
    + booleanequals(java.lang.Object o) + +
    +          Compares this object to the specified object.
    + floatfloatValue() + +
    +           
    + intgetValue() + +
    +          Returns the value of this object, similarly to intValue().
    + inthashCode() + +
    +          Returns a hash code for this ModifiableInteger.
    + voidincrement() + +
    +          Adds one to the value of this modifiable integer.
    + intintValue() + +
    +           
    + longlongValue() + +
    +           
    + voidsetValue(int value) + +
    +          Sets a new value for this modifiable integer.
    + java.lang.IntegertoInteger() + +
    +          Returns an Integer object representing this + ModifiableInteger's value.
    + java.lang.StringtoString() + +
    +          Returns a String object representing this + ModifiableInteger's value.
    + + + + + + + +
    Methods inherited from class java.lang.Number
    byteValue, shortValue
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +value

    +
    +public int value
    +
    +
    The int value represented by this ModifiableInteger. +

    +

    +
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +ModifiableInteger

    +
    +@Deprecated
    +public ModifiableInteger()
    +
    +
    Deprecated. not really deprecated, just marked so to avoid mistaken use. +

    +

    !!! DON'T USE - Use the ModifiableInteger(int) constructor + instead !!! + +

    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. +

    +

    +
    +
    +
    +
    +
    +
    +
    + +

    +compareTo

    +
    +public int compareTo(ModifiableInteger anotherInteger)
    +
    +
    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.
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/PrefetchIterator.NextElementFunctor.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/PrefetchIterator.NextElementFunctor.html new file mode 100644 index 00000000..9f1d171c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/PrefetchIterator.NextElementFunctor.html @@ -0,0 +1,214 @@ + + + + + + +PrefetchIterator.NextElementFunctor (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Interface PrefetchIterator.NextElementFunctor<EE>

    +
    +
    Enclosing class:
    PrefetchIterator<E>
    +
    +
    +
    +
    public static interface PrefetchIterator.NextElementFunctor<EE>
    + + +

    +


    + +

    + + + + + + + + + + + + +
    +Method Summary
    + EEnextElement() + +
    +          You must implement that NoSuchElementException is thrown on + nextElement() if it is out of bound.
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +nextElement

    +
    +EE nextElement()
    +               throws java.util.NoSuchElementException
    +
    +
    You must implement that NoSuchElementException is thrown on + nextElement() if it is out of bound. +

    +

    + +
    Throws: +
    java.util.NoSuchElementException
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/PrefetchIterator.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/PrefetchIterator.html new file mode 100644 index 00000000..4237160a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/PrefetchIterator.html @@ -0,0 +1,450 @@ + + + + + + +PrefetchIterator (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class PrefetchIterator<E>

    +
    +java.lang.Object
    +  extended by org.jgrapht.util.PrefetchIterator<E>
    +
    +
    +
    All Implemented Interfaces:
    java.util.Enumeration<E>, java.util.Iterator<E>
    +
    +
    +
    +
    public class PrefetchIterator<E>
    extends java.lang.Object
    implements java.util.Iterator<E>, java.util.Enumeration<E>
    + + +

    +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();
    +        }
    +  }
    + +

    + +

    +

    +
    Author:
    +
    Assaf_Lehr
    +
    +
    + +

    + + + + + + + + + + + +
    +Nested Class Summary
    +static interfacePrefetchIterator.NextElementFunctor<EE> + +
    +           
    +  + + + + + + + + + + +
    +Constructor Summary
    PrefetchIterator(PrefetchIterator.NextElementFunctor<E> aEnum) + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + booleanhasMoreElements() + +
    +          If (isGetNextLastResultUpToDate==true) returns true else 1.
    + booleanhasNext() + +
    +           
    + booleanisEnumerationStartedEmpty() + +
    +          Tests whether the enumeration started as an empty one.
    + Enext() + +
    +           
    + EnextElement() + +
    +          1.
    + voidremove() + +
    +          Always throws UnsupportedOperationException.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +PrefetchIterator

    +
    +public PrefetchIterator(PrefetchIterator.NextElementFunctor<E> aEnum)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +nextElement

    +
    +public E 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!) +

    +

    +
    Specified by:
    nextElement in interface java.util.Enumeration<E>
    +
    +
    +
    +
    +
    +
    + +

    +hasMoreElements

    +
    +public boolean hasMoreElements()
    +
    +
    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)) +

    +

    +
    +
    +
    +
    +
    +
    +
    + +

    +hasNext

    +
    +public boolean hasNext()
    +
    +
    +
    Specified by:
    hasNext in interface java.util.Iterator<E>
    +
    +
    +
    +
    +
    +
    + +

    +next

    +
    +public E next()
    +
    +
    +
    Specified by:
    next in interface java.util.Iterator<E>
    +
    +
    +
    +
    +
    +
    + +

    +remove

    +
    +public void remove()
    +            throws java.lang.UnsupportedOperationException
    +
    +
    Always throws UnsupportedOperationException. +

    +

    +
    Specified by:
    remove in interface java.util.Iterator<E>
    +
    +
    + +
    Throws: +
    java.lang.UnsupportedOperationException
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/TypeUtil.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/TypeUtil.html new file mode 100644 index 00000000..2caae516 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/TypeUtil.html @@ -0,0 +1,272 @@ + + + + + + +TypeUtil (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Class TypeUtil<T>

    +
    +java.lang.Object
    +  extended by org.jgrapht.util.TypeUtil<T>
    +
    +
    +
    +
    public class TypeUtil<T>
    extends java.lang.Object
    + + +

    +TypeUtil isolates type-unsafety so that code that which uses it for + legitimate reasons can stay warning-free. +

    + +

    +

    +
    Author:
    +
    John V. Sichi
    +
    +
    + +

    + + + + + + + + + + + +
    +Constructor Summary
    TypeUtil() + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    +static + + + + +
    +<T> T
    +
    uncheckedCast(java.lang.Object o, + TypeUtil<T> typeDecl) + +
    +          Casts an object to a type.
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +TypeUtil

    +
    +public TypeUtil()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +uncheckedCast

    +
    +public static <T> T uncheckedCast(java.lang.Object o,
    +                                  TypeUtil<T> typeDecl)
    +
    +
    Casts an object to a type. +

    +

    +
    Parameters:
    o - object to be cast
    typeDecl - conveys the target type information; the actual value is + unused and can be null since this is all just stupid compiler tricks +
    Returns:
    the result of the cast
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/WeightCombiner.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/WeightCombiner.html new file mode 100644 index 00000000..9a3e72b7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/WeightCombiner.html @@ -0,0 +1,331 @@ + + + + + + +WeightCombiner (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +org.jgrapht.util +
    +Interface WeightCombiner

    +
    +
    +
    public interface WeightCombiner
    + + +

    +Binary operator for edge weights. There are some prewritten operators. +

    + +

    +


    + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Field Summary
    +static WeightCombinerFIRST + +
    +          First weight.
    +static WeightCombinerMAX + +
    +          Maximum weight.
    +static WeightCombinerMIN + +
    +          Minimum weight.
    +static WeightCombinerSECOND + +
    +          Second weight.
    +static WeightCombinerSUM + +
    +          Sum of weights.
    +  + + + + + + + + + + + +
    +Method Summary
    + doublecombine(double a, + double b) + +
    +          Combines two weights.
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +SUM

    +
    +static final WeightCombiner SUM
    +
    +
    Sum of weights. +

    +

    +
    +
    +
    + +

    +MIN

    +
    +static final WeightCombiner MIN
    +
    +
    Minimum weight. +

    +

    +
    +
    +
    + +

    +MAX

    +
    +static final WeightCombiner MAX
    +
    +
    Maximum weight. +

    +

    +
    +
    +
    + +

    +FIRST

    +
    +static final WeightCombiner FIRST
    +
    +
    First weight. +

    +

    +
    +
    +
    + +

    +SECOND

    +
    +static final WeightCombiner SECOND
    +
    +
    Second weight. +

    +

    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +combine

    +
    +double combine(double a,
    +               double b)
    +
    +
    Combines two weights. +

    +

    +
    Parameters:
    a - first weight
    b - second weight +
    Returns:
    result of the operator
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-frame.html new file mode 100644 index 00000000..04d31d55 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-frame.html @@ -0,0 +1,57 @@ + + + + + + +org.jgrapht.util (JGraphT : a free Java graph library) + + + + + + + + + + + +org.jgrapht.util + + + + +
    +Interfaces  + +
    +PrefetchIterator.NextElementFunctor +
    +WeightCombiner
    + + + + + + +
    +Classes  + +
    +ArrayUnenforcedSet +
    +FibonacciHeap +
    +FibonacciHeapNode +
    +MathUtil +
    +ModifiableInteger +
    +PrefetchIterator +
    +TypeUtil
    + + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-summary.html new file mode 100644 index 00000000..0fe7cb29 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-summary.html @@ -0,0 +1,219 @@ + + + + + + +org.jgrapht.util (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package org.jgrapht.util +

    +Non-graph-specific data structures, algorithms, and utilities used by +JGraphT. +

    +See: +
    +          Description +

    + + + + + + + + + + + + + +
    +Interface Summary
    PrefetchIterator.NextElementFunctor<EE> 
    WeightCombinerBinary operator for edge weights.
    +  + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Class Summary
    ArrayUnenforcedSet<E>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.
    FibonacciHeap<T>This class implements a Fibonacci heap data structure.
    FibonacciHeapNode<T>Implements a node of the Fibonacci heap.
    MathUtilMath Utilities.
    ModifiableIntegerThe ModifiableInteger class wraps a value of the primitive type + int in an object, similarly to Integer.
    PrefetchIterator<E>Utility class to help implement an iterator/enumerator in which the hasNext() + method needs to calculate the next elements ahead of time.
    TypeUtil<T>TypeUtil isolates type-unsafety so that code that which uses it for + legitimate reasons can stay warning-free.
    +  + +

    +

    +Package org.jgrapht.util Description +

    + +

    +Non-graph-specific data structures, algorithms, and utilities used by +JGraphT. +

    + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-tree.html new file mode 100644 index 00000000..f325a1b1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/org/jgrapht/util/package-tree.html @@ -0,0 +1,171 @@ + + + + + + +org.jgrapht.util Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package org.jgrapht.util +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    +
      +
    • java.lang.Object
        +
      • java.util.AbstractCollection<E> (implements java.util.Collection<E>) +
          +
        • java.util.AbstractList<E> (implements java.util.List<E>) +
            +
          • java.util.ArrayList<E> (implements java.lang.Cloneable, java.util.List<E>, java.util.RandomAccess, java.io.Serializable) + +
          +
        +
      • org.jgrapht.util.FibonacciHeap<T>
      • org.jgrapht.util.FibonacciHeapNode<T>
      • org.jgrapht.util.MathUtil
      • java.lang.Number (implements java.io.Serializable) + +
      • org.jgrapht.util.PrefetchIterator<E> (implements java.util.Enumeration<E>, java.util.Iterator<E>) +
      • org.jgrapht.util.TypeUtil<T>
      +
    +

    +Interface Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-frame.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-frame.html new file mode 100644 index 00000000..6a8262be --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-frame.html @@ -0,0 +1,60 @@ + + + + + + +Overview List (JGraphT : a free Java graph library) + + + + + + + + + + + + + + + +
    +
    + + + + + +
    All Classes +

    + +Packages +
    +org.jgrapht +
    +org.jgrapht.alg +
    +org.jgrapht.alg.util +
    +org.jgrapht.demo +
    +org.jgrapht.event +
    +org.jgrapht.ext +
    +org.jgrapht.generate +
    +org.jgrapht.graph +
    +org.jgrapht.traverse +
    +org.jgrapht.util +
    +

    + +

    +  + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-summary.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-summary.html new file mode 100644 index 00000000..dedd3bb8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-summary.html @@ -0,0 +1,208 @@ + + + + + + +Overview (JGraphT : a free Java graph library) + + + + + + + + + + + + +


    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +JGraphT is a free Java class library that provides mathematical graph-theory +objects and algorithms. +

    +See: +
    +          Description +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Packages
    org.jgraphtThe front-end API's interfaces and classes, including Graph, +DirectedGraph and UndirectedGraph.
    org.jgrapht.algAlgorithms provided with JGraphT.
    org.jgrapht.alg.utilUtilities used by JGraphT algorithms.
    org.jgrapht.demoDemo programs that help to get started with JGraphT.
    org.jgrapht.eventEvent classes and listener interfaces, used to provide a change +notification mechanism on graph modification events.
    org.jgrapht.ext +Extensions and integration means to other products.
    org.jgrapht.generateGenerators for graphs of various topologies.
    org.jgrapht.graphImplementations of various graphs.
    org.jgrapht.traverseGraph traversal means.
    org.jgrapht.utilNon-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. +

    +Visit http://jgrapht.sourceforge.net +to download and to get the latest info on JGraphT. +

    + +

    +


    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-tree.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-tree.html new file mode 100644 index 00000000..49fdaa98 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/overview-tree.html @@ -0,0 +1,320 @@ + + + + + + +Class Hierarchy (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For All Packages

    +
    +
    +
    Package Hierarchies:
    org.jgrapht, org.jgrapht.alg, org.jgrapht.alg.util, org.jgrapht.demo, org.jgrapht.event, org.jgrapht.ext, org.jgrapht.generate, org.jgrapht.graph, org.jgrapht.traverse, org.jgrapht.util
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    + +

    +Enum Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/package-list b/ss2010/gdi2/java/libs/jgrapht/javadoc/package-list new file mode 100644 index 00000000..4bcc1d68 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/package-list @@ -0,0 +1,10 @@ +org.jgrapht +org.jgrapht.alg +org.jgrapht.alg.util +org.jgrapht.demo +org.jgrapht.event +org.jgrapht.ext +org.jgrapht.generate +org.jgrapht.graph +org.jgrapht.traverse +org.jgrapht.util diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/resources/inherit.gif b/ss2010/gdi2/java/libs/jgrapht/javadoc/resources/inherit.gif new file mode 100644 index 00000000..c814867a Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/javadoc/resources/inherit.gif differ diff --git a/ss2010/gdi2/java/libs/jgrapht/javadoc/serialized-form.html b/ss2010/gdi2/java/libs/jgrapht/javadoc/serialized-form.html new file mode 100644 index 00000000..fb8b65d3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/javadoc/serialized-form.html @@ -0,0 +1,1558 @@ + + + + + + +Serialized Form (JGraphT : a free Java graph library) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Serialized Form

    +
    +
    + + + + + +
    +Package org.jgrapht.alg
    + +

    + + + + + +
    +Class org.jgrapht.alg.BlockCutpointGraph extends SimpleGraph<UndirectedGraph<V,E>,DefaultEdge> implements Serializable
    + +

    +serialVersionUID: -9101341117013163934L + +

    + + + + + +
    +Serialized Fields
    + +

    +cutpoints

    +
    +java.util.Set<E> cutpoints
    +
    +
    +
    +
    +
    +

    +dfsTree

    +
    +DirectedGraph<V,E> dfsTree
    +
    +
    DFS (Depth-First-Search) tree. +

    +

    +
    +
    +
    +

    +graph

    +
    +UndirectedGraph<V,E> graph
    +
    +
    +
    +
    +
    +

    +numOrder

    +
    +int numOrder
    +
    +
    +
    +
    +
    +

    +stack

    +
    +java.util.Deque<E> stack
    +
    +
    +
    +
    +
    +

    +vertex2biconnectedSubgraphs

    +
    +java.util.Map<K,V> vertex2biconnectedSubgraphs
    +
    +
    +
    +
    +
    +

    +vertex2block

    +
    +java.util.Map<K,V> vertex2block
    +
    +
    +
    +
    +
    +

    +vertex2numOrder

    +
    +java.util.Map<K,V> vertex2numOrder
    +
    +
    +
    +
    +
    + + + + + +
    +Package org.jgrapht.demo
    + +

    + + + + + +
    +Class org.jgrapht.demo.JGraphAdapterDemo extends javax.swing.JApplet implements Serializable
    + +

    +serialVersionUID: 3256444702936019250L + +

    + + + + + +
    +Serialized Fields
    + +

    +jgAdapter

    +
    +JGraphModelAdapter<V,E> jgAdapter
    +
    +
    +
    +
    +
    + + + + + +
    +Package org.jgrapht.event
    + +

    + + + + + +
    +Class org.jgrapht.event.ConnectedComponentTraversalEvent extends java.util.EventObject implements Serializable
    + +

    +serialVersionUID: 3834311717709822262L + +

    + + + + + +
    +Serialized Fields
    + +

    +type

    +
    +int type
    +
    +
    The type of this event. +

    +

    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.event.EdgeTraversalEvent extends java.util.EventObject implements Serializable
    + +

    +serialVersionUID: 4050768173789820979L + +

    + + + + + +
    +Serialized Fields
    + +

    +edge

    +
    +java.lang.Object edge
    +
    +
    The traversed edge. +

    +

    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.event.GraphChangeEvent extends java.util.EventObject implements Serializable
    + +

    +serialVersionUID: 3834592106026382391L + +

    + + + + + +
    +Serialized Fields
    + +

    +type

    +
    +int type
    +
    +
    The type of graph change this event indicates. +

    +

    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.event.GraphEdgeChangeEvent extends GraphChangeEvent implements Serializable
    + +

    +serialVersionUID: 3618134563335844662L + +

    + + + + + +
    +Serialized Fields
    + +

    +edge

    +
    +java.lang.Object edge
    +
    +
    The edge that this event is related to. +

    +

    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.event.GraphVertexChangeEvent extends GraphChangeEvent implements Serializable
    + +

    +serialVersionUID: 3690189962679104053L + +

    + + + + + +
    +Serialized Fields
    + +

    +vertex

    +
    +java.lang.Object vertex
    +
    +
    The vertex that this event is related to. +

    +

    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.event.VertexTraversalEvent extends java.util.EventObject implements Serializable
    + +

    +serialVersionUID: 3688790267213918768L + +

    + + + + + +
    +Serialized Fields
    + +

    +vertex

    +
    +java.lang.Object vertex
    +
    +
    The traversed vertex. +

    +

    +
    +
    +
    + + + + + +
    +Package org.jgrapht.ext
    + +

    + + + + + +
    +Class org.jgrapht.ext.JGraphModelAdapter extends org.jgraph.graph.DefaultGraphModel implements Serializable
    + +

    +serialVersionUID: 3256722883706302515L + +

    + + + + + +
    +Serialized Fields
    + +

    +jCellsBeingAdded

    +
    +java.util.Set<E> jCellsBeingAdded
    +
    +
    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...

    +

    +

    +
    +
    +
    +

    +jCellsBeingRemoved

    +
    +java.util.Set<E> jCellsBeingRemoved
    +
    +
    +
    +
    +
    +

    +jtElementsBeingAdded

    +
    +java.util.Set<E> jtElementsBeingAdded
    +
    +
    +
    +
    +
    +

    +jtElementsBeingRemoved

    +
    +java.util.Set<E> jtElementsBeingRemoved
    +
    +
    +
    +
    +
    +

    +cellFactory

    +
    +JGraphModelAdapter.CellFactory<VV,EE> cellFactory
    +
    +
    +
    +
    +
    +

    +cellToEdge

    +
    +java.util.Map<K,V> cellToEdge
    +
    +
    Maps JGraph edges to JGraphT edges +

    +

    +
    +
    +
    +

    +cellToVertex

    +
    +java.util.Map<K,V> cellToVertex
    +
    +
    Maps JGraph vertices to JGraphT vertices +

    +

    +
    +
    +
    +

    +defaultEdgeAttributes

    +
    +org.jgraph.graph.AttributeMap defaultEdgeAttributes
    +
    +
    +
    +
    +
    +

    +defaultVertexAttributes

    +
    +org.jgraph.graph.AttributeMap defaultVertexAttributes
    +
    +
    +
    +
    +
    +

    +edgeToCell

    +
    +java.util.Map<K,V> edgeToCell
    +
    +
    Maps JGraphT edges to JGraph edges +

    +

    +
    +
    +
    +

    +vertexToCell

    +
    +java.util.Map<K,V> vertexToCell
    +
    +
    Maps JGraphT vertices to JGraph vertices +

    +

    +
    +
    +
    +

    +jtGraph

    +
    +org.jgrapht.ext.JGraphModelAdapter.ShieldedGraph jtGraph
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.ext.JGraphModelAdapter.DefaultCellFactory extends java.lang.Object implements Serializable
    + +

    +serialVersionUID: 3690194343461861173L + +

    +


    + + + + + +
    +Package org.jgrapht.graph
    + +

    + + + + + +
    +Class org.jgrapht.graph.AbstractBaseGraph extends AbstractGraph<V,E> implements Serializable
    + +

    +serialVersionUID: -1263088497616142427L + +

    + + + + + +
    +Serialized Fields
    + +

    +allowingLoops

    +
    +boolean allowingLoops
    +
    +
    +
    +
    +
    +

    +edgeFactory

    +
    +EdgeFactory<V,E> edgeFactory
    +
    +
    +
    +
    +
    +

    +edgeSetFactory

    +
    +EdgeSetFactory<V,E> edgeSetFactory
    +
    +
    +
    +
    +
    +

    +edgeMap

    +
    +java.util.Map<K,V> edgeMap
    +
    +
    +
    +
    +
    +

    +specifics

    +
    +org.jgrapht.graph.AbstractBaseGraph.Specifics specifics
    +
    +
    +
    +
    +
    +

    +allowingMultipleEdges

    +
    +boolean allowingMultipleEdges
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.AsUndirectedGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: 3257845485078065462L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.AsUnweightedDirectedGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: -4320818446777715312L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.AsUnweightedGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: 7175505077601824663L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.AsWeightedGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: -716810639338971372L + +

    + + + + + +
    +Serialized Fields
    + +

    +weightMap

    +
    +java.util.Map<K,V> weightMap
    +
    +
    +
    +
    +
    +

    +isWeightedGraph

    +
    +boolean isWeightedGraph
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.ClassBasedEdgeFactory extends java.lang.Object implements Serializable
    + +

    +serialVersionUID: 3618135658586388792L + +

    + + + + + +
    +Serialized Fields
    + +

    +edgeClass

    +
    +java.lang.Class<T> edgeClass
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.DefaultDirectedGraph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3544953246956466230L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DefaultDirectedWeightedGraph extends DefaultDirectedGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3761405317841171513L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DefaultEdge extends org.jgrapht.graph.IntrusiveEdge implements Serializable
    + +

    +serialVersionUID: 3258408452177932855L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DefaultListenableGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: 3977575900898471984L + +

    + + + + + +
    +Serialized Fields
    + +

    +graphListeners

    +
    +java.util.ArrayList<E> graphListeners
    +
    +
    +
    +
    +
    +

    +vertexSetListeners

    +
    +java.util.ArrayList<E> vertexSetListeners
    +
    +
    +
    +
    +
    +

    +reuseableEdgeEvent

    +
    +org.jgrapht.graph.DefaultListenableGraph.FlyweightEdgeEvent<VV,EE> reuseableEdgeEvent
    +
    +
    +
    +
    +
    +

    +reuseableVertexEvent

    +
    +org.jgrapht.graph.DefaultListenableGraph.FlyweightVertexEvent<VV> reuseableVertexEvent
    +
    +
    +
    +
    +
    +

    +reuseEvents

    +
    +boolean reuseEvents
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.DefaultWeightedEdge extends DefaultEdge implements Serializable
    + +

    +serialVersionUID: 229708706467350994L + +

    + + + + + +
    +Serialized Fields
    + +

    +weight

    +
    +double weight
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.DirectedGraphUnion extends GraphUnion<V,E,DirectedGraph<V,E>> implements Serializable
    + +

    +serialVersionUID: -740199233080172450L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DirectedMultigraph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3258408413590599219L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DirectedPseudograph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: -8300409752893486415L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DirectedSubgraph extends Subgraph<V,E,DirectedGraph<V,E>> implements Serializable
    + +

    +serialVersionUID: 3616445700507054133L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DirectedWeightedMultigraph extends DirectedMultigraph<V,E> implements Serializable
    + +

    +serialVersionUID: 4049071636005206066L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.DirectedWeightedSubgraph extends DirectedSubgraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3905799799168250680L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.EdgeReversedGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: 9091361782455418631L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.GraphDelegator extends AbstractGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3257005445226181425L + +

    + + + + + +
    +Serialized Fields
    + +

    +delegate

    +
    +Graph<V,E> delegate
    +
    +
    The graph to which operations are delegated. +

    +

    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.GraphUnion extends AbstractGraph<V,E> implements Serializable
    + +

    +serialVersionUID: -740199233080172450L + +

    + + + + + +
    +Serialized Fields
    + +

    +g1

    +
    +Graph<V,E> g1
    +
    +
    +
    +
    +
    +

    +g2

    +
    +Graph<V,E> g2
    +
    +
    +
    +
    +
    +

    +operator

    +
    +WeightCombiner operator
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.ListenableDirectedGraph extends DefaultListenableGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3257571698126368824L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.ListenableDirectedWeightedGraph extends ListenableDirectedGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3977582476627621938L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.ListenableUndirectedGraph extends DefaultListenableGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3256999969193145905L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.ListenableUndirectedWeightedGraph extends ListenableUndirectedGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3690762799613949747L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.Multigraph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3257001055819871795L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.ParanoidGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: 5075284167422166539L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.Pseudograph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3833183614484755253L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.SimpleDirectedGraph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 4049358608472879671L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.SimpleDirectedWeightedGraph extends SimpleDirectedGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3904960841681220919L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.SimpleGraph extends AbstractBaseGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3545796589454112304L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.SimpleWeightedGraph extends SimpleGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3906088949100655922L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.Subgraph extends AbstractGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3208313055169665387L + +

    + + + + + +
    +Serialized Fields
    + +

    +edgeSet

    +
    +java.util.Set<E> edgeSet
    +
    +
    +
    +
    +
    +

    +vertexSet

    +
    +java.util.Set<E> vertexSet
    +
    +
    +
    +
    +
    +

    +base

    +
    +Graph<V,E> base
    +
    +
    +
    +
    +
    +

    +isInduced

    +
    +boolean isInduced
    +
    +
    +
    +
    + +

    + + + + + +
    +Class org.jgrapht.graph.UndirectedGraphUnion extends GraphUnion<V,E,UndirectedGraph<V,E>> implements Serializable
    + +

    +serialVersionUID: -740199233080172450L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.UndirectedSubgraph extends Subgraph<V,E,UndirectedGraph<V,E>> implements Serializable
    + +

    +serialVersionUID: 3256728359772631350L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.UndirectedWeightedSubgraph extends UndirectedSubgraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3689346615735236409L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.UnmodifiableDirectedGraph extends UnmodifiableGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3978701783725913906L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.UnmodifiableGraph extends GraphDelegator<V,E> implements Serializable
    + +

    +serialVersionUID: 3544957670722713913L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.UnmodifiableUndirectedGraph extends UnmodifiableGraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3258134639355704624L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.WeightedMultigraph extends Multigraph<V,E> implements Serializable
    + +

    +serialVersionUID: 3544671793370640696L + +

    + +

    + + + + + +
    +Class org.jgrapht.graph.WeightedPseudograph extends Pseudograph<V,E> implements Serializable
    + +

    +serialVersionUID: 3257290244524356152L + +

    +


    + + + + + +
    +Package org.jgrapht.util
    + +

    + + + + + +
    +Class org.jgrapht.util.ArrayUnenforcedSet extends java.util.ArrayList<E> implements Serializable
    + +

    +serialVersionUID: -7413250161201811238L + +

    + +

    + + + + + +
    +Class org.jgrapht.util.ModifiableInteger extends java.lang.Number implements Serializable
    + +

    +serialVersionUID: 3618698612851422261L + +

    + + + + + +
    +Serialized Fields
    + +

    +value

    +
    +int value
    +
    +
    The int value represented by this ModifiableInteger. +

    +

    +
    +
    + +

    +


    + + + + + + + + + + + + + + + +
    + +
    + + + +
    + + + 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. + * + *

    See + * http://mathworld.wolfram.com/DirectedGraph.html for more on 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 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 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 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 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 destination, + Graph source, + Collection 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 destination, + Collection 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 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 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. + * + *

    See + * http://mathworld.wolfram.com/Graph.html for more on undirected and on + * directed 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 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(sg); + List sortedVertices = new LinkedList(sg.vertexSet()); + Collections.sort(sortedVertices, comp); + Collections.reverse(sortedVertices); + + int color; + + // Each vertex will attempted to be colored with a single color each + // iteration, and these vertices will be removed from the graph at the + // end of each iteration + for (color = 0; sg.vertexSet().size() > 0; color++) { + // This set will contain vertices that are colored with the + // current color of this iteration + Set currentColor = new HashSet(); + for ( + Iterator iter = sortedVertices.iterator(); + iter.hasNext();) + { + V v = iter.next(); + + // Add new vertices to be colored as long as they are not + // adjacent with any other vertex that has already been colored + // with the current color + boolean flag = true; + for ( + Iterator innerIter = currentColor.iterator(); + innerIter.hasNext();) + { + V temp = innerIter.next(); + if (sg.containsEdge(temp, v)) { + flag = false; + break; + } + } + if (flag) { + currentColor.add(v); + } + } + + // Remove vertices from the graph and then repeat the process for + // the next iteration + sg.removeAllVertices(currentColor); + } + return color; + } +} + +// End ChromaticNumber.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/ConnectivityInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/ConnectivityInspector.java new file mode 100644 index 00000000..a7f3ce3c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/ConnectivityInspector.java @@ -0,0 +1,302 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * ConnectivityInspector.java + * -------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): John V. Sichi + * Christian Hammer + * + * $Id: ConnectivityInspector.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Aug-2003 : Initial revision (BN); + * 10-Aug-2003 : Adaptation to new event model (BN); + * 07-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; +import org.jgrapht.graph.*; +import org.jgrapht.traverse.*; + + +/** + * 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 {@link 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 {@link org.jgrapht.event.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.

    + * + * @author Barak Naveh + * @author John V. Sichi + * @since Aug 6, 2003 + */ +public class ConnectivityInspector + implements GraphListener +{ + //~ Instance fields -------------------------------------------------------- + + List> connectedSets; + Map> vertexToConnectedSet; + private Graph graph; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a connectivity inspector for the specified undirected graph. + * + * @param g the graph for which a connectivity inspector to be created. + */ + public ConnectivityInspector(UndirectedGraph g) + { + init(); + this.graph = g; + } + + /** + * Creates a connectivity inspector for the specified directed graph. + * + * @param g the graph for which a connectivity inspector to be created. + */ + public ConnectivityInspector(DirectedGraph g) + { + init(); + this.graph = new AsUndirectedGraph(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Test if the inspected graph is connected. An empty graph is not + * considered connected. + * + * @return true if and only if inspected graph is connected. + */ + public boolean isGraphConnected() + { + return lazyFindConnectedSets().size() == 1; + } + + /** + * Returns a set of all vertices that are in the maximally connected + * component together with the specified vertex. For more on maximally + * connected component, see + * http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html. + * + * @param vertex the vertex for which the connected set to be returned. + * + * @return a set of all vertices that are in the maximally connected + * component together with the specified vertex. + */ + public Set connectedSetOf(V vertex) + { + Set connectedSet = vertexToConnectedSet.get(vertex); + + if (connectedSet == null) { + connectedSet = new HashSet(); + + BreadthFirstIterator i = + new BreadthFirstIterator(graph, vertex); + + while (i.hasNext()) { + connectedSet.add(i.next()); + } + + vertexToConnectedSet.put(vertex, connectedSet); + } + + return connectedSet; + } + + /** + * 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. + * + * @return Returns a list of Set s, where each set contains all + * vertices that are in the same maximally connected component. + */ + public List> connectedSets() + { + return lazyFindConnectedSets(); + } + + /** + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public void edgeAdded(GraphEdgeChangeEvent e) + { + init(); // for now invalidate cached results, in the future need to + // amend them. + } + + /** + * @see GraphListener#edgeRemoved(GraphEdgeChangeEvent) + */ + public void edgeRemoved(GraphEdgeChangeEvent e) + { + init(); // for now invalidate cached results, in the future need to + // amend them. + } + + /** + * 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.

    + * + * @param sourceVertex one end of the path. + * @param targetVertex another end of the path. + * + * @return true if and only if there is a path from the source + * vertex to the target vertex. + */ + public boolean pathExists(V sourceVertex, V targetVertex) + { + /* + * TODO: Ignoring edge direction for directed graph may be + * confusing. For directed graphs, consider Dijkstra's algorithm. + */ + Set sourceSet = connectedSetOf(sourceVertex); + + return sourceSet.contains(targetVertex); + } + + /** + * @see VertexSetListener#vertexAdded(GraphVertexChangeEvent) + */ + public void vertexAdded(GraphVertexChangeEvent e) + { + init(); // for now invalidate cached results, in the future need to + // amend them. + } + + /** + * @see VertexSetListener#vertexRemoved(GraphVertexChangeEvent) + */ + public void vertexRemoved(GraphVertexChangeEvent e) + { + init(); // for now invalidate cached results, in the future need to + // amend them. + } + + private void init() + { + connectedSets = null; + vertexToConnectedSet = new HashMap>(); + } + + private List> lazyFindConnectedSets() + { + if (connectedSets == null) { + connectedSets = new ArrayList>(); + + Set vertexSet = graph.vertexSet(); + + if (vertexSet.size() > 0) { + BreadthFirstIterator i = + new BreadthFirstIterator(graph, null); + i.addTraversalListener(new MyTraversalListener()); + + while (i.hasNext()) { + i.next(); + } + } + } + + return connectedSets; + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * A traversal listener that groups all vertices according to to their + * containing connected set. + * + * @author Barak Naveh + * @since Aug 6, 2003 + */ + private class MyTraversalListener + extends TraversalListenerAdapter + { + private Set currentConnectedSet; + + /** + * @see TraversalListenerAdapter#connectedComponentFinished(ConnectedComponentTraversalEvent) + */ + public void connectedComponentFinished( + ConnectedComponentTraversalEvent e) + { + connectedSets.add(currentConnectedSet); + } + + /** + * @see TraversalListenerAdapter#connectedComponentStarted(ConnectedComponentTraversalEvent) + */ + public void connectedComponentStarted( + ConnectedComponentTraversalEvent e) + { + currentConnectedSet = new HashSet(); + } + + /** + * @see TraversalListenerAdapter#vertexTraversed(VertexTraversalEvent) + */ + public void vertexTraversed(VertexTraversalEvent e) + { + V v = e.getVertex(); + currentConnectedSet.add(v); + vertexToConnectedSet.put(v, currentConnectedSet); + } + } +} + +// End ConnectivityInspector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/CycleDetector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/CycleDetector.java new file mode 100644 index 00000000..8a097970 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/CycleDetector.java @@ -0,0 +1,271 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * CycleDetector.java + * ------------------ + * (C) Copyright 2004-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): Christian Hammer + * + * $Id: CycleDetector.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sept-2004 : Initial revision (JVS); + * 07-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.traverse.*; + + +/** + * 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. + * + * @author John V. Sichi + * @since Sept 16, 2004 + */ +public class CycleDetector +{ + //~ Instance fields -------------------------------------------------------- + + /** + * Graph on which cycle detection is being performed. + */ + DirectedGraph graph; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a cycle detector for the specified graph. Currently only directed + * graphs are supported. + * + * @param graph the DirectedGraph in which to detect cycles + */ + public CycleDetector(DirectedGraph graph) + { + this.graph = graph; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Performs yes/no cycle detection on the entire graph. + * + * @return true iff the graph contains at least one cycle + */ + public boolean detectCycles() + { + try { + execute(null, null); + } catch (CycleDetectedException ex) { + return true; + } + + return false; + } + + /** + * Performs yes/no cycle detection on an individual vertex. + * + * @param v the vertex to test + * + * @return true if v is on at least one cycle + */ + public boolean detectCyclesContainingVertex(V v) + { + try { + execute(null, v); + } catch (CycleDetectedException ex) { + return true; + } + + return false; + } + + /** + * Finds the vertex set for the subgraph of all cycles. + * + * @return set of all vertices which participate in at least one cycle in + * this graph + */ + public Set findCycles() + { + // ProbeIterator can't be used to handle this case, + // so use StrongConnectivityInspector instead. + StrongConnectivityInspector inspector = + new StrongConnectivityInspector(graph); + List> components = inspector.stronglyConnectedSets(); + + // A vertex participates in a cycle if either of the following is + // true: (a) it is in a component whose size is greater than 1 + // or (b) it is a self-loop + + Set set = new HashSet(); + for (Set component : components) { + if (component.size() > 1) { + // cycle + set.addAll(component); + } else { + V v = component.iterator().next(); + if (graph.containsEdge(v, v)) { + // self-loop + set.add(v); + } + } + } + + return set; + } + + /** + * 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. + * + * @param v the vertex to test + * + * @return set of all vertices reachable from v via at least one cycle + */ + public Set findCyclesContainingVertex(V v) + { + Set set = new HashSet(); + execute(set, v); + + return set; + } + + private void execute(Set s, V v) + { + ProbeIterator iter = new ProbeIterator(s, v); + + while (iter.hasNext()) { + iter.next(); + } + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Exception thrown internally when a cycle is detected during a yes/no + * cycle test. Must be caught by top-level detection method. + */ + private static class CycleDetectedException + extends RuntimeException + { + private static final long serialVersionUID = 3834305137802950712L; + } + + /** + * Version of DFS which maintains a backtracking path used to probe for + * cycles. + */ + private class ProbeIterator + extends DepthFirstIterator + { + private List path; + private Set cycleSet; + private V root; + + ProbeIterator(Set cycleSet, V startVertex) + { + super(graph, startVertex); + root = startVertex; + this.cycleSet = cycleSet; + path = new ArrayList(); + } + + /** + * {@inheritDoc} + */ + protected void encounterVertexAgain(V vertex, E edge) + { + super.encounterVertexAgain(vertex, edge); + + int i; + + if (root != null) { + // For rooted detection, the path must either + // double back to the root, or to a node of a cycle + // which has already been detected. + if (vertex == root) { + i = 0; + } else if ((cycleSet != null) && cycleSet.contains(vertex)) { + i = 0; + } else { + return; + } + } else { + i = path.indexOf(vertex); + } + + if (i > -1) { + if (cycleSet == null) { + // we're doing yes/no cycle detection + throw new CycleDetectedException(); + } else { + for (; i < path.size(); ++i) { + cycleSet.add(path.get(i)); + } + } + } + } + + /** + * {@inheritDoc} + */ + protected V provideNextVertex() + { + V v = super.provideNextVertex(); + + // backtrack + for (int i = path.size() - 1; i >= 0; --i) { + if (graph.containsEdge(path.get(i), v)) { + break; + } + + path.remove(i); + } + + path.add(v); + + return v; + } + } +} + +// End CycleDetector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/DijkstraShortestPath.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/DijkstraShortestPath.java new file mode 100644 index 00000000..7fae1a46 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/DijkstraShortestPath.java @@ -0,0 +1,218 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * DijkstraShortestPath.java + * ------------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): Christian Hammer + * + * $Id: DijkstraShortestPath.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 02-Sep-2003 : Initial revision (JVS); + * 29-May-2005 : Make non-static and add radius support (JVS); + * 07-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; +import org.jgrapht.traverse.*; + + +/** + * An implementation of Dijkstra's + * shortest path algorithm using ClosestFirstIterator. + * + * @author John V. Sichi + * @since Sep 2, 2003 + */ +public final class DijkstraShortestPath +{ + //~ Instance fields -------------------------------------------------------- + + private GraphPath path; + + //~ Constructors ----------------------------------------------------------- + + /** + * 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. + * + * @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 + */ + public DijkstraShortestPath(Graph graph, + V startVertex, + V endVertex) + { + this(graph, startVertex, endVertex, Double.POSITIVE_INFINITY); + } + + /** + * 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. + * + * @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 + * @param radius limit on path length, or Double.POSITIVE_INFINITY for + * unbounded search + */ + public DijkstraShortestPath( + Graph graph, + V startVertex, + V endVertex, + double radius) + { + if (!graph.containsVertex(endVertex)) { + throw new IllegalArgumentException( + "graph must contain the end vertex"); + } + + ClosestFirstIterator iter = + new ClosestFirstIterator(graph, startVertex, radius); + + while (iter.hasNext()) { + V vertex = iter.next(); + + if (vertex.equals(endVertex)) { + createEdgeList(graph, iter, startVertex, endVertex); + return; + } + } + + path = null; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Return the edges making up the path found. + * + * @return List of Edges, or null if no path exists + */ + public List getPathEdgeList() + { + if (path == null) { + return null; + } else { + return path.getEdgeList(); + } + } + + /** + * Return the path found. + * + * @return path representation, or null if no path exists + */ + public GraphPath getPath() + { + return path; + } + + /** + * Return the length of the path found. + * + * @return path length, or Double.POSITIVE_INFINITY if no path exists + */ + public double getPathLength() + { + if (path == null) { + return Double.POSITIVE_INFINITY; + } else { + return path.getWeight(); + } + } + + /** + * 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. + * + * @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) + { + DijkstraShortestPath alg = + new DijkstraShortestPath( + graph, + startVertex, + endVertex); + + return alg.getPathEdgeList(); + } + + private void createEdgeList( + Graph graph, + ClosestFirstIterator iter, + V startVertex, + V endVertex) + { + List edgeList = new ArrayList(); + + V v = endVertex; + + while (true) { + E edge = iter.getSpanningTreeEdge(v); + + if (edge == null) { + break; + } + + edgeList.add(edge); + v = Graphs.getOppositeVertex(graph, edge, v); + } + + Collections.reverse(edgeList); + double pathLength = iter.getShortestPathLength(endVertex); + path = + new GraphPathImpl( + graph, + startVertex, + endVertex, + edgeList, + pathLength); + } +} + +// End DijkstraShortestPath.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/DirectedNeighborIndex.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/DirectedNeighborIndex.java new file mode 100644 index 00000000..98792356 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/DirectedNeighborIndex.java @@ -0,0 +1,233 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * DirectedNeighborIndex.java + * -------------------------- + * (C) Copyright 2005-2008, by Charles Fry and Contributors. + * + * Original Author: Charles Fry + * + * $Id: DirectedNeighborIndex.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Dec-2005 : Initial revision (CF); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.alg.NeighborIndex.*; +import org.jgrapht.event.*; + + +/** + * Maintains a cache of each vertex's neighbors. While lists of neighbors can be + * obtained from {@link 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.

    + * + * @author Charles Fry + * @since Dec 13, 2005 + */ +public class DirectedNeighborIndex + implements GraphListener +{ + //~ Instance fields -------------------------------------------------------- + + Map> predecessorMap = new HashMap>(); + Map> successorMap = new HashMap>(); + private DirectedGraph graph; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a neighbor index for the specified directed graph. + * + * @param g the graph for which a neighbor index is to be created. + */ + public DirectedNeighborIndex(DirectedGraph g) + { + graph = g; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * 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. + * + * @param v the vertex whose predecessors are desired + * + * @return all unique predecessors of the specified vertex + */ + public Set predecessorsOf(V v) + { + return getPredecessors(v).getNeighbors(); + } + + /** + * 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 + * {@link #predecessorsOf(Object)} unless duplicate neighbors are required. + * + * @param v the vertex whose predecessors are desired + * + * @return all predecessors of the specified vertex + */ + public List predecessorListOf(V v) + { + return getPredecessors(v).getNeighborList(); + } + + /** + * 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. + * + * @param v the vertex whose successors are desired + * + * @return all unique successors of the specified vertex + */ + public Set successorsOf(V v) + { + return getSuccessors(v).getNeighbors(); + } + + /** + * 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 {@link + * #successorsOf(Object)} unless duplicate neighbors are required. + * + * @param v the vertex whose successors are desired + * + * @return all successors of the specified vertex + */ + public List successorListOf(V v) + { + return getSuccessors(v).getNeighborList(); + } + + /** + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public void edgeAdded(GraphEdgeChangeEvent e) + { + E edge = e.getEdge(); + V source = graph.getEdgeSource(edge); + V target = graph.getEdgeTarget(edge); + + // if a map does not already contain an entry, + // then skip addNeighbor, since instantiating the map + // will take care of processing the edge (which has already + // been added) + + if (successorMap.containsKey(source)) { + getSuccessors(source).addNeighbor(target); + } else { + getSuccessors(source); + } + if (predecessorMap.containsKey(target)) { + getPredecessors(target).addNeighbor(source); + } else { + getPredecessors(target); + } + } + + /** + * @see GraphListener#edgeRemoved(GraphEdgeChangeEvent) + */ + public void edgeRemoved(GraphEdgeChangeEvent e) + { + E edge = e.getEdge(); + V source = graph.getEdgeSource(edge); + V target = graph.getEdgeTarget(edge); + if (successorMap.containsKey(source)) { + successorMap.get(source).removeNeighbor(target); + } + if (predecessorMap.containsKey(target)) { + predecessorMap.get(target).removeNeighbor(source); + } + } + + /** + * @see VertexSetListener#vertexAdded(GraphVertexChangeEvent) + */ + public void vertexAdded(GraphVertexChangeEvent e) + { + // nothing to cache until there are edges + } + + /** + * @see VertexSetListener#vertexRemoved(GraphVertexChangeEvent) + */ + public void vertexRemoved(GraphVertexChangeEvent e) + { + predecessorMap.remove(e.getVertex()); + successorMap.remove(e.getVertex()); + } + + private Neighbors getPredecessors(V v) + { + Neighbors neighbors = predecessorMap.get(v); + if (neighbors == null) { + neighbors = + new Neighbors(v, + Graphs.predecessorListOf(graph, v)); + predecessorMap.put(v, neighbors); + } + return neighbors; + } + + private Neighbors getSuccessors(V v) + { + Neighbors neighbors = successorMap.get(v); + if (neighbors == null) { + neighbors = + new Neighbors(v, + Graphs.successorListOf(graph, v)); + successorMap.put(v, neighbors); + } + return neighbors; + } +} + +// End DirectedNeighborIndex.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/EdmondsKarpMaximumFlow.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/EdmondsKarpMaximumFlow.java new file mode 100644 index 00000000..d3385598 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/EdmondsKarpMaximumFlow.java @@ -0,0 +1,361 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EdmondsKarpMaximumFlow.java + * ----------------- + * (C) Copyright 2008-2008, by Ilya Razenshteyn and Contributors. + * + * Original Author: Ilya Razenshteyn + * Contributor(s): - + * + * $Id: EdmondsKarpMaximumFlow.java 628 2008-08-17 12:00:59Z ilyaraz $ + * + * Changes + * ------- + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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). + */ +public final class EdmondsKarpMaximumFlow +{ + //~ Static fields/initializers --------------------------------------------- + + /** + * Default tolerance. + */ + public static final double DEFAULT_EPSILON = 0.000000001; + + //~ Instance fields -------------------------------------------------------- + + private DirectedGraph network; // our network + private double epsilon; // tolerance (DEFAULT_EPSILON or user-defined) + private int currentSource; // current source vertex + private int currentSink; // current sink vertex + private Map maximumFlow; // current maximum flow + private Double maximumFlowValue; // current maximum flow value + private int numNodes; // number of nodes in the network + private Map indexer; // mapping from vertices to their indexes + // in the internal representation + private List nodes; // internal representation of the network + + //~ Constructors ----------------------------------------------------------- + + /** + * 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. + * + * @param network network, where maximum flow will be calculated + */ + public EdmondsKarpMaximumFlow(DirectedGraph network) + { + this(network, DEFAULT_EPSILON); + } + + /** + * 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. + * + * @param network network, where maximum flow will be calculated + * @param epsilon tolerance for comparing doubles + */ + public EdmondsKarpMaximumFlow(DirectedGraph network, + double epsilon) + { + if (network == null) { + throw new NullPointerException("network is null"); + } + if (epsilon <= 0) { + throw new IllegalArgumentException( + "invalid epsilon (must be positive)"); + } + for (E e : network.edgeSet()) { + if (network.getEdgeWeight(e) < -epsilon) { + throw new IllegalArgumentException( + "invalid capacity (must be non-negative)"); + } + } + + this.network = network; + this.epsilon = epsilon; + + currentSource = -1; + currentSink = -1; + maximumFlow = null; + maximumFlowValue = null; + + buildInternalNetwork(); + } + + //~ Methods ---------------------------------------------------------------- + + // converting the original network into internal more convenient format + private void buildInternalNetwork() + { + numNodes = network.vertexSet().size(); + nodes = new ArrayList(); + Iterator it = network.vertexSet().iterator(); + indexer = new HashMap(); + for (int i = 0; i < numNodes; i++) { + V currentNode = it.next(); + nodes.add(new Node(currentNode)); + indexer.put(currentNode, i); + } + for (int i = 0; i < numNodes; i++) { + V we = nodes.get(i).prototype; + for (E e : network.outgoingEdgesOf(we)) { + V he = network.getEdgeTarget(e); + int j = indexer.get(he); + Arc e1 = new Arc(i, j, network.getEdgeWeight(e), e); + Arc e2 = new Arc(j, i, 0.0, null); + e1.reversed = e2; + e2.reversed = e1; + nodes.get(i).outgoingArcs.add(e1); + nodes.get(j).outgoingArcs.add(e2); + } + } + } + + /** + * 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. + * + * @param source source vertex + * @param sink sink vertex + */ + public void calculateMaximumFlow( + V source, + V sink) + { + if (!network.containsVertex(source)) { + throw new IllegalArgumentException( + "invalid source (null or not from this network)"); + } + if (!network.containsVertex(sink)) { + throw new IllegalArgumentException( + "invalid sink (null or not from this network)"); + } + + if (source.equals(sink)) { + throw new IllegalArgumentException("source is equal to sink"); + } + + currentSource = indexer.get(source); + currentSink = indexer.get(sink); + + for (int i = 0; i < numNodes; i++) { + for (Arc currentArc : nodes.get(i).outgoingArcs) { + currentArc.flow = 0.0; + } + } + maximumFlowValue = 0.0; + for (;;) { + breadthFirstSearch(); + if (!nodes.get(currentSink).visited) { + maximumFlow = new HashMap(); + for (int i = 0; i < numNodes; i++) { + for (Arc currentArc : nodes.get(i).outgoingArcs) { + if (currentArc.prototype != null) { + maximumFlow.put( + currentArc.prototype, + currentArc.flow); + } + } + } + return; + } + augmentFlow(); + } + } + + private void breadthFirstSearch() + { + for (int i = 0; i < numNodes; i++) { + nodes.get(i).visited = false; + } + Queue queue = new LinkedList(); + queue.offer(currentSource); + nodes.get(currentSource).visited = true; + nodes.get(currentSource).flowAmount = Double.POSITIVE_INFINITY; + while (queue.size() != 0) { + int currentNode = queue.poll(); + for (Arc currentArc : nodes.get(currentNode).outgoingArcs) { + if ((currentArc.flow + epsilon) < currentArc.capacity) { + if (!nodes.get(currentArc.head).visited) { + nodes.get(currentArc.head).visited = true; + nodes.get(currentArc.head).flowAmount = + Math.min( + nodes.get(currentNode).flowAmount, + currentArc.capacity - currentArc.flow); + nodes.get(currentArc.head).lastArc = currentArc; + queue.add(currentArc.head); + } + } + } + } + } + + private void augmentFlow() + { + double deltaFlow = nodes.get(currentSink).flowAmount; + maximumFlowValue += deltaFlow; + int currentNode = currentSink; + while (currentNode != currentSource) { + nodes.get(currentNode).lastArc.flow += deltaFlow; + nodes.get(currentNode).lastArc.reversed.flow -= deltaFlow; + currentNode = nodes.get(currentNode).lastArc.tail; + } + } + + /** + * Returns maximum flow value, that was calculated during last + * calculateMaximumFlow call, or null, if there was no + * calculateMaximumFlow calls. + * + * @return maximum flow value + */ + public Double getMaximumFlowValue() + { + return maximumFlowValue; + } + + /** + * Returns maximum flow, that was calculated during last + * calculateMaximumFlow call, or null, if there was no + * calculateMaximumFlow calls. + * + * @return read-only mapping from edges to doubles - flow values + */ + public Map getMaximumFlow() + { + if (maximumFlow == null) { + return null; + } + return Collections.unmodifiableMap(maximumFlow); + } + + /** + * Returns current source vertex, or null if there was no + * calculateMaximumFlow calls. + * + * @return current source + */ + public V getCurrentSource() + { + if (currentSource == -1) { + return null; + } + return nodes.get(currentSource).prototype; + } + + /** + * Returns current sink vertex, or null if there was no + * calculateMaximumFlow calls. + * + * @return current sink + */ + public V getCurrentSink() + { + if (currentSink == -1) { + return null; + } + return nodes.get(currentSink).prototype; + } + + //~ Inner Classes ---------------------------------------------------------- + + // class used for internal representation of network + class Node + { + V prototype; // corresponding node in the original network + List outgoingArcs = new ArrayList(); // list of outgoing arcs + // in the residual + // network + boolean visited; // this mark is used during BFS to mark visited nodes + Arc lastArc; // last arc in the shortest path + double flowAmount; // amount of flow, we are able to push here + + Node( + V prototype) + { + this.prototype = prototype; + } + } + + // class used for internal representation of network + class Arc + { + int tail; // "from" + int head; // "to" + double capacity; // capacity (can be zero) + double flow; // current flow (can be negative) + Arc reversed; // for each arc in the original network we are to create + // reversed arc + E prototype; // corresponding edge in the original network, can be null, + // if it is reversed arc + + Arc( + int tail, + int head, + double capacity, + E prototype) + { + this.tail = tail; + this.head = head; + this.capacity = capacity; + this.prototype = prototype; + } + } +} + +// End EdmondsKarpMaximumFlow.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/EulerianCircuit.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/EulerianCircuit.java new file mode 100644 index 00000000..3a47910e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/EulerianCircuit.java @@ -0,0 +1,148 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * EulerianCircuit.java + * ------------------- + * (C) Copyright 2008-2008, by Andrew Newell and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: EulerianCircuit.java 651 2008-12-24 21:13:41Z perfecthash $ + * + * Changes + * ------- + * 24-Dec-2008 : Initial revision (AN); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * 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. + * + * @author Andrew Newell + * @since Dec 21, 2008 + */ +public abstract class EulerianCircuit +{ + //~ Methods ---------------------------------------------------------------- + + /** + * This method will check whether the graph passed in is Eulerian or not. + * + * @param g The graph to be checked + * + * @return true for Eulerian and false for non-Eulerian + */ + public static boolean isEulerian(UndirectedGraph g) + { + // If the graph is not connected, then no Eulerian circuit exists + if (!(new ConnectivityInspector(g)).isGraphConnected()) { + return false; + } + + // A graph is Eulerian if and only if all vertices have even degree + // So, this code will check for that + Iterator iter = g.vertexSet().iterator(); + while (iter.hasNext()) { + V v = iter.next(); + if ((g.degreeOf(v) % 2) == 1) { + return false; + } + } + return true; + } + + /** + * This method will return a list of vertices which represents the Eulerian + * circuit of the graph. + * + * @param g The graph to find an Eulerian circuit + * + * @return null if no Eulerian circuit exists, or a list of vertices + * representing the Eulerian circuit if one does exist + */ + public static List getEulerianCircuitVertices( + UndirectedGraph g) + { + // If the graph is not Eulerian then just return a null since no + // Eulerian circuit exists + if (!isEulerian(g)) { + return null; + } + + // The circuit will be represented by a linked list + List path = new LinkedList(); + UndirectedGraph sg = new UndirectedSubgraph(g, null, null); + path.add(sg.vertexSet().iterator().next()); + + // Algorithm for finding an Eulerian circuit Basically this will find an + // arbitrary circuit, then it will find another arbitrary circuit until + // every edge has been traversed + while (sg.edgeSet().size() > 0) { + V v = null; + + // Find a vertex which has an edge that hasn't been traversed yet, + // and keep its index position in the circuit list + int index = 0; + for (Iterator iter = path.iterator(); iter.hasNext(); index++) { + v = iter.next(); + if (sg.degreeOf(v) > 0) { + break; + } + } + + // Finds an arbitrary circuit of the current vertex and + // appends this into the circuit list + while (sg.degreeOf(v) > 0) { + for ( + Iterator iter = sg.vertexSet().iterator(); + iter.hasNext();) + { + V temp = iter.next(); + if (sg.containsEdge(v, temp)) { + path.add(index, temp); + sg.removeEdge(v, temp); + v = temp; + break; + } + } + } + } + return path; + } +} + +// End EulerianCircuit.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/FloydWarshallShortestPaths.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/FloydWarshallShortestPaths.java new file mode 100644 index 00000000..a98bf68b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/FloydWarshallShortestPaths.java @@ -0,0 +1,143 @@ +/* ========================================== + * 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-2009, 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. + */ +/* ------------------------- + * FloydWarshallShortestPaths.java + * ------------------------- + * (C) Copyright 2009-2009, by Tom Larkworthy and Contributors + * + * Original Author: Tom Larkworthy + * + * $Id: FloydWarshallShortestPaths.java 684 2009-06-30 04:42:22Z perfecthash $ + * + * Changes + * ------- + * 29-Jun-2009 : Initial revision (TL); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Tom Larkworthy + */ +public class FloydWarshallShortestPaths +{ + //~ Instance fields -------------------------------------------------------- + + int nextIndex = 0; + HashMap indices; + + double [][] d; + + double diameter; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructs the shortest path array for the given graph. + * + * @param g input graph + */ + public FloydWarshallShortestPaths(Graph g) + { + int sz = g.vertexSet().size(); + d = new double[sz][sz]; + indices = new HashMap(); + + //Initialise distance to infinity, or the neighbours weight, or 0 if + //same + for (V v1 : g.vertexSet()) { + for (V v2 : g.vertexSet()) { + if (v1 == v2) { + d[index(v1)][index(v2)] = 0; + } else { + E e = g.getEdge(v1, v2); + + if (e == null) { + d[index(v1)][index(v2)] = Double.POSITIVE_INFINITY; + } else { + d[index(v1)][index(v2)] = g.getEdgeWeight(e); + } + } + } + } + + //now iterate k times + for (int k = 0; k < sz; k++) { + for (V v1 : g.vertexSet()) { + for (V v2 : g.vertexSet()) { + d[index(v1)][index(v2)] = + Math.min( + d[index(v1)][index(v2)], + d[index(v1)][k] + d[k][index(v2)]); + diameter = Math.max(diameter, d[index(v1)][index(v2)]); + } + } + } + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Retrieves the shortest distance between two vertices. + * + * @param v1 first vertex + * @param v2 second vertex + * + * @return distance, or positive infinity if no path + */ + public double shortestDistance(V v1, V v2) + { + return d[index(v1)][index(v2)]; + } + + /** + * @return diameter computed for the graph + */ + public double getDiameter() + { + return diameter; + } + + private int index(V vertex) + { + Integer index = indices.get(vertex); + if (index == null) { + indices.put(vertex, nextIndex); + index = nextIndex++; + } + return index; + } +} + +// End FloydWarshallShortestPaths.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/HamiltonianCycle.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/HamiltonianCycle.java new file mode 100644 index 00000000..f945963e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/HamiltonianCycle.java @@ -0,0 +1,120 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * HamiltonianCycle.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: HamiltonianCycle.java 681 2009-05-25 06:17:31Z perfecthash $ + * + * Changes + * ------- + * 17-Feb-2008 : Initial revision (AN); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.graph.*; + + +/** + * This class will deal with finding the optimal or approximately optimal + * minimum tour (hamiltonian cycle) or commonly known as the Traveling + * Salesman Problem. + * + * @author Andrew Newell + */ +public class HamiltonianCycle +{ + //~ Methods ---------------------------------------------------------------- + + /** + * 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) + * @param + * @param g is the graph to find the optimal tour for. + * + * @return The optimal tour as a list of vertices. + */ + public static List getApproximateOptimalForCompleteGraph( + SimpleWeightedGraph g) + { + List vertices = new LinkedList(g.vertexSet()); + + // If the graph is not complete then return null since this algorithm + // requires the graph be complete + if ((vertices.size() * (vertices.size() - 1) / 2) + != g.edgeSet().size()) + { + return null; + } + + List tour = new LinkedList(); + + // Each iteration a new vertex will be added to the tour until all + // vertices have been added + while (tour.size() != g.vertexSet().size()) { + boolean firstEdge = true; + double minEdgeValue = 0; + int minVertexFound = 0; + int vertexConnectedTo = 0; + + // A check will be made for the shortest edge to a vertex not within + // the tour and that new vertex will be added to the vertex + for (int i = 0; i < tour.size(); i++) { + V v = tour.get(i); + for (int j = 0; j < vertices.size(); j++) { + double weight = + g.getEdgeWeight(g.getEdge(v, vertices.get(j))); + if (firstEdge || (weight < minEdgeValue)) { + firstEdge = false; + minEdgeValue = weight; + minVertexFound = j; + vertexConnectedTo = i; + } + } + } + tour.add(vertexConnectedTo, vertices.get(minVertexFound)); + vertices.remove(minVertexFound); + } + return tour; + } +} + +// End HamiltonianCycle.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/KShortestPaths.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/KShortestPaths.java new file mode 100644 index 00000000..c46470f4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/KShortestPaths.java @@ -0,0 +1,266 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPaths.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * Contributor(s): John V. Sichi + * + * $Id: KShortestPaths.java 689 2009-07-04 06:40:29Z 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.*; + + +/** + * 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. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +public class KShortestPaths +{ + // ~ Instance fields + // -------------------------------------------------------- + + //~ Instance fields -------------------------------------------------------- + + /** + * Graph on which shortest paths are searched. + */ + private Graph graph; + + private int nMaxHops; + + private int nPaths; + + private V startVertex; + + //~ Constructors ----------------------------------------------------------- + + // ~ Constructors + // ----------------------------------------------------------- + + /** + * Creates an object to compute ranking shortest paths between the start + * vertex and others vertices. + * + * @param graph + * @param startVertex + * @param k number of paths to be computed. + */ + public KShortestPaths(Graph graph, V startVertex, int k) + { + this(graph, startVertex, k, graph.vertexSet().size() - 1); + } + + /** + * Creates an object to calculate ranking shortest paths between the start + * vertex and others vertices. + * + * @param graph graph on which shortest paths are searched. + * @param startVertex start vertex of the calculated paths. + * @param nPaths number of ranking paths between the start vertex and an end + * vertex. + * @param nMaxHops maximum number of edges of the calculated paths. + * + * @throws NullPointerException if the specified graph or startVertex is + * null. + * @throws IllegalArgumentException if nPaths is negative or 0. + * @throws IllegalArgumentException if nMaxHops is negative or 0. + */ + public KShortestPaths( + Graph graph, + V startVertex, + int nPaths, + int nMaxHops) + { + assertKShortestPathsFinder(graph, startVertex, nPaths, nMaxHops); + + this.graph = graph; + this.startVertex = startVertex; + this.nPaths = nPaths; + this.nMaxHops = nMaxHops; + } + + //~ Methods ---------------------------------------------------------------- + + // ~ Methods + // ---------------------------------------------------------------- + + /** + * Returns the k shortest simple paths in increasing order of weight. + * + * @param endVertex target vertex of the calculated paths. + * + * @return list of paths, or null if no path exists between the + * start vertex and the end vertex. + */ + public List> getPaths(V endVertex) + { + assertGetPaths(endVertex); + + KShortestPathsIterator iter = + new KShortestPathsIterator( + this.graph, + this.startVertex, + endVertex, + this.nPaths); + + // at the i-th pass the shortest paths with less (or equal) than i edges + // are calculated. + for ( + int passNumber = 1; + (passNumber <= this.nMaxHops) + && iter.hasNext(); + passNumber++) + { + iter.next(); + } + + List> list = iter.getPathElements(endVertex); + + if (list == null) { + return null; + } + + List> pathList = new ArrayList>(); + + for (RankingPathElement element : list) { + pathList.add(new PathWrapper(element)); + } + + return pathList; + } + + private void assertGetPaths(V endVertex) + { + if (endVertex == null) { + throw new NullPointerException("endVertex is null"); + } + if (endVertex.equals(this.startVertex)) { + throw new IllegalArgumentException( + "The end vertex is the same as the start vertex!"); + } + if (!this.graph.vertexSet().contains(endVertex)) { + throw new IllegalArgumentException( + "Graph must contain the end vertex!"); + } + } + + private void assertKShortestPathsFinder( + Graph graph, + V startVertex, + int nPaths, + int nMaxHops) + { + if (graph == null) { + throw new NullPointerException("graph is null"); + } + if (startVertex == null) { + throw new NullPointerException("startVertex is null"); + } + if (nPaths <= 0) { + throw new NullPointerException("nPaths is negative or 0"); + } + if (nMaxHops <= 0) { + throw new NullPointerException("nMaxHops is negative or 0"); + } + } + + //~ Inner Classes ---------------------------------------------------------- + + private class PathWrapper + implements GraphPath + { + private RankingPathElement rankingPathElement; + + private List edgeList; + + PathWrapper(RankingPathElement rankingPathElement) + { + this.rankingPathElement = rankingPathElement; + } + + // implement GraphPath + public Graph getGraph() + { + return graph; + } + + // implement GraphPath + public V getStartVertex() + { + return startVertex; + } + + // implement GraphPath + public V getEndVertex() + { + return rankingPathElement.getVertex(); + } + + // implement GraphPath + public List getEdgeList() + { + if (edgeList == null) { + edgeList = rankingPathElement.createEdgeListPath(); + } + return edgeList; + } + + // implement GraphPath + public double getWeight() + { + return rankingPathElement.getWeight(); + } + + // override Object + public String toString() + { + return getEdgeList().toString(); + } + } +} + +// End KShortestPaths.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/KShortestPathsIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/KShortestPathsIterator.java new file mode 100644 index 00000000..ce6bd987 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/KShortestPathsIterator.java @@ -0,0 +1,362 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPathsIterator.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * Contributor(s): John V. Sichi + * + * $Id: KShortestPathsIterator.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.*; + + +/** + * Helper class for {@link KShortestPaths}. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +class KShortestPathsIterator + implements Iterator> +{ + // ~ Instance fields + // -------------------------------------------------------- + + //~ Instance fields -------------------------------------------------------- + + /** + * End vertex. + */ + private V endVertex; + + /** + * Graph on which shortest paths are searched. + */ + private Graph graph; + + /** + * Number of paths stored at each end vertex. + */ + private int k; + + /** + * Vertices whose ranking shortest paths have been modified during the + * previous pass. + */ + private Set prevImprovedVertices; + + /** + * Key = vertex, value = RankingPathElementList. + */ + private Map> prevSeenDataContainer; + + /** + * Stores the vertices that have been seen during iteration and (optionally) + * some additional traversal info regarding each vertex. Key = vertex, value + * = RankingPathElementList list of calculated paths. + */ + private Map> seenDataContainer; + + /** + * Start vertex. + */ + private V startVertex; + + private boolean startVertexEncountered; + + //~ Constructors ----------------------------------------------------------- + + // ~ Constructors + // ----------------------------------------------------------- + + /** + * @param graph graph on which shortest paths are searched. + * @param startVertex start vertex of the calculated paths. + * @param endVertex end vertex of the calculated paths. + * @param maxSize number of paths stored at end vertex of the graph. + */ + public KShortestPathsIterator( + Graph graph, + V startVertex, + V endVertex, + int maxSize) + { + assertKShortestPathsIterator(graph, startVertex); + + this.graph = graph; + this.startVertex = startVertex; + this.endVertex = endVertex; + + this.k = maxSize; + + this.seenDataContainer = new HashMap>(); + this.prevSeenDataContainer = + new HashMap>(); + + this.prevImprovedVertices = new HashSet(); + } + + //~ Methods ---------------------------------------------------------------- + + // ~ Methods + // ---------------------------------------------------------------- + + /** + * @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 of vertices whose path has been improved during the + * current pass. + * + * @see java.util.Iterator#next() + */ + public Set next() + { + if (!this.startVertexEncountered) { + encounterStartVertex(); + } + + if (hasNext()) { + Set improvedVertices = new HashSet(); + + for ( + Iterator iter = this.prevImprovedVertices.iterator(); + iter.hasNext();) + { + V vertex = iter.next(); + if (!vertex.equals(this.endVertex)) { + // updates outgoing vertices of the vertex. + updateOutgoingVertices(vertex, improvedVertices); + } + } + + savePassData(improvedVertices); + + return improvedVertices; + } + throw new NoSuchElementException(); + } + + /** + * Unsupported. + * + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + /** + * Returns the path elements of the ranking shortest paths with less than + * nMaxHops edges between the start vertex and the end vertex. + * + * @param endVertex end vertex. + * + * @return list of RankingPathElement, or null of + * no path exists between the start vertex and the end vertex. + */ + RankingPathElementList getPathElements(V endVertex) + { + return this.seenDataContainer.get(endVertex); + } + + /** + * Adds the first path to the specified vertex. + * + * @param vertex vertex reached by a path. + * @param edge edge reaching the vertex. + */ + private void addFirstPath(V vertex, E edge) + { + // the vertex has not been reached yet + RankingPathElementList data = createSeenData(vertex, edge); + this.seenDataContainer.put(vertex, data); + } + + private void assertKShortestPathsIterator(Graph graph, V startVertex) + { + if (graph == null) { + throw new NullPointerException("graph is null"); + } + if (startVertex == null) { + throw new NullPointerException("startVertex is null"); + } + } + + /** + * 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. + * + * @return the new entry. + */ + private RankingPathElementList createSeenData(V vertex, E edge) + { + V oppositeVertex = Graphs.getOppositeVertex(this.graph, edge, vertex); + + RankingPathElementList oppositeData = + this.prevSeenDataContainer.get(oppositeVertex); + + RankingPathElementList data = + new RankingPathElementList( + this.graph, + this.k, + oppositeData, + edge); + + return data; + } + + /** + * Returns outgoing edges of the vertex. + */ + private Set edgesOf(V vertex) + { + if (this.graph instanceof DirectedGraph) { + return ((DirectedGraph) this.graph).outgoingEdgesOf(vertex); + } else { + return this.graph.edgesOf(vertex); + } + } + + /** + * Initializes the list of paths at the start vertex ans adds an empty path. + */ + private void encounterStartVertex() + { + RankingPathElementList data = + new RankingPathElementList( + this.graph, + this.k, + new RankingPathElement( + this.startVertex)); + + this.seenDataContainer.put(this.startVertex, data); + this.prevSeenDataContainer.put(this.startVertex, data); + + // initially the only vertex whose value is considered to have changed + // is the start vertex + this.prevImprovedVertices.add(this.startVertex); + + this.startVertexEncountered = true; + } + + private void savePassData(Set improvedVertices) + { + for (Iterator iter = improvedVertices.iterator(); iter.hasNext();) { + V vertex = iter.next(); + + RankingPathElementList clonedData = + new RankingPathElementList( + this.seenDataContainer.get(vertex)); + this.prevSeenDataContainer.put(vertex, clonedData); + } + + this.prevImprovedVertices = improvedVertices; + } + + /** + * Try to add a new paths for the vertex. These new paths reached the + * specified vertex and ended with the specified edge. + * + * @param vertex a vertex which has just been encountered. + * @param edge the edge via which the vertex was encountered. + */ + private boolean tryToAddNewPaths(V vertex, E edge) + { + RankingPathElementList data = this.seenDataContainer.get(vertex); + + V oppositeVertex = Graphs.getOppositeVertex(this.graph, edge, vertex); + RankingPathElementList oppositeData = + this.prevSeenDataContainer.get(oppositeVertex); + + return data.addPathElements(oppositeData, edge); + } + + /** + * Updates outgoing vertices of the vertex. For each outgoing vertex, the + * new paths are obtained by concatenating the specified edge to the + * calculated paths of the specified vertex. If the weight of a new path is + * greater than the weight of any path stored so far at the outgoing vertex + * then the pah is not added, otherwise it is added to the list of paths in + * increasing order of weight. + * + * @param vertex + * @param improvedVertices + */ + private void updateOutgoingVertices(V vertex, Set improvedVertices) + { + // try to add new paths for the target vertices of the outgoing edges + // of the vertex. + for (Iterator iter = edgesOf(vertex).iterator(); iter.hasNext();) { + E edge = iter.next(); + V vertexReachedByEdge = + Graphs.getOppositeVertex(this.graph, edge, + vertex); + + // check if the path does not loop over the start vertex. + if (vertexReachedByEdge != this.startVertex) { + if (this.seenDataContainer.containsKey(vertexReachedByEdge)) { + boolean relaxed = + tryToAddNewPaths(vertexReachedByEdge, + edge); + if (relaxed) { + improvedVertices.add(vertexReachedByEdge); + } + } else { + addFirstPath(vertexReachedByEdge, edge); + improvedVertices.add(vertexReachedByEdge); + } + } + } + } +} + +// End KShortestPathsIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/NeighborIndex.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/NeighborIndex.java new file mode 100644 index 00000000..2e8221db --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/NeighborIndex.java @@ -0,0 +1,262 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * NeighborIndex.java + * -------------------------- + * (C) Copyright 2005-2008, by Charles Fry and Contributors. + * + * Original Author: Charles Fry + * + * $Id: NeighborIndex.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Dec-2005 : Initial revision (CF); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; +import org.jgrapht.util.*; + + +/** + * Maintains a cache of each vertex's neighbors. While lists of neighbors can be + * obtained from {@link 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 {@link + * 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.

    + * + * @author Charles Fry + * @since Dec 13, 2005 + */ +public class NeighborIndex + implements GraphListener +{ + //~ Instance fields -------------------------------------------------------- + + Map> neighborMap = new HashMap>(); + private Graph graph; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a neighbor index for the specified undirected graph. + * + * @param g the graph for which a neighbor index is to be created. + */ + public NeighborIndex(Graph g) + { + // no need to distinguish directedgraphs as we don't do traversals + graph = g; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * 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. + * + * @param v the vertex whose neighbors are desired + * + * @return all unique neighbors of the specified vertex + */ + public Set neighborsOf(V v) + { + return getNeighbors(v).getNeighbors(); + } + + /** + * 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 {@link + * #neighborsOf(Object)} unless duplicate neighbors are important. + * + * @param v the vertex whose neighbors are desired + * + * @return all neighbors of the specified vertex + */ + public List neighborListOf(V v) + { + return getNeighbors(v).getNeighborList(); + } + + /** + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public void edgeAdded(GraphEdgeChangeEvent e) + { + E edge = e.getEdge(); + V source = graph.getEdgeSource(edge); + V target = graph.getEdgeTarget(edge); + + // if a map does not already contain an entry, + // then skip addNeighbor, since instantiating the map + // will take care of processing the edge (which has already + // been added) + + if (neighborMap.containsKey(source)) { + getNeighbors(source).addNeighbor(target); + } else { + getNeighbors(source); + } + if (neighborMap.containsKey(target)) { + getNeighbors(target).addNeighbor(source); + } else { + getNeighbors(target); + } + } + + /** + * @see GraphListener#edgeRemoved(GraphEdgeChangeEvent) + */ + public void edgeRemoved(GraphEdgeChangeEvent e) + { + E edge = e.getEdge(); + V source = graph.getEdgeSource(edge); + V target = graph.getEdgeTarget(edge); + if (neighborMap.containsKey(source)) { + neighborMap.get(source).removeNeighbor(target); + } + if (neighborMap.containsKey(target)) { + neighborMap.get(target).removeNeighbor(source); + } + } + + /** + * @see VertexSetListener#vertexAdded(GraphVertexChangeEvent) + */ + public void vertexAdded(GraphVertexChangeEvent e) + { + // nothing to cache until there are edges + } + + /** + * @see VertexSetListener#vertexRemoved(GraphVertexChangeEvent) + */ + public void vertexRemoved(GraphVertexChangeEvent e) + { + neighborMap.remove(e.getVertex()); + } + + private Neighbors getNeighbors(V v) + { + Neighbors neighbors = neighborMap.get(v); + if (neighbors == null) { + neighbors = new Neighbors(v, + Graphs.neighborListOf(graph, v)); + neighborMap.put(v, neighbors); + } + return neighbors; + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Stores cached neighbors for a single vertex. Includes support for live + * neighbor sets and duplicate neighbors. + */ + static class Neighbors + { + private Map neighborCounts = + new LinkedHashMap(); + + // TODO could eventually make neighborSet modifiable, resulting + // in edge removals from the graph + private Set neighborSet = + Collections.unmodifiableSet( + neighborCounts.keySet()); + + public Neighbors(V v, Collection neighbors) + { + // add all current neighbors + for (V neighbor : neighbors) { + addNeighbor(neighbor); + } + } + + public void addNeighbor(V v) + { + ModifiableInteger count = neighborCounts.get(v); + if (count == null) { + count = new ModifiableInteger(1); + neighborCounts.put(v, count); + } else { + count.increment(); + } + } + + public void removeNeighbor(V v) + { + ModifiableInteger count = neighborCounts.get(v); + if (count == null) { + throw new IllegalArgumentException( + "Attempting to remove a neighbor that wasn't present"); + } + + count.decrement(); + if (count.getValue() == 0) { + neighborCounts.remove(v); + } + } + + public Set getNeighbors() + { + return neighborSet; + } + + public List getNeighborList() + { + List neighbors = new ArrayList(); + for ( + Map.Entry entry + : neighborCounts.entrySet()) + { + V v = entry.getKey(); + int count = entry.getValue().intValue(); + for (int i = 0; i < count; i++) { + neighbors.add(v); + } + } + return neighbors; + } + } +} + +// End NeighborIndex.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/RankingPathElement.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/RankingPathElement.java new file mode 100644 index 00000000..d48247e5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/RankingPathElement.java @@ -0,0 +1,115 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * RankingPathElement.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * Contributor(s): John V. Sichi + * + * $Id: RankingPathElement.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 org.jgrapht.*; + + +/** + * Helper class for {@link KShortestPaths}. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +final class RankingPathElement + extends AbstractPathElement +{ + //~ Instance fields -------------------------------------------------------- + + /** + * Weight of the path. + */ + private double weight; + + //~ 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 weight total cost of the created path element. + */ + RankingPathElement( + Graph graph, + RankingPathElement pathElement, + E edge, + double weight) + { + super(graph, pathElement, edge); + this.weight = weight; + } + + /** + * Creates an empty path element. + * + * @param vertex end vertex of the path element. + */ + RankingPathElement(V vertex) + { + super(vertex); + this.weight = 0; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the weight of the path. + * + * @return . + */ + public double getWeight() + { + return this.weight; + } + + /** + * Returns the previous path element. + * + * @return null is the path is empty. + */ + public RankingPathElement getPrevPathElement() + { + return (RankingPathElement) super.getPrevPathElement(); + } +} + +// End RankingPathElement.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/RankingPathElementList.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/RankingPathElementList.java new file mode 100644 index 00000000..af52d71a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/RankingPathElementList.java @@ -0,0 +1,316 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * RankingPathElementList.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * Contributor(s): John V. Sichi + * + * $Id: RankingPathElementList.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 simple paths in increasing order of weight. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +final class RankingPathElementList + extends AbstractPathElementList> +{ + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a list with an empty path. The list size is 1. + * + * @param maxSize max number of paths the list is able to store. + * @param maxSize maximum number of paths the list is able to store. + */ + RankingPathElementList( + Graph graph, + int maxSize, + RankingPathElement pathElement) + { + super(graph, maxSize, pathElement); + } + + /** + * Creates paths obtained by concatenating the specified edge to the + * specified paths. + * + * @param prevPathElementList paths, list of + * RankingPathElement. + * @param edge edge reaching the end vertex of the created paths. + * @param maxSize maximum number of paths the list is able to store. + */ + RankingPathElementList( + Graph graph, + int maxSize, + RankingPathElementList elementList, + E edge) + { + super(graph, maxSize, elementList, edge); + + // loop over the path elements in increasing order of weight. + for (int i = 0; i < elementList.size(); i++) { + RankingPathElement prevPathElement = elementList.get(i); + if (this.pathElements.size() <= (this.maxSize - 1)) { + double weight = calculatePathWeight(prevPathElement, edge); + RankingPathElement newPathElement = + new RankingPathElement( + this.graph, + prevPathElement, + edge, + weight); + + // the new path is inserted at the end of the list. + this.pathElements.add(newPathElement); + } + } + + assert (!this.pathElements.isEmpty()); + } + + /** + * Copy constructor. + * + * @param original source to copy from + */ + protected RankingPathElementList(RankingPathElementList original) + { + super(original); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Adds paths in the list at vertex y. Candidate paths are obtained by + * concatenating the specified edge (v->y) to the paths + * elementList at vertex v. + * + * @param elementList list of paths at vertex v. + * @param edge edge (v->y). + * + * @return true if at least one path has been added in the + * list, false otherwise. + */ + public boolean addPathElements( + RankingPathElementList elementList, + E edge) + { + assert (this.vertex.equals( + Graphs.getOppositeVertex( + this.graph, + edge, + elementList.getVertex()))); + + boolean pathAdded = false; + + // loop over the paths elements of the list at vertex v. + for ( + int vIndex = 0, yIndex = 0; + vIndex < elementList.size(); + vIndex++) + { + RankingPathElement prevPathElement = elementList.get(vIndex); + if (isAlreadyImprovedByThisEdge(edge, prevPathElement) + || containsTargetPreviously(prevPathElement)) + { + // checks if path is simple. + continue; + } + double weight = calculatePathWeight(prevPathElement, edge); + + // loop over the paths elements of the list at vertex y from yIndex + // to the end. + for (; yIndex < size(); yIndex++) { + RankingPathElement yPathElement = get(yIndex); + RankingPathElement newPathElement = + new RankingPathElement( + this.graph, + prevPathElement, + edge, + weight); + + if (weight < yPathElement.getWeight()) { + this.pathElements.add(yIndex, newPathElement); + if (size() > this.maxSize) { + this.pathElements.remove(this.maxSize); + } + pathAdded = true; + break; + } + if (weight == yPathElement.getWeight()) { + // checks if newPathElement is not already in the list. + if (isAlreadyAdded(newPathElement)) { + break; + } + + if (size() <= (this.maxSize - 1)) { + this.pathElements.add(yIndex + 1, newPathElement); + if (size() > this.maxSize) { + this.pathElements.remove(this.maxSize); + } + pathAdded = true; + break; + } + } + + if ((weight > yPathElement.getWeight()) + && (yIndex == (size() - 1))) + { + if (size() <= (this.maxSize - 1)) { + this.pathElements.add(newPathElement); + pathAdded = true; + break; + } + } + } + } + return pathAdded; + } + + /** + * @return list of RankingPathElement. + */ + List> getPathElements() + { + return this.pathElements; + } + + /** + * Costs taken into account are the weights stored in Edge + * objects. + * + * @param pathElement + * @param edge the edge via which the vertex was encountered. + * + * @return the cost obtained by concatenation. + * + * @see Graph#getEdgeWeight(E) + */ + private double calculatePathWeight( + RankingPathElement pathElement, + E edge) + { + double pathWeight = this.graph.getEdgeWeight(edge); + + // otherwise it's the start vertex. + if ((pathElement.getPrevEdge() != null)) { + pathWeight += pathElement.getWeight(); + } + + return pathWeight; + } + + /** + * Ensures that paths of the list are simple. + * + * @param pathElement + * + * @return true if the vertex specified at constructor is + * already in the specified path element, false otherwise. + */ + private boolean containsTargetPreviously( + RankingPathElement pathElement) + { + RankingPathElement tempPathElement = pathElement; + while (tempPathElement.getPrevEdge() != null) { + if (tempPathElement.getVertex() == this.vertex) { + return true; + } else { + tempPathElement = tempPathElement.getPrevPathElement(); + } + } + return false; + } + + private boolean isAlreadyAdded(RankingPathElement pathElement) + { + for (int i = 0; i <= (size() - 1); i++) { + RankingPathElement yPathElement = get(i); + RankingPathElement pathElementToTest = pathElement; + if (!isDifferent(yPathElement, pathElementToTest)) { + return true; + } + } + return false; + } + + private boolean isAlreadyImprovedByThisEdge( + E edge, + RankingPathElement prevPathElement) + { + RankingPathElement pathElementToTest = prevPathElement; + while (pathElementToTest.getPrevEdge() != null) { + if (pathElementToTest.getPrevEdge() == edge) { + return true; + } + pathElementToTest = pathElementToTest.getPrevPathElement(); + } + return false; + } + + /** + * @param yPathElement + * @param pathElementToTest + * + * @return false if the two paths are equal, true + * otherwise. + */ + private boolean isDifferent( + RankingPathElement yPathElement, + RankingPathElement pathElementToTest) + { + while ( + ((yPathElement.getPrevEdge() != null) + || (pathElementToTest.getPrevEdge() != null))) + { + if (yPathElement.getPrevEdge() != pathElementToTest.getPrevEdge()) { + return true; + } else { + yPathElement = yPathElement.getPrevPathElement(); + pathElementToTest = pathElementToTest.getPrevPathElement(); + } + } + return false; + } +} + +// End RankingPathElementList.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/StrongConnectivityInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/StrongConnectivityInspector.java new file mode 100644 index 00000000..72eb2b01 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/StrongConnectivityInspector.java @@ -0,0 +1,393 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * StrongConnectivityInspector.java + * -------------------------- + * (C) Copyright 2005-2008, by Christian Soltenborn and Contributors. + * + * Original Author: Christian Soltenborn + * + * $Id: StrongConnectivityInspector.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 2-Feb-2005 : Initial revision (CS); + * 5-Feb-2007 : fixed NullPointerException (CS); + * 1-Apr-2008 : Reduced memory consumption (CS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + *

    Complements the {@link org.jgrapht.alg.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).

    + * + *

    Unlike {@link org.jgrapht.alg.ConnectivityInspector}, this class does not + * implement incremental inspection. The full algorithm is executed at the first + * call of {@link StrongConnectivityInspector#stronglyConnectedSets()} or {@link + * StrongConnectivityInspector#isStronglyConnected()}.

    + * + * @author Christian Soltenborn + * @author Christian Hammer + * @since Feb 2, 2005 + */ +public class StrongConnectivityInspector +{ + //~ Instance fields -------------------------------------------------------- + + // the graph to compute the strongly connected sets for + private final DirectedGraph graph; + + // stores the vertices, ordered by their finishing time in first dfs + private LinkedList> orderedVertices; + + // the result of the computation, cached for future calls + private List> stronglyConnectedSets; + + // the result of the computation, cached for future calls + private List> stronglyConnectedSubgraphs; + + // maps vertices to their VertexData object + private Map> vertexToVertexData; + + //~ Constructors ----------------------------------------------------------- + + /** + * The constructor of the StrongConnectivityInspector class. + * + * @param directedGraph the graph to inspect + * + * @throws IllegalArgumentException + */ + public StrongConnectivityInspector(DirectedGraph directedGraph) + { + if (directedGraph == null) { + throw new IllegalArgumentException("null not allowed for graph!"); + } + + graph = directedGraph; + vertexToVertexData = null; + orderedVertices = null; + stronglyConnectedSets = null; + stronglyConnectedSubgraphs = null; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the graph inspected by the StrongConnectivityInspector. + * + * @return the graph inspected by this StrongConnectivityInspector + */ + public DirectedGraph getGraph() + { + return graph; + } + + /** + * Returns true if the graph of this + * StronglyConnectivityInspector instance is strongly connected. + * + * @return true if the graph is strongly connected, false otherwise + */ + public boolean isStronglyConnected() + { + return stronglyConnectedSets().size() == 1; + } + + /** + * Computes a {@link List} of {@link Set}s, where each set contains vertices + * which together form a strongly connected component within the given + * graph. + * + * @return List of Set s containing the strongly + * connected components + */ + public List> stronglyConnectedSets() + { + if (stronglyConnectedSets == null) { + orderedVertices = new LinkedList>(); + stronglyConnectedSets = new Vector>(); + + // create VertexData objects for all vertices, store them + createVertexData(); + + // perform the first round of DFS, result is an ordering + // of the vertices by decreasing finishing time + for (VertexData data : vertexToVertexData.values()) { + if (!data.isDiscovered()) { + dfsVisit(graph, data, null); + } + } + + // 'create' inverse graph (i.e. every edge is reversed) + DirectedGraph inverseGraph = + new EdgeReversedGraph(graph); + + // get ready for next dfs round + resetVertexData(); + + // second dfs round: vertices are considered in decreasing + // finishing time order; every tree found is a strongly + // connected set + for (VertexData data : orderedVertices) { + if (!data.isDiscovered()) { + // new strongly connected set + Set set = new HashSet(); + stronglyConnectedSets.add(set); + dfsVisit(inverseGraph, data, set); + } + } + + // clean up for garbage collection + orderedVertices = null; + vertexToVertexData = null; + } + + return stronglyConnectedSets; + } + + /** + *

    Computes a list of {@link DirectedSubgraph}s 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 {@link + * StrongConnectivityInspector#stronglyConnectedSets()}. If you don't need + * subgraphs, use that method.

    + * + * @return a list of subgraphs representing the strongly connected + * components + */ + public List> stronglyConnectedSubgraphs() + { + if (stronglyConnectedSubgraphs == null) { + List> sets = stronglyConnectedSets(); + stronglyConnectedSubgraphs = + new Vector>(sets.size()); + + for (Set set : sets) { + stronglyConnectedSubgraphs.add( + new DirectedSubgraph( + graph, + set, + null)); + } + } + + return stronglyConnectedSubgraphs; + } + + /* + * Creates a VertexData object for every vertex in the graph and stores + * them + * in a HashMap. + */ + private void createVertexData() + { + vertexToVertexData = + new HashMap>(graph.vertexSet().size()); + + for (V vertex : graph.vertexSet()) { + vertexToVertexData.put( + vertex, + new VertexData2(vertex, false, false)); + } + } + + /* + * The subroutine of DFS. NOTE: the set is used to distinguish between 1st + * and 2nd round of DFS. set == null: finished vertices are stored (1st + * round). set != null: all vertices found will be saved in the set (2nd + * round) + */ + private void dfsVisit( + DirectedGraph visitedGraph, + VertexData vertexData, + Set vertices) + { + Deque> stack = new ArrayDeque>(); + stack.add(vertexData); + + while (!stack.isEmpty()) { + VertexData data = stack.removeLast(); + + if (!data.isDiscovered()) { + data.setDiscovered(true); + + if (vertices != null) { + vertices.add(data.getVertex()); + } + + stack.add(new VertexData1(data, true, true)); + + // follow all edges + for (E edge : visitedGraph.outgoingEdgesOf(data.getVertex())) { + VertexData targetData = + vertexToVertexData.get( + visitedGraph.getEdgeTarget(edge)); + + if (!targetData.isDiscovered()) { + // the "recursion" + stack.add(targetData); + } + } + } else if (data.isFinished()) { + if (vertices == null) { + orderedVertices.addFirst(data.getFinishedData()); + } + } + } + } + + /* + * Resets all VertexData objects. + */ + private void resetVertexData() + { + for (VertexData data : vertexToVertexData.values()) { + data.setDiscovered(false); + data.setFinished(false); + } + } + + //~ Inner Classes ---------------------------------------------------------- + + /* + * Lightweight class storing some data for every vertex. + */ + private static abstract class VertexData + { + private byte bitfield; + + private VertexData( + boolean discovered, + boolean finished) + { + this.bitfield = 0; + setDiscovered(discovered); + setFinished(finished); + } + + private boolean isDiscovered() + { + if ((bitfield & 1) == 1) { + return true; + } + return false; + } + + private boolean isFinished() + { + if ((bitfield & 2) == 2) { + return true; + } + return false; + } + + private void setDiscovered(boolean discovered) + { + if (discovered) { + bitfield |= 1; + } else { + bitfield &= ~1; + } + } + + private void setFinished(boolean finished) + { + if (finished) { + bitfield |= 2; + } else { + bitfield &= ~2; + } + } + + abstract VertexData getFinishedData(); + + abstract V getVertex(); + } + + private static final class VertexData1 + extends VertexData + { + private final VertexData finishedData; + + private VertexData1( + VertexData finishedData, + boolean discovered, + boolean finished) + { + super(discovered, finished); + this.finishedData = finishedData; + } + + VertexData getFinishedData() + { + return finishedData; + } + + V getVertex() + { + return null; + } + } + + private static final class VertexData2 + extends VertexData + { + private final V vertex; + + private VertexData2( + V vertex, + boolean discovered, + boolean finished) + { + super(discovered, finished); + this.vertex = vertex; + } + + VertexData getFinishedData() + { + return null; + } + + V getVertex() + { + return vertex; + } + } +} + +// End StrongConnectivityInspector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/TransitiveClosure.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/TransitiveClosure.java new file mode 100644 index 00000000..4f70b136 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/TransitiveClosure.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. + */ +/* ---------------------- + * TransitiveClosure.java + * ---------------------- + * (C) Copyright 2007, by Vinayak R. Borkar. + * + * Original Author: Vinayak R. Borkar + * Contributor(s): + * + * Changes + * ------- + * 5-May-2007: Initial revision (VRB); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.graph.*; + + +/** + * Constructs the transitive closure of the input graph. + * + * @author Vinayak R. Borkar + * @since May 5, 2007 + */ +public class TransitiveClosure +{ + //~ Static fields/initializers --------------------------------------------- + + /** + * Singleton instance. + */ + public static final TransitiveClosure INSTANCE = new TransitiveClosure(); + + //~ Constructors ----------------------------------------------------------- + + /** + * Private Constructor. + */ + private TransitiveClosure() + { + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Computes the transitive closure of the given graph. + * + * @param graph - Graph to compute transitive closure for. + */ + public void closeSimpleDirectedGraph(SimpleDirectedGraph graph) + { + Set vertexSet = graph.vertexSet(); + + Set newEdgeTargets = new HashSet(); + + // At every iteration of the outer loop, we add a path of length 1 + // between nodes that originally had a path of length 2. In the worst + // case, we need to make floor(log |V|) + 1 iterations. We stop earlier + // if there is no change to the output graph. + + int bound = computeBinaryLog(vertexSet.size()); + boolean done = false; + for (int i = 0; !done && (i < bound); ++i) { + done = true; + for (V v1 : vertexSet) { + newEdgeTargets.clear(); + + for (E v1OutEdge : graph.outgoingEdgesOf(v1)) { + V v2 = graph.getEdgeTarget(v1OutEdge); + for (E v2OutEdge : graph.outgoingEdgesOf(v2)) { + V v3 = graph.getEdgeTarget(v2OutEdge); + + if (v1.equals(v3)) { + // Its a simple graph, so no self loops. + continue; + } + + if (graph.getEdge(v1, v3) != null) { + // There is already an edge from v1 ---> v3, skip; + continue; + } + + newEdgeTargets.add(v3); + done = false; + } + } + + for (V v3 : newEdgeTargets) { + graph.addEdge(v1, v3); + } + } + } + } + + /** + * Computes floor(log_2(n)) + 1 + */ + private int computeBinaryLog(int n) + { + assert n >= 0; + + int result = 0; + while (n > 0) { + n >>= 1; + ++result; + } + + return result; + } +} + +// End TransitiveClosure.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/VertexCovers.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/VertexCovers.java new file mode 100644 index 00000000..2f071d82 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/VertexCovers.java @@ -0,0 +1,157 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * VertexCovers.java + * ----------------- + * (C) Copyright 2003-2008, by Linda Buisman and Contributors. + * + * Original Author: Linda Buisman + * Contributor(s): Barak Naveh + * Christian Hammer + * + * $Id: VertexCovers.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Nov-2003 : Initial revision (LB); + * 07-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.alg.util.*; +import org.jgrapht.graph.*; + + +/** + * 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 + * + * @author Linda Buisman + * @since Nov 6, 2003 + */ +public abstract class VertexCovers +{ + //~ Methods ---------------------------------------------------------------- + + /** + * 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. + * + *

    For more details see Jenny Walter, CMPU-240: Lecture notes for + * Language Theory and Computation, Fall 2002, Vassar College, + * http://www.cs.vassar.edu/~walter/cs241index/lectures/PDF/approx.pdf. + *

    + * + * @param g the graph for which vertex cover approximation is to be found. + * + * @return a set of vertices which is a vertex cover for the specified + * graph. + */ + public static Set find2ApproximationCover(Graph g) + { + // C <-- {} + Set cover = new HashSet(); + + // G'=(V',E') <-- G(V,E) + Subgraph> sg = + new Subgraph>( + g, + null, + null); + + // while E' is non-empty + while (sg.edgeSet().size() > 0) { + // let (u,v) be an arbitrary edge of E' + E e = sg.edgeSet().iterator().next(); + + // C <-- C U {u,v} + V u = g.getEdgeSource(e); + V v = g.getEdgeTarget(e); + cover.add(u); + cover.add(v); + + // remove from E' every edge incident on either u or v + sg.removeVertex(u); + sg.removeVertex(v); + } + + return cover; // return C + } + + /** + * 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 {@link org.jgrapht.Graphs#undirectedGraph(Graph)} + * or {@link org.jgrapht.graph.AsUndirectedGraph}.

    + * + * @param g the graph for which vertex cover approximation is to be found. + * + * @return a set of vertices which is a vertex cover for the specified + * graph. + */ + public static Set findGreedyCover(UndirectedGraph g) + { + // C <-- {} + Set cover = new HashSet(); + + // G' <-- G + UndirectedGraph sg = new UndirectedSubgraph(g, null, null); + + // compare vertices in descending order of degree + VertexDegreeComparator comp = + new VertexDegreeComparator(sg); + + // while G' != {} + while (sg.edgeSet().size() > 0) { + // v <-- vertex with maximum degree in G' + V v = Collections.max(sg.vertexSet(), comp); + + // C <-- C U {v} + cover.add(v); + + // remove from G' every edge incident on v, and v itself + sg.removeVertex(v); + } + + return cover; + } +} + +// End VertexCovers.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/package.html new file mode 100644 index 00000000..a08a9bb2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/package.html @@ -0,0 +1,6 @@ + + + +Algorithms provided with JGraphT. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/util/VertexDegreeComparator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/util/VertexDegreeComparator.java new file mode 100644 index 00000000..d3d70135 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/util/VertexDegreeComparator.java @@ -0,0 +1,134 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * VertexDegreeComparator.java + * --------------------------- + * (C) Copyright 2003-2008, by Linda Buisman and Contributors. + * + * Original Author: Linda Buisman + * Contributor(s): Christian Hammer + * + * $Id: VertexDegreeComparator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Nov-2003 : Initial revision (LB); + * 07-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.alg.util; + +import org.jgrapht.*; + + +/** + * Compares two vertices based on their degree. + * + *

    Used by greedy algorithms that need to sort vertices by their degree. Two + * vertices are considered equal if their degrees are equal.

    + * + * @author Linda Buisman + * @since Nov 6, 2003 + */ +public class VertexDegreeComparator + implements java.util.Comparator +{ + //~ Instance fields -------------------------------------------------------- + + /** + * The graph that contains the vertices to be compared. + */ + private UndirectedGraph graph; + + /** + * The sort order for vertex degree. true for ascending degree + * order (smaller degrees first), false for descending. + */ + private boolean ascendingOrder; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a comparator for comparing the degrees of vertices in the + * specified graph. The comparator compares in ascending order of degrees + * (lowest first). + * + * @param g graph with respect to which the degree is calculated. + */ + public VertexDegreeComparator(UndirectedGraph g) + { + this(g, true); + } + + /** + * Creates a comparator for comparing the degrees of vertices in the + * specified graph. + * + * @param g graph with respect to which the degree is calculated. + * @param ascendingOrder true - compares in ascending order of degrees + * (lowest first), false - compares in descending order of degrees (highest + * first). + */ + public VertexDegreeComparator( + UndirectedGraph g, + boolean ascendingOrder) + { + graph = g; + this.ascendingOrder = ascendingOrder; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Compare the degrees of v1 and v2, taking into + * account whether ascending or descending order is used. + * + * @param v1 the first vertex to be compared. + * @param v2 the second vertex to be compared. + * + * @return -1 if v1 comes before v2, +1 if + * v1 comes after v2, 0 if equal. + */ + public int compare(V v1, V v2) + { + int degree1 = graph.degreeOf(v1); + int degree2 = graph.degreeOf(v2); + + if (((degree1 < degree2) && ascendingOrder) + || ((degree1 > degree2) && !ascendingOrder)) + { + return -1; + } else if ( + ((degree1 > degree2) && ascendingOrder) + || ((degree1 < degree2) && !ascendingOrder)) + { + return 1; + } else { + return 0; + } + } +} + +// End VertexDegreeComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/util/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/util/package.html new file mode 100644 index 00000000..38c56f61 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/alg/util/package.html @@ -0,0 +1,6 @@ + + + +Utilities used by JGraphT algorithms. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/CompleteGraphDemo.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/CompleteGraphDemo.java new file mode 100644 index 00000000..442ff6ef --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/CompleteGraphDemo.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. + */ +/* -------------------- + * CompleteGraphDemo.java + * -------------------- + * (C) Copyright 2003-2008, by Tim Shearouse and Contributors. + * + * Original Author: Tim Shearouse + * Contributor(s): - + * + * $Id: CompleteGraphDemo.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * + */ +package org.jgrapht.demo; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; +import org.jgrapht.traverse.*; + + +public final class CompleteGraphDemo +{ + //~ Static fields/initializers --------------------------------------------- + + static Graph completeGraph; + + //Number of vertices + static int size = 10; + + //~ Methods ---------------------------------------------------------------- + + public static void main(String [] args) + { + //Create the graph object; it is null at this point + completeGraph = new SimpleGraph(DefaultEdge.class); + + //Create the CompleteGraphGenerator object + CompleteGraphGenerator completeGenerator = + new CompleteGraphGenerator(size); + + //Create the VertexFactory so the generator can create vertices + VertexFactory vFactory = + new ClassBasedVertexFactory(Object.class); + + //Use the CompleteGraphGenerator object to make completeGraph a + //complete graph with [size] number of vertices + completeGenerator.generateGraph(completeGraph, vFactory, null); + + //Now, replace all the vertices with sequential numbers so we can ID + //them + Set vertices = new HashSet(); + vertices.addAll(completeGraph.vertexSet()); + Integer counter = 0; + for (Object vertex : vertices) { + replaceVertex(vertex, (Object) counter++); + } + + //Print out the graph to be sure it's really complete + Iterator iter = + new DepthFirstIterator(completeGraph); + Object vertex; + while (iter.hasNext()) { + vertex = iter.next(); + System.out.println( + "Vertex " + vertex.toString() + " is connected to: " + + completeGraph.edgesOf(vertex).toString()); + } + } + + public static boolean replaceVertex(Object oldVertex, Object newVertex) + { + if ((oldVertex == null) || (newVertex == null)) { + return false; + } + Set relatedEdges = completeGraph.edgesOf(oldVertex); + completeGraph.addVertex(newVertex); + + Object sourceVertex; + Object targetVertex; + for (DefaultEdge e : relatedEdges) { + sourceVertex = completeGraph.getEdgeSource(e); + targetVertex = completeGraph.getEdgeTarget(e); + if (sourceVertex.equals(oldVertex) + && targetVertex.equals(oldVertex)) + { + completeGraph.addEdge(newVertex, newVertex); + } else { + if (sourceVertex.equals(oldVertex)) { + completeGraph.addEdge(newVertex, targetVertex); + } else { + completeGraph.addEdge(sourceVertex, newVertex); + } + } + } + completeGraph.removeVertex(oldVertex); + return true; + } +} + +// End CompleteGraphDemo.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/HelloJGraphT.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/HelloJGraphT.java new file mode 100644 index 00000000..0f3f3f5f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/HelloJGraphT.java @@ -0,0 +1,145 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * HelloJGraphT.java + * ----------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: HelloJGraphT.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 27-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht.demo; + +import java.net.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * A simple introduction to using JGraphT. + * + * @author Barak Naveh + * @since Jul 27, 2003 + */ +public final class HelloJGraphT +{ + //~ Constructors ----------------------------------------------------------- + + private HelloJGraphT() + { + } // ensure non-instantiability. + + //~ Methods ---------------------------------------------------------------- + + /** + * The starting point for the demo. + * + * @param args ignored. + */ + public static void main(String [] args) + { + UndirectedGraph stringGraph = createStringGraph(); + + // note undirected edges are printed as: {,} + System.out.println(stringGraph.toString()); + + // create a graph based on URL objects + DirectedGraph hrefGraph = createHrefGraph(); + + // note directed edges are printed as: (,) + System.out.println(hrefGraph.toString()); + } + + /** + * Creates a toy directed graph based on URL objects that represents link + * structure. + * + * @return a graph based on URL objects. + */ + private static DirectedGraph createHrefGraph() + { + DirectedGraph g = + new DefaultDirectedGraph(DefaultEdge.class); + + try { + URL amazon = new URL("http://www.amazon.com"); + URL yahoo = new URL("http://www.yahoo.com"); + URL ebay = new URL("http://www.ebay.com"); + + // add the vertices + g.addVertex(amazon); + g.addVertex(yahoo); + g.addVertex(ebay); + + // add edges to create linking structure + g.addEdge(yahoo, amazon); + g.addEdge(yahoo, ebay); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + return g; + } + + /** + * Craete a toy graph based on String objects. + * + * @return a graph based on String objects. + */ + private static UndirectedGraph createStringGraph() + { + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + + String v1 = "v1"; + String v2 = "v2"; + String v3 = "v3"; + String v4 = "v4"; + + // add the vertices + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + g.addVertex(v4); + + // add edges to create a circuit + g.addEdge(v1, v2); + g.addEdge(v2, v3); + g.addEdge(v3, v4); + g.addEdge(v4, v1); + + return g; + } +} + +// End HelloJGraphT.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/JGraphAdapterDemo.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/JGraphAdapterDemo.java new file mode 100644 index 00000000..9288ab3e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/JGraphAdapterDemo.java @@ -0,0 +1,203 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * JGraphAdapterDemo.java + * ---------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: JGraphAdapterDemo.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Aug-2003 : Initial revision (BN); + * 07-Nov-2003 : Adaptation to JGraph 3.0 (BN); + * + */ +package org.jgrapht.demo; + +import java.awt.*; +import java.awt.geom.*; + +import javax.swing.*; + +import org.jgraph.*; +import org.jgraph.graph.*; + +import org.jgrapht.*; +import org.jgrapht.ext.*; +import org.jgrapht.graph.*; + +// resolve ambiguity +import org.jgrapht.graph.DefaultEdge; + + +/** + * A demo applet that shows how to use JGraph to visualize JGraphT graphs. + * + * @author Barak Naveh + * @since Aug 3, 2003 + */ +public class JGraphAdapterDemo + extends JApplet +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3256444702936019250L; + private static final Color DEFAULT_BG_COLOR = Color.decode("#FAFBFF"); + private static final Dimension DEFAULT_SIZE = new Dimension(530, 320); + + //~ Instance fields -------------------------------------------------------- + + // + private JGraphModelAdapter jgAdapter; + + //~ Methods ---------------------------------------------------------------- + + /** + * An alternative starting point for this demo, to also allow running this + * applet as an application. + * + * @param args ignored. + */ + public static void main(String [] args) + { + JGraphAdapterDemo applet = new JGraphAdapterDemo(); + applet.init(); + + JFrame frame = new JFrame(); + frame.getContentPane().add(applet); + frame.setTitle("JGraphT Adapter to JGraph Demo"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + } + + /** + * {@inheritDoc} + */ + public void init() + { + // create a JGraphT graph + ListenableGraph g = + new ListenableDirectedMultigraph( + DefaultEdge.class); + + // create a visualization using JGraph, via an adapter + jgAdapter = new JGraphModelAdapter(g); + + JGraph jgraph = new JGraph(jgAdapter); + + adjustDisplaySettings(jgraph); + getContentPane().add(jgraph); + resize(DEFAULT_SIZE); + + String v1 = "v1"; + String v2 = "v2"; + String v3 = "v3"; + String v4 = "v4"; + + // add some sample data (graph manipulated via JGraphT) + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + g.addVertex(v4); + + g.addEdge(v1, v2); + g.addEdge(v2, v3); + g.addEdge(v3, v1); + g.addEdge(v4, v3); + + // position vertices nicely within JGraph component + positionVertexAt(v1, 130, 40); + positionVertexAt(v2, 60, 200); + positionVertexAt(v3, 310, 230); + positionVertexAt(v4, 380, 70); + + // that's all there is to it!... + } + + private void adjustDisplaySettings(JGraph jg) + { + jg.setPreferredSize(DEFAULT_SIZE); + + Color c = DEFAULT_BG_COLOR; + String colorStr = null; + + try { + colorStr = getParameter("bgcolor"); + } catch (Exception e) { + } + + if (colorStr != null) { + c = Color.decode(colorStr); + } + + jg.setBackground(c); + } + + @SuppressWarnings("unchecked") // FIXME hb 28-nov-05: See FIXME below + private void positionVertexAt(Object vertex, int x, int y) + { + DefaultGraphCell cell = jgAdapter.getVertexCell(vertex); + AttributeMap attr = cell.getAttributes(); + Rectangle2D bounds = GraphConstants.getBounds(attr); + + Rectangle2D newBounds = + new Rectangle2D.Double( + x, + y, + bounds.getWidth(), + bounds.getHeight()); + + GraphConstants.setBounds(attr, newBounds); + + // TODO: Clean up generics once JGraph goes generic + AttributeMap cellAttr = new AttributeMap(); + cellAttr.put(cell, attr); + jgAdapter.edit(cellAttr, null, null, null); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * a listenable directed multigraph that allows loops and parallel edges. + */ + private static class ListenableDirectedMultigraph + extends DefaultListenableGraph + implements DirectedGraph + { + private static final long serialVersionUID = 1L; + + ListenableDirectedMultigraph(Class edgeClass) + { + super(new DirectedMultigraph(edgeClass)); + } + } +} + +// End JGraphAdapterDemo.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/PerformanceDemo.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/PerformanceDemo.java new file mode 100644 index 00000000..0afab349 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/PerformanceDemo.java @@ -0,0 +1,164 @@ +/* ========================================== + * 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. + */ +/* -------------------- + * PerformanceDemo.java + * -------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: PerformanceDemo.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 10-Aug-2003 : Initial revision (BN); + * + */ +package org.jgrapht.demo; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; +import org.jgrapht.traverse.*; + + +/** + * 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.

    + * + * @author Barak Naveh + * @since Aug 10, 2003 + */ +public final class PerformanceDemo +{ + //~ Methods ---------------------------------------------------------------- + + /** + * The starting point for the demo. + * + * @param args ignored. + */ + public static void main(String [] args) + { + long time = System.currentTimeMillis(); + + reportPerformanceFor("starting at", time); + + Graph g = + new Pseudograph(DefaultEdge.class); + Object prev; + Object curr; + + curr = prev = new Object(); + g.addVertex(prev); + + int numVertices = 10000; + int numEdgesPerVertex = 200; + int numElements = numVertices * (1 + numEdgesPerVertex); + + System.out.println( + "\n" + "allocating graph with " + numElements + + " elements (may take a few tens of seconds)..."); + + for (int i = 0; i < numVertices; i++) { + curr = new Object(); + g.addVertex(curr); + + for (int j = 0; j < numEdgesPerVertex; j++) { + g.addEdge(prev, curr); + } + + prev = curr; + } + + reportPerformanceFor("graph allocation", time); + + time = System.currentTimeMillis(); + + for ( + Iterator i = new BreadthFirstIterator(g); + i.hasNext();) + { + i.next(); + } + + reportPerformanceFor("breadth traversal", time); + + time = System.currentTimeMillis(); + + for ( + Iterator i = new DepthFirstIterator(g); + i.hasNext();) + { + i.next(); + } + + reportPerformanceFor("depth traversal", time); + + System.out.println( + "\n" + + "Paused: graph is still in memory (to check mem consumption)."); + System.out.print("press enter to free memory and finish..."); + + try { + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + System.out.println("done."); + } + + private static void reportPerformanceFor(String msg, long refTime) + { + double time = (System.currentTimeMillis() - refTime) / 1000.0; + double mem = usedMemory() + / (1024.0 * 1024.0); + mem = Math.round(mem * 100) / 100.0; + System.out.println(msg + " (" + time + " sec, " + mem + "MB)"); + } + + private static long usedMemory() + { + Runtime rt = Runtime.getRuntime(); + + return rt.totalMemory() - rt.freeMemory(); + } +} + +// End PerformanceDemo.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/package.html new file mode 100644 index 00000000..4aa19132 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/demo/package.html @@ -0,0 +1,6 @@ + + + +Demo programs that help to get started with JGraphT. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/ConnectedComponentTraversalEvent.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/ConnectedComponentTraversalEvent.java new file mode 100644 index 00000000..134be609 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/ConnectedComponentTraversalEvent.java @@ -0,0 +1,103 @@ +/* ========================================== + * 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. + */ +/* ------------------------------------- + * ConnectedComponentTraversalEvent.java + * ------------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: ConnectedComponentTraversalEvent.java 487 2006-07-02 00:53:17Z + * perfecthash $ + * + * Changes + * ------- + * 11-Aug-2003 : Initial revision (BN); + * + */ +package org.jgrapht.event; + +import java.util.*; + + +/** + * A traversal event with respect to a connected component. + * + * @author Barak Naveh + * @since Aug 11, 2003 + */ +public class ConnectedComponentTraversalEvent + extends EventObject +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3834311717709822262L; + + /** + * Connected component traversal started event. + */ + public static final int CONNECTED_COMPONENT_STARTED = 31; + + /** + * Connected component traversal finished event. + */ + public static final int CONNECTED_COMPONENT_FINISHED = 32; + + //~ Instance fields -------------------------------------------------------- + + /** + * The type of this event. + */ + private int type; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new ConnectedComponentTraversalEvent. + * + * @param eventSource the source of the event. + * @param type the type of event. + */ + public ConnectedComponentTraversalEvent(Object eventSource, int type) + { + super(eventSource); + this.type = type; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the event type. + * + * @return the event type. + */ + public int getType() + { + return type; + } +} + +// End ConnectedComponentTraversalEvent.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/EdgeTraversalEvent.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/EdgeTraversalEvent.java new file mode 100644 index 00000000..7225a933 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/EdgeTraversalEvent.java @@ -0,0 +1,93 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * EdgeTraversalEvent.java + * ----------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: EdgeTraversalEvent.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 11-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.event; + +import java.util.*; + + +/** + * A traversal event for a graph edge. + * + * @author Barak Naveh + * @since Aug 11, 2003 + */ +public class EdgeTraversalEvent + extends EventObject +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 4050768173789820979L; + + //~ Instance fields -------------------------------------------------------- + + /** + * The traversed edge. + */ + protected E edge; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new EdgeTraversalEvent. + * + * @param eventSource the source of the event. + * @param edge the traversed edge. + */ + public EdgeTraversalEvent(Object eventSource, E edge) + { + super(eventSource); + this.edge = edge; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the traversed edge. + * + * @return the traversed edge. + */ + public E getEdge() + { + return edge; + } +} + +// End EdgeTraversalEvent.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphChangeEvent.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphChangeEvent.java new file mode 100644 index 00000000..30cbab20 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphChangeEvent.java @@ -0,0 +1,93 @@ +/* ========================================== + * 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. + */ +/* --------------------- + * GraphChangeEvent.java + * --------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: GraphChangeEvent.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 10-Aug-2003 : Initial revision (BN); + * + */ +package org.jgrapht.event; + +import java.util.*; + + +/** + * An event which indicates that a graph has changed. This class is a root for + * graph change events. + * + * @author Barak Naveh + * @since Aug 10, 2003 + */ +public class GraphChangeEvent + extends EventObject +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3834592106026382391L; + + //~ Instance fields -------------------------------------------------------- + + /** + * The type of graph change this event indicates. + */ + protected int type; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new graph change event. + * + * @param eventSource the source of the event. + * @param type the type of event. + */ + public GraphChangeEvent(Object eventSource, int type) + { + super(eventSource); + this.type = type; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the event type. + * + * @return the event type. + */ + public int getType() + { + return type; + } +} + +// End GraphChangeEvent.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphEdgeChangeEvent.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphEdgeChangeEvent.java new file mode 100644 index 00000000..e9712566 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphEdgeChangeEvent.java @@ -0,0 +1,118 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * GraphEdgeChangeEvent.java + * ------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: GraphEdgeChangeEvent.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 10-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.event; + +/** + * 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 {@link + * org.jgrapht.event.GraphChangeEvent#getType()} method. + * + * @author Barak Naveh + * @since Aug 10, 2003 + */ +public class GraphEdgeChangeEvent + extends GraphChangeEvent +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3618134563335844662L; + + /** + * Before edge added event. This event is fired before an edge is added to a + * graph. + */ + public static final int BEFORE_EDGE_ADDED = 21; + + /** + * Before edge removed event. This event is fired before an edge is removed + * from a graph. + */ + public static final int BEFORE_EDGE_REMOVED = 22; + + /** + * Edge added event. This event is fired after an edge is added to a graph. + */ + public static final int EDGE_ADDED = 23; + + /** + * Edge removed event. This event is fired after an edge is removed from a + * graph. + */ + public static final int EDGE_REMOVED = 24; + + //~ Instance fields -------------------------------------------------------- + + /** + * The edge that this event is related to. + */ + protected E edge; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for GraphEdgeChangeEvent. + * + * @param eventSource the source of this event. + * @param type the event type of this event. + * @param e the edge that this event is related to. + */ + public GraphEdgeChangeEvent(Object eventSource, int type, E e) + { + super(eventSource, type); + edge = e; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the edge that this event is related to. + * + * @return the edge that this event is related to. + */ + public E getEdge() + { + return edge; + } +} + +// End GraphEdgeChangeEvent.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphListener.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphListener.java new file mode 100644 index 00000000..e68ca952 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphListener.java @@ -0,0 +1,74 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * GraphListener.java + * ------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: GraphListener.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.event; + +/** + * A listener that is notified when the graph changes. + * + *

    If only notifications on vertex set changes are required it is more + * efficient to use the VertexSetListener.

    + * + * @author Barak Naveh + * @see VertexSetListener + * @since Jul 18, 2003 + */ +public interface GraphListener + extends VertexSetListener +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Notifies that an edge has been added to the graph. + * + * @param e the edge event. + */ + public void edgeAdded(GraphEdgeChangeEvent e); + + /** + * Notifies that an edge has been removed from the graph. + * + * @param e the edge event. + */ + public void edgeRemoved(GraphEdgeChangeEvent e); +} + +// End GraphListener.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphVertexChangeEvent.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphVertexChangeEvent.java new file mode 100644 index 00000000..be07e1b0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/GraphVertexChangeEvent.java @@ -0,0 +1,119 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * GraphVertexChangeEvent.java + * --------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: GraphVertexChangeEvent.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 10-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.event; + +/** + * 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 {@link + * org.jgrapht.event.GraphChangeEvent#getType()} method. + * + * @author Barak Naveh + * @since Aug 10, 2003 + */ +public class GraphVertexChangeEvent + extends GraphChangeEvent +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3690189962679104053L; + + /** + * Before vertex added event. This event is fired before a vertex is added + * to a graph. + */ + public static final int BEFORE_VERTEX_ADDED = 11; + + /** + * Before vertex removed event. This event is fired before a vertex is + * removed from a graph. + */ + public static final int BEFORE_VERTEX_REMOVED = 12; + + /** + * Vertex added event. This event is fired after a vertex is added to a + * graph. + */ + public static final int VERTEX_ADDED = 13; + + /** + * Vertex removed event. This event is fired after a vertex is removed from + * a graph. + */ + public static final int VERTEX_REMOVED = 14; + + //~ Instance fields -------------------------------------------------------- + + /** + * The vertex that this event is related to. + */ + protected V vertex; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new GraphVertexChangeEvent object. + * + * @param eventSource the source of the event. + * @param type the type of the event. + * @param vertex the vertex that the event is related to. + */ + public GraphVertexChangeEvent(Object eventSource, int type, V vertex) + { + super(eventSource, type); + this.vertex = vertex; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the vertex that this event is related to. + * + * @return the vertex that this event is related to. + */ + public V getVertex() + { + return vertex; + } +} + +// End GraphVertexChangeEvent.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/TraversalListener.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/TraversalListener.java new file mode 100644 index 00000000..bcaa2e3c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/TraversalListener.java @@ -0,0 +1,100 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * TraversalListener.java + * ---------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: TraversalListener.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 11-Aug-2003 : Adaptation to new event model (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.event; + +/** + * A listener on graph iterator or on a graph traverser. + * + * @author Barak Naveh + * @since Jul 19, 2003 + */ +public interface TraversalListener +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Called to inform listeners that the traversal of the current connected + * component has finished. + * + * @param e the traversal event. + */ + public void connectedComponentFinished( + ConnectedComponentTraversalEvent e); + + /** + * Called to inform listeners that a traversal of a new connected component + * has started. + * + * @param e the traversal event. + */ + public void connectedComponentStarted(ConnectedComponentTraversalEvent e); + + /** + * 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. + * + * @param e the edge traversal event. + */ + public void edgeTraversed(EdgeTraversalEvent e); + + /** + * 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. + * + * @param e the vertex traversal event. + */ + public void vertexTraversed(VertexTraversalEvent e); + + /** + * 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. + * + * @param e the vertex traversal event. + */ + public void vertexFinished(VertexTraversalEvent e); +} + +// End TraversalListener.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/TraversalListenerAdapter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/TraversalListenerAdapter.java new file mode 100644 index 00000000..502c042f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/TraversalListenerAdapter.java @@ -0,0 +1,93 @@ +/* ========================================== + * 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. + */ +/* ----------------------------- + * TraversalListenerAdapter.java + * ----------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: TraversalListenerAdapter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Aug-2003 : Initial revision (BN); + * 11-Aug-2003 : Adaptation to new event model (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.event; + +/** + * An empty do-nothing implementation of the {@link TraversalListener} interface + * used for subclasses. + * + * @author Barak Naveh + * @since Aug 6, 2003 + */ +public class TraversalListenerAdapter + implements TraversalListener +{ + //~ Methods ---------------------------------------------------------------- + + /** + * @see TraversalListener#connectedComponentFinished(ConnectedComponentTraversalEvent) + */ + public void connectedComponentFinished( + ConnectedComponentTraversalEvent e) + { + } + + /** + * @see TraversalListener#connectedComponentStarted(ConnectedComponentTraversalEvent) + */ + public void connectedComponentStarted(ConnectedComponentTraversalEvent e) + { + } + + /** + * @see TraversalListener#edgeTraversed(EdgeTraversalEvent) + */ + public void edgeTraversed(EdgeTraversalEvent e) + { + } + + /** + * @see TraversalListener#vertexTraversed(VertexTraversalEvent) + */ + public void vertexTraversed(VertexTraversalEvent e) + { + } + + /** + * @see TraversalListener#vertexFinished(VertexTraversalEvent) + */ + public void vertexFinished(VertexTraversalEvent e) + { + } +} + +// End TraversalListenerAdapter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/VertexSetListener.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/VertexSetListener.java new file mode 100644 index 00000000..8cd09b20 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/VertexSetListener.java @@ -0,0 +1,77 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * VertexSetListener.java + * ---------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: VertexSetListener.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.event; + +import java.util.*; + + +/** + * 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. + * + * @author Barak Naveh + * @see GraphListener + * @since Jul 18, 2003 + */ +public interface VertexSetListener + extends EventListener +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Notifies that a vertex has been added to the graph. + * + * @param e the vertex event. + */ + public void vertexAdded(GraphVertexChangeEvent e); + + /** + * Notifies that a vertex has been removed from the graph. + * + * @param e the vertex event. + */ + public void vertexRemoved(GraphVertexChangeEvent e); +} + +// End VertexSetListener.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/VertexTraversalEvent.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/VertexTraversalEvent.java new file mode 100644 index 00000000..9babf8b8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/VertexTraversalEvent.java @@ -0,0 +1,93 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * VertexTraversalEvent.java + * ------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: VertexTraversalEvent.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 11-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.event; + +import java.util.*; + + +/** + * A traversal event for a graph vertex. + * + * @author Barak Naveh + * @since Aug 11, 2003 + */ +public class VertexTraversalEvent + extends EventObject +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3688790267213918768L; + + //~ Instance fields -------------------------------------------------------- + + /** + * The traversed vertex. + */ + protected V vertex; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new VertexTraversalEvent. + * + * @param eventSource the source of the event. + * @param vertex the traversed vertex. + */ + public VertexTraversalEvent(Object eventSource, V vertex) + { + super(eventSource); + this.vertex = vertex; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the traversed vertex. + * + * @return the traversed vertex. + */ + public V getVertex() + { + return vertex; + } +} + +// End VertexTraversalEvent.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/package.html new file mode 100644 index 00000000..9a0bf096 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/event/package.html @@ -0,0 +1,7 @@ + + + +Event classes and listener interfaces, used to provide a change +notification mechanism on graph modification events. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphReader.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphReader.java new file mode 100644 index 00000000..70f1db72 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphReader.java @@ -0,0 +1,174 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * GraphReader.java + * ------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: GraphReader.java 504 2006-07-03 02:37:26Z perfecthash $ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (BN); + * + */ +package org.jgrapht.experimental; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +public class GraphReader + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + // ~ Static fields/initializers -------------------------------------------- + + // ~ Instance fields ------------------------------------------------------- + + private final BufferedReader _in; + + // ~ Constructors ---------------------------------------------------------- + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new GraphReader. + */ + public GraphReader(String file) + throws IOException + { + _in = new BufferedReader(new FileReader(file)); + } + + //~ Methods ---------------------------------------------------------------- + + // ~ Methods --------------------------------------------------------------- + + private List split(String src) + { + final List l = new ArrayList(); + final StringTokenizer tok = new StringTokenizer(src); + while (tok.hasMoreTokens()) { + l.add(tok.nextToken()); + } + return l; + } + + private List skipComments() + { + try { + if (_in.ready()) { + List cols = split(_in.readLine()); + while ( + cols.isEmpty() + || cols.get(0).equals("c") + || cols.get(0).startsWith("%")) + { + cols = split(_in.readLine()); + } + return cols; + } + } catch (IOException e) { + } + return null; + } + + private int readNodeCount() + { + List cols = skipComments(); + if (cols.get(0).equals("p")) { + return Integer.parseInt(cols.get(1)); + } + return -1; + } + + /** + * {@inheritDoc} + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + final int size = readNodeCount(); + if (resultMap == null) { + resultMap = new HashMap(); + } + + for (int i = 0; i < size; i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + resultMap.put(Integer.toString(i + 1), newVertex); + } + List cols = skipComments(); + while (cols != null) { + if (cols.get(0).equals("e")) { + target.addEdge( + resultMap.get(cols.get(1)), + resultMap.get(cols.get(2))); + } + cols = skipComments(); + } + } + + public static void main(String [] args) + throws Exception + { + GraphReader reader = + new GraphReader( + args[0]); + Graph g = + new SimpleGraph( + DefaultEdge.class); + VertexFactory vf = new IntVertexFactory(); + reader.generateGraph(g, vf, null); + System.out.println(g); + } + + //~ Inner Classes ---------------------------------------------------------- + + private static final class IntVertexFactory + implements VertexFactory + { + int last = 0; + + public Integer createVertex() + { + return last++; + } + } +} + +// End GraphReader.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphSquare.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphSquare.java new file mode 100644 index 00000000..be7f39b1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphSquare.java @@ -0,0 +1,219 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * GraphSquare.java + * ---------------------- + * (C) Copyright 2004-2008, by Michael Behrisch and Contributors. + * + * Original Author: Michael Behrisch + * Contributor(s): - + * + * $Id: GraphSquare.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 14-Sep-2004 : Initial revision (MB); + * + */ +package org.jgrapht.experimental; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; +import org.jgrapht.graph.*; + + +/** + * DOCUMENT ME! + * + * @author Michael Behrisch + * @since Sep 14, 2004 + */ +public class GraphSquare + extends AbstractBaseGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -2642034600395594304L; + private static final String UNMODIFIABLE = "this graph is unmodifiable"; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for GraphSquare. + * + * @param g the graph of which a square is to be created. + * @param createLoops + */ + public GraphSquare(final Graph g, final boolean createLoops) + { + super(g.getEdgeFactory(), false, createLoops); + Graphs.addAllVertices(this, g.vertexSet()); + addSquareEdges(g, createLoops); + + if (g instanceof ListenableGraph) { + ((ListenableGraph) g).addGraphListener( + new GraphListener() { + public void edgeAdded(GraphEdgeChangeEvent e) + { + E edge = e.getEdge(); + addEdgesStartingAt( + g, + g.getEdgeSource(edge), + g.getEdgeTarget(edge), + createLoops); + addEdgesStartingAt( + g, + g.getEdgeTarget(edge), + g.getEdgeSource(edge), + createLoops); + } + + public void edgeRemoved(GraphEdgeChangeEvent e) + { // this is not a very performant implementation + GraphSquare.super.removeAllEdges(edgeSet()); + addSquareEdges(g, createLoops); + } + + public void vertexAdded(GraphVertexChangeEvent e) + { + } + + public void vertexRemoved(GraphVertexChangeEvent e) + { + } + }); + } + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#addEdge(Object, Object, E) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllEdges(Collection) + */ + public boolean removeAllEdges(Collection edges) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllEdges(V, V) + */ + public Set removeAllEdges(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllVertices(Collection) + */ + public boolean removeAllVertices(Collection vertices) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeEdge(E) + */ + public boolean removeEdge(E e) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeEdge(V, V) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeVertex(V) + */ + public boolean removeVertex(V v) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + private void addEdgesStartingAt( + final Graph g, + final V v, + final V u, + boolean createLoops) + { + if (!g.containsEdge(v, u)) { + return; + } + + final List adjVertices = Graphs.neighborListOf(g, u); + + for (int i = 0; i < adjVertices.size(); i++) { + final V w = adjVertices.get(i); + + if (g.containsEdge(u, w) && ((v != w) || createLoops)) { + super.addEdge(v, w); + } + } + } + + private void addSquareEdges(Graph g, boolean createLoops) + { + for (V v : g.vertexSet()) { + List adjVertices = Graphs.neighborListOf(g, v); + + for (int i = 0; i < adjVertices.size(); i++) { + addEdgesStartingAt(g, v, adjVertices.get(i), createLoops); + } + } + } +} + +// End GraphSquare.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphTests.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphTests.java new file mode 100644 index 00000000..8c099e1f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/GraphTests.java @@ -0,0 +1,118 @@ +package org.jgrapht.experimental; + +import java.util.*; + +import org.jgrapht.*; + + +public final class GraphTests +{ + //~ Constructors ----------------------------------------------------------- + + private GraphTests() + { + } + + //~ Methods ---------------------------------------------------------------- + + public static boolean isEmpty(Graph g) + { + return g.edgeSet().isEmpty(); + } + + public static boolean isComplete(Graph g) + { + int n = g.vertexSet().size(); + return g.edgeSet().size() + == (n * (n - 1) / 2); + } + + public static boolean isConnected(Graph g) + { + int numVertices = g.vertexSet().size(); + int numEdges = g.edgeSet().size(); + + if (numEdges < (numVertices - 1)) { + return false; + } + if ((numVertices < 2) + || (numEdges > ((numVertices - 1) * (numVertices - 2) / 2))) + { + return true; + } + + Set known = new HashSet(); + LinkedList queue = new LinkedList(); + V v = g.vertexSet().iterator().next(); + + queue.add(v); // start with node 1 + known.add(v); + + while (!queue.isEmpty()) { + v = queue.removeFirst(); + for ( + Iterator it = Graphs.neighborListOf(g, v).iterator(); + it.hasNext();) + { + v = it.next(); + if (!known.contains(v)) { + known.add(v); + queue.add(v); + } + } + } + return known.size() == numVertices; + } + + public static boolean isTree(Graph g) + { + return isConnected(g) + && (g.edgeSet().size() == (g.vertexSet().size() - 1)); + } + + public static boolean isBipartite(Graph g) + { + if ((4 * g.edgeSet().size()) + > (g.vertexSet().size() * g.vertexSet().size())) + { + return false; + } + if (isEmpty(g)) { + return true; + } + + Set unknown = new HashSet(g.vertexSet()); + LinkedList queue = new LinkedList(); + V v = unknown.iterator().next(); + Set odd = new HashSet(); + + queue.add(v); + + while (!unknown.isEmpty()) { + if (queue.isEmpty()) { + queue.add(unknown.iterator().next()); + } + + v = queue.removeFirst(); + unknown.remove(v); + + for ( + Iterator it = Graphs.neighborListOf(g, v).iterator(); + it.hasNext();) + { + V n = it.next(); + if (unknown.contains(n)) { + queue.add(n); + if (!odd.contains(v)) { + odd.add(n); + } + } else if (!(odd.contains(v) ^ odd.contains(n))) { + return false; + } + } + } + return true; + } +} + +// End GraphTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/PartiteRandomGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/PartiteRandomGraphGenerator.java new file mode 100644 index 00000000..e09bf97e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/PartiteRandomGraphGenerator.java @@ -0,0 +1,171 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * PartiteRandomGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by Michael Behrisch and Contributors. + * + * Original Author: Michael Behrisch + * Contributor(s): - + * + * $Id: PartiteRandomGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Sep-2004 : Initial revision (MB); + * + */ +// package org.jgrapht.generate; +package org.jgrapht.experimental; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; + + +/** + * PartiteRandomGraphGenerator generates a partite uniform random + * graph of any size. A partite uniform random graph contains edges chosen + * independently uniformly at random from the set of possible edges between + * partition classes. + * + * @author Michael Behrisch + * @since Sep 13, 2004 + */ +public class PartiteRandomGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private final int [] numVertices; + private final int numEdges; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new PartiteRandomGraphGenerator for a bipartite graph. + * + * @param numVertices1 number of vertices in the first partition + * @param numVertices2 number of vertices in the second partition + * @param numEdges number of edges to be generated + * + * @throws IllegalArgumentException + */ + public PartiteRandomGraphGenerator( + int numVertices1, + int numVertices2, + int numEdges) + { + if ((numVertices1 < 0) || (numVertices2 < 0)) { + throw new IllegalArgumentException("must be non-negative"); + } + + if ((numEdges < 0) || (numEdges > (numVertices1 * numVertices2))) { + throw new IllegalArgumentException("illegal number of edges"); + } + + final int [] numVertices = { + numVertices1, + numVertices2 + }; + this.numVertices = numVertices; + this.numEdges = numEdges; + } + + /** + * Construct a new PartiteRandomGraphGenerator for a k-partite graph. + * + * @param numVertices number of vertices in the k partitions + * @param numEdges number of edges to be generated between any two + * partitions + * + * @throws IllegalArgumentException + */ + public PartiteRandomGraphGenerator(int [] numVertices, int numEdges) + { + if (numEdges < 0) { + throw new IllegalArgumentException("illegal number of edges"); + } + + for (int i = 0; i < numVertices.length; i++) { + if (numVertices[i] < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + for (int j = 0; j < i; j++) { + if (numEdges > (numVertices[i] * numVertices[j])) { + throw new IllegalArgumentException( + "illegal number of edges"); + } + } + } + + this.numVertices = numVertices; + this.numEdges = numEdges; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * TODO hb 30-nov-05: document me + * + * @param target + * @param vertexFactory + * @param resultMap some array of vertices + * + * @see GraphGenerator#generateGraph + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + Object [][] vertices = new Object[numVertices.length][]; + + for (int i = 0; i < numVertices.length; i++) { + vertices[i] = + RandomGraphHelper.addVertices( + target, + vertexFactory, + numVertices[i]); + + if (resultMap != null) { + resultMap.put(Integer.toString(i), vertices[i]); + } + + for (int j = 0; j < i; j++) { + RandomGraphHelper.addEdges( + target, + Arrays.asList(vertices[i]), + Arrays.asList(vertices[j]), + numEdges); + } + } + } +} + +// End PartiteRandomGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/RandomGraphHelper.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/RandomGraphHelper.java new file mode 100644 index 00000000..d91e13d9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/RandomGraphHelper.java @@ -0,0 +1,126 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * RandomGraphHelper.java + * ------------------- + * (C) Copyright 2003-2008, by Michael Behrisch and Contributors. + * + * Original Author: Michael Behrisch + * Contributor(s): - + * + * $Id: RandomGraphHelper.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Sep-2004 : Initial revision (MB); + * + */ +// package org.jgrapht.generate; +package org.jgrapht.experimental; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * UniformRandomGraphGenerator generates a uniform random graph + * of any size. A uniform random graph contains edges chosen independently + * uniformly at random from the set of all possible edges. + * + * @author Michael Behrisch + * @since Sep 13, 2004 + */ +public final class RandomGraphHelper +{ + //~ Static fields/initializers --------------------------------------------- + + private static final Random randSingleton = new Random(); + + //~ Constructors ----------------------------------------------------------- + + /** + * . + */ + private RandomGraphHelper() + { + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see GraphGenerator#generateGraph + */ + @SuppressWarnings("unchecked") + public static void addEdges( + Graph target, + List sourceVertices, + List destVertices, + int numEdges) + { + int sourceSize = sourceVertices.size(); + int destSize = destVertices.size(); + + for (int i = 0; i < numEdges; ++i) { + while ( + target.addEdge( + sourceVertices.get(randSingleton.nextInt( + sourceSize)), + destVertices.get(randSingleton.nextInt(destSize))) + == null) + { + ; + } + } + } + + /** + * . + * + * @param target + * @param vertexFactory + * @param numVertices + * + * @return + */ + @SuppressWarnings("unchecked") + public static Object [] addVertices( + Graph target, + VertexFactory vertexFactory, + int numVertices) + { + Object [] vertices = new Object[numVertices]; + + for (int i = 0; i < numVertices; ++i) { + vertices[i] = vertexFactory.createVertex(); + target.addVertex(vertices[i]); + } + + return vertices; + } +} + +// End RandomGraphHelper.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/UniformRandomGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/UniformRandomGraphGenerator.java new file mode 100644 index 00000000..7f5cf8cf --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/UniformRandomGraphGenerator.java @@ -0,0 +1,115 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * UniformRandomGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by Michael Behrisch and Contributors. + * + * Original Author: Michael Behrisch + * Contributor(s): - + * + * $Id: UniformRandomGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Sep-2004 : Initial revision (MB); + * + */ +// package org.jgrapht.generate; +package org.jgrapht.experimental; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; + + +/** + * UniformRandomGraphGenerator generates a uniform random graph + * of any size. A uniform random graph contains edges chosen independently + * uniformly at random from the set of all possible edges. + * + * @author Michael Behrisch + * @since Sep 13, 2004 + */ +public class UniformRandomGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private final int numEdges; + private final int numVertices; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new UniformRandomGraphGenerator. + * + * @param numVertices number of vertices to be generated + * @param numEdges number of edges to be generated + * + * @throws IllegalArgumentException + */ + public UniformRandomGraphGenerator(int numVertices, int numEdges) + { + if (numVertices < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + if ((numEdges < 0) + || (numEdges > (numVertices * (numVertices - 1) / 2))) + { + throw new IllegalArgumentException("illegal number of edges"); + } + + this.numVertices = numVertices; + this.numEdges = numEdges; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see GraphGenerator#generateGraph + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + Object [] vertices = + RandomGraphHelper.addVertices( + target, + vertexFactory, + numVertices); + RandomGraphHelper.addEdges( + target, + Arrays.asList(vertices), + Arrays.asList(vertices), + numEdges); + } +} + +// End UniformRandomGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/ApproximationAlgorithm.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/ApproximationAlgorithm.java new file mode 100644 index 00000000..d3669968 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/ApproximationAlgorithm.java @@ -0,0 +1,17 @@ +package org.jgrapht.experimental.alg; + +import java.util.*; + + +public interface ApproximationAlgorithm +{ + //~ Methods ---------------------------------------------------------------- + + ResultType getUpperBound(Map optionalData); + + ResultType getLowerBound(Map optionalData); + + boolean isExact(); +} + +// End ApproximationAlgorithm.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/ExactAlgorithm.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/ExactAlgorithm.java new file mode 100644 index 00000000..a3a4a2e1 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/ExactAlgorithm.java @@ -0,0 +1,13 @@ +package org.jgrapht.experimental.alg; + +import java.util.*; + + +public interface ExactAlgorithm +{ + //~ Methods ---------------------------------------------------------------- + + ResultType getResult(Map optionalData); +} + +// End ExactAlgorithm.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/IntArrayGraphAlgorithm.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/IntArrayGraphAlgorithm.java new file mode 100644 index 00000000..1dffaa86 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/IntArrayGraphAlgorithm.java @@ -0,0 +1,50 @@ +/** + * + */ +package org.jgrapht.experimental.alg; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * @author micha + */ +public abstract class IntArrayGraphAlgorithm +{ + //~ Instance fields -------------------------------------------------------- + + protected final List _vertices; + protected final int [][] _neighbors; + protected final Map _vertexToPos; + + //~ Constructors ----------------------------------------------------------- + + /** + * @param g + */ + public IntArrayGraphAlgorithm(final Graph g) + { + final int numVertices = g.vertexSet().size(); + _vertices = new ArrayList(numVertices); + _neighbors = new int[numVertices][]; + _vertexToPos = new HashMap(numVertices); + int index = 0; + for (V vertex : g.vertexSet()) { + _vertices.add(vertex); + _neighbors[index++] = new int[g.edgesOf(vertex).size()]; + _vertexToPos.put(vertex, index); + } + for (int i = 0; i < numVertices; i++) { + int nbIndex = 0; + final V vertex = _vertices.get(i); + for (E e : g.edgesOf(vertex)) { + _neighbors[i][nbIndex++] = + _vertexToPos.get(Graphs.getOppositeVertex(g, e, vertex)); + } + } + } +} + +// End IntArrayGraphAlgorithm.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/color/BrownBacktrackColoring.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/color/BrownBacktrackColoring.java new file mode 100644 index 00000000..503f9af2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/color/BrownBacktrackColoring.java @@ -0,0 +1,97 @@ +/** + * + */ +package org.jgrapht.experimental.alg.color; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.alg.*; + + +/** + * @author micha + */ +public class BrownBacktrackColoring + extends IntArrayGraphAlgorithm + implements ExactAlgorithm +{ + //~ Instance fields -------------------------------------------------------- + + private int [] _color; + private int [] _colorCount; + private BitSet [] _allowedColors; + private int _chi; + + //~ Constructors ----------------------------------------------------------- + + /** + * @param g + */ + public BrownBacktrackColoring(final Graph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + void recursiveColor(int pos) + { + _colorCount[pos] = _colorCount[pos - 1]; + _allowedColors[pos].set(0, _colorCount[pos] + 1); + for (int i = 0; i < _neighbors[pos].length; i++) { + final int nb = _neighbors[pos][i]; + if (_color[nb] > 0) { + _allowedColors[pos].clear(_color[nb]); + } + } + for ( + int i = 1; + (i <= _colorCount[pos]) + && (_colorCount[pos] < _chi); + i++) + { + if (_allowedColors[pos].get(i)) { + _color[pos] = i; + if (pos < (_neighbors.length - 1)) { + recursiveColor(pos + 1); + } else { + _chi = _colorCount[pos]; + } + } + } + if ((_colorCount[pos] + 1) < _chi) { + _colorCount[pos]++; + _color[pos] = _colorCount[pos]; + if (pos < (_neighbors.length - 1)) { + recursiveColor(pos + 1); + } else { + _chi = _colorCount[pos]; + } + } + _color[pos] = 0; + } + + /* (non-Javadoc) + * @see org.jgrapht.experimental.alg.ExactAlgorithm#getResult() + */ + public Integer getResult(Map additionalData) + { + _chi = _neighbors.length; + _color = new int[_neighbors.length]; + _color[0] = 1; + _colorCount = new int[_neighbors.length]; + _colorCount[0] = 1; + _allowedColors = new BitSet[_neighbors.length]; + for (int i = 0; i < _neighbors.length; i++) { + _allowedColors[i] = new BitSet(1); + } + recursiveColor(1); + for (int i = 0; i < _vertices.size(); i++) { + additionalData.put(_vertices.get(i), _color[i]); + } + return _chi; + } +} + +// End BrownBacktrackColoring.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/color/GreedyColoring.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/color/GreedyColoring.java new file mode 100644 index 00000000..109cafd5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/alg/color/GreedyColoring.java @@ -0,0 +1,192 @@ +package org.jgrapht.experimental.alg.color; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.alg.*; + + +public class GreedyColoring + extends IntArrayGraphAlgorithm + implements ApproximationAlgorithm +{ + //~ Static fields/initializers --------------------------------------------- + + public static final int BEST_ORDER = 0; + public static final int NATURAL_ORDER = 1; + public static final int SMALLEST_DEGREE_LAST_ORDER = 2; + public static final int LARGEST_SATURATION_FIRST_ORDER = 3; + + //~ Instance fields -------------------------------------------------------- + + private int _order = BEST_ORDER; + + //~ Constructors ----------------------------------------------------------- + + /** + * @param g + */ + public GreedyColoring(final Graph g) + { + this(g, BEST_ORDER); + } + + /** + * @param g + */ + public GreedyColoring(final Graph g, final int method) + { + super(g); + _order = method; + } + + //~ Methods ---------------------------------------------------------------- + + int color(int [] order) + { + final int [] color = new int[_neighbors.length]; + int maxColor = 1; + BitSet usedColors = new BitSet(_neighbors.length); + + for (int i = 0; i < _neighbors.length; i++) { + final int v = (order == null) ? i : order[i]; + usedColors.clear(); + for (int j = 0; j < _neighbors[v].length; j++) { + final int nb = _neighbors[v][j]; + if (color[nb] > 0) { + usedColors.set(color[nb]); + } + } + color[v] = 1; + while (usedColors.get(color[v])) { + color[v]++; + } + if (color[v] > maxColor) { + maxColor = color[v]; + } + } + return maxColor; + } + + @SuppressWarnings("unchecked") + int [] smallestDegreeLastOrder() + { + final int [] order = new int[_neighbors.length]; + final int [] degree = new int[_neighbors.length]; + final List [] buckets = new List[_neighbors.length]; + int index = _neighbors.length - 1; + + for (int i = 0; i < _neighbors.length; i++) { + buckets[i] = new ArrayList(); + degree[i] = _neighbors[i].length; + } + for (int i = 0; i < _neighbors.length; i++) { + buckets[degree[i]].add(i); + } + for (int i = 0; i < _neighbors.length; i++) { + while (buckets[i].size() > 0) { + final int s = buckets[i].size() - 1; + final int vertex = (Integer) buckets[i].get(s); + buckets[i].remove(s); + degree[vertex] = -1; + order[index--] = vertex; + for (int j = 0; j < _neighbors[vertex].length; j++) { + final int nb = _neighbors[vertex][j]; + if (degree[nb] >= 0) { + buckets[degree[nb]].remove(new Integer(nb)); + degree[nb]--; + buckets[degree[nb]].add(nb); + if (degree[nb] < i) { + i = degree[nb]; + } + } + } + } + } + return order; + } + + int [] largestSaturationFirstOrder() + { + final int [] order = new int[_neighbors.length]; // could be removed + // since buckets + // contains order + // reversed + final int [] satur = new int[_neighbors.length]; + final int [] buckets = new int[_neighbors.length]; + final int [] cumBucketSize = new int[_neighbors.length]; + final int [] bucketIndex = new int[_neighbors.length]; + int index = 0; + int maxSat = 0; + + for (int i = 0; i < _neighbors.length; i++) { + buckets[i] = i; + bucketIndex[i] = i; + } + cumBucketSize[0] = _neighbors.length; + while (index < _neighbors.length) { + while ( + (maxSat > 0) + && (cumBucketSize[maxSat] == cumBucketSize[maxSat - 1])) + { + cumBucketSize[maxSat--] = 0; + } + final int v = buckets[cumBucketSize[maxSat] - 1]; + cumBucketSize[maxSat]--; + satur[v] = -1; + order[index++] = v; + for (int j = 0; j < _neighbors[v].length; j++) { + final int nb = (int) _neighbors[v][j]; + final int bi = bucketIndex[nb]; + if (satur[nb] >= 0) { + if (bi != (cumBucketSize[satur[nb]] - 1)) { + buckets[bi] = buckets[cumBucketSize[satur[nb]] - 1]; + buckets[cumBucketSize[satur[nb]] - 1] = nb; + bucketIndex[nb] = cumBucketSize[satur[nb]] - 1; + bucketIndex[buckets[bi]] = bi; + } + cumBucketSize[satur[nb]]--; + satur[nb]++; + if (cumBucketSize[satur[nb]] == 0) { + cumBucketSize[satur[nb]] = + cumBucketSize[satur[nb] - 1] + 1; + } + if (satur[nb] > maxSat) { + maxSat = satur[nb]; + } + } + } + } + Collections.reverse(Arrays.asList(buckets)); + return buckets; + } + + public Integer getLowerBound(Map optionalData) + { + return 0; + } + + public Integer getUpperBound(Map optionalData) + { + switch (_order) { + case BEST_ORDER: + return Math.min( + Math.min(color(null), color(smallestDegreeLastOrder())), + color(largestSaturationFirstOrder())); + case NATURAL_ORDER: + return color(null); + case SMALLEST_DEGREE_LAST_ORDER: + return color(smallestDegreeLastOrder()); + case LARGEST_SATURATION_FIRST_ORDER: + return color(largestSaturationFirstOrder()); + } + return _neighbors.length; + } + + public boolean isExact() + { + return false; + } +} + +// End GreedyColoring.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/dag/DirectedAcyclicGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/dag/DirectedAcyclicGraph.java new file mode 100644 index 00000000..958ebd17 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/dag/DirectedAcyclicGraph.java @@ -0,0 +1,1199 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * DirectedAcyclicGraph.java + * ------------------- + * (C) Copyright 2008-2008, by Peter Giles and Contributors. + * + * Original Author: Peter Giles + * Contributor(s): John V. Sichi + * + * $Id: DirectedAcyclicGraph.java 637 2008-09-28 22:23:11Z perfecthash $ + * + * Changes + * ------- + * 17-Mar-2008 : Initial revision (PG); + * 23-Aug-2008 : Added VisitedBitSetImpl and made it the default (JVS); + * + */ +package org.jgrapht.experimental.dag; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + *

    DirectedAcyclicGraph implements a DAG that can be modified (vertices & + * edges added and removed), is guaranteed to remain acyclic, and provides fast + * topological order iteration.

    + * + *

    This is done using a dynamic topological sort which is based on the + * algorithm PK described in "D. Pearce & P. Kelly, 2007: A Dynamic + * Topological Sort Algorithm for Directed Acyclic Graphs", (see Paper or ACM link for details). + *

    + * + *

    The implementation differs from the algorithm specified in the above paper + * in some ways, perhaps most notably in that the topological ordering is stored + * by default using two HashMaps, which will have some effects on runtime, but + * also allows for vertex addition and removal, and other operations which are + * helpful for manipulating or combining DAGs. This storage mechanism is + * pluggable for subclassers.

    + * + *

    This class makes no claims to thread safety, and concurrent usage from + * multiple threads will produce undefined results.

    + * + * @author Peter Giles, gilesp@u.washington.edu + */ +public class DirectedAcyclicGraph + extends SimpleDirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 4522128427004938150L; + + //~ Instance fields -------------------------------------------------------- + + private TopoComparator topoComparator; + + private TopoOrderMapping topoOrderMap; + + private int maxTopoIndex = 0; + private int minTopoIndex = 0; + + // this update count is used to keep internal topological iterators honest + private long topologyUpdateCount = 0; + + /** + * Pluggable VisitedFactory implementation + */ + private VisitedFactory visitedFactory = new VisitedBitSetImpl(); + + /** + * Pluggable TopoOrderMappingFactory implementation + */ + private TopoOrderMappingFactory topoOrderFactory = new TopoVertexBiMap(); + + //~ Constructors ----------------------------------------------------------- + + public DirectedAcyclicGraph(Class arg0) + { + super(arg0); + initialize(); + } + + DirectedAcyclicGraph( + Class arg0, + VisitedFactory visitedFactory, + TopoOrderMappingFactory topoOrderFactory) + { + super(arg0); + if (visitedFactory != null) { + this.visitedFactory = visitedFactory; + } + if (topoOrderFactory != null) { + this.topoOrderFactory = topoOrderFactory; + } + initialize(); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * set the topoOrderMap based on the current factory, and create the + * comparator; + */ + private void initialize() + { + topoOrderMap = topoOrderFactory.getTopoOrderMapping(); + topoComparator = new TopoComparator(topoOrderMap); + } + + /** + * iterator will traverse the vertices in topological order, meaning that + * for a directed graph G = (V,E), if there exists a path from vertex va to + * vertex vb then va is guaranteed to come before vertex vb in the iteration + * order. + * + * @return an iterator that will traverse the graph in topological order + */ + public Iterator iterator() + { + return new TopoIterator(); + } + + /** + * adds the vertex if it wasn't already in the graph, and puts it at the top + * of the internal topological vertex ordering + */ + @Override public boolean addVertex(V v) + { + boolean added = super.addVertex(v); + + if (added) { + // add to the top + ++maxTopoIndex; + topoOrderMap.putVertex(maxTopoIndex, v); + + ++topologyUpdateCount; + } + + return added; + } + + /** + * adds the vertex if it wasn't already in the graph, and puts it either at + * the top or the bottom of the topological ordering, depending on the value + * of addToTop. This may provide useful optimizations for merging + * DirectedAcyclicGraphS that become connected. + * + * @param v + * @param addToTop + * + * @return + */ + public boolean addVertex(V v, boolean addToTop) + { + boolean added = super.addVertex(v); + + if (added) { + int insertIndex; + + // add to the top + if (addToTop) { + insertIndex = ++maxTopoIndex; + } else { + insertIndex = --minTopoIndex; + } + topoOrderMap.putVertex(insertIndex, v); + + ++topologyUpdateCount; + } + return added; + } + + /** + *

    Adds the given edge and updates the internal topological order for + * consistency IFF + * + *

      + *
    • there is not already an edge (fromVertex, toVertex) in the graph + *
    • the edge does not induce a cycle in the graph + *
    + *

    + * + * @return null if the edge is already in the graph, else the created edge + * is returned + * + * @throws IllegalArgumentException If either fromVertex or toVertex is not + * a member of the graph + * @throws CycleFoundException if the edge would induce a cycle in the graph + * + * @see Graph#addEdge(Object, Object, Object) + */ + public E addDagEdge(V fromVertex, V toVertex) + throws CycleFoundException + { + Integer lb = topoOrderMap.getTopologicalIndex(toVertex); + Integer ub = topoOrderMap.getTopologicalIndex(fromVertex); + + if ((lb == null) || (ub == null)) { + throw new IllegalArgumentException( + "vertices must be in the graph already!"); + } + + if (lb < ub) { + Set df = new HashSet(); + Set db = new HashSet(); + + // Discovery + Region affectedRegion = new Region(lb, ub); + Visited visited = visitedFactory.getInstance(affectedRegion); + + // throws CycleFoundException if there is a cycle + dfsF(toVertex, df, visited, affectedRegion); + + dfsB(fromVertex, db, visited, affectedRegion); + reorder(df, db, visited); + ++topologyUpdateCount; // if we do a reorder, than the topology has + // been updated + } + + return super.addEdge(fromVertex, toVertex); + } + + /** + * identical to {@link #addDagEdge(Object, Object)}, except an unchecked + * {@link IllegalArgumentException} is thrown if a cycle would have been + * induced by this edge + */ + @Override public E addEdge(V sourceVertex, V targetVertex) + { + E result = null; + try { + result = addDagEdge(sourceVertex, targetVertex); + } catch (CycleFoundException e) { + throw new IllegalArgumentException(e); + } + return result; + } + + /** + *

    Adds the given edge and updates the internal topological order for + * consistency IFF + * + *

      + *
    • the given edge is not already a member of the graph + *
    • there is not already an edge (fromVertex, toVertex) in the graph + *
    • the edge does not induce a cycle in the graph + *
    + *

    + * + * @return true if the edge was added to the graph + * + * @throws CycleFoundException if adding an edge (fromVertex, toVertex) to + * the graph would induce a cycle. + * + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addDagEdge(V fromVertex, V toVertex, E e) + throws CycleFoundException + { + if (e == null) { + throw new NullPointerException(); + } else if (containsEdge(e)) { + return false; + } + + Integer lb = topoOrderMap.getTopologicalIndex(toVertex); + Integer ub = topoOrderMap.getTopologicalIndex(fromVertex); + + if ((lb == null) || (ub == null)) { + throw new IllegalArgumentException( + "vertices must be in the graph already!"); + } + + if (lb < ub) { + Set df = new HashSet(); + Set db = new HashSet(); + + // Discovery + Region affectedRegion = new Region(lb, ub); + Visited visited = visitedFactory.getInstance(affectedRegion); + + // throws CycleFoundException if there is a cycle + dfsF(toVertex, df, visited, affectedRegion); + + dfsB(fromVertex, db, visited, affectedRegion); + reorder(df, db, visited); + ++topologyUpdateCount; // if we do a reorder, than the topology has + // been updated + } + + return super.addEdge(fromVertex, toVertex, e); + } + + /** + * identical to {@link #addDagEdge(Object, Object, Object)}, except an + * unchecked {@link IllegalArgumentException} is thrown if a cycle would + * have been induced by this edge + */ + @Override public boolean addEdge(V sourceVertex, V targetVertex, E edge) + { + boolean result; + try { + result = addDagEdge(sourceVertex, targetVertex, edge); + } catch (CycleFoundException e) { + throw new IllegalArgumentException(e); + } + return result; + } + + // note that this can leave holes in the topological ordering, which + // (depending on the TopoOrderMap implementation) can degrade performance + // for certain operations over time + @Override public boolean removeVertex(V v) + { + boolean removed = super.removeVertex(v); + + if (removed) { + Integer topoIndex = topoOrderMap.removeVertex(v); + + // contract minTopoIndex as we are able + if (topoIndex == minTopoIndex) { + while ( + (minTopoIndex < 0) + && (null == topoOrderMap.getVertex(minTopoIndex))) + { + ++minTopoIndex; + } + } + + // contract maxTopoIndex as we are able + if (topoIndex == maxTopoIndex) { + while ( + (maxTopoIndex > 0) + && (null == topoOrderMap.getVertex(maxTopoIndex))) + { + --maxTopoIndex; + } + } + + ++topologyUpdateCount; + } + + return removed; + } + + @Override public boolean removeAllVertices(Collection arg0) + { + boolean removed = super.removeAllVertices(arg0); + + topoOrderMap.removeAllVertices(); + + maxTopoIndex = 0; + minTopoIndex = 0; + + ++topologyUpdateCount; + + return removed; + } + + /** + * Depth first search forward, building up the set (df) of forward-connected + * vertices in the Affected Region + * + * @param vertex the vertex being visited + * @param df the set we are populating with forward connected vertices in + * the Affected Region + * @param visited a simple data structure that lets us know if we already + * visited a node with a given topo index + * @param topoIndexMap for quick lookups, a map from vertex to topo index in + * the AR + * @param ub the topo index of the original fromVertex -- used for cycle + * detection + * + * @throws CycleFoundException if a cycle is discovered + */ + private void dfsF( + V vertex, + Set df, + Visited visited, + Region affectedRegion) + throws CycleFoundException + { + int topoIndex = topoOrderMap.getTopologicalIndex(vertex); + + // Assumption: vertex is in the AR and so it will be in visited + visited.setVisited(topoIndex); + + df.add(vertex); + + for (E outEdge : outgoingEdgesOf(vertex)) { + V nextVertex = getEdgeTarget(outEdge); + Integer nextVertexTopoIndex = + topoOrderMap.getTopologicalIndex(nextVertex); + + if (nextVertexTopoIndex.intValue() == affectedRegion.finish) { + // reset visited + try { + for (V visitedVertex : df) { + visited.clearVisited( + topoOrderMap.getTopologicalIndex(visitedVertex)); + } + } catch (UnsupportedOperationException e) { + // okay, fine, some implementations (ones that automatically + // clear themselves out) don't work this way + } + throw new CycleFoundException(); + } + + // note, order of checks is important as we need to make sure the + // vertex is in the affected region before we check its visited + // status (otherwise we will be causing an + // ArrayIndexOutOfBoundsException). + if (affectedRegion.isIn(nextVertexTopoIndex) + && !visited.getVisited(nextVertexTopoIndex)) + { + dfsF(nextVertex, df, visited, affectedRegion); // recurse + } + } + } + + /** + * Depth first search backward, building up the set (db) of back-connected + * vertices in the Affected Region + * + * @param vertex the vertex being visited + * @param db the set we are populating with back-connected vertices in the + * AR + * @param visited + * @param topoIndexMap + */ + private void dfsB( + V vertex, + Set db, + Visited visited, + Region affectedRegion) + { + // Assumption: vertex is in the AR and so we will get a topoIndex from + // the map + int topoIndex = topoOrderMap.getTopologicalIndex(vertex); + visited.setVisited(topoIndex); + + db.add(vertex); + + for (E inEdge : incomingEdgesOf(vertex)) { + V previousVertex = getEdgeSource(inEdge); + Integer previousVertexTopoIndex = + topoOrderMap.getTopologicalIndex(previousVertex); + + // note, order of checks is important as we need to make sure the + // vertex is in the affected region before we check its visited + // status (otherwise we will be causing an + // ArrayIndexOutOfBoundsException). + if (affectedRegion.isIn(previousVertexTopoIndex) + && !visited.getVisited(previousVertexTopoIndex)) + { + // if prevousVertexTopoIndex != null, the vertex is in the + // Affected Region according to our topoIndexMap + + dfsB(previousVertex, db, visited, affectedRegion); + } + } + } + + @SuppressWarnings("unchecked") + private void reorder(Set df, Set db, Visited visited) + { + List topoDf = new ArrayList(df); + List topoDb = new ArrayList(db); + + Collections.sort(topoDf, topoComparator); + Collections.sort(topoDb, topoComparator); + + // merge these suckers together in topo order + + SortedSet availableTopoIndices = new TreeSet(); + + // we have to cast to the generic type, can't do "new V[size]" in java + // 5; + V [] bigL = (V []) new Object[df.size() + db.size()]; + int lIndex = 0; // this index is used for the sole purpose of pushing + // into + + // the correct index of bigL + + // assume (for now) that we are resetting visited + boolean clearVisited = true; + + for (V vertex : topoDb) { + Integer topoIndex = topoOrderMap.getTopologicalIndex(vertex); + + // add the available indices to the set + availableTopoIndices.add(topoIndex); + + bigL[lIndex++] = vertex; + + if (clearVisited) { // reset visited status if supported + try { + visited.clearVisited(topoIndex); + } catch (UnsupportedOperationException e) { + clearVisited = false; + } + } + } + + for (V vertex : topoDf) { + Integer topoIndex = topoOrderMap.getTopologicalIndex(vertex); + + // add the available indices to the set + availableTopoIndices.add(topoIndex); + bigL[lIndex++] = vertex; + + if (clearVisited) { // reset visited status if supported + try { + visited.clearVisited(topoIndex); + } catch (UnsupportedOperationException e) { + clearVisited = false; + } + } + } + + lIndex = 0; // reusing lIndex + for (Integer topoIndex : availableTopoIndices) { + // assign the indexes to the elements of bigL in order + V vertex = bigL[lIndex++]; // note the post-increment + topoOrderMap.putVertex(topoIndex, vertex); + } + } + + //~ Inner Interfaces ------------------------------------------------------- + + /** + * For performance tuning, an interface for storing the topological ordering + * + * @author gilesp + */ + public interface TopoOrderMapping + extends Serializable + { + /** + * add a vertex at the given topological index. + * + * @param index + * @param vertex + */ + public void putVertex(Integer index, V vertex); + + /** + * get the vertex at the given topological index. + * + * @param index + * + * @return + */ + public V getVertex(Integer index); + + /** + * get the topological index of the given vertex. + * + * @param vertex + * + * @return the index that the vertex is at, or null if the vertex isn't + * in the topological ordering + */ + public Integer getTopologicalIndex(V vertex); + + /** + * remove the given vertex from the topological ordering + * + * @param vertex + * + * @return the index that the vertex was at, or null if the vertex + * wasn't in the topological ordering + */ + public Integer removeVertex(V vertex); + + /** + * remove all vertices from the topological ordering + */ + public void removeAllVertices(); + } + + public interface TopoOrderMappingFactory + { + public TopoOrderMapping getTopoOrderMapping(); + } + + /** + * this interface allows specification of a strategy for marking vertices as + * visited (based on their topological index, so the vertex type isn't part + * of the interface). + */ + public interface Visited + { + /** + * mark the given topological index as visited + * + * @param index the topological index + */ + public void setVisited(int index); + + /** + * has the given topological index been visited? + * + * @param index the topological index + */ + public boolean getVisited(int index); + + /** + * Clear the visited state of the given topological index + * + * @param index + * + * @throws UnsupportedOperationException if the implementation doesn't + * support (or doesn't need) clearance. For example, if the factory + * vends a new instance every time, it is a waste of cycles to clear the + * state after the search of the Affected Region is done, so an + * UnsupportedOperationException *should* be thrown. + */ + public void clearVisited(int index) + throws UnsupportedOperationException; + } + + /** + * interface for a factory that vends Visited implementations + * + * @author gilesp + */ + public interface VisitedFactory + extends Serializable + { + public Visited getInstance(Region affectedRegion); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Note, this is a lazy and incomplete implementation, with assumptions that + * inputs are in the given topoIndexMap + * + * @param + * + * @author gilesp + */ + private static class TopoComparator + implements Comparator, + Serializable + { + /** + */ + private static final long serialVersionUID = 1L; + + private TopoOrderMapping topoOrderMap; + + public TopoComparator(TopoOrderMapping topoOrderMap) + { + this.topoOrderMap = topoOrderMap; + } + + public int compare(V o1, V o2) + { + return topoOrderMap.getTopologicalIndex(o1).compareTo( + topoOrderMap.getTopologicalIndex(o2)); + } + } + + /** + * a dual HashMap implementation + * + * @author gilesp + */ + private class TopoVertexBiMap + implements TopoOrderMapping, + TopoOrderMappingFactory + { + /** + */ + private static final long serialVersionUID = 1L; + + private final Map topoToVertex = new HashMap(); + private final Map vertexToTopo = new HashMap(); + + public void putVertex(Integer index, V vertex) + { + topoToVertex.put(index, vertex); + vertexToTopo.put(vertex, index); + } + + public V getVertex(Integer index) + { + return topoToVertex.get(index); + } + + public Integer getTopologicalIndex(V vertex) + { + Integer topoIndex = vertexToTopo.get(vertex); + return topoIndex; + } + + public Integer removeVertex(V vertex) + { + Integer topoIndex = vertexToTopo.remove(vertex); + if (topoIndex != null) { + topoToVertex.remove(topoIndex); + } + return topoIndex; + } + + public void removeAllVertices() + { + vertexToTopo.clear(); + topoToVertex.clear(); + } + + public TopoOrderMapping getTopoOrderMapping() + { + return this; + } + } + + /** + * For performance and flexibility uses an ArrayList for topological index + * to vertex mapping, and a HashMap for vertex to topological index mapping. + * + * @author gilesp + */ + public class TopoVertexMap + implements TopoOrderMapping, + TopoOrderMappingFactory + { + /** + */ + private static final long serialVersionUID = 1L; + + private final List topoToVertex = new ArrayList(); + private final Map vertexToTopo = new HashMap(); + + public void putVertex(Integer index, V vertex) + { + int translatedIndex = translateIndex(index); + + // grow topoToVertex as needed to accommodate elements + while ((translatedIndex + 1) > topoToVertex.size()) { + topoToVertex.add(null); + } + + topoToVertex.set(translatedIndex, vertex); + vertexToTopo.put(vertex, index); + } + + public V getVertex(Integer index) + { + return topoToVertex.get(translateIndex(index)); + } + + public Integer getTopologicalIndex(V vertex) + { + return vertexToTopo.get(vertex); + } + + public Integer removeVertex(V vertex) + { + Integer topoIndex = vertexToTopo.remove(vertex); + if (topoIndex != null) { + topoToVertex.set(translateIndex(topoIndex), null); + } + return topoIndex; + } + + public void removeAllVertices() + { + vertexToTopo.clear(); + topoToVertex.clear(); + } + + public TopoOrderMapping getTopoOrderMapping() + { + return this; + } + + /** + * We translate the topological index to an ArrayList index. We have to + * do this because topological indices can be negative, and we want to + * do it because we can make better use of space by only needing an + * ArrayList of size |AR|. + * + * @param unscaledIndex + * + * @return the ArrayList index + */ + private final int translateIndex(int index) + { + if (index >= 0) { + return 2 * index; + } + return -1 * ((index * 2) - 1); + } + } + + /** + * Region is an *inclusive* range of indices. Esthetically displeasing, but + * convenient for our purposes. + * + * @author gilesp + */ + public static class Region + implements Serializable + { + /** + */ + private static final long serialVersionUID = 1L; + + public final int start; + public final int finish; + + public Region(int start, int finish) + { + if (start > finish) { + throw new IllegalArgumentException( + "(start > finish): invariant broken"); + } + this.start = start; + this.finish = finish; + } + + public int getSize() + { + return (finish - start) + 1; + } + + public boolean isIn(int index) + { + return (index >= start) && (index <= finish); + } + } + + /** + * This implementation is close to the performance of VisitedArrayListImpl, + * with 1/8 the memory usage. + * + * @author perfecthash + */ + public static class VisitedBitSetImpl + implements Visited, + VisitedFactory + { + /** + */ + private static final long serialVersionUID = 1L; + + private final BitSet visited = new BitSet(); + + private Region affectedRegion; + + public Visited getInstance(Region affectedRegion) + { + this.affectedRegion = affectedRegion; + + return this; + } + + public void setVisited(int index) + { + visited.set(translateIndex(index), true); + } + + public boolean getVisited(int index) + { + return visited.get(translateIndex(index)); + } + + public void clearVisited(int index) + throws UnsupportedOperationException + { + visited.clear(translateIndex(index)); + } + + /** + * We translate the topological index to an ArrayList index. We have to + * do this because topological indices can be negative, and we want to + * do it because we can make better use of space by only needing an + * ArrayList of size |AR|. + * + * @param unscaledIndex + * + * @return the ArrayList index + */ + private int translateIndex(int index) + { + return index - affectedRegion.start; + } + } + + /** + * This implementation seems to offer the best performance in most cases. It + * grows the internal ArrayList as needed to be as large as |AR|, so it will + * be more memory intensive than the HashSet implementation, and unlike the + * Array implementation, it will hold on to that memory (it expands, but + * never contracts). + * + * @author gilesp + */ + public static class VisitedArrayListImpl + implements Visited, + VisitedFactory + { + /** + */ + private static final long serialVersionUID = 1L; + + private final List visited = new ArrayList(); + + private Region affectedRegion; + + public Visited getInstance(Region affectedRegion) + { + // Make sure visited is big enough + int minSize = (affectedRegion.finish - affectedRegion.start) + 1; + /* plus one because the region range is inclusive of both indices */ + + while (visited.size() < minSize) { + visited.add(Boolean.FALSE); + } + + this.affectedRegion = affectedRegion; + + return this; + } + + public void setVisited(int index) + { + visited.set(translateIndex(index), Boolean.TRUE); + } + + public boolean getVisited(int index) + { + Boolean result = null; + + result = visited.get(translateIndex(index)); + + return result; + } + + public void clearVisited(int index) + throws UnsupportedOperationException + { + visited.set(translateIndex(index), Boolean.FALSE); + } + + /** + * We translate the topological index to an ArrayList index. We have to + * do this because topological indices can be negative, and we want to + * do it because we can make better use of space by only needing an + * ArrayList of size |AR|. + * + * @param unscaledIndex + * + * @return the ArrayList index + */ + private int translateIndex(int index) + { + return index - affectedRegion.start; + } + } + + /** + * This implementation doesn't seem to perform as well, though I can imagine + * circumstances where it should shine (lots and lots of vertices). It also + * should have the lowest memory footprint as it only uses storage for + * indices that have been visited. + * + * @author gilesp + */ + public static class VisitedHashSetImpl + implements Visited, + VisitedFactory + { + /** + */ + private static final long serialVersionUID = 1L; + + private final Set visited = new HashSet(); + + public Visited getInstance(Region affectedRegion) + { + visited.clear(); + return this; + } + + public void setVisited(int index) + { + visited.add(index); + } + + public boolean getVisited(int index) + { + return visited.contains(index); + } + + public void clearVisited(int index) + throws UnsupportedOperationException + { + throw new UnsupportedOperationException(); + } + } + + /** + * This implementation, somewhat to my surprise, is slower than the + * ArrayList version, probably due to its reallocation of the underlying + * array for every topology reorder that is required. + * + * @author gilesp + */ + public static class VisitedArrayImpl + implements Visited, + VisitedFactory + { + /** + */ + private static final long serialVersionUID = 1L; + + private final boolean [] visited; + + private final Region region; + + /** + * Constructs empty factory instance + */ + public VisitedArrayImpl() + { + this(null); + } + + public VisitedArrayImpl(Region region) + { + if (region == null) { // make empty instance + this.visited = null; + this.region = null; + } else { // fill in the needed pieces + this.region = region; + + // initialized to all false by default + visited = new boolean[region.getSize()]; + } + } + + public Visited getInstance(Region affectedRegion) + { + return new VisitedArrayImpl(affectedRegion); + } + + public void setVisited(int index) + { + try { + visited[index - region.start] = true; + } catch (ArrayIndexOutOfBoundsException e) { + /* + log.error("Visited set operation out of region boundaries", e); + */ + throw e; + } + } + + public boolean getVisited(int index) + { + try { + return visited[index - region.start]; + } catch (ArrayIndexOutOfBoundsException e) { + /* + log.error("Visited set operation out of region boundaries", e); + */ + throw e; + } + } + + public void clearVisited(int index) + throws UnsupportedOperationException + { + throw new UnsupportedOperationException(); + } + } + + /** + * Exception used in dfsF when a cycle is found + * + * @author gilesp + */ + public static class CycleFoundException + extends Exception + { + private static final long serialVersionUID = 5583471522212552754L; + } + + /** + * iterator which follows topological order + * + * @author gilesp + */ + private class TopoIterator + implements Iterator + { + private int currentTopoIndex; + private final long updateCountAtCreation; + private Integer nextIndex = null; + + public TopoIterator() + { + updateCountAtCreation = topologyUpdateCount; + currentTopoIndex = minTopoIndex - 1; + } + + public boolean hasNext() + { + if (updateCountAtCreation != topologyUpdateCount) { + throw new ConcurrentModificationException(); + } + + nextIndex = getNextIndex(); + return nextIndex != null; + } + + public V next() + { + if (updateCountAtCreation != topologyUpdateCount) { + throw new ConcurrentModificationException(); + } + + if (nextIndex == null) { + // find nextIndex + nextIndex = getNextIndex(); + } + if (nextIndex == null) { + throw new NoSuchElementException(); + } + currentTopoIndex = nextIndex; + nextIndex = null; + return topoOrderMap.getVertex(currentTopoIndex); //topoToVertex.get(currentTopoIndex); + } + + public void remove() + { + if (updateCountAtCreation != topologyUpdateCount) { + throw new ConcurrentModificationException(); + } + + V vertexToRemove = null; + if (null + != (vertexToRemove = + topoOrderMap.getVertex( + currentTopoIndex))) + { + topoOrderMap.removeVertex(vertexToRemove); + } else { + // should only happen if next() hasn't been called + throw new IllegalStateException(); + } + } + + private Integer getNextIndex() + { + for (int i = currentTopoIndex + 1; i <= maxTopoIndex; i++) { + if (null != topoOrderMap.getVertex(i)) { + return i; + } + } + return null; + } + } +} + +// End DirectedAcyclicGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparator.java new file mode 100644 index 00000000..0df99ad3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparator.java @@ -0,0 +1,93 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EquivalenceComparator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceComparator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +/** + * This interface distinguishes between Equivalence sets. + * + *

    It is similar, in concept, to the Object.hashcode() and Object.equals() + * methods, but instead of checking whether two objects are equal, it is used to + * check whether they are part of the same Equivalence group, where the + * definition of an "equivalence" is defined by the implementation of this + * interface. + * + *

    A specific usage of it is shown below, but it may be used outside of the + * graph-theory class library. + * + *

    In Isomorphism, edges/vertexes matching may relay on none/some/all of the + * vertex/edge properties. For example, if a vertex representing a person + * contains two properties: gender(male/female) and person name(string), we can + * decide that to check isomorphism in vertex groups of gender only. Meaning if + * this is the graph: + * + *

    (male,"Don")---->(female,"Dana")--->(male,"John") + * + *

    if there is no equivalence set at all , this graph can be described as: + * (1)---->(2)---->(3) + * + *

    if the equivalence set is determined only by the gender property : + * (male)---->(female)---->(male) + * + *

    and if it is determined by both properties: (the original figure) The + * isomorphism inspection may return different result according to this choice. + * If the other graph is: (male,"Don")--->(male,"Sunny")---->(male,"Jo") In no + * eq.set they are Isomorphic, but for the two other cases they are not. Other + * examples: Nodes with the same degree, Edges with the same weight, Graphs with + * the same number of nodes and edges. + * + * @param the type of the elements in the set + * @param the type of the context the element is compared against, e.g. a + * Graph + * + * @author Assaf + * @since Jul 15, 2005 + */ +public interface EquivalenceComparator +{ + //~ Methods ---------------------------------------------------------------- + + public boolean equivalenceCompare( + E arg1, + E arg2, + C context1, + C context2); + + public int equivalenceHashcode(E arg1, C context); +} + +// End EquivalenceComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparatorChain.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparatorChain.java new file mode 100644 index 00000000..9affcc0c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparatorChain.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. + */ +/* ----------------- + * EquivalenceComparatorChain.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceComparatorChain.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +/** + * A container of comparators, which are tested in a chain until the first + * result can be supplied. It implements the EquivalenceComparator, so chains + * can include other chains. The first check will use the current comparator and + * not the next one. So, make sure to use the one which has better performance + * first. (This class follows the "Composite" design-pattern). + * + * @param the type of the elements in the set + * @param the type of the context the element is compared against, e.g. a + * Graph + * + * @author Assaf + * @since Jul 22, 2005 + */ +public interface EquivalenceComparatorChain + extends EquivalenceComparator +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Adds a comparator which will also test equivalence. For + * equivalenceCompare(), the return value is a logical AND of the two + * comparators. The first check will use the first comparator before the + * next one. Make sure to put the one which has better performance first. + * For equivalenceHashcode(), the resulting hashes will be rehashed + * together. This method may be used multiple times to create a long "chain" + * of comparators. + */ + public void appendComparator(EquivalenceComparator comparatorAfter); +} + +// End EquivalenceComparatorChain.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparatorChainBase.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparatorChainBase.java new file mode 100644 index 00000000..b6f9fd32 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceComparatorChainBase.java @@ -0,0 +1,167 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EquivalenceComparatorChainBase.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceComparatorChainBase.java 485 2006-06-26 09:12:14Z perfecthash + * $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +import java.util.*; + + +/** + * This class implements comparator chaining. + * + *

    Usage examples: + *

  • graph-theory, node equivalence: You can create a comparator for + * the inDegree of a node, another for the total weight of outDegree edges, and + * a third which checks the business content of the node. You know that the + * first topological comparators has dozens of different groups, but the + * buisness comparator has only two, and they are hard to check . The best + * performance will be gained by: + * + *
    + *

    EquivalenceComparatorChainBase eqChain = new + * EquivalenceComparatorChainBase(fastNodesDegreeComparator); + * + *

    eqChain.addComparatorAfter(ABitSlowerEdgeWeightComparator); + * + *

    eqChain.addComparatorAfter(slowestBuisnessContentsComparator); + *

    + * + * @param the type of the elements in the set + * @param the type of the context the element is compared against, e.g. a + * Graph + * + * @author Assaf + * @since Jul 22, 2005 + */ +public class EquivalenceComparatorChainBase + implements EquivalenceComparatorChain +{ + //~ Instance fields -------------------------------------------------------- + + private List> chain; + + //~ Constructors ----------------------------------------------------------- + + /** + */ + public EquivalenceComparatorChainBase( + EquivalenceComparator firstComaparator) + { + this.chain = + new LinkedList>(); + this.chain.add(firstComaparator); + } + + //~ Methods ---------------------------------------------------------------- + + /* (non-Javadoc) + * @see + * + * + * + * + * + * org.jgrapht.experimental.equivalence.EquivalenceComparatorChain#addComparatorAfter(org.jgrapht.experimental.equivalence.EquivalenceComparator) + */ + @SuppressWarnings("unchecked") + public void appendComparator(EquivalenceComparator comparatorAfter) + { + if (comparatorAfter != null) { + this.chain.add(comparatorAfter); + } + } + + /** + * Implements logical AND between the comparators results. Iterates through + * the comparators chain until one of them returns false. If none returns + * false, this method returns true. + * + * @see EquivalenceComparator#equivalenceCompare(Object, Object, Object, + * Object) + */ + public boolean equivalenceCompare( + E arg1, + E arg2, + C context1, + C context2) + { + for ( + EquivalenceComparator currentComparator + : this.chain) + { + if (!currentComparator.equivalenceCompare( + arg1, + arg2, + context1, + context2)) + { + return false; + } + } + return true; + } + + /** + * Rehashes the concatenation of the results of all single hashcodes. + * + * @see EquivalenceComparator#equivalenceHashcode(Object, Object) + */ + public int equivalenceHashcode(E arg1, C context) + { + StringBuffer hashStringBuffer = new StringBuffer(); + for ( + ListIterator> iter = + this.chain.listIterator(); + iter.hasNext();) + { + EquivalenceComparator currentComparator = + iter.next(); + int currentHashCode = + currentComparator.equivalenceHashcode(arg1, context); + hashStringBuffer.append(currentHashCode); + + // add a delimeter only if needed for next + if (iter.hasNext()) { + hashStringBuffer.append('+'); + } + } + return hashStringBuffer.toString().hashCode(); + } +} + +// End EquivalenceComparatorChainBase.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceSet.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceSet.java new file mode 100644 index 00000000..2295e133 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceSet.java @@ -0,0 +1,215 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EquivalenceSet.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceSet.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +import java.util.*; + + +/** + * EquivalenceSet is a Set of elements which have been determined to be + * equivalent using EquivalenceComparator. The class makes sure the set size + * will be one or more. + *
  • The group can only be created using the factory method + * createGroupWithElement(). + *
  • The equals and hashcode of a group uses the EquivalenceComparator on one + * of the group members, thus it is actually checking whether the "other" is in + * the same group. + * + * @param the type of the elements in the set + * @param the type of the context the element is compared against, e.g. a + * Graph + * + * @author Assaf + * @since Jul 21, 2005 + */ +public class EquivalenceSet +{ + //~ Instance fields -------------------------------------------------------- + + /** + * The comparator used to define the group + */ + protected EquivalenceComparator eqComparator; + protected C comparatorContext; + + /** + * Contains the current elements of the group + */ + protected Set elementsSet; + + //~ Constructors ----------------------------------------------------------- + + /** + * Private constructor. An empty group cannot be created as a group does not + * have meaning without an element, because the equal and hashcode methods + * cannot work. + */ + private EquivalenceSet() + { + } + + /** + * Constructs a new EquivalenceSet, filled with the aElement parameter and a + * reference to the comparator which is used. + */ + public EquivalenceSet( + E aElement, + EquivalenceComparator aEqComparator, + C aComparatorContext) + { + this.eqComparator = aEqComparator; + this.comparatorContext = aComparatorContext; + + this.elementsSet = new HashSet(); + this.elementsSet.add(aElement); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns an arbitrary object from the group. There is no guarantee as to + * which will be returned, and whether the same will be returned on the next + * call. + */ + public E getRepresentative() + { + return elementsSet.iterator().next(); + } + + public C getContext() + { + return this.comparatorContext; + } + + public int size() + { + return elementsSet.size(); + } + + /** + * Adds an element to the group. It does not check it for equivalance . You + * must make sure it does, using equals(). + */ + public void add(E element) + { + this.elementsSet.add(element); + } + + public boolean equivalentTo(E aOther, C aOtherContext) + { + boolean result = + this.eqComparator.equivalenceCompare( + this.getRepresentative(), + aOther, + this.comparatorContext, + aOtherContext); + return result; + } + + /** + * Uses the equivalenceCompare() of the comparator to compare a + * representation of this group, taken using this.getRepresentative(), and a + * representation of the other object, which may be the object itself, or, + * if it is an equivalence group too, other.getRepresentative() + */ + // FIXME REVIEW hb 26-Jan-2006: I think throwing the exception is kind of + // odd, + // - it feels like violating the contract of Object.equals() + // From what I understand, comparing any object to any other object should + // be + // possible at all times and simply return false if they are not equal. + // Uncomparable objects beeing unequal. + // Suggestion: remove the exception, at best, test on this specific class + // and + // write a warning or some such. + + @SuppressWarnings("unchecked") + public boolean equals(Object other) + { + E otherRepresentative = null; + C otherContext = null; + if (other instanceof EquivalenceSet) { + otherRepresentative = + ((EquivalenceSet) other).getRepresentative(); + otherContext = ((EquivalenceSet) other).getContext(); + } else { + throw new ClassCastException( + "can check equal() only of EqualityGroup"); + } + + boolean result = + this.eqComparator.equivalenceCompare( + this.getRepresentative(), + otherRepresentative, + this.comparatorContext, + otherContext); + return result; + } + + /** + * Uses a representative to calculate the group hashcode using + * equivalenceHashcode(). + * + * @see java.lang.Object#hashCode() + */ + public int hashCode() + { + int result = + this.eqComparator.equivalenceHashcode( + this.getRepresentative(), + this.comparatorContext); + return result; + } + + public String toString() + { + return "Eq.Group=" + this.elementsSet.toString(); + } + + /** + * Returns the elements of the group. The order of the elements in the + * returned array is not guaranteed. In other words, two calls to the same + * object may return different order. + */ + public Object [] toArray() + { + return this.elementsSet.toArray(); + } +} + +// End EquivalenceSet.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceSetCreator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceSetCreator.java new file mode 100644 index 00000000..4ec2033b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/EquivalenceSetCreator.java @@ -0,0 +1,261 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EquivalenceSetCreator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceSetCreator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +import java.util.*; + + +/** + * FIXME Document me. + * + * @param the type of the elements in the set + * @param the type of the context the element is compared against, e.g. a + * Graph TODO hb 060208: REVIEW: Using an array for aElementsArray causes + * problems with generics elsewhere - changed to List? + * + * @author Assaf + * @since Jul 21, 2005 + */ +public class EquivalenceSetCreator +{ + //~ Static fields/initializers --------------------------------------------- + + private static final EqGroupSizeComparator groupSizeComparator = + new EqGroupSizeComparator(); + + //~ Methods ---------------------------------------------------------------- + + /** + * Checks for equivalance groups in the aElementsArray. Returns an ordered + * array of them, where the smallest one is the first in the array. + * + * @param aElementsArray + * @param aEqComparator + * + * @deprecated To improve type-safety when using generics, use {@link + * #createEqualityGroupOrderedArray(Collection, EquivalenceComparator, + * Object)} + */ + @Deprecated public static EquivalenceSet [] + createEqualityGroupOrderedArray( + EE [] aElementsArray, + EquivalenceComparator aEqComparator, + CC aContext) + { + return (createEqualityGroupOrderedArray( + Arrays.asList(aElementsArray), + aEqComparator, + aContext)); + // ArrayList> arrayList = new + // ArrayList>(); + // + // HashMap>> map = + // createEqualityGroupMap(aElementsArray, aEqComparator, aContext); + // // each of the map values is a list with one or more groups in + // it. // Object[] array = map.values().toArray(); // for (int i = + // 0; i < array.length; i++) // { // List list = (List)array[i]; + // + // for (List> list : map.values() + // ) { for (EquivalenceSet eSet : list ) { + // arrayList.add( eSet ); } } + // + // + // now we got all the eq. groups in an array list. we need to sort // + // them EquivalenceSet [] resultArray = new EquivalenceSet + // [arrayList.size()]; arrayList.toArray(resultArray); + // Arrays.sort(resultArray, groupSizeComparator); return + // resultArray; + } + + /** + * Checks for equivalance groups in the aElementsArray. Returns an ordered + * array of them, where the smallest one is the first in the array. + * + * @param elements + * @param aEqComparator TODO hb 060208: Using an array for aElementsArray + * causes problems with generics elsewhere - change to List? + */ + public static EquivalenceSet [] createEqualityGroupOrderedArray( + Collection elements, + EquivalenceComparator aEqComparator, + CC aContext) + { + ArrayList> arrayList = + new ArrayList>(); + + HashMap>> map = + createEqualityGroupMap(elements, aEqComparator, aContext); + // each of the map values is a list with one or more groups in it. + // Object[] array = map.values().toArray(); + // for (int i = 0; i < array.length; i++) + // { + // List list = (List)array[i]; + + for (List> list : map.values()) { + for (EquivalenceSet eSet : list) { + arrayList.add(eSet); + } + } + + // now we got all the eq. groups in an array list. we need to sort + // them + EquivalenceSet [] resultArray = new EquivalenceSet[arrayList.size()]; + arrayList.toArray(resultArray); + Arrays.sort(resultArray, groupSizeComparator); + return resultArray; + } + + /** + * The data structure we use to store groups is a map, where the key is + * eqGroupHashCode, and the value is list, containing one or more eqGroup + * which match this hash. + * + * @param elements + * @param aEqComparator + * + * @return a hashmap with key=group hashcode , value = list of eq.groups + * which match that hash. TODO hb 060208: Using an array for aElementsArray + * causes problems with generics elsewhere - change to List? + */ + private static HashMap>> createEqualityGroupMap( + Collection elements, + EquivalenceComparator aEqComparator, + CC aComparatorContext) + { + HashMap>> equalityGroupMap = + new HashMap>>( + elements.size()); + + for (EE curentElement : elements) { + int hashcode = + aEqComparator.equivalenceHashcode( + curentElement, + aComparatorContext); + List> list = + equalityGroupMap.get(Integer.valueOf(hashcode)); + + // determine the type of value. It can be null(no value yet) , + // or a list of EquivalenceSet + + if (list == null) { + // create list with one element in it + list = new LinkedList>(); + list.add( + new EquivalenceSet( + curentElement, + aEqComparator, + aComparatorContext)); + + // This is the first one .add it to the map , in an eqGroup + equalityGroupMap.put(Integer.valueOf(hashcode), list); + } else { + boolean eqWasFound = false; + + // we need to check the groups in the list. If none are good, + // create a new one + for (EquivalenceSet eqGroup : list) { + if (eqGroup.equivalentTo( + curentElement, + aComparatorContext)) + { + // add it to the list and break + eqGroup.add(curentElement); + eqWasFound = true; + break; + } + } + + // if no match was found add it to the list as a new group + if (!eqWasFound) { + list.add( + new EquivalenceSet( + curentElement, + aEqComparator, + aComparatorContext)); + } + } + } + + return equalityGroupMap; + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Functor used to order groups by size (number of elements in the group) + * from the smallest to the biggest. If they have the same size, uses the + * hashcode of the group to compare from the smallest to the biggest. Note + * that it is inconsistent with equals(). See Object.equals() javadoc. + * + * @author Assaf + * @since Jul 22, 2005 + */ + private static class EqGroupSizeComparator + implements Comparator + { + /** + * compare by size , then (if size equal) by hashcode + * + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public int compare(EquivalenceSet arg1, EquivalenceSet arg2) + { + int eqGroupSize1 = arg1.size(); + int eqGroupSize2 = arg2.size(); + if (eqGroupSize1 > eqGroupSize2) { + return 1; + } else if (eqGroupSize1 < eqGroupSize2) { + return -1; + } else { // size equal , compare hashcodes + int eqGroupHash1 = arg1.hashCode(); + int eqGroupHash2 = arg2.hashCode(); + if (eqGroupHash1 > eqGroupHash2) { + return 1; + } else if (eqGroupHash1 < eqGroupHash2) { + return -1; + } else { + return 0; + } + } + } + } +} + +// End EquivalenceSetCreator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/UniformEquivalenceComparator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/UniformEquivalenceComparator.java new file mode 100644 index 00000000..5cef7d7e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/UniformEquivalenceComparator.java @@ -0,0 +1,80 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * UniformEquivalenceComparator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: UniformEquivalenceComparator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +/** + * This Equivalence comparator acts as if all elements are in one big global + * equivalence class. Useful when a comparator is needed, but there is no + * important difference between the elements. equivalenceCompare() always return + * true; equivalenceHashcode() always returns 0. + * + * @author Assaf + * @since Jul 21, 2005 + */ +public class UniformEquivalenceComparator + implements EquivalenceComparator +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Always returns true. + * + * @see EquivalenceComparator#equivalenceCompare(Object, Object, Object, + * Object) + */ + public boolean equivalenceCompare( + E arg1, + E arg2, + C context1, + C context2) + { + return true; + } + + /** + * Always returns 0. + * + * @see EquivalenceComparator#equivalenceHashcode(Object, Object) + */ + public int equivalenceHashcode(E arg1, C context) + { + return 0; + } +} + +// End UniformEquivalenceComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/package.html new file mode 100644 index 00000000..dbc6049f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/equivalence/package.html @@ -0,0 +1,6 @@ + + + +Classes which enable working with Equivalence Sets. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/AbstractExhaustiveIsomorphismInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/AbstractExhaustiveIsomorphismInspector.java new file mode 100644 index 00000000..d60683ce --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/AbstractExhaustiveIsomorphismInspector.java @@ -0,0 +1,423 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * AbstractExhaustiveIsomorphismInspector.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: AbstractExhaustiveIsomorphismInspector.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; +import org.jgrapht.experimental.permutation.*; +import org.jgrapht.util.*; + + +/** + * Abstract base for isomorphism inspectors which exhaustively test the possible + * mappings between graphs. The current algorithms do not support graphs with + * multiple edges (Multigraph / Pseudograph). For the maintainer: The reason is + * the use of GraphOrdering which currently does not support all graph types. + * + * @author Assaf Lehr + * @since May 20, 2005 ver5.3 + */ +abstract class AbstractExhaustiveIsomorphismInspector + implements GraphIsomorphismInspector +{ + //~ Static fields/initializers --------------------------------------------- + + public static EquivalenceComparator + edgeDefaultIsomorphismComparator = + new UniformEquivalenceComparator(); + public static EquivalenceComparator + vertexDefaultIsomorphismComparator = + new UniformEquivalenceComparator(); + + //~ Instance fields -------------------------------------------------------- + + protected EquivalenceComparator> + edgeComparator; + protected EquivalenceComparator> + vertexComparator; + + protected Graph graph1; + protected Graph graph2; + + private PrefetchIterator nextSupplier; + + // kept as member, to ease computations + private GraphOrdering lableGraph1; + private LinkedHashSet graph1VertexSet; + private LinkedHashSet graph2EdgeSet; + private CollectionPermutationIter vertexPermuteIter; + private Set currVertexPermutation; // filled every iteration, used in the + + //~ Constructors ----------------------------------------------------------- + + // result relation. + + /** + * @param graph1 + * @param graph2 + * @param vertexChecker eq. group checker for vertexes. If null, + * UniformEquivalenceComparator will be used as default (always return true) + * @param edgeChecker eq. group checker for edges. If null, + * UniformEquivalenceComparator will be used as default (always return true) + */ + public AbstractExhaustiveIsomorphismInspector( + Graph graph1, + Graph graph2, + + // XXX hb 060128: FOllowing parameter may need Graph + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + this.graph1 = graph1; + this.graph2 = graph2; + + if (vertexChecker != null) { + this.vertexComparator = vertexChecker; + } else { + this.vertexComparator = vertexDefaultIsomorphismComparator; + } + + // Unlike vertexes, edges have better performance, when not tested for + // Equivalence, so if the user did not supply one, use null + // instead of edgeDefaultIsomorphismComparator. + + if (edgeChecker != null) { + this.edgeComparator = edgeChecker; + } + + init(); + } + + /** + * Constructor which uses the default comparators. + * + * @param graph1 + * @param graph2 + * + * @see #AbstractExhaustiveIsomorphismInspector(Graph,Graph,EquivalenceComparator,EquivalenceComparator) + */ + public AbstractExhaustiveIsomorphismInspector( + Graph graph1, + Graph graph2) + { + this( + graph1, + graph2, + edgeDefaultIsomorphismComparator, + vertexDefaultIsomorphismComparator); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Inits needed data-structures , among them: + *
  • LabelsGraph which is a created in the image of graph1 + *
  • vertexPermuteIter which is created after the vertexes were divided to + * equivalence groups. This saves order-of-magnitude in performance, because + * the number of possible permutations dramatically decreases. + * + *

    for example: if the eq.group are even/odd - only two groups. A graph + * with consist of 10 nodes of which 5 are even , 5 are odd , will need to + * test 5!*5! (14,400) instead of 10! (3,628,800). + * + *

    besides the EquivalenceComparator`s supplied by the user, we also use + * predefined topological comparators. + */ + private void init() + { + this.nextSupplier = + new PrefetchIterator( + + // XXX hb 280106: I don't understand this warning, yet :-) + new NextFunctor()); + + this.graph1VertexSet = new LinkedHashSet(this.graph1.vertexSet()); + + // vertexPermuteIter will be null, if there is no match + this.vertexPermuteIter = + createPermutationIterator( + this.graph1VertexSet, + this.graph2.vertexSet()); + + this.lableGraph1 = + new GraphOrdering( + this.graph1, + this.graph1VertexSet, + this.graph1.edgeSet()); + + this.graph2EdgeSet = new LinkedHashSet(this.graph2.edgeSet()); + } + + /** + * Creates the permutation iterator for vertexSet2 . The subclasses may make + * either cause it to depend on equality groups or use vertexSet1 for it. + * + * @param vertexSet1 [i] may be reordered + * @param vertexSet2 [i] may not. + * + * @return permutation iterator + */ + protected abstract CollectionPermutationIter createPermutationIterator( + Set vertexSet1, + Set vertexSet2); + + /** + *

    1. Creates a LabelsGraph of graph1 which will serve as a source to all + * the comparisons which will follow. + * + *

    2. extract the edge array of graph2; it will be permanent too. + * + *

    3. for each permutation of the vertexes of graph2, test : + * + *

    3.1. vertices + * + *

    3.2. edges (in labelsgraph) + * + *

    Implementation Notes and considerations: Let's consider a trivial + * example: graph of strings "A","B","C" with two edges A->B,B->C. Let's + * assume for this example that the vertex comparator always returns true, + * meaning String value does not matter, only the graph structure does. So + * "D" "E" "A" with D->E->A will be isomorphic , but "A","B,"C"with + * A->B,A->C will not. + * + *

    First let's extract the important info for isomorphism from the graph. + * We don't care what the vertexes are, we care that there are 3 of them + * with edges from first to second and from second to third. So the source + * LabelsGraph will be: vertexes:[1,2,3] edges:[[1->2],[2->3]] Now we will + * do several permutations of D,E,A. A few examples: D->E , E->A + * [1,2,3]=[A,D,E] so edges are: 2->3 , 3->1 . does it match the source? NO. + * [1,2,3]=[D,A,E] so edges are: 1->3 , 3->2 . no match either. + * [1,2,3]=[D,E,A] so edges are: 1->2 , 2->3 . MATCH FOUND ! Trivial + * algorithm: We will iterate on all permutations + * [abc][acb][bac][bca][cab][cba]. (n! of them,3!=6) For each, first compare + * vertexes using the VertexComparator(always true). Then see that the edges + * are in the exact order 1st->2nd , 2nd->3rd. If we found a match stop and + * return true, otherwise return false; we will compare vetices and edges by + * their order (1st,2nd,3rd,etc) only. Two graphs are the same, by this + * order, if: 1. for each i, sourceVertexArray[i] is equivalent to + * targetVertexArray[i] 2. for each vertex, the edges which start in it (it + * is the source) goes to the same ordered vertex. For multiple ones, count + * them too. + * + * @return IsomorphismRelation for a permutation found, or null if no + * permutation was isomorphic + */ + private IsomorphismRelation findNextIsomorphicGraph() + { + boolean result = false; + IsomorphismRelation resultRelation = null; + if (this.vertexPermuteIter != null) { + // System.out.println("Souce LabelsGraph="+this.lableGraph1); + while (this.vertexPermuteIter.hasNext()) { + currVertexPermutation = this.vertexPermuteIter.getNextSet(); + + // compare vertexes + if (!areVertexSetsOfTheSameEqualityGroup( + this.graph1VertexSet, + currVertexPermutation)) + { + continue; // this one is not iso, so try the next one + } + + // compare edges + GraphOrdering currPermuteGraph = + new GraphOrdering( + this.graph2, + currVertexPermutation, + this.graph2EdgeSet); + + // System.out.println("target LablesGraph="+currPermuteGraph); + if (this.lableGraph1.equalsByEdgeOrder(currPermuteGraph)) { + // create result object. + resultRelation = + new IsomorphismRelation( + new ArrayList(graph1VertexSet), + new ArrayList(currVertexPermutation), + graph1, + graph2); + + // if the edge comparator exists, check equivalence by it + boolean edgeEq = + areAllEdgesEquivalent( + resultRelation, + this.edgeComparator); + if (edgeEq) // only if equivalent + + { + result = true; + break; + } + } + } + } + + if (result == true) { + return resultRelation; + } else { + return null; + } + } + + /** + * Will be called on every two sets of vertexes returned by the permutation + * iterator. From findNextIsomorphicGraph(). Should make sure that the two + * sets are euqivalent. Subclasses may decide to implements it as an always + * true methods only if they make sure that the permutationIterator will + * always be already equivalent. + * + * @param vertexSet1 FIXME Document me + * @param vertexSet2 FIXME Document me + */ + protected abstract boolean areVertexSetsOfTheSameEqualityGroup( + Set vertexSet1, + Set vertexSet2); + + /** + * For each edge in g1, get the Correspondence edge and test the pair. + * + * @param resultRelation + * @param edgeComparator if null, always return true. + */ + protected boolean areAllEdgesEquivalent( + IsomorphismRelation resultRelation, + EquivalenceComparator> edgeComparator) + { + boolean checkResult = true; + + if (edgeComparator == null) { + // nothing to check + return true; + } + + try { + Set edgeSet = this.graph1.edgeSet(); + + for (E currEdge : edgeSet) { + E correspondingEdge = + resultRelation.getEdgeCorrespondence(currEdge, true); + + // if one edge test fail , fail the whole method + if (!edgeComparator.equivalenceCompare( + currEdge, + correspondingEdge, + this.graph1, + this.graph2)) + { + checkResult = false; + break; + } + } + } catch (IllegalArgumentException illegal) { + checkResult = false; + } + + return checkResult; + } + + /** + * return nextElement() casted as IsomorphismRelation + */ + public IsomorphismRelation nextIsoRelation() + { + return next(); + } + + /** + * Efficiency: The value is known after the first check for isomorphism + * activated on this class and returned there after in O(1). If called on a + * new ("virgin") class, it activates 1 iso-check. + * + * @return true iff the two graphs are isomorphic + */ + public boolean isIsomorphic() + { + return !(this.nextSupplier.isEnumerationStartedEmpty()); + } + + /* (non-Javadoc) + * @see java.util.Enumeration#hasMoreElements() + */ + public boolean hasNext() + { + boolean result = this.nextSupplier.hasMoreElements(); + + return result; + } + + /** + * @see java.util.Iterator#next() + */ + public IsomorphismRelation next() + { + return this.nextSupplier.nextElement(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException( + "remove() method is not supported in AdaptiveIsomorphismInspectorFactory." + + " There is no meaning to removing an isomorphism result."); + } + + //~ Inner Classes ---------------------------------------------------------- + + private class NextFunctor + implements PrefetchIterator.NextElementFunctor + { + public IsomorphismRelation nextElement() + throws NoSuchElementException + { + IsomorphismRelation resultRelation = findNextIsomorphicGraph(); + if (resultRelation != null) { + return resultRelation; + } else { + throw new NoSuchElementException( + "IsomorphismInspector does not have any more elements"); + } + } + } +} + +// End AbstractExhaustiveIsomorphismInspector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/AdaptiveIsomorphismInspectorFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/AdaptiveIsomorphismInspectorFactory.java new file mode 100644 index 00000000..0e06238c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/AdaptiveIsomorphismInspectorFactory.java @@ -0,0 +1,268 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * AdaptiveIsomorphismInspectorFactory.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: AdaptiveIsomorphismInspectorFactory.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; +import org.jgrapht.graph.*; + + +/** + * This class serves as a factory for GraphIsomorphismInspector concrete + * implementations. It can be used in two ways: + *

  • You can can let this class to determine what is the most efficient + * algorithm for your graph. + *
  • You can specify the type of your graph (planar / tree / other) and save + * this class the graph-checking time. + * + *

    Note that the concrete implementations are package-private and should not + * be created directly. If you are the maintainer of the package, you can add + * new implementation classes, and add them to the "check-list". The current + * algorithms do not support graphs with multiple edges (Multigraph / + * Pseudograph) + * + * @author Assaf + * @see GraphIsomorphismInspector + * @since Jul 17, 2005 + */ +public class AdaptiveIsomorphismInspectorFactory +{ + //~ Static fields/initializers --------------------------------------------- + + public static final int GRAPH_TYPE_ARBITRARY = 0; + public static final int GRAPH_TYPE_PLANAR = 1; + public static final int GRAPH_TYPE_TREE = 2; + public static final int GRAPH_TYPE_MULTIGRAPH = 3; + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates a new inspector, letting this class determine what is the most + * efficient algorithm. + * + * @param graph1 + * @param graph2 + * @param vertexChecker may be null + * @param edgeChecker may be null + */ + public static GraphIsomorphismInspector createIsomorphismInspector( + Graph graph1, + Graph graph2, + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + int graphType = checkGraphsType(graph1, graph2); + return createAppropriateConcreteInspector( + graphType, + graph1, + graph2, + vertexChecker, + edgeChecker); + } + + /** + * Creates a new inspector, letting this class determine what is the most + * efficient algorithm and using default equivalence comparators. + * + *

    same as calling createIsomorphismInspector(graph1,graph2,null,null); + * + * @param graph1 + * @param graph2 + */ + public static GraphIsomorphismInspector createIsomorphismInspector( + Graph graph1, + Graph graph2) + { + return createIsomorphismInspector(graph1, graph2, null, null); + } + + /** + * Creates a new inspector for a particular graph type (planar / tree / + * other). + * + * @param type - AdaptiveIsomorphismInspectorFactory.GRAPH_TYPE_XXX + * @param graph1 + * @param graph2 + * @param vertexChecker - can be null + * @param edgeChecker - can be null + */ + public static GraphIsomorphismInspector + createIsomorphismInspectorByType( + int type, + Graph graph1, + Graph graph2, + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + return createAppropriateConcreteInspector( + type, + graph1, + graph2, + vertexChecker, + edgeChecker); + } + + /** + * Creates a new inspector for a particular graph type (planar / tree / + * other) using default equivalence comparators. + * + *

    same as calling + * createAppropriateConcreteInspector(graph1,graph2,null,null); + * + * @param type - AdaptiveIsomorphismInspectorFactory.GRAPH_TYPE_XXX + * @param graph1 + * @param graph2 + */ + public static GraphIsomorphismInspector + createIsomorphismInspectorByType( + int type, + Graph graph1, + Graph graph2) + { + return createAppropriateConcreteInspector( + type, + graph1, + graph2, + null, + null); + } + + /** + * Checks the graph type, and accordingly decides which type of concrete + * inspector class to create. This implementation creates an exhaustive + * inspector without further tests, because no other implementations are + * available yet. + * + * @param graph1 + * @param graph2 + * @param vertexChecker + * @param edgeChecker + */ + protected static GraphIsomorphismInspector + createAppropriateConcreteInspector( + int graphType, + Graph graph1, + Graph graph2, + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + assertUnsupportedGraphTypes(graph1); + assertUnsupportedGraphTypes(graph2); + GraphIsomorphismInspector currentInspector = null; + + switch (graphType) { + case GRAPH_TYPE_PLANAR: + case GRAPH_TYPE_TREE: + case GRAPH_TYPE_ARBITRARY: + currentInspector = + createTopologicalExhaustiveInspector( + graph1, + graph2, + vertexChecker, + edgeChecker); + break; + + default: + + throw new IllegalArgumentException( + "The type was not one of the supported types."); + } + return currentInspector; + } + + /** + * Checks if one of the graphs is from unsupported graph type and throws + * IllegalArgumentException if it is. The current unsupported types are + * graphs with multiple-edges. + * + * @param graph1 + * @param graph2 + * + * @throws IllegalArgumentException + */ + protected static void assertUnsupportedGraphTypes(Graph g) + throws IllegalArgumentException + { + if ((g instanceof Multigraph) + || (g instanceof DirectedMultigraph) + || (g instanceof Pseudograph)) + { + throw new IllegalArgumentException( + "graph type not supported for the graph" + g); + } + } + + protected static int checkGraphsType(Graph graph1, Graph graph2) + { + return GRAPH_TYPE_ARBITRARY; + } + + /** + * @return ExhaustiveInspector, where the equivalence comparator is chained + * with a topological comparator. This implementation uses: + *

  • vertex degree size comparator + */ + @SuppressWarnings("unchecked") + protected static GraphIsomorphismInspector + createTopologicalExhaustiveInspector( + Graph graph1, + Graph graph2, + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + VertexDegreeEquivalenceComparator degreeComparator = + new VertexDegreeEquivalenceComparator(); + EquivalenceComparatorChain> vertexChainedChecker = + new EquivalenceComparatorChainBase>( + degreeComparator); + vertexChainedChecker.appendComparator(vertexChecker); + + GraphIsomorphismInspector inspector = + + // FIXME hb060208 I don't understand how to generify this, yet + new EquivalenceIsomorphismInspector( + graph1, + graph2, + vertexChainedChecker, + edgeChecker); + return inspector; + } +} + +// End AdaptiveIsomorphismInspectorFactory.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/EquivalenceIsomorphismInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/EquivalenceIsomorphismInspector.java new file mode 100644 index 00000000..38dd3311 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/EquivalenceIsomorphismInspector.java @@ -0,0 +1,325 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EquivalenceIsomorphismInspector.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceIsomorphismInspector.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; +import org.jgrapht.experimental.permutation.*; + + +/** + * The current implementation uses the vertexComparator to greatly increase the + * test speed by dividing the vertexes into equivalent groups and permuting + * inside them only. The EdgeComparator is used to test edges, but not to make a + * finer division, thus it adds overhead. Use it only when needed. + * + * @author Assaf + * @since Jul 29, 2005 + */ +class EquivalenceIsomorphismInspector + extends AbstractExhaustiveIsomorphismInspector +{ + //~ Constructors ----------------------------------------------------------- + + /** + * @param graph1 + * @param graph2 + * @param vertexChecker eq. group checker for vertexes. If null, + * UniformEquivalenceComparator will be used as default (always return true) + * @param edgeChecker eq. group checker for edges. If null, + * UniformEquivalenceComparator will be used as default (always return true) + */ + public EquivalenceIsomorphismInspector( + Graph graph1, + Graph graph2, + + // XXX hb 060128: FOllowing parameter may need Graph + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + super(graph1, graph2, vertexChecker, edgeChecker); + } + + /** + * Constructor which uses the default comparators. + * + * @see ExhaustiveIsomorphismInspector(Graph,Graph,EquivalenceComparator,EquivalenceComparator) + */ + public EquivalenceIsomorphismInspector( + Graph graph1, + Graph graph2) + { + super(graph1, graph2); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates the permutation iterator according to equivalance class. + * + *

    1. Get the eq.group (ordered by size) array of the source vertex set + * (vertexSet1) + * + *

    2. Get the eq.group ordered array of vertexSet2. + * + *

    3. Reorder the second array to match the group order of the first + * array sets. 4. Use CompoundPermutationIter (and not regular + * IntegerPermutationIter) to permute only inside groups. + * + *

    + *

    That's it. If the eq.group comaparator is strong enough to provide + * small groups, this algortihm will produce a small possible permutations + * numbers. example: G1: [A,B,F,X,Y] [A->B,B->X,X->Y] + * + *

    G2: [D,Z,C,U,F] [D->C,Z->C,U->Z] + * + *

    vertexEq: three groups , one all letters A-E , second all letters S-Z + * , third the letter 'f'. 1. [(f)size=1, (X,Y)size=2 , (A,B)size=2] 2. + * [(f)size=1 ,(C,D)size=2 , (Z,U)size=2] 3. the match is done by reordering + * the second array to have the equiviavlant order :##[(f)size=1 , + * (Z,U)size=2 , (C,D)size=2]## 4.for example G2 will not do all 5!=120 + * permutations , but 2!x2!x1!=4 permutations only which are: (of the 3rd + * array) [ F, Z , U , C , D ] [ F, Z , U , D , C ] [ F, U , Z, C , D ] [ F, + * U , Z , D , C ] + * + * @return null, if the eq.group do not match (there cannot be any + * permutation for eq.groups) or the sets do not match in size; otherwise, + * the permutationiterator otherwise + * + * @see AbstractExhaustiveIsomorphismInspector#createPermutationIterator(Set, + * Set) + */ + @SuppressWarnings("unchecked") + protected CollectionPermutationIter createPermutationIterator( + Set vertexSet1, + Set vertexSet2) + { + if (vertexSet1.size() != vertexSet2.size()) { + // throw new IllegalArgumentException("the two vertx-sets + // parameters must be of" + // +"the same size. The first size was:"+vertexSet1.size() + // +" the other size was:" +vertexSet2.size() ); + return null; // only instead of exception + } + + // 1// + EquivalenceSet [] eqGroupArray1 = + EquivalenceSetCreator.createEqualityGroupOrderedArray( + vertexSet1, + this.vertexComparator, + this.graph1); + + // 2// + EquivalenceSet [] eqGroupArray2 = + EquivalenceSetCreator.createEqualityGroupOrderedArray( + vertexSet2, + this.vertexComparator, + this.graph2); + + // 3// + boolean reorderSuccess = + reorderTargetArrayToMatchSourceOrder(eqGroupArray1, eqGroupArray2); // 2 is the taget + if (!reorderSuccess) { + // if reordering fail , no match can be done + return null; + } + + // reorder set1 (source), so when we work with the flat array of the + // second array, + // the permutations will be relevant. + // note that it does not start in any way related to eqGroup sizes. + + V [] reorderingVertexSet1Temp = (V []) new Object[vertexSet1.size()]; + fillElementsflatArray(eqGroupArray1, reorderingVertexSet1Temp); + vertexSet1.clear(); + vertexSet1.addAll(Arrays.asList(reorderingVertexSet1Temp)); + + // 4//use CompoundPermutationIter to permute only inside groups. + // the CollectionPermutationIter needs a array/set of objects and a + // permuter which will + // work on that set/array order. lets make these two: + // 1. create array of the vertexes , by flattening the eq.group array + // contents + + V [] flatVertexArray = (V []) new Object[vertexSet2.size()]; + fillElementsflatArray(eqGroupArray2, flatVertexArray); + + // 2. make the permuter according to the groups size + int [] groupSizesArray = new int[eqGroupArray1.length]; + + // iterate over the EqualityGroup array + for ( + int eqGroupCounter = 0; + eqGroupCounter < eqGroupArray2.length; + eqGroupCounter++) + { + // now for (.2.) size count + groupSizesArray[eqGroupCounter] = + eqGroupArray2[eqGroupCounter].size(); + } + + ArrayPermutationsIter arrayPermIter = + PermutationFactory.createByGroups(groupSizesArray); + CollectionPermutationIter vertexPermIter = + new CollectionPermutationIter( + Arrays.asList(flatVertexArray), + arrayPermIter); + + return vertexPermIter; + } + + /** + * Reorders inplace targetArray + * + *

    rules: + *

  • try to match only group of the same size and then hashcode + *
  • it is enough to choose one from each group to see if a match exist. + * + *

    Algorithm: hold counters in the two arrays. [a,b,c,d,e] assume groups + * are:a,(b,c,d),e [a,c,d,b,e] c1=0 , c2=0 check if eqvivalent . if not , + * advance , as long as both size and hashcode are the same. if found a + * match , swap the group positions in array2. if not , throws + * IllegalArgumentExcpetion. Assumption: array size is the same. not + * checked. + * + * @param sourceArray + * @param targetArray + * + * @return true if the array was reordered successfully. false if not(It + * will happen if there is no complete match between the groups) + */ + private boolean reorderTargetArrayToMatchSourceOrder( + EquivalenceSet [] sourceArray, + EquivalenceSet [] targetArray) + { + boolean result = true; + for ( + int sourceIndex = 0; + sourceIndex < sourceArray.length; + sourceIndex++) + { + int currTargetIndex = sourceIndex; + + // if they are already equivalent do nothing. + EquivalenceSet sourceEqGroup = sourceArray[sourceIndex]; + EquivalenceSet targetEqGroup = targetArray[currTargetIndex]; + if (!sourceEqGroup.equals(targetEqGroup)) { + // iterate through the next group in the targetArray until + // a new size or hashcode is seen + boolean foundMatch = false; + int sourceSize = sourceEqGroup.size(); + int sourceHashCode = sourceEqGroup.hashCode(); + while ( + (targetEqGroup.size() == sourceSize) + && (targetEqGroup.hashCode() == sourceHashCode) + && (currTargetIndex < (targetArray.length - 1))) + { + currTargetIndex++; + targetEqGroup = targetArray[currTargetIndex]; + if (targetEqGroup.equals(sourceEqGroup)) { + foundMatch = true; + + // swap . targetEqGroup will serve as the temp + // variable. + targetArray[currTargetIndex] = targetArray[sourceIndex]; + targetArray[sourceIndex] = targetEqGroup; + } + } + if (!foundMatch) { + // a match was not found + // throw new IllegalArgumentException("could not reorder + // the array , because the groups don`t match"); + result = false; + break; + } + } + } + return result; + } + + /** + * @param eqGroupArray + * @param flatArray an empy array with the proper size + */ + protected void fillElementsflatArray( + EquivalenceSet [] eqGroupArray, + Object [] flatVertexArray) + { + int flatVertexArrayNextFree = 0; // the next free place in the array + + // iterate over the EqualityGroup array + for ( + int eqGroupCounter = 0; + eqGroupCounter < eqGroupArray.length; + eqGroupCounter++) + { + Object [] currGroupArray = eqGroupArray[eqGroupCounter].toArray(); + + // copy this small array to the free place in the big + // flatVertexArray + System.arraycopy( + currGroupArray, // src + 0, // srcPos + flatVertexArray, // dest + flatVertexArrayNextFree, // destPos + currGroupArray.length // length + ); + flatVertexArrayNextFree += currGroupArray.length; + } + } + + /** + * We know for sure, that the sets are alreay checked for equivalence , so + * it will return true without any further checks. + * + * @see AbstractExhaustiveIsomorphismInspector#areVertexSetsOfTheSameEqualityGroup( + * Set, Set) + */ + protected boolean areVertexSetsOfTheSameEqualityGroup( + Set vertexSet1, + Set vertexSet2) + { + return true; + } +} + +// End EquivalenceIsomorphismInspector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/GraphIsomorphismInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/GraphIsomorphismInspector.java new file mode 100644 index 00000000..f9cc75c0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/GraphIsomorphismInspector.java @@ -0,0 +1,95 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * GraphIsomorphismInspector.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: GraphIsomorphismInspector.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + + +/** + * Isomorphism Overview + * + *

    Isomorphism is the problem of testing whether two graphs are topologically + * the same. Suppose we are given a collection of graphs and must perform some + * operation on each of them. If we can identify which of the graphs are + * duplicates, they can be discarded so as to avoid redundant work. + * + *

    In Formal Math: Input description: Two graphs, G and H. Problem + * description: Find a (or all) mappings f of the vertices of G to the + * vertices of H such that G and H are identical; i.e. (x,y) is an edge of G iff + * (f(x),f(y)) is an edge of H. + * http://www2.toki.or.id/book/AlgDesignManual/BOOK/BOOK4/NODE180.HTM. + * + *

    Efficiency: The general algorithm is not polynomial, however + * polynomial algorithms are known for special cases, like acyclic graphs, + * planar graphs etc. There are several heuristic algorithms which gives quite + * good results (polynomial) in general graphs, for most but not all cases. + * + *

    Usage: + * + *

      + *
    1. Choose comparators for the vertexes and edges. You may use the default + * comparator by sending null parameters for them to the constructor. Example: + * Assume Your graphs are of human relations. Each vertex is either a man or a + * woman and also has the person name. You may decide that isomorphism is + * checked according to gender, but not according to the specific name. So you + * will create a comparator that distinguishes vertexes only according to + * gender. + *
    2. Use the isIsomorphic() method as a boolean test for isomorphism + *
    3. Use the Iterator interface to iterate through all the possible + * isomorphism ordering. + *
    + * + * @author Assaf Lehr + * @since Jul 15, 2005 + */ +// REVIEW jvs 5-Sept-2005: Since we're using JDK1.5 now, we should be +// able to declare this as Iterator, correct? Otherwise +// the caller doesn't even know what they're getting back. +public interface GraphIsomorphismInspector + extends Iterator +{ + //~ Methods ---------------------------------------------------------------- + + /** + * @return true iff the two graphs are isomorphic + */ + public boolean isIsomorphic(); +} + +// End GraphIsomorphismInspector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/GraphOrdering.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/GraphOrdering.java new file mode 100644 index 00000000..08a875a2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/GraphOrdering.java @@ -0,0 +1,232 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * GraphOrdering.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: GraphOrdering.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * Holds graph information as int labels only. vertexes: 1,2,3,4 edges:1->2 , + * 3->4 ,1->1. Implementation as imutable graph by int[] for vetexes and + * LabelsEdge[] for edges. The current algorithms do not support graph with + * multiple edges (Multigraph / Pseudograph). For the maintaner: The reason for + * it is the use of edges sets of LabelsEdge in which the equals checks for + * source and target vertexes. Thus there cannot be two LabelsEdge with the same + * source and target in the same Set. + * + * @author Assaf + * @since May 20, 2005 + */ +public class GraphOrdering +{ + //~ Instance fields -------------------------------------------------------- + + /** + * Holds a mapping between key=V(vertex) and value=Integer(vertex order). It + * can be used for identifying the order of regular vertex/edge. + */ + private Map mapVertexToOrder; + + /** + * Holds a HashSet of all LabelsGraph of the graph. + */ + private Set labelsEdgesSet; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new labels graph according to the regular graph. After its + * creation they will no longer be linked, thus changes to one will not + * affect the other. + * + * @param regularGraph + */ + public GraphOrdering(Graph regularGraph) + { + this(regularGraph, regularGraph.vertexSet(), regularGraph.edgeSet()); + } + + /** + * Creates a new labels graph according to the regular graph. After its + * creation they will no longer be linked, thus changes to one will not + * affect the other. + * + * @param regularGraph + * @param vertexSet + * @param edgeSet + */ + public GraphOrdering( + Graph regularGraph, + Set vertexSet, + Set edgeSet) + { + init(regularGraph, vertexSet, edgeSet); + } + + //~ Methods ---------------------------------------------------------------- + + private void init(Graph g, Set vertexSet, Set edgeSet) + { + // create a map between vertex value to its order(1st,2nd,etc) + // "CAT"=1 "DOG"=2 "RHINO"=3 + + this.mapVertexToOrder = new HashMap(vertexSet.size()); + + int counter = 0; + for (V vertex : vertexSet) { + mapVertexToOrder.put(vertex, new Integer(counter)); + counter++; + } + + // create a friendlier representation of an edge + // by order, like 2nd->3rd instead of B->A + // use the map to convert vertex to order + // on directed graph, edge A->B must be (A,B) + // on undirected graph, edge A-B can be (A,B) or (B,A) + + this.labelsEdgesSet = new HashSet(edgeSet.size()); + for (E edge : edgeSet) { + V sourceVertex = g.getEdgeSource(edge); + Integer sourceOrder = mapVertexToOrder.get(sourceVertex); + int sourceLabel = sourceOrder.intValue(); + int targetLabel = + (mapVertexToOrder.get(g.getEdgeTarget(edge))).intValue(); + + LabelsEdge lablesEdge = new LabelsEdge(sourceLabel, targetLabel); + this.labelsEdgesSet.add(lablesEdge); + + if (g instanceof UndirectedGraph) { + LabelsEdge oppositeEdge = + new LabelsEdge(targetLabel, sourceLabel); + this.labelsEdgesSet.add(oppositeEdge); + } + } + } + + /** + * Tests equality by order of edges + */ + public boolean equalsByEdgeOrder(GraphOrdering otherGraph) + { + boolean result = + this.getLabelsEdgesSet().equals(otherGraph.getLabelsEdgesSet()); + + return result; + } + + public Set getLabelsEdgesSet() + { + return labelsEdgesSet; + } + + /** + * This is the format example: + * + *
    +       mapVertexToOrder=        labelsOrder=
    +     * 
    + */ + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("mapVertexToOrder="); + + // vertex will be printed in their order + Object [] vertexArray = new Object[this.mapVertexToOrder.size()]; + Set keySet = this.mapVertexToOrder.keySet(); + for (V currVertex : keySet) { + Integer index = this.mapVertexToOrder.get(currVertex); + vertexArray[index.intValue()] = currVertex; + } + sb.append(Arrays.toString(vertexArray)); + sb.append("labelsOrder=").append(this.labelsEdgesSet.toString()); + return sb.toString(); + } + + //~ Inner Classes ---------------------------------------------------------- + + private class LabelsEdge + { + private int source; + private int target; + private int hashCode; + + public LabelsEdge(int aSource, int aTarget) + { + this.source = aSource; + this.target = aTarget; + this.hashCode = + new String(this.source + "" + this.target).hashCode(); + } + + /** + * Checks both source and target. Does not check class type to be fast, + * so it may throw ClassCastException. Careful! + * + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) + { + LabelsEdge otherEdge = (LabelsEdge) obj; + if ((this.source == otherEdge.source) + && (this.target == otherEdge.target)) + { + return true; + } else { + return false; + } + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() + { + return this.hashCode; // filled on constructor + } + + public String toString() + { + return this.source + "->" + this.target; + } + } +} + +// End GraphOrdering.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/IsomorphismRelation.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/IsomorphismRelation.java new file mode 100644 index 00000000..e5071c41 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/IsomorphismRelation.java @@ -0,0 +1,151 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * IsomorphismRelation.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: IsomorphismRelation.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Holds an isomorphism relation for two graphs. It contains a mapping between + * the two graphs. + * + *

    Usage: + * + *

      + *
    1. use getVertexCorrespondence() or + * getEdgeCorrespondence() to get the mapped object in the other graph. + *
    + * + *

    + *

    It consists of two vertexes array , the i-th vertex in the 1st array is + * the isomorphic eqv. of the i-th in 2nd array. Note that the getters are + * unsafe (they return the array and not a copy of it). + * + * @author Assaf + * @since May 27, 2005 + */ +public class IsomorphismRelation + implements GraphMapping +{ + //~ Instance fields -------------------------------------------------------- + + private List vertexList1; + private List vertexList2; + + private GraphMapping graphMapping = null; + + private Graph graph1; + private Graph graph2; + + //~ Constructors ----------------------------------------------------------- + + /** + */ + public IsomorphismRelation( + List aGraph1vertexArray, + List aGraph2vertexArray, + Graph g1, + Graph g2) + { + this.vertexList1 = aGraph1vertexArray; + this.vertexList2 = aGraph2vertexArray; + this.graph1 = g1; + this.graph2 = g2; + } + + //~ Methods ---------------------------------------------------------------- + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("vertexList1: ").append( + this.vertexList1.toString()); + sb.append("\tvertexList2: ").append( + this.vertexList2.toString()); + return sb.toString(); + } + + public V getVertexCorrespondence(V vertex, boolean forward) + { + // lazy initializer for graphMapping + if (graphMapping == null) { + initGraphMapping(); + } + + return graphMapping.getVertexCorrespondence(vertex, forward); + } + + public E getEdgeCorrespondence(E edge, boolean forward) + { + // lazy initializer for graphMapping + if (graphMapping == null) { + initGraphMapping(); + } + + return graphMapping.getEdgeCorrespondence(edge, forward); + } + + /** + * We currently have the vertexes array. From them we will construct two + * maps: g1ToG2 and g2ToG1, using the array elements with the same index. + */ + private void initGraphMapping() + { + int mapSize = vertexList1.size(); + Map g1ToG2 = new HashMap(mapSize); + Map g2ToG1 = new HashMap(mapSize); + + for (int i = 0; i < mapSize; i++) { + V source = this.vertexList1.get(i); + V target = this.vertexList2.get(i); + g1ToG2.put(source, target); + g2ToG1.put(target, source); + } + this.graphMapping = + new DefaultGraphMapping( + g1ToG2, + g2ToG1, + this.graph1, + this.graph2); + } +} + +// End IsomorphismRelation.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/PermutationIsomorphismInspector.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/PermutationIsomorphismInspector.java new file mode 100644 index 00000000..c8ad67df --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/PermutationIsomorphismInspector.java @@ -0,0 +1,148 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * PermutationIsomorphismInspector.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: PermutationIsomorphismInspector.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; +import org.jgrapht.experimental.permutation.*; + + +/** + * Checks every possible permutation. + * + *

    It does not uses the graph topology to enhance the performance. It is + * recommended to use only if there cannot be a useful division into equivalence + * sets. + * + * @author Assaf + * @since Jul 29, 2005 + */ +class PermutationIsomorphismInspector + extends AbstractExhaustiveIsomorphismInspector +{ + //~ Constructors ----------------------------------------------------------- + + /** + * @param graph1 + * @param graph2 + * @param vertexChecker eq. group checker for vertexes. If null, + * UniformEquivalenceComparator will be used as default (always return true) + * @param edgeChecker eq. group checker for edges. If null, + * UniformEquivalenceComparator will be used as default (always return true) + */ + public PermutationIsomorphismInspector( + Graph graph1, + Graph graph2, + + // XXX hb 060128: FOllowing parameter may need Graph + EquivalenceComparator> vertexChecker, + EquivalenceComparator> edgeChecker) + { + super(graph1, graph2, vertexChecker, edgeChecker); + } + + /** + * Constructor which uses the default comparators. + * + * @see AbstractExhaustiveIsomorphismInspector#AbstractExhaustiveIsomorphismInspector(Graph, + * Graph) + */ + public PermutationIsomorphismInspector( + Graph graph1, + Graph graph2) + { + super(graph1, graph2); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates the permutation iterator, not dependant on equality group, or the + * other vertexset. + * + * @param vertexSet1 FIXME Document me + * @param vertexSet2 FIXME Document me + * + * @return the permutation iterator + */ + protected CollectionPermutationIter createPermutationIterator( + Set vertexSet1, + Set vertexSet2) + { + return new CollectionPermutationIter(vertexSet2); + } + + /** + * FIXME Document me FIXME Document me + * + * @param vertexSet1 FIXME Document me + * @param vertexSet2 FIXME Document me + * + * @return FIXME Document me + */ + protected boolean areVertexSetsOfTheSameEqualityGroup( + Set vertexSet1, + Set vertexSet2) + { + if (vertexSet1.size() != vertexSet2.size()) { + return false; + } + Iterator iter2 = vertexSet2.iterator(); + + // only check hasNext() of one , cause they are of the same size + for (Iterator iter1 = vertexSet1.iterator(); iter1.hasNext();) { + V vertex1 = iter1.next(); + V vertex2 = iter2.next(); + if (!this.vertexComparator.equivalenceCompare( + vertex1, + vertex2, + this.graph1, + this.graph2)) + { + return false; + } + } + return true; + } +} + +// End PermutationIsomorphismInspector.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/VertexDegreeEquivalenceComparator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/VertexDegreeEquivalenceComparator.java new file mode 100644 index 00000000..f372692b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/VertexDegreeEquivalenceComparator.java @@ -0,0 +1,178 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * VertexDegreeEquivalenceComparator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: VertexDegreeEquivalenceComparator.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; + + +/** + * Two vertexes are equivalent under this comparator if and only if: + * + *

      + *
    1. they have the same IN degree + * + *

      AND + *

    2. they have the same OUT degree + *
    + * + * @author Assaf + * @since Jul 21, 2005 + */ +public class VertexDegreeEquivalenceComparator + implements EquivalenceComparator> +{ + //~ Constructors ----------------------------------------------------------- + + /** + */ + public VertexDegreeEquivalenceComparator() + { + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Compares the in degrees and the out degrees of the two vertexes. + * + *

    One may reside in an Undirected Graph and the other in a Directed + * graph, or both on the same graph type. + * + * @see EquivalenceComparator#equivalenceCompare(Object, Object, Object, + * Object) + */ + public boolean equivalenceCompare( + V vertex1, + V vertex2, + Graph context1, + Graph context2) + { + // note that VertexDegreeComparator cannot be used. It supports only + // directed graphs. + InOutDegrees inOut1 = getInOutDegrees(context1, vertex1); + InOutDegrees inOut2 = getInOutDegrees(context2, vertex2); + boolean result = inOut1.equals(inOut2); + return result; + } + + /** + * Hashes using the in & out degree of a vertex + * + * @see EquivalenceComparator#equivalenceHashcode(Object, Object) + */ + public int equivalenceHashcode(V vertex, Graph context) + { + InOutDegrees inOut = getInOutDegrees(context, vertex); + + // hash it using the string hash. use the format N '-' N + StringBuffer sb = new StringBuffer(); + sb.append(String.valueOf(inOut.inDegree)); + sb.append("-"); // to diffrentiate inner and outer + sb.append(String.valueOf(inOut.outDegree)); + return sb.toString().hashCode(); + } + + /** + * Calculates the In and Out degrees of vertexes. Supported graph types: + * UnDirectedGraph, DirectedGraph. In UnDirected graph, the in = out (as if + * it was undirected and every edge is both an in and out edge) + * + * @param aContextGraph + * @param vertex + */ + protected InOutDegrees getInOutDegrees(Graph aContextGraph, + V vertex) + { + int inVertexDegree = 0; + int outVertexDegree = 0; + if (aContextGraph instanceof UndirectedGraph) { + UndirectedGraph undirectedGraph = + (UndirectedGraph) aContextGraph; + inVertexDegree = undirectedGraph.degreeOf(vertex); + outVertexDegree = inVertexDegree; // it is UNdirected + } else if (aContextGraph instanceof DirectedGraph) { + DirectedGraph directedGraph = + (DirectedGraph) aContextGraph; + inVertexDegree = directedGraph.inDegreeOf(vertex); + outVertexDegree = directedGraph.outDegreeOf(vertex); + } else { + throw new RuntimeException( + "contextGraph is of unsupported type . It must be one of these two :" + + " UndirectedGraph or DirectedGraph"); + } + return new InOutDegrees(inVertexDegree, outVertexDegree); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Simple structure used to hold the two ints: vertex in degree and vertex + * out degree. Useful as returned value for methods which calculate both at + * the same time. + * + * @author Assaf + * @since Jul 21, 2005 + */ + protected class InOutDegrees + { + public int inDegree; + public int outDegree; + + public InOutDegrees(int aInDegree, int aOutDegree) + { + this.inDegree = aInDegree; + this.outDegree = aOutDegree; + } + + /** + * Checks both inDegree and outDegree. Does not check class type to save + * time. If should be used with caution. + * + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) + { + InOutDegrees other = (InOutDegrees) obj; + return ((this.inDegree == other.inDegree) + && (this.outDegree == other.outDegree)); + } + } +} + +// End VertexDegreeEquivalenceComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/package.html new file mode 100644 index 00000000..07c613fe --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/isomorphism/package.html @@ -0,0 +1,6 @@ + + + +Algorithms which provide isomorphism check between two graphs. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/package.html new file mode 100644 index 00000000..2686daf0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/package.html @@ -0,0 +1,11 @@ + + + +

    A package that contains experimental work or work-in-progress that +is not yet ready to be included in a release. It may contain classes +that are: incomplete, not yet documented, have not yet reached a +satisfying form, etc.

    + +

    The only requirement for classes included here is to compile.

    + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/ArrayPermutationsIter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/ArrayPermutationsIter.java new file mode 100644 index 00000000..ddfe624c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/ArrayPermutationsIter.java @@ -0,0 +1,56 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * ArrayPermutationsIter.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: ArrayPermutationsIter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.permutation; + +/** + * An interface to iterate over array permutations. Similiar to Iterator, but + * with specific return types and without the remove() method. + * + * @author Assaf + * @since Jul 29, 2005 + */ +public interface ArrayPermutationsIter +{ + //~ Methods ---------------------------------------------------------------- + + public int [] nextPermutation(); + + public boolean hasNextPermutaions(); +} + +// End ArrayPermutationsIter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/CollectionPermutationIter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/CollectionPermutationIter.java new file mode 100644 index 00000000..47a23028 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/CollectionPermutationIter.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. + */ +/* ----------------- + * CollectionPermutationIter.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: CollectionPermutationIter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.permutation; + +import java.util.*; + + +/** + * Given a container with elements (Collection,Enumeration,array) defines a + * permutation iterator which returns, on each iteration, a differnt permutation + * of the source container. You may choose a different container + * type(Collection/Array/etc) for each next call. It will continue as if they + * were the same iterator. + * + * @author Assaf + * @since May 20, 2005 + */ +public class CollectionPermutationIter +{ + //~ Instance fields -------------------------------------------------------- + + private ArrayPermutationsIter permOrder; + private List sourceArray; + + /** + * change everry calculation.can be retrieved publicly + */ + private int [] currPermutationArray; + + //~ Constructors ----------------------------------------------------------- + + /** + * Note: the Set interface does not guarantee iteration order. This method + * iterates on the set to get the initial order and after that the data will + * be saved internally in another (ordered) container. So, remeber that the + * Initial order can be different from the objectSet.toString() method. If + * you want it to be the same, use a LinkedHashSet , or use the array + * constructor. + * + * @param objectsSet + */ + public CollectionPermutationIter(Set objectsSet) + { + this( + new ArrayList(objectsSet), + new IntegerPermutationIter(objectsSet.size())); + } + + /** + * Uses a permArray like [1,1,1,2] where some of the permutations are not + * relevant. Here there will be 4 permutations (only the '2' position is + * important) + * + * @param objectsArray + * @param permuter + */ + public CollectionPermutationIter(List objectsArray) + { + this( + objectsArray, + new IntegerPermutationIter(objectsArray.size())); + } + + public CollectionPermutationIter( + List objectsArray, + ArrayPermutationsIter permuter) + { + this.permOrder = permuter; + this.sourceArray = objectsArray; + } + + //~ Methods ---------------------------------------------------------------- + + public boolean hasNext() + { + return this.permOrder.hasNextPermutaions(); + } + + /** + * On first call, returns the source as an array; on any other call + * thereafter, a new permutation + * + * @return null if we overflowed! the array otherwise + */ + public List getNextArray() + { + List permutationResult; // will hold the array result + if (this.permOrder.hasNextPermutaions()) { + this.currPermutationArray = this.permOrder.nextPermutation(); + permutationResult = applyPermutation(); + } else { + permutationResult = null; + } + + return permutationResult; + } + + private List applyPermutation() + { + ArrayList output = new ArrayList(sourceArray); + + // Example : this.sourceArray = ["A","B","C","D"] + // perOrder: = [ 1 , 0 , 3 , 2 ] + // result : = ["B","A","D","C"] + for (int i = 0; i < output.size(); i++) { + output.set( + i, + this.sourceArray.get(this.currPermutationArray[i])); + } + return output; + } + + /** + * Wrap result to a Set. + * + * @return null if we overflowed! the set otherwise + */ + public Set getNextSet() + { + List result = getNextArray(); + if (result == null) { + return null; + } else // wrap in a SET + { + Set resultSet = new LinkedHashSet(result); + return resultSet; + } + } + + public int [] getCurrentPermutationArray() + { + return this.currPermutationArray; + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("Permutation int[]="); + sb.append(Arrays.toString(getCurrentPermutationArray())); + + List permutationResult = applyPermutation(); + sb.append("\nPermutationSet Source Object[]="); + sb.append(this.sourceArray.toString()); + sb.append("\nPermutationSet Result Object[]="); + sb.append(permutationResult.toString()); + return sb.toString(); + } +} + +// End CollectionPermutationIter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/CompoundPermutationIter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/CompoundPermutationIter.java new file mode 100644 index 00000000..666871e4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/CompoundPermutationIter.java @@ -0,0 +1,307 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * CompoundPermutationIter.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: CompoundPermutationIter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.permutation; + +import java.util.*; + +import org.jgrapht.util.*; + + +/** + * For permutation like this: + *
  • 1,2 are the same eq.group (numbers) + *
  • a,b are og the same eq.group (letters) + *
  • '$' is of its own eq. group (signs) Let the order of the group be + * (arbitrary): signs,numbers,letters (note that for performance reasons, this + * arbitrary order is the worst! see Performance section below) + * + *

    These are the possible compound perm: [$,1,2,a,b,c] + * + *

    [$,1,2,a,c,b] + * + *

    [$,1,2,b,a,c] + * + *

    [$,1,2,b,c,a] + * + *

    [$,1,2,c,a,b] + * + *

    [$,1,2,c,b,a] + * + *

    [$,2,1,a,b,c] + * + *

    [$,2,1,a,c,b] + * + *

    [$,2,1,b,a,c] + * + *

    [$,2,1,b,c,a] + * + *

    [$,2,1,c,a,b] + * + *

    [$,2,1,c,b,a] + * + *

    The overall number is the product of the factorials of each eq. group + * size; in our example : (1!)x(2!)x(3!)=1x2x6=12. Using the constructor with + * eq.group sizes and initial order [1,2,3], the result permutations are + * retrieved as numbers in an array, where [0,1,2,3,4,5] means [$,1,2,a,b,c]: + * + *

    [0,1,2,3,5,4] + * + *

    [0,1,2,4,3,5] + * + *

    etc. etc., till: + * + *

    [0,2,1,5,4,3] means [$,2,1,c,b,a] + * + *

    + *

    Performance: The implementation tries to advance each time the + * group zero, if it does not succeed, it tries the next group (1,2 and so on), + * so: try to put the largest group as the first groups, UNLIKE the example. + * Performance-wise it is better to do [a,b,c,1,2,$] .The effect is improvement + * by constant (for example, by 2) + * + * @author Assaf + * @since May 30, 2005 + */ +public class CompoundPermutationIter + implements ArrayPermutationsIter, + Iterator +{ + //~ Instance fields -------------------------------------------------------- + + IntegerPermutationIter [] permArray; + + /** + * on the example 1+2+3=6 + */ + private int totalPermArraySize; + + /** + * The overall number is the product of the factorial of each eq. group + * size. + */ + private int max; + + private int iterCounter = 0; + + //~ Constructors ----------------------------------------------------------- + + /** + * For the class example, use [1,2,2]. order matters! (performance-wise too) + * + * @param equalityGroupsSizesArray + */ + public CompoundPermutationIter(int [] equalityGroupsSizesArray) + { + init(equalityGroupsSizesArray); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates an IntegerPermutationIter class per equalityGroup with different + * integers. + * + * @param equalityGroupsSizesArray + */ + private void init(int [] equalityGroupsSizesArray) + { + this.permArray = + new IntegerPermutationIter[equalityGroupsSizesArray.length]; + + int counter = 0; + this.max = 1; // each time , multiply by factorail(eqGroupSize) + for ( + int eqGroup = 0; + eqGroup < equalityGroupsSizesArray.length; + eqGroup++) + { + // create an array of eq.group size filled with values + // of counter, counter+1, ... counter+size-1 + int currGroupSize = equalityGroupsSizesArray[eqGroup]; + int [] currArray = new int[currGroupSize]; + for (int i = 0; i < currGroupSize; i++) { + currArray[i] = counter; + counter++; + } + this.permArray[eqGroup] = new IntegerPermutationIter(currArray); + this.permArray[eqGroup].getNext(); // first iteration return the + // source + + // each time , multiply by factorail(eqGroupSize) + this.max *= MathUtil.factorial(currGroupSize); + } + this.totalPermArraySize = counter; + + // calc max + } + + public Object next() + { + return getNext(); + } + + /** + * Iteration may be one of these two: 1. the last group advances by one + * iter, all else stay. 2. the last group cannot advance , so it restarts + * but telling the group after it to advance (done recursively till some + * group can advance) + */ + public int [] getNext() + { + if (this.iterCounter == 0) { + // just return it , without change + this.iterCounter++; + return getPermAsArray(); + } + + int firstGroupCapableOfAdvancing = -1; + int currGroupIndex = 0; // + while (firstGroupCapableOfAdvancing == -1) { + IntegerPermutationIter currGroup = this.permArray[currGroupIndex]; + + if (currGroup.hasNext()) { + currGroup.getNext(); + + // restart all that we passed on + for (int i = 0; i < currGroupIndex; i++) { + restartPermutationGroup(i); + } + firstGroupCapableOfAdvancing = currGroupIndex; + } + + currGroupIndex++; + if (currGroupIndex >= this.permArray.length) { + break; + } + } + + this.iterCounter++; + + if (firstGroupCapableOfAdvancing == -1) { + // nothing found. we finished all iterations + return null; + } else { + int [] tempArray = getPermAsArray(); + return tempArray; + } + } + + /** + * Creates and returns a new array which consists of the eq. group current + * permutation arrays. For example, in the 10th iter ([$,2,1,b,c,a]) The + * permutations current statuses is [0] [2,1] [4,5,3] so retrieve + * [0,2,1,4,5,3] + */ + public int [] getPermAsArray() + { + int [] resultArray = new int[this.totalPermArraySize]; + int counter = 0; + for ( + int groupIndex = 0; + groupIndex < this.permArray.length; + groupIndex++) + { + int [] currPermArray = this.permArray[groupIndex].getCurrent(); + System.arraycopy( + currPermArray, + 0, + resultArray, + counter, + currPermArray.length); + counter += currPermArray.length; + } + return resultArray; + } + + /** + * Restarts by creating a new one instead. + * + * @param groupIndex + */ + private void restartPermutationGroup(int groupIndex) + { + int [] oldPermArray = this.permArray[groupIndex].getCurrent(); + Arrays.sort(oldPermArray); + this.permArray[groupIndex] = new IntegerPermutationIter(oldPermArray); + this.permArray[groupIndex].getNext(); + } + + public boolean hasNext() + { + boolean result; + if (this.iterCounter < this.max) { + result = true; + } else { + result = false; + } + return result; + } + + public int getMax() + { + return max; + } + + /* (non-Javadoc) + * @see ArrayPermutationsIter#nextPermutation() + */ + public int [] nextPermutation() + { + return (int []) next(); + } + + /* (non-Javadoc) + * @see ArrayPermutationsIter#hasNextPermutaions() + */ + public boolean hasNextPermutaions() + { + return hasNext(); + } + + /** + * UNIMPLEMENTED. always throws new UnsupportedOperationException + * + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } +} + +// End CompoundPermutationIter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/IntegerPermutationIter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/IntegerPermutationIter.java new file mode 100644 index 00000000..99f43c12 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/IntegerPermutationIter.java @@ -0,0 +1,311 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * IntegerPermutationIter.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: IntegerPermutationIter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.permutation; + +import java.util.*; + + +/** + * Iterates through permutations of N elements. + *

  • use getNext() to get the next permutation order, for example(N=4): + * perm0=[1,2,3,4] perm1=[1,2,4,3] perm2=[1,3,2,4] . + *
  • use hasNext() or verify by counter[1,1,1,2,3]; + * note that there are much less than 5! premutations here, because of the + * repetitive 1s. + * + * @param array creates a copy of it (so sort / later changes will not + * matter) + */ + public IntegerPermutationIter(int [] array) + { + int [] newArray = new int[array.length]; + System.arraycopy(array, 0, newArray, 0, array.length); + Arrays.sort(newArray); + init(newArray); + } + + //~ Methods ---------------------------------------------------------------- + + private void init(int [] array) + { + this.N = array.length; + this.Value = array; + this.currentValueBackup = this.Value; + permutationCounter = 0; + } + + /** + * Swaps by array indexes + * + * @param i + * @param j + */ + private void swap(int i, int j) + { + int temp = this.Value[i]; + this.Value[i] = this.Value[j]; + this.Value[j] = temp; + } + + private int [] arrayClone(int [] sourceArray) + { + int [] destArray = new int[sourceArray.length]; + System.arraycopy(sourceArray, 0, destArray, 0, sourceArray.length); + return destArray; + } + + private int [] getNextStartingWith2() + { + permutationCounter++; + int i = N - 1; + + if (i <= 0) // may happen only on N<=1 + + { + this.endWasReached = true; + return null; + } + + /** while (Value[i-1] >= Value[i]) + { + i = i-1; + }*/ + while (Value[i - 1] >= Value[i]) { + i = i - 1; + if (i == 0) { + this.endWasReached = true; + return null; + } + } + + int j = N; + + while (Value[j - 1] <= Value[i - 1]) { + j = j - 1; + } + + swap(i - 1, j - 1); // swap values at positions (i-1) and (j-1) + + i++; + j = N; + + while (i < j) { + swap(i - 1, j - 1); + i++; + j--; + } + return this.Value; + } + + /** + * Efficiency: O(N) implementation, try to take the next! + */ + public boolean hasNext() + { + if ((this.permutationCounter == 0) + || (this.wasNextValueCalculatedAlready)) + { + return true; + } else if (this.endWasReached) { + return false; + } + + boolean result = true; + // calculate the next value into this.value save the current result. in + // the end swap the arrays there is no way to know when to stop , but + // the out-of-bound + /* try + * { + * this.wasNextValueCalculatedAlready=true; + * getNextStartingWith2(); + * } + * catch (ArrayIndexOutOfBoundsException outOfBoundException) + * { + * endWasReached=true; + * result=false; + * }*/ + + getNextStartingWith2(); + this.wasNextValueCalculatedAlready = true; + if (endWasReached) { + return false; + } + + ////////////////////////////// + return result; + } + + public Object next() + { + return getNext(); + } + + /** + * Facade. use it with getNext. efficency: O(N) + * + * @return a new Array with the permutatation order. for example: + * perm0=[1,2,3,4] perm1=[1,2,4,3] perm2=[1,3,2,4] + */ + public int [] getNext() + { + if (!hasNext()) { + throw new RuntimeException( + "IntegerPermutationIter exceeds the total number of permutaions." + + " Suggestion: do a check with hasNext() , or count till getTotalNumberOfPermutations" + + " before using getNext()"); + } + + // if it is the first one , return original + int [] internalArray; + if (this.permutationCounter == 0) { + this.permutationCounter++; + internalArray = this.Value; + } else { + // if hasNext() has precaclulated it , take this value. + if (this.wasNextValueCalculatedAlready) { + internalArray = this.Value; + this.wasNextValueCalculatedAlready = false; + } else { + internalArray = getNextStartingWith2(); + if (this.endWasReached) { + return null; + } + } + } + this.currentValueBackup = arrayClone(internalArray); + return arrayClone(internalArray); + } + + public int [] getCurrent() + { + return arrayClone(this.currentValueBackup); + } + + /** + * Utility method to convert the array into a string examples: [] [0] + * [0,1][1,0] + * + * @param array + */ + public String toString(int [] array) + { + if (array.length <= 0) { + return "[]"; + } + StringBuffer stBuffer = new StringBuffer("["); + for (int i = 0; i < (array.length - 1); i++) { + stBuffer.append(array[i]).append(","); + } + stBuffer.append(array[array.length - 1]).append("]"); + return stBuffer.toString(); + } + + /** + * UNIMPLEMENTED. always throws new UnsupportedOperationException + * + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see ArrayPermutationsIter#nextPermutation() + */ + public int [] nextPermutation() + { + return (int []) next(); + } + + /* (non-Javadoc) + * @see ArrayPermutationsIter#hasNextPermutaions() + */ + public boolean hasNextPermutaions() + { + return hasNext(); + } +} + +// End IntegerPermutationIter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/PermutationFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/PermutationFactory.java new file mode 100644 index 00000000..dd5ab15b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/PermutationFactory.java @@ -0,0 +1,98 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * PermutationFactory.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: PermutationFactory.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.permutation; + +/** + * Factory to create Permutations of several types and use them as Enumerations. + * Note that callers may use them directly if they need to use special concrete + * methods. + * + *

    These types are: + * + *

    + *

  • All elements are different. There are N! possible permutations. + * + *

    example: source=[1,2,3] + * result=[1,2,3][1,3,2][2,1,3][2,3,1][3,1,2][3,2,1] + * + *

    + *

  • Some of the elements are the same. + * + *

    example: source=[1,1,2] result=[1,1,2][1,2,1][2,1,1] + * + *

    + *

  • There are separate permutations groups, which are connected to one + * sequence. Permutations are allowed only inside the group. Possible sequences: + * product of factorial of each group. see example. + * + *

    example: assume source=the groups are sizes are : 1,2,2,5 elements + * will be created: (1),(2,3),(4,5). + * + *

    result=[1,(2,3),(4,5)] [1,(2,3),(5,4)] [1,(3,2),(5,4)] [1,(3,2),(4,5)]. In + * this example the number of possiblities is 1! x 2! x 2! = 4 + * + * @author Assaf Lehr + * @since Jun 3, 2005 + */ +public class PermutationFactory +{ + //~ Methods ---------------------------------------------------------------- + + public static ArrayPermutationsIter createRegular(int [] permSourceArray) + { + IntegerPermutationIter regularPerm = + new IntegerPermutationIter(permSourceArray); + return regularPerm; + } + + /** + * For efficiency, try putting the biggest groups at the beggining of the + * array. + * + * @param groupSizesArray . example [3,2] will create an array (0,1,2)(3,4) + */ + public static ArrayPermutationsIter createByGroups( + int [] groupSizesArray) + { + CompoundPermutationIter complexPerm = + new CompoundPermutationIter(groupSizesArray); + return complexPerm; + } +} + +// End PermutationFactory.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/package.html new file mode 100644 index 00000000..82cd61fb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/permutation/package.html @@ -0,0 +1,6 @@ + + + +Classes to provide all the possible permutations of arrays or sets. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/SimpleTouchgraphApplet.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/SimpleTouchgraphApplet.java new file mode 100644 index 00000000..5b7d76b6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/SimpleTouchgraphApplet.java @@ -0,0 +1,132 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * SimpleTouchgraphApplet.java + * ------------------- + * (C) Copyright 2006-2008, by Carl Anderson and Contributors. + * + * Original Author: Carl Anderson + * Contributor(s): - + * + * $Id: SimpleTouchgraphApplet.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 8-May-2006 : Initial revision (CA); + * + */ +package org.jgrapht.experimental.touchgraph; + +import java.applet.*; + +import java.awt.*; + +import javax.swing.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * SimpleTouchgraphApplet + * + * @author canderson + */ +public class SimpleTouchgraphApplet + extends Applet +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 6213379835360007840L; + + //~ Methods ---------------------------------------------------------------- + + /** + * create a graph: code taken from non-visible + * org._3pq.jgrapht.demo.createStringGraph() + */ + public static Graph createSamplegraph() + { + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + + String v1 = "v1"; + String v2 = "v2"; + String v3 = "v3"; + String v4 = "v4"; + + // add the vertices + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + g.addVertex(v4); + + // add edges to create a circuit + g.addEdge(v1, v2); + g.addEdge(v2, v3); + g.addEdge(v3, v4); + g.addEdge(v4, v1); + + return g; + } + + /** + * initialize the applet + */ + public void init() + { + Graph g = createSamplegraph(); + boolean selfReferencesAllowed = false; + + setLayout(new BorderLayout()); + setSize(800, 600); + add( + new TouchgraphPanel(g, selfReferencesAllowed), + BorderLayout.CENTER); + } + + public static void main(String [] args) + { + Graph g = createSamplegraph(); + boolean selfReferencesAllowed = false; + + JFrame frame = new JFrame(); + frame.getContentPane().add( + new TouchgraphPanel(g, selfReferencesAllowed)); + frame.setPreferredSize(new Dimension(800, 800)); + frame.setTitle("JGraphT to Touchgraph Converter Demo"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + try { + Thread.sleep(5000000); + } catch (InterruptedException ex) { + } + } +} + +// End SimpleTouchgraphApplet.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/TouchgraphConverter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/TouchgraphConverter.java new file mode 100644 index 00000000..1685a178 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/TouchgraphConverter.java @@ -0,0 +1,135 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * TouchgraphConverter.java + * ------------------- + * (C) Copyright 2006-2008, by Carl Anderson and Contributors. + * + * Original Author: Carl Anderson + * Contributor(s): - + * + * $Id: TouchgraphConverter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 8-May-2006 : Initial revision (CA); + * + */ +package org.jgrapht.experimental.touchgraph; + +import com.touchgraph.graphlayout.*; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * A Converter class that converts a JGraphT graph to that used in the + * TouchGraph library. + * + * @author canderson + */ +public class TouchgraphConverter +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Convert a JGraphT graph to the representation used in the TouchGraph + * library. http://sourceforge.net/projects/touchgraph TouchGraph doesn't + * have a sensible, extensible graph object class and so one has to add them + * to a TGPanel which will store the graph components (the set of nodes and + * edges) in its own way. The closest Touchgraph has to a graph object is a + * GraphEltSet but Touchgraph does not provide the visibility to use it + * easily and one can use a JGraphT graph. While JGraphT nodes can be any + * type of objects, TouchGraph uses a set of com.touchgraph.graphlayout.Node + * and com.touchgraph.graphlayout.Edge only. Moreover, TouchGraph edges are + * always directed. Having said that, if you want a nice way to visualize + * and explore a graph, especially large complex graphs, TouchGraph is very + * nice + * + * @param graph: the JGraphT graph + * @param tgPanel: the TouchGraph TGPanel + * @param selfReferencesAllowed: do you want to include self-referenctial + * edges, ie an edge from a node to itself? Self-referential loops do not + * show up in the TG visualization but you may want to subclass TG's Node + * class to show them + * + * @return first node of the TouchGraph graph + * + * @throws TGException + */ + @SuppressWarnings("unchecked") + public Node convertToTouchGraph( + Graph graph, + TGPanel tgPanel, + boolean selfReferencesAllowed) + throws TGException + { + List jgtNodes = new ArrayList(graph.vertexSet()); + Node [] tgNodes = new Node[jgtNodes.size()]; + + // add all the nodes... + for (int i = 0; i < jgtNodes.size(); i++) { + Node n; + if (jgtNodes.get(i) instanceof Node) { + // if our JGraphT object was a touchGraph node, add it unaltered + n = (Node) jgtNodes.get(i); + } else { + // create a TG Node with a "label" and "id" equals to the + // objects toString() value + n = new Node(jgtNodes.get(i).toString()); + } + + // store this for edge-related creation below + tgNodes[i] = n; + + // add the node to the TG panel + tgPanel.addNode(n); + } + + // add the edges... + for (int i = 0; i < tgNodes.length; i++) { + for (int j = 0; j < tgNodes.length; j++) { + // self-referential loops do not show up in the TG + // visualization but you may want to + // subclass TG's Node class to show them + if ((i != j) || selfReferencesAllowed) { + if (graph.getEdge(jgtNodes.get(i), jgtNodes.get(j)) + != null) + { + // add TG directed edge from i to j + tgPanel.addEdge(new Edge(tgNodes[i], tgNodes[j])); + } + } + } + } + + // return the first node as a focal point for the TG panel + return tgNodes[0]; + } +} + +// End TouchgraphConverter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/TouchgraphPanel.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/TouchgraphPanel.java new file mode 100644 index 00000000..f891a586 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/TouchgraphPanel.java @@ -0,0 +1,166 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * TouchgraphPanel.java + * ------------------- + * (C) Copyright 2006-2008, by Carl Anderson and Contributors. + * + * Original Author: Carl Anderson + * Contributor(s): - + * + * $Id: TouchgraphPanel.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 8-May-2006 : Initial revision (CA); + * + */ +package org.jgrapht.experimental.touchgraph; + +import com.touchgraph.graphlayout.*; +import com.touchgraph.graphlayout.interaction.*; + +import java.awt.*; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * The Touchgraph panel that displays our graph + * http://sourceforge.net/projects/touchgraph + * + * @author canderson + */ +public class TouchgraphPanel + extends GLPanel +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = -7441058429719746032L; + + //~ Instance fields -------------------------------------------------------- + + private Color defaultBackColor = new Color(0x01, 0x11, 0x44); + private Color defaultBorderBackColor = new Color(0x02, 0x35, 0x81); + private Color defaultForeColor = + new Color((float) 0.95, (float) 0.85, (float) 0.55); + + /** + * the JGraphT graph we are displaying + */ + Graph graph; + + /** + * are self-references allowed? They will not show up in TouchGraph unless + * you override Touchgraph's Node or Edge class to do so + */ + boolean selfReferencesAllowed = true; + + // ================= + + //~ Constructors ----------------------------------------------------------- + + /**constructor*/ + public TouchgraphPanel(Graph graph, boolean selfReferencesAllowed) + { + this.graph = graph; + this.selfReferencesAllowed = selfReferencesAllowed; + + /* + * The code that was in the super's constructor. As it also called + * super's initialize() + * it is impossible to subclass and insert our own graph into the + * initialization process + */ + preinitialize(); + + initialize(); // now we can insert our own graph into this method + } + + //~ Methods ---------------------------------------------------------------- + + /** + * get everything setup: this is the code that was in the super's + * constructor but which was followed by an initialize() call. Hence, it was + * impossible to subclass the superclass and insert our own graph + * initialization code without breaking it out as here. + */ + public void preinitialize() + { + this.setBackground(defaultBorderBackColor); + this.setForeground(defaultForeColor); + scrollBarHash = new Hashtable(); + tgLensSet = new TGLensSet(); + tgPanel = new TGPanel(); + tgPanel.setBackColor(defaultBackColor); + hvScroll = new HVScroll(tgPanel, tgLensSet); + zoomScroll = new ZoomScroll(tgPanel); + hyperScroll = new HyperScroll(tgPanel); + rotateScroll = new RotateScroll(tgPanel); + localityScroll = new LocalityScroll(tgPanel); + } + + /** + * Initialize panel, lens, and establish a random graph as a demonstration. + */ + public void initialize() + { + buildPanel(); + buildLens(); + tgPanel.setLensSet(tgLensSet); + addUIs(); + try { + if (this.graph == null) { + /* + * Add a random graph + */ + randomGraph(); + } else { + /* + * Add users graph + */ + TouchgraphConverter converter = + new TouchgraphConverter(); + Node n = + (Node) converter.convertToTouchGraph( + this.graph, + tgPanel, + this.selfReferencesAllowed); + getHVScroll().slowScrollToCenter(n); + tgPanel.setLocale(n, Integer.MAX_VALUE); + } + } catch (TGException tge) { + System.err.println(tge.getMessage()); + tge.printStackTrace(System.err); + } + setVisible(true); + } +} + +// End TouchgraphPanel.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/package.html new file mode 100644 index 00000000..6a6bd2ac --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/experimental/touchgraph/package.html @@ -0,0 +1,7 @@ + + + +

    Integration with the Touchgraph project.

    + + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/DOTExporter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/DOTExporter.java new file mode 100644 index 00000000..e7351781 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/DOTExporter.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. + */ +/* ------------------ + * DOTExporter.java + * ------------------ + * (C) Copyright 2006, by Trevor Harmon. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import org.jgrapht.*; + + +/** + * Exports a graph into a DOT file. + * + *

    For a description of the format see + * http://en.wikipedia.org/wiki/DOT_language.

    + * + * @author Trevor Harmon + */ +public class DOTExporter +{ + //~ Instance fields -------------------------------------------------------- + + private VertexNameProvider vertexIDProvider; + private VertexNameProvider vertexLabelProvider; + private EdgeNameProvider edgeLabelProvider; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructs a new DOTExporter object with an integer name provider for the + * vertex IDs and null providers for the vertex and edge labels. + */ + public DOTExporter() + { + this(new IntegerNameProvider(), null, null); + } + + /** + * Constructs a new DOTExporter object with the given ID and label + * providers. + * + * @param vertexIDProvider for generating vertex IDs. Must not be null. + * @param vertexLabelProvider for generating vertex labels. If null, vertex + * labels will not be written to the file. + * @param edgeLabelProvider for generating edge labels. If null, edge labels + * will not be written to the file. + */ + public DOTExporter( + VertexNameProvider vertexIDProvider, + VertexNameProvider vertexLabelProvider, + EdgeNameProvider edgeLabelProvider) + { + this.vertexIDProvider = vertexIDProvider; + this.vertexLabelProvider = vertexLabelProvider; + this.edgeLabelProvider = edgeLabelProvider; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Exports a graph into a plain text file in DOT format. + * + * @param writer the writer to which the graph to be exported + * @param g the graph to be exported + */ + public void export(Writer writer, Graph g) + { + PrintWriter out = new PrintWriter(writer); + String indent = " "; + String connector; + + if (g instanceof DirectedGraph) { + out.println("digraph G {"); + connector = " -> "; + } else { + out.println("graph G {"); + connector = " -- "; + } + + for (V v : g.vertexSet()) { + out.print(indent + getVertexID(v)); + + if (vertexLabelProvider != null) { + out.print( + " [label = \"" + vertexLabelProvider.getVertexName(v) + + "\"]"); + } + + out.println(";"); + } + + for (E e : g.edgeSet()) { + String source = getVertexID(g.getEdgeSource(e)); + String target = getVertexID(g.getEdgeTarget(e)); + + out.print(indent + source + connector + target); + + if (edgeLabelProvider != null) { + out.print( + " [label = \"" + edgeLabelProvider.getEdgeName(e) + "\"]"); + } + + out.println(";"); + } + + out.println("}"); + + out.flush(); + } + + /** + * Return a valid vertex ID (with respect to the .dot language definition as + * described in http://www.graphviz.org/doc/info/lang.html Quoted from above + * mentioned source: An ID is valid if it meets one of the following + * criteria: + * + *
      + *
    • any string of alphabetic characters, underscores or digits, not + * beginning with a digit; + *
    • a number [-]?(.[0-9]+ | [0-9]+(.[0-9]*)? ); + *
    • any double-quoted string ("...") possibly containing escaped quotes + * (\"); + *
    • an HTML string (<...>). + *
    + * + * @throws RuntimeException if the given vertexIDProvider + * didn't generate a valid vertex ID. + */ + private String getVertexID(V v) + { + // TODO jvs 28-Jun-2008: possible optimizations here are + // (a) only validate once per vertex + // (b) compile regex patterns + + // use the associated id provider for an ID of the given vertex + String idCandidate = vertexIDProvider.getVertexName(v); + + // now test that this is a valid ID + boolean isAlphaDig = idCandidate.matches("[a-zA-Z]+([\\w_]*)?"); + boolean isDoubleQuoted = idCandidate.matches("\".*\""); + boolean isDotNumber = + idCandidate.matches("[-]?([.][0-9]+|[0-9]+([.][0-9]*)?)"); + boolean isHTML = idCandidate.matches("<.*>"); + + if (isAlphaDig || isDotNumber || isDoubleQuoted || isHTML) { + return idCandidate; + } + + throw new RuntimeException( + "Generated id '" + idCandidate + "'for vertex '" + v + + "' is not valid with respect to the .dot language"); + } +} + +// End DOTExporter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/EdgeNameProvider.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/EdgeNameProvider.java new file mode 100644 index 00000000..05df894b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/EdgeNameProvider.java @@ -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-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. + */ +/* ------------------ + * VertexNameProvider.java + * ------------------ + * (C) Copyright 2005-2008, by Trevor Harmon. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +/** + * Assigns a display name for each of the graph edes. + */ +public interface EdgeNameProvider +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Returns a unique name for an edge. This is useful when exporting a graph, + * as it ensures that all edges are assigned simple, consistent names. + * + * @param edge the edge to be named + * + * @return the name of the edge + */ + public String getEdgeName(E edge); +} + +// End EdgeNameProvider.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/GmlExporter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/GmlExporter.java new file mode 100644 index 00000000..98f91ed7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/GmlExporter.java @@ -0,0 +1,286 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * GmlExporter.java + * ------------------ + * (C) Copyright 2006, by Dimitrios Michail. + * + * Original Author: Dimitrios Michail + * + * $Id: GmlExporter.java 650 2008-12-24 20:44:06Z perfecthash $ + * + * Changes + * ------- + * 15-Dec-2006 : Initial Version (DM); + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import org.jgrapht.*; + + +/** + * Exports a graph into a GML file (Graph Modelling Language). + * + *

    For a description of the format see + * http://www.infosun.fmi.uni-passau.de/Graphlet/GML/.

    + * + *

    The objects associated with vertices and edges are exported as labels + * using their toString() implementation. See the {@link + * #setPrintLabels(Integer)} method. The default behavior is to export no label + * information.

    + * + * @author Dimitrios Michail + */ +public class GmlExporter +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String creator = "JGraphT GML Exporter"; + private static final String version = "1"; + + private static final String delim = " "; + private static final String tab1 = "\t"; + private static final String tab2 = "\t\t"; + + // TODO jvs 27-Jan-2008: convert these to enum + + /** + * Option to export no vertex or edge labels. + */ + public static final Integer PRINT_NO_LABELS = 1; + + /** + * Option to export only the edge labels. + */ + public static final Integer PRINT_EDGE_LABELS = 2; + + /** + * Option to export both edge and vertex labels. + */ + public static final Integer PRINT_EDGE_VERTEX_LABELS = 3; + + /** + * Option to export only the vertex labels. + */ + public static final Integer PRINT_VERTEX_LABELS = 4; + + //~ Instance fields -------------------------------------------------------- + + private Integer printLabels = PRINT_NO_LABELS; + + private VertexNameProvider vertexIDProvider; + private VertexNameProvider vertexLabelProvider; + private EdgeNameProvider edgeIDProvider; + private EdgeNameProvider edgeLabelProvider; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new GmlExporter object with integer name providers for the + * vertex and edge IDs and null providers for the vertex and edge labels. + */ + public GmlExporter() + { + this( + new IntegerNameProvider(), + null, + new IntegerEdgeNameProvider(), + null); + } + + /** + * Constructs a new GmlExporter object with the given ID and label + * providers. + * + * @param vertexIDProvider for generating vertex IDs. Must not be null. + * @param vertexLabelProvider for generating vertex labels. If null, vertex + * labels will be generated using the toString() method of the vertex + * object. + * @param edgeIDProvider for generating vertex IDs. Must not be null. + * @param edgeLabelProvider for generating edge labels. If null, edge labels + * will be generated using the toString() method of the edge object. + */ + public GmlExporter( + VertexNameProvider vertexIDProvider, + VertexNameProvider vertexLabelProvider, + EdgeNameProvider edgeIDProvider, + EdgeNameProvider edgeLabelProvider) + { + this.vertexIDProvider = vertexIDProvider; + this.vertexLabelProvider = vertexLabelProvider; + this.edgeIDProvider = edgeIDProvider; + this.edgeLabelProvider = edgeLabelProvider; + } + + //~ Methods ---------------------------------------------------------------- + + private String quoted(final String s) + { + return "\"" + s + "\""; + } + + private void exportHeader(PrintWriter out) + { + out.println("Creator" + delim + quoted(creator)); + out.println("Version" + delim + version); + } + + private void exportVertices( + PrintWriter out, + Graph g) + { + for (V from : g.vertexSet()) { + out.println(tab1 + "node"); + out.println(tab1 + "["); + out.println( + tab2 + "id" + delim + vertexIDProvider.getVertexName(from)); + if ((printLabels == PRINT_VERTEX_LABELS) + || (printLabels == PRINT_EDGE_VERTEX_LABELS)) + { + String label = + (vertexLabelProvider == null) ? from.toString() + : vertexLabelProvider.getVertexName(from); + out.println(tab2 + "label" + delim + quoted(label)); + } + out.println(tab1 + "]"); + } + } + + private void exportEdges( + PrintWriter out, + Graph g) + { + for (E edge : g.edgeSet()) { + out.println(tab1 + "edge"); + out.println(tab1 + "["); + String id = edgeIDProvider.getEdgeName(edge); + out.println(tab2 + "id" + delim + id); + String s = vertexIDProvider.getVertexName(g.getEdgeSource(edge)); + out.println(tab2 + "source" + delim + s); + String t = vertexIDProvider.getVertexName(g.getEdgeTarget(edge)); + out.println(tab2 + "target" + delim + t); + if ((printLabels == PRINT_EDGE_LABELS) + || (printLabels == PRINT_EDGE_VERTEX_LABELS)) + { + String label = + (edgeLabelProvider == null) ? edge.toString() + : edgeLabelProvider.getEdgeName(edge); + out.println(tab2 + "label" + delim + quoted(label)); + } + out.println(tab1 + "]"); + } + } + + private void export(Writer output, Graph g, boolean directed) + { + PrintWriter out = new PrintWriter(output); + + for (V from : g.vertexSet()) { + // assign ids in vertex set iteration order + vertexIDProvider.getVertexName(from); + } + + exportHeader(out); + out.println("graph"); + out.println("["); + out.println(tab1 + "label" + delim + quoted("")); + if (directed) { + out.println(tab1 + "directed" + delim + "1"); + } else { + out.println(tab1 + "directed" + delim + "0"); + } + exportVertices(out, g); + exportEdges(out, g); + out.println("]"); + out.flush(); + } + + /** + * Exports an undirected graph into a plain text file in GML format. + * + * @param output the writer to which the graph to be exported + * @param g the undirected graph to be exported + */ + public void export(Writer output, UndirectedGraph g) + { + export(output, g, false); + } + + /** + * Exports a directed graph into a plain text file in GML format. + * + * @param output the writer to which the graph to be exported + * @param g the directed graph to be exported + */ + public void export(Writer output, DirectedGraph g) + { + export(output, g, true); + } + + /** + * Set whether to export the vertex and edge labels. The default behavior is + * to export no vertex or edge labels. + * + * @param i What labels to export. Valid options are {@link + * #PRINT_NO_LABELS}, {@link #PRINT_EDGE_LABELS}, {@link + * #PRINT_EDGE_VERTEX_LABELS}, and {@link #PRINT_VERTEX_LABELS}. + * + * @throws IllegalArgumentException if a non-supported value is used + * + * @see #PRINT_NO_LABELS + * @see #PRINT_EDGE_LABELS + * @see #PRINT_EDGE_VERTEX_LABELS + * @see #PRINT_VERTEX_LABELS + */ + public void setPrintLabels(final Integer i) + { + if ((i != PRINT_NO_LABELS) + && (i != PRINT_EDGE_LABELS) + && (i != PRINT_EDGE_VERTEX_LABELS) + && (i != PRINT_VERTEX_LABELS)) + { + throw new IllegalArgumentException( + "Non-supported parameter value: " + Integer.toString(i)); + } + printLabels = i; + } + + /** + * Get whether to export the vertex and edge labels. + * + * @return One of the {@link #PRINT_NO_LABELS}, {@link #PRINT_EDGE_LABELS}, + * {@link #PRINT_EDGE_VERTEX_LABELS}, or {@link #PRINT_VERTEX_LABELS}. + */ + public Integer getPrintLabels() + { + return printLabels; + } +} + +// End GmlExporter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/GraphMLExporter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/GraphMLExporter.java new file mode 100644 index 00000000..bfe2a37b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/GraphMLExporter.java @@ -0,0 +1,260 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * GraphMLExporter.java + * ------------------ + * (C) Copyright 2006, by Trevor Harmon. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import javax.xml.transform.*; +import javax.xml.transform.sax.*; +import javax.xml.transform.stream.*; + +import org.jgrapht.*; + +import org.xml.sax.*; +import org.xml.sax.helpers.*; + + +/** + * Exports a graph into a GraphML file. + * + *

    For a description of the format see + * http://en.wikipedia.org/wiki/GraphML.

    + * + * @author Trevor Harmon + */ +public class GraphMLExporter +{ + //~ Instance fields -------------------------------------------------------- + + private VertexNameProvider vertexIDProvider; + private VertexNameProvider vertexLabelProvider; + private EdgeNameProvider edgeIDProvider; + private EdgeNameProvider edgeLabelProvider; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructs a new GraphMLExporter object with integer name providers for + * the vertex and edge IDs and null providers for the vertex and edge + * labels. + */ + public GraphMLExporter() + { + this( + new IntegerNameProvider(), + null, + new IntegerEdgeNameProvider(), + null); + } + + /** + * Constructs a new GraphMLExporter object with the given ID and label + * providers. + * + * @param vertexIDProvider for generating vertex IDs. Must not be null. + * @param vertexLabelProvider for generating vertex labels. If null, vertex + * labels will not be written to the file. + * @param edgeIDProvider for generating vertex IDs. Must not be null. + * @param edgeLabelProvider for generating edge labels. If null, edge labels + * will not be written to the file. + */ + public GraphMLExporter( + VertexNameProvider vertexIDProvider, + VertexNameProvider vertexLabelProvider, + EdgeNameProvider edgeIDProvider, + EdgeNameProvider edgeLabelProvider) + { + this.vertexIDProvider = vertexIDProvider; + this.vertexLabelProvider = vertexLabelProvider; + this.edgeIDProvider = edgeIDProvider; + this.edgeLabelProvider = edgeLabelProvider; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Exports a graph into a plain text file in GraphML format. + * + * @param writer the writer to which the graph to be exported + * @param g the graph to be exported + */ + public void export(Writer writer, Graph g) + throws SAXException, TransformerConfigurationException + { + // Prepare an XML file to receive the GraphML data + PrintWriter out = new PrintWriter(writer); + StreamResult streamResult = new StreamResult(out); + SAXTransformerFactory factory = + (SAXTransformerFactory) SAXTransformerFactory.newInstance(); + TransformerHandler handler = factory.newTransformerHandler(); + Transformer serializer = handler.getTransformer(); + serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + serializer.setOutputProperty(OutputKeys.INDENT, "yes"); + handler.setResult(streamResult); + handler.startDocument(); + AttributesImpl attr = new AttributesImpl(); + + // + handler.startPrefixMapping( + "xsi", + "http://www.w3.org/2001/XMLSchema-instance"); + + // FIXME: Is this the proper way to add this attribute? + attr.addAttribute( + "", + "", + "xsi:schemaLocation", + "CDATA", + "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"); + handler.startElement( + "http://graphml.graphdrawing.org/xmlns", + "", + "graphml", + attr); + handler.endPrefixMapping("xsi"); + + if (vertexLabelProvider != null) { + // for vertex label attribute + attr.clear(); + attr.addAttribute("", "", "id", "CDATA", "vertex_label"); + attr.addAttribute("", "", "for", "CDATA", "node"); + attr.addAttribute("", "", "attr.name", "CDATA", "Vertex Label"); + attr.addAttribute("", "", "attr.type", "CDATA", "string"); + handler.startElement("", "", "key", attr); + handler.endElement("", "", "key"); + } + + if (edgeLabelProvider != null) { + // for edge label attribute + attr.clear(); + attr.addAttribute("", "", "id", "CDATA", "edge_label"); + attr.addAttribute("", "", "for", "CDATA", "edge"); + attr.addAttribute("", "", "attr.name", "CDATA", "Edge Label"); + attr.addAttribute("", "", "attr.type", "CDATA", "string"); + handler.startElement("", "", "key", attr); + handler.endElement("", "", "key"); + } + + // + attr.clear(); + attr.addAttribute( + "", + "", + "edgedefault", + "CDATA", + (g instanceof DirectedGraph) ? "directed" : "undirected"); + handler.startElement("", "", "graph", attr); + + // Add all the vertices as elements... + for (V v : g.vertexSet()) { + // + attr.clear(); + attr.addAttribute( + "", + "", + "id", + "CDATA", + vertexIDProvider.getVertexName(v)); + handler.startElement("", "", "node", attr); + + if (vertexLabelProvider != null) { + // + attr.clear(); + attr.addAttribute("", "", "key", "CDATA", "vertex_label"); + handler.startElement("", "", "data", attr); + + // Content for + String vertexLabel = vertexLabelProvider.getVertexName(v); + handler.characters( + vertexLabel.toCharArray(), + 0, + vertexLabel.length()); + + handler.endElement("", "", "data"); + } + + handler.endElement("", "", "node"); + } + + // Add all the edges as elements... + for (E e : g.edgeSet()) { + // + attr.clear(); + attr.addAttribute( + "", + "", + "id", + "CDATA", + edgeIDProvider.getEdgeName(e)); + attr.addAttribute( + "", + "", + "source", + "CDATA", + vertexIDProvider.getVertexName(g.getEdgeSource(e))); + attr.addAttribute( + "", + "", + "target", + "CDATA", + vertexIDProvider.getVertexName(g.getEdgeTarget(e))); + handler.startElement("", "", "edge", attr); + + if (edgeLabelProvider != null) { + // + attr.clear(); + attr.addAttribute("", "", "key", "CDATA", "edge_label"); + handler.startElement("", "", "data", attr); + + // Content for + String edgeLabel = edgeLabelProvider.getEdgeName(e); + handler.characters( + edgeLabel.toCharArray(), + 0, + edgeLabel.length()); + handler.endElement("", "", "data"); + } + + handler.endElement("", "", "edge"); + } + + handler.endElement("", "", "graph"); + handler.endElement("", "", "graphml"); + handler.endDocument(); + + out.flush(); + } +} + +// End GraphMLExporter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/IntegerEdgeNameProvider.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/IntegerEdgeNameProvider.java new file mode 100644 index 00000000..bf5f1d0f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/IntegerEdgeNameProvider.java @@ -0,0 +1,82 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * IntegerNameProvider.java + * ------------------ + * (C) Copyright 2005-2008, by Trevor Harmon. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +import java.util.*; + + +/** + * 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. + * + * @author Trevor Harmon + */ +public class IntegerEdgeNameProvider + implements EdgeNameProvider +{ + //~ Instance fields -------------------------------------------------------- + + private int nextID = 1; + private final Map idMap = new HashMap(); + + //~ Methods ---------------------------------------------------------------- + + /** + * Clears all cached identifiers, and resets the unique identifier counter. + */ + public void clear() + { + nextID = 1; + idMap.clear(); + } + + /** + * Returns the String representation of an edge. + * + * @param edge the edge to be named + */ + public String getEdgeName(E edge) + { + Integer id = idMap.get(edge); + if (id == null) { + id = nextID++; + idMap.put(edge, id); + } + + return id.toString(); + } +} + +// End IntegerEdgeNameProvider.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/IntegerNameProvider.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/IntegerNameProvider.java new file mode 100644 index 00000000..e4aa5a86 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/IntegerNameProvider.java @@ -0,0 +1,95 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * IntegerNameProvider.java + * ------------------ + * (C) Copyright 2005-2008, by Charles Fry and Contributors. + * + * Original Author: Charles Fry + * + * $Id: IntegerNameProvider.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Dec-2005 : Initial Version (CF); + * + */ +package org.jgrapht.ext; + +import java.util.*; + +import org.jgrapht.event.*; + + +/** + * 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. + * + * @author Charles Fry + */ +public class IntegerNameProvider + implements VertexNameProvider +{ + //~ Instance fields -------------------------------------------------------- + + private int nextID = 1; + private final Map idMap = new HashMap(); + + //~ Methods ---------------------------------------------------------------- + + /** + * Clears all cached identifiers, and resets the unique identifier counter. + */ + public void clear() + { + nextID = 1; + idMap.clear(); + } + + /** + * Returns the String representation of the unique integer representing a + * vertex. + * + * @param vertex the vertex to be named + * + * @return the name of + * + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public String getVertexName(V vertex) + { + Integer id = idMap.get(vertex); + if (id == null) { + id = nextID++; + idMap.put(vertex, id); + } + + return id.toString(); + } +} + +// End IntegerNameProvider.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/JGraphModelAdapter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/JGraphModelAdapter.java new file mode 100644 index 00000000..6104228c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/JGraphModelAdapter.java @@ -0,0 +1,1148 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * JGraphModelAdapter.java + * ----------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Erik Postma + * + * $Id: JGraphModelAdapter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 02-Aug-2003 : Initial revision (BN); + * 10-Aug-2003 : Adaptation to new event model (BN); + * 06-Nov-2003 : Allowed non-listenable underlying JGraphT graph (BN); + * 12-Dec-2003 : Added CellFactory support (BN); + * 27-Jan-2004 : Added support for JGraph->JGraphT change propagation (EP); + * 29-Jan-2005 : Added support for JGraph dangling edges (BN); + * 07-May-2006 : Changed from List to Set (JVS); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.ext; + +import java.awt.Color; +import java.awt.Font; +import java.awt.geom.*; + +import java.io.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.swing.*; + +import org.jgraph.event.*; +import org.jgraph.event.GraphModelEvent.*; +import org.jgraph.graph.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; + + +/** + * 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 {@link + * org.jgrapht.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.

    + * + * @author Barak Naveh + * @since Aug 2, 2003 + */ + +/* + * FUTURE WORK: Now that the adapter supports JGraph dangling edges, it is + * possible, with a little effort, to eliminate the "known bugs" above. Some + * todo and fixme marks in the code indicate where the possible improvements + * could be made to realize that. + */ +public class JGraphModelAdapter + extends DefaultGraphModel +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3256722883706302515L; + + //~ Instance fields -------------------------------------------------------- + + /** + * 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...

    + */ + final Set jCellsBeingAdded = new HashSet(); + final Set jCellsBeingRemoved = new HashSet(); + final Set jtElementsBeingAdded = new HashSet(); + final Set jtElementsBeingRemoved = new HashSet(); + private final CellFactory cellFactory; + + /** + * Maps JGraph edges to JGraphT edges + */ + private final Map cellToEdge = + new HashMap(); + + /** + * Maps JGraph vertices to JGraphT vertices + */ + private final Map cellToVertex = new HashMap(); + private AttributeMap defaultEdgeAttributes; + private AttributeMap defaultVertexAttributes; + + /** + * Maps JGraphT edges to JGraph edges + */ + private final Map edgeToCell = + new HashMap(); + + /** + * Maps JGraphT vertices to JGraph vertices + */ + private final Map vertexToCell = new HashMap(); + private final ShieldedGraph jtGraph; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructs a new JGraph model adapter for the specified JGraphT graph. + * + * @param jGraphTGraph the JGraphT graph for which JGraph model adapter to + * be created. null is NOT permitted. + */ + public JGraphModelAdapter(Graph jGraphTGraph) + { + this( + jGraphTGraph, + createDefaultVertexAttributes(), + createDefaultEdgeAttributes(jGraphTGraph)); + } + + /** + * Constructs a new JGraph model adapter for the specified JGraphT graph. + * + * @param jGraphTGraph the JGraphT graph for which JGraph model adapter to + * be created. null is NOT permitted. + * @param defaultVertexAttributes a default map of JGraph attributes to + * format vertices. null is NOT permitted. + * @param defaultEdgeAttributes a default map of JGraph attributes to format + * edges. null is NOT permitted. + */ + public JGraphModelAdapter( + Graph jGraphTGraph, + AttributeMap defaultVertexAttributes, + AttributeMap defaultEdgeAttributes) + { + this( + jGraphTGraph, + defaultVertexAttributes, + defaultEdgeAttributes, + new DefaultCellFactory()); + } + + /** + * Constructs a new JGraph model adapter for the specified JGraphT graph. + * + * @param jGraphTGraph the JGraphT graph for which JGraph model adapter to + * be created. null is NOT permitted. + * @param defaultVertexAttributes a default map of JGraph attributes to + * format vertices. null is NOT permitted. + * @param defaultEdgeAttributes a default map of JGraph attributes to format + * edges. null is NOT permitted. + * @param cellFactory a {@link CellFactory} to be used to create the JGraph + * cells. null is NOT permitted. + * + * @throws IllegalArgumentException + */ + public JGraphModelAdapter( + Graph jGraphTGraph, + AttributeMap defaultVertexAttributes, + AttributeMap defaultEdgeAttributes, + CellFactory cellFactory) + { + super(); + + if ((jGraphTGraph == null) + || (defaultVertexAttributes == null) + || (defaultEdgeAttributes == null) + || (cellFactory == null)) + { + throw new IllegalArgumentException("null is NOT permitted"); + } + + jtGraph = new ShieldedGraph(jGraphTGraph); + setDefaultVertexAttributes(defaultVertexAttributes); + setDefaultEdgeAttributes(defaultEdgeAttributes); + this.cellFactory = cellFactory; + + if (jGraphTGraph instanceof ListenableGraph) { + ListenableGraph g = (ListenableGraph) jGraphTGraph; + g.addGraphListener(new JGraphTListener()); + } + + for ( + Iterator i = jGraphTGraph.vertexSet().iterator(); + i.hasNext();) + { + handleJGraphTAddedVertex(i.next()); + } + + for (Iterator i = jGraphTGraph.edgeSet().iterator(); i.hasNext();) { + handleJGraphTAddedEdge(i.next()); + } + + this.addGraphModelListener(new JGraphListener()); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates and returns a map of attributes to be used as defaults for edge + * attributes, depending on the specified graph. + * + * @param jGraphTGraph the graph for which default edge attributes to be + * created. + * + * @return a map of attributes to be used as default for edge attributes. + */ + public static AttributeMap createDefaultEdgeAttributes( + Graph jGraphTGraph) + { + AttributeMap map = new AttributeMap(); + + if (jGraphTGraph instanceof DirectedGraph) { + GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL); + GraphConstants.setEndFill(map, true); + GraphConstants.setEndSize(map, 10); + } + + GraphConstants.setForeground(map, Color.decode("#25507C")); + GraphConstants.setFont( + map, + GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); + GraphConstants.setLineColor(map, Color.decode("#7AA1E6")); + + return map; + } + + /** + * Creates and returns a map of attributes to be used as defaults for vertex + * attributes. + * + * @return a map of attributes to be used as defaults for vertex attributes. + */ + public static AttributeMap createDefaultVertexAttributes() + { + AttributeMap map = new AttributeMap(); + Color c = Color.decode("#FF9900"); + + GraphConstants.setBounds(map, new Rectangle2D.Double(50, 50, 90, 30)); + GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder()); + GraphConstants.setBackground(map, c); + GraphConstants.setForeground(map, Color.white); + GraphConstants.setFont( + map, + GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12)); + GraphConstants.setOpaque(map, true); + + return map; + } + + /** + * Returns the cell factory used to create the JGraph cells. + * + * @return the cell factory used to create the JGraph cells. + */ + public CellFactory getCellFactory() + { + return cellFactory; + } + + /** + * Sets the default edge attributes used for creating new JGraph edges. + * + * @param defaultEdgeAttributes the default edge attributes to set. + */ + public void setDefaultEdgeAttributes(AttributeMap defaultEdgeAttributes) + { + this.defaultEdgeAttributes = defaultEdgeAttributes; + } + + /** + * Returns the default edge attributes used for creating new JGraph edges. + * + * @return the default edge attributes used for creating new JGraph edges. + */ + public AttributeMap getDefaultEdgeAttributes() + { + return defaultEdgeAttributes; + } + + /** + * Sets the default vertex attributes used for creating new JGraph vertices. + * + * @param defaultVertexAttributes the default vertex attributes to set. + */ + public void setDefaultVertexAttributes( + AttributeMap defaultVertexAttributes) + { + this.defaultVertexAttributes = defaultVertexAttributes; + } + + /** + * Returns the default vertex attributes used for creating new JGraph + * vertices. + * + * @return the default vertex attributes used for creating new JGraph + * vertices. + */ + public AttributeMap getDefaultVertexAttributes() + { + return defaultVertexAttributes; + } + + /** + * Returns the JGraph edge cell that corresponds to the specified JGraphT + * edge. If no corresponding cell found, returns null. + * + * @param jGraphTEdge a JGraphT edge of the JGraphT graph. + * + * @return the JGraph edge cell that corresponds to the specified JGraphT + * edge, or null if no corresponding cell found. + */ + public DefaultEdge getEdgeCell(E jGraphTEdge) + { + return (DefaultEdge) edgeToCell.get(jGraphTEdge); + } + + /** + * Returns the JGraph vertex cell that corresponds to the specified JGraphT + * vertex. If no corresponding cell found, returns null. + * + * @param jGraphTVertex a JGraphT vertex of the JGraphT graph. + * + * @return the JGraph vertex cell that corresponds to the specified JGraphT + * vertex, or null if no corresponding cell found. + */ + public DefaultGraphCell getVertexCell(Object jGraphTVertex) + { + return (DefaultGraphCell) vertexToCell.get(jGraphTVertex); + } + + /** + * Returns the JGraph port cell that corresponds to the specified JGraphT + * vertex. If no corresponding port found, returns null. + * + * @param jGraphTVertex a JGraphT vertex of the JGraphT graph. + * + * @return the JGraph port cell that corresponds to the specified JGraphT + * vertex, or null if no corresponding cell found. + */ + public DefaultPort getVertexPort(Object jGraphTVertex) + { + DefaultGraphCell vertexCell = getVertexCell(jGraphTVertex); + + if (vertexCell == null) { + return null; + } else { + return (DefaultPort) vertexCell.getChildAt(0); + } + } + + /** + * Adds/removes an edge to/from the underlying JGraphT graph according to + * the change in the specified JGraph edge. If both vertices are connected, + * we ensure to have a corresponding JGraphT edge. Otherwise, we ensure NOT + * to have a corresponding JGraphT edge. + * + *

    This method is to be called only for edges that have already been + * changed in the JGraph graph.

    + * + * @param jEdge the JGraph edge that has changed. + */ + void handleJGraphChangedEdge(org.jgraph.graph.Edge jEdge) + { + if (isDangling(jEdge)) { + if (cellToEdge.containsKey(jEdge)) { + // a non-dangling edge became dangling -- remove the JGraphT + // edge by faking as if the edge is removed from the JGraph. + // TODO: Consider keeping the JGraphT edges outside the graph + // to avoid loosing user data, such as weights. + handleJGraphRemovedEdge(jEdge); + } else { + // a dangling edge is still dangling -- just ignore. + } + } else { + // edge is not dangling + if (cellToEdge.containsKey(jEdge)) { + // edge already has a corresponding JGraphT edge. + // check if any change to its endpoints. + E jtEdge = cellToEdge.get(jEdge); + + Object jSource = getSourceVertex(this, jEdge); + Object jTarget = getTargetVertex(this, jEdge); + + Object jtSource = cellToVertex.get(jSource); + Object jtTarget = cellToVertex.get(jTarget); + + if ((jtGraph.getEdgeSource(jtEdge) == jtSource) + && (jtGraph.getEdgeTarget(jtEdge) == jtTarget)) + { + // no change in edge's endpoints -- nothing to do. + } else { + // edge's end-points have changed -- need to refresh the + // JGraphT edge. Refresh by faking as if the edge has been + // removed from JGraph and then added again. + // ALSO HERE: consider an alternative that maintains user + // data + handleJGraphRemovedEdge(jEdge); + handleJGraphInsertedEdge(jEdge); + } + } else { + // a new edge + handleJGraphInsertedEdge(jEdge); + } + } + } + + /** + * Adds to the underlying JGraphT graph an edge that corresponds to the + * specified JGraph edge. If the specified JGraph edge is a dangling edge, + * it is NOT added to the underlying JGraphT graph. + * + *

    This method is to be called only for edges that have already been + * added to the JGraph graph.

    + * + * @param jEdge the JGraph edge that has been added. + */ + void handleJGraphInsertedEdge(org.jgraph.graph.Edge jEdge) + { + if (isDangling(jEdge)) { + // JGraphT forbid dangling edges so we cannot add the edge yet. If + // later the edge becomes connected, we will add it. + } else { + // FIXME hb 28-nov-05: waiting for jgraph to go generic + Object jSource = getSourceVertex(this, jEdge); + Object jTarget = getTargetVertex(this, jEdge); + + V jtSource = cellToVertex.get(jSource); + V jtTarget = cellToVertex.get(jTarget); + + E jtEdge = jtGraph.addEdge(jtSource, jtTarget); + + if (jtEdge != null) { + cellToEdge.put(jEdge, jtEdge); + edgeToCell.put(jtEdge, jEdge); + } else { + // Adding failed because user is using a JGraphT graph the + // forbids parallel edges. + // For consistency, we remove the edge from the JGraph too. + internalRemoveCell(jEdge); + System.err.println( + "Warning: an edge was deleted because the underlying " + + "JGraphT graph refused to create it. " + + "This situation can happen when a constraint of the " + + "underlying graph is violated, e.g., an attempt to add " + + "a parallel edge or a self-loop to a graph that forbids " + + "them. To avoid this message, make sure to use a " + + "suitable underlying JGraphT graph."); + } + } + } + + /** + * Adds to the underlying JGraphT graph a vertex corresponding to the + * specified JGraph vertex. In JGraph, two vertices with the same user + * object are in principle allowed; in JGraphT, this would lead to duplicate + * vertices, which is not allowed. So if such vertex already exists, the + * specified vertex is REMOVED from the JGraph graph and a a warning is + * printed. + * + *

    This method is to be called only for vertices that have already been + * added to the JGraph graph.

    + * + * @param jVertex the JGraph vertex that has been added. + */ + @SuppressWarnings("unchecked") + void handleJGraphInsertedVertex(GraphCell jVertex) + { + V jtVertex; + + if (jVertex instanceof DefaultGraphCell) { + // FIXME hb 28-nov-05: waiting for jgraph to go generic + jtVertex = (V) ((DefaultGraphCell) jVertex).getUserObject(); + } else { + // FIXME: Why toString? Explain if for a good reason otherwise fix. + jtVertex = (V) jVertex.toString(); + } + + if (vertexToCell.containsKey(jtVertex)) { + // We have to remove the new vertex, because it would lead to + // duplicate vertices. We can't use ShieldedGraph.removeVertex for + // that, because it would remove the wrong (existing) vertex. + System.err.println( + "Warning: detected two JGraph vertices with " + + "the same JGraphT vertex as user object. It is an " + + "indication for a faulty situation that should NOT happen." + + "Removing vertex: " + jVertex); + internalRemoveCell(jVertex); + } else { + jtGraph.addVertex(jtVertex); + + cellToVertex.put(jVertex, jtVertex); + vertexToCell.put(jtVertex, jVertex); + } + } + + /** + * Removes the edge corresponding to the specified JGraph edge from the + * JGraphT graph. If the specified edge is not contained in {@link + * #cellToEdge}, it is silently ignored. + * + *

    This method is to be called only for edges that have already been + * removed from the JGraph graph.

    + * + * @param jEdge the JGraph edge that has been removed. + */ + void handleJGraphRemovedEdge(org.jgraph.graph.Edge jEdge) + { + if (cellToEdge.containsKey(jEdge)) { + E jtEdge = cellToEdge.get(jEdge); + + jtGraph.removeEdge(jtEdge); + + cellToEdge.remove(jEdge); + edgeToCell.remove(jtEdge); + } + } + + /** + * Removes the vertex corresponding to the specified JGraph vertex from the + * JGraphT graph. If the specified vertex is not contained in {@link + * #cellToVertex}, it is silently ignored. + * + *

    If any edges are incident with this vertex, we first remove them from + * the both graphs, because otherwise the JGraph graph would leave them + * intact and the JGraphT graph would throw them out. TODO: Revise this + * behavior now that we gracefully tolerate dangling edges. It might be + * possible to remove just the JGraphT edges. The JGraph edges will be left + * dangling, as a result.

    + * + *

    This method is to be called only for vertices that have already been + * removed from the JGraph graph.

    + * + * @param jVertex the JGraph vertex that has been removed. + */ + void handleJGraphRemovedVertex(GraphCell jVertex) + { + if (cellToVertex.containsKey(jVertex)) { + V jtVertex = cellToVertex.get(jVertex); + Set jtIncidentEdges = jtGraph.edgesOf(jtVertex); + + if (!jtIncidentEdges.isEmpty()) { + // We can't just call removeAllEdges with this list: that + // would throw a ConcurrentModificationException. So we create + // a shallow copy. + // This also triggers removal of the corresponding JGraph + // edges. + jtGraph.removeAllEdges(new ArrayList(jtIncidentEdges)); + } + + jtGraph.removeVertex(jtVertex); + + cellToVertex.remove(jVertex); + vertexToCell.remove(jtVertex); + } + } + + /** + * Adds the specified JGraphT edge to be reflected by this graph model. To + * be called only for edges that already exist in the JGraphT graph. + * + * @param jtEdge a JGraphT edge to be reflected by this graph model. + */ + void handleJGraphTAddedEdge(E jtEdge) + { + DefaultEdge edgeCell = cellFactory.createEdgeCell(jtEdge); + edgeToCell.put(jtEdge, edgeCell); + cellToEdge.put(edgeCell, jtEdge); + + ConnectionSet cs = new ConnectionSet(); + cs.connect( + edgeCell, + getVertexPort(jtGraph.getEdgeSource(jtEdge)), + getVertexPort(jtGraph.getEdgeTarget(jtEdge))); + + internalInsertCell(edgeCell, createEdgeAttributeMap(edgeCell), cs); + } + + /** + * Adds the specified JGraphT vertex to be reflected by this graph model. To + * be called only for edges that already exist in the JGraphT graph. + * + * @param jtVertex a JGraphT vertex to be reflected by this graph model. + */ + void handleJGraphTAddedVertex(V jtVertex) + { + DefaultGraphCell vertexCell = cellFactory.createVertexCell(jtVertex); + vertexCell.add(new DefaultPort()); + + vertexToCell.put(jtVertex, vertexCell); + cellToVertex.put(vertexCell, jtVertex); + + internalInsertCell( + vertexCell, + createVertexAttributeMap(vertexCell), + null); + } + + /** + * Removes the specified JGraphT vertex from being reflected by this graph + * model. To be called only for vertices that have already been removed from + * the JGraphT graph. + * + * @param jtVertex a JGraphT vertex to be removed from being reflected by + * this graph model. + */ + void handleJGraphTRemoveVertex(Object jtVertex) + { + DefaultGraphCell vertexCell = + (DefaultGraphCell) vertexToCell.remove(jtVertex); + cellToVertex.remove(vertexCell); + + List ports = new ArrayList(); + + for (Object child : vertexCell.getChildren()) { + if (this.isPort(child)) { + ports.add(child); + } + } + this.remove(ports.toArray()); + + internalRemoveCell(vertexCell); + } + + /** + * Removes the specified JGraphT edge from being reflected by this graph + * model. To be called only for edges that have already been removed from + * the JGraphT graph. + * + * @param jtEdge a JGraphT edge to be removed from being reflected by this + * graph model. + */ + void handleJGraphTRemovedEdge(E jtEdge) + { + DefaultEdge edgeCell = (DefaultEdge) edgeToCell.remove(jtEdge); + cellToEdge.remove(edgeCell); + internalRemoveCell(edgeCell); + } + + /** + * Tests if the specified JGraph edge is 'dangling', that is having at least + * one endpoint which is not connected to a vertex. + * + * @param jEdge the JGraph edge to be tested for being dangling. + * + * @return true if the specified edge is dangling, otherwise + * false. + */ + private boolean isDangling(org.jgraph.graph.Edge jEdge) + { + Object jSource = getSourceVertex(this, jEdge); + Object jTarget = getTargetVertex(this, jEdge); + + return !cellToVertex.containsKey(jSource) + || !cellToVertex.containsKey(jTarget); + } + + @SuppressWarnings("unchecked") + private AttributeMap createEdgeAttributeMap(DefaultEdge edgeCell) + { + AttributeMap attrs = new AttributeMap(); + + // FIXME hb 28-nov-05: waiting for graph to go generic + attrs.put(edgeCell, getDefaultEdgeAttributes().clone()); + + return attrs; + } + + @SuppressWarnings("unchecked") + private AttributeMap createVertexAttributeMap(GraphCell vertexCell) + { + AttributeMap attrs = new AttributeMap(); + + // FIXME hb 28-nov-05: waiting for graph to go generic + attrs.put(vertexCell, getDefaultVertexAttributes().clone()); + + return attrs; + } + + /** + * Inserts the specified cell into the JGraph graph model. + * + * @param cell + * @param attrs + * @param cs + */ + // FIXME hb 28-nov-05: waiting for graph to go generic + private void internalInsertCell( + GraphCell cell, + AttributeMap attrs, + ConnectionSet cs) + { + jCellsBeingAdded.add(cell); + insert(new Object[] { cell }, attrs, cs, null, null); + jCellsBeingAdded.remove(cell); + } + + /** + * Removed the specified cell from the JGraph graph model. + * + * @param cell + */ + private void internalRemoveCell(GraphCell cell) + { + jCellsBeingRemoved.add(cell); + remove(new Object[] { cell }); + jCellsBeingRemoved.remove(cell); + } + + //~ Inner Interfaces ------------------------------------------------------- + + /** + * Creates the JGraph cells that reflect the respective JGraphT elements. + * + * @author Barak Naveh + * @since Dec 12, 2003 + */ + public static interface CellFactory + { + /** + * Creates an edge cell that contains its respective JGraphT edge. + * + * @param jGraphTEdge a JGraphT edge to be contained. + * + * @return an edge cell that contains its respective JGraphT edge. + */ + public DefaultEdge createEdgeCell(EE jGraphTEdge); + + /** + * Creates a vertex cell that contains its respective JGraphT vertex. + * + * @param jGraphTVertex a JGraphT vertex to be contained. + * + * @return a vertex cell that contains its respective JGraphT vertex. + */ + public DefaultGraphCell createVertexCell(VV jGraphTVertex); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * A simple default cell factory. + * + * @author Barak Naveh + * @since Dec 12, 2003 + */ + public static class DefaultCellFactory + implements CellFactory, + Serializable + { + private static final long serialVersionUID = 3690194343461861173L; + + /** + * @see JGraphModelAdapter.CellFactory#createEdgeCell(Object) + */ + public DefaultEdge createEdgeCell(EE jGraphTEdge) + { + return new DefaultEdge(jGraphTEdge); + } + + /** + * @see JGraphModelAdapter.CellFactory#createVertexCell(Object) + */ + public DefaultGraphCell createVertexCell(VV jGraphTVertex) + { + return new DefaultGraphCell(jGraphTVertex); + } + } + + /** + *

    Inner class listening to the GraphModel. If something is changed in + * the GraphModel, this Listener gets notified and propagates the change + * back to the JGraphT graph, if it didn't originate there.

    + * + *

    If this change contains changes that would make this an illegal + * JGraphT graph, like adding an edge that is incident with only one vertex, + * the illegal parts of the change are undone.

    + */ + private class JGraphListener + implements GraphModelListener, + Serializable + { + private static final long serialVersionUID = 3544673988098865209L; + + /** + * This method is called for all JGraph changes. + * + * @param e + */ + public void graphChanged(GraphModelEvent e) + { + // We first remove edges that have to be removed, then we + // remove vertices, then we add vertices and finally we add + // edges. Otherwise, things might go wrong: for example, if we + // would first remove vertices and then edges, removal of the + // vertices might induce 'automatic' removal of edges. If we + // later attempt to re-remove these edges, we get confused. + GraphModelChange change = e.getChange(); + + Object [] removedCells = change.getRemoved(); + + if (removedCells != null) { + handleRemovedEdges(filterEdges(removedCells)); + handleRemovedVertices(filterVertices(removedCells)); + } + + Object [] insertedCells = change.getInserted(); + + if (insertedCells != null) { + handleInsertedVertices(filterVertices(insertedCells)); + handleInsertedEdges(filterEdges(insertedCells)); + } + + // Now handle edges that became 'dangling' or became connected. + Object [] changedCells = change.getChanged(); + + if (changedCells != null) { + handleChangedEdges(filterEdges(changedCells)); + } + } + + /** + * Filters a list of edges out of an array of JGraph GraphCell objects. + * Other objects are thrown away. + * + * @param cells Array of cells to be filtered. + * + * @return a list of edges. + */ + private List filterEdges(Object [] cells) + { + List jEdges = new ArrayList(); + + for (int i = 0; i < cells.length; i++) { + if (cells[i] instanceof org.jgraph.graph.Edge) { + jEdges.add(cells[i]); + } + } + + return jEdges; + } + + /** + * Filters a list of vertices out of an array of JGraph GraphCell + * objects. Other objects are thrown away. + * + * @param cells Array of cells to be filtered. + * + * @return a list of vertices. + */ + private List filterVertices(Object [] cells) + { + List jVertices = new ArrayList(); + + for (int i = 0; i < cells.length; i++) { + Object cell = cells[i]; + + if (cell instanceof org.jgraph.graph.Edge) { + // ignore -- we don't care about edges. + } else if (cell instanceof Port) { + // ignore -- we don't care about ports. + } else if (cell instanceof DefaultGraphCell) { + DefaultGraphCell graphCell = (DefaultGraphCell) cell; + + // If a DefaultGraphCell has a Port as a child, it is a + // vertex. + // Note: do not change the order of following conditions; + // the code uses the short-circuit evaluation of ||. + if (graphCell.isLeaf() + || (graphCell.getFirstChild() instanceof Port)) + { + jVertices.add(cell); + } + } else if (cell instanceof GraphCell) { + // If it is not a DefaultGraphCell, it doesn't have + // children. + jVertices.add(cell); + } + } + + return jVertices; + } + + private void handleChangedEdges(List jEdges) + { + for (Iterator i = jEdges.iterator(); i.hasNext();) { + org.jgraph.graph.Edge jEdge = (org.jgraph.graph.Edge) i.next(); + + handleJGraphChangedEdge(jEdge); + } + } + + private void handleInsertedEdges(List jEdges) + { + for (Iterator i = jEdges.iterator(); i.hasNext();) { + org.jgraph.graph.Edge jEdge = (org.jgraph.graph.Edge) i.next(); + + if (!jCellsBeingAdded.remove(jEdge)) { + handleJGraphInsertedEdge(jEdge); + } + } + } + + private void handleInsertedVertices(List jVertices) + { + for (Iterator i = jVertices.iterator(); i.hasNext();) { + GraphCell jVertex = (GraphCell) i.next(); + + if (!jCellsBeingAdded.remove(jVertex)) { + handleJGraphInsertedVertex(jVertex); + } + } + } + + private void handleRemovedEdges(List jEdges) + { + for (Iterator i = jEdges.iterator(); i.hasNext();) { + org.jgraph.graph.Edge jEdge = (org.jgraph.graph.Edge) i.next(); + + if (!jCellsBeingRemoved.remove(jEdge)) { + handleJGraphRemovedEdge(jEdge); + } + } + } + + private void handleRemovedVertices(List jVertices) + { + for (Iterator i = jVertices.iterator(); i.hasNext();) { + GraphCell jVertex = (GraphCell) i.next(); + + if (!jCellsBeingRemoved.remove(jVertex)) { + handleJGraphRemovedVertex(jVertex); + } + } + } + } + + /** + * A listener on the underlying JGraphT graph. This listener is used to keep + * the JGraph model in sync. Whenever one of the event handlers is called, + * it first checks whether the change is due to a previous change in the + * JGraph model. If it is, then no action is taken. + * + * @author Barak Naveh + * @since Aug 2, 2003 + */ + private class JGraphTListener + implements GraphListener, + Serializable + { + private static final long serialVersionUID = 3616724963609360440L; + + /** + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public void edgeAdded(GraphEdgeChangeEvent e) + { + E jtEdge = e.getEdge(); + + if (!jtElementsBeingAdded.remove(jtEdge)) { + handleJGraphTAddedEdge(jtEdge); + } + } + + /** + * @see GraphListener#edgeRemoved(GraphEdgeChangeEvent) + */ + public void edgeRemoved(GraphEdgeChangeEvent e) + { + E jtEdge = e.getEdge(); + + if (!jtElementsBeingRemoved.remove(jtEdge)) { + handleJGraphTRemovedEdge(jtEdge); + } + } + + /** + * @see VertexSetListener#vertexAdded(GraphVertexChangeEvent) + */ + public void vertexAdded(GraphVertexChangeEvent e) + { + V jtVertex = e.getVertex(); + + if (!jtElementsBeingAdded.remove(jtVertex)) { + handleJGraphTAddedVertex(jtVertex); + } + } + + /** + * @see VertexSetListener#vertexRemoved(GraphVertexChangeEvent) + */ + public void vertexRemoved(GraphVertexChangeEvent e) + { + V jtVertex = e.getVertex(); + + if (!jtElementsBeingRemoved.remove(jtVertex)) { + handleJGraphTRemoveVertex(jtVertex); + } + } + } + + /** + * A wrapper around a JGraphT graph that ensures a few atomic operations. + */ + private class ShieldedGraph + { + private final Graph graph; + + ShieldedGraph(Graph graph) + { + this.graph = graph; + } + + EdgeFactory getEdgeFactory() + { + return graph.getEdgeFactory(); + } + + E addEdge(V jtSource, V jtTarget) + { + E jtEdge = graph.getEdgeFactory().createEdge(jtSource, jtTarget); + jtElementsBeingAdded.add(jtEdge); + + boolean added = graph.addEdge(jtSource, jtTarget, jtEdge); + jtElementsBeingAdded.remove(jtEdge); + + return added ? jtEdge : null; + } + + V getEdgeSource(E e) + { + return graph.getEdgeSource(e); + } + + V getEdgeTarget(E e) + { + return graph.getEdgeTarget(e); + } + + void addVertex(V jtVertex) + { + jtElementsBeingAdded.add(jtVertex); + graph.addVertex(jtVertex); + jtElementsBeingAdded.remove(jtVertex); + } + + Set edgesOf(V vertex) + { + return graph.edgesOf(vertex); + } + + boolean removeAllEdges(Collection edges) + { + return graph.removeAllEdges(edges); + } + + void removeEdge(E jtEdge) + { + jtElementsBeingRemoved.add(jtEdge); + graph.removeEdge(jtEdge); + jtElementsBeingRemoved.remove(jtEdge); + } + + void removeVertex(V jtVertex) + { + jtElementsBeingRemoved.add(jtVertex); + graph.removeVertex(jtVertex); + jtElementsBeingRemoved.remove(jtVertex); + } + } +} + +// End JGraphModelAdapter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/MatrixExporter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/MatrixExporter.java new file mode 100644 index 00000000..3c746bc7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/MatrixExporter.java @@ -0,0 +1,264 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * MatrixExporter.java + * ------------------ + * (C) Copyright 2005-2008, by Charles Fry and Contributors. + * + * Original Author: Charles Fry + * + * $Id: MatrixExporter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Dec-2005 : Initial Version (CF); + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * 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 + */ +public class MatrixExporter +{ + //~ Instance fields -------------------------------------------------------- + + private String delimiter = " "; + private String prefix = ""; + private String suffix = ""; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new MatrixExporter object. + */ + public MatrixExporter() + { + } + + //~ Methods ---------------------------------------------------------------- + + private void println( + PrintWriter out, + String fromName, + String toName, + String value) + { + out.println( + prefix + fromName + suffix + delimiter + + prefix + toName + suffix + delimiter + + prefix + value + suffix); + } + + /** + * 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. + * + * @param output the writer to which the graph to be exported. + * @param g the graph to be exported. + */ + public void exportAdjacencyMatrix(Writer output, UndirectedGraph g) + { + PrintWriter out = new PrintWriter(output); + + VertexNameProvider nameProvider = new IntegerNameProvider(); + for (V from : g.vertexSet()) { + // assign ids in vertex set iteration order + nameProvider.getVertexName(from); + } + + for (V from : g.vertexSet()) { + exportAdjacencyMatrixVertex( + out, + nameProvider, + from, + Graphs.neighborListOf(g, from)); + } + + out.flush(); + } + + /** + * 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. + * + * @param output the writer to which the graph to be exported. + * @param g the graph to be exported. + */ + public void exportAdjacencyMatrix(Writer output, DirectedGraph g) + { + PrintWriter out = new PrintWriter(output); + + VertexNameProvider nameProvider = new IntegerNameProvider(); + for (V from : g.vertexSet()) { + // assign ids in vertex set iteration order + nameProvider.getVertexName(from); + } + + for (V from : g.vertexSet()) { + exportAdjacencyMatrixVertex( + out, + nameProvider, + from, + Graphs.successorListOf(g, from)); + } + + out.flush(); + } + + private void exportAdjacencyMatrixVertex( + PrintWriter out, + VertexNameProvider nameProvider, + V from, + List neighbors) + { + String fromName = nameProvider.getVertexName(from); + Map counts = + new LinkedHashMap(); + for (V to : neighbors) { + String toName = nameProvider.getVertexName(to); + ModifiableInteger count = counts.get(toName); + if (count == null) { + count = new ModifiableInteger(0); + counts.put(toName, count); + } + + count.increment(); + if (from.equals(to)) { + // count loops twice, once for each end + count.increment(); + } + } + for (Map.Entry entry : counts.entrySet()) { + String toName = entry.getKey(); + ModifiableInteger count = entry.getValue(); + println(out, fromName, toName, count.toString()); + } + } + + /** + * 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. + * + * @param output the writer to which the graph is to be exported. + * @param g the graph to be exported. + */ + public void exportLaplacianMatrix(Writer output, UndirectedGraph g) + { + PrintWriter out = new PrintWriter(output); + + VertexNameProvider nameProvider = new IntegerNameProvider(); + for (V from : g.vertexSet()) { + // assign ids in vertex set iteration order + nameProvider.getVertexName(from); + } + + for (V from : g.vertexSet()) { + String fromName = nameProvider.getVertexName(from); + + // TODO modify Graphs to return neighbor sets + List neighbors = Graphs.neighborListOf(g, from); + println( + out, + fromName, + fromName, + Integer.toString(neighbors.size())); + for (V to : neighbors) { + String toName = nameProvider.getVertexName(to); + println(out, fromName, toName, "-1"); + } + } + + out.flush(); + } + + /** + * 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. + * + * @param output the writer to which the graph is to be exported. + * @param g the graph to be exported. + */ + public void exportNormalizedLaplacianMatrix( + Writer output, + UndirectedGraph g) + { + PrintWriter out = new PrintWriter(output); + + VertexNameProvider nameProvider = new IntegerNameProvider(); + for (V from : g.vertexSet()) { + // assign ids in vertex set iteration order + nameProvider.getVertexName(from); + } + + for (V from : g.vertexSet()) { + String fromName = nameProvider.getVertexName(from); + Set neighbors = + new LinkedHashSet(Graphs.neighborListOf(g, from)); + if (neighbors.isEmpty()) { + println(out, fromName, fromName, "0"); + } else { + println(out, fromName, fromName, "1"); + + for (V to : neighbors) { + String toName = nameProvider.getVertexName(to); + double value = + -1 / Math.sqrt(g.degreeOf(from) * g.degreeOf(to)); + println(out, fromName, toName, Double.toString(value)); + } + } + } + + out.flush(); + } +} + +// End MatrixExporter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/StringEdgeNameProvider.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/StringEdgeNameProvider.java new file mode 100644 index 00000000..61a1fb45 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/StringEdgeNameProvider.java @@ -0,0 +1,64 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * StringNameProvider.java + * ------------------ + * (C) Copyright 2005-2008, by Trevor Harmon. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +/** + * Generates edge names by invoking {@link #toString()} on them. This assumes + * that the edge's {@link #toString()} method returns a unique String + * representation for each edge. + * + * @author Trevor Harmon + */ +public class StringEdgeNameProvider + implements EdgeNameProvider +{ + //~ Constructors ----------------------------------------------------------- + + public StringEdgeNameProvider() + { + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the String representation an edge. + * + * @param edge the edge to be named + */ + public String getEdgeName(E edge) + { + return edge.toString(); + } +} + +// End StringEdgeNameProvider.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/StringNameProvider.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/StringNameProvider.java new file mode 100644 index 00000000..b3fab5e8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/StringNameProvider.java @@ -0,0 +1,78 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * StringNameProvider.java + * ------------------ + * (C) Copyright 2005-2008, by Charles Fry and Contributors. + * + * Original Author: Charles Fry + * + * $Id: StringNameProvider.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 13-Dec-2005 : Initial Version (CF); + * + */ +package org.jgrapht.ext; + +import org.jgrapht.event.*; + + +/** + * Generates vertex names by invoking {@link #toString()} on them. This assumes + * that the vertex's {@link #toString()} method returns a unique String + * representation for each vertex. + * + * @author Charles Fry + */ +public class StringNameProvider + implements VertexNameProvider +{ + //~ Constructors ----------------------------------------------------------- + + public StringNameProvider() + { + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Returns the String representation of the unique integer representing a + * vertex. + * + * @param vertex the vertex to be named + * + * @return the name of + * + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public String getVertexName(V vertex) + { + return vertex.toString(); + } +} + +// End StringNameProvider.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/VertexNameProvider.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/VertexNameProvider.java new file mode 100644 index 00000000..c97fdae3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/VertexNameProvider.java @@ -0,0 +1,61 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * VertexNameProvider.java + * ------------------ + * (C) Copyright 2005-2008, by Avner Linder and Contributors. + * + * Original Author: Avner Linder + * + * $Id: VertexNameProvider.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 27-May-2004 : Initial Version (AL); + * 13-Dec-2005 : Split out of VisioExporter (CF); + * + */ +package org.jgrapht.ext; + +/** + * Assigns a display name for each of the graph vertices. + */ +public interface VertexNameProvider +{ + //~ Methods ---------------------------------------------------------------- + + /** + * 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. + * + * @param vertex the vertex to be named + * + * @return the name of the vertex + */ + public String getVertexName(V vertex); +} + +// End VertexNameProvider.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/VisioExporter.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/VisioExporter.java new file mode 100644 index 00000000..b1b62405 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/VisioExporter.java @@ -0,0 +1,149 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * VisioExporter.java + * ------------------ + * (C) Copyright 2003-2008, by Avner Linder and Contributors. + * + * Original Author: Avner Linder + * Contributor(s): Barak Naveh + * + * $Id: VisioExporter.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 27-May-2004 : Initial Version (AL); + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * Exports a graph to a csv format that can be imported into MS Visio. + * + *

    Tip: By default, the exported graph doesn't show link directions. + * To show link directions:
    + * + *

      + *
    1. Select All (Ctrl-A)
    2. + *
    3. Right Click the selected items
    4. + *
    5. Format/Line...
    6. + *
    7. Line ends: End: (choose an arrow)
    8. + *
    + *

    + * + * @author Avner Linder + */ +public class VisioExporter +{ + //~ Instance fields -------------------------------------------------------- + + private VertexNameProvider vertexNameProvider; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new VisioExporter object with the specified naming policy. + * + * @param vertexNameProvider the vertex name provider to be used for naming + * the Visio shapes. + */ + public VisioExporter(VertexNameProvider vertexNameProvider) + { + this.vertexNameProvider = vertexNameProvider; + } + + /** + * Creates a new VisioExporter object. + */ + public VisioExporter() + { + this(new StringNameProvider()); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Exports the specified graph into a Visio csv file format. + * + * @param output the print stream to which the graph to be exported. + * @param g the graph to be exported. + */ + public void export(OutputStream output, Graph g) + { + PrintStream out = new PrintStream(output); + + for (Iterator i = g.vertexSet().iterator(); i.hasNext();) { + exportVertex(out, i.next()); + } + + for (Iterator i = g.edgeSet().iterator(); i.hasNext();) { + exportEdge(out, i.next(), g); + } + + out.flush(); + } + + private void exportEdge(PrintStream out, E edge, Graph g) + { + String sourceName = + vertexNameProvider.getVertexName(g.getEdgeSource(edge)); + String targetName = + vertexNameProvider.getVertexName(g.getEdgeTarget(edge)); + + out.print("Link,"); + + // create unique ShapeId for link + out.print(sourceName); + out.print("-->"); + out.print(targetName); + + // MasterName and Text fields left blank + out.print(",,,"); + out.print(sourceName); + out.print(","); + out.print(targetName); + out.print("\n"); + } + + private void exportVertex(PrintStream out, V vertex) + { + String name = vertexNameProvider.getVertexName(vertex); + + out.print("Shape,"); + out.print(name); + out.print(",,"); // MasterName field left empty + out.print(name); + out.print("\n"); + } +} + +// End VisioExporter.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/package.html new file mode 100644 index 00000000..19dfbaeb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/ext/package.html @@ -0,0 +1,8 @@ + + + +

    +Extensions and integration means to other products. +

    + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/CompleteBipartiteGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/CompleteBipartiteGraphGenerator.java new file mode 100644 index 00000000..3098cb11 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/CompleteBipartiteGraphGenerator.java @@ -0,0 +1,119 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * CompleteBipartiteGraphGenerator.java + * ------------------- + * (C) Copyright 2008-2008, by Andrew Newell and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: CompleteBipartiteGraphGenerator.java 680 2009-05-25 05:55:31Z perfecthash $ + * + * Changes + * ------- + * 24-Dec-2008 : Initial revision (AN); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Andrew Newell + * @since Dec 21, 2008 + */ +public class CompleteBipartiteGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private int sizeA, sizeB; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new CompleteBipartiteGraphGenerator object. + * + * @param partitionOne This is the number of vertices in the first partition + * @param partitionTwo This is the number of vertices in the second parition + */ + public CompleteBipartiteGraphGenerator(int partitionOne, int partitionTwo) + { + if ((partitionOne < 0) || (partitionTwo < 0)) { + throw new IllegalArgumentException("must be non-negative"); + } + this.sizeA = partitionOne; + this.sizeB = partitionTwo; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Construct a complete bipartite graph + */ + public void generateGraph( + Graph target, + final VertexFactory vertexFactory, + Map resultMap) + { + if ((sizeA < 1) && (sizeB < 1)) { + return; + } + + //Create vertices in each of the partitions + Set a = new HashSet(); + Set b = new HashSet(); + for (int i = 0; i < sizeA; i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + a.add(newVertex); + } + for (int i = 0; i < sizeB; i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + b.add(newVertex); + } + + //Add an edge for each pair of vertices in different partitions + for (Iterator iterA = a.iterator(); iterA.hasNext();) { + V v = iterA.next(); + for (Iterator iterB = b.iterator(); iterB.hasNext();) { + target.addEdge(v, iterB.next()); + } + } + } +} + +// End CompleteBipartiteGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/CompleteGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/CompleteGraphGenerator.java new file mode 100644 index 00000000..6573db5d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/CompleteGraphGenerator.java @@ -0,0 +1,139 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * CompleteGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by Tim Shearouse and Contributors. + * + * Original Author: Tim Shearouse + * Contributor(s): - + * + * $Id: CompleteGraphGenerator.java 598 2008-04-13 02:50:13Z perfecthash $ + * + * Changes + * ------- + * 10-Feb-2008 : Initial revision (TS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Tim Shearouse + * @since Nov 02, 2008 + */ +public class CompleteGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private int size; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new CompleteGraphGenerator. + * + * @param size number of vertices to be generated + * + * @throws IllegalArgumentException if the specified size is negative. + */ + public CompleteGraphGenerator(int size) + { + if (size < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + this.size = size; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + if (size < 1) { + return; + } + + //Add all the vertices to the set + for (int i = 0; i < size; i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + } + + /* + * We want two iterators over the vertex set, one fast and one slow. + * The slow one will move through the set once. For each vertex, + * the fast iterator moves through the set, adding an edge to all + * vertices we haven't connected to yet. + * + * If we have an undirected graph, the second addEdge call will return + * nothing; it will not add a second edge. + */ + Iterator slowI = target.vertexSet().iterator(); + Iterator fastI; + + while (slowI.hasNext()) { //While there are more vertices in the set + + V latestVertex = slowI.next(); + fastI = target.vertexSet().iterator(); + + //Jump to the first vertex *past* latestVertex + while (fastI.next() != latestVertex) { + ; + } + + //And, add edges to all remaining vertices + V temp; + while (fastI.hasNext()) { + temp = fastI.next(); + target.addEdge(latestVertex, temp); + target.addEdge(temp, latestVertex); + } + } + } +} + +// End CompleteGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/EmptyGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/EmptyGraphGenerator.java new file mode 100644 index 00000000..db56bd30 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/EmptyGraphGenerator.java @@ -0,0 +1,95 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * EmptyGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: EmptyGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * Generates an empty + * graph of any size. An empty graph is a graph that has no edges. + * + * @author John V. Sichi + * @since Sep 16, 2003 + */ +public class EmptyGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private int size; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new EmptyGraphGenerator. + * + * @param size number of vertices to be generated + * + * @throws IllegalArgumentException if the specified size is negative. + */ + public EmptyGraphGenerator(int size) + { + if (size < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + this.size = size; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + for (int i = 0; i < size; ++i) { + target.addVertex(vertexFactory.createVertex()); + } + } +} + +// End EmptyGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/GraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/GraphGenerator.java new file mode 100644 index 00000000..218dbcec --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/GraphGenerator.java @@ -0,0 +1,80 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * GraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: GraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * GraphGenerator defines an interface for generating new graph structures. + * + * @author John V. Sichi + * @since Sep 16, 2003 + */ +public interface GraphGenerator +{ + //~ Methods ---------------------------------------------------------------- + + /** + * 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. + * + * @param 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 + * @param vertexFactory called to produce new vertices + * @param resultMap if non-null, receives implementation-specific mappings + * from String roles to graph elements (or collections of graph elements) + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap); +} + +// End GraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/HyperCubeGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/HyperCubeGraphGenerator.java new file mode 100644 index 00000000..6bcf3039 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/HyperCubeGraphGenerator.java @@ -0,0 +1,118 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * HyperCubeGraphGenerator.java + * ------------------- + * (C) Copyright 2008-2008, by Andrew Newell and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: HyperCubeGraphGenerator.java 650 2008-12-24 20:44:06Z perfecthash $ + * + * Changes + * ------- + * 24-Dec-2008 : Initial revision (AN); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Andrew Newell + * @since Dec 21, 2008 + */ +public class HyperCubeGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private int dim; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new HyperCubeGraphGenerator object. + * + * @param dim This is the dimension of the hypercube. + */ + public HyperCubeGraphGenerator(int dim) + { + this.dim = dim; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * This will generate the hypercube graph + */ + public void generateGraph( + Graph target, + final VertexFactory vertexFactory, + Map resultMap) + { + //Vertices are created, and they are included in the resultmap as their + //bitstring representation + int order = (int) Math.pow(2, dim); + LinkedList vertices = new LinkedList(); + for (int i = 0; i < order; i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + vertices.add(newVertex); + if (resultMap != null) { + String s = Integer.toBinaryString(i); + while (s.length() < dim) { + s = "0" + s; + } + resultMap.put(s, newVertex); + } + } + + //Two vertices will have an edge if their bitstrings differ by exactly + //1 element + for (int i = 0; i < order; i++) { + for (int j = i + 1; j < order; j++) { + for (int z = 0; z < dim; z++) { + if ((j ^ i) == (1 << z)) { + target.addEdge(vertices.get(i), vertices.get(j)); + break; + } + } + } + } + } +} + +// End HyberCubeGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/LinearGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/LinearGraphGenerator.java new file mode 100644 index 00000000..ce1b6753 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/LinearGraphGenerator.java @@ -0,0 +1,124 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * LinearGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: LinearGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * Generates a linear graph of any size. For a directed graph, the edges are + * oriented from START_VERTEX to END_VERTEX. + * + * @author John V. Sichi + * @since Sep 16, 2003 + */ +public class LinearGraphGenerator + implements GraphGenerator +{ + //~ Static fields/initializers --------------------------------------------- + + /** + * Role for the first vertex generated. + */ + public static final String START_VERTEX = "Start Vertex"; + + /** + * Role for the last vertex generated. + */ + public static final String END_VERTEX = "End Vertex"; + + //~ Instance fields -------------------------------------------------------- + + private int size; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new LinearGraphGenerator. + * + * @param size number of vertices to be generated + * + * @throws IllegalArgumentException if the specified size is negative. + */ + public LinearGraphGenerator(int size) + { + if (size < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + this.size = size; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + V lastVertex = null; + + for (int i = 0; i < size; ++i) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + + if (lastVertex == null) { + if (resultMap != null) { + resultMap.put(START_VERTEX, newVertex); + } + } else { + target.addEdge(lastVertex, newVertex); + } + + lastVertex = newVertex; + } + + if ((resultMap != null) && (lastVertex != null)) { + resultMap.put(END_VERTEX, lastVertex); + } + } +} + +// End LinearGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/RandomGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/RandomGraphGenerator.java new file mode 100644 index 00000000..9fe6de32 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/RandomGraphGenerator.java @@ -0,0 +1,375 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * RandomGraphGenerator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: RandomGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * 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). + * + * @author Assaf Lehr + * @since Aug 6, 2005 + */ +public class RandomGraphGenerator + implements GraphGenerator +{ + //~ Static fields/initializers --------------------------------------------- + + private static long seedUniquifier = 8682522807148012L; + + //~ Instance fields -------------------------------------------------------- + + protected int numOfVertexes; + protected int numOfEdges; + protected Random randomizer; + private long randomizerSeed; + + //~ Constructors ----------------------------------------------------------- + + public RandomGraphGenerator(int aNumOfVertexes, int aNumOfEdges) + { + if ((aNumOfVertexes < 0) || (aNumOfEdges < 0)) { + throw new IllegalArgumentException("must be non-negative"); + } + this.numOfVertexes = aNumOfVertexes; + this.numOfEdges = aNumOfEdges; + + this.randomizerSeed = chooseRandomSeedOnce(); + this.randomizer = new Random(this.randomizerSeed); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Should be called only once on creation. Chooses a seed which can be used + * later to reset the randomizer before each method call. This + * implementation copies the java.util.Random constructor because there is + * no getSeed() there, and seed is protected. + * + * @author Assaf + * @since Aug 6, 2005 + */ + private synchronized static long chooseRandomSeedOnce() + { + return (++seedUniquifier + System.nanoTime()); + } + + /** + * Resets seed to generate the same random stream. + */ + private void resetRandomSeed() + { + this.randomizer.setSeed(this.randomizerSeed); + } + + /** + * (non-Javadoc) + * + * @throws 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) + * + * @see GraphGenerator#generateGraph(Graph, VertexFactory, Map) + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + resetRandomSeed(); + + // key = generation order (1st,2nd,3rd,...) value=vertex Object + // will be used later + Map orderToVertexMap = + new HashMap(this.numOfVertexes); + + for (int i = 0; i < this.numOfVertexes; i++) { + V currVertex = vertexFactory.createVertex(); + target.addVertex(currVertex); + orderToVertexMap.put(Integer.valueOf(i), currVertex); + } + + // use specific type of edge factory, depending of the graph type + // and edge density + EdgeTopologyFactory edgesFactory = + edgeTopologyFactoryChooser(target, numOfEdges); + if (!edgesFactory.isNumberOfEdgesValid(target, numOfEdges)) { + throw new IllegalArgumentException( + "numOfEdges is not valid for the graph type " + + "\n-> Invalid number Of Edges=" + numOfEdges + " for:" + + " graph type=" + target.getClass() + + " ,number Of Vertexes=" + this.numOfVertexes + + "\n-> Advice: For the Max value , check the javadoc for" + + " org.jgrapht.generate.RandomGraphGenerator.DefaultEdgeTopologyFactory"); + } + + edgesFactory.createEdges( + target, + orderToVertexMap, + this.numOfEdges, + this.randomizer); + } + + /** + * Returns a concrete EdgeTopologyFactory, depending on graph type and + * numOfEdges + * + * @param target + * + * @return + */ + private EdgeTopologyFactory edgeTopologyFactoryChooser( + Graph target, + int numOfEdges) + { + return new DefaultEdgeTopologyFactory(); + } + + //~ Inner Interfaces ------------------------------------------------------- + + /** + * This class is used to generate the edge topology for a graph. + * + * @author Assaf + * @since Aug 6, 2005 + */ + public interface EdgeTopologyFactory + { + /** + * 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. + * + * @param targetGraph - guranteed to start with zero edges. + * @param orderToVertexMap - key=Integer of vertex order . between zero + * to numOfVertexes (exclusive). value = vertex from the graph. unique. + * @param numberOfEdges - to create in the graph + * @param randomizer + */ + public void createEdges( + Graph targetGraph, + Map orderToVertexMap, + int numberOfEdges, + Random randomizer); + + /** + * 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 + * + * @param targetGraph guranteed to start with zero edges. + * @param numberOfEdges + */ + public boolean isNumberOfEdgesValid( + Graph targetGraph, + int numberOfEdges); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * 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. + * + * @author Assaf + * @since Aug 6, 2005 + */ + public class DefaultEdgeTopologyFactory + implements EdgeTopologyFactory + { + public void createEdges( + Graph targetGraph, + Map orderToVertexMap, + int numberOfEdges, + Random randomizer) + { + int iterationsCounter = 0; + int edgesCounter = 0; + while (edgesCounter < numberOfEdges) { + // randomizer.nextInt(int n) return a number between zero + // (inclusive) and n(exclusive) + VV startVertex = + orderToVertexMap.get( + Integer.valueOf(randomizer.nextInt(numOfVertexes))); + VV endVertex = + orderToVertexMap.get( + Integer.valueOf(randomizer.nextInt(numOfVertexes))); + try { + EE resultEdge = targetGraph.addEdge(startVertex, endVertex); + if (resultEdge != null) { + edgesCounter++; + } + } catch (Exception e) { + // do nothing.just ignore the edge + } + + iterationsCounter++; + } + } + + /** + * checks if the numOfEdges is smaller than the Max edges according to + * the following table: + * + *

    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Graph TypeDirected / UnDirectedmultiple edgesloopsMax Edges
    SimpleGraphUnDirected--N(N-1)/2
    MultigraphUnDirected+-Infinite
    PseudographUnDirected++Infinite
    SimpleDirectedGraphDirected--N (N-1)
    DefaultDirectedGraphDirected-+N*(N-1)+ N = N^2
    DirectedMultigraphDirected++Infinite
    + * + * @see RandomGraphGenerator.EdgeTopologyFactory#isNumberOfEdgesValid(Graph, + * int) + */ + public boolean isNumberOfEdgesValid( + Graph targetGraph, + int numberOfEdges) + { + boolean result; + + boolean infinite = false; + int maxAllowedEdges = getMaxEdgesForVertexNum(targetGraph); + if (maxAllowedEdges == -1) { + infinite = true; + } + + if (true == infinite) { + result = true; + } else if (numberOfEdges <= maxAllowedEdges) { + result = true; + } else { + result = false; + } + return result; + } + + /** + * Return max edges for that graph. If it is infinite return -1 instead. + */ + public int getMaxEdgesForVertexNum(Graph targetGraph) + { + int maxAllowedEdges = 0; + if (targetGraph instanceof SimpleGraph) { + maxAllowedEdges = numOfVertexes * (numOfVertexes - 1) / 2; + } else if (targetGraph instanceof SimpleDirectedGraph) { + maxAllowedEdges = numOfVertexes * (numOfVertexes - 1); + } else if (targetGraph instanceof DefaultDirectedGraph) { + maxAllowedEdges = numOfVertexes * numOfVertexes; + } else { + // This may be overly liberal in the case of something + // like a simple graph which has been wrapped with + // a graph adapter or view. + maxAllowedEdges = -1; // infinite + } + return maxAllowedEdges; + } + } +} + +// End RandomGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/RingGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/RingGraphGenerator.java new file mode 100644 index 00000000..6f0c9d66 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/RingGraphGenerator.java @@ -0,0 +1,106 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * RingGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: RingGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author John V. Sichi + * @since Sep 16, 2003 + */ +public class RingGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private int size; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new RingGraphGenerator. + * + * @param size number of vertices to be generated + * + * @throws IllegalArgumentException if the specified size is negative. + */ + public RingGraphGenerator(int size) + { + if (size < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + this.size = size; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + if (size < 1) { + return; + } + + LinearGraphGenerator linearGenerator = + new LinearGraphGenerator(size); + Map privateMap = new HashMap(); + linearGenerator.generateGraph(target, vertexFactory, privateMap); + + V startVertex = privateMap.get(LinearGraphGenerator.START_VERTEX); + V endVertex = privateMap.get(LinearGraphGenerator.END_VERTEX); + target.addEdge(endVertex, startVertex); + } +} + +// End RingGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/ScaleFreeGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/ScaleFreeGraphGenerator.java new file mode 100644 index 00000000..41bb889f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/ScaleFreeGraphGenerator.java @@ -0,0 +1,154 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * ScaleFreeGraphGenerator.java + * ----------------- + * (C) Copyright 2008-2008, by Ilya Razenshteyn and Contributors. + * + * Original Author: Ilya Razenshteyn + * Contributor(s): - + * + * $Id: ScaleFreeGraphGenerator.java 627 2008-08-17 08:17:03Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Ilya Razenshteyn + */ +public class ScaleFreeGraphGenerator + implements GraphGenerator +{ + //~ Instance fields -------------------------------------------------------- + + private int size; // size of graphs, generated by this instance of generator + private long seed; // initial seed + private Random random; // the source of randomness + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructs a new ScaleFreeGraphGenerator. + * + * @param size number of vertices to be generated + */ + public ScaleFreeGraphGenerator( + int size) + { + if (size < 0) { + throw new IllegalArgumentException( + "invalid size: " + size + " (must be non-negative)"); + } + this.size = size; + random = new Random(); + seed = random.nextLong(); + } + + /** + * Constructs a new ScaleFreeGraphGenerator using fixed + * seed for the random generator. + * + * @param size number of vertices to be generated + * @param seed initial seed for the random generator + */ + public ScaleFreeGraphGenerator( + int size, + long seed) + { + if (size < 0) { + throw new IllegalArgumentException( + "invalid size: " + size + " (must be non-negative)"); + } + this.size = size; + random = new Random(); + this.seed = seed; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * 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). + * + * @param 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 + * @param vertexFactory called to produce new vertices + * @param resultMap unused parameter + */ + public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + random.setSeed(seed); + List vertexList = new ArrayList(); + List degrees = new ArrayList(); + int degreeSum = 0; + for (int i = 0; i < size; i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + int newDegree = 0; + while ((newDegree == 0) && (i != 0)) // we want our graph to be + // connected + + { + for (int j = 0; j < vertexList.size(); j++) { + if ((degreeSum == 0) + || (random.nextInt(degreeSum) < degrees.get(j))) + { + degrees.set(j, degrees.get(j) + 1); + newDegree++; + degreeSum += 2; + if (random.nextInt(2) == 0) { + target.addEdge(vertexList.get(j), newVertex); + } else { + target.addEdge(newVertex, vertexList.get(j)); + } + } + } + } + vertexList.add(newVertex); + degrees.add(newDegree); + } + } +} + +// End ScaleFreeGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/StarGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/StarGraphGenerator.java new file mode 100644 index 00000000..49fd2dbb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/StarGraphGenerator.java @@ -0,0 +1,116 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * StarGraphGenerator.java + * ------------------- + * (C) Copyright 2008-2008, by Andrew Newell and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: StarGraphGenerator.java 651 2008-12-24 21:13:41Z perfecthash $ + * + * Changes + * ------- + * 24-Dec-2008 : Initial revision (AN); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * Generates a star + * graph of any size. This is a graph where every vertex has exactly one + * edge with a center vertex. + * + * @author Andrew Newell + * @since Dec 21, 2008 + */ +public class StarGraphGenerator + implements GraphGenerator +{ + //~ Static fields/initializers --------------------------------------------- + + public static final String CENTER_VERTEX = "Center Vertex"; + + //~ Instance fields -------------------------------------------------------- + + private int order; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new StarGraphGenerator object. + * + * @param order number of total vertices including the center vertex + */ + public StarGraphGenerator(int order) + { + this.order = order; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Generates a star graph with the designated order from the constructor + */ + public void generateGraph( + Graph target, + final VertexFactory vertexFactory, + Map resultMap) + { + if (order < 1) { + return; + } + + //Create center vertex + V centerVertex = vertexFactory.createVertex(); + target.addVertex(centerVertex); + if (resultMap != null) { + resultMap.put(CENTER_VERTEX, centerVertex); + } + + //Create other vertices + for (int i = 0; i < (order - 1); i++) { + V newVertex = vertexFactory.createVertex(); + target.addVertex(newVertex); + } + + //Add one edge between the center vertex and every other vertex + Iterator iter = target.vertexSet().iterator(); + while (iter.hasNext()) { + V v = iter.next(); + if (v != centerVertex) { + target.addEdge(v, centerVertex); + } + } + } +} + +// End StarGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/WheelGraphGenerator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/WheelGraphGenerator.java new file mode 100644 index 00000000..260d4360 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/WheelGraphGenerator.java @@ -0,0 +1,155 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * WheelGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: WheelGraphGenerator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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". + * + * @author John V. Sichi + * @since Sep 16, 2003 + */ +public class WheelGraphGenerator + implements GraphGenerator +{ + //~ Static fields/initializers --------------------------------------------- + + /** + * Role for the hub vertex. + */ + public static final String HUB_VERTEX = "Hub Vertex"; + + //~ Instance fields -------------------------------------------------------- + + private boolean inwardSpokes; + private int size; + + //~ Constructors ----------------------------------------------------------- + + /** + * 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. + * + * @param size number of vertices to be generated. + */ + public WheelGraphGenerator(int size) + { + this(size, true); + } + + /** + * Construct a new WheelGraphGenerator. + * + * @param size number of vertices to be generated. + * @param inwardSpokes if true and graph is directed, spokes + * are oriented from rim to hub; else from hub to rim. + * + * @throws IllegalArgumentException + */ + public WheelGraphGenerator(int size, boolean inwardSpokes) + { + if (size < 0) { + throw new IllegalArgumentException("must be non-negative"); + } + + this.size = size; + this.inwardSpokes = inwardSpokes; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + public void generateGraph( + Graph target, + final VertexFactory vertexFactory, + Map resultMap) + { + if (size < 1) { + return; + } + + // A little trickery to intercept the rim generation. This is + // necessary since target may be initially non-empty, meaning we can't + // rely on its vertex set after the rim is generated. + final Collection rim = new ArrayList(); + VertexFactory rimVertexFactory = + new VertexFactory() { + public V createVertex() + { + V vertex = vertexFactory.createVertex(); + rim.add(vertex); + + return vertex; + } + }; + + RingGraphGenerator ringGenerator = + new RingGraphGenerator(size - 1); + ringGenerator.generateGraph(target, rimVertexFactory, resultMap); + + V hubVertex = vertexFactory.createVertex(); + target.addVertex(hubVertex); + + if (resultMap != null) { + resultMap.put(HUB_VERTEX, hubVertex); + } + + for (V rimVertex : rim) { + if (inwardSpokes) { + target.addEdge(rimVertex, hubVertex); + } else { + target.addEdge(hubVertex, rimVertex); + } + } + } +} + +// End WheelGraphGenerator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/package.html new file mode 100644 index 00000000..096acaef --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/generate/package.html @@ -0,0 +1,6 @@ + + + +Generators for graphs of various topologies. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AbstractBaseGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AbstractBaseGraph.java new file mode 100644 index 00000000..44ced959 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AbstractBaseGraph.java @@ -0,0 +1,1222 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * AbstractBaseGraph.java + * ---------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): John V. Sichi + * Christian Hammer + * + * $Id: AbstractBaseGraph.java 675 2009-03-12 08:30:09Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 10-Aug-2003 : General edge refactoring (BN); + * 06-Nov-2003 : Change edge sharing semantics (JVS); + * 07-Feb-2004 : Enabled serialization (BN); + * 11-Mar-2004 : Made generic (CH); + * 01-Jun-2005 : Added EdgeListFactory (JVS); + * 07-May-2006 : Changed from List to Set (JVS); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * The most general implementation of the {@link org.jgrapht.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 {@link LinkedHashMap} and {@link LinkedHashSet}).

    + * + * @author Barak Naveh + * @since Jul 24, 2003 + */ +public abstract class AbstractBaseGraph + extends AbstractGraph + implements Graph, + Cloneable, + Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -1263088497616142427L; + + private static final String LOOPS_NOT_ALLOWED = "loops not allowed"; + + //~ Instance fields -------------------------------------------------------- + + boolean allowingLoops; + + private EdgeFactory edgeFactory; + private EdgeSetFactory edgeSetFactory; + private Map edgeMap; + private transient Set unmodifiableEdgeSet = null; + private transient Set unmodifiableVertexSet = null; + private Specifics specifics; + private boolean allowingMultipleEdges; + + private transient TypeUtil vertexTypeDecl = null; + + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new pseudograph. The pseudograph can either be directed or + * undirected, depending on the specified edge factory. + * + * @param ef the edge factory of the new graph. + * @param allowMultipleEdges whether to allow multiple edges or not. + * @param allowLoops whether to allow edges that are self-loops or not. + * + * @throws NullPointerException if the specified edge factory is + * null. + */ + public AbstractBaseGraph( + EdgeFactory ef, + boolean allowMultipleEdges, + boolean allowLoops) + { + if (ef == null) { + throw new NullPointerException(); + } + + edgeMap = new LinkedHashMap(); + edgeFactory = ef; + allowingLoops = allowLoops; + allowingMultipleEdges = allowMultipleEdges; + + specifics = createSpecifics(); + + this.edgeSetFactory = new ArrayListFactory(); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + return specifics.getAllEdges(sourceVertex, targetVertex); + } + + /** + * 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. + * + * @return true if and only if graph loops are allowed. + */ + public boolean isAllowingLoops() + { + return allowingLoops; + } + + /** + * 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. + * + * @return true if and only if multiple edges are allowed. + */ + public boolean isAllowingMultipleEdges() + { + return allowingMultipleEdges; + } + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + return specifics.getEdge(sourceVertex, targetVertex); + } + + /** + * @see Graph#getEdgeFactory() + */ + public EdgeFactory getEdgeFactory() + { + return edgeFactory; + } + + /** + * Set the {@link EdgeSetFactory} to use for this graph. Initially, a graph + * is created with a default implementation which always supplies an {@link + * java.util.ArrayList} with capacity 1. + * + * @param edgeSetFactory factory to use for subsequently created edge sets + * (this call has no effect on existing edge sets) + */ + public void setEdgeSetFactory(EdgeSetFactory edgeSetFactory) + { + this.edgeSetFactory = edgeSetFactory; + } + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + assertVertexExist(sourceVertex); + assertVertexExist(targetVertex); + + if (!allowingMultipleEdges + && containsEdge(sourceVertex, targetVertex)) + { + return null; + } + + if (!allowingLoops && sourceVertex.equals(targetVertex)) { + throw new IllegalArgumentException(LOOPS_NOT_ALLOWED); + } + + E e = edgeFactory.createEdge(sourceVertex, targetVertex); + + if (containsEdge(e)) { // this restriction should stay! + + return null; + } else { + IntrusiveEdge intrusiveEdge = + createIntrusiveEdge(e, sourceVertex, targetVertex); + + edgeMap.put(e, intrusiveEdge); + specifics.addEdgeToTouchingVertices(e); + + return e; + } + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + if (e == null) { + throw new NullPointerException(); + } else if (containsEdge(e)) { + return false; + } + + assertVertexExist(sourceVertex); + assertVertexExist(targetVertex); + + if (!allowingMultipleEdges + && containsEdge(sourceVertex, targetVertex)) + { + return false; + } + + if (!allowingLoops && sourceVertex.equals(targetVertex)) { + throw new IllegalArgumentException(LOOPS_NOT_ALLOWED); + } + + IntrusiveEdge intrusiveEdge = + createIntrusiveEdge(e, sourceVertex, targetVertex); + + edgeMap.put(e, intrusiveEdge); + specifics.addEdgeToTouchingVertices(e); + + return true; + } + + private IntrusiveEdge createIntrusiveEdge( + E e, + V sourceVertex, + V targetVertex) + { + IntrusiveEdge intrusiveEdge; + if (e instanceof IntrusiveEdge) { + intrusiveEdge = (IntrusiveEdge) e; + } else { + intrusiveEdge = new IntrusiveEdge(); + } + intrusiveEdge.source = sourceVertex; + intrusiveEdge.target = targetVertex; + return intrusiveEdge; + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + if (v == null) { + throw new NullPointerException(); + } else if (containsVertex(v)) { + return false; + } else { + specifics.addVertex(v); + + return true; + } + } + + /** + * @see Graph#getEdgeSource(Object) + */ + public V getEdgeSource(E e) + { + return TypeUtil.uncheckedCast( + getIntrusiveEdge(e).source, + vertexTypeDecl); + } + + /** + * @see Graph#getEdgeTarget(Object) + */ + public V getEdgeTarget(E e) + { + return TypeUtil.uncheckedCast( + getIntrusiveEdge(e).target, + vertexTypeDecl); + } + + private IntrusiveEdge getIntrusiveEdge(E e) + { + if (e instanceof IntrusiveEdge) { + return (IntrusiveEdge) e; + } + + return edgeMap.get(e); + } + + /** + * Returns a shallow copy of this graph instance. Neither edges nor vertices + * are cloned. + * + * @return a shallow copy of this set. + * + * @throws RuntimeException + * + * @see java.lang.Object#clone() + */ + public Object clone() + { + try { + TypeUtil> typeDecl = null; + + AbstractBaseGraph newGraph = + TypeUtil.uncheckedCast(super.clone(), typeDecl); + + newGraph.edgeMap = new LinkedHashMap(); + + newGraph.edgeFactory = this.edgeFactory; + newGraph.unmodifiableEdgeSet = null; + newGraph.unmodifiableVertexSet = null; + + // NOTE: it's important for this to happen in an object + // method so that the new inner class instance gets associated with + // the right outer class instance + newGraph.specifics = newGraph.createSpecifics(); + + Graphs.addGraph(newGraph, this); + + return newGraph; + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + throw new RuntimeException(); + } + } + + /** + * @see Graph#containsEdge(Object) + */ + public boolean containsEdge(E e) + { + return edgeMap.containsKey(e); + } + + /** + * @see Graph#containsVertex(Object) + */ + public boolean containsVertex(V v) + { + return specifics.getVertexSet().contains(v); + } + + /** + * @see UndirectedGraph#degreeOf(Object) + */ + public int degreeOf(V vertex) + { + return specifics.degreeOf(vertex); + } + + /** + * @see Graph#edgeSet() + */ + public Set edgeSet() + { + if (unmodifiableEdgeSet == null) { + unmodifiableEdgeSet = Collections.unmodifiableSet(edgeMap.keySet()); + } + + return unmodifiableEdgeSet; + } + + /** + * @see Graph#edgesOf(Object) + */ + public Set edgesOf(V vertex) + { + return specifics.edgesOf(vertex); + } + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + return specifics.inDegreeOf(vertex); + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + return specifics.incomingEdgesOf(vertex); + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + return specifics.outDegreeOf(vertex); + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + return specifics.outgoingEdgesOf(vertex); + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + E e = getEdge(sourceVertex, targetVertex); + + if (e != null) { + specifics.removeEdgeFromTouchingVertices(e); + edgeMap.remove(e); + } + + return e; + } + + /** + * @see Graph#removeEdge(Object) + */ + public boolean removeEdge(E e) + { + if (containsEdge(e)) { + specifics.removeEdgeFromTouchingVertices(e); + edgeMap.remove(e); + + return true; + } else { + return false; + } + } + + /** + * @see Graph#removeVertex(Object) + */ + public boolean removeVertex(V v) + { + if (containsVertex(v)) { + Set touchingEdgesList = edgesOf(v); + + // cannot iterate over list - will cause + // ConcurrentModificationException + removeAllEdges(new ArrayList(touchingEdgesList)); + + specifics.getVertexSet().remove(v); // remove the vertex itself + + return true; + } else { + return false; + } + } + + /** + * @see Graph#vertexSet() + */ + public Set vertexSet() + { + if (unmodifiableVertexSet == null) { + unmodifiableVertexSet = + Collections.unmodifiableSet(specifics.getVertexSet()); + } + + return unmodifiableVertexSet; + } + + /** + * @see Graph#getEdgeWeight(Object) + */ + public double getEdgeWeight(E e) + { + if (e instanceof DefaultWeightedEdge) { + return ((DefaultWeightedEdge) e).weight; + } else { + return WeightedGraph.DEFAULT_EDGE_WEIGHT; + } + } + + /** + * @see WeightedGraph#setEdgeWeight(Object, double) + */ + public void setEdgeWeight(E e, double weight) + { + assert (e instanceof DefaultWeightedEdge) : e.getClass(); + ((DefaultWeightedEdge) e).weight = weight; + } + + private Specifics createSpecifics() + { + if (this instanceof DirectedGraph) { + return new DirectedSpecifics(); + } else if (this instanceof UndirectedGraph) { + return new UndirectedSpecifics(); + } else { + throw new IllegalArgumentException( + "must be instance of either DirectedGraph or UndirectedGraph"); + } + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * . + * + * @author Barak Naveh + */ + private abstract class Specifics + implements Serializable + { + private static final long serialVersionUID = 785196247314761183L; + + public abstract void addVertex(V vertex); + + public abstract Set getVertexSet(); + + /** + * . + * + * @param sourceVertex + * @param targetVertex + * + * @return + */ + public abstract Set getAllEdges(V sourceVertex, + V targetVertex); + + /** + * . + * + * @param sourceVertex + * @param targetVertex + * + * @return + */ + public abstract E getEdge(V sourceVertex, V targetVertex); + + /** + * Adds the specified edge to the edge containers of its source and + * target vertices. + * + * @param e + */ + public abstract void addEdgeToTouchingVertices(E e); + + /** + * . + * + * @param vertex + * + * @return + */ + public abstract int degreeOf(V vertex); + + /** + * . + * + * @param vertex + * + * @return + */ + public abstract Set edgesOf(V vertex); + + /** + * . + * + * @param vertex + * + * @return + */ + public abstract int inDegreeOf(V vertex); + + /** + * . + * + * @param vertex + * + * @return + */ + public abstract Set incomingEdgesOf(V vertex); + + /** + * . + * + * @param vertex + * + * @return + */ + public abstract int outDegreeOf(V vertex); + + /** + * . + * + * @param vertex + * + * @return + */ + public abstract Set outgoingEdgesOf(V vertex); + + /** + * Removes the specified edge from the edge containers of its source and + * target vertices. + * + * @param e + */ + public abstract void removeEdgeFromTouchingVertices(E e); + } + + private static class ArrayListFactory + implements EdgeSetFactory, + Serializable + { + private static final long serialVersionUID = 5936902837403445985L; + + /** + * @see EdgeSetFactory.createEdgeSet + */ + public Set createEdgeSet(VV vertex) + { + // NOTE: use size 1 to keep memory usage under control + // for the common case of vertices with low degree + return new ArrayUnenforcedSet(1); + } + } + + /** + * A container for vertex edges. + * + *

    In this edge container we use array lists to minimize memory toll. + * However, for high-degree vertices we replace the entire edge container + * with a direct access subclass (to be implemented).

    + * + * @author Barak Naveh + */ + private static class DirectedEdgeContainer + implements Serializable + { + private static final long serialVersionUID = 7494242245729767106L; + Set incoming; + Set outgoing; + private transient Set unmodifiableIncoming = null; + private transient Set unmodifiableOutgoing = null; + + DirectedEdgeContainer(EdgeSetFactory edgeSetFactory, + VV vertex) + { + incoming = edgeSetFactory.createEdgeSet(vertex); + outgoing = edgeSetFactory.createEdgeSet(vertex); + } + + /** + * A lazy build of unmodifiable incoming edge set. + * + * @return + */ + public Set getUnmodifiableIncomingEdges() + { + if (unmodifiableIncoming == null) { + unmodifiableIncoming = Collections.unmodifiableSet(incoming); + } + + return unmodifiableIncoming; + } + + /** + * A lazy build of unmodifiable outgoing edge set. + * + * @return + */ + public Set getUnmodifiableOutgoingEdges() + { + if (unmodifiableOutgoing == null) { + unmodifiableOutgoing = Collections.unmodifiableSet(outgoing); + } + + return unmodifiableOutgoing; + } + + /** + * . + * + * @param e + */ + public void addIncomingEdge(EE e) + { + incoming.add(e); + } + + /** + * . + * + * @param e + */ + public void addOutgoingEdge(EE e) + { + outgoing.add(e); + } + + /** + * . + * + * @param e + */ + public void removeIncomingEdge(EE e) + { + incoming.remove(e); + } + + /** + * . + * + * @param e + */ + public void removeOutgoingEdge(EE e) + { + outgoing.remove(e); + } + } + + /** + * . + * + * @author Barak Naveh + */ + private class DirectedSpecifics + extends Specifics + implements Serializable + { + private static final long serialVersionUID = 8971725103718958232L; + private static final String NOT_IN_DIRECTED_GRAPH = + "no such operation in a directed graph"; + + private Map> vertexMapDirected = + new LinkedHashMap>(); + + public void addVertex(V v) + { + // add with a lazy edge container entry + vertexMapDirected.put(v, null); + } + + public Set getVertexSet() + { + return vertexMapDirected.keySet(); + } + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + Set edges = null; + + if (containsVertex(sourceVertex) + && containsVertex(targetVertex)) + { + edges = new ArrayUnenforcedSet(); + + DirectedEdgeContainer ec = getEdgeContainer(sourceVertex); + + Iterator iter = ec.outgoing.iterator(); + + while (iter.hasNext()) { + E e = iter.next(); + + if (getEdgeTarget(e).equals(targetVertex)) { + edges.add(e); + } + } + } + + return edges; + } + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + if (containsVertex(sourceVertex) + && containsVertex(targetVertex)) + { + DirectedEdgeContainer ec = getEdgeContainer(sourceVertex); + + Iterator iter = ec.outgoing.iterator(); + + while (iter.hasNext()) { + E e = iter.next(); + + if (getEdgeTarget(e).equals(targetVertex)) { + return e; + } + } + } + + return null; + } + + /** + * @see AbstractBaseGraph#addEdgeToTouchingVertices(Edge) + */ + public void addEdgeToTouchingVertices(E e) + { + V source = getEdgeSource(e); + V target = getEdgeTarget(e); + + getEdgeContainer(source).addOutgoingEdge(e); + getEdgeContainer(target).addIncomingEdge(e); + } + + /** + * @see UndirectedGraph#degreeOf(Object) + */ + public int degreeOf(V vertex) + { + throw new UnsupportedOperationException(NOT_IN_DIRECTED_GRAPH); + } + + /** + * @see Graph#edgesOf(Object) + */ + public Set edgesOf(V vertex) + { + ArrayUnenforcedSet inAndOut = + new ArrayUnenforcedSet(getEdgeContainer(vertex).incoming); + inAndOut.addAll(getEdgeContainer(vertex).outgoing); + + // we have two copies for each self-loop - remove one of them. + if (allowingLoops) { + Set loops = getAllEdges(vertex, vertex); + + for (int i = 0; i < inAndOut.size();) { + Object e = inAndOut.get(i); + + if (loops.contains(e)) { + inAndOut.remove(i); + loops.remove(e); // so we remove it only once + } else { + i++; + } + } + } + + return Collections.unmodifiableSet(inAndOut); + } + + /** + * @see DirectedGraph#inDegree(Object) + */ + public int inDegreeOf(V vertex) + { + return getEdgeContainer(vertex).incoming.size(); + } + + /** + * @see DirectedGraph#incomingEdges(Object) + */ + public Set incomingEdgesOf(V vertex) + { + return getEdgeContainer(vertex).getUnmodifiableIncomingEdges(); + } + + /** + * @see DirectedGraph#outDegree(Object) + */ + public int outDegreeOf(V vertex) + { + return getEdgeContainer(vertex).outgoing.size(); + } + + /** + * @see DirectedGraph#outgoingEdges(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + return getEdgeContainer(vertex).getUnmodifiableOutgoingEdges(); + } + + /** + * @see AbstractBaseGraph#removeEdgeFromTouchingVertices(Edge) + */ + public void removeEdgeFromTouchingVertices(E e) + { + V source = getEdgeSource(e); + V target = getEdgeTarget(e); + + getEdgeContainer(source).removeOutgoingEdge(e); + getEdgeContainer(target).removeIncomingEdge(e); + } + + /** + * A lazy build of edge container for specified vertex. + * + * @param vertex a vertex in this graph. + * + * @return EdgeContainer + */ + private DirectedEdgeContainer getEdgeContainer(V vertex) + { + assertVertexExist(vertex); + + DirectedEdgeContainer ec = vertexMapDirected.get(vertex); + + if (ec == null) { + ec = new DirectedEdgeContainer(edgeSetFactory, vertex); + vertexMapDirected.put(vertex, ec); + } + + return ec; + } + } + + /** + * A container of for vertex edges. + * + *

    In this edge container we use array lists to minimize memory toll. + * However, for high-degree vertices we replace the entire edge container + * with a direct access subclass (to be implemented).

    + * + * @author Barak Naveh + */ + private static class UndirectedEdgeContainer + implements Serializable + { + private static final long serialVersionUID = -6623207588411170010L; + Set vertexEdges; + private transient Set unmodifiableVertexEdges = null; + + UndirectedEdgeContainer( + EdgeSetFactory edgeSetFactory, + VV vertex) + { + vertexEdges = edgeSetFactory.createEdgeSet(vertex); + } + + /** + * A lazy build of unmodifiable list of vertex edges + * + * @return + */ + public Set getUnmodifiableVertexEdges() + { + if (unmodifiableVertexEdges == null) { + unmodifiableVertexEdges = + Collections.unmodifiableSet(vertexEdges); + } + + return unmodifiableVertexEdges; + } + + /** + * . + * + * @param e + */ + public void addEdge(EE e) + { + vertexEdges.add(e); + } + + /** + * . + * + * @return + */ + public int edgeCount() + { + return vertexEdges.size(); + } + + /** + * . + * + * @param e + */ + public void removeEdge(EE e) + { + vertexEdges.remove(e); + } + } + + /** + * . + * + * @author Barak Naveh + */ + private class UndirectedSpecifics + extends Specifics + implements Serializable + { + private static final long serialVersionUID = 6494588405178655873L; + private static final String NOT_IN_UNDIRECTED_GRAPH = + "no such operation in an undirected graph"; + + private Map> vertexMapUndirected = + new LinkedHashMap>(); + + public void addVertex(V v) + { + // add with a lazy edge container entry + vertexMapUndirected.put(v, null); + } + + public Set getVertexSet() + { + return vertexMapUndirected.keySet(); + } + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + Set edges = null; + + if (containsVertex(sourceVertex) + && containsVertex(targetVertex)) + { + edges = new ArrayUnenforcedSet(); + + Iterator iter = + getEdgeContainer(sourceVertex).vertexEdges.iterator(); + + while (iter.hasNext()) { + E e = iter.next(); + + boolean equalStraight = + sourceVertex.equals(getEdgeSource(e)) + && targetVertex.equals(getEdgeTarget(e)); + + boolean equalInverted = + sourceVertex.equals(getEdgeTarget(e)) + && targetVertex.equals(getEdgeSource(e)); + + if (equalStraight || equalInverted) { + edges.add(e); + } + } + } + + return edges; + } + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + if (containsVertex(sourceVertex) + && containsVertex(targetVertex)) + { + Iterator iter = + getEdgeContainer(sourceVertex).vertexEdges.iterator(); + + while (iter.hasNext()) { + E e = iter.next(); + + boolean equalStraight = + sourceVertex.equals(getEdgeSource(e)) + && targetVertex.equals(getEdgeTarget(e)); + + boolean equalInverted = + sourceVertex.equals(getEdgeTarget(e)) + && targetVertex.equals(getEdgeSource(e)); + + if (equalStraight || equalInverted) { + return e; + } + } + } + + return null; + } + + /** + * @see AbstractBaseGraph#addEdgeToTouchingVertices(Edge) + */ + public void addEdgeToTouchingVertices(E e) + { + V source = getEdgeSource(e); + V target = getEdgeTarget(e); + + getEdgeContainer(source).addEdge(e); + + if (!source.equals(target)) { + getEdgeContainer(target).addEdge(e); + } + } + + /** + * @see UndirectedGraph#degreeOf(V) + */ + public int degreeOf(V vertex) + { + if (allowingLoops) { // then we must count, and add loops twice + + int degree = 0; + Set edges = getEdgeContainer(vertex).vertexEdges; + + for (E e : edges) { + if (getEdgeSource(e).equals(getEdgeTarget(e))) { + degree += 2; + } else { + degree += 1; + } + } + + return degree; + } else { + return getEdgeContainer(vertex).edgeCount(); + } + } + + /** + * @see Graph#edgesOf(V) + */ + public Set edgesOf(V vertex) + { + return getEdgeContainer(vertex).getUnmodifiableVertexEdges(); + } + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + throw new UnsupportedOperationException(NOT_IN_UNDIRECTED_GRAPH); + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + throw new UnsupportedOperationException(NOT_IN_UNDIRECTED_GRAPH); + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + throw new UnsupportedOperationException(NOT_IN_UNDIRECTED_GRAPH); + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + throw new UnsupportedOperationException(NOT_IN_UNDIRECTED_GRAPH); + } + + /** + * @see AbstractBaseGraph#removeEdgeFromTouchingVertices(Edge) + */ + public void removeEdgeFromTouchingVertices(E e) + { + V source = getEdgeSource(e); + V target = getEdgeTarget(e); + + getEdgeContainer(source).removeEdge(e); + + if (!source.equals(target)) { + getEdgeContainer(target).removeEdge(e); + } + } + + /** + * A lazy build of edge container for specified vertex. + * + * @param vertex a vertex in this graph. + * + * @return EdgeContainer + */ + private UndirectedEdgeContainer getEdgeContainer(V vertex) + { + assertVertexExist(vertex); + + UndirectedEdgeContainer ec = vertexMapUndirected.get(vertex); + + if (ec == null) { + ec = new UndirectedEdgeContainer( + edgeSetFactory, + vertex); + vertexMapUndirected.put(vertex, ec); + } + + return ec; + } + } +} + +// End AbstractBaseGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AbstractGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AbstractGraph.java new file mode 100644 index 00000000..0aa9a034 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AbstractGraph.java @@ -0,0 +1,231 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * AbstractGraph.java + * ------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: AbstractGraph.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); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Barak Naveh + * @see Graph + * @see DirectedGraph + * @see UndirectedGraph + */ +public abstract class AbstractGraph + implements Graph +{ + //~ Constructors ----------------------------------------------------------- + + /** + * Construct a new empty graph object. + */ + public AbstractGraph() + { + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#containsEdge(Object, Object) + */ + public boolean containsEdge(V sourceVertex, V targetVertex) + { + return getEdge(sourceVertex, targetVertex) != null; + } + + /** + * @see Graph#removeAllEdges(Collection) + */ + public boolean removeAllEdges(Collection edges) + { + boolean modified = false; + + for (E e : edges) { + modified |= removeEdge(e); + } + + return modified; + } + + /** + * @see Graph#removeAllEdges(Object, Object) + */ + public Set removeAllEdges(V sourceVertex, V targetVertex) + { + Set removed = getAllEdges(sourceVertex, targetVertex); + removeAllEdges(removed); + + return removed; + } + + /** + * @see Graph#removeAllVertices(Collection) + */ + public boolean removeAllVertices(Collection vertices) + { + boolean modified = false; + + for (V v : vertices) { + modified |= removeVertex(v); + } + + return modified; + } + + /** + * 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. + * + * @return a string representation of this graph. + */ + public String toString() + { + return toStringFromSets( + vertexSet(), + edgeSet(), + (this instanceof DirectedGraph)); + } + + /** + * Ensures that the specified vertex exists in this graph, or else throws + * exception. + * + * @param v vertex + * + * @return true if this assertion holds. + * + * @throws NullPointerException if specified vertex is null. + * @throws IllegalArgumentException if specified vertex does not exist in + * this graph. + */ + protected boolean assertVertexExist(V v) + { + if (containsVertex(v)) { + return true; + } else if (v == null) { + throw new NullPointerException(); + } else { + throw new IllegalArgumentException("no such vertex in graph"); + } + } + + /** + * 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 + * {@link Graph#removeEdge(Object)} method. + * + * @param edges edges to be removed from this graph. + * + * @return true if this graph changed as a result of the call. + * + * @see Graph#removeEdge(Object) + * @see Graph#containsEdge(Object) + */ + protected boolean removeAllEdges(E [] edges) + { + boolean modified = false; + + for (int i = 0; i < edges.length; i++) { + modified |= removeEdge(edges[i]); + } + + return modified; + } + + /** + * Helper for subclass implementations of toString( ). + * + * @param vertexSet the vertex set V to be printed + * @param edgeSet the edge set E to be printed + * @param directed true to use parens for each edge (representing directed); + * false to use curly braces (representing undirected) + * + * @return a string representation of (V,E) + */ + protected String toStringFromSets( + Collection vertexSet, + Collection edgeSet, + boolean directed) + { + List renderedEdges = new ArrayList(); + + StringBuffer sb = new StringBuffer(); + for (E e : edgeSet) { + if ((e.getClass() != DefaultEdge.class) + && (e.getClass() != DefaultWeightedEdge.class)) + { + sb.append(e.toString()); + sb.append("="); + } + if (directed) { + sb.append("("); + } else { + sb.append("{"); + } + sb.append(getEdgeSource(e)); + sb.append(","); + sb.append(getEdgeTarget(e)); + if (directed) { + sb.append(")"); + } else { + sb.append("}"); + } + + // REVIEW jvs 29-May-2006: dump weight somewhere? + renderedEdges.add(sb.toString()); + sb.setLength(0); + } + + return "(" + vertexSet + ", " + renderedEdges + ")"; + } +} + +// End AbstractGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUndirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUndirectedGraph.java new file mode 100644 index 00000000..b777a012 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUndirectedGraph.java @@ -0,0 +1,209 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * AsUndirectedGraph.java + * ---------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): Christian Hammer + * + * $Id: AsUndirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 14-Aug-2003 : Initial revision (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.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * 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.

    + * + * @author John V. Sichi + * @since Aug 14, 2003 + */ +public class AsUndirectedGraph + extends GraphDelegator + implements Serializable, + UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3257845485078065462L; // @todo renew + private static final String NO_EDGE_ADD = + "this graph does not support edge addition"; + private static final String UNDIRECTED = + "this graph only supports undirected operations"; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for AsUndirectedGraph. + * + * @param g the backing directed graph over which an undirected view is to + * be created. + */ + public AsUndirectedGraph(DirectedGraph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + Set forwardList = super.getAllEdges(sourceVertex, targetVertex); + + if (sourceVertex.equals(targetVertex)) { + // avoid duplicating loops + return forwardList; + } + + Set reverseList = super.getAllEdges(targetVertex, sourceVertex); + Set list = + new ArrayUnenforcedSet( + forwardList.size() + reverseList.size()); + list.addAll(forwardList); + list.addAll(reverseList); + + return list; + } + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + E edge = super.getEdge(sourceVertex, targetVertex); + + if (edge != null) { + return edge; + } + + // try the other direction + return super.getEdge(targetVertex, sourceVertex); + } + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(NO_EDGE_ADD); + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + throw new UnsupportedOperationException(NO_EDGE_ADD); + } + + /** + * @see UndirectedGraph#degreeOf(Object) + */ + public int degreeOf(V vertex) + { + // this counts loops twice, which is consistent with AbstractBaseGraph + return super.inDegreeOf(vertex) + super.outDegreeOf(vertex); + } + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + throw new UnsupportedOperationException(UNDIRECTED); + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + throw new UnsupportedOperationException(UNDIRECTED); + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + throw new UnsupportedOperationException(UNDIRECTED); + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + throw new UnsupportedOperationException(UNDIRECTED); + } + + /** + * @see AbstractBaseGraph#toString() + */ + public String toString() + { + return super.toStringFromSets(vertexSet(), edgeSet(), false); + } +} + +// End AsUndirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUnweightedDirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUnweightedDirectedGraph.java new file mode 100644 index 00000000..708ccaa3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUnweightedDirectedGraph.java @@ -0,0 +1,100 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * AsUnweightedGraph.java + * ---------------------- + * (C) Copyright 2007-2008, by Lucas J. Scharenbroich and Contributors. + * + * Original Author: Lucas J. Scharenbroich + * Contributor(s): John V. Sichi + * + * $Id: AsUnweightedDirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 7-Sep-2007 : Initial revision (LJS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import org.jgrapht.*; + + +/** + * 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.

    + * + * @author Lucas J. Scharenbroich + * @since Sep 7, 2007 + */ +public class AsUnweightedDirectedGraph + extends GraphDelegator + implements Serializable, + DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = -4320818446777715312L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for AsUnweightedGraph. + * + * @param g the backing graph over which an unweighted view is to be + * created. + */ + public AsUnweightedDirectedGraph(DirectedGraph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getEdgeWeight + */ + public double getEdgeWeight(E e) + { + return WeightedGraph.DEFAULT_EDGE_WEIGHT; + } +} + +// End AsUnweightedDirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUnweightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUnweightedGraph.java new file mode 100644 index 00000000..33fa16f2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsUnweightedGraph.java @@ -0,0 +1,100 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * AsUnweightedGraph.java + * ---------------------- + * (C) Copyright 2007-2008, by Lucas J. Scharenbroich and Contributors. + * + * Original Author: Lucas J. Scharenbroich + * Contributor(s): John V. Sichi +* + * $Id: AsUnweightedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 7-Sep-2007 : Initial revision (LJS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import org.jgrapht.*; + + +/** + * 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.

    + * + * @author Lucas J. Scharenbroich + * @since Sep 7, 2007 + */ + +public class AsUnweightedGraph + extends GraphDelegator + implements Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 7175505077601824663L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for AsUnweightedGraph. + * + * @param g the backing graph over which an unweighted view is to be + * created. + */ + public AsUnweightedGraph(Graph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getEdgeWeight + */ + public double getEdgeWeight(E e) + { + return WeightedGraph.DEFAULT_EDGE_WEIGHT; + } +} + +// End AsUnweightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsWeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsWeightedGraph.java new file mode 100644 index 00000000..d2cf915e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/AsWeightedGraph.java @@ -0,0 +1,147 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * AsWeightedGraph.java + * ---------------------- + * (C) Copyright 2007, by Lucas J. Scharenbroich and Contributors. + * + * Original Author: Lucas J. Scharenbroich + * Contributor(s): John V. Sichi + * + * $Id: AsWeightedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 10-Sep-2007 : Initial revision (LJS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; + + +/** + *

    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.

    + * + * @author Lucas J. Scharenbroich + * @since Sep 10, 2007 + */ +public class AsWeightedGraph + extends GraphDelegator + implements Serializable, + WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = -716810639338971372L; + + //~ Instance fields -------------------------------------------------------- + + protected final Map weightMap; + private final boolean isWeightedGraph; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for AsWeightedGraph. + * + * @param g the backing graph over which a weighted view is to be created. + * @param 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. + */ + public AsWeightedGraph(Graph g, Map weightMap) + { + super(g); + assert (weightMap != null); + this.weightMap = weightMap; + + // Remember whether the backing graph implements the WeightedGraph + // interface + this.isWeightedGraph = (g instanceof WeightedGraph); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see WeightedGraph#setEdgeWeight + */ + public void setEdgeWeight(E e, double weight) + { + if (isWeightedGraph) { + super.setEdgeWeight(e, weight); + } + + // Always modify the weight map. It would be a terrible violation + // of the use contract to silently ignore changes to the weights. + weightMap.put(e, weight); + } + + /** + * @see Graph#getEdgeWeight + */ + public double getEdgeWeight(E e) + { + double weight; + + // Always return the value from the weight map first and + // only pass the call through as a backup + if (weightMap.containsKey(e)) { + weight = weightMap.get(e); + } else { + weight = super.getEdgeWeight(e); + } + + return weight; + } +} + +// End AsWeightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ClassBasedEdgeFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ClassBasedEdgeFactory.java new file mode 100644 index 00000000..a9c91d2f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ClassBasedEdgeFactory.java @@ -0,0 +1,91 @@ +/* ========================================== + * 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. + */ +/* ------------------ + * ClassBasedEdgeFactory.java + * ------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: ClassBasedEdgeFactory.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 04-Aug-2003 : Renamed from EdgeFactoryFactory & made utility class (BN); + * 03-Nov-2003 : Made edge factories serializable (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import org.jgrapht.*; + + +/** + * An {@link EdgeFactory} for producing edges by using a class as a factory. + * + * @author Barak Naveh + * @since Jul 14, 2003 + */ +public class ClassBasedEdgeFactory + implements EdgeFactory, + Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3618135658586388792L; + + //~ Instance fields -------------------------------------------------------- + + private final Class edgeClass; + + //~ Constructors ----------------------------------------------------------- + + public ClassBasedEdgeFactory(Class edgeClass) + { + this.edgeClass = edgeClass; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see EdgeFactory#createEdge(Object, Object) + */ + public E createEdge(V source, V target) + { + try { + return edgeClass.newInstance(); + } catch (Exception ex) { + throw new RuntimeException("Edge factory failed", ex); + } + } +} + +// End ClassBasedEdgeFactory.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ClassBasedVertexFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ClassBasedVertexFactory.java new file mode 100644 index 00000000..7e390c3b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ClassBasedVertexFactory.java @@ -0,0 +1,79 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * ClassBasedVertexFactory.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: ClassBasedVertexFactory.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A {@link VertexFactory} for producing vertices by using a class as a factory. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +public class ClassBasedVertexFactory + implements VertexFactory +{ + //~ Instance fields -------------------------------------------------------- + + private final Class vertexClass; + + //~ Constructors ----------------------------------------------------------- + + public ClassBasedVertexFactory(Class vertexClass) + { + this.vertexClass = vertexClass; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see VertexFactory#createVertex() + */ + public V createVertex() + { + try { + return this.vertexClass.newInstance(); + } catch (Exception e) { + throw new RuntimeException("Vertex factory failed", e); + } + } +} + +// End ClassBasedVertexFactory.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultDirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultDirectedGraph.java new file mode 100644 index 00000000..8ac21da0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultDirectedGraph.java @@ -0,0 +1,86 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * DefaultDirectedGraph.java + * ------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DefaultDirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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.

    + */ +public class DefaultDirectedGraph + extends AbstractBaseGraph + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3544953246956466230L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new directed graph. + * + * @param edgeClass class on which to base factory for edges + */ + public DefaultDirectedGraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new directed graph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public DefaultDirectedGraph(EdgeFactory ef) + { + super(ef, false, true); + } +} + +// End DefaultDirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultDirectedWeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultDirectedWeightedGraph.java new file mode 100644 index 00000000..26e6e84f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultDirectedWeightedGraph.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* --------------------------------- + * DefaultDirectedWeightedGraph.java + * --------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DefaultDirectedWeightedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Jun-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + * + * @see DefaultDirectedGraph + */ +public class DefaultDirectedWeightedGraph + extends DefaultDirectedGraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3761405317841171513L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new directed weighted graph. + * + * @param edgeClass class on which to base factory for edges + */ + public DefaultDirectedWeightedGraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new directed weighted graph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public DefaultDirectedWeightedGraph(EdgeFactory ef) + { + super(ef); + } +} + +// End DefaultDirectedWeightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultEdge.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultEdge.java new file mode 100644 index 00000000..abea7533 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultEdge.java @@ -0,0 +1,91 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * DefaultEdge.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DefaultEdge.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 10-Aug-2003 : General edge refactoring (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A default implementation for edges in a {@link Graph}. + * + * @author Barak Naveh + * @since Jul 14, 2003 + */ +public class DefaultEdge + extends IntrusiveEdge +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3258408452177932855L; + + //~ Methods ---------------------------------------------------------------- + + /** + * Retrieves the source of this edge. This is protected, for use by + * subclasses only (e.g. for implementing toString). + * + * @return source of this edge + */ + protected Object getSource() + { + return source; + } + + /** + * Retrieves the target of this edge. This is protected, for use by + * subclasses only (e.g. for implementing toString). + * + * @return target of this edge + */ + protected Object getTarget() + { + return target; + } + + public String toString() + { + return "(" + source + " : " + target + ")"; + } +} + +// End DefaultEdge.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultGraphMapping.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultGraphMapping.java new file mode 100644 index 00000000..1917e7ae --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultGraphMapping.java @@ -0,0 +1,135 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * DefaultGraphMapping.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: DefaultGraphMapping.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Assaf + * @since Jul 30, 2005 + */ +public class DefaultGraphMapping + implements GraphMapping +{ + //~ Instance fields -------------------------------------------------------- + + private Map graphMappingForward; + private Map graphMappingReverse; + + private Graph graph1; + private Graph graph2; + + //~ Constructors ----------------------------------------------------------- + + /** + * 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. + * + * @param g1ToG2 + * @param g2ToG1 + * @param g1 + * @param g2 + */ + public DefaultGraphMapping( + Map g1ToG2, + Map g2ToG1, + Graph g1, + Graph g2) + { + this.graph1 = g1; + this.graph2 = g2; + this.graphMappingForward = g1ToG2; + this.graphMappingReverse = g2ToG1; + } + + //~ Methods ---------------------------------------------------------------- + + public E getEdgeCorrespondence(E currEdge, boolean forward) + { + Graph sourceGraph, targetGraph; + + if (forward) { + sourceGraph = this.graph1; + targetGraph = this.graph2; + } else { + sourceGraph = this.graph2; + targetGraph = this.graph1; + } + + V mappedSourceVertex = + getVertexCorrespondence( + sourceGraph.getEdgeSource(currEdge), + forward); + V mappedTargetVertex = + getVertexCorrespondence( + sourceGraph.getEdgeTarget(currEdge), + forward); + if ((mappedSourceVertex == null) || (mappedTargetVertex == null)) { + return null; + } else { + return targetGraph.getEdge( + mappedSourceVertex, + mappedTargetVertex); + } + } + + public V getVertexCorrespondence( + V keyVertex, + boolean forward) + { + Map graphMapping; + if (forward) { + graphMapping = graphMappingForward; + } else { + graphMapping = graphMappingReverse; + } + + return graphMapping.get(keyVertex); + } +} + +// End DefaultGraphMapping.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultListenableGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultListenableGraph.java new file mode 100644 index 00000000..11d50ff2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultListenableGraph.java @@ -0,0 +1,511 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * DefaultListenableGraph.java + * --------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DefaultListenableGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 04-Aug-2003 : Strong refs to listeners instead of weak refs (BN); + * 10-Aug-2003 : Adaptation to new event model (BN); + * 07-Mar-2004 : Fixed unnecessary clone bug #819075 (BN); + * 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.graph; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; +import org.jgrapht.util.*; + + +/** + * 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.

    + * + * @author Barak Naveh + * @see GraphListener + * @see VertexSetListener + * @since Jul 20, 2003 + */ +public class DefaultListenableGraph + extends GraphDelegator + implements ListenableGraph, + Cloneable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3977575900898471984L; + + //~ Instance fields -------------------------------------------------------- + + private ArrayList> graphListeners = + new ArrayList>(); + private ArrayList> vertexSetListeners = + new ArrayList>(); + private FlyweightEdgeEvent reuseableEdgeEvent; + private FlyweightVertexEvent reuseableVertexEvent; + private boolean reuseEvents; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new listenable graph. + * + * @param g the backing graph. + */ + public DefaultListenableGraph(Graph g) + { + this(g, false); + } + + /** + * 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. + * + * @param g the backing graph. + * @param reuseEvents whether to reuse previously fired event objects + * instead of creating a new event object for each event. + * + * @throws IllegalArgumentException if the backing graph is already a + * listenable graph. + */ + public DefaultListenableGraph(Graph g, boolean reuseEvents) + { + super(g); + this.reuseEvents = reuseEvents; + reuseableEdgeEvent = new FlyweightEdgeEvent(this, -1, null); + reuseableVertexEvent = new FlyweightVertexEvent(this, -1, null); + + // the following restriction could be probably relaxed in the future. + if (g instanceof ListenableGraph) { + throw new IllegalArgumentException( + "base graph cannot be listenable"); + } + } + + //~ Methods ---------------------------------------------------------------- + + /** + * 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. + * + * @param reuseEvents whether to reuse previously fired event objects + * instead of creating a new event object for each event. + */ + public void setReuseEvents(boolean reuseEvents) + { + this.reuseEvents = reuseEvents; + } + + /** + * 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. + * + * @return the value of the reuseEvents flag. + */ + public boolean isReuseEvents() + { + return reuseEvents; + } + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + E e = super.addEdge(sourceVertex, targetVertex); + + if (e != null) { + fireEdgeAdded(e); + } + + return e; + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + boolean added = super.addEdge(sourceVertex, targetVertex, e); + + if (added) { + fireEdgeAdded(e); + } + + return added; + } + + /** + * @see ListenableGraph#addGraphListener(GraphListener) + */ + public void addGraphListener(GraphListener l) + { + addToListenerList(graphListeners, l); + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + boolean modified = super.addVertex(v); + + if (modified) { + fireVertexAdded(v); + } + + return modified; + } + + /** + * @see ListenableGraph#addVertexSetListener(VertexSetListener) + */ + public void addVertexSetListener(VertexSetListener l) + { + addToListenerList(vertexSetListeners, l); + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() + { + try { + TypeUtil> typeDecl = null; + + DefaultListenableGraph g = + TypeUtil.uncheckedCast(super.clone(), typeDecl); + g.graphListeners = new ArrayList>(); + g.vertexSetListeners = new ArrayList>(); + + return g; + } catch (CloneNotSupportedException e) { + // should never get here since we're Cloneable + e.printStackTrace(); + throw new RuntimeException("internal error"); + } + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + E e = super.removeEdge(sourceVertex, targetVertex); + + if (e != null) { + fireEdgeRemoved(e); + } + + return e; + } + + /** + * @see Graph#removeEdge(Object) + */ + public boolean removeEdge(E e) + { + boolean modified = super.removeEdge(e); + + if (modified) { + fireEdgeRemoved(e); + } + + return modified; + } + + /** + * @see ListenableGraph#removeGraphListener(GraphListener) + */ + public void removeGraphListener(GraphListener l) + { + graphListeners.remove(l); + } + + /** + * @see Graph#removeVertex(Object) + */ + public boolean removeVertex(V v) + { + if (containsVertex(v)) { + Set touchingEdgesList = edgesOf(v); + + // copy set to avoid ConcurrentModificationException + removeAllEdges(new ArrayList(touchingEdgesList)); + + super.removeVertex(v); // remove the vertex itself + + fireVertexRemoved(v); + + return true; + } else { + return false; + } + } + + /** + * @see ListenableGraph#removeVertexSetListener(VertexSetListener) + */ + public void removeVertexSetListener(VertexSetListener l) + { + vertexSetListeners.remove(l); + } + + /** + * Notify listeners that the specified edge was added. + * + * @param edge the edge that was added. + */ + protected void fireEdgeAdded(E edge) + { + GraphEdgeChangeEvent e = + createGraphEdgeChangeEvent(GraphEdgeChangeEvent.EDGE_ADDED, edge); + + for (int i = 0; i < graphListeners.size(); i++) { + GraphListener l = graphListeners.get(i); + + l.edgeAdded(e); + } + } + + /** + * Notify listeners that the specified edge was removed. + * + * @param edge the edge that was removed. + */ + protected void fireEdgeRemoved(E edge) + { + GraphEdgeChangeEvent e = + createGraphEdgeChangeEvent( + GraphEdgeChangeEvent.EDGE_REMOVED, + edge); + + for (int i = 0; i < graphListeners.size(); i++) { + GraphListener l = graphListeners.get(i); + + l.edgeRemoved(e); + } + } + + /** + * Notify listeners that the specified vertex was added. + * + * @param vertex the vertex that was added. + */ + protected void fireVertexAdded(V vertex) + { + GraphVertexChangeEvent e = + createGraphVertexChangeEvent( + GraphVertexChangeEvent.VERTEX_ADDED, + vertex); + + for (int i = 0; i < vertexSetListeners.size(); i++) { + VertexSetListener l = vertexSetListeners.get(i); + + l.vertexAdded(e); + } + + for (int i = 0; i < graphListeners.size(); i++) { + GraphListener l = graphListeners.get(i); + + l.vertexAdded(e); + } + } + + /** + * Notify listeners that the specified vertex was removed. + * + * @param vertex the vertex that was removed. + */ + protected void fireVertexRemoved(V vertex) + { + GraphVertexChangeEvent e = + createGraphVertexChangeEvent( + GraphVertexChangeEvent.VERTEX_REMOVED, + vertex); + + for (int i = 0; i < vertexSetListeners.size(); i++) { + VertexSetListener l = vertexSetListeners.get(i); + + l.vertexRemoved(e); + } + + for (int i = 0; i < graphListeners.size(); i++) { + GraphListener l = graphListeners.get(i); + + l.vertexRemoved(e); + } + } + + private static void addToListenerList( + List list, + L l) + { + if (!list.contains(l)) { + list.add(l); + } + } + + private GraphEdgeChangeEvent createGraphEdgeChangeEvent( + int eventType, + E edge) + { + if (reuseEvents) { + reuseableEdgeEvent.setType(eventType); + reuseableEdgeEvent.setEdge(edge); + + return reuseableEdgeEvent; + } else { + return new GraphEdgeChangeEvent(this, eventType, edge); + } + } + + private GraphVertexChangeEvent createGraphVertexChangeEvent( + int eventType, + V vertex) + { + if (reuseEvents) { + reuseableVertexEvent.setType(eventType); + reuseableVertexEvent.setVertex(vertex); + + return reuseableVertexEvent; + } else { + return new GraphVertexChangeEvent(this, eventType, vertex); + } + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * A reuseable edge event. + * + * @author Barak Naveh + * @since Aug 10, 2003 + */ + private static class FlyweightEdgeEvent + extends GraphEdgeChangeEvent + { + private static final long serialVersionUID = 3907207152526636089L; + + /** + * @see GraphEdgeChangeEvent#GraphEdgeChangeEvent(Object, int, Edge) + */ + public FlyweightEdgeEvent(Object eventSource, int type, EE e) + { + super(eventSource, type, e); + } + + /** + * Sets the edge of this event. + * + * @param e the edge to be set. + */ + protected void setEdge(EE e) + { + this.edge = e; + } + + /** + * Set the event type of this event. + * + * @param type the type to be set. + */ + protected void setType(int type) + { + this.type = type; + } + } + + /** + * A reuseable vertex event. + * + * @author Barak Naveh + * @since Aug 10, 2003 + */ + private static class FlyweightVertexEvent + extends GraphVertexChangeEvent + { + private static final long serialVersionUID = 3257848787857585716L; + + /** + * @see GraphVertexChangeEvent#GraphVertexChangeEvent(Object, int, + * Object) + */ + public FlyweightVertexEvent(Object eventSource, int type, VV vertex) + { + super(eventSource, type, vertex); + } + + /** + * Set the event type of this event. + * + * @param type type to be set. + */ + protected void setType(int type) + { + this.type = type; + } + + /** + * Sets the vertex of this event. + * + * @param vertex the vertex to be set. + */ + protected void setVertex(VV vertex) + { + this.vertex = vertex; + } + } +} + +// End DefaultListenableGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultWeightedEdge.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultWeightedEdge.java new file mode 100644 index 00000000..45c44c2a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DefaultWeightedEdge.java @@ -0,0 +1,77 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * DefaultWeightedEdge.java + * ---------------- + * (C) Copyright 2006-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: DefaultWeightedEdge.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 29-May-2006 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A default implementation for edges in a {@link 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. + * + * @author John V. Sichi + */ +public class DefaultWeightedEdge + extends DefaultEdge +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 229708706467350994L; + + //~ Instance fields -------------------------------------------------------- + + double weight = WeightedGraph.DEFAULT_EDGE_WEIGHT; + + //~ Methods ---------------------------------------------------------------- + + /** + * Retrieves the weight of this edge. This is protected, for use by + * subclasses only (e.g. for implementing toString). + * + * @return weight of this edge + */ + protected double getWeight() + { + return weight; + } +} + +// End DefaultWeightedEdge.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedGraphUnion.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedGraphUnion.java new file mode 100644 index 00000000..649863c4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedGraphUnion.java @@ -0,0 +1,71 @@ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +public class DirectedGraphUnion + extends GraphUnion> + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -740199233080172450L; + + //~ Constructors ----------------------------------------------------------- + + DirectedGraphUnion( + DirectedGraph g1, + DirectedGraph g2, + WeightCombiner operator) + { + super(g1, g2, operator); + } + + DirectedGraphUnion(DirectedGraph g1, DirectedGraph g2) + { + super(g1, g2); + } + + //~ Methods ---------------------------------------------------------------- + + public int inDegreeOf(V vertex) + { + Set res = incomingEdgesOf(vertex); + return res.size(); + } + + public Set incomingEdgesOf(V vertex) + { + Set res = new HashSet(); + if (getG1().containsVertex(vertex)) { + res.addAll(getG1().incomingEdgesOf(vertex)); + } + if (getG2().containsVertex(vertex)) { + res.addAll(getG2().incomingEdgesOf(vertex)); + } + return Collections.unmodifiableSet(res); + } + + public int outDegreeOf(V vertex) + { + Set res = outgoingEdgesOf(vertex); + return res.size(); + } + + public Set outgoingEdgesOf(V vertex) + { + Set res = new HashSet(); + if (getG1().containsVertex(vertex)) { + res.addAll(getG1().outgoingEdgesOf(vertex)); + } + if (getG2().containsVertex(vertex)) { + res.addAll(getG2().outgoingEdgesOf(vertex)); + } + return Collections.unmodifiableSet(res); + } +} + +// End $file.name$ diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedMaskSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedMaskSubgraph.java new file mode 100644 index 00000000..2bd4317c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedMaskSubgraph.java @@ -0,0 +1,64 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * DirectedMaskSubgraph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: DirectedMaskSubgraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A directed graph that is a {@link MaskSubgraph} on another graph. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +public class DirectedMaskSubgraph + extends MaskSubgraph + implements DirectedGraph +{ + //~ Constructors ----------------------------------------------------------- + + public DirectedMaskSubgraph( + DirectedGraph base, + MaskFunctor mask) + { + super(base, mask); + } +} + +// End DirectedMaskSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedMultigraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedMultigraph.java new file mode 100644 index 00000000..ea8fc503 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedMultigraph.java @@ -0,0 +1,82 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * DirectedMultigraph.java + * ----------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DirectedMultigraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A directed multigraph. A directed multigraph is a non-simple directed graph + * in which loops and multiple edges between any two vertices are permitted. + */ +public class DirectedMultigraph + extends AbstractBaseGraph + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3258408413590599219L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new directed multigraph. + * + * @param edgeClass class on which to base factory for edges + */ + public DirectedMultigraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new directed multigraph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public DirectedMultigraph(EdgeFactory ef) + { + super(ef, true, true); + } +} + +// End DirectedMultigraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedPseudograph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedPseudograph.java new file mode 100644 index 00000000..6801f208 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedPseudograph.java @@ -0,0 +1,80 @@ +/* ========================================== + * JGraphT : a free Java graph-theory library + * ========================================== + * + * Project Info: http://jgrapht.sourceforge.net/ + * Project Creator: Barak Naveh (barak_naveh@users.sourceforge.net) + * + * (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. + */ +/* ---------------- + * DirectedPseudograph.java + * ---------------- + * (C) Copyright 2004-2008, by Christian Hammer and Contributors. + * + * Original Author: Christian Hammer + * Contributor(s): - + * + * $Id: DirectedPseudograph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 11-Mar-2004 : Initial revision: generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class DirectedPseudograph + extends AbstractBaseGraph + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -8300409752893486415L; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see AbstractBaseGraph + */ + public DirectedPseudograph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * @see AbstractBaseGraph + */ + public DirectedPseudograph(EdgeFactory ef) + { + super(ef, true, true); + } +} + +// End DirectedPseudograph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedSubgraph.java new file mode 100644 index 00000000..f745663b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedSubgraph.java @@ -0,0 +1,158 @@ +/* ========================================== + * 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. + */ +/* --------------------- + * DirectedSubgraph.java + * --------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DirectedSubgraph.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * A directed graph that is a subgraph on other graph. + * + * @see Subgraph + */ +public class DirectedSubgraph + extends Subgraph> + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3616445700507054133L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new directed subgraph. + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param vertexSubset vertices to include in the subgraph. If + * null then all vertices are included. + * @param edgeSubset edges to in include in the subgraph. If + * null then all the edges whose vertices found in the graph are + * included. + */ + public DirectedSubgraph( + DirectedGraph base, + Set vertexSubset, + Set edgeSubset) + { + super(base, vertexSubset, edgeSubset); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + assertVertexExist(vertex); + + int degree = 0; + + for (E e : getBase().incomingEdgesOf(vertex)) { + if (containsEdge(e)) { + degree++; + } + } + + return degree; + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + assertVertexExist(vertex); + + Set edges = new ArrayUnenforcedSet(); + + for (E e : getBase().incomingEdgesOf(vertex)) { + if (containsEdge(e)) { + edges.add(e); + } + } + + return edges; + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + assertVertexExist(vertex); + + int degree = 0; + + for (E e : getBase().outgoingEdgesOf(vertex)) { + if (containsEdge(e)) { + degree++; + } + } + + return degree; + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + assertVertexExist(vertex); + + Set edges = new ArrayUnenforcedSet(); + + for (E e : getBase().outgoingEdgesOf(vertex)) { + if (containsEdge(e)) { + edges.add(e); + } + } + + return edges; + } +} + +// End DirectedSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedWeightedMultigraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedWeightedMultigraph.java new file mode 100644 index 00000000..0202ab59 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedWeightedMultigraph.java @@ -0,0 +1,84 @@ +/* ========================================== + * 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. + */ +/* ------------------------------- + * DirectedWeightedMultigraph.java + * ------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DirectedWeightedMultigraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Jun-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class DirectedWeightedMultigraph + extends DirectedMultigraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 4049071636005206066L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new directed weighted multigraph. + * + * @param edgeClass class on which to base factory for edges + */ + public DirectedWeightedMultigraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new directed weighted multigraph with the specified edge + * factory. + * + * @param ef the edge factory of the new graph. + */ + public DirectedWeightedMultigraph(EdgeFactory ef) + { + super(ef); + } +} + +// End DirectedWeightedMultigraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedWeightedSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedWeightedSubgraph.java new file mode 100644 index 00000000..16d76aa5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/DirectedWeightedSubgraph.java @@ -0,0 +1,83 @@ +/* ========================================== + * 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. + */ +/* ----------------------------- + * DirectedWeightedSubgraph.java + * ----------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: DirectedWeightedSubgraph.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * A directed weighted graph that is a subgraph on other graph. + * + * @see Subgraph + */ +public class DirectedWeightedSubgraph + extends DirectedSubgraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3905799799168250680L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new weighted directed subgraph. + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param vertexSubset vertices to include in the subgraph. If + * null then all vertices are included. + * @param edgeSubset edges to in include in the subgraph. If + * null then all the edges whose vertices found in the graph are + * included. + */ + public DirectedWeightedSubgraph( + WeightedGraph base, + Set vertexSubset, + Set edgeSubset) + { + super((DirectedGraph) base, vertexSubset, edgeSubset); + } +} + +// End DirectedWeightedSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/EdgeReversedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/EdgeReversedGraph.java new file mode 100644 index 00000000..47368d29 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/EdgeReversedGraph.java @@ -0,0 +1,187 @@ +/* ========================================== + * 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. + */ +/* ------------- + * EdgeReversedGraph.java + * ------------- + * (C) Copyright 2006-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: EdgeReversedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sept-2006 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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 + * {@link org.jgrapht.traverse.DepthFirstIterator}. + * + * @author John V. Sichi + * @see AsUndirectedGraph + */ +public class EdgeReversedGraph + extends GraphDelegator + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 9091361782455418631L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new EdgeReversedGraph. + * + * @param g the base (backing) graph on which the edge-reversed view will be + * based. + */ + public EdgeReversedGraph(DirectedGraph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + return super.getEdge(targetVertex, sourceVertex); + } + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + return super.getAllEdges(targetVertex, sourceVertex); + } + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + return super.addEdge(targetVertex, sourceVertex); + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + return super.addEdge(targetVertex, sourceVertex, e); + } + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + return super.outDegreeOf(vertex); + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + return super.inDegreeOf(vertex); + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + return super.outgoingEdgesOf(vertex); + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + return super.incomingEdgesOf(vertex); + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + return super.removeEdge(targetVertex, sourceVertex); + } + + /** + * @see Graph#getEdgeSource(Object) + */ + public V getEdgeSource(E e) + { + return super.getEdgeTarget(e); + } + + /** + * @see Graph#getEdgeTarget(Object) + */ + public V getEdgeTarget(E e) + { + return super.getEdgeSource(e); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() + { + return toStringFromSets( + vertexSet(), + edgeSet(), + true); + } +} + +// End EdgeReversedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/EdgeSetFactory.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/EdgeSetFactory.java new file mode 100644 index 00000000..53fbd3d5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/EdgeSetFactory.java @@ -0,0 +1,73 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * EdgeSetFactory.java + * ---------------- + * (C) Copyright 2005-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): Christian Hammer + * + * $Id: EdgeSetFactory.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 01-Jun-2005 : Initial revision (JVS); + * 06-Aug-2005 : Made generic (CH); + * 07-May-2006 : Renamed and changed from List to Set (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + + +/** + * A factory for edge sets. This interface allows the creator of a graph to + * choose the {@link java.util.Set} implementation used internally by the graph + * to maintain sets of edges. This provides control over performance tradeoffs + * between memory and CPU usage. + * + * @author John V. Sichi + */ +public interface EdgeSetFactory +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Create a new edge set for a particular vertex. + * + * @param 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) + * + * @return new set + */ + public Set createEdgeSet(V vertex); +} + +// End EdgeSetFactory.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphDelegator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphDelegator.java new file mode 100644 index 00000000..df5e744d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphDelegator.java @@ -0,0 +1,298 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * GraphDelegator.java + * ------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: GraphDelegator.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); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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.

    + * + * @author Barak Naveh + * @since Jul 20, 2003 + */ +public class GraphDelegator + extends AbstractGraph + implements Graph, + Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3257005445226181425L; + + //~ Instance fields -------------------------------------------------------- + + /** + * The graph to which operations are delegated. + */ + private Graph delegate; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for GraphDelegator. + * + * @param g the backing graph (the delegate). + * + * @throws IllegalArgumentException iff g==null + */ + public GraphDelegator(Graph g) + { + super(); + + if (g == null) { + throw new IllegalArgumentException("g must not be null."); + } + + delegate = g; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + return delegate.getAllEdges(sourceVertex, targetVertex); + } + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + return delegate.getEdge(sourceVertex, targetVertex); + } + + /** + * @see Graph#getEdgeFactory() + */ + public EdgeFactory getEdgeFactory() + { + return delegate.getEdgeFactory(); + } + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + return delegate.addEdge(sourceVertex, targetVertex); + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + return delegate.addEdge(sourceVertex, targetVertex, e); + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + return delegate.addVertex(v); + } + + /** + * @see Graph#containsEdge(Object) + */ + public boolean containsEdge(E e) + { + return delegate.containsEdge(e); + } + + /** + * @see Graph#containsVertex(Object) + */ + public boolean containsVertex(V v) + { + return delegate.containsVertex(v); + } + + /** + * @see UndirectedGraph#degreeOf(Object) + */ + public int degreeOf(V vertex) + { + return ((UndirectedGraph) delegate).degreeOf(vertex); + } + + /** + * @see Graph#edgeSet() + */ + public Set edgeSet() + { + return delegate.edgeSet(); + } + + /** + * @see Graph#edgesOf(Object) + */ + public Set edgesOf(V vertex) + { + return delegate.edgesOf(vertex); + } + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + return ((DirectedGraph) delegate).inDegreeOf(vertex); + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + return ((DirectedGraph) delegate).incomingEdgesOf(vertex); + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + return ((DirectedGraph) delegate).outDegreeOf(vertex); + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + return ((DirectedGraph) delegate).outgoingEdgesOf(vertex); + } + + /** + * @see Graph#removeEdge(Object) + */ + public boolean removeEdge(E e) + { + return delegate.removeEdge(e); + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + return delegate.removeEdge(sourceVertex, targetVertex); + } + + /** + * @see Graph#removeVertex(Object) + */ + public boolean removeVertex(V v) + { + return delegate.removeVertex(v); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() + { + return delegate.toString(); + } + + /** + * @see Graph#vertexSet() + */ + public Set vertexSet() + { + return delegate.vertexSet(); + } + + /** + * @see Graph#getEdgeSource(Object) + */ + public V getEdgeSource(E e) + { + return delegate.getEdgeSource(e); + } + + /** + * @see Graph#getEdgeTarget(Object) + */ + public V getEdgeTarget(E e) + { + return delegate.getEdgeTarget(e); + } + + /** + * @see Graph#getEdgeWeight(Object) + */ + public double getEdgeWeight(E e) + { + return delegate.getEdgeWeight(e); + } + + /** + * @see WeightedGraph#setEdgeWeight(Object, double) + */ + public void setEdgeWeight(E e, double weight) + { + ((WeightedGraph) delegate).setEdgeWeight(e, weight); + } +} + +// End GraphDelegator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphPathImpl.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphPathImpl.java new file mode 100644 index 00000000..cebeb6b6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphPathImpl.java @@ -0,0 +1,122 @@ +/* ========================================== + * 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-2009, 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. + */ +/* ---------------- + * GraphPathImpl.java + * ---------------- + * (C) Copyright 2009-2009, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * + * $Id: GraphPathImpl.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 03-Jul-2009 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * GraphPathImpl is a default implementation of {@link GraphPath}. + * + * @author John Sichi + * @version $Id: GraphPathImpl.java 689 2009-07-04 06:40:29Z perfecthash $ + */ +public class GraphPathImpl + implements GraphPath +{ + //~ Instance fields -------------------------------------------------------- + + private Graph graph; + + private List edgeList; + + private V startVertex; + + private V endVertex; + + private double weight; + + //~ Constructors ----------------------------------------------------------- + + public GraphPathImpl( + Graph graph, + V startVertex, + V endVertex, + List edgeList, + double weight) + { + this.graph = graph; + this.startVertex = startVertex; + this.endVertex = endVertex; + this.edgeList = edgeList; + this.weight = weight; + } + + //~ Methods ---------------------------------------------------------------- + + // implement GraphPath + public Graph getGraph() + { + return graph; + } + + // implement GraphPath + public V getStartVertex() + { + return startVertex; + } + + // implement GraphPath + public V getEndVertex() + { + return endVertex; + } + + // implement GraphPath + public List getEdgeList() + { + return edgeList; + } + + // implement GraphPath + public double getWeight() + { + return weight; + } + + // override Object + public String toString() + { + return edgeList.toString(); + } +} + +// End GraphPathImpl.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphUnion.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphUnion.java new file mode 100644 index 00000000..8644b390 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/GraphUnion.java @@ -0,0 +1,250 @@ +package org.jgrapht.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + *

    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.

    + */ +public class GraphUnion> + extends AbstractGraph + implements Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -740199233080172450L; + + private static final String READ_ONLY = "union of graphs is read-only"; + + //~ Instance fields -------------------------------------------------------- + + private G g1; + private G g2; + private WeightCombiner operator; + + //~ Constructors ----------------------------------------------------------- + + public GraphUnion(G g1, G g2, WeightCombiner operator) + { + if (g1 == null) { + throw new NullPointerException("g1 is null"); + } + if (g2 == null) { + throw new NullPointerException("g2 is null"); + } + if (g1 == g2) { + throw new IllegalArgumentException("g1 is equal to g2"); + } + this.g1 = g1; + this.g2 = g2; + this.operator = operator; + } + + public GraphUnion(G g1, G g2) + { + this(g1, g2, WeightCombiner.SUM); + } + + //~ Methods ---------------------------------------------------------------- + + public Set getAllEdges(V sourceVertex, V targetVertex) + { + Set res = new HashSet(); + if (g1.containsVertex(sourceVertex) + && g1.containsVertex(targetVertex)) + { + res.addAll(g1.getAllEdges(sourceVertex, targetVertex)); + } + if (g2.containsVertex(sourceVertex) + && g2.containsVertex(targetVertex)) + { + res.addAll(g2.getAllEdges(sourceVertex, targetVertex)); + } + return Collections.unmodifiableSet(res); + } + + public E getEdge(V sourceVertex, V targetVertex) + { + E res = null; + if (g1.containsVertex(sourceVertex) + && g1.containsVertex(targetVertex)) + { + res = g1.getEdge(sourceVertex, targetVertex); + } + if ((res == null) + && g2.containsVertex(sourceVertex) + && g2.containsVertex(targetVertex)) + { + res = g2.getEdge(sourceVertex, targetVertex); + } + return res; + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public EdgeFactory getEdgeFactory() + { + throw new UnsupportedOperationException(READ_ONLY); + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public E addEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(READ_ONLY); + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + throw new UnsupportedOperationException(READ_ONLY); + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public boolean addVertex(V v) + { + throw new UnsupportedOperationException(READ_ONLY); + } + + public boolean containsEdge(E e) + { + return g1.containsEdge(e) || g2.containsEdge(e); + } + + public boolean containsVertex(V v) + { + return g1.containsVertex(v) || g2.containsVertex(v); + } + + public Set edgeSet() + { + Set res = new HashSet(); + res.addAll(g1.edgeSet()); + res.addAll(g2.edgeSet()); + return Collections.unmodifiableSet(res); + } + + public Set edgesOf(V vertex) + { + Set res = new HashSet(); + if (g1.containsVertex(vertex)) { + res.addAll(g1.edgesOf(vertex)); + } + if (g2.containsVertex(vertex)) { + res.addAll(g2.edgesOf(vertex)); + } + return Collections.unmodifiableSet(res); + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(READ_ONLY); + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public boolean removeEdge(E e) + { + throw new UnsupportedOperationException(READ_ONLY); + } + + /** + * Throws UnsupportedOperationException, because + * GraphUnion is read-only. + */ + public boolean removeVertex(V v) + { + throw new UnsupportedOperationException(READ_ONLY); + } + + public Set vertexSet() + { + Set res = new HashSet(); + res.addAll(g1.vertexSet()); + res.addAll(g2.vertexSet()); + return Collections.unmodifiableSet(res); + } + + public V getEdgeSource(E e) + { + if (g1.containsEdge(e)) { + return g1.getEdgeSource(e); + } + if (g2.containsEdge(e)) { + return g2.getEdgeSource(e); + } + return null; + } + + public V getEdgeTarget(E e) + { + if (g1.containsEdge(e)) { + return g1.getEdgeTarget(e); + } + if (g2.containsEdge(e)) { + return g2.getEdgeTarget(e); + } + return null; + } + + public double getEdgeWeight(E e) + { + if (g1.containsEdge(e) && g2.containsEdge(e)) { + return operator.combine(g1.getEdgeWeight(e), g2.getEdgeWeight(e)); + } + if (g1.containsEdge(e)) { + return g1.getEdgeWeight(e); + } + if (g2.containsEdge(e)) { + return g2.getEdgeWeight(e); + } + throw new IllegalArgumentException("no such edge in the union"); + } + + /** + * @return G1 + */ + public G getG1() + { + return g1; + } + + /** + * @return G2 + */ + public G getG2() + { + return g2; + } +} + +// End $file.name$ diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/IntrusiveEdge.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/IntrusiveEdge.java new file mode 100644 index 00000000..a71106ae --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/IntrusiveEdge.java @@ -0,0 +1,82 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * IntrusiveEdge.java + * ------------------- + * (C) Copyright 2006-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: IntrusiveEdge.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 28-May-2006 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + + +/** + * IntrusiveEdge encapsulates the internals for the default edge implementation. + * It is not intended to be referenced directly (which is why it's not public); + * use DefaultEdge for that. + * + * @author John V. Sichi + */ +class IntrusiveEdge + implements Cloneable, + Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3258408452177932855L; + + //~ Instance fields -------------------------------------------------------- + + Object source; + + Object target; + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Object#clone() + */ + public Object clone() + { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + // shouldn't happen as we are Cloneable + throw new InternalError(); + } + } +} + +// End IntrusiveEdge.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableDirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableDirectedGraph.java new file mode 100644 index 00000000..9effa8a3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableDirectedGraph.java @@ -0,0 +1,83 @@ +/* ========================================== + * 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. + */ +/* ---------------------------- + * ListenableDirectedGraph.java + * ---------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: ListenableDirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A directed graph which is also {@link org.jgrapht.ListenableGraph}. + * + * @see DefaultListenableGraph + */ +public class ListenableDirectedGraph + extends DefaultListenableGraph + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3257571698126368824L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new listenable directed graph. + * + * @param edgeClass class on which to base factory for edges + */ + public ListenableDirectedGraph(Class edgeClass) + { + this(new DefaultDirectedGraph(edgeClass)); + } + + /** + * Creates a new listenable directed graph. + * + * @param base the backing graph. + */ + public ListenableDirectedGraph(DirectedGraph base) + { + super(base); + } +} + +// End ListenableDirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableDirectedWeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableDirectedWeightedGraph.java new file mode 100644 index 00000000..eaff740e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableDirectedWeightedGraph.java @@ -0,0 +1,84 @@ +/* ========================================== + * 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. + */ +/* ------------------------------------ + * ListenableDirectedWeightedGraph.java + * ------------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: ListenableDirectedWeightedGraph.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Jun-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A directed weighted graph which is also {@link org.jgrapht.ListenableGraph}. + * + * @see DefaultListenableGraph + */ +public class ListenableDirectedWeightedGraph + extends ListenableDirectedGraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3977582476627621938L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new listenable directed weighted graph. + * + * @param edgeClass class on which to base factory for edges + */ + public ListenableDirectedWeightedGraph(Class edgeClass) + { + this(new DefaultDirectedWeightedGraph(edgeClass)); + } + + /** + * Creates a new listenable directed weighted graph. + * + * @param base the backing graph. + */ + public ListenableDirectedWeightedGraph(WeightedGraph base) + { + super((DirectedGraph) base); + } +} + +// End ListenableDirectedWeightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableUndirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableUndirectedGraph.java new file mode 100644 index 00000000..1057effb --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableUndirectedGraph.java @@ -0,0 +1,83 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * ListenableUndirectedGraph.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: ListenableUndirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * An undirected graph which is also {@link org.jgrapht.ListenableGraph}. + * + * @see DefaultListenableGraph + */ +public class ListenableUndirectedGraph + extends DefaultListenableGraph + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3256999969193145905L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new listenable undirected simple graph. + * + * @param edgeClass class on which to base factory for edges + */ + public ListenableUndirectedGraph(Class edgeClass) + { + this(new SimpleGraph(edgeClass)); + } + + /** + * Creates a new listenable undirected graph. + * + * @param base the backing graph. + */ + public ListenableUndirectedGraph(UndirectedGraph base) + { + super(base); + } +} + +// End ListenableUndirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableUndirectedWeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableUndirectedWeightedGraph.java new file mode 100644 index 00000000..1910c50c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ListenableUndirectedWeightedGraph.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* -------------------------------------- + * ListenableUndirectedWeightedGraph.java + * -------------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: ListenableUndirectedWeightedGraph.java 485 2006-06-26 09:12:14Z + * perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Jun-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * An undirected weighted graph which is also {@link + * org.jgrapht.ListenableGraph}. + * + * @see DefaultListenableGraph + */ +public class ListenableUndirectedWeightedGraph + extends ListenableUndirectedGraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3690762799613949747L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new listenable undirected weighted graph. + * + * @param edgeClass class on which to base factory for edges + */ + public ListenableUndirectedWeightedGraph(Class edgeClass) + { + this(new SimpleWeightedGraph(edgeClass)); + } + + /** + * Creates a new listenable undirected weighted graph. + * + * @param base the backing graph. + */ + public ListenableUndirectedWeightedGraph(WeightedGraph base) + { + super((UndirectedGraph) base); + } +} + +// End ListenableUndirectedWeightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskEdgeSet.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskEdgeSet.java new file mode 100644 index 00000000..ebd7e2a6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskEdgeSet.java @@ -0,0 +1,149 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * MaskEdgeSet.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: MaskEdgeSet.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; +import org.jgrapht.util.PrefetchIterator.*; + + +/** + * Helper for {@link MaskSubgraph}. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +class MaskEdgeSet + extends AbstractSet +{ + //~ Instance fields -------------------------------------------------------- + + private Set edgeSet; + + private Graph graph; + + private MaskFunctor mask; + + private transient TypeUtil edgeTypeDecl = null; + + private int size; + + //~ Constructors ----------------------------------------------------------- + + public MaskEdgeSet( + Graph graph, + Set edgeSet, + MaskFunctor mask) + { + this.graph = graph; + this.edgeSet = edgeSet; + this.mask = mask; + this.size = -1; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see java.util.Collection#contains(java.lang.Object) + */ + public boolean contains(Object o) + { + return this.edgeSet.contains(o) + && !this.mask.isEdgeMasked(TypeUtil.uncheckedCast(o, edgeTypeDecl)); + } + + /** + * @see java.util.Set#iterator() + */ + public Iterator iterator() + { + return new PrefetchIterator(new MaskEdgeSetNextElementFunctor()); + } + + /** + * @see java.util.Set#size() + */ + public int size() + { + if (this.size == -1) { + this.size = 0; + for (Iterator iter = iterator(); iter.hasNext();) { + iter.next(); + this.size++; + } + } + return this.size; + } + + //~ Inner Classes ---------------------------------------------------------- + + private class MaskEdgeSetNextElementFunctor + implements NextElementFunctor + { + private Iterator iter; + + public MaskEdgeSetNextElementFunctor() + { + this.iter = MaskEdgeSet.this.edgeSet.iterator(); + } + + public E nextElement() + throws NoSuchElementException + { + E edge = this.iter.next(); + while (isMasked(edge)) { + edge = this.iter.next(); + } + return edge; + } + + private boolean isMasked(E edge) + { + return MaskEdgeSet.this.mask.isEdgeMasked(edge) + || MaskEdgeSet.this.mask.isVertexMasked( + MaskEdgeSet.this.graph.getEdgeSource(edge)) + || MaskEdgeSet.this.mask.isVertexMasked( + MaskEdgeSet.this.graph.getEdgeTarget(edge)); + } + } +} + +// End MaskEdgeSet.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskFunctor.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskFunctor.java new file mode 100644 index 00000000..a7bb3cf8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskFunctor.java @@ -0,0 +1,72 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * MaskFunctor.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: MaskFunctor.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +/** + * A functor interface for masking out vertices and edges of a graph. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +public interface MaskFunctor +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Returns true if the edge is masked, false + * otherwise. + * + * @param edge edge. + * + * @return . + */ + public boolean isEdgeMasked(E edge); + + /** + * Returns true if the vertex is masked, false + * otherwise. + * + * @param vertex vertex. + * + * @return . + */ + public boolean isVertexMasked(V vertex); +} + +// End MaskFunctor.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskSubgraph.java new file mode 100644 index 00000000..6103c433 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskSubgraph.java @@ -0,0 +1,298 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * MaskSubgraph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: MaskSubgraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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). + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +public class MaskSubgraph + extends AbstractGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String UNMODIFIABLE = "this graph is unmodifiable"; + + //~ Instance fields -------------------------------------------------------- + + private Graph base; + + private Set edges; + + private MaskFunctor mask; + + private Set vertices; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new induced subgraph. Running-time = O(1). + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param mask vertices and edges to exclude in the subgraph. If a + * vertex/edge is masked, it is as if it is not in the subgraph. + */ + public MaskSubgraph(Graph base, MaskFunctor mask) + { + super(); + this.base = base; + this.mask = mask; + + this.vertices = new MaskVertexSet(base.vertexSet(), mask); + this.edges = new MaskEdgeSet(base, base.edgeSet(), mask); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + public boolean addEdge(V sourceVertex, V targetVertex, E edge) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + public boolean containsEdge(E e) + { + return edgeSet().contains(e); + } + + public boolean containsVertex(V v) + { + return !this.mask.isVertexMasked(v) && this.base.containsVertex(v); + } + + /** + * @see UndirectedGraph#degreeOf(Object) + */ + public int degreeOf(V vertex) + { + return edgesOf(vertex).size(); + } + + public Set edgeSet() + { + return this.edges; + } + + public Set edgesOf(V vertex) + { + assertVertexExist(vertex); + + return new MaskEdgeSet( + this.base, + this.base.edgesOf(vertex), + this.mask); + } + + public Set getAllEdges(V sourceVertex, V targetVertex) + { + Set edges = null; + + if (containsVertex(sourceVertex) && containsVertex(targetVertex)) { + return new MaskEdgeSet( + this.base, + this.base.getAllEdges( + sourceVertex, + targetVertex), + this.mask); + } + + return edges; + } + + public E getEdge(V sourceVertex, V targetVertex) + { + Set edges = getAllEdges(sourceVertex, targetVertex); + + if ((edges == null) || edges.isEmpty()) { + return null; + } else { + return edges.iterator().next(); + } + } + + public EdgeFactory getEdgeFactory() + { + return this.base.getEdgeFactory(); + } + + public V getEdgeSource(E edge) + { + assert (edgeSet().contains(edge)); + + return this.base.getEdgeSource(edge); + } + + public V getEdgeTarget(E edge) + { + assert (edgeSet().contains(edge)); + + return this.base.getEdgeTarget(edge); + } + + public double getEdgeWeight(E edge) + { + assert (edgeSet().contains(edge)); + + return this.base.getEdgeWeight(edge); + } + + /** + * @see DirectedGraph#incomingEdgesOf(Object) + */ + public Set incomingEdgesOf(V vertex) + { + assertVertexExist(vertex); + + return new MaskEdgeSet( + this.base, + ((DirectedGraph) this.base).incomingEdgesOf(vertex), + this.mask); + } + + /** + * @see DirectedGraph#inDegreeOf(Object) + */ + public int inDegreeOf(V vertex) + { + return incomingEdgesOf(vertex).size(); + } + + /** + * @see DirectedGraph#outDegreeOf(Object) + */ + public int outDegreeOf(V vertex) + { + return outgoingEdgesOf(vertex).size(); + } + + /** + * @see DirectedGraph#outgoingEdgesOf(Object) + */ + public Set outgoingEdgesOf(V vertex) + { + assertVertexExist(vertex); + + return new MaskEdgeSet( + this.base, + ((DirectedGraph) this.base).outgoingEdgesOf(vertex), + this.mask); + } + + /** + * @see Graph#removeAllEdges(Collection) + */ + public boolean removeAllEdges(Collection edges) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllEdges(Object, Object) + */ + public Set removeAllEdges(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllVertices(Collection) + */ + public boolean removeAllVertices(Collection vertices) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeEdge(Object) + */ + public boolean removeEdge(E e) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeVertex(Object) + */ + public boolean removeVertex(V v) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + public Set vertexSet() + { + return this.vertices; + } +} + +// End MaskSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskVertexSet.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskVertexSet.java new file mode 100644 index 00000000..a312098e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/MaskVertexSet.java @@ -0,0 +1,134 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * MaskVertexSet.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: MaskVertexSet.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.util.*; +import org.jgrapht.util.PrefetchIterator.*; + + +/** + * Helper for {@link MaskSubgraph}. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +class MaskVertexSet + extends AbstractSet +{ + //~ Instance fields -------------------------------------------------------- + + private MaskFunctor mask; + + private int size; + + private Set vertexSet; + + private transient TypeUtil vertexTypeDecl = null; + + //~ Constructors ----------------------------------------------------------- + + public MaskVertexSet(Set vertexSet, MaskFunctor mask) + { + this.vertexSet = vertexSet; + this.mask = mask; + this.size = -1; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see java.util.Collection#contains(java.lang.Object) + */ + public boolean contains(Object o) + { + return + !this.mask.isVertexMasked(TypeUtil.uncheckedCast(o, vertexTypeDecl)) + && this.vertexSet.contains(o); + } + + /** + * @see java.util.Set#iterator() + */ + public Iterator iterator() + { + return new PrefetchIterator(new MaskVertexSetNextElementFunctor()); + } + + /** + * @see java.util.Set#size() + */ + public int size() + { + if (this.size == -1) { + this.size = 0; + for (Iterator iter = iterator(); iter.hasNext();) { + iter.next(); + this.size++; + } + } + return this.size; + } + + //~ Inner Classes ---------------------------------------------------------- + + private class MaskVertexSetNextElementFunctor + implements NextElementFunctor + { + private Iterator iter; + + public MaskVertexSetNextElementFunctor() + { + this.iter = MaskVertexSet.this.vertexSet.iterator(); + } + + public V nextElement() + throws NoSuchElementException + { + V element = this.iter.next(); + while (MaskVertexSet.this.mask.isVertexMasked(element)) { + element = this.iter.next(); + } + return element; + } + } +} + +// End MaskVertexSet.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Multigraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Multigraph.java new file mode 100644 index 00000000..a0d2f43e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Multigraph.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* --------------- + * Multigraph.java + * --------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: Multigraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class Multigraph + extends AbstractBaseGraph + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3257001055819871795L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new multigraph. + * + * @param edgeClass class on which to base factory for edges + */ + public Multigraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new multigraph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public Multigraph(EdgeFactory ef) + { + super(ef, true, false); + } +} + +// End Multigraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ParanoidGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ParanoidGraph.java new file mode 100644 index 00000000..7989c42e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/ParanoidGraph.java @@ -0,0 +1,110 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * ParanoidGraph.java + * ------------------- + * (C) Copyright 2007-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: ParanoidGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 8-Nov-2007 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author John Sichi + * @version $Id: ParanoidGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + */ +public class ParanoidGraph + extends GraphDelegator +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 5075284167422166539L; + + //~ Constructors ----------------------------------------------------------- + + public ParanoidGraph(Graph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + verifyAdd(edgeSet(), e); + return super.addEdge(sourceVertex, targetVertex, e); + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + verifyAdd(vertexSet(), v); + return super.addVertex(v); + } + + private static void verifyAdd(Set set, T t) + { + for (T o : set) { + if (o == t) { + continue; + } + if (o.equals(t) && (o.hashCode() != t.hashCode())) { + throw new IllegalArgumentException( + "ParanoidGraph detected objects " + + "o1 (hashCode=" + o.hashCode() + + ") and o2 (hashCode=" + t.hashCode() + + ") where o1.equals(o2) " + + "but o1.hashCode() != o2.hashCode()"); + } + } + } +} + +// End ParanoidGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Pseudograph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Pseudograph.java new file mode 100644 index 00000000..9fed4bd7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Pseudograph.java @@ -0,0 +1,84 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * Pseudograph.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: Pseudograph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class Pseudograph + extends AbstractBaseGraph + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3833183614484755253L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new pseudograph. + * + * @param edgeClass class on which to base factory for edges + */ + public Pseudograph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new pseudograph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public Pseudograph(EdgeFactory ef) + { + super(ef, true, true); + } +} + +// End Pseudograph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleDirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleDirectedGraph.java new file mode 100644 index 00000000..68e2a004 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleDirectedGraph.java @@ -0,0 +1,82 @@ +/* ========================================== + * 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. + */ +/* ------------------------ + * SimpleDirectedGraph.java + * ------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: SimpleDirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class SimpleDirectedGraph + extends AbstractBaseGraph + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 4049358608472879671L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new simple directed graph. + * + * @param edgeClass class on which to base factory for edges + */ + public SimpleDirectedGraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } + + /** + * Creates a new simple directed graph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public SimpleDirectedGraph(EdgeFactory ef) + { + super(ef, false, false); + } +} + +// End SimpleDirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleDirectedWeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleDirectedWeightedGraph.java new file mode 100644 index 00000000..2b8fba79 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleDirectedWeightedGraph.java @@ -0,0 +1,83 @@ +/* ========================================== + * 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. + */ +/* -------------------------------- + * SimpleDirectedWeightedGraph.java + * -------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: SimpleDirectedWeightedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A simple directed weighted graph. A simple directed weighted graph is a + * simple directed graph for which edges are assigned weights. + */ +public class SimpleDirectedWeightedGraph + extends SimpleDirectedGraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3904960841681220919L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new simple directed weighted graph with the specified edge + * factory. + * + * @param ef the edge factory of the new graph. + */ + public SimpleDirectedWeightedGraph(EdgeFactory ef) + { + super(ef); + } + + /** + * Creates a new simple directed weighted graph. + * + * @param edgeClass class on which to base factory for edges + */ + public SimpleDirectedWeightedGraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } +} + +// End SimpleDirectedWeightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleGraph.java new file mode 100644 index 00000000..f68f8988 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleGraph.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * SimpleGraph.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): CHristian Hammer + * + * $Id: SimpleGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class SimpleGraph + extends AbstractBaseGraph + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3545796589454112304L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new simple graph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public SimpleGraph(EdgeFactory ef) + { + super(ef, false, false); + } + + /** + * Creates a new simple graph. + * + * @param edgeClass class on which to base factory for edges + */ + public SimpleGraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } +} + +// End SimpleGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleWeightedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleWeightedGraph.java new file mode 100644 index 00000000..53544975 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/SimpleWeightedGraph.java @@ -0,0 +1,82 @@ +/* ========================================== + * 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. + */ +/* ------------------------ + * SimpleWeightedGraph.java + * ------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: SimpleWeightedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A simple weighted graph. A simple weighted graph is a simple graph for which + * edges are assigned weights. + */ +public class SimpleWeightedGraph + extends SimpleGraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3906088949100655922L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new simple weighted graph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public SimpleWeightedGraph(EdgeFactory ef) + { + super(ef); + } + + /** + * Creates a new simple weighted graph. + * + * @param edgeClass class on which to base factory for edges + */ + public SimpleWeightedGraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } +} + +// End SimpleWeightedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Subgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Subgraph.java new file mode 100644 index 00000000..8b7306f3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/Subgraph.java @@ -0,0 +1,542 @@ +/* ========================================== + * 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. + */ +/* ------------- + * Subgraph.java + * ------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: Subgraph.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 26-Jul-2003 : Accurate constructors to avoid casting problems (BN); + * 10-Aug-2003 : Adaptation to new event model (BN); + * 23-Oct-2003 : Allowed non-listenable graph as base (BN); + * 07-Feb-2004 : Enabled serialization (BN); + * 11-Mar-2004 : Made generic (CH); + * 15-Mar-2004 : Integrity is now checked using Maps (CH); + * 20-Mar-2004 : Cancelled verification of element identity to base graph (BN); + * 21-Sep-2004 : Added induced subgraph (who?) + * 07-May-2006 : Changed from List to Set (JVS); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; +import org.jgrapht.util.*; + + +/** + * 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 {@link org.jgrapht.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 {@link LinkedHashSet}).

    + * + * @author Barak Naveh + * @see Graph + * @see Set + * @since Jul 18, 2003 + */ +public class Subgraph> + extends AbstractGraph + implements Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3208313055169665387L; + private static final String NO_SUCH_EDGE_IN_BASE = + "no such edge in base graph"; + private static final String NO_SUCH_VERTEX_IN_BASE = + "no such vertex in base graph"; + + //~ Instance fields -------------------------------------------------------- + + // + Set edgeSet = new LinkedHashSet(); // friendly to improve performance + Set vertexSet = new LinkedHashSet(); // friendly to improve + + // performance + + // + private transient Set unmodifiableEdgeSet = null; + private transient Set unmodifiableVertexSet = null; + private G base; + private boolean isInduced = false; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new Subgraph. + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param vertexSubset vertices to include in the subgraph. If + * null then all vertices are included. + * @param edgeSubset edges to in include in the subgraph. If + * null then all the edges whose vertices found in the graph are + * included. + */ + public Subgraph(G base, Set vertexSubset, Set edgeSubset) + { + super(); + + this.base = base; + + if (edgeSubset == null) { + isInduced = true; + } + + if (base instanceof ListenableGraph) { + ((ListenableGraph) base).addGraphListener( + new BaseGraphListener()); + } + + addVerticesUsingFilter(base.vertexSet(), vertexSubset); + addEdgesUsingFilter(base.edgeSet(), edgeSubset); + } + + /** + * 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) . + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param vertexSubset vertices to include in the subgraph. If + * null then all vertices are included. + */ + public Subgraph(G base, Set vertexSubset) + { + this(base, vertexSubset, null); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#getAllEdges(Object, Object) + */ + public Set getAllEdges(V sourceVertex, V targetVertex) + { + Set edges = null; + + if (containsVertex(sourceVertex) && containsVertex(targetVertex)) { + edges = new ArrayUnenforcedSet(); + + Set baseEdges = base.getAllEdges(sourceVertex, targetVertex); + + for (Iterator iter = baseEdges.iterator(); iter.hasNext();) { + E e = iter.next(); + + if (edgeSet.contains(e)) { // add if subgraph also contains + // it + edges.add(e); + } + } + } + + return edges; + } + + /** + * @see Graph#getEdge(Object, Object) + */ + public E getEdge(V sourceVertex, V targetVertex) + { + Set edges = getAllEdges(sourceVertex, targetVertex); + + if ((edges == null) || edges.isEmpty()) { + return null; + } else { + return edges.iterator().next(); + } + } + + /** + * @see Graph#getEdgeFactory() + */ + public EdgeFactory getEdgeFactory() + { + return base.getEdgeFactory(); + } + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + assertVertexExist(sourceVertex); + assertVertexExist(targetVertex); + + if (!base.containsEdge(sourceVertex, targetVertex)) { + throw new IllegalArgumentException(NO_SUCH_EDGE_IN_BASE); + } + + Set edges = base.getAllEdges(sourceVertex, targetVertex); + + for (Iterator iter = edges.iterator(); iter.hasNext();) { + E e = iter.next(); + + if (!containsEdge(e)) { + edgeSet.add(e); + + return e; + } + } + + return null; + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + if (e == null) { + throw new NullPointerException(); + } + + if (!base.containsEdge(e)) { + throw new IllegalArgumentException(NO_SUCH_EDGE_IN_BASE); + } + + assertVertexExist(sourceVertex); + assertVertexExist(targetVertex); + + assert (base.getEdgeSource(e) == sourceVertex); + assert (base.getEdgeTarget(e) == targetVertex); + + if (containsEdge(e)) { + return false; + } else { + edgeSet.add(e); + + return true; + } + } + + /** + * Adds the specified vertex to this subgraph. + * + * @param v the vertex to be added. + * + * @return true if the vertex was added, otherwise + * false. + * + * @throws NullPointerException + * @throws IllegalArgumentException + * + * @see Subgraph + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + if (v == null) { + throw new NullPointerException(); + } + + if (!base.containsVertex(v)) { + throw new IllegalArgumentException(NO_SUCH_VERTEX_IN_BASE); + } + + if (containsVertex(v)) { + return false; + } else { + vertexSet.add(v); + + return true; + } + } + + /** + * @see Graph#containsEdge(Object) + */ + public boolean containsEdge(E e) + { + return edgeSet.contains(e); + } + + /** + * @see Graph#containsVertex(Object) + */ + public boolean containsVertex(V v) + { + return vertexSet.contains(v); + } + + /** + * @see Graph#edgeSet() + */ + public Set edgeSet() + { + if (unmodifiableEdgeSet == null) { + unmodifiableEdgeSet = Collections.unmodifiableSet(edgeSet); + } + + return unmodifiableEdgeSet; + } + + /** + * @see Graph#edgesOf(Object) + */ + public Set edgesOf(V vertex) + { + assertVertexExist(vertex); + + Set edges = new ArrayUnenforcedSet(); + Set baseEdges = base.edgesOf(vertex); + + for (E e : baseEdges) { + if (containsEdge(e)) { + edges.add(e); + } + } + + return edges; + } + + /** + * @see Graph#removeEdge(Object) + */ + public boolean removeEdge(E e) + { + return edgeSet.remove(e); + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + E e = getEdge(sourceVertex, targetVertex); + + return edgeSet.remove(e) ? e : null; + } + + /** + * @see Graph#removeVertex(Object) + */ + public boolean removeVertex(V v) + { + // If the base graph does NOT contain v it means we are here in + // response to removal of v from the base. In such case we don't need + // to remove all the edges of v as they were already removed. + if (containsVertex(v) && base.containsVertex(v)) { + removeAllEdges(edgesOf(v)); + } + + return vertexSet.remove(v); + } + + /** + * @see Graph#vertexSet() + */ + public Set vertexSet() + { + if (unmodifiableVertexSet == null) { + unmodifiableVertexSet = Collections.unmodifiableSet(vertexSet); + } + + return unmodifiableVertexSet; + } + + /** + * @see Graph#getEdgeSource(Object) + */ + public V getEdgeSource(E e) + { + return base.getEdgeSource(e); + } + + /** + * @see Graph#getEdgeTarget(Object) + */ + public V getEdgeTarget(E e) + { + return base.getEdgeTarget(e); + } + + private void addEdgesUsingFilter(Set edgeSet, Set filter) + { + E e; + boolean containsVertices; + boolean edgeIncluded; + + for (Iterator iter = edgeSet.iterator(); iter.hasNext();) { + e = iter.next(); + + V sourceVertex = base.getEdgeSource(e); + V targetVertex = base.getEdgeTarget(e); + containsVertices = + containsVertex(sourceVertex) + && containsVertex(targetVertex); + + // note the use of short circuit evaluation + edgeIncluded = (filter == null) || filter.contains(e); + + if (containsVertices && edgeIncluded) { + addEdge(sourceVertex, targetVertex, e); + } + } + } + + private void addVerticesUsingFilter(Set vertexSet, Set filter) + { + V v; + + for (Iterator iter = vertexSet.iterator(); iter.hasNext();) { + v = iter.next(); + + // note the use of short circuit evaluation + if ((filter == null) || filter.contains(v)) { + addVertex(v); + } + } + } + + public G getBase() + { + return base; + } + + /** + * @see Graph#getEdgeWeight(Object) + */ + public double getEdgeWeight(E e) + { + return base.getEdgeWeight(e); + } + + /** + * @see WeightedGraph#setEdgeWeight(Object, double) + */ + public void setEdgeWeight(E e, double weight) + { + ((WeightedGraph) base).setEdgeWeight(e, weight); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * An internal listener on the base graph. + * + * @author Barak Naveh + * @since Jul 20, 2003 + */ + private class BaseGraphListener + implements GraphListener, + Serializable + { + private static final long serialVersionUID = 4343535244243546391L; + + /** + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public void edgeAdded(GraphEdgeChangeEvent e) + { + if (isInduced) { + E edge = e.getEdge(); + addEdge( + base.getEdgeSource(edge), + base.getEdgeTarget(edge), + edge); + } + } + + /** + * @see GraphListener#edgeRemoved(GraphEdgeChangeEvent) + */ + public void edgeRemoved(GraphEdgeChangeEvent e) + { + E edge = e.getEdge(); + + removeEdge(edge); + } + + /** + * @see VertexSetListener#vertexAdded(GraphVertexChangeEvent) + */ + public void vertexAdded(GraphVertexChangeEvent e) + { + // we don't care + } + + /** + * @see VertexSetListener#vertexRemoved(GraphVertexChangeEvent) + */ + public void vertexRemoved(GraphVertexChangeEvent e) + { + V vertex = e.getVertex(); + + removeVertex(vertex); + } + } +} + +// End Subgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedGraphUnion.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedGraphUnion.java new file mode 100644 index 00000000..f07093d9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedGraphUnion.java @@ -0,0 +1,43 @@ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +public class UndirectedGraphUnion + extends GraphUnion> + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -740199233080172450L; + + //~ Constructors ----------------------------------------------------------- + + UndirectedGraphUnion( + UndirectedGraph g1, + UndirectedGraphUnion g2, + WeightCombiner operator) + { + super(g1, g2, operator); + } + + UndirectedGraphUnion( + UndirectedGraph g1, + UndirectedGraphUnion g2) + { + super(g1, g2); + } + + //~ Methods ---------------------------------------------------------------- + + public int degreeOf(V vertex) + { + Set res = edgesOf(vertex); + return res.size(); + } +} + +// End $file.name$ diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedMaskSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedMaskSubgraph.java new file mode 100644 index 00000000..010d88c3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedMaskSubgraph.java @@ -0,0 +1,64 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * UndirectedMaskSubgraph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: UndirectedMaskSubgraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * An undirected graph that is a {@link MaskSubgraph} on another graph. + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +public class UndirectedMaskSubgraph + extends MaskSubgraph + implements UndirectedGraph +{ + //~ Constructors ----------------------------------------------------------- + + public UndirectedMaskSubgraph( + UndirectedGraph base, + MaskFunctor mask) + { + super(base, mask); + } +} + +// End UndirectedMaskSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedSubgraph.java new file mode 100644 index 00000000..28304133 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedSubgraph.java @@ -0,0 +1,106 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * UndirectedSubgraph.java + * ----------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: UndirectedSubgraph.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * An undirected graph that is a subgraph on other graph. + * + * @see Subgraph + */ +public class UndirectedSubgraph + extends Subgraph> + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3256728359772631350L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new undirected subgraph. + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param vertexSubset vertices to include in the subgraph. If + * null then all vertices are included. + * @param edgeSubset edges to in include in the subgraph. If + * null then all the edges whose vertices found in the graph are + * included. + */ + public UndirectedSubgraph( + UndirectedGraph base, + Set vertexSubset, + Set edgeSubset) + { + super(base, vertexSubset, edgeSubset); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see UndirectedGraph#degreeOf(Object) + */ + public int degreeOf(V vertex) + { + assertVertexExist(vertex); + + int degree = 0; + + for (E e : getBase().edgesOf(vertex)) { + if (containsEdge(e)) { + degree++; + + if (getEdgeSource(e).equals(getEdgeTarget(e))) { + degree++; + } + } + } + + return degree; + } +} + +// End UndirectedSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedWeightedSubgraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedWeightedSubgraph.java new file mode 100644 index 00000000..a5592e37 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UndirectedWeightedSubgraph.java @@ -0,0 +1,82 @@ +/* ========================================== + * 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. + */ +/* ------------------------------- + * UndirectedWeightedSubgraph.java + * ------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: UndirectedWeightedSubgraph.java 689 2009-07-04 06:40:29Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * An undirected weighted graph that is a subgraph on other graph. + * + * @see Subgraph + */ +public class UndirectedWeightedSubgraph + extends UndirectedSubgraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3689346615735236409L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new undirected weighted subgraph. + * + * @param base the base (backing) graph on which the subgraph will be based. + * @param vertexSubset vertices to include in the subgraph. If + * null then all vertices are included. + * @param edgeSubset edges to in include in the subgraph. If + * null then all the edges whose vertices found in the graph are + * included. + */ + public UndirectedWeightedSubgraph( + WeightedGraph base, + Set vertexSubset, + Set edgeSubset) + { + super((UndirectedGraph) base, vertexSubset, edgeSubset); + } +} + +// End UndirectedWeightedSubgraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableDirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableDirectedGraph.java new file mode 100644 index 00000000..f2a61056 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableDirectedGraph.java @@ -0,0 +1,74 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * UnmodifiableDirectedGraph.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: UnmodifiableDirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A directed graph that cannot be modified. + * + * @see UnmodifiableGraph + */ +public class UnmodifiableDirectedGraph + extends UnmodifiableGraph + implements DirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3978701783725913906L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new unmodifiable directed graph based on the specified backing + * graph. + * + * @param g the backing graph on which an unmodifiable graph is to be + * created. + */ + public UnmodifiableDirectedGraph(DirectedGraph g) + { + super(g); + } +} + +// End UnmodifiableDirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableGraph.java new file mode 100644 index 00000000..c46112c3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableGraph.java @@ -0,0 +1,164 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * UnmodifiableGraph.java + * ---------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: UnmodifiableGraph.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); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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.

    + * + * @author Barak Naveh + * @since Jul 24, 2003 + */ +public class UnmodifiableGraph + extends GraphDelegator + implements Serializable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3544957670722713913L; + private static final String UNMODIFIABLE = "this graph is unmodifiable"; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new unmodifiable graph based on the specified backing graph. + * + * @param g the backing graph on which an unmodifiable graph is to be + * created. + */ + public UnmodifiableGraph(Graph g) + { + super(g); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see Graph#addEdge(Object, Object) + */ + public E addEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#addEdge(Object, Object, Object) + */ + public boolean addEdge(V sourceVertex, V targetVertex, E e) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#addVertex(Object) + */ + public boolean addVertex(V v) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllEdges(Collection) + */ + public boolean removeAllEdges(Collection edges) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllEdges(Object, Object) + */ + public Set removeAllEdges(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeAllVertices(Collection) + */ + public boolean removeAllVertices(Collection vertices) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeEdge(Object) + */ + public boolean removeEdge(E e) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeEdge(Object, Object) + */ + public E removeEdge(V sourceVertex, V targetVertex) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } + + /** + * @see Graph#removeVertex(Object) + */ + public boolean removeVertex(V v) + { + throw new UnsupportedOperationException(UNMODIFIABLE); + } +} + +// End UnmodifiableGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableUndirectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableUndirectedGraph.java new file mode 100644 index 00000000..f0d29f30 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/UnmodifiableUndirectedGraph.java @@ -0,0 +1,74 @@ +/* ========================================== + * 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. + */ +/* -------------------------------- + * UnmodifiableUndirectedGraph.java + * -------------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: UnmodifiableUndirectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 11-Mar-2004 : Made generic (CH) + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * An undirected graph that cannot be modified. + * + * @see UnmodifiableGraph + */ +public class UnmodifiableUndirectedGraph + extends UnmodifiableGraph + implements UndirectedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3258134639355704624L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new unmodifiable undirected graph based on the specified + * backing graph. + * + * @param g the backing graph on which an unmodifiable graph is to be + * created. + */ + public UnmodifiableUndirectedGraph(UndirectedGraph g) + { + super(g); + } +} + +// End UnmodifiableUndirectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/WeightedMultigraph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/WeightedMultigraph.java new file mode 100644 index 00000000..5a2b0b88 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/WeightedMultigraph.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * WeightedMultigraph.java + * ----------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: WeightedMultigraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class WeightedMultigraph + extends Multigraph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3544671793370640696L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new weighted multigraph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public WeightedMultigraph(EdgeFactory ef) + { + super(ef); + } + + /** + * Creates a new weighted multigraph. + * + * @param edgeClass class on which to base factory for edges + */ + public WeightedMultigraph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } +} + +// End WeightedMultigraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/WeightedPseudograph.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/WeightedPseudograph.java new file mode 100644 index 00000000..9315570e --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/WeightedPseudograph.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* ------------------------ + * WeightedPseudograph.java + * ------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: WeightedPseudograph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Aug-2003 : Initial revision (BN); + * 06-Aug-2005 : Made generic (CH); + * 28-May-2006 : Moved connectivity info from edge to graph (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * 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. + */ +public class WeightedPseudograph + extends Pseudograph + implements WeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3257290244524356152L; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new weighted pseudograph with the specified edge factory. + * + * @param ef the edge factory of the new graph. + */ + public WeightedPseudograph(EdgeFactory ef) + { + super(ef); + } + + /** + * Creates a new weighted pseudograph. + * + * @param edgeClass class on which to base factory for edges + */ + public WeightedPseudograph(Class edgeClass) + { + this(new ClassBasedEdgeFactory(edgeClass)); + } +} + +// End WeightedPseudograph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/package.html new file mode 100644 index 00000000..700ab7f5 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/graph/package.html @@ -0,0 +1,6 @@ + + + +Implementations of various graphs. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/package.html new file mode 100644 index 00000000..76a55673 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/package.html @@ -0,0 +1,7 @@ + + + +The front-end API's interfaces and classes, including {@link org.jgrapht.Graph}, +{@link org.jgrapht.DirectedGraph} and {@link org.jgrapht.UndirectedGraph}. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/AbstractGraphIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/AbstractGraphIterator.java new file mode 100644 index 00000000..e77badba --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/AbstractGraphIterator.java @@ -0,0 +1,217 @@ +/* ========================================== + * JGraphT : a free Java graph-theory library + * ========================================== + * + * Project Info: http://jgrapht.sourceforge.net/ + * Project Creator: Barak Naveh (barak_naveh@users.sourceforge.net) + * + * (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. + */ +/* -------------------------- + * AbstractGraphIterator.java + * -------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: AbstractGraphIterator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 11-Aug-2003 : Adaptation to new event model (BN); + * 04-May-2004 : Made generic (CH) + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.event.*; + + +/** + * An empty implementation of a graph iterator to minimize the effort required + * to implement graph iterators. + * + * @author Barak Naveh + * @since Jul 19, 2003 + */ +public abstract class AbstractGraphIterator + implements GraphIterator +{ + //~ Instance fields -------------------------------------------------------- + + private List> traversalListeners = + new ArrayList>(); + private boolean crossComponentTraversal = true; + private boolean reuseEvents = false; + + // We keep this cached redundantly with traversalListeners.size() + // so that subclasses can use it as a fast check to see if + // event firing calls can be skipped. + protected int nListeners = 0; + + //~ Methods ---------------------------------------------------------------- + + /** + * Sets the cross component traversal flag - indicates whether to traverse + * the graph across connected components. + * + * @param crossComponentTraversal if true traverses across + * connected components. + */ + public void setCrossComponentTraversal(boolean crossComponentTraversal) + { + this.crossComponentTraversal = crossComponentTraversal; + } + + /** + * Test whether this iterator is set to traverse the graph across connected + * components. + * + * @return true if traverses across connected components, + * otherwise false. + */ + public boolean isCrossComponentTraversal() + { + return crossComponentTraversal; + } + + /** + * @see GraphIterator#setReuseEvents(boolean) + */ + public void setReuseEvents(boolean reuseEvents) + { + this.reuseEvents = reuseEvents; + } + + /** + * @see GraphIterator#isReuseEvents() + */ + public boolean isReuseEvents() + { + return reuseEvents; + } + + /** + * Adds the specified traversal listener to this iterator. + * + * @param l the traversal listener to be added. + */ + public void addTraversalListener(TraversalListener l) + { + if (!traversalListeners.contains(l)) { + traversalListeners.add(l); + nListeners = traversalListeners.size(); + } + } + + /** + * Unsupported. + * + * @throws UnsupportedOperationException + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + /** + * Removes the specified traversal listener from this iterator. + * + * @param l the traversal listener to be removed. + */ + public void removeTraversalListener(TraversalListener l) + { + traversalListeners.remove(l); + nListeners = traversalListeners.size(); + } + + /** + * Informs all listeners that the traversal of the current connected + * component finished. + * + * @param e the connected component finished event. + */ + protected void fireConnectedComponentFinished( + ConnectedComponentTraversalEvent e) + { + for (int i = 0; i < nListeners; i++) { + TraversalListener l = traversalListeners.get(i); + l.connectedComponentFinished(e); + } + } + + /** + * Informs all listeners that a traversal of a new connected component has + * started. + * + * @param e the connected component started event. + */ + protected void fireConnectedComponentStarted( + ConnectedComponentTraversalEvent e) + { + for (int i = 0; i < nListeners; i++) { + TraversalListener l = traversalListeners.get(i); + l.connectedComponentStarted(e); + } + } + + /** + * Informs all listeners that a the specified edge was visited. + * + * @param e the edge traversal event. + */ + protected void fireEdgeTraversed(EdgeTraversalEvent e) + { + for (int i = 0; i < nListeners; i++) { + TraversalListener l = traversalListeners.get(i); + l.edgeTraversed(e); + } + } + + /** + * Informs all listeners that a the specified vertex was visited. + * + * @param e the vertex traversal event. + */ + protected void fireVertexTraversed(VertexTraversalEvent e) + { + for (int i = 0; i < nListeners; i++) { + TraversalListener l = traversalListeners.get(i); + l.vertexTraversed(e); + } + } + + /** + * Informs all listeners that a the specified vertex was finished. + * + * @param e the vertex traversal event. + */ + protected void fireVertexFinished(VertexTraversalEvent e) + { + for (int i = 0; i < nListeners; i++) { + TraversalListener l = traversalListeners.get(i); + l.vertexFinished(e); + } + } +} + +// End AbstractGraphIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/BreadthFirstIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/BreadthFirstIterator.java new file mode 100644 index 00000000..e420ddf2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/BreadthFirstIterator.java @@ -0,0 +1,130 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * BreadthFirstIterator.java + * ------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Liviu Rau + * Christian Hammer + * Ross Judson + * + * $Id: BreadthFirstIterator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * 06-Aug-2003 : Extracted common logic to TraverseUtils.XXFirstIterator (BN); + * 31-Jan-2004 : Reparented and changed interface to parent class (BN); + * 28-Sep-2008 : Optimized using ArrayDeque per suggestion from Ross (JVS) + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * 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. + * + * @author Barak Naveh + * @since Jul 19, 2003 + */ +public class BreadthFirstIterator + extends CrossComponentIterator +{ + //~ Instance fields -------------------------------------------------------- + + private Deque queue = new ArrayDeque(); + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new breadth-first iterator for the specified graph. + * + * @param g the graph to be iterated. + */ + public BreadthFirstIterator(Graph g) + { + this(g, null); + } + + /** + * 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. + * + * @param g the graph to be iterated. + * @param startVertex the vertex iteration to be started. + */ + public BreadthFirstIterator(Graph g, V startVertex) + { + super(g, startVertex); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see CrossComponentIterator#isConnectedComponentExhausted() + */ + protected boolean isConnectedComponentExhausted() + { + return queue.isEmpty(); + } + + /** + * @see CrossComponentIterator#encounterVertex(Object, Object) + */ + protected void encounterVertex(V vertex, E edge) + { + putSeenData(vertex, null); + queue.add(vertex); + } + + /** + * @see CrossComponentIterator#encounterVertexAgain(Object, Object) + */ + protected void encounterVertexAgain(V vertex, E edge) + { + } + + /** + * @see CrossComponentIterator#provideNextVertex() + */ + protected V provideNextVertex() + { + return queue.removeFirst(); + } +} + +// End BreadthFirstIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/ClosestFirstIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/ClosestFirstIterator.java new file mode 100644 index 00000000..60328d7f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/ClosestFirstIterator.java @@ -0,0 +1,342 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * ClosestFirstIterator.java + * ------------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): Barak Naveh + * + * $Id: ClosestFirstIterator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 02-Sep-2003 : Initial revision (JVS); + * 31-Jan-2004 : Reparented and changed interface to parent class (BN); + * 29-May-2005 : Added radius support (JVS); + * 06-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.traverse; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * 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.

    + * + * @author John V. Sichi + * @since Sep 2, 2003 + */ +public class ClosestFirstIterator + extends CrossComponentIterator>> +{ + //~ Instance fields -------------------------------------------------------- + + /** + * Priority queue of fringe vertices. + */ + private FibonacciHeap> heap = + new FibonacciHeap>(); + + /** + * Maximum distance to search. + */ + private double radius = Double.POSITIVE_INFINITY; + + private boolean initialized = false; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new closest-first iterator for the specified graph. + * + * @param g the graph to be iterated. + */ + public ClosestFirstIterator(Graph g) + { + this(g, null); + } + + /** + * 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. + * + * @param g the graph to be iterated. + * @param startVertex the vertex iteration to be started. + */ + public ClosestFirstIterator(Graph g, V startVertex) + { + this(g, startVertex, Double.POSITIVE_INFINITY); + } + + /** + * 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. + * + * @param g the graph to be iterated. + * @param startVertex the vertex iteration to be started. + * @param radius limit on path length, or Double.POSITIVE_INFINITY for + * unbounded search. + */ + public ClosestFirstIterator(Graph g, V startVertex, double radius) + { + super(g, startVertex); + this.radius = radius; + checkRadiusTraversal(isCrossComponentTraversal()); + initialized = true; + } + + //~ Methods ---------------------------------------------------------------- + + // override AbstractGraphIterator + public void setCrossComponentTraversal(boolean crossComponentTraversal) + { + if (initialized) { + checkRadiusTraversal(crossComponentTraversal); + } + super.setCrossComponentTraversal(crossComponentTraversal); + } + + /** + * 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. + * + * @param vertex vertex being sought from start vertex + * + * @return length of shortest path known, or Double.POSITIVE_INFINITY if no + * path found yet + */ + public double getShortestPathLength(V vertex) + { + FibonacciHeapNode> node = getSeenData(vertex); + + if (node == null) { + return Double.POSITIVE_INFINITY; + } + + return node.getKey(); + } + + /** + * 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. + * + * @param vertex the spanned vertex. + * + * @return the spanning tree edge, or null if the vertex either has not been + * seen yet or is the start vertex. + */ + public E getSpanningTreeEdge(V vertex) + { + FibonacciHeapNode> node = getSeenData(vertex); + + if (node == null) { + return null; + } + + return node.getData().spanningTreeEdge; + } + + /** + * @see CrossComponentIterator#isConnectedComponentExhausted() + */ + protected boolean isConnectedComponentExhausted() + { + if (heap.size() == 0) { + return true; + } else { + if (heap.min().getKey() > radius) { + heap.clear(); + + return true; + } else { + return false; + } + } + } + + /** + * @see CrossComponentIterator#encounterVertex(Object, Object) + */ + protected void encounterVertex(V vertex, E edge) + { + FibonacciHeapNode> node = createSeenData(vertex, edge); + putSeenData(vertex, node); + heap.insert(node, node.getKey()); + } + + /** + * Override superclass. When we see a vertex again, we need to see if the + * new edge provides a shorter path than the old edge. + * + * @param vertex the vertex re-encountered + * @param edge the edge via which the vertex was re-encountered + */ + protected void encounterVertexAgain(V vertex, E edge) + { + FibonacciHeapNode> node = getSeenData(vertex); + + if (node.getData().frozen) { + // no improvement for this vertex possible + return; + } + + double candidatePathLength = calculatePathLength(vertex, edge); + + if (candidatePathLength < node.getKey()) { + node.getData().spanningTreeEdge = edge; + heap.decreaseKey(node, candidatePathLength); + } + } + + /** + * @see CrossComponentIterator#provideNextVertex() + */ + protected V provideNextVertex() + { + FibonacciHeapNode> node = heap.removeMin(); + node.getData().frozen = true; + + return node.getData().vertex; + } + + private void assertNonNegativeEdge(E edge) + { + if (getGraph().getEdgeWeight(edge) < 0) { + throw new IllegalArgumentException( + "negative edge weights not allowed"); + } + } + + /** + * Determine path length to a vertex via an edge, using the path length for + * the opposite vertex. + * + * @param vertex the vertex for which to calculate the path length. + * @param edge the edge via which the path is being extended. + * + * @return calculated path length. + */ + private double calculatePathLength(V vertex, E edge) + { + assertNonNegativeEdge(edge); + + V otherVertex = Graphs.getOppositeVertex(getGraph(), edge, vertex); + FibonacciHeapNode> otherEntry = + getSeenData(otherVertex); + + return otherEntry.getKey() + + getGraph().getEdgeWeight(edge); + } + + private void checkRadiusTraversal(boolean crossComponentTraversal) + { + if (crossComponentTraversal && (radius != Double.POSITIVE_INFINITY)) { + throw new IllegalArgumentException( + "radius may not be specified for cross-component traversal"); + } + } + + /** + * The first time we see a vertex, make up a new heap node for it. + * + * @param vertex a vertex which has just been encountered. + * @param edge the edge via which the vertex was encountered. + * + * @return the new heap node. + */ + private FibonacciHeapNode> createSeenData( + V vertex, + E edge) + { + double shortestPathLength; + + if (edge == null) { + shortestPathLength = 0; + } else { + shortestPathLength = calculatePathLength(vertex, edge); + } + + QueueEntry entry = new QueueEntry(); + entry.vertex = vertex; + entry.spanningTreeEdge = edge; + + return new FibonacciHeapNode>( + entry, + shortestPathLength); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Private data to associate with each entry in the priority queue. + */ + static class QueueEntry + { + /** + * Best spanning tree edge to vertex seen so far. + */ + E spanningTreeEdge; + + /** + * The vertex reached. + */ + V vertex; + + /** + * True once spanningTreeEdge is guaranteed to be the true minimum. + */ + boolean frozen; + + QueueEntry() + { + } + } +} + +// End ClosestFirstIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/CrossComponentIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/CrossComponentIterator.java new file mode 100644 index 00000000..94241243 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/CrossComponentIterator.java @@ -0,0 +1,570 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * CrossComponentIterator.java + * --------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): John V. Sichi + * Christian Hammer + * + * $Id: CrossComponentIterator.java 650 2008-12-24 20:44:06Z perfecthash $ + * + * Changes + * ------- + * 31-Jul-2003 : Initial revision (BN); + * 11-Aug-2003 : Adaptation to new event model (BN); + * 31-Jan-2004 : Extracted cross-component traversal functionality (BN); + * 04-May-2004 : Made generic (CH) + * 07-May-2006 : Changed from List to Set (JVS); + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; + + +/** + * Provides a cross-connected-component traversal functionality for iterator + * subclasses. + * + * @param vertex type + * @param edge type + * @param type of data associated to seen vertices + * + * @author Barak Naveh + * @since Jan 31, 2004 + */ +public abstract class CrossComponentIterator + extends AbstractGraphIterator +{ + //~ Static fields/initializers --------------------------------------------- + + private static final int CCS_BEFORE_COMPONENT = 1; + private static final int CCS_WITHIN_COMPONENT = 2; + private static final int CCS_AFTER_COMPONENT = 3; + + //~ Enums ------------------------------------------------------------------ + + /** + * Standard vertex visit state enumeration. + */ + protected static enum VisitColor + { + /** + * Vertex has not been returned via iterator yet. + */ + WHITE, + + /** + * Vertex has been returned via iterator, but we're not done with all of + * its out-edges yet. + */ + GRAY, + + /** + * Vertex has been returned via iterator, and we're done with all of its + * out-edges. + */ + BLACK + } + + //~ Instance fields -------------------------------------------------------- + + // + private final ConnectedComponentTraversalEvent ccFinishedEvent = + new ConnectedComponentTraversalEvent( + this, + ConnectedComponentTraversalEvent.CONNECTED_COMPONENT_FINISHED); + private final ConnectedComponentTraversalEvent ccStartedEvent = + new ConnectedComponentTraversalEvent( + this, + ConnectedComponentTraversalEvent.CONNECTED_COMPONENT_STARTED); + + // TODO: support ConcurrentModificationException if graph modified + // during iteration. + private FlyweightEdgeEvent reusableEdgeEvent; + private FlyweightVertexEvent reusableVertexEvent; + private Iterator vertexIterator = null; + + /** + * Stores the vertices that have been seen during iteration and (optionally) + * some additional traversal info regarding each vertex. + */ + private Map seen = new HashMap(); + private V startVertex; + private Specifics specifics; + + private final Graph graph; + + /** + * The connected component state + */ + private int state = CCS_BEFORE_COMPONENT; + + //~ Constructors ----------------------------------------------------------- + + /** + * 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. + * + * @param g the graph to be iterated. + * @param startVertex the vertex iteration to be started. + * + * @throws IllegalArgumentException if g==null or does not + * contain startVertex + */ + public CrossComponentIterator(Graph g, V startVertex) + { + super(); + + if (g == null) { + throw new IllegalArgumentException("graph must not be null"); + } + graph = g; + + specifics = createGraphSpecifics(g); + vertexIterator = g.vertexSet().iterator(); + setCrossComponentTraversal(startVertex == null); + + reusableEdgeEvent = new FlyweightEdgeEvent(this, null); + reusableVertexEvent = new FlyweightVertexEvent(this, null); + + if (startVertex == null) { + // pick a start vertex if graph not empty + if (vertexIterator.hasNext()) { + this.startVertex = vertexIterator.next(); + } else { + this.startVertex = null; + } + } else if (g.containsVertex(startVertex)) { + this.startVertex = startVertex; + } else { + throw new IllegalArgumentException( + "graph must contain the start vertex"); + } + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @return the graph being traversed + */ + public Graph getGraph() + { + return graph; + } + + /** + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + if (startVertex != null) { + encounterStartVertex(); + } + + if (isConnectedComponentExhausted()) { + if (state == CCS_WITHIN_COMPONENT) { + state = CCS_AFTER_COMPONENT; + if (nListeners != 0) { + fireConnectedComponentFinished(ccFinishedEvent); + } + } + + if (isCrossComponentTraversal()) { + while (vertexIterator.hasNext()) { + V v = vertexIterator.next(); + + if (!isSeenVertex(v)) { + encounterVertex(v, null); + state = CCS_BEFORE_COMPONENT; + + return true; + } + } + + return false; + } else { + return false; + } + } else { + return true; + } + } + + /** + * @see java.util.Iterator#next() + */ + public V next() + { + if (startVertex != null) { + encounterStartVertex(); + } + + if (hasNext()) { + if (state == CCS_BEFORE_COMPONENT) { + state = CCS_WITHIN_COMPONENT; + if (nListeners != 0) { + fireConnectedComponentStarted(ccStartedEvent); + } + } + + V nextVertex = provideNextVertex(); + if (nListeners != 0) { + fireVertexTraversed(createVertexTraversalEvent(nextVertex)); + } + + addUnseenChildrenOf(nextVertex); + + return nextVertex; + } else { + throw new NoSuchElementException(); + } + } + + /** + * Returns true if there are no more uniterated vertices in the + * currently iterated connected component; false otherwise. + * + * @return true if there are no more uniterated vertices in the + * currently iterated connected component; false otherwise. + */ + protected abstract boolean isConnectedComponentExhausted(); + + /** + * Update data structures the first time we see a vertex. + * + * @param vertex the vertex encountered + * @param edge the edge via which the vertex was encountered, or null if the + * vertex is a starting point + */ + protected abstract void encounterVertex(V vertex, E edge); + + /** + * Returns the vertex to be returned in the following call to the iterator + * next method. + * + * @return the next vertex to be returned by this iterator. + */ + protected abstract V provideNextVertex(); + + /** + * Access the data stored for a seen vertex. + * + * @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. A null return can also + * indicate that the vertex was explicitly associated with + * null. + */ + protected D getSeenData(V vertex) + { + return seen.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(Object vertex) + { + return seen.containsKey(vertex); + } + + /** + * Called whenever we re-encounter a vertex. The default implementation does + * nothing. + * + * @param vertex the vertex re-encountered + * @param edge the edge via which the vertex was re-encountered + */ + protected abstract void encounterVertexAgain(V vertex, E edge); + + /** + * Stores iterator-dependent data for a vertex that has been seen. + * + * @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. A + * null return can also indicate that the vertex was explicitly + * associated with null. + */ + protected D putSeenData(V vertex, D data) + { + return seen.put(vertex, data); + } + + /** + * Called when a vertex has been finished (meaning is dependent on traversal + * represented by subclass). + * + * @param vertex vertex which has been finished + */ + protected void finishVertex(V vertex) + { + if (nListeners != 0) { + fireVertexFinished(createVertexTraversalEvent(vertex)); + } + } + + // ------------------------------------------------------------------------- + /** + * @param + * @param + * @param g + * + * @return TODO Document me + */ + static Specifics createGraphSpecifics(Graph g) + { + if (g instanceof DirectedGraph) { + return new DirectedSpecifics((DirectedGraph) g); + } else { + return new UndirectedSpecifics(g); + } + } + + private void addUnseenChildrenOf(V vertex) + { + for (E edge : specifics.edgesOf(vertex)) { + if (nListeners != 0) { + fireEdgeTraversed(createEdgeTraversalEvent(edge)); + } + + V oppositeV = Graphs.getOppositeVertex(graph, edge, vertex); + + if (isSeenVertex(oppositeV)) { + encounterVertexAgain(oppositeV, edge); + } else { + encounterVertex(oppositeV, edge); + } + } + } + + private EdgeTraversalEvent createEdgeTraversalEvent(E edge) + { + if (isReuseEvents()) { + reusableEdgeEvent.setEdge(edge); + + return reusableEdgeEvent; + } else { + return new EdgeTraversalEvent(this, edge); + } + } + + private VertexTraversalEvent createVertexTraversalEvent(V vertex) + { + if (isReuseEvents()) { + reusableVertexEvent.setVertex(vertex); + + return reusableVertexEvent; + } else { + return new VertexTraversalEvent(this, vertex); + } + } + + private void encounterStartVertex() + { + encounterVertex(startVertex, null); + startVertex = null; + } + + //~ Inner Interfaces ------------------------------------------------------- + + static interface SimpleContainer + { + /** + * Tests if this container is empty. + * + * @return true if empty, otherwise false. + */ + public boolean isEmpty(); + + /** + * Adds the specified object to this container. + * + * @param o the object to be added. + */ + public void add(T o); + + /** + * Remove an object from this container and return it. + * + * @return the object removed from this container. + */ + public T remove(); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Provides unified interface for operations that are different in directed + * graphs and in undirected graphs. + */ + abstract static class Specifics + { + /** + * Returns the edges outgoing from the specified vertex in case of + * directed graph, and the edge touching the specified vertex in case of + * undirected graph. + * + * @param vertex the vertex whose outgoing edges are to be returned. + * + * @return the edges outgoing from the specified vertex in case of + * directed graph, and the edge touching the specified vertex in case of + * undirected graph. + */ + public abstract Set edgesOf(VV vertex); + } + + /** + * A reusable edge event. + * + * @author Barak Naveh + * @since Aug 11, 2003 + */ + static class FlyweightEdgeEvent + extends EdgeTraversalEvent + { + private static final long serialVersionUID = 4051327833765000755L; + + /** + * @see EdgeTraversalEvent#EdgeTraversalEvent(Object, Edge) + */ + public FlyweightEdgeEvent(Object eventSource, localE edge) + { + super(eventSource, edge); + } + + /** + * Sets the edge of this event. + * + * @param edge the edge to be set. + */ + protected void setEdge(localE edge) + { + this.edge = edge; + } + } + + /** + * A reusable vertex event. + * + * @author Barak Naveh + * @since Aug 11, 2003 + */ + static class FlyweightVertexEvent + extends VertexTraversalEvent + { + private static final long serialVersionUID = 3834024753848399924L; + + /** + * @see VertexTraversalEvent#VertexTraversalEvent(Object, Object) + */ + public FlyweightVertexEvent(Object eventSource, VV vertex) + { + super(eventSource, vertex); + } + + /** + * Sets the vertex of this event. + * + * @param vertex the vertex to be set. + */ + protected void setVertex(VV vertex) + { + this.vertex = vertex; + } + } + + /** + * An implementation of {@link Specifics} for a directed graph. + */ + private static class DirectedSpecifics + extends Specifics + { + private DirectedGraph graph; + + /** + * Creates a new DirectedSpecifics object. + * + * @param g the graph for which this specifics object to be created. + */ + public DirectedSpecifics(DirectedGraph g) + { + graph = g; + } + + /** + * @see CrossComponentIterator.Specifics#edgesOf(Object) + */ + public Set edgesOf(VV vertex) + { + return graph.outgoingEdgesOf(vertex); + } + } + + /** + * An implementation of {@link Specifics} in which edge direction (if any) + * is ignored. + */ + private static class UndirectedSpecifics + extends Specifics + { + private Graph graph; + + /** + * Creates a new UndirectedSpecifics object. + * + * @param g the graph for which this specifics object to be created. + */ + public UndirectedSpecifics(Graph g) + { + graph = g; + } + + /** + * @see CrossComponentIterator.Specifics#edgesOf(Object) + */ + public Set edgesOf(VV vertex) + { + return graph.edgesOf(vertex); + } + } +} + +// End CrossComponentIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/DepthFirstIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/DepthFirstIterator.java new file mode 100644 index 00000000..c0b69591 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/DepthFirstIterator.java @@ -0,0 +1,223 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * DepthFirstIterator.java + * ----------------------- + * (C) Copyright 2003-2008, by Liviu Rau and Contributors. + * + * Original Author: Liviu Rau + * Contributor(s): Barak Naveh + * Christian Hammer + * Welson Sun + * Ross Judson + * + * $Id: DepthFirstIterator.java 686 2009-07-01 18:27:21Z perfecthash $ + * + * Changes + * ------- + * 29-Jul-2003 : Initial revision (LR); + * 31-Jul-2003 : Fixed traversal across connected components (BN); + * 06-Aug-2003 : Extracted common logic to TraverseUtils.XXFirstIterator (BN); + * 31-Jan-2004 : Reparented and changed interface to parent class (BN); + * 04-May-2004 : Made generic (CH) + * 27-Aug-2006 : Added WHITE/GRAY/BLACK to fix bug reported by Welson Sun (JVS) + * 28-Sep-2008 : Optimized using ArrayDeque per suggestion from Ross (JVS) + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * 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. + * + * @author Liviu Rau + * @author Barak Naveh + * @since Jul 29, 2003 + */ +public class DepthFirstIterator + extends CrossComponentIterator +{ + //~ Static fields/initializers --------------------------------------------- + + /** + * 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. + */ + public static final Object SENTINEL = new Object(); + + //~ Instance fields -------------------------------------------------------- + + /** + * @see #getStack + */ + private Deque stack = new ArrayDeque(); + + private transient TypeUtil vertexTypeDecl = null; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new depth-first iterator for the specified graph. + * + * @param g the graph to be iterated. + */ + public DepthFirstIterator(Graph g) + { + this(g, null); + } + + /** + * 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. + * + * @param g the graph to be iterated. + * @param startVertex the vertex iteration to be started. + */ + public DepthFirstIterator(Graph g, V startVertex) + { + super(g, startVertex); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see CrossComponentIterator#isConnectedComponentExhausted() + */ + protected boolean isConnectedComponentExhausted() + { + for (;;) { + if (stack.isEmpty()) { + return true; + } + if (stack.getLast() != SENTINEL) { + // Found a non-sentinel. + return false; + } + + // Found a sentinel: pop it, record the finish time, + // and then loop to check the rest of the stack. + + // Pop null we peeked at above. + stack.removeLast(); + + // This will pop corresponding vertex to be recorded as finished. + recordFinish(); + } + } + + /** + * @see CrossComponentIterator#encounterVertex(Object, Object) + */ + protected void encounterVertex(V vertex, E edge) + { + putSeenData(vertex, VisitColor.WHITE); + stack.addLast(vertex); + } + + /** + * @see CrossComponentIterator#encounterVertexAgain(Object, Object) + */ + protected void encounterVertexAgain(V vertex, E edge) + { + VisitColor color = getSeenData(vertex); + if (color != VisitColor.WHITE) { + // We've already visited this vertex; no need to mess with the + // stack (either it's BLACK and not there at all, or it's GRAY + // and therefore just a sentinel). + return; + } + + // Since we've encountered it before, and it's still WHITE, it + // *must* be on the stack. Use removeLastOccurrence on the + // assumption that for typical topologies and traversals, + // it's likely to be nearer the top of the stack than + // the bottom of the stack. + boolean found = stack.removeLastOccurrence(vertex); + assert (found); + stack.addLast(vertex); + } + + /** + * @see CrossComponentIterator#provideNextVertex() + */ + protected V provideNextVertex() + { + V v; + for (;;) { + Object o = stack.removeLast(); + if (o == SENTINEL) { + // This is a finish-time sentinel we previously pushed. + recordFinish(); + // Now carry on with another pop until we find a non-sentinel + } else { + // Got a real vertex to start working on + v = TypeUtil.uncheckedCast(o, vertexTypeDecl); + break; + } + } + + // Push a sentinel for v onto the stack so that we'll know + // when we're done with it. + stack.addLast(v); + stack.addLast(SENTINEL); + putSeenData(v, VisitColor.GRAY); + return v; + } + + private void recordFinish() + { + V v = TypeUtil.uncheckedCast(stack.removeLast(), vertexTypeDecl); + putSeenData(v, VisitColor.BLACK); + finishVertex(v); + } + + /** + * 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). + * + * @return stack + */ + public Deque getStack() + { + return stack; + } +} + +// End DepthFirstIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/GraphIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/GraphIterator.java new file mode 100644 index 00000000..485b2634 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/GraphIterator.java @@ -0,0 +1,114 @@ +/* ========================================== + * JGraphT : a free Java graph-theory library + * ========================================== + * + * Project Info: http://jgrapht.sourceforge.net/ + * Project Creator: Barak Naveh (barak_naveh@users.sourceforge.net) + * + * (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. + */ +/* ------------------ + * GraphIterator.java + * ------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): Christian Hammer + * + * $Id: GraphIterator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 31-Jul-2003 : Initial revision (BN); + * 11-Aug-2003 : Adaptation to new event model (BN); + * 04-May-2004 : Made generic (CH) + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.event.*; + + +/** + * A graph iterator. + * + * @author Barak Naveh + * @since Jul 31, 2003 + */ +public interface GraphIterator + extends Iterator +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Test whether this iterator is set to traverse the grpah across connected + * components. + * + * @return true if traverses across connected components, + * otherwise false. + */ + public boolean isCrossComponentTraversal(); + + /** + * 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. + * + * @param reuseEvents whether to reuse previously fired event objects + * instead of creating a new event object for each event. + */ + public void setReuseEvents(boolean reuseEvents); + + /** + * 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. + * + * @return the value of the reuseEvents flag. + */ + public boolean isReuseEvents(); + + /** + * Adds the specified traversal listener to this iterator. + * + * @param l the traversal listener to be added. + */ + public void addTraversalListener(TraversalListener l); + + /** + * Unsupported. + * + * @throws UnsupportedOperationException + */ + public void remove(); + + /** + * Removes the specified traversal listener from this iterator. + * + * @param l the traversal listener to be removed. + */ + public void removeTraversalListener(TraversalListener l); +} + +// End GraphIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/TopologicalOrderIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/TopologicalOrderIterator.java new file mode 100644 index 00000000..aef47b05 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/TopologicalOrderIterator.java @@ -0,0 +1,279 @@ +/* ========================================== + * 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. + */ +/* ----------------------------- + * TopologicalOrderIterator.java + * ----------------------------- + * (C) Copyright 2004-2008, by Marden Neubert and Contributors. + * + * Original Author: Marden Neubert + * Contributor(s): Barak Naveh, John V. Sichi + * + * $Id: TopologicalOrderIterator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 17-Dec-2004 : Initial revision (MN); + * 25-Apr-2005 : Fixes for start vertex order (JVS); + * 06-Jun-2005 : Made generic (CH); + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + + +/** + * 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 {@link org.jgrapht.alg.CycleDetector} or {@link + * org.jgrapht.alg.StrongConnectivityInspector}.

    + * + * @author Marden Neubert + * @since Dec 18, 2004 + */ +public class TopologicalOrderIterator + extends CrossComponentIterator +{ + //~ Instance fields -------------------------------------------------------- + + private Queue queue; + private Map inDegreeMap; + + //~ Constructors ----------------------------------------------------------- + + /** + * 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. + * + * @param dg the directed graph to be iterated. + */ + public TopologicalOrderIterator(DirectedGraph dg) + { + this(dg, new LinkedListQueue()); + } + + /** + * 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. + * + * @param dg the directed graph to be iterated. + * @param 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 + */ + public TopologicalOrderIterator(DirectedGraph dg, Queue queue) + { + this(dg, queue, new HashMap()); + } + + // NOTE: This is a hack to deal with the fact that CrossComponentIterator + // needs to know the start vertex in its constructor + private TopologicalOrderIterator( + DirectedGraph dg, + Queue queue, + Map inDegreeMap) + { + this(dg, initialize(dg, queue, inDegreeMap)); + this.queue = queue; + this.inDegreeMap = inDegreeMap; + + if (!dg.vertexSet().isEmpty()) { + // empty queue for non-empty graph would indicate presence of + // cycles (no roots found) + assert (!queue.isEmpty()); + } + } + + // NOTE: This is intentionally private, because starting the sort "in the + // middle" doesn't make sense. + private TopologicalOrderIterator(DirectedGraph dg, V start) + { + super(dg, start); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * @see CrossComponentIterator#isConnectedComponentExhausted() + */ + protected boolean isConnectedComponentExhausted() + { + // FIXME jvs 25-Apr-2005: This isn't correct for a graph with more than + // one component. We will actually exhaust a connected component + // before the queue is empty, because initialize adds roots from all + // components to the queue. + return queue.isEmpty(); + } + + /** + * @see CrossComponentIterator#encounterVertex(Object, Object) + */ + protected void encounterVertex(V vertex, E edge) + { + putSeenData(vertex, null); + decrementInDegree(vertex); + } + + /** + * @see CrossComponentIterator#encounterVertexAgain(Object, Object) + */ + protected void encounterVertexAgain(V vertex, E edge) + { + decrementInDegree(vertex); + } + + /** + * @see CrossComponentIterator#provideNextVertex() + */ + protected V provideNextVertex() + { + return queue.remove(); + } + + /** + * Decrements the in-degree of a vertex. + * + * @param vertex the vertex whose in-degree will be decremented. + */ + private void decrementInDegree(V vertex) + { + ModifiableInteger inDegree = inDegreeMap.get(vertex); + + if (inDegree.value > 0) { + inDegree.value--; + + if (inDegree.value == 0) { + queue.offer(vertex); + } + } + } + + /** + * Initializes the internal traversal object structure. Sets up the internal + * queue with the directed graph vertices and creates the control structure + * for the in-degrees. + * + * @param dg the directed graph to be iterated. + * @param queue initializer for queue + * @param inDegreeMap initializer for inDegreeMap + * + * @return start vertex + */ + private static V initialize( + DirectedGraph dg, + Queue queue, + Map inDegreeMap) + { + for (Iterator i = dg.vertexSet().iterator(); i.hasNext();) { + V vertex = i.next(); + + int inDegree = dg.inDegreeOf(vertex); + inDegreeMap.put(vertex, new ModifiableInteger(inDegree)); + + if (inDegree == 0) { + queue.offer(vertex); + } + } + + if (queue.isEmpty()) { + return null; + } else { + return queue.peek(); + } + } + + //~ Inner Classes ---------------------------------------------------------- + + // NOTE jvs 22-Dec-2006: For JDK1.4-compatibility, we can't assume + // that LinkedList implements Queue, since that wasn't introduced + // until JDK1.5, so use an adapter here. Move this to + // top-level in org.jgrapht.util if anyone else needs it. + private static class LinkedListQueue + extends LinkedList + implements Queue + { + private static final long serialVersionUID = 4217659843476891334L; + + public T element() + { + return getFirst(); + } + + public boolean offer(T o) + { + return add(o); + } + + public T peek() + { + if (isEmpty()) { + return null; + } + return getFirst(); + } + + public T poll() + { + if (isEmpty()) { + return null; + } + return removeFirst(); + } + + public T remove() + { + return removeFirst(); + } + } +} + +// End TopologicalOrderIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/package.html new file mode 100644 index 00000000..8f988b7d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/traverse/package.html @@ -0,0 +1,6 @@ + + + +Graph traversal means. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/ArrayUnenforcedSet.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/ArrayUnenforcedSet.java new file mode 100644 index 00000000..c96404b3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/ArrayUnenforcedSet.java @@ -0,0 +1,112 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * ArrayUnenforcedSet.java + * ----------------- + * (C) Copyright 2006-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: ArrayUnenforcedSet.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 07-May-2006 : Initial version (JVS); + */ +package org.jgrapht.util; + +import java.util.*; + + +/** + * 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. + * + * @author John V. Sichi + */ +public class ArrayUnenforcedSet + extends ArrayList + implements Set +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = -7413250161201811238L; + + //~ Constructors ----------------------------------------------------------- + + public ArrayUnenforcedSet() + { + super(); + } + + public ArrayUnenforcedSet(Collection c) + { + super(c); + } + + public ArrayUnenforcedSet(int n) + { + super(n); + } + + //~ Methods ---------------------------------------------------------------- + + public boolean equals(Object o) + { + return new SetForEquality().equals(o); + } + + public int hashCode() + { + return new SetForEquality().hashCode(); + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Multiple inheritance helper. + */ + private class SetForEquality + extends AbstractSet + { + public Iterator iterator() + { + return ArrayUnenforcedSet.this.iterator(); + } + + public int size() + { + return ArrayUnenforcedSet.this.size(); + } + } +} + +// End ArrayUnenforcedSet.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/FibonacciHeap.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/FibonacciHeap.java new file mode 100644 index 00000000..c0644f82 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/FibonacciHeap.java @@ -0,0 +1,611 @@ +/* ========================================== + * JGraphT : a free Java graph-theory library + * ========================================== + * + * Project Info: http://jgrapht.sourceforge.net/ + * Project Creator: Barak Naveh (barak_naveh@users.sourceforge.net) + * + * (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. + */ +/* -------------------------- + * FibonnaciHeap.java + * -------------------------- + * (C) Copyright 1999-2003, by Nathan Fiedler and Contributors. + * + * Original Author: Nathan Fiedler + * Contributor(s): John V. Sichi + * + * $Id: FibonacciHeap.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Sept-2003 : Adapted from Nathan Fiedler (JVS); + * + * Name Date Description + * ---- ---- ----------- + * nf 08/31/97 Initial version + * nf 09/07/97 Removed FibHeapData interface + * nf 01/20/01 Added synchronization + * nf 01/21/01 Made Node an inner class + * nf 01/05/02 Added clear(), renamed empty() to + * isEmpty(), and renamed printHeap() + * to toString() + * nf 01/06/02 Removed all synchronization + * + */ +package org.jgrapht.util; + +import java.util.*; + + +/** + * 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 + */ +public class FibonacciHeap +{ + //~ Static fields/initializers --------------------------------------------- + + private static final double oneOverLogPhi = + 1.0 / Math.log((1.0 + Math.sqrt(5.0)) / 2.0); + + //~ Instance fields -------------------------------------------------------- + + /** + * Points to the minimum node in the heap. + */ + private FibonacciHeapNode minNode; + + /** + * Number of nodes in the heap. + */ + private int nNodes; + + //~ Constructors ----------------------------------------------------------- + + /** + * Constructs a FibonacciHeap object that contains no elements. + */ + public FibonacciHeap() + { + } // FibonacciHeap + + //~ Methods ---------------------------------------------------------------- + + /** + * Tests if the Fibonacci heap is empty or not. Returns true if the heap is + * empty, false otherwise. + * + *

    Running time: O(1) actual

    + * + * @return true if the heap is empty, false otherwise + */ + public boolean isEmpty() + { + return minNode == null; + } + + // isEmpty + + /** + * Removes all elements from this heap. + */ + public void clear() + { + minNode = null; + nNodes = 0; + } + + // clear + + /** + * Decreases the key value for a heap node, given the new value to take on. + * The structure of the heap may be changed and will not be consolidated. + * + *

    Running time: O(1) amortized

    + * + * @param x node to decrease the key of + * @param k new key value for node x + * + * @exception IllegalArgumentException Thrown if k is larger than x.key + * value. + */ + public void decreaseKey(FibonacciHeapNode x, double k) + { + if (k > x.key) { + throw new IllegalArgumentException( + "decreaseKey() got larger key value"); + } + + x.key = k; + + FibonacciHeapNode y = x.parent; + + if ((y != null) && (x.key < y.key)) { + cut(x, y); + cascadingCut(y); + } + + if (x.key < minNode.key) { + minNode = x; + } + } + + // decreaseKey + + /** + * 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. + * + *

    Running time: O(log n) amortized

    + * + * @param x node to remove from heap + */ + public void delete(FibonacciHeapNode x) + { + // make x as small as possible + decreaseKey(x, Double.NEGATIVE_INFINITY); + + // remove the smallest, which decreases n also + removeMin(); + } + + // delete + + /** + * 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. + * + *

    Running time: O(1) actual

    + * + * @param node new node to insert into heap + * @param key key value associated with data object + */ + public void insert(FibonacciHeapNode node, double key) + { + node.key = key; + + // concatenate node into min list + if (minNode != null) { + node.left = minNode; + node.right = minNode.right; + minNode.right = node; + node.right.left = node; + + if (key < minNode.key) { + minNode = node; + } + } else { + minNode = node; + } + + nNodes++; + } + + // insert + + /** + * Returns the smallest element in the heap. This smallest element is the + * one with the minimum key value. + * + *

    Running time: O(1) actual

    + * + * @return heap node with the smallest key + */ + public FibonacciHeapNode min() + { + return minNode; + } + + // min + + /** + * Removes the smallest element from the heap. This will cause the trees in + * the heap to be consolidated, if necessary. + * + *

    Running time: O(log n) amortized

    + * + * @return node with the smallest key + */ + public FibonacciHeapNode removeMin() + { + FibonacciHeapNode z = minNode; + + if (z != null) { + int numKids = z.degree; + FibonacciHeapNode x = z.child; + FibonacciHeapNode tempRight; + + // for each child of z do... + while (numKids > 0) { + tempRight = x.right; + + // remove x from child list + x.left.right = x.right; + x.right.left = x.left; + + // add x to root list of heap + x.left = minNode; + x.right = minNode.right; + minNode.right = x; + x.right.left = x; + + // set parent[x] to null + x.parent = null; + x = tempRight; + numKids--; + } + + // remove z from root list of heap + z.left.right = z.right; + z.right.left = z.left; + + if (z == z.right) { + minNode = null; + } else { + minNode = z.right; + consolidate(); + } + + // decrement size of heap + nNodes--; + } + + return z; + } + + // removeMin + + /** + * Returns the size of the heap which is measured in the number of elements + * contained in the heap. + * + *

    Running time: O(1) actual

    + * + * @return number of elements in the heap + */ + public int size() + { + return nNodes; + } + + // size + + /** + * Joins two Fibonacci heaps into a new one. No heap consolidation is + * performed at this time. The two root lists are simply joined together. + * + *

    Running time: O(1) actual

    + * + * @param h1 first heap + * @param h2 second heap + * + * @return new heap containing h1 and h2 + */ + public static FibonacciHeap union( + FibonacciHeap h1, + FibonacciHeap h2) + { + FibonacciHeap h = new FibonacciHeap(); + + if ((h1 != null) && (h2 != null)) { + h.minNode = h1.minNode; + + if (h.minNode != null) { + if (h2.minNode != null) { + h.minNode.right.left = h2.minNode.left; + h2.minNode.left.right = h.minNode.right; + h.minNode.right = h2.minNode; + h2.minNode.left = h.minNode; + + if (h2.minNode.key < h1.minNode.key) { + h.minNode = h2.minNode; + } + } + } else { + h.minNode = h2.minNode; + } + + h.nNodes = h1.nNodes + h2.nNodes; + } + + return h; + } + + // union + + /** + * Creates a String representation of this Fibonacci heap. + * + * @return String of this. + */ + public String toString() + { + if (minNode == null) { + return "FibonacciHeap=[]"; + } + + // create a new stack and put root on it + Stack> stack = new Stack>(); + stack.push(minNode); + + StringBuffer buf = new StringBuffer(512); + buf.append("FibonacciHeap=["); + + // do a simple breadth-first traversal on the tree + while (!stack.empty()) { + FibonacciHeapNode curr = stack.pop(); + buf.append(curr); + buf.append(", "); + + if (curr.child != null) { + stack.push(curr.child); + } + + FibonacciHeapNode start = curr; + curr = curr.right; + + while (curr != start) { + buf.append(curr); + buf.append(", "); + + if (curr.child != null) { + stack.push(curr.child); + } + + curr = curr.right; + } + } + + buf.append(']'); + + return buf.toString(); + } + + // toString + + /** + * Performs a cascading cut operation. This cuts y from its parent and then + * does the same for its parent, and so on up the tree. + * + *

    Running time: O(log n); O(1) excluding the recursion

    + * + * @param y node to perform cascading cut on + */ + protected void cascadingCut(FibonacciHeapNode y) + { + FibonacciHeapNode z = y.parent; + + // if there's a parent... + if (z != null) { + // if y is unmarked, set it marked + if (!y.mark) { + y.mark = true; + } else { + // it's marked, cut it from parent + cut(y, z); + + // cut its parent as well + cascadingCut(z); + } + } + } + + // cascadingCut + + protected void consolidate() + { + int arraySize = + ((int) Math.floor(Math.log(nNodes) * oneOverLogPhi)) + 1; + + List> array = + new ArrayList>(arraySize); + + // Initialize degree array + for (int i = 0; i < arraySize; i++) { + array.add(null); + } + + // Find the number of root nodes. + int numRoots = 0; + FibonacciHeapNode x = minNode; + + if (x != null) { + numRoots++; + x = x.right; + + while (x != minNode) { + numRoots++; + x = x.right; + } + } + + // For each node in root list do... + while (numRoots > 0) { + // Access this node's degree.. + int d = x.degree; + FibonacciHeapNode next = x.right; + + // ..and see if there's another of the same degree. + for (;;) { + FibonacciHeapNode y = array.get(d); + if (y == null) { + // Nope. + break; + } + + // There is, make one of the nodes a child of the other. + // Do this based on the key value. + if (x.key > y.key) { + FibonacciHeapNode temp = y; + y = x; + x = temp; + } + + // FibonacciHeapNode y disappears from root list. + link(y, x); + + // We've handled this degree, go to next one. + array.set(d, null); + d++; + } + + // Save this node for later when we might encounter another + // of the same degree. + array.set(d, x); + + // Move forward through list. + x = next; + numRoots--; + } + + // Set min to null (effectively losing the root list) and + // reconstruct the root list from the array entries in array[]. + minNode = null; + + for (int i = 0; i < arraySize; i++) { + FibonacciHeapNode y = array.get(i); + if (y == null) { + continue; + } + + // We've got a live one, add it to root list. + if (minNode != null) { + // First remove node from root list. + y.left.right = y.right; + y.right.left = y.left; + + // Now add to root list, again. + y.left = minNode; + y.right = minNode.right; + minNode.right = y; + y.right.left = y; + + // Check if this is a new min. + if (y.key < minNode.key) { + minNode = y; + } + } else { + minNode = y; + } + } + } + + // consolidate + + /** + * The reverse of the link operation: removes x from the child list of y. + * This method assumes that min is non-null. + * + *

    Running time: O(1)

    + * + * @param x child of y to be removed from y's child list + * @param y parent of x about to lose a child + */ + protected void cut(FibonacciHeapNode x, FibonacciHeapNode y) + { + // remove x from childlist of y and decrement degree[y] + x.left.right = x.right; + x.right.left = x.left; + y.degree--; + + // reset y.child if necessary + if (y.child == x) { + y.child = x.right; + } + + if (y.degree == 0) { + y.child = null; + } + + // add x to root list of heap + x.left = minNode; + x.right = minNode.right; + minNode.right = x; + x.right.left = x; + + // set parent[x] to nil + x.parent = null; + + // set mark[x] to false + x.mark = false; + } + + // cut + + /** + * Make node y a child of node x. + * + *

    Running time: O(1) actual

    + * + * @param y node to become child + * @param x node to become parent + */ + protected void link(FibonacciHeapNode y, FibonacciHeapNode x) + { + // remove y from root list of heap + y.left.right = y.right; + y.right.left = y.left; + + // make y a child of x + y.parent = x; + + if (x.child == null) { + x.child = y; + y.right = y; + y.left = y; + } else { + y.left = x.child; + y.right = x.child.right; + x.child.right = y; + y.right.left = y; + } + + // increase degree[x] + x.degree++; + + // set mark[y] false + y.mark = false; + } + + // link +} + +// FibonacciHeap diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/FibonacciHeapNode.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/FibonacciHeapNode.java new file mode 100644 index 00000000..4029618d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/FibonacciHeapNode.java @@ -0,0 +1,199 @@ +/* ========================================== + * JGraphT : a free Java graph-theory library + * ========================================== + * + * Project Info: http://jgrapht.sourceforge.net/ + * Project Creator: Barak Naveh (barak_naveh@users.sourceforge.net) + * + * (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. + */ +/* -------------------------- + * FibonnaciHeapNode.java + * -------------------------- + * (C) Copyright 1999-2008, by Nathan Fiedler and Contributors. + * + * Original Author: Nathan Fiedler + * Contributor(s): John V. Sichi + * + * $Id: FibonacciHeapNode.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Sept-2003 : Adapted from Nathan Fiedler (JVS); + * + * Name Date Description + * ---- ---- ----------- + * nf 08/31/97 Initial version + * nf 09/07/97 Removed FibHeapData interface + * nf 01/20/01 Added synchronization + * nf 01/21/01 Made Node an inner class + * nf 01/05/02 Added clear(), renamed empty() to + * isEmpty(), and renamed printHeap() + * to toString() + * nf 01/06/02 Removed all synchronization + * JVS 06/24/06 Generics + * + */ +package org.jgrapht.util; + +/** + * 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). + * + * @author Nathan Fiedler + */ +public class FibonacciHeapNode +{ + //~ Instance fields -------------------------------------------------------- + + /** + * Node data. + */ + T data; + + /** + * first child node + */ + FibonacciHeapNode child; + + /** + * left sibling node + */ + FibonacciHeapNode left; + + /** + * parent node + */ + FibonacciHeapNode parent; + + /** + * right sibling node + */ + FibonacciHeapNode right; + + /** + * true if this node has had a child removed since this node was added to + * its parent + */ + boolean mark; + + /** + * key value for this node + */ + double key; + + /** + * number of children of this node (does not count grandchildren) + */ + int degree; + + //~ Constructors ----------------------------------------------------------- + + /** + * Default constructor. Initializes the right and left pointers, making this + * a circular doubly-linked list. + * + * @param data data for this node + * @param key initial key for node + */ + public FibonacciHeapNode(T data, double key) + { + right = this; + left = this; + this.data = data; + this.key = key; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Obtain the key for this node. + * + * @return the key + */ + public final double getKey() + { + return key; + } + + /** + * Obtain the data for this node. + */ + public final T getData() + { + return data; + } + + /** + * Return the string representation of this object. + * + * @return string representing this object + */ + public String toString() + { + if (true) { + return Double.toString(key); + } else { + StringBuffer buf = new StringBuffer(); + buf.append("Node=[parent = "); + + if (parent != null) { + buf.append(Double.toString(parent.key)); + } else { + buf.append("---"); + } + + buf.append(", key = "); + buf.append(Double.toString(key)); + buf.append(", degree = "); + buf.append(Integer.toString(degree)); + buf.append(", right = "); + + if (right != null) { + buf.append(Double.toString(right.key)); + } else { + buf.append("---"); + } + + buf.append(", left = "); + + if (left != null) { + buf.append(Double.toString(left.key)); + } else { + buf.append("---"); + } + + buf.append(", child = "); + + if (child != null) { + buf.append(Double.toString(child.key)); + } else { + buf.append("---"); + } + + buf.append(']'); + + return buf.toString(); + } + } + + // toString +} + +// End FibonacciHeapNode.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/MathUtil.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/MathUtil.java new file mode 100644 index 00000000..29cce82c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/MathUtil.java @@ -0,0 +1,61 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * MathUtil.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: MathUtil.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.util; + +/** + * Math Utilities. Currently contains the following: + *
  • factorial(int N) - caclulate the factorial of N (aka N!) + * + * @author Assaf + * @since May 30, 2005 + */ +public class MathUtil +{ + //~ Methods ---------------------------------------------------------------- + + public static long factorial(int N) + { + long multi = 1; + for (int i = 1; i <= N; i++) { + multi = multi * i; + } + return multi; + } +} + +// End MathUtil.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/ModifiableInteger.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/ModifiableInteger.java new file mode 100644 index 00000000..69916fae --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/ModifiableInteger.java @@ -0,0 +1,285 @@ +/* ========================================== + * 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. + */ +/* ---------------------- + * ModifiableInteger.java + * ---------------------- + * + * (C) Copyright 2002-2004, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: ModifiableInteger.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 2004-05-27 : Initial version (BN); + * + */ +package org.jgrapht.util; + +/** + * The ModifiableInteger class wraps a value of the primitive type + * int in an object, similarly to {@link java.lang.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 + * {@link java.util.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 {@link java.util.Map} or as values in a {@link + * java.util.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.

    + * + * @author Barak Naveh + * @since May 27, 2004 + */ +public class ModifiableInteger + extends Number + implements Comparable +{ + //~ Static fields/initializers --------------------------------------------- + + private static final long serialVersionUID = 3618698612851422261L; + + //~ Instance fields -------------------------------------------------------- + + /** + * The int value represented by this ModifiableInteger. + */ + public int value; + + //~ Constructors ----------------------------------------------------------- + + /** + * !!! DON'T USE - Use the {@link #ModifiableInteger(int)} constructor + * instead !!! + * + *

    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.

    + * + * @deprecated not really deprecated, just marked so to avoid mistaken use. + */ + @Deprecated public ModifiableInteger() + { + } + + /** + * Constructs a newly allocated ModifiableInteger object that + * represents the specified int value. + * + * @param value the value to be represented by the + * ModifiableInteger object. + */ + public ModifiableInteger(int value) + { + this.value = value; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Sets a new value for this modifiable integer. + * + * @param value the new value to set. + */ + public void setValue(int value) + { + this.value = value; + } + + /** + * Returns the value of this object, similarly to {@link #intValue()}. This + * getter is NOT redundant. It is used for serialization by + * java.beans.XMLEncoder. + * + * @return the value. + */ + public int getValue() + { + return this.value; + } + + /** + * Adds one to the value of this modifiable integer. + */ + public void increment() + { + this.value++; + } + + /** + * Subtracts one from the value of this modifiable integer. + */ + public void decrement() + { + this.value--; + } + + /** + * Compares two ModifiableInteger objects numerically. + * + * @param anotherInteger the ModifiableInteger to be compared. + * + * @return 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). + */ + public int compareTo(ModifiableInteger anotherInteger) + { + int thisVal = this.value; + int anotherVal = anotherInteger.value; + + return (thisVal < anotherVal) ? -1 : ((thisVal == anotherVal) ? 0 : 1); + } + + /** + * 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). + * + * @param o the Object to be compared. + * + * @return 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 java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(Object o) + { + return compareTo((ModifiableInteger) o); + } + + /** + * @see Number#doubleValue() + */ + public double doubleValue() + { + return this.value; + } + + /** + * 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. + * + * @param o the object to compare with. + * + * @return true if the objects are the same; false + * otherwise. + */ + public boolean equals(Object o) + { + if (o instanceof ModifiableInteger) { + return this.value == ((ModifiableInteger) o).value; + } + + return false; + } + + /** + * @see Number#floatValue() + */ + public float floatValue() + { + return this.value; + } + + /** + * Returns a hash code for this ModifiableInteger. + * + * @return a hash code value for this object, equal to the primitive + * int value represented by this ModifiableInteger + * object. + */ + public int hashCode() + { + return this.value; + } + + /** + * @see Number#intValue() + */ + public int intValue() + { + return this.value; + } + + /** + * @see Number#longValue() + */ + public long longValue() + { + return this.value; + } + + /** + * Returns an Integer object representing this + * ModifiableInteger's value. + * + * @return an Integer representation of the value of this + * object. + */ + public Integer toInteger() + { + return Integer.valueOf(this.value); + } + + /** + * 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 {@link + * java.lang.Integer#toString(int)} method. + * + * @return a string representation of the value of this object in + * base 10. + */ + public String toString() + { + return String.valueOf(this.value); + } +} + +// End ModifiableInteger.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/PrefetchIterator.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/PrefetchIterator.java new file mode 100644 index 00000000..c7e7f3c4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/PrefetchIterator.java @@ -0,0 +1,223 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * PrefetchIterator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: PrefetchIterator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.util; + +import java.util.*; + + +/** + * 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();
    +        }
    +  }
    + * + * + * @author Assaf_Lehr + */ +public class PrefetchIterator + implements Iterator, + Enumeration +{ + //~ Instance fields -------------------------------------------------------- + + private NextElementFunctor innerEnum; + private E getNextLastResult; + private boolean isGetNextLastResultUpToDate = false; + private boolean endOfEnumerationReached = false; + private boolean flagIsEnumerationStartedEmpty = true; + private int innerFunctorUsageCounter = 0; + + //~ Constructors ----------------------------------------------------------- + + public PrefetchIterator(NextElementFunctor aEnum) + { + innerEnum = aEnum; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Serves as one contact place to the functor; all must use it and not + * directly the NextElementFunctor. + */ + private E getNextElementFromInnerFunctor() + { + innerFunctorUsageCounter++; + E result = this.innerEnum.nextElement(); + + // if we got here , an exception was not thrown, so at least + // one time a good value returned + flagIsEnumerationStartedEmpty = false; + return result; + } + + /** + * 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!) + */ + public E nextElement() + { + E result = null; + if (this.isGetNextLastResultUpToDate) { + result = this.getNextLastResult; + } else { + result = getNextElementFromInnerFunctor(); + } + + this.isGetNextLastResultUpToDate = false; + return result; + } + + /** + * If (isGetNextLastResultUpToDate==true) returns true else 1. calculates + * getNext() and saves it 2. sets isGetNextLastResultUpToDate to true. + */ + public boolean hasMoreElements() + { + if (endOfEnumerationReached) { + return false; + } + + if (isGetNextLastResultUpToDate) { + return true; + } else { + try { + this.getNextLastResult = getNextElementFromInnerFunctor(); + this.isGetNextLastResultUpToDate = true; + return true; + } catch (NoSuchElementException noSuchE) { + endOfEnumerationReached = true; + return false; + } + } // else + } // method + + /** + * 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)) + */ + public boolean isEnumerationStartedEmpty() + { + if (this.innerFunctorUsageCounter == 0) { + if (hasMoreElements()) { + return false; + } else { + return true; + } + } else // it is not the first time , so use the saved value + // which was initilaizeed during a call to + // getNextElementFromInnerFunctor + { + return flagIsEnumerationStartedEmpty; + } + } + + public boolean hasNext() + { + return this.hasMoreElements(); + } + + public E next() + { + return this.nextElement(); + } + + /** + * Always throws UnsupportedOperationException. + */ + public void remove() + throws UnsupportedOperationException + { + throw new UnsupportedOperationException(); + } + + //~ Inner Interfaces ------------------------------------------------------- + + public interface NextElementFunctor + { + /** + * You must implement that NoSuchElementException is thrown on + * nextElement() if it is out of bound. + */ + public EE nextElement() + throws NoSuchElementException; + } +} + +// End PrefetchIterator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/TypeUtil.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/TypeUtil.java new file mode 100644 index 00000000..bf4150b0 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/TypeUtil.java @@ -0,0 +1,67 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * TypeUtil.java + * ----------------- + * (C) Copyright 2006-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: TypeUtil.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 07-May-2006 : Initial version (JVS); + */ +package org.jgrapht.util; + +/** + * TypeUtil isolates type-unsafety so that code that which uses it for + * legitimate reasons can stay warning-free. + * + * @author John V. Sichi + */ +public class TypeUtil +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Casts an object to a type. + * + * @param o object to be cast + * @param typeDecl conveys the target type information; the actual value is + * unused and can be null since this is all just stupid compiler tricks + * + * @return the result of the cast + */ + @SuppressWarnings("unchecked") + public static T uncheckedCast(Object o, TypeUtil typeDecl) + { + return (T) o; + } +} + +// End TypeUtil.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/WeightCombiner.java b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/WeightCombiner.java new file mode 100644 index 00000000..525468b2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/WeightCombiner.java @@ -0,0 +1,78 @@ +package org.jgrapht.util; + +/** + * Binary operator for edge weights. There are some prewritten operators. + */ +public interface WeightCombiner +{ + //~ Instance fields -------------------------------------------------------- + + /** + * Sum of weights. + */ + public WeightCombiner SUM = + new WeightCombiner() { + public double combine(double a, double b) + { + return a + b; + } + }; + + /** + * Minimum weight. + */ + public WeightCombiner MIN = + new WeightCombiner() { + public double combine(double a, double b) + { + return Math.min(a, b); + } + }; + + /** + * Maximum weight. + */ + public WeightCombiner MAX = + new WeightCombiner() { + public double combine(double a, double b) + { + return Math.max(a, b); + } + }; + + /** + * First weight. + */ + public WeightCombiner FIRST = + new WeightCombiner() { + public double combine(double a, double b) + { + return a; + } + }; + + /** + * Second weight. + */ + public WeightCombiner SECOND = + new WeightCombiner() { + public double combine(double a, double b) + { + return b; + } + }; + + //~ Methods ---------------------------------------------------------------- + + /** + * Combines two weights. + * + * @param a first weight + * @param b second weight + * + * @return result of the operator + */ + double combine(double a, double b); +} + +// End WeightCombiner.java diff --git a/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/package.html b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/package.html new file mode 100644 index 00000000..15706d5d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/org/jgrapht/util/package.html @@ -0,0 +1,7 @@ + + + +Non-graph-specific data structures, algorithms, and utilities used by +JGraphT. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/src/overview.html b/ss2010/gdi2/java/libs/jgrapht/src/overview.html new file mode 100644 index 00000000..68542147 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/src/overview.html @@ -0,0 +1,12 @@ + + + +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. +

    +Visit http://jgrapht.sourceforge.net +to download and to get the latest info on JGraphT. + + diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/AllTests.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/AllTests.java new file mode 100644 index 00000000..fed25309 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/AllTests.java @@ -0,0 +1,123 @@ +/* ========================================== + * 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. + */ +/* ------------- + * AllTests.java + * ------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: AllTests.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.alg.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; +import org.jgrapht.traverse.*; +import org.jgrapht.util.*; + + +/** + * Runs all unit tests of the JGraphT library. + * + * @author Barak Naveh + */ +public final class AllTests +{ + //~ Constructors ----------------------------------------------------------- + + private AllTests() + { + } // ensure non-instantiability. + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates a test suite that includes all JGraphT tests. + * + * @return a test suite that includes all JGraphT tests. + */ + public static Test suite() + { + ExpandableTestSuite suite = + new ExpandableTestSuite("All tests of JGraphT"); + + suite.addTestSuit((TestSuite) AllAlgTests.suite()); + suite.addTestSuit((TestSuite) AllGenerateTests.suite()); + suite.addTestSuit((TestSuite) AllGraphTests.suite()); + suite.addTestSuit((TestSuite) AllTraverseTests.suite()); + suite.addTestSuit((TestSuite) AllUtilTests.suite()); + + return suite; + } + + //~ Inner Classes ---------------------------------------------------------- + + private static class ExpandableTestSuite + extends TestSuite + { + /** + * @see TestSuite#TestSuite() + */ + public ExpandableTestSuite() + { + super(); + } + + /** + * @see TestSuite#TestSuite(java.lang.String) + */ + public ExpandableTestSuite(String name) + { + super(name); + } + + /** + * Adds all the test from the specified suite into this suite. + * + * @param suite + */ + public void addTestSuit(TestSuite suite) + { + for (Enumeration e = suite.tests(); e.hasMoreElements();) { + Test t = (Test) e.nextElement(); + this.addTest(t); + } + } + } +} + +// End AllTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/EnhancedTestCase.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/EnhancedTestCase.java new file mode 100644 index 00000000..b3db6a05 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/EnhancedTestCase.java @@ -0,0 +1,91 @@ +/* ========================================== + * 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. + */ +/* --------------------- + * EnhancedTestCase.java + * --------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: EnhancedTestCase.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht; + +import junit.framework.*; + + +/** + * A little extension to JUnit's TestCase. + * + * @author Barak Naveh + * @since Jul 25, 2003 + */ +public abstract class EnhancedTestCase + extends TestCase +{ + //~ Constructors ----------------------------------------------------------- + + /** + * @see TestCase#TestCase() + */ + public EnhancedTestCase() + { + super(); + } + + /** + * @see TestCase#TestCase(java.lang.String) + */ + public EnhancedTestCase(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * It means: it's wrong that we got here. + */ + public void assertFalse() + { + assertTrue(false); + } + + /** + * It means: it's right that we got here. + */ + public void assertTrue() + { + assertTrue(true); + } +} + +// End EnhancedTestCase.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/AllAlgTests.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/AllAlgTests.java new file mode 100644 index 00000000..7a4f85a8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/AllAlgTests.java @@ -0,0 +1,96 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * AllAlgTests.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: AllAlgTests.java 683 2009-06-30 04:41:05Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht.alg; + +import junit.framework.*; + +import org.jgrapht.experimental.isomorphism.*; + + +/** + * A TestSuite for all tests in this package. + * + * @author Barak Naveh + */ +public final class AllAlgTests +{ + //~ Constructors ----------------------------------------------------------- + + private AllAlgTests() + { + } // ensure non-instantiability. + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates a test suite for all tests in this package. + * + * @return a test suite for all tests in this package. + */ + public static Test suite() + { + TestSuite suite = new TestSuite(); + + // $JUnit-BEGIN$ + suite.addTest(new TestSuite(ConnectivityInspectorTest.class)); + suite.addTest(new TestSuite(DijkstraShortestPathTest.class)); + suite.addTest(new TestSuite(BellmanFordShortestPathTest.class)); + suite.addTest(new TestSuite(FloydWarshallShortestPathsTest.class)); + suite.addTest(new TestSuite(VertexCoversTest.class)); + suite.addTest(new TestSuite(CycleDetectorTest.class)); + suite.addTest(new TestSuite(BronKerboschCliqueFinderTest.class)); + suite.addTest(new TestSuite(TransitiveClosureTest.class)); + suite.addTest(new TestSuite(BiconnectivityInspectorTest.class)); + suite.addTest(new TestSuite(BlockCutpointGraphTest.class)); + suite.addTest(new TestSuite(KShortestPathCostTest.class)); + suite.addTest(new TestSuite(KShortestPathKValuesTest.class)); + suite.addTest(new TestSuite(KSPExampleTest.class)); + suite.addTestSuite(IsomorphismInspectorTest.class); + suite.addTest(new TestSuite(EdmondsKarpMaximumFlowTest.class)); + suite.addTest(new TestSuite(ChromaticNumberTest.class)); + suite.addTest(new TestSuite(EulerianCircuitTest.class)); + suite.addTest(new TestSuite(HamiltonianCycleTest.class)); + + // $JUnit-END$ + return suite; + } +} + +// End AllAlgTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BellmanFordShortestPathTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BellmanFordShortestPathTest.java new file mode 100644 index 00000000..fddaf80a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BellmanFordShortestPathTest.java @@ -0,0 +1,131 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * BellmanFordShortestPathTest.java + * ------------------------------ + * (C) Copyright 2006-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: BellmanFordShortestPathTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 14-Jan-2006 : Initial revision (JVS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + */ +public class BellmanFordShortestPathTest + extends ShortestPathTestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testConstructor() + { + BellmanFordShortestPath path; + Graph g = create(); + + path = new BellmanFordShortestPath(g, V3); + + // find best path with no constraint on number of hops + assertEquals( + Arrays.asList( + new DefaultEdge[] { + e13, + e12, + e24, + e45 + }), + path.getPathEdgeList(V5)); + assertEquals(15.0, path.getCost(V5), 0); + + // find best path within 2 hops (less than optimal) + path = + new BellmanFordShortestPath( + g, + V3, + 2); + assertEquals( + Arrays.asList( + new DefaultEdge[] { + e34, + e45 + }), + path.getPathEdgeList(V5)); + assertEquals(25.0, path.getCost(V5), 0); + + // find best path within 1 hop (doesn't exist!) + path = + new BellmanFordShortestPath( + g, + V3, + 1); + assertNull(path.getPathEdgeList(V5)); + assertEquals(Double.POSITIVE_INFINITY, path.getCost(V5)); + } + + protected List findPathBetween( + Graph g, + String src, + String dest) + { + return BellmanFordShortestPath.findPathBetween(g, src, dest); + } + + public void testWithNegativeEdges() + { + Graph g = createWithBias(true); + + List path; + + path = findPathBetween(g, V1, V4); + assertEquals(Arrays.asList( + new DefaultEdge[] { + e13, + e34 + }), path); + + path = findPathBetween(g, V1, V5); + assertEquals(Arrays.asList(new DefaultEdge[] { e15 }), path); + } +} + +// End BellmanFordShortestPathTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BiconnectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BiconnectedGraph.java new file mode 100644 index 00000000..445c04f9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BiconnectedGraph.java @@ -0,0 +1,91 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * BiconnectedGraph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: BiconnectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class BiconnectedGraph + extends SimpleGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 6007460525580983710L; + + //~ Constructors ----------------------------------------------------------- + + public BiconnectedGraph() + { + super(DefaultEdge.class); + + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + addEdge("0", "1"); + addEdge("1", "2"); + addEdge("2", "3"); + addEdge("3", "4"); + addEdge("4", "5"); + addEdge("5", "0"); + } + + private void addVertices() + { + addVertex("0"); + addVertex("1"); + addVertex("2"); + addVertex("3"); + addVertex("4"); + addVertex("5"); + } +} + +// End BiconnectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BiconnectivityInspectorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BiconnectivityInspectorTest.java new file mode 100644 index 00000000..a104527a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BiconnectivityInspectorTest.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. + */ +/* ------------------------- + * BiconnectivityInspectorTest.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: BiconnectivityInspectorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class BiconnectivityInspectorTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testBiconnected() + { + BiconnectedGraph graph = new BiconnectedGraph(); + + BiconnectivityInspector inspector = new BiconnectivityInspector(graph); + + assertTrue(inspector.isBiconnected()); + assertEquals(0, inspector.getCutpoints().size()); + assertEquals(1, inspector.getBiconnectedVertexComponents().size()); + } + + public void testLinearGraph() + { + testLinearGraph(3); + testLinearGraph(5); + } + + public void testLinearGraph(int nbVertices) + { + UndirectedGraph graph = new SimpleGraph(DefaultEdge.class); + + LinearGraphGenerator generator = new LinearGraphGenerator(nbVertices); + generator.generateGraph( + graph, + new ClassBasedVertexFactory( + Object.class), + null); + + BiconnectivityInspector inspector = new BiconnectivityInspector(graph); + + assertEquals(nbVertices - 2, inspector.getCutpoints().size()); + assertEquals( + nbVertices - 1, + inspector.getBiconnectedVertexComponents().size()); + } + + public void testNotBiconnected() + { + NotBiconnectedGraph graph = new NotBiconnectedGraph(); + + BiconnectivityInspector inspector = new BiconnectivityInspector(graph); + + assertEquals(2, inspector.getCutpoints().size()); + assertEquals(3, inspector.getBiconnectedVertexComponents().size()); + } +} + +// End BiconnectivityInspectorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BlockCutpointGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BlockCutpointGraphTest.java new file mode 100644 index 00000000..8ebcc218 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BlockCutpointGraphTest.java @@ -0,0 +1,143 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * BlockCutpointGraphTest.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: BlockCutpointGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class BlockCutpointGraphTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testBiconnected() + { + BiconnectedGraph graph = new BiconnectedGraph(); + + BlockCutpointGraph blockCutpointGraph = new BlockCutpointGraph(graph); + testGetBlock(blockCutpointGraph); + + assertEquals(0, blockCutpointGraph.getCutpoints().size()); + int nbBiconnectedComponents = + blockCutpointGraph.vertexSet().size() + - blockCutpointGraph.getCutpoints().size(); + assertEquals(1, nbBiconnectedComponents); + } + + public void testGetBlock(BlockCutpointGraph blockCutpointGraph) + { + for ( + Iterator iter = blockCutpointGraph.vertexSet().iterator(); + iter.hasNext();) + { + UndirectedGraph component = (UndirectedGraph) iter.next(); + if (!component.edgeSet().isEmpty()) { + for ( + Iterator iterator = component.vertexSet().iterator(); + iterator.hasNext();) + { + Object vertex = iterator.next(); + if (!blockCutpointGraph.getCutpoints().contains(vertex)) { + assertEquals( + component, + blockCutpointGraph.getBlock(vertex)); + } + } + } else { + assertTrue( + blockCutpointGraph.getCutpoints().contains( + component.vertexSet().iterator().next())); + } + } + } + + public void testLinearGraph() + { + testLinearGraph(3); + testLinearGraph(5); + } + + public void testLinearGraph(int nbVertices) + { + UndirectedGraph graph = new SimpleGraph(DefaultEdge.class); + + LinearGraphGenerator generator = new LinearGraphGenerator(nbVertices); + generator.generateGraph( + graph, + new ClassBasedVertexFactory( + Object.class), + null); + + BlockCutpointGraph blockCutpointGraph = new BlockCutpointGraph(graph); + testGetBlock(blockCutpointGraph); + + assertEquals(nbVertices - 2, blockCutpointGraph.getCutpoints().size()); + int nbBiconnectedComponents = + blockCutpointGraph.vertexSet().size() + - blockCutpointGraph.getCutpoints().size(); + assertEquals(nbVertices - 1, nbBiconnectedComponents); + } + + public void testNotBiconnected() + { + UndirectedGraph graph = new NotBiconnectedGraph(); + + BlockCutpointGraph blockCutpointGraph = new BlockCutpointGraph(graph); + testGetBlock(blockCutpointGraph); + + assertEquals(2, blockCutpointGraph.getCutpoints().size()); + int nbBiconnectedComponents = + blockCutpointGraph.vertexSet().size() + - blockCutpointGraph.getCutpoints().size(); + assertEquals(3, nbBiconnectedComponents); + } +} + +// End BlockCutpointGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BronKerboschCliqueFinderTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BronKerboschCliqueFinderTest.java new file mode 100644 index 00000000..a41a5b0d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/BronKerboschCliqueFinderTest.java @@ -0,0 +1,179 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * BronKerboschCliqueFinderTest.java + * ------------------------------ + * (C) Copyright 2005-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: BronKerboschCliqueFinderTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 26-July-2005 : Initial revision (JVS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + */ +public class BronKerboschCliqueFinderTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + private static final String V4 = "v4"; + private static final String V5 = "v5"; + private static final String V6 = "v6"; + private static final String V7 = "v7"; + private static final String V8 = "v8"; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + * + * @param g + */ + public void createGraph(Graph g) + { + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + g.addVertex(V4); + g.addVertex(V5); + g.addVertex(V6); + g.addVertex(V7); + g.addVertex(V8); + + // biggest clique: { V1, V2, V3, V4 } + g.addEdge(V1, V2); + g.addEdge(V1, V3); + g.addEdge(V1, V4); + g.addEdge(V2, V3); + g.addEdge(V2, V4); + g.addEdge(V3, V4); + + // smaller clique: { V5, V6, V7 } + g.addEdge(V5, V6); + g.addEdge(V5, V7); + g.addEdge(V6, V7); + + // for fun, add an overlapping clique { V3, V4, V5 } + g.addEdge(V3, V5); + g.addEdge(V4, V5); + + // make V8 less lonely + g.addEdge(V7, V8); + } + + public void testFindBiggest() + { + SimpleGraph g = + new SimpleGraph(DefaultEdge.class); + createGraph(g); + + BronKerboschCliqueFinder finder = + new BronKerboschCliqueFinder(g); + + Collection> cliques = finder.getBiggestMaximalCliques(); + + assertEquals(1, cliques.size()); + + Set expected = new HashSet(); + expected.add(V1); + expected.add(V2); + expected.add(V3); + expected.add(V4); + + Set actual = cliques.iterator().next(); + + assertEquals(expected, actual); + } + + public void testFindAll() + { + SimpleGraph g = + new SimpleGraph(DefaultEdge.class); + createGraph(g); + + BronKerboschCliqueFinder finder = + new BronKerboschCliqueFinder(g); + + Collection> cliques = finder.getAllMaximalCliques(); + + assertEquals(4, cliques.size()); + + Set> expected = new HashSet>(); + + Set set = new HashSet(); + set.add(V1); + set.add(V2); + set.add(V3); + set.add(V4); + expected.add(set); + + set = new HashSet(); + set.add(V5); + set.add(V6); + set.add(V7); + expected.add(set); + + set = new HashSet(); + set.add(V3); + set.add(V4); + set.add(V5); + expected.add(set); + + set = new HashSet(); + set.add(V7); + set.add(V8); + expected.add(set); + + // convert result from Collection to Set because we don't want + // order to be significant + Set> actual = new HashSet>(cliques); + + assertEquals(expected, actual); + } +} + +// End BronKerboschCliqueFinderTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ChromaticNumberTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ChromaticNumberTest.java new file mode 100644 index 00000000..43576fbc --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ChromaticNumberTest.java @@ -0,0 +1,97 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * ChromaticNumberTest.java + * ------------------- + * (C) Copyright 2008-2008, by Andrew Newell and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: ChromaticNumberTest.java 652 2008-12-24 21:26:17Z perfecthash $ + * + * Changes + * ------- + * 24-Dec-2008 : Initial revision (AN); + * + */ +package org.jgrapht.alg; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Andrew Newell + */ +public class ChromaticNumberTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testChromaticNumber() + { + UndirectedGraph completeGraph = + new SimpleGraph( + DefaultEdge.class); + CompleteGraphGenerator completeGenerator = + new CompleteGraphGenerator( + 7); + completeGenerator.generateGraph( + completeGraph, + new ClassBasedVertexFactory(Object.class), + null); + + // A complete graph has a chromatic number equal to its order + assertEquals( + 7, + ChromaticNumber.findGreedyChromaticNumber(completeGraph)); + + UndirectedGraph linearGraph = + new SimpleGraph( + DefaultEdge.class); + LinearGraphGenerator linearGenerator = + new LinearGraphGenerator( + 50); + linearGenerator.generateGraph( + linearGraph, + new ClassBasedVertexFactory(Object.class), + null); + + // A linear graph is a tree, and a greedy algorithm for chromatic number + // can always find a 2-coloring + assertEquals(2, ChromaticNumber.findGreedyChromaticNumber(linearGraph)); + } +} + +// End ChromaticNumberTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ConnectivityInspectorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ConnectivityInspectorTest.java new file mode 100644 index 00000000..7a660dc2 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ConnectivityInspectorTest.java @@ -0,0 +1,377 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * ConnectivityInspectorTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): John V. Sichi + * + * $Id: ConnectivityInspectorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 07-Aug-2003 : Initial revision (BN); + * 20-Apr-2005 : Added StrongConnectivityInspector test (JVS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Barak Naveh + */ +public class ConnectivityInspectorTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + private static final String V4 = "v4"; + + //~ Instance fields -------------------------------------------------------- + + // + DefaultEdge e1; + DefaultEdge e2; + DefaultEdge e3; + DefaultEdge e3_b; + DefaultEdge u; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + * + * @return a graph + */ + public Pseudograph create() + { + Pseudograph g = + new Pseudograph(DefaultEdge.class); + + assertEquals(0, g.vertexSet().size()); + g.addVertex(V1); + assertEquals(1, g.vertexSet().size()); + g.addVertex(V2); + assertEquals(2, g.vertexSet().size()); + g.addVertex(V3); + assertEquals(3, g.vertexSet().size()); + g.addVertex(V4); + assertEquals(4, g.vertexSet().size()); + + assertEquals(0, g.edgeSet().size()); + + e1 = g.addEdge(V1, V2); + assertEquals(1, g.edgeSet().size()); + + e2 = g.addEdge(V2, V3); + assertEquals(2, g.edgeSet().size()); + + e3 = g.addEdge(V3, V1); + assertEquals(3, g.edgeSet().size()); + + e3_b = g.addEdge(V3, V1); + assertEquals(4, g.edgeSet().size()); + assertNotNull(e3_b); + + u = g.addEdge(V1, V1); + assertEquals(5, g.edgeSet().size()); + u = g.addEdge(V1, V1); + assertEquals(6, g.edgeSet().size()); + + return g; + } + + /** + * . + */ + public void testDirectedGraph() + { + ListenableDirectedGraph g = + new ListenableDirectedGraph( + DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + + g.addEdge(V1, V2); + + ConnectivityInspector inspector = + new ConnectivityInspector(g); + g.addGraphListener(inspector); + + assertEquals(false, inspector.isGraphConnected()); + + g.addEdge(V1, V3); + + assertEquals(true, inspector.isGraphConnected()); + } + + /** + * . + */ + public void testIsGraphConnected() + { + Pseudograph g = create(); + ConnectivityInspector inspector = + new ConnectivityInspector(g); + + assertEquals(false, inspector.isGraphConnected()); + + g.removeVertex(V4); + inspector = new ConnectivityInspector(g); + assertEquals(true, inspector.isGraphConnected()); + + g.removeVertex(V1); + assertEquals(1, g.edgeSet().size()); + + g.removeEdge(e2); + g.addEdge(V2, V2); + assertEquals(1, g.edgeSet().size()); + + inspector = new ConnectivityInspector(g); + assertEquals(false, inspector.isGraphConnected()); + } + + /** + * . + */ + public void testStronglyConnected1() + { + DirectedGraph g = + new DefaultDirectedGraph( + DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + g.addVertex(V4); + + g.addEdge(V1, V2); + g.addEdge(V2, V1); // strongly connected + + g.addEdge(V3, V4); // only weakly connected + + StrongConnectivityInspector inspector = + new StrongConnectivityInspector(g); + + // convert from List to Set because we need to ignore order + // during comparison + Set> actualSets = + new HashSet>(inspector.stronglyConnectedSets()); + + // construct the expected answer + Set> expectedSets = new HashSet>(); + Set set = new HashSet(); + set.add(V1); + set.add(V2); + expectedSets.add(set); + set = new HashSet(); + set.add(V3); + expectedSets.add(set); + set = new HashSet(); + set.add(V4); + expectedSets.add(set); + + assertEquals(expectedSets, actualSets); + + actualSets.clear(); + + List> subgraphs = + inspector.stronglyConnectedSubgraphs(); + for (DirectedSubgraph sg : subgraphs) { + actualSets.add(sg.vertexSet()); + + StrongConnectivityInspector ci = + new StrongConnectivityInspector(sg); + assertTrue(ci.isStronglyConnected()); + } + + assertEquals(expectedSets, actualSets); + } + + /** + * . + */ + public void testStronglyConnected2() + { + DirectedGraph g = + new DefaultDirectedGraph( + DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + g.addVertex(V4); + + g.addEdge(V1, V2); + g.addEdge(V2, V1); // strongly connected + + g.addEdge(V4, V3); // only weakly connected + g.addEdge(V3, V2); // only weakly connected + + StrongConnectivityInspector inspector = + new StrongConnectivityInspector(g); + + // convert from List to Set because we need to ignore order + // during comparison + Set> actualSets = + new HashSet>(inspector.stronglyConnectedSets()); + + // construct the expected answer + Set> expectedSets = new HashSet>(); + Set set = new HashSet(); + set.add(V1); + set.add(V2); + expectedSets.add(set); + set = new HashSet(); + set.add(V3); + expectedSets.add(set); + set = new HashSet(); + set.add(V4); + expectedSets.add(set); + + assertEquals(expectedSets, actualSets); + + actualSets.clear(); + + List> subgraphs = + inspector.stronglyConnectedSubgraphs(); + for (DirectedSubgraph sg : subgraphs) { + actualSets.add(sg.vertexSet()); + + StrongConnectivityInspector ci = + new StrongConnectivityInspector(sg); + assertTrue(ci.isStronglyConnected()); + } + + assertEquals(expectedSets, actualSets); + } + + /** + * . + */ + public void testStronglyConnected3() + { + DirectedGraph g = + new DefaultDirectedGraph( + DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + g.addVertex(V4); + + g.addEdge(V1, V2); + g.addEdge(V2, V3); + g.addEdge(V3, V1); // strongly connected + + g.addEdge(V1, V4); + g.addEdge(V2, V4); + g.addEdge(V3, V4); // weakly connected + + StrongConnectivityInspector inspector = + new StrongConnectivityInspector(g); + + // convert from List to Set because we need to ignore order + // during comparison + Set> actualSets = + new HashSet>(inspector.stronglyConnectedSets()); + + // construct the expected answer + Set> expectedSets = new HashSet>(); + Set set = new HashSet(); + set.add(V1); + set.add(V2); + set.add(V3); + expectedSets.add(set); + set = new HashSet(); + set.add(V4); + expectedSets.add(set); + + assertEquals(expectedSets, actualSets); + + actualSets.clear(); + + List> subgraphs = + inspector.stronglyConnectedSubgraphs(); + + for (DirectedSubgraph sg : subgraphs) { + actualSets.add(sg.vertexSet()); + + StrongConnectivityInspector ci = + new StrongConnectivityInspector(sg); + assertTrue(ci.isStronglyConnected()); + } + + assertEquals(expectedSets, actualSets); + } + + public void testStronglyConnected4() + { + DefaultDirectedGraph graph = + new DefaultDirectedGraph( + new EdgeFactory() { + public String createEdge(Integer from, Integer to) + { + return (from + "->" + to).intern(); + } + }); + + new RingGraphGenerator(3).generateGraph( + graph, + new VertexFactory() { + private int i = 0; + + public Integer createVertex() + { + return i++; + } + }, + null); + + StrongConnectivityInspector sc = + new StrongConnectivityInspector( + graph); + Set> expected = new HashSet>(); + expected.add(graph.vertexSet()); + assertEquals( + expected, + new HashSet>(sc.stronglyConnectedSets())); + } +} + +// End ConnectivityInspectorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/CycleDetectorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/CycleDetectorTest.java new file mode 100644 index 00000000..f1723704 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/CycleDetectorTest.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. + */ +/* ------------------------------ + * CycleDetectorTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): Khanh Vu + * + * $Id: CycleDetectorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 16-Sept-2004 : Initial revision (JVS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + */ +public class CycleDetectorTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + private static final String V4 = "v4"; + private static final String V5 = "v5"; + private static final String V6 = "v6"; + private static final String V7 = "v7"; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + * + * @param g + */ + public void createGraph(Graph g) + { + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + g.addVertex(V4); + g.addVertex(V5); + g.addVertex(V6); + g.addVertex(V7); + + g.addEdge(V1, V2); + g.addEdge(V2, V3); + g.addEdge(V3, V4); + g.addEdge(V4, V1); + g.addEdge(V4, V5); + g.addEdge(V5, V6); + g.addEdge(V1, V6); + + // test an edge which leads into a cycle, but where the source + // is not itself part of a cycle + g.addEdge(V7, V1); + } + + /** + * . + */ + public void testDirectedWithCycle() + { + DirectedGraph g = + new DefaultDirectedGraph( + DefaultEdge.class); + createGraph(g); + + Set cyclicSet = new HashSet(); + cyclicSet.add(V1); + cyclicSet.add(V2); + cyclicSet.add(V3); + cyclicSet.add(V4); + + Set acyclicSet = new HashSet(); + acyclicSet.add(V5); + acyclicSet.add(V6); + acyclicSet.add(V7); + + runTest(g, cyclicSet, acyclicSet); + } + + /** + * . + */ + public void testDirectedWithDoubledCycle() + { + DirectedGraph g = + new DefaultDirectedGraph( + DefaultEdge.class); + + // build the graph: vertex order is chosen specifically + // to exercise old bug-cases in CycleDetector + g.addVertex(V2); + g.addVertex(V1); + g.addVertex(V3); + + g.addEdge(V1, V2); + g.addEdge(V2, V3); + g.addEdge(V3, V1); + g.addEdge(V2, V1); + + Set cyclicSet = new HashSet(); + cyclicSet.add(V1); + cyclicSet.add(V2); + cyclicSet.add(V3); + + Set acyclicSet = new HashSet(); + + runTest(g, cyclicSet, acyclicSet); + } + + /** + * . + */ + @SuppressWarnings("unchecked") + public void testDirectedWithoutCycle() + { + DirectedGraph g = + new DefaultDirectedGraph( + DefaultEdge.class); + createGraph(g); + g.removeVertex(V2); + + Set cyclicSet = Collections.EMPTY_SET; // hb: I would like + // EMPTY_SET to be typed + // as well... + Set acyclicSet = g.vertexSet(); + + runTest(g, cyclicSet, acyclicSet); + } + + private void runTest( + DirectedGraph g, + Set cyclicSet, + Set acyclicSet) + { + CycleDetector detector = + new CycleDetector(g); + + Set emptySet = Collections.EMPTY_SET; + + assertEquals(!cyclicSet.isEmpty(), detector.detectCycles()); + + assertEquals(cyclicSet, detector.findCycles()); + + for (String v : cyclicSet) { + assertEquals(true, detector.detectCyclesContainingVertex(v)); + assertEquals(cyclicSet, detector.findCyclesContainingVertex(v)); + } + + for (String v : acyclicSet) { + assertEquals(false, detector.detectCyclesContainingVertex(v)); + assertEquals(emptySet, detector.findCyclesContainingVertex(v)); + } + } +} + +// End CycleDetectorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/DijkstraShortestPathTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/DijkstraShortestPathTest.java new file mode 100644 index 00000000..f73c403a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/DijkstraShortestPathTest.java @@ -0,0 +1,102 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * DijkstraShortestPathTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: DijkstraShortestPathTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Sept-2003 : Initial revision (JVS); + * 14-Jan-2006 : Factored out ShortestPathTestCase (JVS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + */ +public class DijkstraShortestPathTest + extends ShortestPathTestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testConstructor() + { + DijkstraShortestPath path; + Graph g = create(); + + path = + new DijkstraShortestPath( + g, + V3, + V4, + Double.POSITIVE_INFINITY); + assertEquals( + Arrays.asList( + new DefaultEdge[] { + e13, + e12, + e24 + }), + path.getPathEdgeList()); + assertEquals(10.0, path.getPathLength(), 0); + + path = + new DijkstraShortestPath( + g, + V3, + V4, + 7); + assertNull(path.getPathEdgeList()); + assertEquals(Double.POSITIVE_INFINITY, path.getPathLength(), 0); + } + + protected List findPathBetween( + Graph g, + String src, + String dest) + { + return DijkstraShortestPath.findPathBetween(g, src, dest); + } +} + +// End DijkstraShortestPathTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/EdmondsKarpMaximumFlowTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/EdmondsKarpMaximumFlowTest.java new file mode 100644 index 00000000..6a4d846c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/EdmondsKarpMaximumFlowTest.java @@ -0,0 +1,254 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EdmondsKarpMaximumFlowTest.java + * ----------------- + * (C) Copyright 2008-2008, by Ilya Razenshteyn and Contributors. + * + * Original Author: Ilya Razenshteyn + * Contributor(s): - + * + * $Id: EdmondsKarpMaximumFlowTest.java 628 2008-08-17 12:00:59Z ilyaraz $ + * + * Changes + * ------- + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.graph.*; + + +public final class EdmondsKarpMaximumFlowTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testCornerCases() + { + DirectedWeightedMultigraph simple = + new DirectedWeightedMultigraph( + DefaultWeightedEdge.class); + simple.addVertex(0); + simple.addVertex(1); + DefaultWeightedEdge e = simple.addEdge(0, 1); + try { + new EdmondsKarpMaximumFlow(null); + fail(); + } catch (NullPointerException ex) { + } + try { + new EdmondsKarpMaximumFlow( + simple, + -0.1); + fail(); + } catch (IllegalArgumentException ex) { + } + try { + simple.setEdgeWeight(e, -1.0); + new EdmondsKarpMaximumFlow(simple); + fail(); + } catch (IllegalArgumentException ex) { + } + try { + simple.setEdgeWeight(e, 1.0); + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow( + simple); + solver.calculateMaximumFlow(0, 1); + Map flow = solver.getMaximumFlow(); + flow.put(e, 25.0); + fail(); + } catch (UnsupportedOperationException ex) { + } + try { + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow( + simple); + solver.calculateMaximumFlow(2, 0); + fail(); + } catch (IllegalArgumentException ex) { + } + try { + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow( + simple); + solver.calculateMaximumFlow(1, 2); + fail(); + } catch (IllegalArgumentException ex) { + } + try { + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow( + simple); + solver.calculateMaximumFlow(0, 0); + fail(); + } catch (IllegalArgumentException ex) { + } + try { + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow( + simple); + solver.calculateMaximumFlow(null, 0); + fail(); + } catch (IllegalArgumentException ex) { + } + try { + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow( + simple); + solver.calculateMaximumFlow(0, null); + fail(); + } catch (IllegalArgumentException ex) { + } + } + + /** + * . + */ + public void testLogic() + { + runTest( + new int[] {}, + new int[] {}, + new double[] {}, + new int[] { 1 }, + new int[] { 4057218 }, + new double[] { 0.0 }); + runTest( + new int[] { 3, 1, 4, 3, 2, 8, 2, 5, 7 }, + new int[] { 1, 4, 8, 2, 8, 6, 5, 7, 6 }, + new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + new int[] { 3 }, + new int[] { 6 }, + new double[] { 2 }); + runTest( + new int[] { 5, 5, 5, 1, 1, 4, 2, 7, 8, 3 }, + new int[] { 1, 4, 2, 7, 8, 3, 8, 6, 6, 6 }, + new double[] { 7, 8, 573146, 31337, 1, 1, 1, 1, 2391717, 170239 }, + new int[] { 5 }, + new int[] { 6 }, + new double[] { 4.0 }); + runTest( + new int[] { 1, 1, 2, 2, 3 }, + new int[] { 2, 3, 3, 4, 4 }, + new double[] { + 1000000000.0, 1000000000.0, 1.0, 1000000000.0, 1000000000.0 + }, + new int[] { 1 }, + new int[] { 4 }, + new double[] { 2000000000.0 }); + } + + private void runTest( + int [] tails, + int [] heads, + double [] capacities, + int [] sources, + int [] sinks, + double [] expectedResults) + { + assertTrue(tails.length == heads.length); + assertTrue(tails.length == capacities.length); + DirectedWeightedMultigraph network = + new DirectedWeightedMultigraph( + DefaultWeightedEdge.class); + int m = tails.length; + for (int i = 0; i < m; i++) { + network.addVertex(tails[i]); + network.addVertex(heads[i]); + DefaultWeightedEdge e = network.addEdge(tails[i], heads[i]); + network.setEdgeWeight(e, capacities[i]); + } + assertTrue(sources.length == sinks.length); + int q = sources.length; + for (int i = 0; i < q; i++) { + network.addVertex(sources[i]); + network.addVertex(sinks[i]); + } + EdmondsKarpMaximumFlow solver = + new EdmondsKarpMaximumFlow(network); + assertTrue(solver.getCurrentSource() == null); + assertTrue(solver.getCurrentSink() == null); + assertTrue(solver.getMaximumFlowValue() == null); + assertTrue(solver.getMaximumFlow() == null); + for (int i = 0; i < q; i++) { + solver.calculateMaximumFlow(sources[i], sinks[i]); + assertTrue(solver.getCurrentSource().equals(sources[i])); + assertTrue(solver.getCurrentSink().equals(sinks[i])); + double flowValue = solver.getMaximumFlowValue(); + Map flow = solver.getMaximumFlow(); + assertEquals( + expectedResults[i], + flowValue, + EdmondsKarpMaximumFlow.DEFAULT_EPSILON); + for (DefaultWeightedEdge e : network.edgeSet()) { + assertTrue(flow.containsKey(e)); + } + for (DefaultWeightedEdge e : flow.keySet()) { + assertTrue(network.containsEdge(e)); + assertTrue( + flow.get(e) >= -EdmondsKarpMaximumFlow.DEFAULT_EPSILON); + assertTrue( + flow.get(e) + <= (network.getEdgeWeight(e) + + EdmondsKarpMaximumFlow.DEFAULT_EPSILON)); + } + for (Integer v : network.vertexSet()) { + double balance = 0.0; + for (DefaultWeightedEdge e : network.outgoingEdgesOf(v)) { + balance -= flow.get(e); + } + for (DefaultWeightedEdge e : network.incomingEdgesOf(v)) { + balance += flow.get(e); + } + if (v.equals(sources[i])) { + assertEquals( + -flowValue, + balance, + EdmondsKarpMaximumFlow.DEFAULT_EPSILON); + } else if (v.equals(sinks[i])) { + assertEquals( + flowValue, + balance, + EdmondsKarpMaximumFlow.DEFAULT_EPSILON); + } else { + assertEquals( + 0.0, + balance, + EdmondsKarpMaximumFlow.DEFAULT_EPSILON); + } + } + } + } +} + +// End EdmondsKarpMaximumFlowTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/EulerianCircuitTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/EulerianCircuitTest.java new file mode 100644 index 00000000..65bc8e2c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/EulerianCircuitTest.java @@ -0,0 +1,101 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * EulerianCircuitTest.java + * ------------------- + * (C) Copyright 2008-2008, by Andrew Newell and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: EulerianCircuitTest.java 652 2008-12-24 21:26:17Z perfecthash $ + * + * Changes + * ------- + * 24-Dec-2008 : Initial revision (AN); + * + */ +package org.jgrapht.alg; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Andrew Newell + */ +public class EulerianCircuitTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testEulerianCircuit() + { + UndirectedGraph completeGraph1 = + new SimpleGraph( + DefaultEdge.class); + CompleteGraphGenerator completeGenerator1 = + new CompleteGraphGenerator( + 6); + completeGenerator1.generateGraph( + completeGraph1, + new ClassBasedVertexFactory(Object.class), + null); + + // A complete graph of order 6 will have all vertices with degree 5 + // which is odd, therefore this graph is not Eulerian + assertFalse(EulerianCircuit.isEulerian(completeGraph1)); + assertTrue( + EulerianCircuit.getEulerianCircuitVertices(completeGraph1) == null); + + UndirectedGraph completeGraph2 = + new SimpleGraph( + DefaultEdge.class); + CompleteGraphGenerator completeGenerator2 = + new CompleteGraphGenerator( + 5); + completeGenerator2.generateGraph( + completeGraph2, + new ClassBasedVertexFactory(Object.class), + null); + assertTrue(EulerianCircuit.isEulerian(completeGraph2)); + + // There are 10 edges total in this graph, so an Eulerian circuit + // labeled by vertices should have 11 vertices + assertEquals( + 11, + EulerianCircuit.getEulerianCircuitVertices(completeGraph2).size()); + } +} + +// End EulerianCircuitTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/FloydWarshallShortestPathsTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/FloydWarshallShortestPathsTest.java new file mode 100644 index 00000000..5a4c7954 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/FloydWarshallShortestPathsTest.java @@ -0,0 +1,130 @@ +/* ========================================== + * 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-2009, 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. + */ +/* ------------------------- + * FloydWarshallShortestPathsTest.java + * ------------------------- + * (C) Copyright 2009-2009, by Tom Larkworthy and Contributors + * + * Original Author: Tom Larkworthy + * + * $Id: FloydWarshallShortestPathsTest.java 684 2009-06-30 04:42:22Z perfecthash $ + * + * Changes + * ------- + * 29-Jun-2009 : Initial revision (TL); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * @author Tom Larkworthy + * @version $Id: FloydWarshallShortestPathsTest.java 684 2009-06-30 04:42:22Z perfecthash $ + */ +public class FloydWarshallShortestPathsTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testCompareWithDijkstra() + { + RandomGraphGenerator gen = + new RandomGraphGenerator( + 10, + 15); + VertexFactory f = + new VertexFactory() { + int gid; + + public Integer createVertex() + { + return gid++; + } + }; + + for (int i = 0; i < 10; i++) { + SimpleDirectedGraph directed = + new SimpleDirectedGraph( + DefaultWeightedEdge.class); + + gen.generateGraph(directed, f, new HashMap()); + + // setup our shortest path measurer + FloydWarshallShortestPaths fw = + new FloydWarshallShortestPaths( + directed); + + for (Integer v1 : directed.vertexSet()) { + for (Integer v2 : directed.vertexSet()) { + double fwSp = fw.shortestDistance(v1, v2); + double dijSp = + new DijkstraShortestPath( + directed, + v1, + v2).getPathLength(); + assertTrue( + (Math.abs(dijSp - fwSp) < .01) + || (Double.isInfinite(fwSp) + && Double.isInfinite(dijSp))); + } + } + + SimpleGraph undirected = + new SimpleGraph( + DefaultWeightedEdge.class); + + gen.generateGraph(undirected, f, new HashMap()); + + // setup our shortest path measurer + fw = new FloydWarshallShortestPaths( + undirected); + + for (Integer v1 : undirected.vertexSet()) { + for (Integer v2 : undirected.vertexSet()) { + double fwSp = fw.shortestDistance(v1, v2); + double dijSp = + new DijkstraShortestPath( + undirected, + v1, + v2).getPathLength(); + assertTrue( + (Math.abs(dijSp - fwSp) < .01) + || (Double.isInfinite(fwSp) + && Double.isInfinite(dijSp))); + } + } + } + } +} + +// End FloydWarshallShortestPathsTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/HamiltonianCycleTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/HamiltonianCycleTest.java new file mode 100644 index 00000000..3ec78e04 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/HamiltonianCycleTest.java @@ -0,0 +1,95 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * HamiltonianCycleTest.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Andrew Newell + * Contributor(s): - + * + * $Id: HamiltonianCycleTest.java 681 2009-05-25 06:17:31Z perfecthash $ + * + * Changes + * ------- + * 17-Feb-2008 : Initial revision (AN); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Andrew Newell + */ +public class HamiltonianCycleTest + extends TestCase +{ + // ~ Methods + // ---------------------------------------------------------------- + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testHamiltonianCycle() + { + SimpleWeightedGraph completeGraph = + new SimpleWeightedGraph( + DefaultWeightedEdge.class); + CompleteGraphGenerator completeGraphGenerator = + new CompleteGraphGenerator( + 6); + completeGraphGenerator.generateGraph( + completeGraph, + new ClassBasedVertexFactory(Object.class), + null); + + assertTrue( + HamiltonianCycle.getApproximateOptimalForCompleteGraph( + completeGraph).size() == 6); + + List vertices = + new LinkedList(completeGraph.vertexSet()); + completeGraph.removeEdge( + completeGraph.getEdge(vertices.get(0), + vertices.get(1))); + + assertTrue( + HamiltonianCycle.getApproximateOptimalForCompleteGraph( + completeGraph) == null); + } +} + +// End HamiltonianCycleTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExample.png b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExample.png new file mode 100644 index 00000000..b81a2697 Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExample.png differ diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExampleGraph.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExampleGraph.java new file mode 100644 index 00000000..41e55bc6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExampleGraph.java @@ -0,0 +1,123 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KSPExampleGraph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KSPExampleGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 23-Sep-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * + */ +@SuppressWarnings("unchecked") +public class KSPExampleGraph + extends SimpleWeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = -1850978181764235655L; + + //~ Instance fields -------------------------------------------------------- + + public Object edgeAD; + + public Object edgeBT; + + public Object edgeCB; + + public Object edgeCT; + + public Object edgeDE; + + public Object edgeEC; + + public Object edgeSA; + + public Object edgeST; + + //~ Constructors ----------------------------------------------------------- + + /** + * + */ + public KSPExampleGraph() + { + super(DefaultWeightedEdge.class); + + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + this.edgeST = this.addEdge("S", "T"); + this.edgeSA = this.addEdge("S", "A"); + this.edgeAD = this.addEdge("A", "D"); + this.edgeDE = this.addEdge("D", "E"); + this.edgeEC = this.addEdge("E", "C"); + this.edgeCB = this.addEdge("C", "B"); + this.edgeCT = this.addEdge("C", "T"); + this.edgeBT = this.addEdge("B", "T"); + + setEdgeWeight(this.edgeST, 1); + setEdgeWeight(this.edgeSA, 100); + setEdgeWeight(this.edgeAD, 1); + setEdgeWeight(this.edgeDE, 1); + setEdgeWeight(this.edgeEC, 1); + setEdgeWeight(this.edgeCB, 1); + setEdgeWeight(this.edgeCT, 1); + setEdgeWeight(this.edgeBT, 1); + } + + private void addVertices() + { + addVertex("S"); + addVertex("T"); + addVertex("A"); + addVertex("B"); + addVertex("C"); + addVertex("D"); + addVertex("E"); + } +} + +// End KSPExampleGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExampleTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExampleTest.java new file mode 100644 index 00000000..358ef701 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KSPExampleTest.java @@ -0,0 +1,88 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KSPExampleTest.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KSPExampleTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 23-Sep-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import junit.framework.*; + +import org.jgrapht.graph.*; + + +@SuppressWarnings("unchecked") +public class KSPExampleTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testFourReturnedPathsJGraphT() + { + SimpleWeightedGraph graph = new KSPExampleGraph(); + + Object sourceVertex = "S"; + KShortestPaths ksp = new KShortestPaths(graph, sourceVertex, 4); + + Object targetVertex = "T"; + assertEquals(3, ksp.getPaths(targetVertex).size()); + } + + public void testThreeReturnedPathsJGraphT() + { + SimpleWeightedGraph graph = new KSPExampleGraph(); + + Object sourceVertex = "S"; + int nbPaths = 3; + KShortestPaths ksp = new KShortestPaths(graph, sourceVertex, nbPaths); + + Object targetVertex = "T"; + assertEquals(nbPaths, ksp.getPaths(targetVertex).size()); + } + + public void testTwoReturnedPathsJGraphT() + { + SimpleWeightedGraph graph = new KSPExampleGraph(); + + Object sourceVertex = "S"; + int nbPaths = 2; + KShortestPaths ksp = new KShortestPaths(graph, sourceVertex, nbPaths); + + Object targetVertex = "T"; + assertEquals(nbPaths, ksp.getPaths(targetVertex).size()); + } +} + +// End $file.name$ diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph4.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph4.java new file mode 100644 index 00000000..217bb421 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph4.java @@ -0,0 +1,109 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPathCompleteGraph4.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KShortestPathCompleteGraph4.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class KShortestPathCompleteGraph4 + extends SimpleWeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = -4091707260999013100L; + + //~ Instance fields -------------------------------------------------------- + + public Object e12; + + public Object e13; + + public Object e23; + + public Object eS1; + + public Object eS2; + + public Object eS3; + + //~ Constructors ----------------------------------------------------------- + + public KShortestPathCompleteGraph4() + { + super(DefaultWeightedEdge.class); + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + this.eS1 = addEdge("vS", "v1"); + this.eS2 = addEdge("vS", "v2"); + this.eS3 = addEdge("vS", "v3"); + this.e12 = addEdge("v1", "v2"); + this.e13 = addEdge("v1", "v3"); + this.e23 = addEdge("v2", "v3"); + + setEdgeWeight(this.eS1, 1.0); + setEdgeWeight(this.eS2, 1.0); + setEdgeWeight(this.eS3, 1000.0); + setEdgeWeight(this.e12, 1.0); + setEdgeWeight(this.e13, 1.0); + setEdgeWeight(this.e23, 1.0); + } + + private void addVertices() + { + addVertex("vS"); + addVertex("v1"); + addVertex("v2"); + addVertex("v3"); + } +} + +// End KShortestPathCompleteGraph4.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph5.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph5.java new file mode 100644 index 00000000..994ef4f3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph5.java @@ -0,0 +1,127 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPathCompleteGraph5.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KShortestPathCompleteGraph5.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class KShortestPathCompleteGraph5 + extends SimpleWeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = -3289497257289559394L; + + //~ Instance fields -------------------------------------------------------- + + public Object e12; + + public Object e13; + + public Object e14; + + public Object e23; + + public Object e24; + + public Object e34; + + public Object eS1; + + public Object eS2; + + public Object eS3; + + public Object eS4; + + //~ Constructors ----------------------------------------------------------- + + public KShortestPathCompleteGraph5() + { + super(DefaultWeightedEdge.class); + + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + this.eS1 = addEdge("vS", "v1"); + this.eS2 = addEdge("vS", "v2"); + this.eS3 = addEdge("vS", "v3"); + this.eS4 = addEdge("vS", "v4"); + this.e12 = addEdge("v1", "v2"); + this.e13 = addEdge("v1", "v3"); + this.e14 = addEdge("v1", "v4"); + this.e23 = addEdge("v2", "v3"); + this.e24 = addEdge("v2", "v4"); + this.e34 = addEdge("v3", "v4"); + + setEdgeWeight(this.eS1, 1.0); + setEdgeWeight(this.eS2, 1.0); + setEdgeWeight(this.eS3, 1.0); + setEdgeWeight(this.eS4, 1000.0); + setEdgeWeight(this.e12, 1.0); + setEdgeWeight(this.e13, 1.0); + setEdgeWeight(this.e14, 1.0); + setEdgeWeight(this.e23, 1.0); + setEdgeWeight(this.e24, 1.0); + setEdgeWeight(this.e34, 1.0); + } + + private void addVertices() + { + addVertex("vS"); + addVertex("v1"); + addVertex("v2"); + addVertex("v3"); + addVertex("v4"); + } +} + +// End KShortestPathCompleteGraph5.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph6.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph6.java new file mode 100644 index 00000000..24d0afb9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCompleteGraph6.java @@ -0,0 +1,156 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPathCompleteGraph6.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KShortestPathCompleteGraph6.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class KShortestPathCompleteGraph6 + extends SimpleWeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 6310990195071210970L; + + //~ Instance fields -------------------------------------------------------- + + public Object e12; + + public Object e13; + + public Object e14; + + public Object e23; + + public Object e24; + + public Object e34; + + public Object eS1; + + public Object eS2; + + public Object eS3; + + public Object eS4; + + private Object e15; + + private Object e25; + + private Object e35; + + private Object e45; + + private Object eS5; + + //~ Constructors ----------------------------------------------------------- + + public KShortestPathCompleteGraph6() + { + super(DefaultWeightedEdge.class); + + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + this.eS1 = this.addEdge("vS", "v1"); + this.eS2 = this.addEdge("vS", "v2"); + this.eS3 = this.addEdge("vS", "v3"); + this.eS4 = this.addEdge("vS", "v4"); + this.eS5 = this.addEdge("vS", "v5"); + + this.e12 = this.addEdge("v1", "v2"); + this.e13 = this.addEdge("v1", "v3"); + this.e14 = this.addEdge("v1", "v4"); + this.e15 = this.addEdge("v1", "v5"); + + this.e23 = this.addEdge("v2", "v3"); + this.e24 = this.addEdge("v2", "v4"); + this.e25 = this.addEdge("v2", "v5"); + + this.e34 = this.addEdge("v3", "v4"); + this.e35 = this.addEdge("v3", "v5"); + + this.e45 = this.addEdge("v4", "v5"); + + setEdgeWeight(this.eS1, 1.0); + setEdgeWeight(this.eS2, 1.0); + setEdgeWeight(this.eS3, 1.0); + setEdgeWeight(this.eS4, 1.0); + setEdgeWeight(this.eS5, 1000.0); + + setEdgeWeight(this.e12, 1.0); + setEdgeWeight(this.e13, 1.0); + setEdgeWeight(this.e14, 1.0); + setEdgeWeight(this.e15, 1.0); + + setEdgeWeight(this.e23, 1.0); + setEdgeWeight(this.e24, 1.0); + setEdgeWeight(this.e25, 1.0); + + setEdgeWeight(this.e34, 1.0); + setEdgeWeight(this.e35, 1.0); + + setEdgeWeight(this.e45, 1.0); + } + + private void addVertices() + { + addVertex("vS"); + addVertex("v1"); + addVertex("v2"); + addVertex("v3"); + addVertex("v4"); + addVertex("v5"); + } +} + +// End KShortestPathCompleteGraph6.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCostTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCostTest.java new file mode 100644 index 00000000..7374efc8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathCostTest.java @@ -0,0 +1,183 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPathCostTest.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KShortestPathCostTest.java 680 2009-05-25 05:55:31Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class KShortestPathCostTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testKShortestPathCompleteGraph4() + { + int nbPaths = 5; + + KShortestPathCompleteGraph4 graph = new KShortestPathCompleteGraph4(); + + KShortestPaths pathFinder = new KShortestPaths(graph, "vS", nbPaths); + List pathElements = pathFinder.getPaths("v3"); + + assertEquals( + "[[(vS : v1), (v1 : v3)], [(vS : v2), (v2 : v3)]," + + " [(vS : v2), (v1 : v2), (v1 : v3)], " + + "[(vS : v1), (v1 : v2), (v2 : v3)], " + + "[(vS : v3)]]", + pathElements.toString()); + + assertEquals(5, pathElements.size(), 0); + GraphPath pathElement = (GraphPath) pathElements.get(0); + assertEquals(2, pathElement.getWeight(), 0); + + assertEquals( + Arrays.asList(new Object[] { graph.eS1, graph.e13 }), + pathElement.getEdgeList()); + } + + public void testKShortestPathCosts(Graph graph) + { + int maxSize = 20; + + for ( + Iterator sourceIterator = graph.vertexSet().iterator(); + sourceIterator.hasNext();) + { + Object sourceVertex = sourceIterator.next(); + + for ( + Iterator targetIterator = graph.vertexSet().iterator(); + targetIterator.hasNext();) + { + Object targetVertex = targetIterator.next(); + + if (targetVertex != sourceVertex) { + KShortestPaths pathFinder = + new KShortestPaths(graph, + sourceVertex, maxSize); + + List pathElements = pathFinder.getPaths(targetVertex); + GraphPath pathElement = (GraphPath) pathElements.get(0); + double lastCost = pathElement.getWeight(); + for (int i = 0; i < pathElements.size(); i++) { + pathElement = (GraphPath) pathElements.get(i); + double cost = pathElement.getWeight(); + assertTrue(lastCost <= cost); + lastCost = cost; + } + assertTrue(pathElements.size() <= maxSize); + } + } + } + } + + public void testPicture1Graph() + { + Picture1Graph picture1Graph = new Picture1Graph(); + + int maxSize = 10; + + KShortestPaths pathFinder = + new KShortestPaths(picture1Graph, "vS", + maxSize); + + assertEquals(2, pathFinder.getPaths("v5").size()); + + List pathElements = pathFinder.getPaths("v5"); + GraphPath pathElement = (GraphPath) pathElements.get(0); + assertEquals( + Arrays.asList( + new Object[] { + picture1Graph.eS1, + picture1Graph.e15 + }), + pathElement.getEdgeList()); + + List vertices = Graphs.getPathVertexList(pathElement); + assertEquals( + Arrays.asList( + new Object[] { + "vS", + "v1", + "v5" + }), + vertices); + + pathElement = (GraphPath) pathElements.get(1); + assertEquals( + Arrays.asList( + new Object[] { + picture1Graph.eS2, + picture1Graph.e25 + }), + pathElement.getEdgeList()); + + vertices = Graphs.getPathVertexList(pathElement); + assertEquals( + Arrays.asList( + new Object[] { + "vS", + "v2", + "v5" + }), + vertices); + + pathElements = pathFinder.getPaths("v7"); + pathElement = (GraphPath) pathElements.get(0); + double lastCost = pathElement.getWeight(); + for (int i = 0; i < pathElements.size(); i++) { + pathElement = (GraphPath) pathElements.get(i); + double cost = pathElement.getWeight(); + + assertTrue(lastCost <= cost); + lastCost = cost; + } + } +} + +// End KShortestPathCostTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathKValuesTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathKValuesTest.java new file mode 100644 index 00000000..3b001070 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/KShortestPathKValuesTest.java @@ -0,0 +1,161 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * KShortestPathKValuesTest.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: KShortestPathKValuesTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class KShortestPathKValuesTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * @param n + * + * @return n!. + */ + public static int factorial(int n) + { + int factorial = 1; + for (int i = 1; i <= n; i++) { + factorial *= i; + } + return factorial; + } + + /** + * @param k + * @param n + * + * @return A(n,k). + */ + public static int permutation(int n, int k) + { + if (k <= n) { + return factorial(n) / factorial(n - k); + } else { + return 0; + } + } + + public void testMaxSizeValue() + { + KShortestPathCompleteGraph6 graph = new KShortestPathCompleteGraph6(); + + for ( + int maxSize = 1; + maxSize <= calculateNbElementaryPathsForCompleteGraph(6); + maxSize++) + { + KShortestPaths finder = new KShortestPaths(graph, "vS", maxSize); + + assertEquals(finder.getPaths("v1").size(), maxSize); + assertEquals(finder.getPaths("v2").size(), maxSize); + assertEquals(finder.getPaths("v3").size(), maxSize); + assertEquals(finder.getPaths("v4").size(), maxSize); + assertEquals(finder.getPaths("v5").size(), maxSize); + } + } + + public void testNbReturnedPaths() + { + KShortestPathCompleteGraph4 kSPCompleteGraph4 = + new KShortestPathCompleteGraph4(); + verifyNbPathsForAllVertices(kSPCompleteGraph4); + + KShortestPathCompleteGraph5 kSPCompleteGraph5 = + new KShortestPathCompleteGraph5(); + verifyNbPathsForAllVertices(kSPCompleteGraph5); + + KShortestPathCompleteGraph6 kSPCompleteGraph6 = + new KShortestPathCompleteGraph6(); + verifyNbPathsForAllVertices(kSPCompleteGraph6); + } + + private int calculateNbElementaryPathsForCompleteGraph(int n) + { + int nbPaths = 0; + for (int k = 1; k <= (n - 1); k++) { + nbPaths = nbPaths + permutation(n - 2, k - 1); + } + return nbPaths; + } + + private void verifyNbPathsForAllVertices(Graph graph) + { + int nbpaths = + calculateNbElementaryPathsForCompleteGraph( + graph.vertexSet().size()); + int maxSize = Integer.MAX_VALUE; + + for ( + Iterator sourceIterator = graph.vertexSet().iterator(); + sourceIterator.hasNext();) + { + Object sourceVertex = sourceIterator.next(); + + KShortestPaths finder = + new KShortestPaths(graph, sourceVertex, + maxSize); + for ( + Iterator targetIterator = graph.vertexSet().iterator(); + targetIterator.hasNext();) + { + Object targetVertex = targetIterator.next(); + if (targetVertex != sourceVertex) { + assertEquals( + finder.getPaths(targetVertex).size(), + nbpaths); + } + } + } + } +} + +// End KShortestPathKValuesTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/NeighborIndexTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/NeighborIndexTest.java new file mode 100644 index 00000000..d5f3d13b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/NeighborIndexTest.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. + */ +/* ------------------------------ + * NeighborIndexTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Charles Fry + * + * $Id: NeighborIndexTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 12-Dec-2005 : Initial revision (CF); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Charles Fry + */ +public class NeighborIndexTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + + //~ Methods ---------------------------------------------------------------- + + public void testNeighborSet() + { + ListenableUndirectedGraph g = + new ListenableUndirectedGraph( + DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + + g.addEdge(V1, V2); + + NeighborIndex index = + new NeighborIndex(g); + g.addGraphListener(index); + + Set neighbors1 = index.neighborsOf(V1); + + assertEquals(1, neighbors1.size()); + assertEquals(true, neighbors1.contains(V2)); + + g.addVertex(V3); + g.addEdge(V3, V1); + + Set neighbors3 = index.neighborsOf(V3); + + assertEquals(2, neighbors1.size()); + assertEquals(true, neighbors1.contains(V3)); + + assertEquals(1, neighbors3.size()); + assertEquals(true, neighbors3.contains(V1)); + + g.removeEdge(V3, V1); + + assertEquals(1, neighbors1.size()); + assertEquals(false, neighbors1.contains(V3)); + + assertEquals(0, neighbors3.size()); + + g.removeVertex(V2); + + assertEquals(0, neighbors1.size()); + } + + public void testDirectedNeighborSet() + { + ListenableDirectedGraph g = + new ListenableDirectedGraph( + DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + + g.addEdge(V1, V2); + + DirectedNeighborIndex index = + new DirectedNeighborIndex(g); + g.addGraphListener(index); + + Set p = index.predecessorsOf(V1); + Set s = index.successorsOf(V1); + + assertEquals(0, p.size()); + assertEquals(1, s.size()); + assertEquals(true, s.contains(V2)); + + g.addVertex(V3); + g.addEdge(V3, V1); + + Set q = index.successorsOf(V3); + + assertEquals(1, p.size()); + assertEquals(1, s.size()); + assertEquals(true, p.contains(V3)); + + assertEquals(1, q.size()); + assertEquals(true, q.contains(V1)); + + g.removeEdge(V3, V1); + + assertEquals(0, q.size()); + assertEquals(0, p.size()); + + g.removeVertex(V2); + + assertEquals(0, s.size()); + } +} + +// End NeighborIndexTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/NotBiconnectedGraph.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/NotBiconnectedGraph.java new file mode 100644 index 00000000..cb3dad8c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/NotBiconnectedGraph.java @@ -0,0 +1,91 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * NotBiconnectedGraph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: NotBiconnectedGraph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class NotBiconnectedGraph + extends SimpleGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 6518961051694377584L; + + //~ Constructors ----------------------------------------------------------- + + public NotBiconnectedGraph() + { + super(DefaultEdge.class); + + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + addEdge("0", "2"); + addEdge("0", "3"); + addEdge("3", "1"); + addEdge("1", "4"); + addEdge("4", "5"); + addEdge("5", "3"); + } + + private void addVertices() + { + addVertex("0"); + addVertex("1"); + addVertex("2"); + addVertex("3"); + addVertex("4"); + addVertex("5"); + } +} + +// End NotBiconnectedGraph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/Picture1.jpg b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/Picture1.jpg new file mode 100644 index 00000000..073f28b5 Binary files /dev/null and b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/Picture1.jpg differ diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/Picture1Graph.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/Picture1Graph.java new file mode 100644 index 00000000..f13403c3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/Picture1Graph.java @@ -0,0 +1,147 @@ +/* ========================================== + * 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. + */ +/* ------------------------- + * Picture1Graph.java + * ------------------------- + * (C) Copyright 2007-2008, by France Telecom + * + * Original Author: Guillaume Boulmier and Contributors. + * + * $Id: Picture1Graph.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 05-Jun-2007 : Initial revision (GB); + * + */ +package org.jgrapht.alg; + +import org.jgrapht.graph.*; + + +/** + * + * + * @author Guillaume Boulmier + * @since July 5, 2007 + */ +@SuppressWarnings("unchecked") +public class Picture1Graph + extends SimpleDirectedWeightedGraph +{ + //~ Static fields/initializers --------------------------------------------- + + /** + */ + private static final long serialVersionUID = 5587737522611531029L; + + //~ Instance fields -------------------------------------------------------- + + public Object e15; + + public Object e25; + + public Object e27; + + public Object e37; + + public Object e47; + + public Object e56; + + public Object e57; + + public Object e67; + + public Object eS1; + + public Object eS2; + + public Object eS3; + + public Object eS4; + + public Object eS7; + + //~ Constructors ----------------------------------------------------------- + + /** + * + */ + public Picture1Graph() + { + super(DefaultWeightedEdge.class); + + addVertices(); + addEdges(); + } + + //~ Methods ---------------------------------------------------------------- + + private void addEdges() + { + this.eS1 = this.addEdge("vS", "v1"); + this.eS2 = this.addEdge("vS", "v2"); + this.eS3 = this.addEdge("vS", "v3"); + this.eS4 = this.addEdge("vS", "v4"); + this.eS7 = this.addEdge("vS", "v7"); + this.e15 = this.addEdge("v1", "v5"); + this.e25 = this.addEdge("v2", "v5"); + this.e27 = this.addEdge("v2", "v7"); + this.e37 = this.addEdge("v3", "v7"); + this.e47 = this.addEdge("v4", "v7"); + this.e56 = this.addEdge("v5", "v6"); + this.e57 = this.addEdge("v5", "v7"); + this.e67 = this.addEdge("v6", "v7"); + + setEdgeWeight(this.eS1, 3.0); + setEdgeWeight(this.eS2, 2.0); + setEdgeWeight(this.eS3, 10.0); + setEdgeWeight(this.eS4, 15.0); + setEdgeWeight(this.eS7, 15.0); + setEdgeWeight(this.e15, 3.0); + setEdgeWeight(this.e25, 6.0); + setEdgeWeight(this.e27, 10.0); + setEdgeWeight(this.e37, 20.0); + setEdgeWeight(this.e47, 5.0); + setEdgeWeight(this.e56, -3.0); + setEdgeWeight(this.e57, 4.0); + setEdgeWeight(this.e67, 5.0); + } + + private void addVertices() + { + addVertex("vS"); + addVertex("v1"); + addVertex("v2"); + addVertex("v3"); + addVertex("v4"); + addVertex("v5"); + addVertex("v6"); + addVertex("v7"); + } +} + +// End Picture1Graph.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ShortestPathTestCase.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ShortestPathTestCase.java new file mode 100644 index 00000000..4e755647 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/ShortestPathTestCase.java @@ -0,0 +1,161 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * ShortestPathTestCase.java + * ------------------------------ + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: ShortestPathTestCase.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 14-Jan-2006 : Factored out of DijkstraShortestPathTest (JVS); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + */ +public abstract class ShortestPathTestCase + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + static final String V1 = "v1"; + static final String V2 = "v2"; + static final String V3 = "v3"; + static final String V4 = "v4"; + static final String V5 = "v5"; + + //~ Instance fields -------------------------------------------------------- + + DefaultWeightedEdge e12; + DefaultWeightedEdge e13; + DefaultWeightedEdge e15; + DefaultWeightedEdge e24; + DefaultWeightedEdge e34; + DefaultWeightedEdge e45; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testPathBetween() + { + List path; + Graph g = create(); + + path = findPathBetween(g, V1, V2); + assertEquals(Arrays.asList(new DefaultEdge[] { e12 }), path); + + path = findPathBetween(g, V1, V4); + assertEquals(Arrays.asList( + new DefaultEdge[] { + e12, + e24 + }), path); + + path = findPathBetween(g, V1, V5); + assertEquals(Arrays.asList( + new DefaultEdge[] { + e12, + e24, + e45 + }), path); + + path = findPathBetween(g, V3, V4); + assertEquals(Arrays.asList( + new DefaultEdge[] { + e13, + e12, + e24 + }), path); + } + + protected abstract List findPathBetween( + Graph g, + String src, + String dest); + + protected Graph create() + { + return createWithBias(false); + } + + protected Graph createWithBias( + boolean negate) + { + Graph g; + double bias = 1; + if (negate) { + // negative-weight edges are being tested, so only a directed graph + // makes sense + g = new SimpleDirectedWeightedGraph( + DefaultWeightedEdge.class); + bias = -1; + } else { + // by default, use an undirected graph + g = new SimpleWeightedGraph( + DefaultWeightedEdge.class); + } + + g.addVertex(V1); + g.addVertex(V2); + g.addVertex(V3); + g.addVertex(V4); + g.addVertex(V5); + + e12 = Graphs.addEdge(g, V1, V2, bias * 2); + + e13 = Graphs.addEdge(g, V1, V3, bias * 3); + + e24 = Graphs.addEdge(g, V2, V4, bias * 5); + + e34 = Graphs.addEdge(g, V3, V4, bias * 20); + + e45 = Graphs.addEdge(g, V4, V5, bias * 5); + + e15 = Graphs.addEdge(g, V1, V5, bias * 100); + + return g; + } +} + +// End ShortestPathTestCase.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/TransitiveClosureTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/TransitiveClosureTest.java new file mode 100644 index 00000000..54e2fd81 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/TransitiveClosureTest.java @@ -0,0 +1,120 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * TransitiveClosureTest.java + * ------------------------------ + * (C) Copyright 2007, by Vinayak R. Borkar. + * + * Original Author: Vinayak R. Borkar + * Contributor(s): + * + * Changes + * ------- + * 5-May-2007: Initial revision (VRB); + * + */ +package org.jgrapht.alg; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + */ +public class TransitiveClosureTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testLinearGraph() + { + SimpleDirectedGraph graph = + new SimpleDirectedGraph(DefaultEdge.class); + + int N = 10; + LinearGraphGenerator gen = + new LinearGraphGenerator(N); + + VertexFactory vf = + new VertexFactory() { + private int m_index = 0; + + public Integer createVertex() + { + return Integer.valueOf(m_index++); + } + }; + gen.generateGraph(graph, vf, null); + TransitiveClosure.INSTANCE.closeSimpleDirectedGraph(graph); + + assertEquals(true, graph.edgeSet().size() == ((N * (N - 1)) / 2)); + for (int i = 0; i < N; ++i) { + for (int j = i + 1; j < N; ++j) { + assertEquals( + true, + graph.getEdge(Integer.valueOf(i), Integer.valueOf(j)) + != null); + } + } + } + + public void testRingGraph() + { + SimpleDirectedGraph graph = + new SimpleDirectedGraph(DefaultEdge.class); + + int N = 10; + RingGraphGenerator gen = + new RingGraphGenerator(N); + + VertexFactory vf = + new VertexFactory() { + private int m_index = 0; + + public Integer createVertex() + { + return Integer.valueOf(m_index++); + } + }; + gen.generateGraph(graph, vf, null); + TransitiveClosure.INSTANCE.closeSimpleDirectedGraph(graph); + + assertEquals(true, graph.edgeSet().size() == (N * (N - 1))); + for (int i = 0; i < N; ++i) { + for (int j = 0; j < N; ++j) { + assertEquals( + true, + (i == j) + || (graph.getEdge(Integer.valueOf(i), Integer.valueOf(j)) + != null)); + } + } + } +} + +// End TransitiveClosureTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/VertexCoversTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/VertexCoversTest.java new file mode 100644 index 00000000..4f9cd0ca --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/alg/VertexCoversTest.java @@ -0,0 +1,151 @@ +/* ========================================== + * 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. + */ +/* --------------------- + * VertexCoversTest.java + * --------------------- + * (C) Copyright 2003-2008, by Linda Buisman and Contributors. + * + * Original Author: Linda Buisman + * Contributor(s): Barak Naveh + * + * $Id: VertexCoversTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Nov-2003 : Initial revision (LB); + * 10-Nov-2003 : Adapted to VertexCovers (BN); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Tests the vertex cover algorithms. + * + * @author Linda Buisman + * @since Nov 6, 2003 + */ +public class VertexCoversTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final int TEST_GRAPH_SIZE = 200; + private static final int TEST_REPEATS = 20; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testFind2ApproximationCover() + { + for (int i = 0; i < TEST_REPEATS; i++) { + Graph g = createRandomGraph(); + assertTrue( + isCover(VertexCovers.find2ApproximationCover(g), g)); + } + } + + /** + * . + */ + public void testFindGreedyCover() + { + for (int i = 0; i < TEST_REPEATS; i++) { + Graph g = createRandomGraph(); + Set c = + VertexCovers.findGreedyCover( + Graphs.undirectedGraph(g)); + assertTrue(isCover(c, g)); + } + } + + /** + * Checks if the specified vertex set covers every edge of the graph. Uses + * the definition of Vertex Cover - removes every edge that is incident on a + * vertex in vertexSet. If no edges are left, vertexSet is a vertex cover + * for the specified graph. + * + * @param vertexSet the vertices to be tested for covering the graph. + * @param g the graph to be covered. + * + * @return + */ + private boolean isCover( + Set vertexSet, + Graph g) + { + Set uncoveredEdges = new HashSet(g.edgeSet()); + + for (Iterator i = vertexSet.iterator(); i.hasNext();) { + uncoveredEdges.removeAll(g.edgesOf(i.next())); + } + + return uncoveredEdges.size() == 0; + } + + /** + * Create a random graph of TEST_GRAPH_SIZE nodes. + * + * @return + */ + private Graph createRandomGraph() + { + // TODO: move random graph generator to be under GraphGenerator + // framework. + Pseudograph g = + new Pseudograph(DefaultEdge.class); + + for (int i = 0; i < TEST_GRAPH_SIZE; i++) { + g.addVertex(new Integer(i)); + } + + List vertices = new ArrayList(g.vertexSet()); + + // join every vertex with a random number of other vertices + for (int source = 0; source < TEST_GRAPH_SIZE; source++) { + int numEdgesToCreate = + ((int) Math.random() * TEST_GRAPH_SIZE / 2) + 1; + + for (int j = 0; j < numEdgesToCreate; j++) { + // find a random vertex to join to + int target = (int) Math.floor(Math.random() * TEST_GRAPH_SIZE); + g.addEdge(vertices.get(source), vertices.get(target)); + } + } + + return g; + } +} + +// End VertexCoversTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/dag/DirectedAcyclicGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/dag/DirectedAcyclicGraphTest.java new file mode 100644 index 00000000..921337a9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/dag/DirectedAcyclicGraphTest.java @@ -0,0 +1,603 @@ +/* ========================================== + * 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. + */ +/* ------------------- + * DirectedAcyclicGraphTest.java + * ------------------- + * (C) Copyright 2008-2008, by Peter Giles and Contributors. + * + * Original Author: Peter Giles + * Contributor(s): - + * + * $Id: DirectedAcyclicGraphTest.java 637 2008-09-28 22:23:11Z perfecthash $ + * + * Changes + * ------- + * 17-Mar-2008 : Initial revision (PG); + * + */ +package org.jgrapht.experimental.dag; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.alg.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; +import org.jgrapht.traverse.*; + + +/** + * Unit tests for the DirectedAcyclicGraph, a dynamic DAG implementation. + * + * @author gilesp@u.washington.edu + */ +public class DirectedAcyclicGraphTest + extends TestCase +{ + //~ Instance fields -------------------------------------------------------- + + private RandomGraphGenerator randomGraphGenerator = null; + private Graph sourceGraph = null; + + //~ Methods ---------------------------------------------------------------- + + @Override protected void setUp() + throws Exception + { + super.setUp(); + + setUpWithSeed(100, 5000, 2); + } + + private void setUpWithSeed(int vertices, int edges, long seed) + { + randomGraphGenerator = + new RepeatableRandomGraphGenerator( + vertices, + edges, + seed); + sourceGraph = + new SimpleDirectedGraph(DefaultEdge.class); + randomGraphGenerator.generateGraph( + sourceGraph, + new LongVertexFactory(), + null); + } + + /** + * Tests the cycle detection capabilities of DirectedAcyclicGraph by + * building a parallel SimpleDirectedGraph and using a CycleDetector to + * check for cycles, and comparing the results. + */ + public void testCycleDetectionInRandomGraphBuild() + { + for (int i = 0; i < 50; i++) { // test with 50 random graph + // configurations + setUpWithSeed(20, 200, i); + + DirectedAcyclicGraph dag = + new DirectedAcyclicGraph(DefaultEdge.class); + SimpleDirectedGraph compareGraph = + new SimpleDirectedGraph(DefaultEdge.class); + + for (Long vertex : sourceGraph.vertexSet()) { + dag.addVertex(vertex); + compareGraph.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + boolean dagRejectedEdge = false; + try { + dag.addDagEdge(edgeSource, edgeTarget); + } catch (DirectedAcyclicGraph.CycleFoundException e) { + // okay, it did't add that edge + dagRejectedEdge = true; + } + + DefaultEdge compareEdge = + compareGraph.addEdge(edgeSource, edgeTarget); + CycleDetector cycleDetector = + new CycleDetector(compareGraph); + + boolean cycleDetected = cycleDetector.detectCycles(); + + assertTrue(dagRejectedEdge == cycleDetected); + + if (cycleDetected) { + // remove the edge from the compareGraph so the graphs + // remain in sync + compareGraph.removeEdge(compareEdge); + } + } + + // after all this, our graphs must be equal + assertEquals(compareGraph.vertexSet(), dag.vertexSet()); + + // for some reason comparing vertex sets doesn't work, so doing it + // the hard way: + for (Long sourceVertex : compareGraph.vertexSet()) { + for ( + DefaultEdge outgoingEdge + : compareGraph.outgoingEdgesOf(sourceVertex)) + { + Long targetVertex = + compareGraph.getEdgeTarget(outgoingEdge); + assertTrue(dag.containsEdge(sourceVertex, targetVertex)); + } + } + } + } + + /** + * trivial test of topological order using a linear graph + */ + public void testTopoIterationOrderLinearGraph() + { + DirectedAcyclicGraph dag = + new DirectedAcyclicGraph(DefaultEdge.class); + LinearGraphGenerator graphGen = + new LinearGraphGenerator(100); + graphGen.generateGraph(dag, new LongVertexFactory(), null); + + Iterator internalTopoIter = dag.iterator(); + TopologicalOrderIterator comparTopoIter = + new TopologicalOrderIterator(dag); + + while (comparTopoIter.hasNext()) { + Long compareNext = comparTopoIter.next(); + Long myNext = null; + + if (internalTopoIter.hasNext()) { + myNext = internalTopoIter.next(); + } + + assertSame(compareNext, myNext); + assertEquals(comparTopoIter.hasNext(), internalTopoIter.hasNext()); + } + } + + /** + * more rigorous test of topological iteration order, by assuring that each + * visited vertex adheres to the definition of topological order, that is + * that it doesn't have a path leading to any of its predecessors. + */ + public void testTopoIterationOrderComplexGraph() + { + for (int seed = 0; seed < 20; seed++) { + DirectedAcyclicGraph dag = + new DirectedAcyclicGraph(DefaultEdge.class); + RepeatableRandomGraphGenerator graphGen = + new RepeatableRandomGraphGenerator( + 100, + 500, + seed); + graphGen.generateGraph(dag, new LongVertexFactory(), null); + + ConnectivityInspector connectivityInspector = + new ConnectivityInspector(dag); + + Iterator internalTopoIter = dag.iterator(); + + List previousVertices = new ArrayList(); + + while (internalTopoIter.hasNext()) { + Long vertex = internalTopoIter.next(); + + for (Long previousVertex : previousVertices) { + connectivityInspector.pathExists(vertex, previousVertex); + } + + previousVertices.add(vertex); + } + } + } + + public void testIterationBehaviors() + { + int vertexCount = 100; + + DirectedAcyclicGraph dag = + new DirectedAcyclicGraph(DefaultEdge.class); + RepeatableRandomGraphGenerator graphGen = + new RepeatableRandomGraphGenerator( + vertexCount, + 500, + 2); + graphGen.generateGraph(dag, new LongVertexFactory(), null); + + Iterator dagIter = dag.iterator(); + + // Scroll through all the elements, then make sure things happen as + // should when an iterator is all used up + + for (int i = 0; i < vertexCount; i++) { + assertTrue(dagIter.hasNext()); + dagIter.next(); + } + assertFalse(dagIter.hasNext()); + + try { + dagIter.next(); + fail(); + } catch (NoSuchElementException e) { + // good, we already looked at all of the elements + } + + assertFalse(dagIter.hasNext()); + + dagIter = dag.iterator(); // replace dagIter; + + assertNotNull(dagIter.next()); // make sure it works on first element + // even if hasNext() wasn't called + + // Test that ConcurrentModificationExceptionS happen as they should when + // the topology is modified during iteration + + // remove a random vertex + dag.removeVertex(dag.vertexSet().iterator().next()); + + // now we expect exceptions since the topological order has been + // modified (albeit trivially) + try { + dagIter.next(); + fail(); // fail, no exception was thrown + } catch (ConcurrentModificationException e) { + // good, this is expected + } + + try { + dagIter.hasNext(); + fail(); // fail, no exception was thrown + } catch (ConcurrentModificationException e) { + // good, this is expected + } + + try { + dagIter.remove(); + fail(); // fail, no exception was thrown + } catch (ConcurrentModificationException e) { + // good, this is expected + } + + // TODO: further iterator tests + } + + // Performance tests have underscores in the names so that they + // they are only run explicitly (not automatically as part of + // default JUnit runs). + + /** + * A somewhat frivolous test of the performance difference between doing a + * full cycle detection (non-dynamic algorithm) for each edge added versus + * the dynamic algorithm used by DirectedAcyclicGraph. + */ + public void _testPerformanceVersusStaticChecking() + { + int trialsPerConfiguration = 10; + int maxVertices = 1024; + int maxConnectednessFactor = 4; + + for ( + int numVertices = 1024; + numVertices <= maxVertices; + numVertices *= 2) + { + for ( + int connectednessFactor = 1; + (connectednessFactor <= maxConnectednessFactor) + && (connectednessFactor < (numVertices - 1)); + connectednessFactor *= 2) + { + long dynamicDagTime = 0; + long staticDagTime = 0; + + for (int seed = 0; seed < trialsPerConfiguration; seed++) { // test with random graph configurations + setUpWithSeed( + numVertices, + numVertices * connectednessFactor, + seed); + + DirectedAcyclicGraph dag = + new DirectedAcyclicGraph( + DefaultEdge.class); + + long dynamicOpStart = System.nanoTime(); + + for (Long vertex : sourceGraph.vertexSet()) { + dag.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + dag.addEdge(edgeSource, edgeTarget); + } + + dynamicDagTime += System.nanoTime() - dynamicOpStart; + + SimpleDirectedGraph compareGraph = + new SimpleDirectedGraph( + DefaultEdge.class); + + long staticOpStart = System.nanoTime(); + + for (Long vertex : sourceGraph.vertexSet()) { + compareGraph.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + DefaultEdge compareEdge = + compareGraph.addEdge(edgeSource, edgeTarget); + CycleDetector cycleDetector = + new CycleDetector(compareGraph); + + boolean cycleDetected = cycleDetector.detectCycles(); + + if (cycleDetected) { + // remove the edge from the compareGraph + compareGraph.removeEdge(compareEdge); + } + } + + staticDagTime += System.nanoTime() - staticOpStart; + } + + System.out.println( + "vertices = " + numVertices + " connectednessFactor = " + + connectednessFactor + " trialsPerConfiguration = " + + trialsPerConfiguration); + System.out.println( + "total static DAG time = " + staticDagTime + " ns"); + System.out.println( + "total dynamic DAG time = " + dynamicDagTime + " ns"); + System.out.println(); + } + } + } + + /** + * A somewhat frivolous test of the performance difference between doing a + * full cycle detection (non-dynamic algorithm) for each edge added versus + * the dynamic algorithm used by DirectedAcyclicGraph. + */ + public void _testVisitedImplementationPerformance() + { + int trialsPerConfiguration = 10; + int maxVertices = 1024; + int maxConnectednessFactor = 4; + + for ( + int numVertices = 64; + numVertices <= maxVertices; + numVertices *= 2) + { + for ( + int connectednessFactor = 1; + (connectednessFactor <= maxConnectednessFactor) + && (connectednessFactor < (numVertices - 1)); + connectednessFactor *= 2) + { + long arrayDagTime = 0; + long arrayListDagTime = 0; + long hashSetDagTime = 0; + long bitSetDagTime = 0; + + for (int seed = 0; seed < trialsPerConfiguration; seed++) { // test with random graph configurations + setUpWithSeed( + numVertices, + numVertices * connectednessFactor, + seed); + + DirectedAcyclicGraph arrayDag = + new DirectedAcyclicGraph( + DefaultEdge.class, + new DirectedAcyclicGraph.VisitedArrayImpl(), + null); + DirectedAcyclicGraph arrayListDag = + new DirectedAcyclicGraph( + DefaultEdge.class, + new DirectedAcyclicGraph.VisitedArrayListImpl(), + null); + DirectedAcyclicGraph hashSetDag = + new DirectedAcyclicGraph( + DefaultEdge.class, + new DirectedAcyclicGraph.VisitedHashSetImpl(), + null); + DirectedAcyclicGraph bitSetDag = + new DirectedAcyclicGraph( + DefaultEdge.class, + new DirectedAcyclicGraph.VisitedBitSetImpl(), + null); + + long arrayStart = System.nanoTime(); + + for (Long vertex : sourceGraph.vertexSet()) { + arrayDag.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + try { + arrayDag.addDagEdge(edgeSource, edgeTarget); + } catch (DirectedAcyclicGraph.CycleFoundException e) { + // okay + } + } + + arrayDagTime += System.nanoTime() - arrayStart; + + long arrayListStart = System.nanoTime(); + + for (Long vertex : sourceGraph.vertexSet()) { + arrayListDag.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + try { + arrayListDag.addDagEdge(edgeSource, edgeTarget); + } catch (DirectedAcyclicGraph.CycleFoundException e) { + // okay + } + } + + arrayListDagTime += System.nanoTime() - arrayListStart; + + long hashSetStart = System.nanoTime(); + + for (Long vertex : sourceGraph.vertexSet()) { + hashSetDag.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + try { + hashSetDag.addDagEdge(edgeSource, edgeTarget); + } catch (DirectedAcyclicGraph.CycleFoundException e) { + // okay + } + } + + hashSetDagTime += System.nanoTime() - hashSetStart; + + long bitSetStart = System.nanoTime(); + + for (Long vertex : sourceGraph.vertexSet()) { + bitSetDag.addVertex(vertex); + } + + for (DefaultEdge edge : sourceGraph.edgeSet()) { + Long edgeSource = sourceGraph.getEdgeSource(edge); + Long edgeTarget = sourceGraph.getEdgeTarget(edge); + + try { + bitSetDag.addDagEdge(edgeSource, edgeTarget); + } catch (DirectedAcyclicGraph.CycleFoundException e) { + // okay + } + } + + bitSetDagTime += System.nanoTime() - bitSetStart; + } + + System.out.println( + "vertices = " + numVertices + " connectednessFactor = " + + connectednessFactor + " trialsPerConfiguration = " + + trialsPerConfiguration); + System.out.println( + "total array time = " + arrayDagTime + " ns"); + System.out.println( + "total ArrayList time = " + arrayListDagTime + " ns"); + System.out.println( + "total HashSet time = " + hashSetDagTime + " ns"); + System.out.println( + "total BitSet time = " + bitSetDagTime + " ns"); + System.out.println(); + } + } + } + + //~ Inner Classes ---------------------------------------------------------- + + private static class LongVertexFactory + implements VertexFactory + { + private long nextVertex = 0; + + public Long createVertex() + { + return nextVertex++; + } + } + + // it is nice for tests to be easily repeatable, so we use a graph generator + // that we can seed for specific configurations + private static class RepeatableRandomGraphGenerator + extends RandomGraphGenerator + { + public RepeatableRandomGraphGenerator( + int vertices, + int edges, + long seed) + { + super(vertices, edges); + randomizer = new Random(seed); + } + + @Override public void generateGraph( + Graph graph, + VertexFactory vertexFactory, + Map namedVerticesMap) + { + List vertices = new ArrayList(numOfVertexes); + Set edgeGeneratorIds = new HashSet(); + + for (int i = 0; i < numOfVertexes; i++) { + V vertex = vertexFactory.createVertex(); + vertices.add(vertex); + graph.addVertex(vertex); + } + + for (int i = 0; i < numOfEdges; i++) { + Integer edgeGeneratorId; + do { + edgeGeneratorId = + randomizer.nextInt(numOfVertexes * (numOfVertexes - 1)); + } while (edgeGeneratorIds.contains(edgeGeneratorId)); + + int fromVertexId = edgeGeneratorId / numOfVertexes; + int toVertexId = edgeGeneratorId % (numOfVertexes - 1); + if (toVertexId >= fromVertexId) { + ++toVertexId; + } + + try { + graph.addEdge( + vertices.get(fromVertexId), + vertices.get(toVertexId)); + } catch (IllegalArgumentException e) { + // okay, that's fine; omit cycle + } + } + } + } +} + +// End DirectedAcyclicGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/equivalence/EquivalenceGroupCreatorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/equivalence/EquivalenceGroupCreatorTest.java new file mode 100644 index 00000000..d1dcfa71 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/equivalence/EquivalenceGroupCreatorTest.java @@ -0,0 +1,170 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * EquivalenceGroupCreatorTest.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EquivalenceGroupCreatorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.equivalence; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.experimental.isomorphism.comparators.*; + + +/** + * @author Assaf + * @since Jul 22, 2005 + */ +public class EquivalenceGroupCreatorTest + extends TestCase +{ + //~ Instance fields -------------------------------------------------------- + + // create the groups array as 0 to X (it) + final int INTEGER_ARRAY_SIZE = 25; + + //~ Methods ---------------------------------------------------------------- + + /* + * @see TestCase#setUp() + */ + protected void setUp() + throws Exception + { + super.setUp(); + } + + public void testUniformGroup() + { + // expecting two seperate groups , one with odd , one with even nubmers" + testOneComparator(new UniformEquivalenceComparator(), 1); + + // " expecting 3 seperate groups , one for each mod3 + testOneComparator( + new org.jgrapht.experimental.isomorphism.comparators.Mod3GroupComparator(), + 3); + } + + public void testOddEvenGroup() + { + // " expecting two seperate groups , one with odd , one with even + // nubmers"); + testOneComparator( + new org.jgrapht.experimental.isomorphism.comparators.OddEvenGroupComparator(), + 2); + + // " expecting 3 seperate groups , one for each mod3"); + testOneComparator( + new org.jgrapht.experimental.isomorphism.comparators.Mod3GroupComparator(), + 3); + } + + /** + * Using a chain of evenOdd(mod2) and mod3 comparator , should yield the 6 + * groups , which are infact mod6 , examples: + *
  • mod2 = 0 , mod3 = 0 --> mod6=0 , like : 6 , 12 + *
  • mod2 = 1 , mod3 = 0 --> mod6=1 , like : 7 , 13 + *
  • + */ + public void testComparatorChain() + { + EquivalenceComparatorChain comparatorChain = + new EquivalenceComparatorChainBase( + new OddEvenGroupComparator()); + comparatorChain.appendComparator(new Mod3GroupComparator()); + + // for (int i=0 ; i integerArray = + new ArrayList(INTEGER_ARRAY_SIZE); + for (int i = 0; i < INTEGER_ARRAY_SIZE; i++) { + integerArray.add(i); + } + + EquivalenceSet [] eqGroupArray = + EquivalenceSetCreator.createEqualityGroupOrderedArray( + integerArray, + comparator, + null); + assertEquals(expectedNumOfGroups, eqGroupArray.length); + + // assert the group order size is sorted. + for (int i = 1; i < eqGroupArray.length; i++) { + EquivalenceSet set = eqGroupArray[i]; + assertTrue(set.size() >= eqGroupArray[i - 1].size()); + } + // System.out.println("\nTesting the EquivalenceSet[] returned from + // Integer[" + // +INTEGER_ARRAY_SIZE+"] filled with the integers as the indexes. \n" + // + expectedResult); + // System.out.println("result size="+eqGroupArray.length); + // for (int i = 0; i < eqGroupArray.length; i++) { + // System.out.println(eqGroupArray[i]); + // } + } +} + +// End EquivalenceGroupCreatorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/EdgeTopologyCompare.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/EdgeTopologyCompare.java new file mode 100644 index 00000000..f90a3944 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/EdgeTopologyCompare.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. + */ +/* ----------------- + * EdgeTopologyCompare.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: EdgeTopologyCompare.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import org.jgrapht.*; + + +/** + * @author Assaf + * @since Aug 6, 2005 + */ +public class EdgeTopologyCompare +{ + //~ Methods ---------------------------------------------------------------- + + /** + * Compare topology of the two graphs. It does not compare the contents of + * the vertexes/edges, but only the relationships between them. + * + * @param g1 + * @param g2 + */ + @SuppressWarnings("unchecked") + public static boolean compare(Graph g1, Graph g2) + { + boolean result = false; + GraphOrdering lg1 = new GraphOrdering(g1); + GraphOrdering lg2 = new GraphOrdering(g2); + result = lg1.equalsByEdgeOrder(lg2); + + return result; + } +} + +// End EdgeTopologyCompare.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/IntegerVertexFactory.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/IntegerVertexFactory.java new file mode 100644 index 00000000..8e27bafd --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/IntegerVertexFactory.java @@ -0,0 +1,87 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * IntegerVertexFactory.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: IntegerVertexFactory.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import org.jgrapht.*; + + +/** + * Implements createVertex() by producing a sequence of Integers; their values + * start with the successor to the constructor value. + * + *

    for example : IntegerVertexFactory(10); the first createVertex() will + * return Integer=11 + * + * @author Assaf + * @since May 25, 2005 + */ +public class IntegerVertexFactory + implements VertexFactory +{ + //~ Instance fields -------------------------------------------------------- + + private int counter; + + //~ Constructors ----------------------------------------------------------- + + /** + * Equivalent to IntegerVertexFactory(0); + * + * @author Assaf + * @since Aug 6, 2005 + */ + public IntegerVertexFactory() + { + this(0); + } + + public IntegerVertexFactory(int oneBeforeFirstValue) + { + this.counter = oneBeforeFirstValue; + } + + //~ Methods ---------------------------------------------------------------- + + public Integer createVertex() + { + this.counter++; + return new Integer(this.counter); + } +} + +// End IntegerVertexFactory.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/IsomorphismInspectorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/IsomorphismInspectorTest.java new file mode 100644 index 00000000..7dd86f59 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/IsomorphismInspectorTest.java @@ -0,0 +1,640 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * IsomorphismInspectorTest.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: IsomorphismInspectorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; +import org.jgrapht.experimental.isomorphism.comparators.*; +import org.jgrapht.generate.*; +import org.jgrapht.graph.*; + + +/** + * @author Assaf + * @since May 27, 2005 + */ +public class IsomorphismInspectorTest + extends TestCase +{ + //~ Constructors ----------------------------------------------------------- + + /** + * Constructor for IsomorphismInspectorTest. + * + * @param arg0 + */ + public IsomorphismInspectorTest(String arg0) + { + super(arg0); + } + + //~ Methods ---------------------------------------------------------------- + + /* + * @see TestCase#setUp() + */ + protected void setUp() + throws Exception + { + super.setUp(); + } + + /** + * Calls the same method with different (default) parameters + * EqualityGroupChecker vertexChecker = null EqualityGroupChecker + * edgeChecker = null + */ + private void assertIsomorphic( + Graph [] graphs, + boolean shouldTheyBeIsomorphic) + { + assertIsomorphic(graphs, shouldTheyBeIsomorphic, null, null); + } + + @SuppressWarnings("unchecked") + private void assertIsomorphic( + Graph [] graphs, + boolean shouldTheyBeIsomorphic, + EquivalenceComparator vertexChecker, + EquivalenceComparator edgeChecker) + { + // System.out.println("\nassertIsomorphic:"+shouldTheyBeIsomorphic); + Graph g1 = graphs[0]; + Graph g2 = graphs[1]; + + // System.out.println("g1:"+g1); + // System.out.println("g2:"+g2); + // long beforeTime=System.currentTimeMillis(); + GraphIsomorphismInspector iso = + AdaptiveIsomorphismInspectorFactory.createIsomorphismInspector( + g1, + g2, + vertexChecker, + edgeChecker); + int counter = 0; + while (iso.hasNext()) { + IsomorphismRelation isioResult = (IsomorphismRelation) iso.next(); + + if (false) { + if (counter == 0) { + System.out.println( + "Graphs are isomorphic. Iterating over all options:"); + } + System.out.println(counter + " : " + isioResult); + } + counter++; + } + + // if (counter==0) + // { + // System.out.println("Graphs are NOT isomorphic."); + // } + // long deltaTime=System.currentTimeMillis()-beforeTime; + // String timeDesc; + // timeDesc= deltaTime<=10 ? "<10ms [less than minimum measurement + // time]": String.valueOf(deltaTime); + // System.out.println("# Performence: Isomorphism check in + // MiliSeconds:"+timeDesc); + if (shouldTheyBeIsomorphic) { + assertTrue(counter != 0); + } else { + assertTrue(counter == 0); + } + } + + @SuppressWarnings("unchecked") + private void checkRelation( + Graph [] graphs, + EquivalenceComparator vertexChecker, + EquivalenceComparator edgeChecker) + { + Graph g1 = graphs[0]; + Graph g2 = graphs[1]; + + GraphIsomorphismInspector iso = + AdaptiveIsomorphismInspectorFactory.createIsomorphismInspector( + g1, + g2, + vertexChecker, + edgeChecker); + IsomorphismRelation isoResult; + if (iso.hasNext()) { + isoResult = (IsomorphismRelation) iso.next(); + + Set vertexSet = g1.vertexSet(); + for ( + Iterator iter = vertexSet.iterator(); + iter.hasNext();) + { + Integer v1 = iter.next(); + Integer v2 = isoResult.getVertexCorrespondence(v1, true); + if (false) { + System.out.println("Vertex relation " + v1 + " to " + v2); + } + } + Set edgeSet = g1.edgeSet(); + for ( + Iterator iter = edgeSet.iterator(); + iter.hasNext();) + { + DefaultEdge e1 = iter.next(); + DefaultEdge e2 = isoResult.getEdgeCorrespondence(e1, true); + if (false) { + System.out.println("Vertex relation " + e1 + " to " + e2); + } + } + + // if (counter==0) + // { + // System.out.println("Graphs are isomorphic. Iterating over all + // options:"); + // } + // System.out.println(counter+" : "+isioResult); + + } + } + + @SuppressWarnings("unchecked") + public void testWheelGraphAddRemoveParts() + { + final int NUM_OF_VERTEXES_IN_WHEEL = 6; + final int FIRST_INTEGER_FOR_G2 = 13; + + Graph g1 = + new DefaultDirectedGraph( + DefaultEdge.class); + Graph g2 = + new DefaultDirectedGraph( + DefaultEdge.class); + WheelGraphGenerator gen1 = + new WheelGraphGenerator( + NUM_OF_VERTEXES_IN_WHEEL); + gen1.generateGraph(g1, new IntegerVertexFactory(), null); + + // FIRST_INTEGER_FOR_G2-1 , cause first integer is always the next one. + gen1.generateGraph( + g2, + new IntegerVertexFactory(FIRST_INTEGER_FOR_G2), + null); + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + true); + + // In a wheel , the last vertex is the wheel center! + g1.removeVertex(new Integer(NUM_OF_VERTEXES_IN_WHEEL)); // delete one vertex from g1 + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + false); + + // for example: 10+4 + g2.removeVertex( + new Integer(FIRST_INTEGER_FOR_G2 + + NUM_OF_VERTEXES_IN_WHEEL)); + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + true); + + g1.removeEdge(new Integer(1), new Integer(2)); + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + false); + } + + @SuppressWarnings("unchecked") + public void testLinear4vertexIsomorphicGraph() + { + Graph g1 = + new DefaultDirectedGraph( + DefaultEdge.class); + LinearGraphGenerator gen1 = new LinearGraphGenerator(4); + gen1.generateGraph(g1, new IntegerVertexFactory(), null); + + Graph g2 = + new DefaultDirectedGraph( + DefaultEdge.class); + LinearGraphGenerator gen2 = new LinearGraphGenerator(4); + gen2.generateGraph(g2, new IntegerVertexFactory(5), null); // start vertex from number 6 + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + true); + + checkRelation( + new Graph[] { + g1, + g2 + }, + null, + null); + } + + /** + * Create two graphs which are topologically the same (same number of + * vertexes and same edges connection), but the contents of the vertexes + * belong to different eq. set. g1: 1-->2-->3-->4 g2: 2-->3-->4-->5 g3: + * 3-->4-->5-->6 The eq-group-check is if the number is even or odd. So, g1 + * and g3 are isomorphic. g2 is not isomorphic to either of them. + */ + @SuppressWarnings("unchecked") + public void testLinear4vertexNonIsomorphicCauseOfVertexEqGroup() + { + LinearGraphGenerator gen4 = + new LinearGraphGenerator(4); + + Graph g1 = + new DefaultDirectedGraph( + DefaultEdge.class); + gen4.generateGraph(g1, new IntegerVertexFactory(), null); + + Graph g2 = + new DefaultDirectedGraph( + DefaultEdge.class); + gen4.generateGraph(g2, new IntegerVertexFactory(1), null); // start vertex from number 2 + + Graph g3 = + new DefaultDirectedGraph( + DefaultEdge.class); + gen4.generateGraph(g3, new IntegerVertexFactory(2), null); // start vertex from number 3 + + // first assert all are isomorphic (if vertexChecker is not used) + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + true); + assertIsomorphic( + new Graph[] { + g2, + g3 + }, + true); + assertIsomorphic( + new Graph[] { + g1, + g3 + }, + true); + + // create a functor according to odd even + EquivalenceComparator vertexEqChecker = new OddEvenGroupComparator(); + assertIsomorphic( + new Graph[] { + g1, + g2 + }, + false, + vertexEqChecker, + null); + assertIsomorphic( + new Graph[] { + g2, + g3 + }, + false, + vertexEqChecker, + null); + assertIsomorphic( + new Graph[] { + g1, + g3 + }, + true, + vertexEqChecker, + null); + } + + /** + * Passes an EdgeComparator, which compares according to odd-even edge + * weight. The generated graphs are: A-(12)->B-(10)->C-(5)->D + * A-(10)->B-(18)->C-(3)->D A-(11)->B-(10)->C-(5)->D (the first here is odd) + * + * @author Assaf + * @since Aug 12, 2005 + */ + @SuppressWarnings("unchecked") + public void testEdgeComparator() + { + int LINEAR_GRAPH_VERTEX_NUM = 4; + Graph [] graphsArray = new DirectedGraph[3]; + Character [] charArray = + new Character[] { + new Character('A'), + new Character('B'), + new Character('C'), + new Character('D') + }; + int [][] weigthsArray = + new int[][] { + { + 12, + 10, + 5 + }, + { + 10, + 18, + 3 + }, + { + 11, + 10, + 5 + } + }; + + for (int i = 0; i < graphsArray.length; i++) { + Graph currGraph = + graphsArray[i] = + new DefaultDirectedWeightedGraph( + DefaultWeightedEdge.class); + for (int j = 0; j < LINEAR_GRAPH_VERTEX_NUM; j++) { + currGraph.addVertex(charArray[j]); + } + + // create the 3 edges with weights + for (int j = 0; j < 3; j++) { + Graphs.addEdge( + currGraph, + charArray[j], + charArray[j + 1], + weigthsArray[i][j]); + } + } + + // first assert all are isomorphic (if vertexChecker is not used) + assertIsomorphic(new Graph[] { graphsArray[0], graphsArray[1] }, + true); + assertIsomorphic(new Graph[] { graphsArray[0], graphsArray[2] }, + true); + assertIsomorphic(new Graph[] { graphsArray[1], graphsArray[2] }, + true); + + // create a functor according to odd even + EquivalenceComparator edgeEqChecker = + new DirectedEdgeWeightOddEvenComparator(graphsArray[0]); + assertIsomorphic( + new Graph[] { graphsArray[0], graphsArray[1] }, + true, + null, + edgeEqChecker); + assertIsomorphic( + new Graph[] { graphsArray[0], graphsArray[2] }, + false, + null, + edgeEqChecker); + assertIsomorphic( + new Graph[] { graphsArray[1], graphsArray[2] }, + false, + null, + edgeEqChecker); + } + + @SuppressWarnings("unchecked") + private void assertIsomorphicStopAfterFirstMatch( + Graph [] graphs, + boolean assertActive, + boolean shouldTheyBeIsomorphic, + EquivalenceComparator vertexChecker, + EquivalenceComparator edgeChecker) + { + if (assertActive) { + System.out.println("\nassertIsomorphic:" + + shouldTheyBeIsomorphic); + } + Graph g1 = graphs[0]; + Graph g2 = graphs[1]; + System.out.println("g1:" + g1); + System.out.println("g2:" + g2); + long beforeTime = System.currentTimeMillis(); + GraphIsomorphismInspector iso = + AdaptiveIsomorphismInspectorFactory.createIsomorphismInspector( + g1, + g2, + vertexChecker, + edgeChecker); + boolean isoResult = iso.isIsomorphic(); + if (isoResult) { + System.out.println("Graphs are isomorphic. "); + } else { + System.out.println("Graphs are NOT isomorphic."); + } + + long deltaTime = System.currentTimeMillis() - beforeTime; + String timeDesc; + timeDesc = + (deltaTime <= 10) ? "<10ms [less than minumun measurement time]" + : String.valueOf(deltaTime); + System.out.println( + "# Performence: Isomorphism check in MiliSeconds:" + timeDesc); + if (assertActive) { + assertEquals(shouldTheyBeIsomorphic, isoResult); + } + } + + /** + * Performance test with different number of vertex, edges. For each number + * pair, 3 graphs are generated. The first two, using the same generator, + * the third using a different generator. Note: the 1st and 2nd must be + * isomorphic. The 3rd will most likely not be isomorphic , but on special + * occasaions may be, so do not assert it. (example: empty graph, full mesh + * , rare case that they are not real random). NOTE: RENAME TO testXXX to + * make it work. It shows output and not assertions, so it cannot be used by + * automatic tests. + */ + @SuppressWarnings("unchecked") + public void performanceTestOnRandomGraphs() + throws Exception + { + final int [] numOfVertexesArray = + new int[] { + 6, + 6, + 6, + 8, + 8, + 8, + 10, + 10, + 10, + 12, + 14, + 20, + 30, + 99 + }; + final int [] numOfEdgesArray = + new int[] { + 0, + 4, + 12, + 1, + 15, + 54, + 0, + 40, + 90, + 130, + 50, + 79, + 30, + 234 + }; + + // there will be two different generators. The first will be used for + // 1st,2nd graph + // the other for the3rd graph + final int NUM_OF_GENERATORS = 2; + RandomGraphGenerator [] genArray = + new RandomGraphGenerator[NUM_OF_GENERATORS]; + + String [] graphConctereClassesFullName = + new String[] { // "org.jgrapht.graph.SimpleGraph" , + "org.jgrapht.graph.SimpleDirectedGraph", + "org.jgrapht.graph.DefaultDirectedGraph", + // "org.jgrapht.graph.Multigraph", + // "org.jgrapht.graph.Pseudograph" + }; + + // 3 graphs. 1st,2nd must be isomorphic .3rd probably not iso. + final int SIZE_OF_GENERATED_GRAPH_ARRAY = 3; + + // graphsArray rows are different graph types. Columns are few + // instances of that type + Graph [][] graphsArray = + new Graph[graphConctereClassesFullName.length][SIZE_OF_GENERATED_GRAPH_ARRAY]; + + Graph [] currIsoTestArray = new Graph[2]; + for (int testNum = 0; testNum < numOfVertexesArray.length; testNum++) { + // recreate the graphs (empty) + try { + for (int i = 0; i < graphConctereClassesFullName.length; i++) { + for (int j = 0; j < SIZE_OF_GENERATED_GRAPH_ARRAY; j++) { + graphsArray[i][j] = + (Graph) Class.forName( + graphConctereClassesFullName[i]).newInstance(); + } + } + } catch (Exception e) { + throw new Exception("failed to initilized the graphs", e); + } + + // create generators for the new vertex/edges number + for (int i = 0; i < genArray.length; i++) { + genArray[i] = + new RandomGraphGenerator( + numOfVertexesArray[testNum], + numOfEdgesArray[testNum]); + } + + for ( + int graphType = 0; + graphType < graphConctereClassesFullName.length; + graphType++) + { + System.out.println( + "### numOfVertexes= " + numOfVertexesArray[testNum]); + System.out.println( + "### numOfEdges= " + numOfEdgesArray[testNum]); + System.out.println( + "######### Graph Type:" + + graphConctereClassesFullName[graphType]); + System.out.println( + "# # # # # # # # # # # # # # # # # # # # # # # # # # # #"); + + // 1st and 2nd from genArray[0] + genArray[0].generateGraph( + graphsArray[graphType][0], + new IntegerVertexFactory(), + null); + genArray[0].generateGraph( + graphsArray[graphType][1], + new IntegerVertexFactory(), + null); + + // 3rd from genArray[1] + genArray[1].generateGraph( + graphsArray[graphType][2], + new IntegerVertexFactory(), + null); + + // now start testing + currIsoTestArray[0] = graphsArray[graphType][0]; + currIsoTestArray[1] = graphsArray[graphType][1]; + + assertIsomorphicStopAfterFirstMatch( + currIsoTestArray, + true, + true, + null, + null); + + // remember it is not a MUST - it can be true . DEGUG REASON + // ONLY , and with care + currIsoTestArray[1] = graphsArray[graphType][2]; + assertIsomorphicStopAfterFirstMatch( + currIsoTestArray, + false, + false, + null, + null); + } + } + } +} + +// End IsomorphismInspectorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/DirectedEdgeWeightOddEvenComparator.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/DirectedEdgeWeightOddEvenComparator.java new file mode 100644 index 00000000..87e66d3c --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/DirectedEdgeWeightOddEvenComparator.java @@ -0,0 +1,110 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * DirectedEdgeWeightOddEvenComparator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: DirectedEdgeWeightOddEvenComparator.java 489 2006-07-02 02:05:47Z + * perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism.comparators; + +import org.jgrapht.*; +import org.jgrapht.experimental.equivalence.*; + + +/** + * eq.set according to the weights of the edges. Uses Graph.getEdgeWeight(Edge) + * (cast to integer) and checks odd/even. + * + * @author Assaf + * @since Aug 12, 2005 + */ +public class DirectedEdgeWeightOddEvenComparator + implements EquivalenceComparator +{ + //~ Instance fields -------------------------------------------------------- + + private final Graph graph; + + //~ Constructors ----------------------------------------------------------- + + public DirectedEdgeWeightOddEvenComparator(Graph graph) + { + this.graph = graph; + } + + //~ Methods ---------------------------------------------------------------- + + /* (non-Javadoc) + * @see + * + * + * + * + * + * org.jgrapht.experimental.equivalence.EquivalenceComparator#equivalenceCompare(java.lang.Object, + * java.lang.Object, java.lang.Object, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public boolean equivalenceCompare( + Object arg1, + Object arg2, + Object context1, + Object context2) + { + int int1 = (int) graph.getEdgeWeight(arg1); + int int2 = (int) graph.getEdgeWeight(arg2); + + boolean result = ((int1 % 2) == (int2 % 2)); + return result; + } + + /* (non-Javadoc) + * @see + * + * + * + * + * + * org.jgrapht.experimental.equivalence.EquivalenceComparator#equivalenceHashcode(java.lang.Object, + * java.lang.Object) + */ + @SuppressWarnings("unchecked") + public int equivalenceHashcode(Object arg1, Object context) + { + int int1 = (int) graph.getEdgeWeight(arg1); + return int1 % 2; + } +} + +// End DirectedEdgeWeightOddEvenComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/Mod3GroupComparator.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/Mod3GroupComparator.java new file mode 100644 index 00000000..0ae4fed4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/Mod3GroupComparator.java @@ -0,0 +1,86 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * Mod3GroupComparator.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: Mod3GroupComparator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism.comparators; + +import org.jgrapht.experimental.equivalence.*; + + +/** + * Comparator which defines three groups of integers, according to mod3 result + *

  • mod3=0 , + *
  • mod3=1 + *
  • mod3=2 Works only on Integers. + * + * @author Assaf + * @since Jul 22, 2005 + */ +public class Mod3GroupComparator + implements EquivalenceComparator +{ + //~ Methods ---------------------------------------------------------------- + + public boolean equivalenceCompare( + Integer arg1, + Integer arg2, + Object context1, + Object context2) + { + int int1 = arg1.intValue(); + int int2 = arg2.intValue(); + + boolean result = ((int1 % 3) == (int2 % 3)); + return result; + } + + /* Each group must have unique values. + * @see + * + * + * + * + * + * org.jgrapht.experimental.equivalence.EquivalenceComparator#equivalenceHashcode(java.lang.Object) + */ + public int equivalenceHashcode(Integer arg1, Object context) + { + int int1 = arg1.intValue(); + return int1 % 3; + } +} + +// End Mod3GroupComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/OddEvenGroupComparator.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/OddEvenGroupComparator.java new file mode 100644 index 00000000..093df6a9 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/isomorphism/comparators/OddEvenGroupComparator.java @@ -0,0 +1,84 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * OddEvenGroupComparator.java + * ----------------- + * (C) Copyright 2005-2008, by Barak Naveh and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: OddEvenGroupComparator.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.isomorphism.comparators; + +import org.jgrapht.experimental.equivalence.*; + + +/** + * Comparator which defines two groups of integers. Odds (mod2=1) and + * Evens(mod2=0). Works only on Integers. + * + * @author Assaf + * @since Jul 22, 2005 + */ +public class OddEvenGroupComparator + implements EquivalenceComparator +{ + //~ Methods ---------------------------------------------------------------- + + public boolean equivalenceCompare( + Integer arg1, + Integer arg2, + Object context1, + Object context2) + { + int int1 = arg1.intValue(); + int int2 = arg2.intValue(); + + boolean result = ((int1 % 2) == (int2 % 2)); + return result; + } + + /* Odd and even must have unique values. + * @see + * + * + * + * + * + * org.jgrapht.experimental.equivalence.EquivalenceComparator#equivalenceHashcode(java.lang.Object) + */ + public int equivalenceHashcode(Integer arg1, Object context) + { + int int1 = arg1.intValue(); + return int1 % 2; + } +} + +// End OddEvenGroupComparator.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/permutation/CompoundPermutationIterTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/permutation/CompoundPermutationIterTest.java new file mode 100644 index 00000000..2706974f --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/experimental/permutation/CompoundPermutationIterTest.java @@ -0,0 +1,132 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * CompoundPermutationIterTest.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: CompoundPermutationIterTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.experimental.permutation; + +import java.util.*; + +import junit.framework.*; + + +/** + * @author Assaf + * @since May 30, 2005 + */ +public class CompoundPermutationIterTest + extends TestCase +{ + //~ Instance fields -------------------------------------------------------- + + private CompoundPermutationIter complexPerm; + + //~ Methods ---------------------------------------------------------------- + + /** + * Asserts that the number of permutations is the same as getMax. It also + * verifies that the number is the same when using different internal order + * of the permutation components. Note: The prints and timer can be unmarked + * to see performance results and the permutations array themselves. + */ + public void testGetNext() + { + // System.out.println("testing complex perm {1,1,1,2,2,3,4,5} "); + // StopperTimer timer = new StopperTimer(); + // timer.start(); + + this.complexPerm = + new CompoundPermutationIter( + new int[] { + 1, + 1, + 1, + 2, + 2, + 3, + 4, + 5 + }); + int maxPermNum = this.complexPerm.getMax(); + + // System.out.println(Arrays.toString(this.complexPerm.getPermAsArray())); + int counter = 0; + while (this.complexPerm.hasNext()) { + int [] resultArray = this.complexPerm.getNext(); + + if (false) { + System.out.println(Arrays.toString(resultArray)); + } + counter++; + } + + // System.out.println(counter); + assertEquals(maxPermNum, counter); + + // timer.stopAndReport(); + + // timer.start(); + this.complexPerm = + new CompoundPermutationIter( + new int[] { + 5, + 4, + 3, + 2, + 2, + 1, + 1, + 1 + }); + + // System.out.println("testing complex perm {5,4,3,2,2,1,1,1} "); + // System.out.println(Arrays.toString(this.complexPerm.getPermAsArray())); + counter = 0; + while (this.complexPerm.hasNext()) { + int [] resultArray = this.complexPerm.getNext(); + + if (false) { + System.out.println(Arrays.toString(resultArray)); + } + counter++; + } + + // System.out.println(counter); + assertEquals(maxPermNum, counter); + // timer.stopAndReport(); + } +} + +// End CompoundPermutationIterTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/DOTExporterTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/DOTExporterTest.java new file mode 100644 index 00000000..af4b4f46 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/DOTExporterTest.java @@ -0,0 +1,136 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * DOTExporterTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Trevor Harmon + */ +public class DOTExporterTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + + private static final String NL = System.getProperty("line.separator"); + + // TODO jvs 23-Dec-2006: externalized diff-based testing framework + + private static final String UNDIRECTED = + "graph G {" + NL + + " 1;" + NL + + " 2;" + NL + + " 3;" + NL + + " 1 -- 2;" + NL + + " 3 -- 1;" + NL + + "}" + NL; + + private static final DOTExporter exporter = + new DOTExporter(); + + //~ Methods ---------------------------------------------------------------- + + public void testUndirected() + { + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addEdge(V1, V2); + g.addVertex(V3); + g.addEdge(V3, V1); + + StringWriter w = new StringWriter(); + exporter.export(w, g); + assertEquals(UNDIRECTED, w.toString()); + } + + public void testValidNodeIDs() + { + DOTExporter exporter = + new DOTExporter( + new StringNameProvider(), + null, + null); + + List validVertices = + Arrays.asList( + "-9.78", + "-.5", + "12", + "a", + "12", + "abc_78", + "\"--34asdf\""); + for (String vertex : validVertices) { + Graph graph = + new DefaultDirectedGraph( + DefaultEdge.class); + graph.addVertex(vertex); + + exporter.export(new StringWriter(), graph); + } + + List invalidVertices = + Arrays.asList("2test", "--4", "foo-bar", "", "t:32"); + for (String vertex : invalidVertices) { + Graph graph = + new DefaultDirectedGraph( + DefaultEdge.class); + graph.addVertex(vertex); + + try { + exporter.export(new StringWriter(), graph); + Assert.fail(vertex); + } catch (RuntimeException re) { + // this is a negative test so exception is expected + } + } + } +} + +// End DOTExporterTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/GmlExporterTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/GmlExporterTest.java new file mode 100644 index 00000000..6ca334f4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/GmlExporterTest.java @@ -0,0 +1,121 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * GmlExporterTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: John V. Sichi + * + * $Id: GmlExporterTest.java 648 2008-12-19 04:10:28Z vocaro $ + * + * Changes + * ------- + * 23-Dec-2006 : Initial revision (JVS); + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + */ +public class GmlExporterTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + + private static final String NL = System.getProperty("line.separator"); + + // TODO jvs 23-Dec-2006: externalized diff-based testing framework + + private static final String UNDIRECTED = + "Creator \"JGraphT GML Exporter\"" + NL + + "Version 1" + NL + + "graph" + NL + + "[" + NL + + "\tlabel \"\"" + NL + + "\tdirected 0" + NL + + "\tnode" + NL + + "\t[" + NL + + "\t\tid 1" + NL + + "\t]" + NL + + "\tnode" + NL + + "\t[" + NL + + "\t\tid 2" + NL + + "\t]" + NL + + "\tnode" + NL + + "\t[" + NL + + "\t\tid 3" + NL + + "\t]" + NL + + "\tedge" + NL + + "\t[" + NL + + "\t\tid 1" + NL + + "\t\tsource 1" + NL + + "\t\ttarget 2" + NL + + "\t]" + NL + + "\tedge" + NL + + "\t[" + NL + + "\t\tid 2" + NL + + "\t\tsource 3" + NL + + "\t\ttarget 1" + NL + + "\t]" + NL + + "]" + NL; + + private static final GmlExporter exporter = + new GmlExporter(); + + //~ Methods ---------------------------------------------------------------- + + public void testUndirected() + { + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addEdge(V1, V2); + g.addVertex(V3); + g.addEdge(V3, V1); + + StringWriter w = new StringWriter(); + exporter.export(w, g); + assertEquals(UNDIRECTED, w.toString()); + } +} + +// End GmlExporterTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/GraphMLExporterTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/GraphMLExporterTest.java new file mode 100644 index 00000000..be4e7b29 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/GraphMLExporterTest.java @@ -0,0 +1,106 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * GraphMLExporterTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Trevor Harmon + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import junit.framework.*; + +import org.custommonkey.xmlunit.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Trevor Harmon + */ +public class GraphMLExporterTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + + private static final String NL = System.getProperty("line.separator"); + + // TODO jvs 23-Dec-2006: externalized diff-based testing framework + + private static final String UNDIRECTED = + "" + NL + + "" + + NL + + "" + NL + + "" + NL + + "" + NL + + "" + NL + + "" + NL + + "" + NL + + "" + NL + + "" + NL; + + private static final GraphMLExporter exporter = + new GraphMLExporter(); + + //~ Methods ---------------------------------------------------------------- + + public void testUndirected() + throws Exception + { + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addEdge(V1, V2); + g.addVertex(V3); + g.addEdge(V3, V1); + + StringWriter w = new StringWriter(); + exporter.export(w, g); + + if (System.getProperty("java.vm.version").startsWith("1.4")) { + // NOTE jvs 16-Mar-2007: XML prefix mapping comes out + // with missing info on 1.4, so skip the verification part + // of the test. + return; + } + + XMLAssert.assertXMLEqual(UNDIRECTED, w.toString()); + } +} + +// End GraphMLExporterTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/MatrixExporterTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/MatrixExporterTest.java new file mode 100644 index 00000000..028d649a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/ext/MatrixExporterTest.java @@ -0,0 +1,153 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * MatrixExporterTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Charles Fry + * + * $Id: MatrixExporterTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 12-Dec-2005 : Initial revision (CF); + * + */ +package org.jgrapht.ext; + +import java.io.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author Charles Fry + */ +public class MatrixExporterTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String V1 = "v1"; + private static final String V2 = "v2"; + private static final String V3 = "v3"; + + private static final String NL = System.getProperty("line.separator"); + + // TODO jvs 23-Dec-2006: externalized diff-based testing framework + + private static final String LAPLACIAN = + "1 1 2" + NL + + "1 2 -1" + NL + + "1 3 -1" + NL + + "2 2 1" + NL + + "2 1 -1" + NL + + "3 3 1" + NL + + "3 1 -1" + NL; + + private static final String NORMALIZED_LAPLACIAN = + "1 1 1" + NL + + "1 2 -0.7071067811865475" + NL + + "1 3 -0.7071067811865475" + NL + + "2 2 1" + NL + + "2 1 -0.7071067811865475" + NL + + "3 3 1" + NL + + "3 1 -0.7071067811865475" + NL; + + private static final String UNDIRECTED_ADJACENCY = + "1 2 1" + NL + + "1 3 1" + NL + + "1 1 2" + NL + + "2 1 1" + NL + + "3 1 1" + NL; + + private static final String DIRECTED_ADJACENCY = + "1 2 1" + NL + + "3 1 2" + NL; + + private static final MatrixExporter exporter = + new MatrixExporter(); + + //~ Methods ---------------------------------------------------------------- + + public void testLaplacian() + { + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addEdge(V1, V2); + g.addVertex(V3); + g.addEdge(V3, V1); + + StringWriter w = new StringWriter(); + exporter.exportLaplacianMatrix(w, g); + assertEquals(LAPLACIAN, w.toString()); + + w = new StringWriter(); + exporter.exportNormalizedLaplacianMatrix(w, g); + assertEquals(NORMALIZED_LAPLACIAN, w.toString()); + } + + public void testAdjacencyUndirected() + { + UndirectedGraph g = + new Pseudograph(DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addEdge(V1, V2); + g.addVertex(V3); + g.addEdge(V3, V1); + g.addEdge(V1, V1); + + StringWriter w = new StringWriter(); + exporter.exportAdjacencyMatrix(w, g); + assertEquals(UNDIRECTED_ADJACENCY, w.toString()); + } + + public void testAdjacencyDirected() + { + DirectedGraph g = + new DirectedMultigraph(DefaultEdge.class); + g.addVertex(V1); + g.addVertex(V2); + g.addEdge(V1, V2); + g.addVertex(V3); + g.addEdge(V3, V1); + g.addEdge(V3, V1); + + Writer w = new StringWriter(); + exporter.exportAdjacencyMatrix(w, g); + assertEquals(DIRECTED_ADJACENCY, w.toString()); + } +} + +// End MatrixExporterTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/AllGenerateTests.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/AllGenerateTests.java new file mode 100644 index 00000000..b242c8bc --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/AllGenerateTests.java @@ -0,0 +1,78 @@ +/* ========================================== + * 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. + */ +/* --------------------- + * AllGenerateTests.java + * --------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: AllGenerateTests.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht.generate; + +import junit.framework.*; + + +/** + * A TestSuite for all tests in this package. + * + * @author Barak Naveh + */ +public final class AllGenerateTests +{ + //~ Constructors ----------------------------------------------------------- + + private AllGenerateTests() + { + } // ensure non-instantiability. + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates a test suite for all tests in this package. + * + * @return a test suite for all tests in this package. + */ + public static Test suite() + { + TestSuite suite = new TestSuite(); + + // $JUnit-BEGIN$ + suite.addTest(new TestSuite(GraphGeneratorTest.class)); + suite.addTestSuite(RandomGraphGeneratorTest.class); + + // $JUnit-END$ + return suite; + } +} + +// End AllGenerateTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/GraphGeneratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/GraphGeneratorTest.java new file mode 100644 index 00000000..7d294d97 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/GraphGeneratorTest.java @@ -0,0 +1,295 @@ +/* ========================================== + * 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. + */ +/* ----------------------- + * GraphGeneratorTest.java + * ----------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: GraphGeneratorTest.java 680 2009-05-25 05:55:31Z perfecthash $ + * + * Changes + * ------- + * 17-Sep-2003 : Initial revision (JVS); + * 07-May-2006 : Changed from List to Set (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.alg.*; +import org.jgrapht.graph.*; + + +/** + * . + * + * @author John V. Sichi + * @since Sep 17, 2003 + */ +public class GraphGeneratorTest + extends TestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final int SIZE = 10; + + //~ Instance fields -------------------------------------------------------- + + private VertexFactory vertexFactory = + new VertexFactory() { + private int i; + + public Object createVertex() + { + return new Integer(++i); + } + }; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testEmptyGraphGenerator() + { + GraphGenerator gen = + new EmptyGraphGenerator(SIZE); + DirectedGraph g = + new DefaultDirectedGraph(DefaultEdge.class); + Map resultMap = new HashMap(); + gen.generateGraph(g, vertexFactory, resultMap); + assertEquals(SIZE, g.vertexSet().size()); + assertEquals(0, g.edgeSet().size()); + assertTrue(resultMap.isEmpty()); + } + + /** + * . + */ + public void testLinearGraphGenerator() + { + GraphGenerator gen = + new LinearGraphGenerator(SIZE); + DirectedGraph g = + new DefaultDirectedGraph(DefaultEdge.class); + Map resultMap = new HashMap(); + gen.generateGraph(g, vertexFactory, resultMap); + assertEquals(SIZE, g.vertexSet().size()); + assertEquals(SIZE - 1, g.edgeSet().size()); + + Object startVertex = resultMap.get(LinearGraphGenerator.START_VERTEX); + Object endVertex = resultMap.get(LinearGraphGenerator.END_VERTEX); + Iterator vertexIter = g.vertexSet().iterator(); + + while (vertexIter.hasNext()) { + Object vertex = vertexIter.next(); + + if (vertex == startVertex) { + assertEquals(0, g.inDegreeOf(vertex)); + assertEquals(1, g.outDegreeOf(vertex)); + + continue; + } + + if (vertex == endVertex) { + assertEquals(1, g.inDegreeOf(vertex)); + assertEquals(0, g.outDegreeOf(vertex)); + + continue; + } + + assertEquals(1, g.inDegreeOf(vertex)); + assertEquals(1, g.outDegreeOf(vertex)); + } + } + + /** + * . + */ + public void testRingGraphGenerator() + { + GraphGenerator gen = + new RingGraphGenerator(SIZE); + DirectedGraph g = + new DefaultDirectedGraph(DefaultEdge.class); + Map resultMap = new HashMap(); + gen.generateGraph(g, vertexFactory, resultMap); + assertEquals(SIZE, g.vertexSet().size()); + assertEquals(SIZE, g.edgeSet().size()); + + Object startVertex = g.vertexSet().iterator().next(); + assertEquals(1, g.outDegreeOf(startVertex)); + + Object nextVertex = startVertex; + Set seen = new HashSet(); + + for (int i = 0; i < SIZE; ++i) { + DefaultEdge nextEdge = + g.outgoingEdgesOf(nextVertex).iterator().next(); + nextVertex = g.getEdgeTarget(nextEdge); + assertEquals(1, g.inDegreeOf(nextVertex)); + assertEquals(1, g.outDegreeOf(nextVertex)); + assertTrue(!seen.contains(nextVertex)); + seen.add(nextVertex); + } + + // do you ever get the feeling you're going in circles? + assertTrue(nextVertex == startVertex); + assertTrue(resultMap.isEmpty()); + } + + /** + * . + */ + public void testCompleteGraphGenerator() + { + Graph completeGraph = + new SimpleGraph(DefaultEdge.class); + CompleteGraphGenerator completeGenerator = + new CompleteGraphGenerator(10); + completeGenerator.generateGraph( + completeGraph, + new ClassBasedVertexFactory(Object.class), + null); + + // complete graph with 10 vertices has 10*(10-1)/2 = 45 edges + assertEquals(45, completeGraph.edgeSet().size()); + } + + /** + * . + */ + public void testScaleFreeGraphGenerator() + { + DirectedGraph graph = + new DefaultDirectedGraph(DefaultEdge.class); + ScaleFreeGraphGenerator generator = + new ScaleFreeGraphGenerator(500); + generator.generateGraph(graph, vertexFactory, null); + ConnectivityInspector inspector = + new ConnectivityInspector(graph); + assertTrue( + "generated graph is not connected", + inspector.isGraphConnected()); + + try { + generator = new ScaleFreeGraphGenerator(-50); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + } + + try { + generator = + new ScaleFreeGraphGenerator(-50, 31337); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + } + + generator = new ScaleFreeGraphGenerator(0); + DirectedGraph empty = + new DefaultDirectedGraph(DefaultEdge.class); + generator.generateGraph(empty, vertexFactory, null); + assertTrue("non-empty graph generated", empty.vertexSet().size() == 0); + } + + /** + * . + */ + public void testCompleteBipartiteGraphGenerator() + { + Graph completeBipartiteGraph = + new SimpleGraph( + DefaultEdge.class); + CompleteBipartiteGraphGenerator completeBipartiteGenerator = + new CompleteBipartiteGraphGenerator( + 10, + 4); + completeBipartiteGenerator.generateGraph( + completeBipartiteGraph, + new ClassBasedVertexFactory(Object.class), + null); + + // Complete bipartite graph with 10 and 4 vertices should have 14 + // total vertices and 4*10=40 total edges + assertEquals(14, completeBipartiteGraph.vertexSet().size()); + assertEquals(40, completeBipartiteGraph.edgeSet().size()); + } + + /** + * . + */ + public void testHyperCubeGraphGenerator() + { + Graph hyperCubeGraph = + new SimpleGraph( + DefaultEdge.class); + HyperCubeGraphGenerator hyperCubeGenerator = + new HyperCubeGraphGenerator( + 4); + hyperCubeGenerator.generateGraph( + hyperCubeGraph, + new ClassBasedVertexFactory(Object.class), + null); + + // Hypercube of 4 dimensions should have 2^4=16 vertices and + // 4*2^(4-1)=32 total edges + assertEquals(16, hyperCubeGraph.vertexSet().size()); + assertEquals(32, hyperCubeGraph.edgeSet().size()); + } + + /** + * . + */ + public void testStarGraphGenerator() + { + Map map = new HashMap(); + Graph starGraph = + new SimpleGraph( + DefaultEdge.class); + StarGraphGenerator starGenerator = + new StarGraphGenerator( + 10); + starGenerator.generateGraph( + starGraph, + new ClassBasedVertexFactory(Object.class), + map); + + // Star graph of order 10 should have 10 vertices and 9 edges + assertEquals(9, starGraph.edgeSet().size()); + assertEquals(10, starGraph.vertexSet().size()); + assertTrue(map.get(StarGraphGenerator.CENTER_VERTEX) != null); + } + + // TODO: testWheelGraphGenerator +} + +// End GraphGeneratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/RandomGraphGeneratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/RandomGraphGeneratorTest.java new file mode 100644 index 00000000..779ef863 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/generate/RandomGraphGeneratorTest.java @@ -0,0 +1,136 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * RandomGraphGeneratorTest.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: RandomGraphGeneratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.generate; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.experimental.isomorphism.*; +import org.jgrapht.graph.*; + + +/** + * @author Assaf + * @since Aug 6, 2005 + */ +public class RandomGraphGeneratorTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testGenerateDirectedGraph() + { + List> graphArray = + new ArrayList>(); + for (int i = 0; i < 3; ++i) { + graphArray.add( + new SimpleDirectedGraph( + DefaultEdge.class)); + } + + generateGraphs(graphArray, 11, 100); + + assertTrue( + EdgeTopologyCompare.compare(graphArray.get(0), graphArray.get(1))); + // cannot assert false , cause it may be true once in a while (random) + // but it generally should work. + // assertFalse(EdgeTopologyCompare.compare(graphArray.get(1),graphArray.get(2))); + } + + public void testGenerateListenableUndirectedGraph() + { + List> graphArray = + new ArrayList>(); + for (int i = 0; i < 3; ++i) { + graphArray.add( + new ListenableUndirectedGraph( + DefaultEdge.class)); + } + + generateGraphs(graphArray, 11, 50); + + assertTrue( + EdgeTopologyCompare.compare(graphArray.get(0), graphArray.get(1))); + } + + /** + * Generates 3 graphs with the same numOfVertex and numOfEdges. The first + * two are generated using the same RandomGraphGenerator; the third is + * generated using a new instance. + * + * @param graphs array of graphs to generate + * @param numOfVertex number of vertices to generate per graph + * @param numOfEdges number of edges to generate per graph + */ + private static void generateGraphs( + List> graphs, + int numOfVertex, + int numOfEdges) + { + RandomGraphGenerator randomGen = + new RandomGraphGenerator( + numOfVertex, + numOfEdges); + + randomGen.generateGraph( + graphs.get(0), + new IntegerVertexFactory(), + null); + + // use the same randomGen + randomGen.generateGraph( + graphs.get(1), + new IntegerVertexFactory(), + null); + + // use new randomGen here + RandomGraphGenerator newRandomGen = + new RandomGraphGenerator( + numOfVertex, + numOfEdges); + + newRandomGen.generateGraph( + graphs.get(2), + new IntegerVertexFactory(), + null); + } +} + +// End RandomGraphGeneratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AllGraphTests.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AllGraphTests.java new file mode 100644 index 00000000..e4945a7b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AllGraphTests.java @@ -0,0 +1,85 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * AllGraphTests.java + * ----------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: AllGraphTests.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Aug-2003 : Initial revision (BN); + * + */ +package org.jgrapht.graph; + +import junit.framework.*; + + +/** + * A TestSuite for all tests in this package. + * + * @author Barak Naveh + * @since Aug 3, 2003 + */ +public final class AllGraphTests +{ + //~ Constructors ----------------------------------------------------------- + + private AllGraphTests() + { + } // ensure non-instantiability. + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates a test suite for all tests in this package. + * + * @return a test suite for all tests in this package. + */ + public static Test suite() + { + TestSuite suite = new TestSuite(); + + // $JUnit-BEGIN$ + suite.addTest(new TestSuite(DefaultDirectedGraphTest.class)); + suite.addTest(new TestSuite(ListenableGraphTest.class)); + suite.addTest(new TestSuite(SimpleDirectedGraphTest.class)); + suite.addTest(new TestSuite(AsUndirectedGraphTest.class)); + suite.addTest(new TestSuite(AsUnweightedGraphTest.class)); + suite.addTest(new TestSuite(CloneTest.class)); + suite.addTest(new TestSuite(SerializationTest.class)); + suite.addTest(new TestSuite(GenericGraphsTest.class)); + + // $JUnit-END$ + return suite; + } +} + +// End AllGraphTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsUndirectedGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsUndirectedGraphTest.java new file mode 100644 index 00000000..10e1911b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsUndirectedGraphTest.java @@ -0,0 +1,190 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * AsUndirectedGraphTest.java + * -------------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: AsUndirectedGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 14-Aug-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * A unit test for the AsDirectedGraph view. + * + * @author John V. Sichi + */ +public class AsUndirectedGraphTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + private DirectedGraph directed; + private DefaultEdge loop; + private String v1 = "v1"; + private String v2 = "v2"; + private String v3 = "v3"; + private String v4 = "v4"; + private UndirectedGraph undirected; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public AsUndirectedGraphTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testAddEdge() + { + try { + undirected.addEdge(v3, v4); + assertFalse(); + } catch (UnsupportedOperationException e) { + assertTrue(); + } + + assertEquals( + "([v1, v2, v3, v4], [{v1,v2}, {v2,v3}, {v2,v4}, {v4,v4}])", + undirected.toString()); + } + + /** + * . + */ + public void testAddVertex() + { + String v5 = "v5"; + + undirected.addVertex(v5); + assertEquals(true, undirected.containsVertex(v5)); + assertEquals(true, directed.containsVertex(v5)); + } + + /** + * . + */ + public void testDegreeOf() + { + assertEquals(1, undirected.degreeOf(v1)); + assertEquals(3, undirected.degreeOf(v2)); + assertEquals(1, undirected.degreeOf(v3)); + assertEquals(3, undirected.degreeOf(v4)); + } + + /** + * . + */ + public void testGetAllEdges() + { + Set edges = undirected.getAllEdges(v3, v2); + assertEquals(1, edges.size()); + assertEquals(directed.getEdge(v2, v3), + edges.iterator().next()); + + edges = undirected.getAllEdges(v4, v4); + assertEquals(1, edges.size()); + assertEquals(loop, edges.iterator().next()); + } + + /** + * . + */ + public void testGetEdge() + { + assertEquals( + directed.getEdge(v1, v2), + undirected.getEdge(v1, v2)); + assertEquals( + directed.getEdge(v1, v2), + undirected.getEdge(v2, v1)); + + assertEquals( + directed.getEdge(v4, v4), + undirected.getEdge(v4, v4)); + } + + /** + * . + */ + public void testRemoveEdge() + { + undirected.removeEdge(loop); + assertEquals(false, undirected.containsEdge(loop)); + assertEquals(false, directed.containsEdge(loop)); + } + + /** + * . + */ + public void testRemoveVertex() + { + undirected.removeVertex(v4); + assertEquals(false, undirected.containsVertex(v4)); + assertEquals(false, directed.containsVertex(v4)); + } + + /** + * . + */ + protected void setUp() + { + directed = + new DefaultDirectedGraph( + DefaultEdge.class); + undirected = new AsUndirectedGraph(directed); + + directed.addVertex(v1); + directed.addVertex(v2); + directed.addVertex(v3); + directed.addVertex(v4); + directed.addEdge(v1, v2); + directed.addEdge(v2, v3); + directed.addEdge(v2, v4); + loop = directed.addEdge(v4, v4); + } +} + +// End AsUndirectedGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsUnweightedGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsUnweightedGraphTest.java new file mode 100644 index 00000000..441593a8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsUnweightedGraphTest.java @@ -0,0 +1,143 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * AsUnweightedGraphTest.java + * -------------------------- + * (C) Copyright 2007-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: AsUnweightedGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 22-Sep-2007 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A unit test for the AsUnweighted[Directed]Graph views. + * + * @author John V. Sichi + */ +public class AsUnweightedGraphTest + extends EnhancedTestCase +{ + //~ Static fields/initializers --------------------------------------------- + + private static final String v1 = "v1"; + private static final String v2 = "v2"; + private static final String v3 = "v3"; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public AsUnweightedGraphTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testDirected() + { + DefaultDirectedWeightedGraph directed = + new DefaultDirectedWeightedGraph( + DefaultWeightedEdge.class); + constructWeighted(directed); + + AsUnweightedDirectedGraph unweighted = + new AsUnweightedDirectedGraph( + directed); + checkView(directed, unweighted); + } + + /** + * . + */ + public void testUndirected() + { + WeightedGraph undirected = + new SimpleWeightedGraph( + DefaultWeightedEdge.class); + constructWeighted(undirected); + + AsUnweightedGraph unweighted = + new AsUnweightedGraph( + undirected); + checkView(undirected, unweighted); + } + + private void constructWeighted( + WeightedGraph weighted) + { + weighted.addVertex(v1); + weighted.addVertex(v2); + weighted.addVertex(v3); + Graphs.addEdge(weighted, v1, v2, 3.0); + assertEquals( + 3.0, + weighted.getEdgeWeight( + weighted.getEdge(v1, v2))); + } + + private void checkView( + WeightedGraph weighted, + Graph unweighted) + { + assertEquals( + WeightedGraph.DEFAULT_EDGE_WEIGHT, + unweighted.getEdgeWeight( + unweighted.getEdge(v1, v2))); + + Graphs.addEdge(weighted, v2, v3, 5.0); + assertEquals( + WeightedGraph.DEFAULT_EDGE_WEIGHT, + unweighted.getEdgeWeight( + unweighted.getEdge(v2, v3))); + + unweighted.addEdge(v3, v1); + assertEquals( + WeightedGraph.DEFAULT_EDGE_WEIGHT, + unweighted.getEdgeWeight( + unweighted.getEdge(v3, v1))); + assertEquals( + WeightedGraph.DEFAULT_EDGE_WEIGHT, + weighted.getEdgeWeight( + weighted.getEdge(v3, v1))); + } +} + +// End AsUnweightedGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsWeightedGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsWeightedGraphTest.java new file mode 100644 index 00000000..93a155af --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/AsWeightedGraphTest.java @@ -0,0 +1,146 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * AsWeightedGraphTest.java + * -------------------------- + * (C) Copyright 2007, by Lucas J. Scharenbroich and Contributors. + * + * Original Author: Lucas J. Scharenbroich + * Contributor(s): John V. Sichi + * + * $Id: AsWeightedGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 22-Sep-2007 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * A unit test for the AsWeightedGraph view. + * + * @author Lucas J. Scharenbroich + */ +public class AsWeightedGraphTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + public SimpleWeightedGraph weightedGraph; + public SimpleGraph unweightedGraph; + + //~ Methods ---------------------------------------------------------------- + + public void setUp() + { + weightedGraph = + new SimpleWeightedGraph( + DefaultWeightedEdge.class); + unweightedGraph = + new SimpleGraph(DefaultEdge.class); + + // Create a very simple graph + weightedGraph.addVertex("v1"); + weightedGraph.addVertex("v2"); + weightedGraph.addVertex("v3"); + + unweightedGraph.addVertex("v1"); + unweightedGraph.addVertex("v2"); + unweightedGraph.addVertex("v3"); + + weightedGraph.setEdgeWeight(weightedGraph.addEdge("v1", "v2"), 1.); + weightedGraph.setEdgeWeight(weightedGraph.addEdge("v2", "v3"), 2.); + weightedGraph.setEdgeWeight(weightedGraph.addEdge("v3", "v1"), 3.); + + unweightedGraph.addEdge("v1", "v2"); + unweightedGraph.addEdge("v2", "v3"); + unweightedGraph.addEdge("v3", "v1"); + } + + public void tearDown() + { + } + + public void test1() + { + Map weightMap1 = + new HashMap(); + Map weightMap2 = + new HashMap(); + + DefaultEdge e1 = unweightedGraph.getEdge("v1", "v2"); + DefaultEdge e2 = unweightedGraph.getEdge("v2", "v3"); + DefaultEdge e3 = unweightedGraph.getEdge("v3", "v1"); + + DefaultWeightedEdge e4 = weightedGraph.getEdge("v1", "v2"); + DefaultWeightedEdge e5 = weightedGraph.getEdge("v2", "v3"); + DefaultWeightedEdge e6 = weightedGraph.getEdge("v3", "v1"); + + weightMap1.put(e1, 9.0); + + weightMap2.put(e4, 9.0); + weightMap2.put(e6, 8.0); + + assertEquals( + unweightedGraph.getEdgeWeight(e1), + WeightedGraph.DEFAULT_EDGE_WEIGHT); + + WeightedGraph g1 = + new AsWeightedGraph( + unweightedGraph, + weightMap1); + WeightedGraph g2 = + new AsWeightedGraph( + weightedGraph, + weightMap2); + + assertEquals(g1.getEdgeWeight(e1), 9.0); + assertEquals(g1.getEdgeWeight(e2), WeightedGraph.DEFAULT_EDGE_WEIGHT); + assertEquals(g1.getEdgeWeight(e3), WeightedGraph.DEFAULT_EDGE_WEIGHT); + + assertEquals(g2.getEdgeWeight(e4), 9.0); + assertEquals(g2.getEdgeWeight(e5), 2.0); + assertEquals(g2.getEdgeWeight(e6), 8.0); + + g1.setEdgeWeight(e2, 5.0); + g2.setEdgeWeight(e5, 5.0); + + assertEquals(g1.getEdgeWeight(e2), 5.0); + assertEquals( + unweightedGraph.getEdgeWeight(e2), + WeightedGraph.DEFAULT_EDGE_WEIGHT); + + assertEquals(g2.getEdgeWeight(e5), 5.0); + assertEquals(weightedGraph.getEdgeWeight(e5), 5.0); + } +} + +// End AsWeightedGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/CloneTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/CloneTest.java new file mode 100644 index 00000000..12de6f6a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/CloneTest.java @@ -0,0 +1,141 @@ +/* ========================================== + * 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. + */ +/* -------------- + * CloneTest.java + * -------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: CloneTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Oct-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A unit test for a cloning bug, adapted from a forum entry from Linda Buisman. + * + * @author John V. Sichi + * @since Oct 6, 2003 + */ +public class CloneTest + extends EnhancedTestCase +{ + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public CloneTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Test graph cloning. + */ + @SuppressWarnings("unchecked") + public void testCloneSpecificsBug() + { + SimpleGraph g1 = + new SimpleGraph(DefaultEdge.class); + String one = "1"; + String two = "2"; + String three = "3"; + g1.addVertex(one); + g1.addVertex(two); + g1.addVertex(three); + g1.addEdge(one, two); + g1.addEdge(two, three); + + SimpleGraph g2 = + (SimpleGraph) g1.clone(); // Type-safty + // warning OK with + // clone + assertEquals(2, g2.edgeSet().size()); + assertNotNull(g2.getEdge(one, two)); + assertTrue(g2.removeEdge(g2.getEdge(one, two))); + assertNotNull(g2.removeEdge("2", "3")); + assertTrue(g2.edgeSet().isEmpty()); + } + + /** + * Tests usage of {@link ParanoidGraph} for detecting broken vertex + * implementations. + */ + public void testParanoidGraph() + { + BrokenVertex v1 = new BrokenVertex(1); + BrokenVertex v2 = new BrokenVertex(2); + BrokenVertex v3 = new BrokenVertex(1); + + SimpleGraph g = + new SimpleGraph(DefaultEdge.class); + ParanoidGraph pg = + new ParanoidGraph(g); + pg.addVertex(v1); + pg.addVertex(v2); + try { + pg.addVertex(v3); + + // should not get here + assertFalse(); + } catch (IllegalArgumentException ex) { + // expected, swallow + } + } + + //~ Inner Classes ---------------------------------------------------------- + + private class BrokenVertex + { + private int x; + + BrokenVertex(int x) + { + this.x = x; + } + + public boolean equals(Object other) + { + if (!(other instanceof BrokenVertex)) { + return false; + } + return x == ((BrokenVertex) other).x; + } + } +} + +// End CloneTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/DefaultDirectedGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/DefaultDirectedGraphTest.java new file mode 100644 index 00000000..3d4c6240 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/DefaultDirectedGraphTest.java @@ -0,0 +1,213 @@ +/* ========================================== + * 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. + */ +/* ----------------------------- + * DefaultDirectedGraphTest.java + * ----------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: DefaultDirectedGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 09-Aug-2003 : Initial revision (BN); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * A unit test for directed multigraph. + * + * @author Barak Naveh + * @since Aug 9, 2003 + */ +public class DefaultDirectedGraphTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + private String v1 = "v1"; + private String v2 = "v2"; + private String v3 = "v3"; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testEdgeSetFactory() + { + DirectedMultigraph g = + new DirectedMultigraph( + DefaultEdge.class); + g.setEdgeSetFactory(new LinkedHashSetFactory()); + initMultiTriangleWithMultiLoop(g); + } + + /** + * . + */ + public void testEdgeOrderDeterminism() + { + DirectedGraph g = + new DirectedMultigraph( + DefaultEdge.class); + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + + DefaultEdge e1 = g.addEdge(v1, v2); + DefaultEdge e2 = g.addEdge(v2, v3); + DefaultEdge e3 = g.addEdge(v3, v1); + + Iterator iter = g.edgeSet().iterator(); + assertEquals(e1, iter.next()); + assertEquals(e2, iter.next()); + assertEquals(e3, iter.next()); + + // some bonus tests + assertTrue(Graphs.testIncidence(g, e1, v1)); + assertTrue(Graphs.testIncidence(g, e1, v2)); + assertFalse(Graphs.testIncidence(g, e1, v3)); + assertEquals(v2, Graphs.getOppositeVertex(g, e1, v1)); + assertEquals(v1, Graphs.getOppositeVertex(g, e1, v2)); + + assertEquals( + "([v1, v2, v3], [(v1,v2), (v2,v3), (v3,v1)])", + g.toString()); + } + + /** + * . + */ + public void testEdgesOf() + { + DirectedGraph g = + createMultiTriangleWithMultiLoop(); + + assertEquals(3, g.edgesOf(v1).size()); + assertEquals(2, g.edgesOf(v2).size()); + } + + /** + * . + */ + public void testGetAllEdges() + { + DirectedGraph g = + createMultiTriangleWithMultiLoop(); + + Set loops = g.getAllEdges(v1, v1); + assertEquals(1, loops.size()); + } + + /** + * . + */ + public void testInDegreeOf() + { + DirectedGraph g = + createMultiTriangleWithMultiLoop(); + + assertEquals(2, g.inDegreeOf(v1)); + assertEquals(1, g.inDegreeOf(v2)); + } + + /** + * . + */ + public void testOutDegreeOf() + { + DirectedGraph g = + createMultiTriangleWithMultiLoop(); + + assertEquals(2, g.outDegreeOf(v1)); + assertEquals(1, g.outDegreeOf(v2)); + } + + /** + * . + */ + public void testVertexOrderDeterminism() + { + DirectedGraph g = + createMultiTriangleWithMultiLoop(); + Iterator iter = g.vertexSet().iterator(); + assertEquals(v1, iter.next()); + assertEquals(v2, iter.next()); + assertEquals(v3, iter.next()); + } + + private DirectedGraph + createMultiTriangleWithMultiLoop() + { + DirectedGraph g = + new DirectedMultigraph( + DefaultEdge.class); + initMultiTriangleWithMultiLoop(g); + + return g; + } + + private void initMultiTriangleWithMultiLoop( + DirectedGraph g) + { + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + + g.addEdge(v1, v1); + g.addEdge(v1, v2); + g.addEdge(v2, v3); + g.addEdge(v3, v1); + } + + //~ Inner Classes ---------------------------------------------------------- + + private static class LinkedHashSetFactory + implements EdgeSetFactory + { + /** + * . + * + * @param vertex + * + * @return an empty list. + */ + public Set createEdgeSet(V vertex) + { + return new LinkedHashSet(); + } + } +} + +// End DefaultDirectedGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/GenericGraphsTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/GenericGraphsTest.java new file mode 100644 index 00000000..b99178f8 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/GenericGraphsTest.java @@ -0,0 +1,250 @@ +/* ========================================== + * 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. + */ +/* -------------------------- + * GenericGraphsTest.java + * -------------------------- + * (C) Copyright 2006-2008, by HartmutBenz and Contributors. + * + * Original Author: Hartmut Benz + * Contributor(s): John V. Sichi + * + * $Id: GenericGraphsTest.java 692 2009-07-04 06:50:26Z perfecthash $ + * + * Changes + * ------- + * ??-???-2006 : Initial revision (HB); + * + */ +package org.jgrapht.graph; + +import org.jgrapht.*; + + +/** + * A unit test for graph generic vertex/edge parameters. + * + * @author Hartmut Benz + */ +public class GenericGraphsTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + Graph objectGraph; + Graph fooFooGraph; + Graph barBarGraph; + Graph fooBarGraph; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public GenericGraphsTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + // ~ Methods --------------------------------------------------------------- + + public void testLegalInsertStringGraph() + { + String v1 = "Vertex1"; + Object v2 = "Vertex2"; + objectGraph.addVertex(v1); + objectGraph.addVertex(v2); + objectGraph.addEdge(v1, v2); + } + + public void testLegalInsertFooGraph() + { + FooVertex v1 = new FooVertex(); + FooVertex v2 = new FooVertex(); + BarVertex vb1 = new BarVertex(); + BarVertex vb2 = new BarVertex(); + fooFooGraph.addVertex(v1); + fooFooGraph.addVertex(v2); + fooFooGraph.addVertex(vb1); + fooFooGraph.addVertex(vb2); + fooFooGraph.addEdge(v1, v2); + fooFooGraph.addEdge(vb1, vb2); + fooFooGraph.addEdge(v1, vb2); + fooFooGraph.addEdge(v1, v2, new BarEdge()); + fooFooGraph.addEdge(v1, vb2, new BarEdge()); + fooFooGraph.addEdge(vb1, vb2, new BarEdge()); + } + + public void testLegalInsertBarGraph() + { + BarVertex v1 = new BarVertex(); + BarVertex v2 = new BarVertex(); + barBarGraph.addVertex(v1); + barBarGraph.addVertex(v2); + barBarGraph.addEdge(v1, v2); + } + + public void testLegalInsertFooBarGraph() + { + FooVertex v1 = new FooVertex(); + FooVertex v2 = new FooVertex(); + BarVertex vb1 = new BarVertex(); + BarVertex vb2 = new BarVertex(); + fooFooGraph.addVertex(v1); + fooFooGraph.addVertex(v2); + fooFooGraph.addVertex(vb1); + fooFooGraph.addVertex(vb2); + fooFooGraph.addEdge(v1, v2); + fooFooGraph.addEdge(vb1, vb2); + fooFooGraph.addEdge(v1, vb2); + } + + public void testAlissaHacker() + { + DirectedGraph g = + new DefaultDirectedGraph(CustomEdge.class); + g.addVertex("a"); + g.addVertex("b"); + g.addEdge("a", "b"); + CustomEdge custom = g.getEdge("a", "b"); + String s = custom.toString(); + assertEquals("Alissa P. Hacker approves the edge from a to b", s); + } + + public void testEqualButNotSameVertex() + { + EquivVertex v1 = new EquivVertex(); + EquivVertex v2 = new EquivVertex(); + EquivGraph g = new EquivGraph(); + g.addVertex(v1); + g.addVertex(v2); + g.addEdge(v1, v2, new DefaultEdge()); + assertEquals(2, g.degreeOf(v1)); + assertEquals(2, g.degreeOf(v2)); + } + + /** + * . + */ + protected void setUp() + { + objectGraph = + new DefaultDirectedGraph( + DefaultEdge.class); + fooFooGraph = new SimpleGraph(FooEdge.class); + barBarGraph = new SimpleGraph(BarEdge.class); + } + + //~ Inner Classes ---------------------------------------------------------- + + public static class CustomEdge + extends DefaultEdge + { + private static final long serialVersionUID = 1L; + + public String toString() + { + return "Alissa P. Hacker approves the edge from " + getSource() + + " to " + getTarget(); + } + } + + public static class EquivVertex + { + public boolean equals(Object o) + { + return true; + } + + public int hashCode() + { + return 1; + } + } + + public static class EquivGraph + extends AbstractBaseGraph + implements UndirectedGraph + { + /** + * + */ + private static final long serialVersionUID = 8647217182401022498L; + + public EquivGraph() + { + super( + new ClassBasedEdgeFactory( + DefaultEdge.class), + true, + true); + } + } + + public static class FooEdge + extends DefaultEdge + { + private static final long serialVersionUID = 1L; + } + + private class FooVertex + { + String str; + + public FooVertex() + { + super(); + str = "empty foo"; + } + + public FooVertex(String s) + { + str = s; + } + } + + public static class BarEdge + extends FooEdge + { + private static final long serialVersionUID = 1L; + } + + private class BarVertex + extends FooVertex + { + public BarVertex() + { + super("empty bar"); + } + + public BarVertex(String s) + { + super(s); + } + } +} + +// End GenericGraphsTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/ListenableGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/ListenableGraphTest.java new file mode 100644 index 00000000..f287b6bc --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/ListenableGraphTest.java @@ -0,0 +1,250 @@ +/* ========================================== + * 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. + */ +/* ------------------------ + * ListenableGraphTest.java + * ------------------------ + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: ListenableGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Aug-2003 : Initial revision (BN); + * 10-Aug-2003 : Adaptation to new event model (BN); + * + */ +package org.jgrapht.graph; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.event.*; + + +/** + * Unit test for {@link ListenableGraph} class. + * + * @author Barak Naveh + * @since Aug 3, 2003 + */ +public class ListenableGraphTest + extends TestCase +{ + //~ Instance fields -------------------------------------------------------- + + DefaultEdge lastAddedEdge; + DefaultEdge lastRemovedEdge; + Object lastAddedVertex; + Object lastRemovedVertex; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public ListenableGraphTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Tests GraphListener listener. + */ + public void testGraphListener() + { + init(); + + ListenableGraph g = + new ListenableUndirectedGraph( + DefaultEdge.class); + GraphListener listener = new MyGraphListner(); + g.addGraphListener(listener); + + String v1 = "v1"; + String v2 = "v2"; + + // test vertex notification + g.addVertex(v1); + assertEquals(v1, lastAddedVertex); + assertEquals(null, lastRemovedVertex); + + init(); + g.removeVertex(v1); + assertEquals(v1, lastRemovedVertex); + assertEquals(null, lastAddedVertex); + + // test edge notification + g.addVertex(v1); + g.addVertex(v2); + + init(); + + DefaultEdge e = g.addEdge(v1, v2); + assertEquals(e, lastAddedEdge); + assertEquals(null, lastRemovedEdge); + + init(); + assertTrue(g.removeEdge(e)); + assertEquals(e, lastRemovedEdge); + assertEquals(null, lastAddedEdge); + + g.removeVertex(v1); + g.removeVertex(v2); + + // + // test notification stops when removing listener + // + g.removeGraphListener(listener); + init(); + g.addVertex(v1); + g.addVertex(v2); + e = g.addEdge(v1, v2); + g.removeEdge(e); + + assertEquals(null, lastAddedEdge); + assertEquals(null, lastAddedVertex); + assertEquals(null, lastRemovedEdge); + assertEquals(null, lastRemovedVertex); + } + + /** + * Tests VertexSetListener listener. + */ + public void testVertexSetListener() + { + init(); + + ListenableGraph g = + new ListenableUndirectedGraph( + DefaultEdge.class); + VertexSetListener listener = new MyGraphListner(); + g.addVertexSetListener(listener); + + String v1 = "v1"; + String v2 = "v2"; + + // test vertex notification + g.addVertex(v1); + assertEquals(v1, lastAddedVertex); + assertEquals(null, lastRemovedVertex); + + init(); + g.removeVertex(v1); + assertEquals(v1, lastRemovedVertex); + assertEquals(null, lastAddedVertex); + + // test edge notification + g.addVertex(v1); + g.addVertex(v2); + + init(); + + DefaultEdge e = g.addEdge(v1, v2); + assertEquals(null, lastAddedEdge); + assertEquals(null, lastRemovedEdge); + + init(); + assertTrue(g.removeEdge(e)); + assertEquals(null, lastRemovedEdge); + assertEquals(null, lastAddedEdge); + + g.removeVertex(v1); + g.removeVertex(v2); + + // + // test notification stops when removing listener + // + g.removeVertexSetListener(listener); + init(); + g.addVertex(v1); + g.addVertex(v2); + e = g.addEdge(v1, v2); + g.removeEdge(e); + + assertEquals(null, lastAddedEdge); + assertEquals(null, lastAddedVertex); + assertEquals(null, lastRemovedEdge); + assertEquals(null, lastRemovedVertex); + } + + private void init() + { + lastAddedEdge = null; + lastAddedVertex = null; + lastRemovedEdge = null; + lastRemovedVertex = null; + } + + //~ Inner Classes ---------------------------------------------------------- + + /** + * A listener on the tested graph. + * + * @author Barak Naveh + * @since Aug 3, 2003 + */ + private class MyGraphListner + implements GraphListener + { + /** + * @see GraphListener#edgeAdded(GraphEdgeChangeEvent) + */ + public void edgeAdded(GraphEdgeChangeEvent e) + { + lastAddedEdge = e.getEdge(); + } + + /** + * @see GraphListener#edgeRemoved(GraphEdgeChangeEvent) + */ + public void edgeRemoved(GraphEdgeChangeEvent e) + { + lastRemovedEdge = e.getEdge(); + } + + /** + * @see VertexSetListener#vertexAdded(GraphVertexChangeEvent) + */ + public void vertexAdded(GraphVertexChangeEvent e) + { + lastAddedVertex = e.getVertex(); + } + + /** + * @see VertexSetListener#vertexRemoved(GraphVertexChangeEvent) + */ + public void vertexRemoved(GraphVertexChangeEvent e) + { + lastRemovedVertex = e.getVertex(); + } + } +} + +// End ListenableGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SerializationTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SerializationTest.java new file mode 100644 index 00000000..04667985 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SerializationTest.java @@ -0,0 +1,120 @@ +/* ========================================== + * 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. + */ +/* -------------- + * SerializationTest.java + * -------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: SerializationTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 06-Oct-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.graph; + +import java.io.*; + +import org.jgrapht.*; + + +/** + * SerializationTest tests serialization and deserialization of JGraphT objects. + * + * @author John V. Sichi + */ +public class SerializationTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + private String v1 = "v1"; + private String v2 = "v2"; + private String v3 = "v3"; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public SerializationTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Tests serialization of DirectedMultigraph. + */ + @SuppressWarnings("unchecked") + public void testDirectedMultigraph() + throws Exception + { + DirectedMultigraph graph = + new DirectedMultigraph( + DefaultEdge.class); + graph.addVertex(v1); + graph.addVertex(v2); + graph.addVertex(v3); + graph.addEdge(v1, v2); + graph.addEdge(v2, v3); + graph.addEdge(v2, v3); + + graph = + (DirectedMultigraph) serializeAndDeserialize( + graph); + assertTrue(graph.containsVertex(v1)); + assertTrue(graph.containsVertex(v2)); + assertTrue(graph.containsVertex(v3)); + assertTrue(graph.containsEdge(v1, v2)); + assertTrue(graph.containsEdge(v2, v3)); + assertEquals(1, graph.edgesOf(v1).size()); + assertEquals(3, graph.edgesOf(v2).size()); + assertEquals(2, graph.edgesOf(v3).size()); + } + + private Object serializeAndDeserialize(Object obj) + throws Exception + { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(bout); + + out.writeObject(obj); + out.flush(); + + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bin); + + obj = in.readObject(); + return obj; + } +} + +// End SerializationTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SimpleDirectedGraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SimpleDirectedGraphTest.java new file mode 100644 index 00000000..004d04b7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SimpleDirectedGraphTest.java @@ -0,0 +1,502 @@ +/* ========================================== + * 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. + */ +/* ---------------------------- + * SimpleDirectedGraphTest.java + * ---------------------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: SimpleDirectedGraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 25-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import org.jgrapht.*; + + +/** + * A unit test for simple directed graph. + * + * @author Barak Naveh + * @since Jul 25, 2003 + */ +public class SimpleDirectedGraphTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + DirectedGraph gEmpty; + private DirectedGraph g1; + private DirectedGraph g2; + private DirectedGraph g3; + private DirectedGraph g4; + private DefaultEdge eLoop; + private EdgeFactory eFactory; + private String v1 = "v1"; + private String v2 = "v2"; + private String v3 = "v3"; + private String v4 = "v4"; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public SimpleDirectedGraphTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * Class to test for boolean addEdge(V, V, E) + */ + public void testAddEdgeEdge() + { + init(); + + try { + g1.addEdge(v1, v1, eLoop); // loops not allowed + assertFalse(); + } catch (IllegalArgumentException e) { + assertTrue(); + } + + try { + g3.addEdge(v1, v1, null); + assertFalse(); // NPE + } catch (NullPointerException e) { + assertTrue(); + } + + DefaultEdge e = eFactory.createEdge(v2, v1); + + try { + g1.addEdge("ya", "ya", e); // no such vertex in graph + assertFalse(); + } catch (IllegalArgumentException ile) { + assertTrue(); + } + + assertEquals(false, g2.addEdge(v2, v1, e)); + assertEquals(false, g3.addEdge(v2, v1, e)); + assertEquals(true, g4.addEdge(v2, v1, e)); + } + + /** + * Class to test for Edge addEdge(Object, Object) + */ + public void testAddEdgeObjectObject() + { + init(); + + try { + g1.addEdge(v1, v1); // loops not allowed + assertFalse(); + } catch (IllegalArgumentException e) { + assertTrue(); + } + + try { + g3.addEdge(null, null); + assertFalse(); // NPE + } catch (NullPointerException e) { + assertTrue(); + } + + try { + g1.addEdge(v2, v1); // no such vertex in graph + assertFalse(); + } catch (IllegalArgumentException ile) { + assertTrue(); + } + + assertNull(g2.addEdge(v2, v1)); + assertNull(g3.addEdge(v2, v1)); + assertNotNull(g4.addEdge(v2, v1)); + } + + /** + * . + */ + public void testAddVertex() + { + init(); + + assertEquals(1, g1.vertexSet().size()); + assertEquals(2, g2.vertexSet().size()); + assertEquals(3, g3.vertexSet().size()); + assertEquals(4, g4.vertexSet().size()); + + assertFalse(g1.addVertex(v1)); + assertTrue(g1.addVertex(v2)); + assertEquals(2, g1.vertexSet().size()); + } + + /** + * Class to test for boolean containsEdge(Edge) + */ + public void testContainsEdgeEdge() + { + init(); + + // TODO Implement containsEdge(). + } + + /** + * Class to test for boolean containsEdge(Object, Object) + */ + public void testContainsEdgeObjectObject() + { + init(); + + assertFalse(g1.containsEdge(v1, v2)); + assertFalse(g1.containsEdge(v1, v1)); + + assertTrue(g2.containsEdge(v1, v2)); + assertTrue(g2.containsEdge(v2, v1)); + + assertTrue(g3.containsEdge(v1, v2)); + assertTrue(g3.containsEdge(v2, v1)); + assertTrue(g3.containsEdge(v3, v2)); + assertTrue(g3.containsEdge(v2, v3)); + assertTrue(g3.containsEdge(v1, v3)); + assertTrue(g3.containsEdge(v3, v1)); + + assertFalse(g4.containsEdge(v1, v4)); + g4.addEdge(v1, v4); + assertTrue(g4.containsEdge(v1, v4)); + + assertFalse(g3.containsEdge(v4, v2)); + assertFalse(g3.containsEdge(null, null)); + } + + /** + * . + */ + public void testContainsVertex() + { + init(); + + // TODO Implement containsVertex(). + } + + /** + * . + */ + public void testEdgeSet() + { + init(); + + // TODO Implement edgeSet(). + } + + /** + * . + */ + public void testEdgesOf() + { + init(); + + assertEquals(g4.edgesOf(v1).size(), 2); + assertEquals(g3.edgesOf(v1).size(), 4); + + Iterator iter = g3.edgesOf(v1).iterator(); + int count = 0; + + while (iter.hasNext()) { + iter.next(); + count++; + } + + assertEquals(count, 4); + } + + /** + * . + */ + public void testGetAllEdges() + { + init(); // TODO Implement getAllEdges(). + } + + /** + * . + */ + public void testGetEdge() + { + init(); // TODO Implement getEdge(). + } + + /** + * . + */ + public void testGetEdgeFactory() + { + init(); // TODO Implement getEdgeFactory(). + } + + /** + * . + */ + public void testInDegreeOf() + { + init(); + + assertEquals(0, g1.inDegreeOf(v1)); + + assertEquals(1, g2.inDegreeOf(v1)); + assertEquals(1, g2.inDegreeOf(v2)); + + assertEquals(2, g3.inDegreeOf(v1)); + assertEquals(2, g3.inDegreeOf(v2)); + assertEquals(2, g3.inDegreeOf(v3)); + + assertEquals(1, g4.inDegreeOf(v1)); + assertEquals(1, g4.inDegreeOf(v2)); + assertEquals(1, g4.inDegreeOf(v3)); + assertEquals(1, g4.inDegreeOf(v4)); + + try { + g3.inDegreeOf(new String()); + assertFalse(); + } catch (IllegalArgumentException e) { + assertTrue(); + } + + try { + g3.inDegreeOf(null); + assertFalse(); + } catch (NullPointerException e) { + assertTrue(); + } + } + + /** + * . + */ + public void testIncomingOutgoingEdgesOf() + { + init(); + + Set e1to2 = g2.outgoingEdgesOf(v1); + Set e2from1 = g2.incomingEdgesOf(v2); + assertEquals(e1to2, e2from1); + } + + /** + * . + */ + public void testOutDegreeOf() + { + init(); // TODO Implement outDegreeOf(). + } + + /** + * . + */ + public void testOutgoingEdgesOf() + { + init(); // TODO Implement outgoingEdgesOf(). + } + + /** + * Class to test for boolean removeEdge(Edge) + */ + public void testRemoveEdgeEdge() + { + init(); + + assertEquals(g4.edgeSet().size(), 4); + g4.removeEdge(v1, v2); + assertEquals(g4.edgeSet().size(), 3); + assertFalse(g4.removeEdge(eLoop)); + assertTrue(g4.removeEdge(g4.getEdge(v2, v3))); + assertEquals(g4.edgeSet().size(), 2); + } + + /** + * Class to test for Edge removeEdge(Object, Object) + */ + public void testRemoveEdgeObjectObject() + { + init(); // TODO Implement removeEdge(). + } + + /** + * . + */ + public void testRemoveVertex() + { + init(); + assertEquals(4, g4.vertexSet().size()); + assertTrue(g4.removeVertex(v1)); + assertEquals(3, g4.vertexSet().size()); + + assertEquals(2, g4.edgeSet().size()); + assertFalse(g4.removeVertex(v1)); + assertTrue(g4.removeVertex(v2)); + assertEquals(1, g4.edgeSet().size()); + assertTrue(g4.removeVertex(v3)); + assertEquals(0, g4.edgeSet().size()); + assertEquals(1, g4.vertexSet().size()); + assertTrue(g4.removeVertex(v4)); + assertEquals(0, g4.vertexSet().size()); + } + + /** + * . + */ + public void testVertexSet() + { + init(); // TODO Implement vertexSet(). + } + + public void testReversedView() + { + init(); + + DirectedGraph g = + new SimpleDirectedGraph(DefaultEdge.class); + DirectedGraph r = + new EdgeReversedGraph(g); + + g.addVertex(v1); + g.addVertex(v2); + DefaultEdge e = g.addEdge(v1, v2); + + verifyReversal(g, r, e); + + // We have implicitly verified that r is backed by g for additive + // operations (since we constructed it before adding anything to g). + // Now verify for deletion. + + g.removeEdge(e); + + assertTrue(r.edgeSet().isEmpty()); + assertEquals(0, r.inDegreeOf(v1)); + assertEquals(0, r.outDegreeOf(v1)); + assertEquals(0, r.inDegreeOf(v2)); + assertEquals(0, r.outDegreeOf(v2)); + assertTrue(r.incomingEdgesOf(v1).isEmpty()); + assertTrue(r.outgoingEdgesOf(v1).isEmpty()); + assertTrue(r.incomingEdgesOf(v2).isEmpty()); + assertTrue(r.outgoingEdgesOf(v2).isEmpty()); + } + + private void verifyReversal( + DirectedGraph g, + DirectedGraph r, + DefaultEdge e) + { + assertTrue(r.containsVertex(v1)); + assertTrue(r.containsVertex(v2)); + + assertEquals(g.vertexSet(), r.vertexSet()); + assertEquals(g.edgeSet(), r.edgeSet()); + + assertTrue(r.containsEdge(v2, v1)); + assertSame(e, r.getEdge(v2, v1)); + assertFalse(r.containsEdge(v1, v2)); + assertNull(r.getEdge(v1, v2)); + + Set s = r.getAllEdges(v1, v2); + assertEquals(0, s.size()); + + s = r.getAllEdges(v2, v1); + assertEquals(1, s.size()); + assertSame(e, s.iterator().next()); + + assertEquals(1, r.inDegreeOf(v1)); + assertEquals(0, r.inDegreeOf(v2)); + assertEquals(0, r.outDegreeOf(v1)); + assertEquals(1, r.outDegreeOf(v2)); + + assertEquals(g.edgeSet(), r.incomingEdgesOf(v1)); + assertTrue(r.outgoingEdgesOf(v1).isEmpty()); + assertTrue(r.incomingEdgesOf(v2).isEmpty()); + assertEquals(g.edgeSet(), r.outgoingEdgesOf(v2)); + + assertSame(v2, r.getEdgeSource(e)); + assertSame(v1, r.getEdgeTarget(e)); + + assertEquals("([v1, v2], [(v2,v1)])", r.toString()); + } + + private void init() + { + gEmpty = + new SimpleDirectedGraph( + DefaultEdge.class); + g1 = new SimpleDirectedGraph( + DefaultEdge.class); + g2 = new SimpleDirectedGraph( + DefaultEdge.class); + g3 = new SimpleDirectedGraph( + DefaultEdge.class); + g4 = new SimpleDirectedGraph( + DefaultEdge.class); + + eFactory = g1.getEdgeFactory(); + eLoop = eFactory.createEdge(v1, v1); + + g1.addVertex(v1); + + g2.addVertex(v1); + g2.addVertex(v2); + g2.addEdge(v1, v2); + g2.addEdge(v2, v1); + + g3.addVertex(v1); + g3.addVertex(v2); + g3.addVertex(v3); + g3.addEdge(v1, v2); + g3.addEdge(v2, v1); + g3.addEdge(v2, v3); + g3.addEdge(v3, v2); + g3.addEdge(v3, v1); + g3.addEdge(v1, v3); + + g4.addVertex(v1); + g4.addVertex(v2); + g4.addVertex(v3); + g4.addVertex(v4); + g4.addEdge(v1, v2); + g4.addEdge(v2, v3); + g4.addEdge(v3, v4); + g4.addEdge(v4, v1); + } +} + +// End SimpleDirectedGraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SubgraphTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SubgraphTest.java new file mode 100644 index 00000000..738cddf6 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/graph/SubgraphTest.java @@ -0,0 +1,174 @@ +/* ========================================== + * 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. + */ +/* ------------------------ + * SubgraphTest.java + * ------------------------ + * (C) Copyright 2003-2008, by Michael Behrisch and Contributors. + * + * Original Author: Michael Behrisch + * Contributor(s): - + * + * $Id: SubgraphTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 21-Sep-2004 : Initial revision (MB); + * + */ +package org.jgrapht.graph; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; + + +/** + * Unit test for {@link Subgraph} class. + * + * @author Michael Behrisch + * @since Sep 21, 2004 + */ +public class SubgraphTest + extends TestCase +{ + //~ Instance fields -------------------------------------------------------- + + private String v1 = "v1"; + private String v2 = "v2"; + private String v3 = "v3"; + private String v4 = "v4"; + + //~ Constructors ----------------------------------------------------------- + + /** + * @see junit.framework.TestCase#TestCase(java.lang.String) + */ + public SubgraphTest(String name) + { + super(name); + } + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testInducedSubgraphListener() + { + UndirectedGraph g = init(true); + UndirectedSubgraph sub = + new UndirectedSubgraph(g, null, null); + + assertEquals(g.vertexSet(), sub.vertexSet()); + assertEquals(g.edgeSet(), sub.edgeSet()); + + g.addEdge(v3, v4); + + assertEquals(g.vertexSet(), sub.vertexSet()); + assertEquals(g.edgeSet(), sub.edgeSet()); + } + + /** + * Tests Subgraph. + */ + public void testSubgraph() + { + UndirectedGraph g = init(false); + UndirectedSubgraph sub = + new UndirectedSubgraph(g, null, null); + + assertEquals(g.vertexSet(), sub.vertexSet()); + assertEquals(g.edgeSet(), sub.edgeSet()); + + Set vset = new HashSet(g.vertexSet()); + g.removeVertex(v1); + assertEquals(vset, sub.vertexSet()); // losing track + + g = init(false); + vset = new HashSet(); + vset.add(v1); + sub = new UndirectedSubgraph(g, vset, null); + assertEquals(vset, sub.vertexSet()); + assertEquals(0, sub.degreeOf(v1)); + assertEquals(Collections.EMPTY_SET, sub.edgeSet()); + + vset.add(v2); + vset.add(v3); + sub = + new UndirectedSubgraph( + g, + vset, + new HashSet(g.getAllEdges(v1, v2))); + assertEquals(vset, sub.vertexSet()); + assertEquals(1, sub.edgeSet().size()); + } + + /** + * . + */ + public void testSubgraphListener() + { + UndirectedGraph g = init(true); + UndirectedSubgraph sub = + new UndirectedSubgraph(g, null, null); + + assertEquals(g.vertexSet(), sub.vertexSet()); + assertEquals(g.edgeSet(), sub.edgeSet()); + + Set vset = new HashSet(g.vertexSet()); + g.removeVertex(v1); + vset.remove(v1); + assertEquals(vset, sub.vertexSet()); // not losing track + assertEquals(g.edgeSet(), sub.edgeSet()); + } + + private UndirectedGraph init(boolean listenable) + { + UndirectedGraph g; + + if (listenable) { + g = new ListenableUndirectedGraph( + DefaultEdge.class); + } else { + g = new SimpleGraph( + DefaultEdge.class); + } + + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + g.addVertex(v4); + g.addEdge(v1, v2); + g.addEdge(v2, v3); + g.addEdge(v3, v1); + g.addEdge(v1, v4); + + return g; + } +} + +// End SubgraphTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/AbstractGraphIteratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/AbstractGraphIteratorTest.java new file mode 100644 index 00000000..b244e32d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/AbstractGraphIteratorTest.java @@ -0,0 +1,235 @@ +/* ========================================== + * 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. + */ +/* ------------------------------ + * AbstractGraphIteratorTest.java + * ------------------------------ + * (C) Copyright 2003-2008, by Liviu Rau and Contributors. + * + * Original Author: Liviu Rau + * Contributor(s): Barak Naveh + * + * $Id: AbstractGraphIteratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 30-Jul-2003 : Initial revision (LR); + * 06-Aug-2003 : Test traversal listener & extract a shared superclass (BN); + * + */ +package org.jgrapht.traverse; + +import org.jgrapht.*; +import org.jgrapht.event.*; +import org.jgrapht.graph.*; + + +/** + * A basis for testing {@link org.jgrapht.traverse.BreadthFirstIterator} and + * {@link org.jgrapht.traverse.DepthFirstIterator} classes. + * + * @author Liviu Rau + * @since Jul 30, 2003 + */ +public abstract class AbstractGraphIteratorTest + extends EnhancedTestCase +{ + //~ Instance fields -------------------------------------------------------- + + StringBuffer result; + + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testDirectedGraph() + { + result = new StringBuffer(); + + DirectedGraph graph = createDirectedGraph(); + + AbstractGraphIterator iterator = + createIterator(graph, "1"); + MyTraversalListener listener = new MyTraversalListener(); + iterator.addTraversalListener(listener); + + while (iterator.hasNext()) { + result.append(iterator.next()); + + if (iterator.hasNext()) { + result.append(','); + } + } + + assertEquals(getExpectedStr2(), result.toString()); + + assertEquals(getExpectedFinishString(), listener.getFinishString()); + } + + abstract String getExpectedStr1(); + + abstract String getExpectedStr2(); + + String getExpectedFinishString() + { + return ""; + } + + DirectedGraph createDirectedGraph() + { + DirectedGraph graph = + new DefaultDirectedWeightedGraph( + DefaultWeightedEdge.class); + + // + String v1 = "1"; + String v2 = "2"; + String v3 = "3"; + String v4 = "4"; + String v5 = "5"; + String v6 = "6"; + String v7 = "7"; + String v8 = "8"; + String v9 = "9"; + + graph.addVertex(v1); + graph.addVertex(v2); + graph.addVertex("3"); + graph.addVertex("4"); + graph.addVertex("5"); + graph.addVertex("6"); + graph.addVertex("7"); + graph.addVertex("8"); + graph.addVertex("9"); + + graph.addVertex("orphan"); + + // NOTE: set weights on some of the edges to test traversals like + // ClosestFirstIterator where it matters. For other traversals, it + // will be ignored. Rely on the default edge weight being 1. + graph.addEdge(v1, v2); + Graphs.addEdge(graph, v1, v3, 100); + Graphs.addEdge(graph, v2, v4, 1000); + graph.addEdge(v3, v5); + Graphs.addEdge(graph, v3, v6, 100); + graph.addEdge(v5, v6); + Graphs.addEdge(graph, v5, v7, 200); + graph.addEdge(v6, v1); + Graphs.addEdge(graph, v7, v8, 100); + graph.addEdge(v7, v9); + graph.addEdge(v8, v2); + graph.addEdge(v9, v4); + + return graph; + } + + abstract AbstractGraphIterator createIterator( + DirectedGraph g, + String startVertex); + + //~ Inner Classes ---------------------------------------------------------- + + /** + * Internal traversal listener. + * + * @author Barak Naveh + */ + private class MyTraversalListener + implements TraversalListener + { + private int componentNumber = 0; + private int numComponentVertices = 0; + + private String finishString = ""; + + /** + * @see TraversalListener#connectedComponentFinished(ConnectedComponentTraversalEvent) + */ + public void connectedComponentFinished( + ConnectedComponentTraversalEvent e) + { + switch (componentNumber) { + case 1: + assertEquals(getExpectedStr1(), result.toString()); + assertEquals(9, numComponentVertices); + + break; + + case 2: + assertEquals(getExpectedStr2(), result.toString()); + assertEquals(1, numComponentVertices); + + break; + + default: + assertFalse(); + + break; + } + + numComponentVertices = 0; + } + + /** + * @see TraversalListener#connectedComponentStarted(ConnectedComponentTraversalEvent) + */ + public void connectedComponentStarted( + ConnectedComponentTraversalEvent e) + { + componentNumber++; + } + + /** + * @see TraversalListener#edgeTraversed(EdgeTraversalEvent) + */ + public void edgeTraversed(EdgeTraversalEvent e) + { + // to be tested... + } + + /** + * @see TraversalListener#vertexTraversed(VertexTraversalEvent) + */ + public void vertexTraversed(VertexTraversalEvent e) + { + numComponentVertices++; + } + + /** + * @see TraversalListener#vertexTraversed(VertexTraversalEvent) + */ + public void vertexFinished(VertexTraversalEvent e) + { + finishString += e.getVertex() + ":"; + } + + public String getFinishString() + { + return finishString; + } + } +} + +// End AbstractGraphIteratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/AllTraverseTests.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/AllTraverseTests.java new file mode 100644 index 00000000..1025bc92 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/AllTraverseTests.java @@ -0,0 +1,81 @@ +/* ========================================== + * 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. + */ +/* ---------------- + * AllTraverseTests.java + * ---------------- + * (C) Copyright 2003-2008, by Barak Naveh and Contributors. + * + * Original Author: Barak Naveh + * Contributor(s): - + * + * $Id: AllTraverseTests.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 24-Jul-2003 : Initial revision (BN); + * + */ +package org.jgrapht.traverse; + +import junit.framework.*; + + +/** + * A TestSuite for all tests in this package. + * + * @author Barak Naveh + */ +public final class AllTraverseTests +{ + //~ Constructors ----------------------------------------------------------- + + private AllTraverseTests() + { + } // ensure non-instantiability. + + //~ Methods ---------------------------------------------------------------- + + /** + * Creates a test suite for all tests in this package. + * + * @return a test suite for all tests in this package. + */ + public static Test suite() + { + TestSuite suite = new TestSuite(); + + // $JUnit-BEGIN$ + suite.addTest(new TestSuite(BreadthFirstIteratorTest.class)); + suite.addTest(new TestSuite(DepthFirstIteratorTest.class)); + suite.addTest(new TestSuite(ClosestFirstIteratorTest.class)); + suite.addTest(new TestSuite(IgnoreDirectionTest.class)); + suite.addTest(new TestSuite(TopologicalOrderIteratorTest.class)); + + // $JUnit-END$ + return suite; + } +} + +// End AllTraverseTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/BreadthFirstIteratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/BreadthFirstIteratorTest.java new file mode 100644 index 00000000..f80f553b --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/BreadthFirstIteratorTest.java @@ -0,0 +1,84 @@ +/* ========================================== + * 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. + */ +/* ----------------------------- + * BreadthFirstIteratorTest.java + * ----------------------------- + * (C) Copyright 2003-2008, by Liviu Rau and Contributors. + * + * Original Author: Liviu Rau + * Contributor(s): Barak Naveh + * + * $Id: BreadthFirstIteratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 30-Jul-2003 : Initial revision (LR); + * 06-Aug-2003 : Test traversal listener & extract a shared superclass (BN); + * + */ +package org.jgrapht.traverse; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Tests for the {@link BreadthFirstIterator} class. + * + *

    NOTE: This test uses hard-coded expected ordering isn't really guaranteed + * by the specification of the algorithm. This could cause false failures if the + * traversal implementation changes.

    + * + * @author Liviu Rau + * @since Jul 30, 2003 + */ +public class BreadthFirstIteratorTest + extends AbstractGraphIteratorTest +{ + //~ Methods ---------------------------------------------------------------- + + String getExpectedStr1() + { + return "1,2,3,4,5,6,7,8,9"; + } + + String getExpectedStr2() + { + return "1,2,3,4,5,6,7,8,9,orphan"; + } + + AbstractGraphIterator createIterator( + DirectedGraph g, + String vertex) + { + AbstractGraphIterator i = + new BreadthFirstIterator(g, vertex); + i.setCrossComponentTraversal(true); + + return i; + } +} + +// End BreadthFirstIteratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/ClosestFirstIteratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/ClosestFirstIteratorTest.java new file mode 100644 index 00000000..c50f9dd7 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/ClosestFirstIteratorTest.java @@ -0,0 +1,129 @@ +/* ========================================== + * 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. + */ +/* ----------------------------- + * ClosestFirstIteratorTest.java + * ----------------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: ClosestFirstIteratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 03-Sep-2003 : Initial revision (JVS); + * 29-May-2005 : Test radius support (JVS); + * + */ +package org.jgrapht.traverse; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Tests for ClosestFirstIterator. + * + * @author John V. Sichi + * @since Sep 3, 2003 + */ +public class ClosestFirstIteratorTest + extends AbstractGraphIteratorTest +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testRadius() + { + result = new StringBuffer(); + + DirectedGraph graph = createDirectedGraph(); + + // NOTE: pick 301 as the radius because it discriminates + // the boundary case edge between v7 and v9 + AbstractGraphIterator iterator = + new ClosestFirstIterator(graph, "1", 301); + + while (iterator.hasNext()) { + result.append(iterator.next()); + + if (iterator.hasNext()) { + result.append(','); + } + } + + assertEquals("1,2,3,5,6,7", result.toString()); + } + + /** + * . + */ + public void testNoStart() + { + result = new StringBuffer(); + + DirectedGraph graph = createDirectedGraph(); + + AbstractGraphIterator iterator = + new ClosestFirstIterator(graph); + + while (iterator.hasNext()) { + result.append(iterator.next()); + + if (iterator.hasNext()) { + result.append(','); + } + } + + assertEquals("1,2,3,5,6,7,9,4,8,orphan", result.toString()); + } + + // NOTE: the edge weights make the result deterministic + String getExpectedStr1() + { + return "1,2,3,5,6,7,9,4,8"; + } + + String getExpectedStr2() + { + return getExpectedStr1() + ",orphan"; + } + + AbstractGraphIterator createIterator( + DirectedGraph g, + String vertex) + { + AbstractGraphIterator i = + new ClosestFirstIterator(g, vertex); + i.setCrossComponentTraversal(true); + + return i; + } +} + +// End ClosestFirstIteratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/DepthFirstIteratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/DepthFirstIteratorTest.java new file mode 100644 index 00000000..7a27296a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/DepthFirstIteratorTest.java @@ -0,0 +1,153 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * DepthFirstIteratorTest.java + * --------------------------- + * (C) Copyright 2003-2008, by Liviu Rau and Contributors. + * + * Original Author: Liviu Rau + * Contributor(s): Barak Naveh + * + * $Id: DepthFirstIteratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 30-Jul-2003 : Initial revision (LR); + * 06-Aug-2003 : Test traversal listener & extract a shared superclass (BN); + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Tests for the {@link DepthFirstIteratorTest} class. + * + *

    NOTE: This test uses hard-coded expected ordering isn't really guaranteed + * by the specification of the algorithm. This could cause false failures if the + * traversal implementation changes.

    + * + * @author Liviu Rau + * @since Jul 30, 2003 + */ +public class DepthFirstIteratorTest + extends AbstractGraphIteratorTest +{ + //~ Methods ---------------------------------------------------------------- + + String getExpectedStr1() + { + return "1,3,6,5,7,9,4,8,2"; + } + + String getExpectedStr2() + { + return "1,3,6,5,7,9,4,8,2,orphan"; + } + + String getExpectedFinishString() + { + return "6:4:9:2:8:7:5:3:1:orphan:"; + } + + AbstractGraphIterator createIterator( + DirectedGraph g, + String vertex) + { + AbstractGraphIterator i = + new DepthFirstIterator(g, vertex); + i.setCrossComponentTraversal(true); + + return i; + } + + /** + * See Sourceforge bug 1169182 + * for details. + */ + public void testBug1169182() + { + DirectedGraph dg = + new DefaultDirectedGraph(DefaultEdge.class); + + String a = "A"; + String b = "B"; + String c = "C"; + String d = "D"; + String e = "E"; + String f = "F"; + String g = "G"; + String h = "H"; + String i = "I"; + String j = "J"; + String k = "K"; + String l = "L"; + + dg.addVertex(a); + dg.addVertex(b); + dg.addVertex(c); + dg.addVertex(d); + dg.addVertex(e); + dg.addVertex(f); + dg.addVertex(g); + dg.addVertex(h); + dg.addVertex(i); + dg.addVertex(j); + dg.addVertex(k); + dg.addVertex(l); + + dg.addEdge(a, b); + dg.addEdge(b, c); + dg.addEdge(c, j); + dg.addEdge(c, d); + dg.addEdge(c, e); + dg.addEdge(c, f); + dg.addEdge(c, g); + dg.addEdge(d, h); + dg.addEdge(e, h); + dg.addEdge(f, i); + dg.addEdge(g, i); + dg.addEdge(h, j); + dg.addEdge(i, c); + dg.addEdge(j, k); + dg.addEdge(k, l); + + Iterator dfs = new DepthFirstIterator(dg); + String actual = ""; + while (dfs.hasNext()) { + String v = dfs.next(); + actual += v; + } + + String expected = "ABCGIFEHJKLD"; + assertEquals(expected, actual); + } +} + +// End DepthFirstIteratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/IgnoreDirectionTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/IgnoreDirectionTest.java new file mode 100644 index 00000000..abc601e3 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/IgnoreDirectionTest.java @@ -0,0 +1,92 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * IgnoreDirectionTest.java + * --------------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: IgnoreDirectionTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 08-Aug-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.traverse; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Tests for the ignoreDirection parameter to XXFirstIterator. + * + *

    NOTE: This test uses hard-coded expected ordering which isn't really + * guaranteed by the specification of the algorithm. This could cause spurious + * failures if the traversal implementation changes.

    + * + * @author John V. Sichi + * @since Aug 8, 2003 + */ +public class IgnoreDirectionTest + extends AbstractGraphIteratorTest +{ + //~ Methods ---------------------------------------------------------------- + + String getExpectedStr1() + { + return "4,9,7,8,2,1,3,6,5"; + } + + String getExpectedStr2() + { + return "4,9,7,8,2,1,3,6,5,orphan"; + } + + String getExpectedFinishString() + { + return "5:6:3:1:2:8:7:9:4:orphan:"; + } + + AbstractGraphIterator createIterator( + DirectedGraph g, + String vertex) + { + // ignore the passed in vertex and always start from v4, since that's + // the only vertex without out-edges + UndirectedGraph undirectedView = + new AsUndirectedGraph(g); + AbstractGraphIterator i = + new DepthFirstIterator(undirectedView, "4"); + i.setCrossComponentTraversal(true); + + return i; + } +} + +// End IgnoreDirectionTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/TopologicalOrderIteratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/TopologicalOrderIteratorTest.java new file mode 100644 index 00000000..dab9a170 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/traverse/TopologicalOrderIteratorTest.java @@ -0,0 +1,140 @@ +/* ========================================== + * 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. + */ +/* --------------------------- + * TopologicalOrderIteratorTest.java + * --------------------------- + * (C) Copyright 2005-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: TopologicalOrderIteratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + * 25-Apr-2005 : Initial revision (JVS); + * + */ +package org.jgrapht.traverse; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + + +/** + * Tests for TopologicalOrderIterator. + * + * @author John V. Sichi + * @since Apr 25, 2005 + */ +public class TopologicalOrderIteratorTest + extends EnhancedTestCase +{ + //~ Methods ---------------------------------------------------------------- + + /** + * . + */ + public void testRecipe() + { + DirectedGraph graph = + new DefaultDirectedGraph( + DefaultEdge.class); + + String [] v = new String[9]; + + v[0] = "preheat oven"; + v[1] = "sift dry ingredients"; + v[2] = "stir wet ingredients"; + v[3] = "mix wet and dry ingredients"; + v[4] = "spoon onto pan"; + v[5] = "bake"; + v[6] = "cool"; + v[7] = "frost"; + v[8] = "eat"; + + // add in mixed up order + graph.addVertex(v[4]); + graph.addVertex(v[8]); + graph.addVertex(v[1]); + graph.addVertex(v[3]); + graph.addVertex(v[7]); + graph.addVertex(v[6]); + graph.addVertex(v[0]); + graph.addVertex(v[2]); + graph.addVertex(v[5]); + + // specify enough edges to guarantee deterministic total order + graph.addEdge(v[0], v[1]); + graph.addEdge(v[1], v[2]); + graph.addEdge(v[0], v[2]); + graph.addEdge(v[1], v[3]); + graph.addEdge(v[2], v[3]); + graph.addEdge(v[3], v[4]); + graph.addEdge(v[4], v[5]); + graph.addEdge(v[5], v[6]); + graph.addEdge(v[6], v[7]); + graph.addEdge(v[7], v[8]); + graph.addEdge(v[6], v[8]); + + Iterator iter = + new TopologicalOrderIterator(graph); + int i = 0; + + while (iter.hasNext()) { + assertEquals(v[i], iter.next()); + ++i; + } + + // Test with a reversed view + DirectedGraph reversed = + new EdgeReversedGraph(graph); + + iter = new TopologicalOrderIterator(reversed); + i = v.length - 1; + + while (iter.hasNext()) { + assertEquals(v[i], iter.next()); + --i; + } + } + + /** + * . + */ + public void testEmptyGraph() + { + DirectedGraph graph = + new DefaultDirectedGraph( + DefaultEdge.class); + Iterator iter = + new TopologicalOrderIterator(graph); + assertFalse(iter.hasNext()); + } +} + +// End TopologicalOrderIteratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/AllUtilTests.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/AllUtilTests.java new file mode 100644 index 00000000..6d755e0d --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/AllUtilTests.java @@ -0,0 +1,65 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * AllUtilTests.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: AllUtilTests.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.util; + +import junit.framework.*; + +import org.jgrapht.experimental.equivalence.*; +import org.jgrapht.experimental.permutation.*; + + +public class AllUtilTests +{ + //~ Methods ---------------------------------------------------------------- + + public static Test suite() + { + TestSuite suite = new TestSuite("Test for org.jgrapht.util"); + + // $JUnit-BEGIN$ + suite.addTestSuite(FibonacciHeapTest.class); + suite.addTestSuite(PrefetchIteratorTest.class); + suite.addTestSuite(CompoundPermutationIterTest.class); + suite.addTestSuite(EquivalenceGroupCreatorTest.class); + + // $JUnit-END$ + return suite; + } +} + +// End AllUtilTests.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/FibonacciHeapTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/FibonacciHeapTest.java new file mode 100644 index 00000000..e0aec202 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/FibonacciHeapTest.java @@ -0,0 +1,96 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * FibonacciHeapTest.java + * ----------------- + * (C) Copyright 2008-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id: FibonacciHeapTest.java 603 2008-06-28 07:51:50Z perfecthash $ + * + * Changes + * ------- + * 20-Apr-2008 : Initial revision (JVS); + */ +package org.jgrapht.util; + +import java.util.*; + +import junit.framework.*; + + +public class FibonacciHeapTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + // in honor of sf.net bug #1845376 + public void testAddRemoveOne() + { + String s = "A"; + FibonacciHeapNode n = new FibonacciHeapNode(s, 1.0); + FibonacciHeap h = new FibonacciHeap(); + assertTrue(h.isEmpty()); + h.insert(n, n.getKey()); + assertFalse(h.isEmpty()); + FibonacciHeapNode n2 = h.removeMin(); + assertEquals(s, n2.getData()); + assertTrue(h.isEmpty()); + } + + public void testGrowReplaceShrink() + { + Random r = new Random(); + int k = 10000; + String s = "A"; + double t = 0; + FibonacciHeap h = new FibonacciHeap(); + for (int i = 0; i < (k * 3); ++i) { + // during first two-thirds, insert + if (i < (k * 2)) { + double d = r.nextDouble(); + t += d; + FibonacciHeapNode n = + new FibonacciHeapNode(s, d); + h.insert(n, n.getKey()); + } + + // during last two-thirds, delete (so during middle + // third, we'll do both insert and delete, interleaved) + if (i >= k) { + FibonacciHeapNode n2 = h.removeMin(); + t -= n2.getKey(); + } + } + assertTrue(h.isEmpty()); + + // tally should come back down to zero, or thereabouts (due to roundoff) + assertEquals(0.0, t, 0.00001); + } +} + +// End FibonacciHeapTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/PrefetchIteratorTest.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/PrefetchIteratorTest.java new file mode 100644 index 00000000..a952369a --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/PrefetchIteratorTest.java @@ -0,0 +1,141 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * PrefetchIteratorTest.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: PrefetchIteratorTest.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.util; + +import java.util.*; + +import junit.framework.*; + + +public class PrefetchIteratorTest + extends TestCase +{ + //~ Methods ---------------------------------------------------------------- + + public void testIteratorInterface() + { + Iterator iterator = new IterateFrom1To99(); + for (int i = 1; i < 100; i++) { + assertEquals(true, iterator.hasNext()); + assertEquals(i, iterator.next()); + } + assertEquals(false, iterator.hasNext()); + Exception exceptionThrown = null; + try { + iterator.next(); + } catch (Exception e) { + exceptionThrown = e; + } + assertTrue(exceptionThrown instanceof NoSuchElementException); + } + + public void testEnumInterface() + { + Enumeration enumuration = new IterateFrom1To99(); + for (int i = 1; i < 100; i++) { + assertEquals(true, enumuration.hasMoreElements()); + assertEquals(i, enumuration.nextElement()); + } + assertEquals(false, enumuration.hasMoreElements()); + Exception exceptionThrown = null; + try { + enumuration.nextElement(); + } catch (Exception e) { + exceptionThrown = e; + } + assertTrue(exceptionThrown instanceof NoSuchElementException); + } + + //~ Inner Classes ---------------------------------------------------------- + + // This test class supplies enumeration of integer from 1 till 100. + public static class IterateFrom1To99 + implements Enumeration, + Iterator + { + private int counter = 0; + private PrefetchIterator nextSupplier; + + public IterateFrom1To99() + { + nextSupplier = + new PrefetchIterator( + new PrefetchIterator.NextElementFunctor() { + public Integer 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(); + } + + public Object next() + { + return this.nextSupplier.next(); + } + + public boolean hasNext() + { + return this.nextSupplier.hasNext(); + } + + public void remove() + { + this.nextSupplier.remove(); + } + } +} + +// End PrefetchIteratorTest.java diff --git a/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/StopWatch.java b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/StopWatch.java new file mode 100644 index 00000000..bc1ff2b4 --- /dev/null +++ b/ss2010/gdi2/java/libs/jgrapht/testsrc/org/jgrapht/util/StopWatch.java @@ -0,0 +1,74 @@ +/* ========================================== + * 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. + */ +/* ----------------- + * StopWatch.java + * ----------------- + * (C) Copyright 2005-2008, by Assaf Lehr and Contributors. + * + * Original Author: Assaf Lehr + * Contributor(s): - + * + * $Id: StopWatch.java 645 2008-09-30 19:44:48Z perfecthash $ + * + * Changes + * ------- + */ +package org.jgrapht.util; + +/** + * @author Assaf + * @since May 30, 2005 + */ +public class StopWatch +{ + //~ Instance fields -------------------------------------------------------- + + long beforeTime; + + //~ Methods ---------------------------------------------------------------- + + public void start() + { + this.beforeTime = System.currentTimeMillis(); + } + + public void stopAndReport() + { + long deltaTime = System.currentTimeMillis() - beforeTime; + if (deltaTime > 9999) { + double deltaTimeSec = deltaTime / 1000.0; + System.out.println( + "# Performence: " + deltaTimeSec + " full Seconds"); + } else { + String timeDesc; + timeDesc = + (deltaTime <= 10) ? "<10ms [less than minumun measurement time]" + : String.valueOf(deltaTime); + System.out.println("# Performence: in MiliSeconds:" + timeDesc); + } + } +} + +// End StopWatch.java diff --git a/ss2010/gdi2/java/libs/jl/jl1.0.1.jar b/ss2010/gdi2/java/libs/jl/jl1.0.1.jar new file mode 100644 index 00000000..bd5fb8b8 Binary files /dev/null and b/ss2010/gdi2/java/libs/jl/jl1.0.1.jar differ diff --git a/ss2010/gdi2/java/libs/translator/translator.jar b/ss2010/gdi2/java/libs/translator/translator.jar new file mode 100644 index 00000000..683910fa Binary files /dev/null and b/ss2010/gdi2/java/libs/translator/translator.jar differ diff --git a/ws2009/tgdi/practical/TGDI Practical/.classpath b/ws2009/tgdi/practical/TGDI Practical/.classpath new file mode 100644 index 00000000..fb501163 --- /dev/null +++ b/ws2009/tgdi/practical/TGDI Practical/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ws2009/tgdi/practical/TGDI Practical/.project b/ws2009/tgdi/practical/TGDI Practical/.project new file mode 100644 index 00000000..a1fed82a --- /dev/null +++ b/ws2009/tgdi/practical/TGDI Practical/.project @@ -0,0 +1,17 @@ + + + TGdi Practical + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ws2009/tgdi/practical/TGDI Practical/.settings/org.eclipse.jdt.core.prefs b/ws2009/tgdi/practical/TGDI Practical/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..d3b733b7 --- /dev/null +++ b/ws2009/tgdi/practical/TGDI Practical/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Jan 21 13:47:28 CET 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/ws2009/tgdi/practical/TGDI Practical/src/tgdip.java b/ws2009/tgdi/practical/TGDI Practical/src/tgdip.java new file mode 100644 index 00000000..c2d5647e --- /dev/null +++ b/ws2009/tgdi/practical/TGDI Practical/src/tgdip.java @@ -0,0 +1,61 @@ + +public class tgdip { + + public static int[] matrix = {3, 4, 5, 9, 4, 9, 1, 2, 2}; + public static int matrixsize = 3; + + public int[] calcnewmatrix(int pos, int size, int[] matrix) + { + int[] newmatrix = new int[(size-1)*(size-1)]; + + for(int i=1; i < size;i++) //rows -> i*(size) -> start from row 1! + { + for(int j=0; j < size;j++) //lines -> j*1 + { + int rowval = i*(size); + int lineval = j; //verschiebung um 1 nach rechts! + + if(lineval != pos) //skip pos + { + int newrowval = (i-1)*(size-1); //wird um 1 kleiner + int newlineval = j; + + if(newlineval > pos) //correct actpos after skip pos + { + newlineval -= 1; + } + + newmatrix[newrowval + newlineval] = matrix[rowval+lineval]; + } + } + } + + return newmatrix; + } + + public int calcdet(int size, int[] matrix) + { + //anchor + if(size <= 1) + { + return matrix[0]; + } + + int result = 0; + + for(int i=0; i