diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 00000000000..ef10618e988 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,55 @@ +## Contributors ## + +JGraphT wouldn't be the library it is today without the source contributions and suggestions made by the authors: + +- [Barak Naveh](http://sourceforge.net/users/barak_naveh/) (project founder) +- [John V Sichi](http://sourceforge.net/users/perfecthash/) (current project administrator) +- [Liviu Rau](http://sourceforge.net/users/liviu_aurelian/) +- [Nathan Fiedler](http://www.bluemarsh.com/personal/index.html) +- [Michael Behrisch](http://sourceforge.net/users/behrisch/) +- [Linda Buisman](http://sourceforge.net/users/linda_buisman/) +- Erik Postma +- Mikael Hansen +- Avner Linder +- Marden Neubert +- [Christian Soltenborn](http://sourceforge.net/users/csoltenborn/) +- [Christian Hammer](http://sourceforge.net/users/hammerc/) +- Ewgenij Proschak +- [Hartmut Benz](http://sourceforge.net/users/ivins/) +- [Charles Fry](http://frogcircus.org/) +- Guillaume Boulmier +- Carl Anderson +- Khanh Vu +- Aaron Harnly +- Dimitrios Michail +- Welson Sun +- Trevor Harmon +- David Black-Schaffer +- Vinayak Borkar +- Andrew Berman +- Lucas Scharenbroich +- Hookahey +- Tim Shearouse +- Holger Brandl +- Ilya Razenshteyn +- Peter Giles +- Andrew Newell +- Tim Engler +- Tom Larkworthy +- Soren Davidsen +- Andrea Pagani +- Tom Conerly +- Michele Mancioppi +- Adrian Marte +- Assaf Mizrachi +- Harshal Vora +- Matt Sarjent +- Robby McKilliam +- Yuriy Nakonechnyy +- Alejandro R. Lopez del Huerto + +(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. \ No newline at end of file diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 00000000000..c1a6babff50 --- /dev/null +++ b/HISTORY.md @@ -0,0 +1,138 @@ +# HISTORY # + +Changes to JGraphT in each version: + +- **version 0.8.4** (under development): + - Move to github for source control, and Apache Maven for build, contributed by Andreas Schnaiter and Owen Jacobson. + - Add source/target vertices to edge events to fix sf.net bug 3486775, spotted by Frank Mori Hess. + - Add EdmondsBlossomShrinking algorithm, contributed by Alejandro R. Lopez del Huerto. + + +- **version 0.8.3** (20-Jan-2012): + - fix regression in `DOTExporter` inadvertently introduced by `0.8.2` changes. + - Add `GridGraphGenerator`, contributed by Assaf Mizrachi. + - Return coloring from ChromaticNumber, contributed by Harshal Vora. + - Fix bugs in KSP, contributed by Guillaume Boulmier; note that these bugfixes worsen the running time. + - Fix an object identity bug in CycleDetector, contributed by Matt Sarjent. + -Add StoerWagnerMinimumCut, contributed by Robby McKilliam. + - Fix `MANIFEST.MF`, spotted by Olly. + - Make `FloydWarshallShortestPaths.getShortestPaths` unidirectional, contributed by Yuriy Nakonechnyy. + +- **version 0.8.2** (27-Nov-2010): + - Clean up `FibonacciHeapNode` constructor, as suggested by Johan +Henriksson. + - Optimize and enhance `FloydWarshallShortestPaths`, contributed by Soren Davidsen. + - Optimize `ChromaticNumber`,pointed out by gpaschos@netscape.net. + - Add unit test for `FloydWarshallShortestPaths` for bug noticed by +Andrea Pagani. + - Add vertex factory validation to `RandomGraphGenerator` to prevent a confusing problem encountered by Andrea Pagani. + - Add `KruskalMinimumSpanningTree` and `UnionFind`, contributed by Tom Conerly. + - Add attributes to `DOTExporter`, based on suggestion from Chris Lott. + - Fix inefficient assertion in `TopologicalOrderIterator`, spotted by +Peter Lawrey. + - Fix induced subgraph bug with addition of edge to underlying graph, contributed by Michele Mancioppi. + - Make `getEdgeWeight` delegate to `DefaultWeightedEdge.getWeight`, spotted by Michael Lindig. + - Add maven support, contributed by Adrian Marte. + +- **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. + - Add `GraphUnion` (with directed and undirected variants), contributed by Ilya Razenshteyn. + +- **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 + - improved ant build + - 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. \ No newline at end of file diff --git a/README.html b/README.html deleted file mode 100644 index 28441a4df7b..00000000000 --- a/README.html +++ /dev/null @@ -1,658 +0,0 @@ - - - - - - - - - - - JGraphT Release Notes - - - - -


JGraphT� 0.8.3
-

� - -

Released: January, 2012

- -

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

- -

(C) Copyright 2003-2012, by Barak Naveh and Contributors. All rights - reserved.

- -

Please address all contributions, suggestions, and inquiries to the - current project administrator, John Sichi.

- -

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:

- - - -

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

- - - -

Online Resources

- -

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

- - - -

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:

- - - -

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/README.md b/README.md new file mode 100644 index 00000000000..f71d7c99921 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# JGraphtT + +Released: January, 2012

+ +Written by [Barak Naveh](mailto:barak_naveh@users.sourceforge.net) and Contributors + +(C) Copyright 2003-2012, by Barak Naveh and Contributors. All rights +reserved. + +Please address all contributions, suggestions, and inquiries to the current project administrator [John Sichi](mailto:perfecthash@users.sf.net) + +## 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](license-LGPL.txt) 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 ## + +- `README.md` this file +- `CONTRIBUTORS.md` list of contributors +- `HISTORY.md` changelog +- `licence-LGPL.txt` GNU Lesser General Public License +- `javadoc/` Javadoc documentation +- `lib/` JGraphT libraries: +- `jgrapht-core-x.y.z.jar` core library +- `jgrapht-demo-x.y.z.jar` demo classes +- `jgrapht-ext-x.y.z.jar` extensions +- `jgrapht-x.y.z-combined.jar` all libraries rolled into one +- `jgraph-a.b.c.jar` JGraph dependency library +- `source/` complete source tree used to build this release +- `pom.xml` Maven project file + +## 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](HISTORY.md) 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](http://www.jgrapht.org/javadoc). + +## Dependencies ## + +- JGraphT requires JDK 1.6 or later to build. +- [JUnit](http://www.junit.org) is a unit testing framework. You need JUnit only if you want to run the unit tests. JUnit is licensed under the terms of the IBM Common Public License. The JUnit tests included with JGraphT have been created using JUnit `3.8.1`. +- [XMLUnit](http://xmlunit.sourceforge.net) extends JUnit with XML capabilities. You need XMLUnit only if you want to run the unit tests. XMLUnit is licensed under the terms of the BSD + License. +- [JGraph](http://sourceforge.net/projects/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. JGraph is licensed under the terms of the GNU Lesser General Public License (LGPL). +- [Touchgraph](http://sourceforge.net/projects/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. Touchgraph is licensed under the terms of an Apache-style License. + +## Online Resources ## + +The JGraphT website is at [http://www.jgrapht.org](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](http://wiki.jgrapht.org) set up for everyone in the JGraphT community to share information about the project. + +Source code is hosted on [github](https://github.com/lingeringsocket/jgrapht). You can send contributions as pull requests there. + +## Your Improvements ## + +If you add improvements to JGraphT please send them to us as pull requests on github. 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. + +## Thanks ## + +With regards from + +[Barak Naveh](mailto:barak_naveh@users.sourceforge.net), JGraphT Project Creator + +[John Sichi](mailto:perfecthash@users.sourceforge.net), JGraphT Project Administrator \ No newline at end of file diff --git a/etc/pom.xml.template b/etc/pom.xml.template deleted file mode 100644 index 9349659f50b..00000000000 --- a/etc/pom.xml.template +++ /dev/null @@ -1,91 +0,0 @@ - - 4.0.0 - - net.sf.jgrapht - jgrapht - jar - JGraphT - @VERSION@ - A Java class library for graph-theory data structures - and algorithms. - http://www.jgrapht.org - - - GNU Lesser General Public License Version 2.1, February 1999 - http://jgrapht.sourceforge.net/LGPL.html - repo - - - - http://jgrapht.svn.sourceforge.net/svnroot/jgrapht - - - - - 1.6 - - - 5.13.0.0 - - ${basedir}/src - ${basedir}/testsrc - org/jgrapht/experimental/touchgraph/**/*.java - - UTF-8 - UTF-8 - - - - - jgraph - jgraph - ${jgraph.version} - - - - xmlunit - xmlunit - 1.3 - test - - - - junit - junit - 4.8.1 - test - - - - - ${jgrapht.sourceDirectory} - ${jgrapht.testSourceDirectory} - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - ${compiler.version} - ${compiler.version} - - - ${jgrapht.touchgraph.filter} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.6 - - false - - - - - diff --git a/etc/release-process.html b/etc/release-process.html index 6f2cb339b8a..37aa14c8732 100644 --- a/etc/release-process.html +++ b/etc/release-process.html @@ -139,7 +139,7 @@

JGraphUpdate the new version number and SVN tag in the build.xml file. -
  • Review the README.html and META-INF/MANIFEST.MF files and update: +
  • Review the README.md, HISTORY.md, CONTRIBUTORS.md, and META-INF/MANIFEST.MF files and update:
    • Version
    • Dependencies @@ -149,7 +149,7 @@

      JGraphReview/update the bug/feature trackers to make sure they reflect the current state. If there were important bug/feature changes, it is worth -mentioning them in the README.html release notes. +mentioning them in the README.md release notes.
    • Bring dependent libraries (e.g. JGraph) up to date and update lib/lib-readme.txt accordingly. diff --git a/jgrapht-core/src/main/java/org/jgrapht/alg/DirectedNeighborIndex.java b/jgrapht-core/src/main/java/org/jgrapht/alg/DirectedNeighborIndex.java index 94fe7d7c5ea..fdf755711e7 100644 --- a/jgrapht-core/src/main/java/org/jgrapht/alg/DirectedNeighborIndex.java +++ b/jgrapht-core/src/main/java/org/jgrapht/alg/DirectedNeighborIndex.java @@ -178,8 +178,8 @@ public void edgeAdded(GraphEdgeChangeEvent e) public void edgeRemoved(GraphEdgeChangeEvent e) { E edge = e.getEdge(); - V source = graph.getEdgeSource(edge); - V target = graph.getEdgeTarget(edge); + V source = e.getEdgeSource(); + V target = e.getEdgeTarget(); if (successorMap.containsKey(source)) { successorMap.get(source).removeNeighbor(target); } diff --git a/jgrapht-core/src/main/java/org/jgrapht/alg/EdmondsBlossomShrinking.java b/jgrapht-core/src/main/java/org/jgrapht/alg/EdmondsBlossomShrinking.java new file mode 100644 index 00000000000..866b4d37f99 --- /dev/null +++ b/jgrapht-core/src/main/java/org/jgrapht/alg/EdmondsBlossomShrinking.java @@ -0,0 +1,194 @@ +/* ========================================== + * 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-2012, 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. + */ +/* ------------------------- + * EdmondsBlossomShrinking.java + * ------------------------- + * (C) Copyright 2012-2012, by Alejandro Ramon Lopez del Huerto and Contributors. + * + * Original Author: Alejandro Ramon Lopez del Huerto + * Contributor(s): + * + * Changes + * ------- + * 24-Jan-2012 : Initial revision (ARLH); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import org.jgrapht.*; +import org.jgrapht.util.*; + +/** + * An implementation of Edmonds Blossom Shrinking algorithm for constructing + * maximum matchings on graphs. The algorithm runs in time O(V^4). + * + * @author Alejandro R. Lopez del Huerto + * @since Jan 24, 2012 + */ +public class EdmondsBlossomShrinking +{ + // ~ Instance fields + // -------------------------------------------------------- + + private Map match; + private Map p; + private Map base; + private Queue q; + private Set used; + private Set blossom; + + // ~ Methods + // ---------------------------------------------------------------- + + /** + * Runs the algorithm on the input graph and returns the match edge set. + * + * @param g + * The graph to be matched + * @return set of Edges + */ + public Set findMatch(final UndirectedGraph g) + { + Set result = new ArrayUnenforcedSet(); + match = new HashMap(); + p = new HashMap(); + q = new ArrayDeque(); + base = new HashMap(); + used = new HashSet(); + blossom = new HashSet(); + + for (V i : g.vertexSet()) { + if (!match.containsKey(i)) { + V v = findPath(g, i); + while (v != null) { + V pv = p.get(v); + V ppv = match.get(pv); + match.put(v, pv); + match.put(pv, v); + v = ppv; + } + } + } + + Set seen = new HashSet(); + for (V v : g.vertexSet()) { + if (!seen.contains(v) && match.containsKey(v)) { + seen.add(v); + seen.add(match.get(v)); + result.add(g.getEdge(v, match.get(v))); + } + } + + return result; + } + + private V findPath(UndirectedGraph g, V root) + { + used.clear(); + p.clear(); + base.clear(); + + for (V i : g.vertexSet()) { + base.put(i, i); + } + + used.add(root); + q.add(root); + while (!q.isEmpty()) { + V v = q.remove(); + for (V to : g.vertexSet()) { + if (!g.containsEdge(v, to)) { + continue; + } + + if ((base.get(v) == base.get(to)) || (match.get(v) == to)) { + continue; + } + if (to == root || (match.containsKey(to)) + && (p.containsKey(match.get(to)))) { + V curbase = lca(g, v, to); + blossom.clear(); + markPath(g, v, curbase, to); + markPath(g, to, curbase, v); + + for (V i : g.vertexSet()) { + if (base.containsKey(i) + && blossom.contains(base.get(i))) + { + base.put(i, curbase); + if (!used.contains(i)) { + used.add(i); + q.add(i); + } + } + } + } else if (!p.containsKey(to)) { + p.put(to, v); + if (!match.containsKey(to)) { + return to; + } + to = match.get(to); + used.add(to); + q.add(to); + } + } + } + return null; + } + + private void markPath(UndirectedGraph g, V v, V b, V children) + { + while (base.get(v) != b) { + blossom.add(base.get(v)); + blossom.add(base.get(match.get(v))); + p.put(v, children); + children = match.get(v); + v = p.get(match.get(v)); + } + } + + private V lca(UndirectedGraph g, V a, V b) + { + Set seen = new HashSet(); + for (;;) { + a = base.get(a); + seen.add(a); + if (!match.containsKey(a)) { + break; + } + a = p.get(match.get(a)); + } + for (;;) { + b = base.get(b); + if (seen.contains(b)) { + return b; + } + b = p.get(match.get(b)); + } + } + +} diff --git a/jgrapht-core/src/main/java/org/jgrapht/alg/NeighborIndex.java b/jgrapht-core/src/main/java/org/jgrapht/alg/NeighborIndex.java index 4c654ae4329..36bfa821549 100644 --- a/jgrapht-core/src/main/java/org/jgrapht/alg/NeighborIndex.java +++ b/jgrapht-core/src/main/java/org/jgrapht/alg/NeighborIndex.java @@ -149,8 +149,8 @@ public void edgeAdded(GraphEdgeChangeEvent e) public void edgeRemoved(GraphEdgeChangeEvent e) { E edge = e.getEdge(); - V source = graph.getEdgeSource(edge); - V target = graph.getEdgeTarget(edge); + V source = e.getEdgeSource(); + V target = e.getEdgeTarget(); if (neighborMap.containsKey(source)) { neighborMap.get(source).removeNeighbor(target); } diff --git a/jgrapht-core/src/main/java/org/jgrapht/event/GraphEdgeChangeEvent.java b/jgrapht-core/src/main/java/org/jgrapht/event/GraphEdgeChangeEvent.java index 226f8ed7c3f..bfe47c0b741 100644 --- a/jgrapht-core/src/main/java/org/jgrapht/event/GraphEdgeChangeEvent.java +++ b/jgrapht-core/src/main/java/org/jgrapht/event/GraphEdgeChangeEvent.java @@ -87,6 +87,16 @@ public class GraphEdgeChangeEvent */ protected E edge; + /** + * The source vertex of the edge that this event is related to. + */ + protected V edgeSource; + + /** + * The target vertex of the edge that this event is related to. + */ + protected V edgeTarget; + //~ Constructors ----------------------------------------------------------- /** @@ -94,12 +104,33 @@ public class 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. + * @param edge the edge that this event is related to. + * + * @deprecated Use new constructor which takes vertex parameters. + */ + public GraphEdgeChangeEvent( + Object eventSource, int type, E edge) + { + this(eventSource, type, edge, null, null); + } + + /** + * Constructor for GraphEdgeChangeEvent. + * + * @param eventSource the source of this event. + * @param type the event type of this event. + * @param edge the edge that this event is related to. + * @param edgeSource edge source vertex + * @param edgeTarget edge target vertex */ - public GraphEdgeChangeEvent(Object eventSource, int type, E e) + public GraphEdgeChangeEvent( + Object eventSource, int type, E edge, + V edgeSource, V edgeTarget) { super(eventSource, type); - edge = e; + this.edge = edge; + this.edgeSource = edgeSource; + this.edgeTarget = edgeTarget; } //~ Methods ---------------------------------------------------------------- @@ -107,12 +138,32 @@ public GraphEdgeChangeEvent(Object eventSource, int type, E e) /** * Returns the edge that this event is related to. * - * @return the edge that this event is related to. + * @return event edge */ public E getEdge() { return edge; } + + /** + * Returns the source vertex that this event is related to. + * + * @return event source vertex + */ + public V getEdgeSource() + { + return edgeSource; + } + + /** + * Returns the target vertex that this event is related to. + * + * @return event target vertex + */ + public V getEdgeTarget() + { + return edgeTarget; + } } // End GraphEdgeChangeEvent.java diff --git a/jgrapht-core/src/main/java/org/jgrapht/graph/DefaultListenableGraph.java b/jgrapht-core/src/main/java/org/jgrapht/graph/DefaultListenableGraph.java index f1b78bc90ef..d13173268ff 100644 --- a/jgrapht-core/src/main/java/org/jgrapht/graph/DefaultListenableGraph.java +++ b/jgrapht-core/src/main/java/org/jgrapht/graph/DefaultListenableGraph.java @@ -79,9 +79,9 @@ public class DefaultListenableGraph //~ Instance fields -------------------------------------------------------- - private ArrayList> graphListeners = + private List> graphListeners = new ArrayList>(); - private ArrayList> vertexSetListeners = + private List> vertexSetListeners = new ArrayList>(); private FlyweightEdgeEvent reuseableEdgeEvent; private FlyweightVertexEvent reuseableVertexEvent; @@ -165,7 +165,7 @@ public E addEdge(V sourceVertex, V targetVertex) E e = super.addEdge(sourceVertex, targetVertex); if (e != null) { - fireEdgeAdded(e); + fireEdgeAdded(e, sourceVertex, targetVertex); } return e; @@ -179,7 +179,7 @@ public boolean addEdge(V sourceVertex, V targetVertex, E e) boolean added = super.addEdge(sourceVertex, targetVertex, e); if (added) { - fireEdgeAdded(e); + fireEdgeAdded(e, sourceVertex, targetVertex); } return added; @@ -244,7 +244,7 @@ public E removeEdge(V sourceVertex, V targetVertex) E e = super.removeEdge(sourceVertex, targetVertex); if (e != null) { - fireEdgeRemoved(e); + fireEdgeRemoved(e, sourceVertex, targetVertex); } return e; @@ -255,10 +255,13 @@ public E removeEdge(V sourceVertex, V targetVertex) */ public boolean removeEdge(E e) { + V sourceVertex = getEdgeSource(e); + V targetVertex = getEdgeTarget(e); + boolean modified = super.removeEdge(e); if (modified) { - fireEdgeRemoved(e); + fireEdgeRemoved(e, sourceVertex, targetVertex); } return modified; @@ -305,15 +308,19 @@ public void removeVertexSetListener(VertexSetListener l) * Notify listeners that the specified edge was added. * * @param edge the edge that was added. + * + * @param source edge source + * + * @param target edge target */ - protected void fireEdgeAdded(E edge) + protected void fireEdgeAdded(E edge, V source, V target) { GraphEdgeChangeEvent e = - createGraphEdgeChangeEvent(GraphEdgeChangeEvent.EDGE_ADDED, edge); - - for (int i = 0; i < graphListeners.size(); i++) { - GraphListener l = graphListeners.get(i); + createGraphEdgeChangeEvent( + GraphEdgeChangeEvent.EDGE_ADDED, + edge, source, target); + for (GraphListener l : graphListeners) { l.edgeAdded(e); } } @@ -322,17 +329,19 @@ protected void fireEdgeAdded(E edge) * Notify listeners that the specified edge was removed. * * @param edge the edge that was removed. + * + * @param source edge source + * + * @param target edge target */ - protected void fireEdgeRemoved(E edge) + protected void fireEdgeRemoved(E edge, V source, V target) { GraphEdgeChangeEvent e = createGraphEdgeChangeEvent( GraphEdgeChangeEvent.EDGE_REMOVED, - edge); - - for (int i = 0; i < graphListeners.size(); i++) { - GraphListener l = graphListeners.get(i); + edge, source, target); + for (GraphListener l : graphListeners) { l.edgeRemoved(e); } } @@ -349,15 +358,11 @@ protected void fireVertexAdded(V vertex) GraphVertexChangeEvent.VERTEX_ADDED, vertex); - for (int i = 0; i < vertexSetListeners.size(); i++) { - VertexSetListener l = vertexSetListeners.get(i); - + for (VertexSetListener l : vertexSetListeners) { l.vertexAdded(e); } - for (int i = 0; i < graphListeners.size(); i++) { - GraphListener l = graphListeners.get(i); - + for (GraphListener l : graphListeners) { l.vertexAdded(e); } } @@ -374,15 +379,11 @@ protected void fireVertexRemoved(V vertex) GraphVertexChangeEvent.VERTEX_REMOVED, vertex); - for (int i = 0; i < vertexSetListeners.size(); i++) { - VertexSetListener l = vertexSetListeners.get(i); - + for (VertexSetListener l : vertexSetListeners) { l.vertexRemoved(e); } - for (int i = 0; i < graphListeners.size(); i++) { - GraphListener l = graphListeners.get(i); - + for (GraphListener l : graphListeners) { l.vertexRemoved(e); } } @@ -397,16 +398,18 @@ private static void addToListenerList( } private GraphEdgeChangeEvent createGraphEdgeChangeEvent( - int eventType, - E edge) + int eventType, E edge, V source, V target) { if (reuseEvents) { reuseableEdgeEvent.setType(eventType); reuseableEdgeEvent.setEdge(edge); + reuseableEdgeEvent.setEdgeSource(source); + reuseableEdgeEvent.setEdgeTarget(target); return reuseableEdgeEvent; } else { - return new GraphEdgeChangeEvent(this, eventType, edge); + return new GraphEdgeChangeEvent( + this, eventType, edge, source, target); } } @@ -455,6 +458,16 @@ protected void setEdge(EE e) this.edge = e; } + protected void setEdgeSource(VV v) + { + this.edgeSource = v; + } + + protected void setEdgeTarget(VV v) + { + this.edgeTarget = v; + } + /** * Set the event type of this event. * diff --git a/jgrapht-core/src/main/java/org/jgrapht/graph/DirectedGraphUnion.java b/jgrapht-core/src/main/java/org/jgrapht/graph/DirectedGraphUnion.java index 363312152e1..b151370790a 100644 --- a/jgrapht-core/src/main/java/org/jgrapht/graph/DirectedGraphUnion.java +++ b/jgrapht-core/src/main/java/org/jgrapht/graph/DirectedGraphUnion.java @@ -54,7 +54,7 @@ public class DirectedGraphUnion //~ Constructors ----------------------------------------------------------- - DirectedGraphUnion( + public DirectedGraphUnion( DirectedGraph g1, DirectedGraph g2, WeightCombiner operator) @@ -62,7 +62,7 @@ public class DirectedGraphUnion super(g1, g2, operator); } - DirectedGraphUnion(DirectedGraph g1, DirectedGraph g2) + public DirectedGraphUnion(DirectedGraph g1, DirectedGraph g2) { super(g1, g2); } diff --git a/jgrapht-core/src/main/java/org/jgrapht/graph/Subgraph.java b/jgrapht-core/src/main/java/org/jgrapht/graph/Subgraph.java index 24c1a3d384e..bfb7da5bf19 100644 --- a/jgrapht-core/src/main/java/org/jgrapht/graph/Subgraph.java +++ b/jgrapht-core/src/main/java/org/jgrapht/graph/Subgraph.java @@ -502,8 +502,8 @@ public void edgeAdded(GraphEdgeChangeEvent e) { if (isInduced) { E edge = e.getEdge(); - V source = base.getEdgeSource(edge); - V target = base.getEdgeTarget(edge); + V source = e.getEdgeSource(); + V target = e.getEdgeTarget(); if (containsVertex(source) && containsVertex(target)) { addEdge( source, diff --git a/jgrapht-core/src/test/java/org/jgrapht/alg/AllAlgTests.java b/jgrapht-core/src/test/java/org/jgrapht/alg/AllAlgTests.java index 80634e57b23..816f135456d 100644 --- a/jgrapht-core/src/test/java/org/jgrapht/alg/AllAlgTests.java +++ b/jgrapht-core/src/test/java/org/jgrapht/alg/AllAlgTests.java @@ -90,6 +90,7 @@ public static Test suite() suite.addTest(new TestSuite(HamiltonianCycleTest.class)); suite.addTest(new TestSuite(KruskalMinimumSpanningTreeTest.class)); suite.addTest(new TestSuite(StoerWagnerMinimumCutTest.class)); + suite.addTest(new TestSuite(EdmondsBlossomShrinkingTest.class)); // $JUnit-END$ return suite; diff --git a/jgrapht-core/src/test/java/org/jgrapht/alg/EdmondsBlossomShrinkingTest.java b/jgrapht-core/src/test/java/org/jgrapht/alg/EdmondsBlossomShrinkingTest.java new file mode 100644 index 00000000000..b1c90171273 --- /dev/null +++ b/jgrapht-core/src/test/java/org/jgrapht/alg/EdmondsBlossomShrinkingTest.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-2012, 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. + */ +/* ------------------------- + * EdmondsBlossomShrinkingTest.java + * ------------------------- + * (C) Copyright 2012-2012, by Alejandro Ramon Lopez del Huerto and Contributors. + * + * Original Author: Alejandro Ramon Lopez del Huerto + * Contributor(s): + * + * Changes + * ------- + * 24-Jan-2012 : Initial revision (ARLH); + * + */ +package org.jgrapht.alg; + +import java.util.*; + +import junit.framework.*; + +import org.jgrapht.*; +import org.jgrapht.graph.*; + +/** + * . + * + * @author Alejandro R. Lopez del Huerto + * @since Jan 24, 2012 + */ +public final class EdmondsBlossomShrinkingTest extends TestCase +{ + public void testOne() + { + // create an undirected graph + UndirectedGraph g = + new SimpleGraph(DefaultEdge.class); + + Integer v1 = 1; + Integer v2 = 2; + Integer v3 = 3; + Integer v4 = 4; + + g.addVertex(v1); + g.addVertex(v2); + g.addVertex(v3); + g.addVertex(v4); + + DefaultEdge e12 = g.addEdge(v1, v2); + DefaultEdge e23 = g.addEdge(v2, v3); + DefaultEdge e24 = g.addEdge(v2, v4); + DefaultEdge e34 = g.addEdge(v3, v4); + + // compute max match + EdmondsBlossomShrinking matcher = + new EdmondsBlossomShrinking(); + Set match = matcher.findMatch(g); + assertEquals(2, match.size()); + assertTrue(match.contains(e12)); + assertTrue(match.contains(e34)); + } +} diff --git a/jgrapht-core/src/test/java/org/jgrapht/alg/NeighborIndexTest.java b/jgrapht-core/src/test/java/org/jgrapht/alg/NeighborIndexTest.java index 32bca6f57a1..a38b99935bf 100644 --- a/jgrapht-core/src/test/java/org/jgrapht/alg/NeighborIndexTest.java +++ b/jgrapht-core/src/test/java/org/jgrapht/alg/NeighborIndexTest.java @@ -63,16 +63,19 @@ public class NeighborIndexTest public void testNeighborSet() { - ListenableUndirectedGraph g = - new ListenableUndirectedGraph( - DefaultEdge.class); + // We use Object instead of DefaultEdge for the edge type + // in order to cover the case in + // https://sourceforge.net/tracker/index.php?func=detail&aid=3486775&group_id=86459&atid=579687 + ListenableUndirectedGraph g = + new ListenableUndirectedGraph( + Object.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); - NeighborIndex index = - new NeighborIndex(g); + NeighborIndex index = + new NeighborIndex(g); g.addGraphListener(index); Set neighbors1 = index.neighborsOf(V1); @@ -105,16 +108,16 @@ public void testNeighborSet() public void testDirectedNeighborSet() { - ListenableDirectedGraph g = - new ListenableDirectedGraph( - DefaultEdge.class); + ListenableDirectedGraph g = + new ListenableDirectedGraph( + Object.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); - DirectedNeighborIndex index = - new DirectedNeighborIndex(g); + DirectedNeighborIndex index = + new DirectedNeighborIndex(g); g.addGraphListener(index); Set p = index.predecessorsOf(V1); diff --git a/jgrapht-demo/pom.xml b/jgrapht-demo/pom.xml index c499bd508bf..19806875050 100644 --- a/jgrapht-demo/pom.xml +++ b/jgrapht-demo/pom.xml @@ -19,6 +19,7 @@ org.jgrapht.demo.JGraphAdapterDemo + true diff --git a/jgrapht-dist/src/assembly/assembly.xml b/jgrapht-dist/src/assembly/assembly.xml index 79d15e774e3..2eb8470a596 100644 --- a/jgrapht-dist/src/assembly/assembly.xml +++ b/jgrapht-dist/src/assembly/assembly.xml @@ -33,12 +33,30 @@ - ${basedir}/../README.html + ${basedir}/../README.md + / + + + ${basedir}/../HISTORY.md + / + + + ${basedir}/../CONTRIBUTORS.md / ${basedir}/../license-LGPL.txt / - - \ No newline at end of file + + + + + ${basedir}/.. + /source + + **/target/** + + + +