This commit is contained in:
eslusarz
2026-05-25 13:55:30 +02:00
parent cec7009044
commit ddf329482a
5 changed files with 30 additions and 2 deletions
Binary file not shown.
+30 -2
View File
@@ -23,6 +23,36 @@ public class Network<Vertex extends Comparable<? super Vertex>> implements Graph
public Network(Network<Vertex> network) { public Network(Network<Vertex> network) {
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) {
@@ -305,7 +335,5 @@ public class Network<Vertex extends Comparable<? super Vertex>> implements Graph
} }
return true; return true;
} }
} }