logo

Crowdly

Browser

Add to Chrome

Considerar la siguiente implementación de un grafo ponderado (con ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Considerar la siguiente

implementación de un grafo ponderado (con pesos en sus arcos/edges) de vértices

con datos genéricos (asumiendo todos los

import

necesarios, así como los métodos hashCode, equals, compareTo y toString de la

clase de un vértice: Vertex).

public class Vertex<T> implements

Comparable<Vertex<T>> {

  private final int id;

  private T data;

  public Vertex(int id, T data) {

     this.id = id;

     this.data = data;

  }

  public int getId() { return this.id; }

  public T getData() { return this.data; }

  ...

}

public class Graph<T> {

  protected

List<Vertex<T>> vertices; // vértices v

  protected

Map<Vertex<T>, Map<Vertex<T>, Double>> edges; // arcos

(v1,v2) con pesos w

  public Graph() {

     this.vertices = new

ArrayList<>();

     this.edges = new

HashMap<>();

  }

  public

Vertex<T>

addVertex(T data) { ... }

  public void

addEdge(Vertex<T> v1, Vertex<T> v2,

double w) { ... }

  public

List<Vertex<T>> getVertices() { ... }

  public double

getEdgeWeight(Vertex<T> v1, Vertex<T> v2) { ... }

  ...

}

 

¿Qué es lo

que almacena la variable x de abajo dentro de un método de Graph?

x = this.edges.get(v).entrySet()

  .stream()

  .filter(e ->

e.getValue() > 0.5)

  .map(e -> e.getKey())

  .collect(Collectors.toList());

0%
0%
0%
0%
More questions like this

Want instant access to all verified answers on moodle.uam.es?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome