All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgrapht.graph.AsUnweightedGraph Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
/*
 * (C) Copyright 2007-2018, by Lucas J Scharenbroich and Contributors.
 *
 * JGraphT : a free Java graph-theory library
 *
 * This program and the accompanying materials are dual-licensed under
 * either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation, or (at your option) any
 * later version.
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */
package org.jgrapht.graph;

import org.jgrapht.*;

import java.io.*;

/**
 * An unweighted view of a graph.
 * 
 * 

* 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 * 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. * * @param the graph vertex type * @param the graph edge type * * @author Lucas J. Scharenbroich * @since Sep 7, 2007 */ public class AsUnweightedGraph extends GraphDelegator implements Serializable { private static final long serialVersionUID = 7175505077601824663L; /** * Constructor * * @param g the backing graph over which an unweighted view is to be created. */ public AsUnweightedGraph(Graph g) { super(g); } /** * {@inheritDoc} */ @Override public double getEdgeWeight(E e) { if (e == null) { throw new NullPointerException(); } else { return Graph.DEFAULT_EDGE_WEIGHT; } } /** * {@inheritDoc} */ @Override public void setEdgeWeight(E e, double weight) { throw new UnsupportedOperationException("Graph is unweighted"); } /** * {@inheritDoc} */ @Override public GraphType getType() { return super.getType().asUnweighted(); } } // End AsUnweightedGraph.java





© 2015 - 2025 Weber Informatics LLC | Privacy Policy