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

gr.james.simplegraph.examples.MinimumEdgeWeight Maven / Gradle / Ivy

Go to download

Simple Graph is a graph interface for Java 6 that is designed to expose a very simple API to support working with graphs

The newest version!
package gr.james.simplegraph.examples;

import gr.james.simplegraph.WeightedGraph;

/**
 * Get the edge with the minimum weight from a {@link WeightedGraph}.
 */
public final class MinimumEdgeWeight {
    private MinimumEdgeWeight() {
    }

    /**
     * Returns the minimum edge weight of a {@link WeightedGraph}.
     * 

* Returns {@link Double#NaN} if the graph has no edges. *

* Complexity: O(V+E) * * @param g the graph * @return the minimum edge weight of {@code g} * @throws NullPointerException if {@code g} is {@code null} */ public static double minimumEdgeWeight(WeightedGraph g) { double min = Double.NaN; for (int i = 0; i < g.size(); i++) { for (int j : g.getEdges(i)) { final double weight = g.getEdgeWeight(i, j); if (Double.isNaN(min) || weight < min) { min = weight; } } } return min; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy