Skip to content
Snippets Groups Projects
Commit b2703a63 authored by Renato Melo's avatar Renato Melo
Browse files

PrevalentSeed

parent dca44317
Branches
Tags
No related merge requests found
...@@ -88,7 +88,7 @@ public class MinDominatingSet { ...@@ -88,7 +88,7 @@ public class MinDominatingSet {
} }
/** /**
* Está errado, tem que olhar melhor a questão da direção das arestas * Com grafo direcionado não retorna um conjunto dominante, mas é um bom cojunto de vértices influentes
**/ **/
public HashSet<Actor> fastGreedy(DirectedSocialNetwork grafo) { public HashSet<Actor> fastGreedy(DirectedSocialNetwork grafo) {
......
...@@ -5,6 +5,10 @@ import java.util.PriorityQueue; ...@@ -5,6 +5,10 @@ import java.util.PriorityQueue;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import util.ComparaPorGrau;
import com.google.common.collect.MinMaxPriorityQueue;
import algoritmos.MarginalGain; import algoritmos.MarginalGain;
import geradores.SocialNetworkGenerate; import geradores.SocialNetworkGenerate;
import grafos.Actor; import grafos.Actor;
...@@ -13,33 +17,61 @@ import interfaces.SeedChooser; ...@@ -13,33 +17,61 @@ import interfaces.SeedChooser;
/*De acordo com os experimentos, utilizando o CELF como subrotina /*De acordo com os experimentos, utilizando o CELF como subrotina
* dentro do conjunto dominante obtem-se um resultado semelhante * dentro do conjunto dominante obtem-se um resultado semelhante
* ao CELF original, o que leva a crer sãio fortes indicativos de * ao CELF original, o que leva a crer são fortes indicativos de
* que os vértices "bons" estão dentro do conjunto dominante minimo * que os vértices "bons" estão dentro do conjunto dominante minimo
* num grafo direcionado * num grafo direcionado
*/ */
public class DominatingSeed implements SeedChooser<Actor> { public class PrevalentSeed implements SeedChooser<Actor> {
private DirectedSocialNetwork grafo; private DirectedSocialNetwork grafo;
public DominatingSeed(DirectedSocialNetwork g) { public PrevalentSeed(DirectedSocialNetwork g) {
this.grafo = g; this.grafo = g;
} }
public HashSet<Actor> preSelecao(DirectedSocialNetwork grafo) {
int n = grafo.vertexSet().size();
// DS <-- {}
HashSet<Actor> candidatos = new HashSet<>();
// compare os vertices pelo grau
ComparaPorGrau comp = new ComparaPorGrau(grafo);
MinMaxPriorityQueue<Actor> heapMinMax = null;
heapMinMax = MinMaxPriorityQueue.orderedBy(comp).maximumSize(n)
.create();
for (Actor v : grafo.vertexSet()) {
heapMinMax.add(v);
}
Set<Actor> cobertos = new HashSet<>();
while (cobertos.size() < n) {
Actor v = heapMinMax.removeLast();
Set<Actor> vizinhos = grafo.outNeighborsOf(v);
if (cobertos.addAll(vizinhos)) {
candidatos.add(v);
}
cobertos.add(v);
}
return candidatos;
}
@Override @Override
public HashSet<Actor> escolher(int k) { public HashSet<Actor> escolher(int k) {
HashSet<Actor> semente = new HashSet<Actor>(); HashSet<Actor> semente = new HashSet<Actor>();
HashSet<Actor> minSet = new HashSet<Actor>(); HashSet<Actor> candidatos = new HashSet<Actor>();
MinDominatingSet ds = new MinDominatingSet(); candidatos = preSelecao(grafo);
minSet = ds.fastGreedy(grafo);
System.out.println("|DS| = " + minSet.size()); if (candidatos.size() < k) {
if (minSet.size() < k) { System.out.println("Erro: o cojunto de candidatos é menor que K");
System.out.println("Erro: o cojunto domintante é menor que K");
return null; return null;
} }
// create priority queue of all nodes, with marginal gain delta +inf // create priority queue of all nodes, with marginal gain delta +inf
PriorityQueue<MarginalGain> fila = priorityQueueOfGains(minSet); PriorityQueue<MarginalGain> fila = priorityQueueOfGains(candidatos);
double MaxSpread = 0; double MaxSpread = 0;
...@@ -231,7 +263,7 @@ public class DominatingSeed implements SeedChooser<Actor> { ...@@ -231,7 +263,7 @@ public class DominatingSeed implements SeedChooser<Actor> {
2.5); 2.5);
long startTime = 0; long startTime = 0;
startTime = System.nanoTime(); startTime = System.nanoTime();
HashSet<Actor> seed = new DominatingSeed(g).escolher2(15); HashSet<Actor> seed = new PrevalentSeed(g).escolher2(15);
System.out.println("Tempo: " + (System.nanoTime() - startTime) / 1000); System.out.println("Tempo: " + (System.nanoTime() - startTime) / 1000);
HashSet<Actor> ativos = g.indepCascadeDiffusion(seed); HashSet<Actor> ativos = g.indepCascadeDiffusion(seed);
...@@ -243,7 +275,7 @@ public class DominatingSeed implements SeedChooser<Actor> { ...@@ -243,7 +275,7 @@ public class DominatingSeed implements SeedChooser<Actor> {
// g.visualize(); // g.visualize();
startTime = System.nanoTime(); startTime = System.nanoTime();
HashSet<Actor> seed2 = new DominatingSeed(g).escolher(15); HashSet<Actor> seed2 = new PrevalentSeed(g).escolher(15);
System.out.println("Tempo: " + (System.nanoTime() - startTime) / 1000); System.out.println("Tempo: " + (System.nanoTime() - startTime) / 1000);
HashSet<Actor> ativos2 = g.indepCascadeDiffusion(seed2); HashSet<Actor> ativos2 = g.indepCascadeDiffusion(seed2);
......
...@@ -186,7 +186,7 @@ public class DirectedSocialNetwork extends ...@@ -186,7 +186,7 @@ public class DirectedSocialNetwork extends
public double espectedSpread(HashSet<Actor> seed, boolean ic) { public double espectedSpread(HashSet<Actor> seed, boolean ic) {
double media = 0; double media = 0;
int soma = 0; int soma = 0;
int repeticoes = 10000; int repeticoes = 5000;
if (!ic) { if (!ic) {
HashSet<Actor> ativados = linearThresholdDiffusion(seed); HashSet<Actor> ativados = linearThresholdDiffusion(seed);
...@@ -243,6 +243,7 @@ public class DirectedSocialNetwork extends ...@@ -243,6 +243,7 @@ public class DirectedSocialNetwork extends
while (escolhidos.size() < k) { while (escolhidos.size() < k) {
Actor maior = heapMinMax.removeLast(); Actor maior = heapMinMax.removeLast();
System.out.print(maior+"; ");
escolhidos.add(maior); escolhidos.add(maior);
} }
...@@ -327,29 +328,32 @@ public class DirectedSocialNetwork extends ...@@ -327,29 +328,32 @@ public class DirectedSocialNetwork extends
DirectedSocialNetwork g = new DirectedSocialNetwork( DirectedSocialNetwork g = new DirectedSocialNetwork(
DefaultWeightedEdge.class); DefaultWeightedEdge.class);
g = new SocialNetworkGenerate().gerarGrafo(40, 2); g = new SocialNetworkGenerate().gerarGrafo(30, 2);
HashSet<Actor> seed = new HashSet<>(); // HashSet<Actor> seed = new HashSet<>();
//
Set<Actor> vertices = g.vertexSet(); // Set<Actor> vertices = g.vertexSet();
for (Actor actor : vertices) { // for (Actor actor : vertices) {
if (seed.size() < 5) { // if (seed.size() < 5) {
seed.add(actor); // seed.add(actor);
} // }
//
} // }
//
System.out.println("|V(G)| = " + g.vertexSet().size()); System.out.println("|V(G)| = " + g.vertexSet().size());
System.out.println("|E(G)| = " + g.edgeSet().size()); System.out.println("|E(G)| = " + g.edgeSet().size());
System.out.println("Seed:"); System.out.println("Q: ");
for (Actor a : seed) { Set<Actor> Q = g.verticesGrauMaior(g.vertexSet(), g.vertexSet().size());
System.out.println(a.toString()); System.out.println();
} // System.out.println("Seed:");
// for (Actor a : seed) {
System.out.println("Difusão média no modelo IC = "+g.espectedSpread(seed, true)); // System.out.println(a.toString());
System.out.println("Difusão média no modelo LT = "+g.espectedSpread(seed, false)); // }
//
// System.out.println("Difusão média no modelo IC = "+g.espectedSpread(seed, true));
// System.out.println("Difusão média no modelo LT = "+g.espectedSpread(seed, false));
// g.activate(seed); // g.activate(seed);
// g.visualize(); g.visualize();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment