Skip to content

Instantly share code, notes, and snippets.

@sammacbeth
Created July 12, 2011 16:38
Show Gist options
  • Save sammacbeth/1078377 to your computer and use it in GitHub Desktop.
Save sammacbeth/1078377 to your computer and use it in GitHub Desktop.
Multiple networks in presage simulation
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.
}
}
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