Created
July 12, 2011 16:38
-
-
Save sammacbeth/1078377 to your computer and use it in GitHub Desktop.
Multiple networks in presage simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloAgent extends AbstractParticipant implements HasLocation, | |
HasPerceptionRange, HasCommunicationRange { | |
final protected NetworkAdaptor uplink; | |
public HelloAgent(UUID id, String name, Location loc, | |
double perceptionRange, double communicationRange, NetworkAdaptor uplink) { | |
super(id, name); | |
... | |
this.uplink = uplink; | |
// now this.uplink is fully connected uplink network, and this.network is ad-hoc. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloWorldSimulation extends InjectedSimulation { | |
@Override | |
protected void addToScenario(Scenario s) { | |
// create uplink network | |
NetworkController uplinkController = new NetworkController(getInjector().getInstance( | |
Time.class), getInjector().getInstance( | |
EnvironmentSharedStateAccess.class), getInjector().getInstance( | |
Scenario.class)); | |
for (int i = 0; i < agentCount; i++) { | |
final UUID id = Random.randomUUID(); | |
// create network adaptor for agent | |
NetworkAdaptor uplink = new NetworkConnectorWithNodeDiscovery( | |
uplinkController, new NetworkAddress(id), getInjector() | |
.getInstance(Time.class), getInjector() | |
.getInstance(Scenario.class)); | |
Participant p = new HelloAgent(id, "helloagent" + i, | |
new Discrete2DLocation(Random.randomInt(xSize), | |
Random.randomInt(ySize)), 10, 10, uplink); | |
getInjector().injectMembers(p); | |
s.addParticipant(p); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment