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

depois dos experimentos

parent 3d844620
Branches
Tags
No related merge requests found
...@@ -31,6 +31,50 @@ public class DominatingSeed implements SeedChooser<Actor> { ...@@ -31,6 +31,50 @@ public class DominatingSeed implements SeedChooser<Actor> {
MinDominatingSet ds = new MinDominatingSet(); MinDominatingSet ds = new MinDominatingSet();
minSet = ds.fastGreedy(grafo); minSet = ds.fastGreedy(grafo);
System.out.println("|DS| = " + minSet.size());
if (minSet.size() < k) {
System.out.println("Erro: o cojunto domintante é menor que K");
return null;
}
// create priority queue of all nodes, with marginal gain delta +inf
PriorityQueue<MarginalGain> fila = priorityQueueOfGains(minSet);
double MaxSpread = 0;
while (semente.size() < k) {
// set all gains invalid
for (MarginalGain mg : fila) {
mg.setValid(false);
}
while (true) {
MarginalGain max = fila.poll();
if (max.isValid() == true) {
semente.add(max.getVertice());
MaxSpread = MaxSpread + max.getGain();
break;
} else {
double sigma = cascata(max.getVertice(), semente);
double delta = sigma - MaxSpread;
max.setGain(delta);
max.setValid(true);
fila.add(max);
}
}
}
return semente;
}
public HashSet<Actor> escolher2(int k) {
HashSet<Actor> semente = new HashSet<Actor>();
HashSet<Actor> minSet = new HashSet<Actor>();
MinDominatingSet ds = new MinDominatingSet();
minSet = ds.fastGreedy2(grafo);
System.out.println("|DS| = " + minSet.size()); System.out.println("|DS| = " + minSet.size());
if (minSet.size() < k) { if (minSet.size() < k) {
System.out.println("Erro: o cojunto domintante é menor que K"); System.out.println("Erro: o cojunto domintante é menor que K");
...@@ -120,7 +164,7 @@ public class DominatingSeed implements SeedChooser<Actor> { ...@@ -120,7 +164,7 @@ public class DominatingSeed implements SeedChooser<Actor> {
vertices[i++] = a; vertices[i++] = a;
Random rand = new Random(); Random rand = new Random();
while (rSet.size() < vSet.size()/4) { while (rSet.size() < vSet.size() / 3) {
rSet.add(vertices[rand.nextInt(vertices.length)]); rSet.add(vertices[rand.nextInt(vertices.length)]);
} }
...@@ -183,30 +227,35 @@ public class DominatingSeed implements SeedChooser<Actor> { ...@@ -183,30 +227,35 @@ public class DominatingSeed implements SeedChooser<Actor> {
} }
public static void main(String[] args) { public static void main(String[] args) {
DirectedSocialNetwork g = new SocialNetworkGenerate() DirectedSocialNetwork g = new SocialNetworkGenerate().gerarGrafo(2000,
.gerarGrafo(800, 2.5); 2.5);
HashSet<Actor> seed = new DominatingSeed(g).escolherGreedy(15); long startTime = 0;
startTime = System.nanoTime();
HashSet<Actor> seed = new DominatingSeed(g).escolher2(15);
System.out.println("Tempo: " + (System.nanoTime() - startTime) / 1000);
HashSet<Actor> ativos = g.indepCascadeDiffusion(seed); HashSet<Actor> ativos = g.indepCascadeDiffusion(seed);
System.out.println("|V(G)| = " + g.vertexSet().size()); System.out.println("|V(G)| = " + g.vertexSet().size());
System.out.println("|S| = " + seed.size()); // System.out.println("|S| = " + seed.size());
System.out.println("|A| = " + ativos.size()); System.out.println("|A| = " + ativos.size());
g.deactivate(ativos); g.deactivate(ativos);
// g.activate(seed); // g.activate(seed);
// g.visualize(); // g.visualize();
startTime = System.nanoTime();
HashSet<Actor> seed2 = new DominatingSeed(g).escolher(15); HashSet<Actor> seed2 = new DominatingSeed(g).escolher(15);
System.out.println("Tempo: " + (System.nanoTime() - startTime) / 1000);
HashSet<Actor> ativos2 = g.indepCascadeDiffusion(seed2); HashSet<Actor> ativos2 = g.indepCascadeDiffusion(seed2);
System.out.println("\n|S| = " + seed2.size()); // System.out.println("\n|S| = " + seed2.size());
System.out.println("|A| = " + ativos2.size()); System.out.println("|A| = " + ativos2.size());
g.deactivate(ativos2); g.deactivate(ativos2);
HashSet<Actor> seed3 = new DominatingSeed(g).escolherRandom(15); // HashSet<Actor> seed3 = new DominatingSeed(g).escolherRandom(15);
//
HashSet<Actor> ativos3 = g.indepCascadeDiffusion(seed3); // HashSet<Actor> ativos3 = g.indepCascadeDiffusion(seed3);
System.out.println("\n|S| = " + seed3.size()); //// System.out.println("\n|S| = " + seed3.size());
System.out.println("|A| = "+ativos3.size()); // System.out.println("|A| = "+ativos3.size());
} }
......
...@@ -108,16 +108,45 @@ public class MinDominatingSet { ...@@ -108,16 +108,45 @@ public class MinDominatingSet {
} }
Set<Actor> dominados = new HashSet<>(); Set<Actor> dominados = new HashSet<>();
while (dominados.size() < n) { while (dominados.size() < n) {
Actor v = heapMinMax.removeLast(); Actor v = heapMinMax.removeLast();
dominados.add(v);
Set<Actor> vizinhos = grafo.outNeighborsOf(v); Set<Actor> vizinhos = grafo.outNeighborsOf(v);
if (dominados.addAll(vizinhos)) { if (dominados.addAll(vizinhos)) {
dominante.add(v); dominante.add(v);
} }
dominados.add(v);
}
return dominante;
}
public HashSet<Actor> fastGreedy2(DirectedSocialNetwork grafo) {
int n = grafo.vertexSet().size();
// DS <-- {}
HashSet<Actor> dominante = new HashSet<>();
// compare os vertices pelo grau
ComparaPorGrau comp = new ComparaPorGrau(grafo);
MinMaxPriorityQueue<Actor> fila = null;
fila = MinMaxPriorityQueue.orderedBy(comp).maximumSize(n)
.create();
for (Actor v : grafo.vertexSet()) {
fila.add(v);
}
Set<Actor> dominados = new HashSet<>();
while (!fila.isEmpty()) {
Actor v = fila.removeLast();
Set<Actor> vizinhos = grafo.outNeighborsOf(v);
if (dominados.addAll(vizinhos)) {
dominante.add(v);
}else
dominados.add(v);
} }
return dominante; return dominante;
} }
...@@ -125,7 +154,7 @@ public class MinDominatingSet { ...@@ -125,7 +154,7 @@ public class MinDominatingSet {
public static void main(String[] args) { public static void main(String[] args) {
DirectedSocialNetwork g = new SocialNetworkGenerate().gerarGrafo( DirectedSocialNetwork g = new SocialNetworkGenerate().gerarGrafo(
100, 2.5); 5000, 2.5);
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());
...@@ -139,10 +168,10 @@ public class MinDominatingSet { ...@@ -139,10 +168,10 @@ public class MinDominatingSet {
startTime = System.nanoTime(); startTime = System.nanoTime();
HashSet<Actor> ds = (HashSet<Actor>) minDom.greedy(g); HashSet<Actor> ds = (HashSet<Actor>) minDom.greedy(g);
System.out.println("Tempo: "+(System.nanoTime() - startTime)/1000); System.out.println("Tempo: "+(System.nanoTime() - startTime)/1000);
System.out.println("|DS|- GreedyPlus: " + ds.size()); System.out.println("|DS|- vRegularGreedy: " + ds.size());
System.out.println("\nspread: "+g.espectedSpread(ds, true)); System.out.println("\nspread: "+g.espectedSpread(ds, true));
g.activate(ds); // g.activate(ds);
g.visualize(); // g.visualize();
startTime = System.nanoTime(); startTime = System.nanoTime();
HashSet<Actor> ds2 = (HashSet<Actor>) minDom.regularGreedy(g); HashSet<Actor> ds2 = (HashSet<Actor>) minDom.regularGreedy(g);
...@@ -159,13 +188,12 @@ public class MinDominatingSet { ...@@ -159,13 +188,12 @@ public class MinDominatingSet {
HashSet<Actor> ds3 = minDom.fastGreedy(g); HashSet<Actor> ds3 = minDom.fastGreedy(g);
// System.out.println("Tempo: "+(System.nanoTime() - startTime)/1000); // System.out.println("Tempo: "+(System.nanoTime() - startTime)/1000);
System.out.println("\n\n|DS|- FastGreedy: " + ds3.size()); System.out.println("\n\n|DS|- FastGreedy: " + ds3.size());
System.out.println("Vertices dominantes:");
// for (Actor v : ds3) { // for (Actor v : ds3) {
// System.out.print(v.toString()+" "); // System.out.print(v.toString()+" ");
// } // }
System.out.println("\nspread: "+g.espectedSpread(ds3, true)); System.out.println("\nspread: "+g.espectedSpread(ds3, true));
g.activate(ds3); // g.activate(ds3);
g.visualize(); // g.visualize();
// HashSet<Actor> seed = new LazyGreedy(g).escolher(ds3.size()); // HashSet<Actor> seed = new LazyGreedy(g).escolher(ds3.size());
// System.out.println("\nVertices Influentes: "+seed.size()); // System.out.println("\nVertices Influentes: "+seed.size());
......
...@@ -43,7 +43,7 @@ public class GeradorGrafoPowerLaw { ...@@ -43,7 +43,7 @@ public class GeradorGrafoPowerLaw {
boolean direcionado) { boolean direcionado) {
//Devido a futura remoção dos vertices isolados //Devido a futura remoção dos vertices isolados
if (direcionado) { if (direcionado) {
n = (int) (n + n * 0.17); n = (int) (n + n * 0.7);
}else }else
n = (int) (n + n * 0.5); n = (int) (n + n * 0.5);
...@@ -135,7 +135,7 @@ public class GeradorGrafoPowerLaw { ...@@ -135,7 +135,7 @@ public class GeradorGrafoPowerLaw {
int n, double beta, boolean direcionado) { int n, double beta, boolean direcionado) {
if (direcionado) { if (direcionado) {
n = (int) (n + n * 0.17); n = (int) (n + n * 0.65);
}else }else
n = (int) (n + n * 0.5); n = (int) (n + n * 0.5);
......
...@@ -122,7 +122,7 @@ public class GeradorModeloGRG { ...@@ -122,7 +122,7 @@ public class GeradorModeloGRG {
if (Math.random() < p){ if (Math.random() < p){
DefaultWeightedEdge e; DefaultWeightedEdge e;
e = g.addEdge(vertices.get(i), vertices.get(j)); e = g.addEdge(vertices.get(i), vertices.get(j));
g.setEdgeWeight(e, Math.random()); g.setEdgeWeight(e, peso());
} }
} }
} }
...@@ -135,7 +135,7 @@ public class GeradorModeloGRG { ...@@ -135,7 +135,7 @@ public class GeradorModeloGRG {
if (Math.random() < p){ if (Math.random() < p){
DefaultWeightedEdge e; DefaultWeightedEdge e;
e = g.addEdge(vertices.get(i), vertices.get(j)); e = g.addEdge(vertices.get(i), vertices.get(j));
g.setEdgeWeight(e, Math.random()); g.setEdgeWeight(e, peso());
} }
} }
} }
...@@ -143,4 +143,16 @@ public class GeradorModeloGRG { ...@@ -143,4 +143,16 @@ public class GeradorModeloGRG {
} }
return g; return g;
} }
public double peso() {
// int p = (int) (Math.random() * 3);
// double[] choice = { 0.2, 0.04, 0.008 };
// return choice[p];
// uniform IC model
// return (double)10/100;
// return 0.025;
return (Math.random())/4;
}
} }
...@@ -20,6 +20,7 @@ import org.jgrapht.WeightedGraph; ...@@ -20,6 +20,7 @@ import org.jgrapht.WeightedGraph;
import org.jgrapht.graph.DefaultEdge; import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.DefaultWeightedEdge;
import plot.Histograma;
import util.ComponentesConexos; import util.ComponentesConexos;
public class SocialNetworkGenerate { public class SocialNetworkGenerate {
...@@ -66,6 +67,18 @@ public class SocialNetworkGenerate { ...@@ -66,6 +67,18 @@ public class SocialNetworkGenerate {
return g; return g;
} }
public DirectedSocialNetwork gerarGrafoInteiro(int n, double beta,
boolean direcionado, boolean comPeso) {
WeightedGraph<Actor, DefaultWeightedEdge> grafo;
grafo = new GeradorGrafoPowerLaw().gerarComPesos(n, beta,
direcionado);
g = asDirectedSocialNetwork(grafo);
return g;
}
// Por padrão a rede resultante é direcionada e com pesos // Por padrão a rede resultante é direcionada e com pesos
public DirectedSocialNetwork gerarModeloIC(int n, double beta) { public DirectedSocialNetwork gerarModeloIC(int n, double beta) {
boolean direcionado = true; boolean direcionado = true;
...@@ -115,4 +128,16 @@ public class SocialNetworkGenerate { ...@@ -115,4 +128,16 @@ public class SocialNetworkGenerate {
return sn; return sn;
} }
public static void main(String[] args) {
// DirectedSocialNetwork g = new SocialNetworkGenerate().gerarGrafo(50000, 2.5);
DirectedSocialNetwork g = new SocialNetworkGenerate().gerarGrafoInteiro(30000, 2.5, true, true);
System.out.println("|V(G)|"+g.vertexSet().size());
System.out.println("|E(G)|"+g.edgeSet().size());
Histograma histograma = new Histograma();
try {
histograma.plotarGraficos(histograma.gerarHistograma(g));
} catch (IOException e) {
e.printStackTrace();
}
}
} }
...@@ -63,7 +63,7 @@ public class GraphReader { ...@@ -63,7 +63,7 @@ public class GraphReader {
DefaultWeightedEdge e; DefaultWeightedEdge e;
e = g.addEdge(vertices[v1], vertices[v2]); e = g.addEdge(vertices[v1], vertices[v2]);
if (e != null) { if (e != null) {
g.setEdgeWeight(e, trivalencyModel()); g.setEdgeWeight(e, peso());
} }
} }
} }
...@@ -79,18 +79,17 @@ public class GraphReader { ...@@ -79,18 +79,17 @@ public class GraphReader {
/** /**
* Sorteia um valor aleatório * Sorteia um valor aleatório
*
* @return um número entre {0.2, 0.04, 0.008}
*/ */
public double trivalencyModel() { public double peso() {
// int p = (int) (Math.random() * 3); // int p = (int) (Math.random() * 3);
// double[] choice = { 0.2, 0.04, 0.008 }; // double[] choice = { 0.2, 0.04, 0.008 };
// return choice[p]; // return choice[p];
// uniform IC model // uniform IC model
return (double)10/100; // return (double)10/100;
// return Math.random(); // return 0.025;
return Math.random()/4;
} }
public DirectedSocialNetwork readEpinions() { public DirectedSocialNetwork readEpinions() {
......
...@@ -4,8 +4,11 @@ import java.text.DateFormat; ...@@ -4,8 +4,11 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import javax.media.j3d.PhysicalBody; import javax.media.j3d.PhysicalBody;
import org.jgrapht.graph.DefaultWeightedEdge;
import plot.MeuPlot; import plot.MeuPlot;
import readgraph.GraphReader; import readgraph.GraphReader;
import algoritmos.ArticulationSeed; import algoritmos.ArticulationSeed;
...@@ -75,16 +78,102 @@ public class Simulacao { ...@@ -75,16 +78,102 @@ public class Simulacao {
outDir); outDir);
} }
private static void simularArtificial() { public static void simularRandomGraphIC(int n, String outDir) {
double[] tamSemente = { 10, 20, 30, 40, 50 };
double[] sigma1 = new double[5], tempo1 = new double[5];
double[] sigma2 = new double[5], tempo2 = new double[5];
double[] sigma3 = new double[5], tempo3 = new double[5];
double[] sigma4 = new double[5], tempo4 = new double[5];
int k, repeticoes = 10;
double[] ssigma1 = new double[5], stempo1 = new double[5];
double[] ssigma2 = new double[5], stempo2 = new double[5];
double[] ssigma3 = new double[5], stempo3 = new double[5];
double[] ssigma4 = new double[5], stempo4 = new double[5];
for (int j = 0; j < repeticoes; j++) {
System.out.println("Grafo "+j);
DirectedSocialNetwork g; DirectedSocialNetwork g;
g = new SocialNetworkGenerate().gerarGrafo(30000, 2.8); g = new SocialNetworkGenerate().gerarGrafo(n * 1000, 2.5);
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();
String outDir = "'plots/tex/"; long excutionTime = 0;
for (int i = 0; i < tamSemente.length; i++) {
k = (int) tamSemente[i];
System.out.println("\nTestando para k = " + k);
new Simulacao().simularIC(g, outDir); excutionTime = System.currentTimeMillis() * -1;
HashSet<Actor> seed1 = new DominatingSeed(g).escolher(k);
excutionTime += System.currentTimeMillis();
tempo1[i] = (excutionTime / 1000.0f);
sigma1[i] = g.espectedSpread(seed1, true);
System.out.println("DominatingSeed: sigma = " + sigma1[i]
+ ", tempo = " + tempo1[i] + " segundos");
ssigma1[i] += sigma1[i];
stempo1[i] += tempo1[i];
/*excutionTime = System.currentTimeMillis() * -1;
HashSet<Actor> seed2 = new LazyGreedy(g).escolher(k);
excutionTime += System.currentTimeMillis();
tempo2[i] = (excutionTime / 1000.0f);
sigma2[i] = g.espectedSpread(seed2, true);
System.out.println("LazyGreedy: sigma = " + sigma2[i]
+ ", tempo = " + tempo2[i] + " segundos");
ssigma2[i] += sigma2[i];
stempo2[i] += tempo2[i];*/
excutionTime = System.currentTimeMillis() * -1;
HashSet<Actor> seed2 = new DominatingSeed(g).escolher2(k);
excutionTime += System.currentTimeMillis();
tempo2[i] = (excutionTime / 1000.0f);
sigma2[i] = g.espectedSpread(seed2, true);
System.out.println("preSelect: sigma = " + sigma2[i]
+ ", tempo = " + tempo2[i] + " segundos");
ssigma2[i] += sigma2[i];
stempo2[i] += tempo2[i];
excutionTime = System.currentTimeMillis() * -1;
HashSet<Actor> seed3 = new HightDegree(g).escolher(k);
excutionTime += System.currentTimeMillis();
tempo3[i] = (excutionTime / 1000.0f);
sigma3[i] = g.espectedSpread(seed3, true);
System.out.println("HighDegree: sigma = " + sigma3[i]
+ ", tempo = " + tempo3[i] + " segundos");
ssigma3[i] += sigma3[i];
stempo3[i] += tempo3[i];
excutionTime = System.currentTimeMillis() * -1;
HashSet<Actor> seed4 = new RandomSeed(g).escolher(k);
excutionTime += System.currentTimeMillis();
tempo4[i] = (excutionTime / 1000.0f);
sigma4[i] = g.espectedSpread(seed4, true);
System.out.println("RandomSeed: sigma = " + sigma4[i]
+ ", tempo = " + tempo4[i] + " segundos");
ssigma4[i] += sigma4[i];
stempo4[i] += tempo4[i];
}
}
// TODO tirar a média das 10 repetiçoes e plotar a media
for (int i = 0; i < tamSemente.length; i++) {
sigma1[i] = ssigma1[i] / repeticoes;
sigma2[i] = ssigma2[i] / repeticoes;
sigma3[i] = ssigma3[i] / repeticoes;
sigma4[i] = ssigma4[i] / repeticoes;
tempo1[i] = stempo1[i] / repeticoes;
tempo2[i] = stempo2[i] / repeticoes;
tempo3[i] = stempo3[i] / repeticoes;
tempo4[i] = stempo4[i] / repeticoes;
}
MeuPlot meuplot = new MeuPlot();
meuplot.plotPropagacao(tamSemente, sigma1, sigma2, sigma3, sigma4,
outDir);
meuplot.plotTempoExecucao(tamSemente, tempo1, tempo2, tempo3, tempo4,
outDir);
} }
private static void simularPhy() { private static void simularPhy() {
...@@ -124,17 +213,39 @@ public class Simulacao { ...@@ -124,17 +213,39 @@ public class Simulacao {
new Simulacao().simularIC(g, outDir); new Simulacao().simularIC(g, outDir);
} }
private static void simularDblp() {
System.out.println("dblp.txt");
DirectedSocialNetwork g;
g = new GraphReader().readDblp();
System.out.println("|V(G)| = " + g.vertexSet().size());
System.out.println("|E(G)| = " + g.edgeSet().size());
String outDir = "'plots/dblp/";
new Simulacao().simularIC(g, outDir);
}
private static void simularArtificial() {
int i = 2;
while (i <= 4) {
String outDir = "'plots/rand/"+i+"/";
simularRandomGraphIC(i, outDir);
System.out.println("\t----------");
i = i * 2;
}
}
public static void main(String[] args) { public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date data = new Date(); Date data = new Date();
System.out.println("Data de início: " + dateFormat.format(data)); System.out.println("Data de início: " + dateFormat.format(data));
// simularArtificial(); simularArtificial();
// System.out.println("Data de término: " + dateFormat.format(data));
simularPhy(); simularPhy();
System.out.println("Data de término: " + dateFormat.format(data)); // simularEpinions();
simularEpinions();
System.out.println("Data de término: " + dateFormat.format(data));
simularHep(); simularHep();
System.out.println("Data de término: " + dateFormat.format(data)); // simularDblp();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment