Skip to content

Commit

Permalink
Add file headers to recently added files, and make computationally-ex…
Browse files Browse the repository at this point in the history
…pensive

HopcroftKarpBipartiteMatching input validation only run when
assertions are enabled.
  • Loading branch information
jsichi committed Nov 27, 2012
1 parent efe61ca commit a8056d6
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 8 deletions.
6 changes: 3 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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.
- Fix empty diameter calculation in FloydWarshallShortestPaths, contributed by Ernst de Ridder (bug spotted by Jens Lehmann)
- Add HopcroftKarpBipartiteMatching and MinSourceSinkCut, contributed by Joris Kinable
- Add `EdmondsBlossomShrinking` algorithm, contributed by Alejandro R. Lopez del Huerto.
- Fix empty diameter calculation in `FloydWarshallShortestPaths`, contributed by Ernst de Ridder (bug spotted by Jens Lehmann)
- Add `HopcroftKarpBipartiteMatching` and `MinSourceSinkCut`, contributed by Joris Kinable

- **version 0.8.3** (20-Jan-2012):
- fix regression in `DOTExporter` inadvertently introduced by `0.8.2` changes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
/* ==========================================
* 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.
*/
/* -------------------------
* HopcroftKarpBipartiteMatching.java
* -------------------------
* (C) Copyright 2012-2012, by Joris Kinable and Contributors.
*
* Original Author: Joris Kinable
* Contributor(s):
*
* Changes
* -------
* 26-Nov-2012 : Initial revision (JK);
*
*/
package org.jgrapht.alg;

import java.util.ArrayList;
Expand Down Expand Up @@ -38,8 +75,8 @@ public class HopcroftKarpBipartiteMatching<V,E> {
private final Set<V> partition2;
private Set<E> matching; //Set containing the matchings

private final HashSet<V> unmatchedVertices1; //Set which contains the unmatched vertices in partition 1
private final HashSet<V> unmatchedVertices2;
private final Set<V> unmatchedVertices1; //Set which contains the unmatched vertices in partition 1
private final Set<V> unmatchedVertices2;


public HopcroftKarpBipartiteMatching(UndirectedGraph<V, E> graph, Set<V> partition1, Set<V> partition2){
Expand All @@ -51,14 +88,14 @@ public HopcroftKarpBipartiteMatching(UndirectedGraph<V, E> graph, Set<V> partiti
unmatchedVertices1=new HashSet<V>(partition1);
unmatchedVertices2=new HashSet<V>(partition2);

this.checkInputData();
assert this.checkInputData();
this.maxMatching();
}

/**
* Checks whether the input data meets the requirements: simple undirected graph and bipartite partitions.
*/
private void checkInputData(){
private boolean checkInputData(){
if(graph instanceof Multigraph)
throw new IllegalArgumentException("Multi graphs are not allowed as input, only simple graphs!");
//Test the bipartiteness
Expand All @@ -71,7 +108,8 @@ private void checkInputData(){
for(V v: partition2)
neighborsSet2.addAll(Graphs.neighborListOf(graph, v));
if(interSectionNotEmpty(partition2, neighborsSet2))
throw new IllegalArgumentException("There are edges within partition 2, i.e. not a bipartite graph");
throw new IllegalArgumentException("There are edges within partition 2, i.e. not a bipartite graph");
return true;
}
/**
* Greedily match the vertices in partition1 to the vertices in partition2.
Expand Down
37 changes: 37 additions & 0 deletions jgrapht-core/src/main/java/org/jgrapht/alg/MinSourceSinkCut.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
/* ==========================================
* 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.
*/
/* -------------------------
* MinSourceSinkCut.java
* -------------------------
* (C) Copyright 2012-2012, by Joris Kinable and Contributors.
*
* Original Author: Joris Kinable
* Contributor(s):
*
* Changes
* -------
* 26-Nov-2012 : Initial revision (JK);
*
*/
package org.jgrapht.alg;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
/* ==========================================
* 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.
*/
/* -------------------------
* HopcroftKarpBipartiteMatchingTest.java
* -------------------------
* (C) Copyright 2012-2012, by Joris Kinable and Contributors.
*
* Original Author: Joris Kinable
* Contributor(s):
*
* Changes
* -------
* 26-Nov-2012 : Initial revision (JK);
*
*/
package org.jgrapht.alg;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
/* ==========================================
* 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.
*/
/* -------------------------
* MinSourceSinkCutTest.java
* -------------------------
* (C) Copyright 2012-2012, by Joris Kinable and Contributors.
*
* Original Author: Joris Kinable
* Contributor(s):
*
* Changes
* -------
* 26-Nov-2012 : Initial revision (JK);
*
*/
package org.jgrapht.alg;

import static org.junit.Assert.*;
Expand Down

0 comments on commit a8056d6

Please sign in to comment.