update
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -24,6 +24,36 @@ public class Network<Vertex extends Comparable<? super Vertex>> implements Graph
|
|||||||
this.adjacencyMap = new TreeMap<Vertex, TreeMap<Vertex, Double>>(network.adjacencyMap);
|
this.adjacencyMap = new TreeMap<Vertex, TreeMap<Vertex, Double>>(network.adjacencyMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TOTALE 2024-02-13
|
||||||
|
Implementare un metodo costruttore public Network(Vertex[] V) della
|
||||||
|
classe network che prende in input i vertici (distinti) del grafo e
|
||||||
|
inserisce nel nuovo grafo un arco diretto da un vertice V[i] a un vertice V[j] (i!=j)
|
||||||
|
con probabilità 1/2 assegnando peso -1.0 se V[i]<V[j], 1.0 altrimenti.
|
||||||
|
*/
|
||||||
|
public Network(Vertex[] V) {
|
||||||
|
// Null check
|
||||||
|
if (V == null) throw new NullPointerException();
|
||||||
|
// Aggiunta di tutti i vertici
|
||||||
|
for (Vertex v : V) addVertex(v);
|
||||||
|
// Lettura dei valori
|
||||||
|
for (int i = 0; i < V.length; i++) {
|
||||||
|
// Leggiamo il vertice
|
||||||
|
Vertex iVertex = V[i];
|
||||||
|
for (int j = 0; j < V.length; j++) {
|
||||||
|
// Se la coppia è uguale, allora salta
|
||||||
|
if (i == j) continue;
|
||||||
|
// Leggiamo il vertice j
|
||||||
|
Vertex jVertex = V[j];
|
||||||
|
// Probabilità 1/2
|
||||||
|
if (Math.random() < 0.5) continue;
|
||||||
|
// Aggiunta dell'arco
|
||||||
|
if (iVertex.compareTo(jVertex) < 0) addEdge(iVertex, jVertex, -1.0);
|
||||||
|
else addEdge(iVertex, jVertex, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (object == null) return false;
|
if (object == null) return false;
|
||||||
@@ -306,6 +336,4 @@ public class Network<Vertex extends Comparable<? super Vertex>> implements Graph
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user