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

org.jgrapht.graph.guava.ImmutableDoubleValueGraphAdapter Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
/*
 * (C) Copyright 2018-2018, by Dimitrios Michail 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.guava;

import com.google.common.graph.*;
import org.jgrapht.Graph;

import java.io.*;
import java.util.function.*;

/**
 * A graph adapter class using Guava's {@link ImmutableValueGraph} specialized with double values.
 * 
 * 

* The adapter uses class {@link EndpointPair} to represent edges. Since the underlying value graph * is immutable, the resulting graph is unmodifiable. * *

* Each edge in {@link ImmutableValueGraph} is associated with a double value which is mapped to the * edge weight in the resulting {@link Graph}. Thus, the graph is weighted and calling method * {@link #getEdgeWeight(Object)} will return the value of an edge. * *

* See the example below on how to create such an adapter:

* *
 * MutableValueGraph<String, Double> mutableValueGraph =
 *     ValueGraphBuilder.directed().allowsSelfLoops(true).build();
 * 
 * mutableValueGraph.addNode("v1");
 * mutableValueGraph.addNode("v2");
 * mutableValueGraph.putEdgeValue("v1", "v2", 3.0);
 * 
 * ImmutableValueGraph<String, Double> immutableValueGraph = ImmutableValueGraph.copyOf(mutableValueGraph);
 * 
 * Graph<String, EndpointPair<String>> graph = new ImmutableDoubleValueGraphAdapter<>(immutableValueGraph);
 * 
 * System.out.println(graph.getEdgeWeight(EndpointPair.ordered("v1", "v2")); // outputs 3.0
 * 
* *
* * @author Dimitrios Michail * * @param the graph vertex type */ public class ImmutableDoubleValueGraphAdapter extends ImmutableValueGraphAdapter { private static final long serialVersionUID = 8730006126353129360L; /** * Create a new adapter. * * @param valueGraph the value graph */ public ImmutableDoubleValueGraphAdapter(ImmutableValueGraph valueGraph) { super(valueGraph, (ToDoubleFunction & Serializable) x -> x); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy