Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
influence_maximization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rsmelo@inf.ufpr.br
influence_maximization
Commits
b2703a63
Commit
b2703a63
authored
Mar 21, 2016
by
Renato Melo
Browse files
Options
Downloads
Patches
Plain Diff
PrevalentSeed
parent
dca44317
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/algoritmos/MinDominatingSet.java
+1
-1
1 addition, 1 deletion
src/algoritmos/MinDominatingSet.java
src/algoritmos/PrevalentSeed.java
+44
-12
44 additions, 12 deletions
src/algoritmos/PrevalentSeed.java
src/grafos/DirectedSocialNetwork.java
+25
-21
25 additions, 21 deletions
src/grafos/DirectedSocialNetwork.java
with
70 additions
and
34 deletions
src/algoritmos/MinDominatingSet.java
+
1
−
1
View file @
b2703a63
...
@@ -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 aresta
s
*
Com grafo direcionado não retorna um conjunto dominante, mas é um bom cojunto de vértices influente
s
**/
**/
public
HashSet
<
Actor
>
fastGreedy
(
DirectedSocialNetwork
grafo
)
{
public
HashSet
<
Actor
>
fastGreedy
(
DirectedSocialNetwork
grafo
)
{
...
...
This diff is collapsed.
Click to expand it.
src/algoritmos/
Dominating
Seed.java
→
src/algoritmos/
Prevalent
Seed.java
+
44
−
12
View file @
b2703a63
...
@@ -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ã
i
o 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
Dominating
Seed
implements
SeedChooser
<
Actor
>
{
public
class
Prevalent
Seed
implements
SeedChooser
<
Actor
>
{
private
DirectedSocialNetwork
grafo
;
private
DirectedSocialNetwork
grafo
;
public
Dominating
Seed
(
DirectedSocialNetwork
g
)
{
public
Prevalent
Seed
(
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
Dominating
Seed
(
g
).
escolher2
(
15
);
HashSet
<
Actor
>
seed
=
new
Prevalent
Seed
(
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
Dominating
Seed
(
g
).
escolher
(
15
);
HashSet
<
Actor
>
seed2
=
new
Prevalent
Seed
(
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
);
...
...
This diff is collapsed.
Click to expand it.
src/grafos/DirectedSocialNetwork.java
+
25
−
21
View file @
b2703a63
...
@@ -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
=
10
000
;
int
repeticoes
=
5
000
;
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
(
4
0
,
2
);
g
=
new
SocialNetworkGenerate
().
gerarGrafo
(
3
0
,
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
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment