From 65c2b7a661c0daa6d5506198438cac0743682797 Mon Sep 17 00:00:00 2001 From: mayank097 Date: Mon, 2 Apr 2018 12:46:36 +0530 Subject: [PATCH] Created Ladder Graph Generator --- .../generate/LadderGraphGenerator.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 jgrapht-core/src/main/java/org/jgrapht/generate/LadderGraphGenerator.java diff --git a/jgrapht-core/src/main/java/org/jgrapht/generate/LadderGraphGenerator.java b/jgrapht-core/src/main/java/org/jgrapht/generate/LadderGraphGenerator.java new file mode 100644 index 00000000000..3fae583b91e --- /dev/null +++ b/jgrapht-core/src/main/java/org/jgrapht/generate/LadderGraphGenerator.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. + */ +/* ------------------- + * LadderGraphGenerator.java + * ------------------- + * (C) Copyright 2003-2008, by John V. Sichi and Contributors. + * + * Original Author: John V. Sichi + * Contributor(s): - + * + * $Id$ + * + * Changes + * ------- + * 16-Sep-2003 : Initial revision (JVS); + * + */ +package org.jgrapht.generate; + +import java.util.*; + +import org.jgrapht.*; + +/** + * Generates a ladder + * graph of any size.it is same as grid graph but with number of collumns + * fixed to two. + * + * @author John V. Sichi + * @since Sep 16, 2003 + */ + public class LadderGraphGenerator + implements GraphGenerator +{ + //~ Static fields/initializers --------------------------------------------- + //~ Instance fields -------------------------------------------------------- + + private int rows; + + private int cols=2; + + //~ Constructors ----------------------------------------------------------- + + /** + * Creates a new ladderGraphGenerator object with rows x cols dimension. + * + * @param rows the number of rows + * @param cols the number of columns + */ + public ladderGraphGenerator(int rows, int cols) + { + if (rows < 2) { + throw new IllegalArgumentException( + "illegal number of rows (" + rows + + "). there must be at least two."); + } + if (cols < 2) { + throw new IllegalArgumentException( + "illegal number of columns (" + cols + + "). there must be at least two."); + } + this.rows = rows; + this.cols = cols; + } + + //~ Methods ---------------------------------------------------------------- + + /** + * {@inheritDoc} + */ + @Override public void generateGraph( + Graph target, + VertexFactory vertexFactory, + Map resultMap) + { + GridGraphGenerator gridGenerator = + new gridGraphGenerator(row,cols); + gridGenerator.generateGraph(target, vertexFactory, resultMap); +} + }