Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gs-algo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
graphstream
gs-algo
Commits
4ad586f9
Commit
4ad586f9
authored
13 years ago
by
Ant01n3
Browse files
Options
Downloads
Patches
Plain Diff
Preferential attachement uses doubles.
Also added the citation of the Barabàsi-Albert model used by this generator.
parent
8455d821
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/org/graphstream/algorithm/generator/PreferentialAttachmentGenerator.java
+21
-9
21 additions, 9 deletions
.../algorithm/generator/PreferentialAttachmentGenerator.java
with
21 additions
and
9 deletions
src/org/graphstream/algorithm/generator/PreferentialAttachmentGenerator.java
+
21
−
9
View file @
4ad586f9
...
...
@@ -33,13 +33,15 @@ package org.graphstream.algorithm.generator;
import
java.util.ArrayList
;
/**
* Scale-free graph (tree) generator using the preferential attachement rule.
* Scale-free graph (tree) generator using the preferential attachment rule
* as defined in the Barabási-Albert model.
*
* <p>
* This is a very simple graph generator that generates a tree using the
* preferential attachement rule: nodes are generated one by one, and each time
* attached by an edge to another node that has more chance to choosed if it
* already has lots of nodes attached to it.
* preferential attachment rule defined in the Barabási-Albert model: nodes
* are generated one by one, and each time attached by an edge to another
* node that has more chance to chosen if it already has lots of nodes
* attached to it.
* </p>
*
* <p>
...
...
@@ -47,6 +49,16 @@ import java.util.ArrayList;
* therefore generate trees of any size.
* </p>
*
* <p>This is taken from the paper :
* <ul>
* <li>Emergence of scaling in random networks</li>
* <li>Albert-László Barabási & Réka Albert</li>
* <li>Science 286: 509–512</li>
* <li>October 1999</li>
* <li>doi:10.1126/science.286.5439.509.</li>
* </ul>
* </p>
*
* @since 20061128
*/
public
class
PreferentialAttachmentGenerator
extends
BaseGenerator
{
...
...
@@ -102,16 +114,16 @@ public class PreferentialAttachmentGenerator extends BaseGenerator {
// Compute the attachment probability of each previouly added node
int
sumDeg
=
edgesCount
*
2
;
sumDeg
=
sumDeg
>
0
?
sumDeg
:
1
;
// Choose the node to attach to.
float
sumProba
=
0
;
float
rnd
=
(
float
)
Math
.
random
();
double
sumProba
=
0
;
double
rnd
=
Math
.
random
();
int
otherIdx
=
-
1
;
for
(
int
i
=
0
;
i
<
index
;
++
i
)
{
float
proba
=
sumDeg
==
0
?
1
:
((
float
)
degrees
.
get
(
i
))
/
((
float
)
sumDeg
);
for
(
int
i
=
0
;
i
<
index
;
++
i
)
{
double
proba
=
degrees
.
get
(
i
)
/
((
double
)
sumDeg
);
sumProba
+=
proba
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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