Sample6_Networks.java
Created with JBuilder |
import mads.core.*;
import mads.networks.*;
/**
* <p><H1>Introducing Networks</H1></p>
*
* <p><B>Sample project no. 6 </B><BR> </p>
* In many simulation, studying just one agent in isolation is not enough. In these
* cases, an agent`s decisions are not motivated only by direct profit (like it was
* in the previously presented cogeneration simulation) but also by the decisions
* taken by other agents, which whom this agent is in direct contact with. In such
* cases, agents are considered to reside on a network with some specified topology.
* Each agent corresponds to one not in this network (graph). <BR>
* In MADS, the most used network topologies are predefined and can be used by accessing
* one of the available network generators. The obtained network is called Service
* Network Function and contains at any point in time a network (graph). Currently, for
* MADS works only with networks that store the same network for all points in time,
* but future versions may allow for networks that evolve through time<BR>
* This example will show how to work with networks. Complete simulations will be shown
* in the next two samples.
* The user should notice the following things:<BR\>
* <UL>
* <LI> Network are expressed as Service Network Functions
* <LI> Service Network Functions can be obtained using Network Generators
* </UL>
*/
public class Sample6_Networks extends ASimulationAgent
{
public void doWork(){
/**
In the following, we will define a 2D grid generator and use it to create a
5x5 grid. To have access to network generators, one must include the
the network package by using the "import mads.networks.*;" instruction.
*/
// Get the generator
NetworkGenerator gridGenerator = new TwoDimLatticeGenerator(5, false);
// Get the ServiceNetworkFunction
ServiceNetworkFunction snfGrid = gridGenerator.generateNetwork();
// Plot the structure at t = 0 (as we said, the network is the same for all the
// values of t.
snfGrid.plot(0, "2D Grid");
/**
* Now let`s define a 1D small world network, using a shorter form.
* This network will have 25 nodes, an average degree of 4 and a re-wiring probability
* of 0.1
*/
// Get the ServiceNetworkFunction
ServiceNetworkFunction snfSmWorld = (new WattsSmallWorldNetworkGenerator(25, 0.1, 4)).generateNetwork();
// Plot it
snfSmWorld.plot(0, "Small world network");
}
}
Sample6_Networks.java
Created with JBuilder |