Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
8c2dd499
Commit
8c2dd499
authored
Aug 15, 2016
by
Tim Feuerbach
Browse files
fixed nondeterministic behavior in SocialTransitionStrategy
parent
d8cf5cf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modular/transition/SocialTransitionStrategy.java
View file @
8c2dd499
...
...
@@ -20,24 +20,13 @@
package
de.tud.kom.p2psim.impl.topology.movement.modular.transition
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.Random
;
import
java.util.Set
;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.common.SimHostComponent
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.api.topology.social.SocialView
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
...
...
@@ -51,7 +40,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* This is a {@link TransitionStrategy} for the Social Case. It will be try to
* build groups based on the {@link SocialView} information. For this, it tries
* to assignment the given {@link
MovementSupported
} objects to the given
* to assignment the given {@link
SimLocationActuator
} objects to the given
* {@link AttractionPoint}s. For the {@link SocialView}, it is required a
* {@link #socialId}, to find the right {@link SocialView}.
*
...
...
@@ -65,7 +54,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* {@link AttractionPoint}. For that, it will be used only the AttractionPoints,
* of the hosts, which are in the same SocialCluster or are SocialNeighbors. For
* this AttractionPoints it will be find the highest scoring, which is to found
* in {@link #score(
MovementSupported
, AttractionPoint, List, List, List, List)}
* in {@link #score(
SimLocationActuator
, AttractionPoint, List, List, List, List)}
* .
*
* <br>
...
...
@@ -205,7 +194,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
private
AttractionPoint
findHighestScore
(
SimLocationActuator
ms
,
List
<
AttractionPoint
>
apFavorites
,
List
<
AttractionPoint
>
apFriends
,
List
<
AttractionPoint
>
apClusters
,
List
<
AttractionPoint
>
apRandom
)
{
Set
<
AttractionPoint
>
aps
=
new
HashSet
<
AttractionPoint
>();
Set
<
AttractionPoint
>
aps
=
new
Linked
HashSet
<
AttractionPoint
>();
aps
.
addAll
(
apFavorites
);
aps
.
addAll
(
apFriends
);
aps
.
addAll
(
apClusters
);
...
...
@@ -226,7 +215,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
}
/**
* Score the given AttractionPoint for the given {@link
MovementSupported
}. <br>
* Score the given AttractionPoint for the given {@link
SimLocationActuator
}. <br>
* (clusterScore/#NodesInAp + friendsScore + 1/#NodesInAp) * socialFactor +
* (distanceScore + penalty) + (1-socialFactor) <br>
*
...
...
@@ -303,7 +292,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
private
List
<
AttractionPoint
>
getRandomPlaces
(
SimLocationActuator
ms
,
int
number
)
{
Collections
.
shuffle
(
aPoints
);
Collections
.
shuffle
(
aPoints
,
rand
);
List
<
AttractionPoint
>
result
=
new
Vector
<
AttractionPoint
>();
Iterator
<
AttractionPoint
>
iAP
=
aPoints
.
iterator
();
for
(
int
i
=
0
;
i
<
number
&&
iAP
.
hasNext
();
i
++)
{
...
...
@@ -346,7 +335,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
}
private
AttractionPoint
getRandomPlace
(
SimLocationActuator
ms
)
{
Collections
.
shuffle
(
aPoints
);
Collections
.
shuffle
(
aPoints
,
rand
);
return
aPoints
.
iterator
().
next
();
}
...
...
@@ -384,7 +373,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
}
private
void
assignFavoritePlaces
(
SimLocationActuator
ms
)
{
Set
<
AttractionPoint
>
msFavoritePlaces
=
new
HashSet
<
AttractionPoint
>();
Set
<
AttractionPoint
>
msFavoritePlaces
=
new
Linked
HashSet
<
AttractionPoint
>();
LinkedList
<
AttractionPoint
>
temp
=
new
LinkedList
<
AttractionPoint
>(
aPoints
);
Collections
.
shuffle
(
temp
,
rand
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/SocialTransitionStrategy.java
View file @
8c2dd499
...
...
@@ -23,7 +23,6 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedList
;
...
...
@@ -224,7 +223,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private
AttractionPoint
findHighestScore
(
SimLocationActuator
ms
,
List
<
AttractionPoint
>
apFavorites
,
List
<
AttractionPoint
>
apFriends
,
List
<
AttractionPoint
>
apClusters
,
List
<
AttractionPoint
>
apRandom
)
{
Set
<
AttractionPoint
>
aps
=
new
HashSet
<
AttractionPoint
>();
Set
<
AttractionPoint
>
aps
=
new
Linked
HashSet
<
AttractionPoint
>();
aps
.
addAll
(
apFavorites
);
aps
.
addAll
(
apFriends
);
aps
.
addAll
(
apClusters
);
...
...
@@ -322,7 +321,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private
List
<
AttractionPoint
>
getRandomPlaces
(
SimLocationActuator
ms
,
int
number
)
{
Collections
.
shuffle
(
aPoints
);
Collections
.
shuffle
(
aPoints
,
rand
);
List
<
AttractionPoint
>
result
=
new
Vector
<
AttractionPoint
>();
Iterator
<
AttractionPoint
>
iAP
=
aPoints
.
iterator
();
for
(
int
i
=
0
;
i
<
number
&&
iAP
.
hasNext
();
i
++)
{
...
...
@@ -365,7 +364,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
}
private
void
assignFavoritePlaces
(
SimLocationActuator
ms
)
{
Set
<
AttractionPoint
>
msFavoritePlaces
=
new
HashSet
<
AttractionPoint
>();
Set
<
AttractionPoint
>
msFavoritePlaces
=
new
Linked
HashSet
<
AttractionPoint
>();
LinkedList
<
AttractionPoint
>
temp
=
new
LinkedList
<
AttractionPoint
>(
aPoints
);
Collections
.
shuffle
(
temp
,
rand
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment