Quantcast

Getting started with a network

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting started with a network

Elliott, Beau

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.

 

I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.

 

I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?

 

Beau Elliott

University of Alabama

Center for Advanced Public Safety


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

Vallee, Francois

Hi Beau,

You need to define a custom NodeCreator class which looks like this:

-----------------------------------------------

import repast.simphony.context.space.graph.NodeCreator;

public class MyNodeCreator implements NodeCreator<Object> {

    @Override
    public Object createNode(String label) {
        return new MyNode(label);
    }

}

-----------------------------------------------

Then you can create a network in Repast with these instructions in the main context build method:

-----------------------------------------------

NetworkBuilder<Object> builder = new NetworkBuilder<Object>(Constants.NETWORK_ID, context, false);
MyNodeCreator nodeCreator = new MyNodeCreator();

builder.load(Constants.NETWORK_FILE, NetworkFileFormat.EXCEL, nodeCreator);

Network<Object> net = builder.buildNetwork();

-----------------------------------------------

Details of networks formats here: http://repast.sourceforge.net/docs/api/repast_simphony/repast/simphony/context/space/graph/NetworkFileFormat.html

Regards,
Francois


On 13/05/16 06:43, Elliott, Beau wrote:

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.

 

I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.

 

I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?

 

Beau Elliott

University of Alabama

Center for Advanced Public Safety



------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j


_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

Elliott, Beau

When you say:

 

return new MyNode(label);

 

That is the node class that I have created?

 

Beau Elliott

Deputy Director, Center for Advanced Public Safety

The University of Alabama
2133 Cyber Hall
Box 870289
Tuscaloosa, AL 35487
Phone <a href="tel:256-333-0769">256-333-0769
[hidden email] | http://caps.ua.edu

The University of Alabama

 

From: Vallee, Francois [mailto:[hidden email]]
Sent: Thursday, May 12, 2016 4:20 PM
To: Elliott, Beau <[hidden email]>; [hidden email]
Subject: Re: [Repast-interest] Getting started with a network

 

Hi Beau,

You need to define a custom NodeCreator class which looks like this:

-----------------------------------------------

import repast.simphony.context.space.graph.NodeCreator;

public class MyNodeCreator implements NodeCreator<Object> {

    @Override
    public Object createNode(String label) {
        return new MyNode(label);
    }

}

-----------------------------------------------

Then you can create a network in Repast with these instructions in the main context build method:

-----------------------------------------------

NetworkBuilder<Object> builder = new NetworkBuilder<Object>(Constants.NETWORK_ID, context, false);
MyNodeCreator nodeCreator = new MyNodeCreator();

builder.load(Constants.NETWORK_FILE, NetworkFileFormat.EXCEL, nodeCreator);

Network<Object> net = builder.buildNetwork();

-----------------------------------------------

Details of networks formats here: http://repast.sourceforge.net/docs/api/repast_simphony/repast/simphony/context/space/graph/NetworkFileFormat.html

Regards,
Francois

 

On 13/05/16 06:43, Elliott, Beau wrote:

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.

 

I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.

 

I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?

 

Beau Elliott

University of Alabama

Center for Advanced Public Safety




------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j




_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

 


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

Vallee, Francois

Yes, it is if you need a custom node class.


On 24/05/16 00:58, Elliott, Beau wrote:

When you say:

 

return new MyNode(label);

 

That is the node class that I have created?

 

Beau Elliott

Deputy Director, Center for Advanced Public Safety

The University of Alabama
2133 Cyber Hall
Box 870289
Tuscaloosa, AL 35487
Phone <a moz-do-not-send="true" href="tel:256-333-0769">256-333-0769
[hidden email]| http://caps.ua.edu

The University of Alabama

 

From: Vallee, Francois [[hidden email]]
Sent: Thursday, May 12, 2016 4:20 PM
To: Elliott, Beau [hidden email]; [hidden email]
Subject: Re: [Repast-interest] Getting started with a network

 

Hi Beau,

You need to define a custom NodeCreator class which looks like this:

-----------------------------------------------

import repast.simphony.context.space.graph.NodeCreator;

public class MyNodeCreator implements NodeCreator<Object> {

    @Override
    public Object createNode(String label) {
        return new MyNode(label);
    }

}

-----------------------------------------------

Then you can create a network in Repast with these instructions in the main context build method:

-----------------------------------------------

NetworkBuilder<Object> builder = new NetworkBuilder<Object>(Constants.NETWORK_ID, context, false);
MyNodeCreator nodeCreator = new MyNodeCreator();

builder.load(Constants.NETWORK_FILE, NetworkFileFormat.EXCEL, nodeCreator);

Network<Object> net = builder.buildNetwork();

-----------------------------------------------

Details of networks formats here: http://repast.sourceforge.net/docs/api/repast_simphony/repast/simphony/context/space/graph/NetworkFileFormat.html

Regards,
Francois

 

On 13/05/16 06:43, Elliott, Beau wrote:

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.

 

I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.

 

I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?

 

Beau Elliott

University of Alabama

Center for Advanced Public Safety




------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j




_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

 



------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

srcnick
In reply to this post by Elliott, Beau
The JZombies model does contain a network. You can see the Network being created in lines 35-37 in JZombiesBuilder. 

NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(
"infection network", context, true);
netBuilder.buildNetwork();

Any agent added to the context referenced above automatically becomes a node in the network. So,

for (int i = 0; i < zombieCount; i++) {
context.add(new Zombie(space, grid));
}


adds Zombies as nodes in the network. The edges are created when a Zombie infects a Human in Zombie.infect(). 

Network<Object> net = (Network<Object>)context.getProjection("infection network");
net.addEdge(this, zombie);

Here we get by name the network that was created in JZombiesBuilder (above), and add an edge to it. “this” refers to the Zombie whose infect method is being run and “zombie” is the Human infected by this Zombie that is now a Zombie.

Nick


On May 12, 2016, at 2:43 PM, Elliott, Beau <[hidden email]> wrote:

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.
 
I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.
 
I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?
 
Beau Elliott
University of Alabama
Center for Advanced Public Safety
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

Elliott, Beau

I see that now.  I’m now able to create a small network using the code:

 

 

            NetworkBuilder<Object> builder = new NetworkBuilder<Object>("Network", context, false);

            MyNodeCreator nodeCreator = new MyNodeCreator();

            try {

            builder.load("C:\\Users\\Beau\\workspace\\GraphExample\\data\\test.xls", NetworkFileFormat.EXCEL, nodeCreator);

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            }

            Network<Object> net = builder.buildNetwork();

 

The spreadsheet looks like this: 

A

B

C

D

A

0

1835

0

0

B

0

0

400

0

C

0

0

0

2400

D

0

600

0

0

 

 

When I look at the output file for the network, I see this:

0.00 1.00 0.00 0.00

1.00 0.00 1.00 1.00

0.00 1.00 0.00 1.00

0.00 1.00 1.00 0.00

 

It doesn’t have the weights that I need, but that’s probably ok for now. 


Here’s my next question:  My “agents” aren’t the nodes.   They are representing the road network.  My actual agents will be the officer class that I have built.  I would like to place the officers on random nodes throughout the network that I built above.  Is that possible?  Then for every tick that transpires, I want the officer to move to a different a neighbor node based off the distance (i.e. the weights of the edges). 

 

Thanks for helping me in this!


Beau

From: Nick Collier [mailto:[hidden email]]
Sent: Tuesday, May 24, 2016 7:54 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email]
Subject: Re: [Repast-interest] Getting started with a network

 

The JZombies model does contain a network. You can see the Network being created in lines 35-37 in JZombiesBuilder. 

 

NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(

                              "infection network", context, true);

               netBuilder.buildNetwork();

 

Any agent added to the context referenced above automatically becomes a node in the network. So,

 

for (int i = 0; i < zombieCount; i++) {

                       context.add(new Zombie(space, grid));

               }

 

 

adds Zombies as nodes in the network. The edges are created when a Zombie infects a Human in Zombie.infect(). 

 

Network<Object> net = (Network<Object>)context.getProjection("infection network");

                       net.addEdge(this, zombie);

 

Here we get by name the network that was created in JZombiesBuilder (above), and add an edge to it. “this” refers to the Zombie whose infect method is being run and “zombie” is the Human infected by this Zombie that is now a Zombie.

 

Nick

 

 

On May 12, 2016, at 2:43 PM, Elliott, Beau <[hidden email]> wrote:

 

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.

 

I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.

 

I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?

 

Beau Elliott

University of Alabama

Center for Advanced Public Safety

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

 


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

srcnick
That doesn’t look like the correct network, so something is going wrong in your loading. Is any other network creation code being run? 

You can get random objects (such as the network node agents) from the context with context.getRandomObjects.

So assuming you have a list of your Officers in officers. You could also get them from the context.

int i = 0;
int officerCount = officers.size();
for (X node : context.getRandomObjects(X.class, officerCount)) {
     Officer officer = officers.get(i);
    officer.setNode(node);
++i;
}

where X is the class of your network node. 

Nick

On May 24, 2016, at 4:45 PM, Elliott, Beau <[hidden email]> wrote:

 
 
            NetworkBuilder<Object> builder = new NetworkBuilder<Object>("Network",context, false);
            MyNodeCreator nodeCreator = new MyNodeCreator();
            try {
            builder.load("C:<a href="smb://Users//Beau//workspace//GraphExample//data//test.xls" style="color: purple; text-decoration: underline;" class="">\\Users\\Beau\\workspace\\GraphExample\\data\\test.xls", NetworkFileFormat.EXCEL, nodeCreator);
            } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
            Network<Object> net = builder.buildNetwork();
 
The spreadsheet looks like this: 
A
B
C
D
A
0
1835
0
0
B
0
0
400
0
C
0
0
0
2400
D
0
600
0
0
 
 
When I look at the output file for the network, I see this:
0.00 1.00 0.00 0.00
1.00 0.00 1.00 1.00
0.00 1.00 0.00 1.00
0.00 1.00 1.00 0.00
 
It doesn’t have the weights that I need, but that’s probably ok for now. 

Here’s my next question:  My “agents” aren’t the nodes.   They are representing the road network.  My actual agents will be the officer class that I have built.  I would like to place the officers on random nodes throughout the network that I built above.  Is that possible?  Then for every tick that transpires, I want the officer to move to a different a neighbor node based off the distance (i.e. the weights of the edges). 
 
Thanks for helping me in this!

Beau
From: Nick Collier [[hidden email]] 
Sent: Tuesday, May 24, 2016 7:54 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email]
Subject: Re: [Repast-interest] Getting started with a network
 
The JZombies model does contain a network. You can see the Network being created in lines 35-37 in JZombiesBuilder. 
 
NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(
                              "infection network", context, true);
               netBuilder.buildNetwork();
 
Any agent added to the context referenced above automatically becomes a node in the network. So,
 
for (int i = 0; i < zombieCount; i++) {
                       context.add(new Zombie(space, grid));
               }
 
 
adds Zombies as nodes in the network. The edges are created when a Zombie infects a Human in Zombie.infect(). 
 
Network<Object> net = (Network<Object>)context.getProjection("infection network");
                       net.addEdge(this, zombie);
 
Here we get by name the network that was created in JZombiesBuilder (above), and add an edge to it. “this” refers to the Zombie whose infect method is being run and “zombie” is the Human infected by this Zombie that is now a Zombie.
 
Nick
 
 
On May 12, 2016, at 2:43 PM, Elliott, Beau <[hidden email]> wrote:
 
I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.
 
I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.
 
I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?
 
Beau Elliott
University of Alabama
Center for Advanced Public Safety
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

Elliott, Beau

That’s the only network creation code I have.  Not looking at the actual weights, the output seems to create the same undirected graph that I input in…it’s just instead of a weight of 1835, it’s just 1.0…but I could be wrong about that.

 

I apologize if I’m not understanding you on the placing officers on my network that I created below.  I want to create that network as the “roadway” for my agents to travel on.  I don’t really want the nodes of the network to do anything.  I just want them to have a name (i.e. node 18732) and a weight to it’s neighbors. 

 

So in the example you have below, my context.getRandomObjects will be my network that I created?   If that’s the case, then I can get the random node from that list and store that data in my Officer class as where that officer is placed in the network?

 

Is that accurate?

 

 

Beau

From: Nick Collier [mailto:[hidden email]]
Sent: Wednesday, May 25, 2016 8:08 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email]
Subject: Re: [Repast-interest] Getting started with a network

 

That doesn’t look like the correct network, so something is going wrong in your loading. Is any other network creation code being run? 

 

You can get random objects (such as the network node agents) from the context with context.getRandomObjects.

 

So assuming you have a list of your Officers in officers. You could also get them from the context.

 

int i = 0;

int officerCount = officers.size();

for (X node : context.getRandomObjects(X.class, officerCount)) {

     Officer officer = officers.get(i);

    officer.setNode(node);

            ++i;

}

 

where X is the class of your network node. 

 

Nick

 

On May 24, 2016, at 4:45 PM, Elliott, Beau <[hidden email]> wrote:

 

I see that now.  I’m now able to create a small network using the code:

 

 

            NetworkBuilder<Object> builder = new NetworkBuilder<Object>("Network",context, false);

            MyNodeCreator nodeCreator = new MyNodeCreator();

            try {

            builder.load("C:<a href="smb://Users/Beau/workspace/GraphExample/data/test.xls">\\Users\\Beau\\workspace\\GraphExample\\data\\test.xls", NetworkFileFormat.EXCEL, nodeCreator);

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            }

            Network<Object> net = builder.buildNetwork();

 

The spreadsheet looks like this: 

A

B

C

D

A

0

1835

0

0

B

0

0

400

0

C

0

0

0

2400

D

0

600

0

0

 

 

When I look at the output file for the network, I see this:

0.00 1.00 0.00 0.00

1.00 0.00 1.00 1.00

0.00 1.00 0.00 1.00

0.00 1.00 1.00 0.00

 

It doesn’t have the weights that I need, but that’s probably ok for now. 


Here’s my next question:  My “agents” aren’t the nodes.   They are representing the road network.  My actual agents will be the officer class that I have built.  I would like to place the officers on random nodes throughout the network that I built above.  Is that possible?  Then for every tick that transpires, I want the officer to move to a different a neighbor node based off the distance (i.e. the weights of the edges). 

 

Thanks for helping me in this!


Beau

From: Nick Collier [[hidden email]] 
Sent: Tuesday, May 24, 2016 7:54 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email]
Subject: Re: [Repast-interest] Getting started with a network

 

The JZombies model does contain a network. You can see the Network being created in lines 35-37 in JZombiesBuilder. 

 

NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(

                              "infection network", context, true);

               netBuilder.buildNetwork();

 

Any agent added to the context referenced above automatically becomes a node in the network. So,

 

for (int i = 0; i < zombieCount; i++) {

                       context.add(new Zombie(space, grid));

               }

 

 

adds Zombies as nodes in the network. The edges are created when a Zombie infects a Human in Zombie.infect(). 

 

Network<Object> net = (Network<Object>)context.getProjection("infection network");

                       net.addEdge(this, zombie);

 

Here we get by name the network that was created in JZombiesBuilder (above), and add an edge to it. “this” refers to the Zombie whose infect method is being run and “zombie” is the Human infected by this Zombie that is now a Zombie.

 

Nick

 

 

On May 12, 2016, at 2:43 PM, Elliott, Beau <[hidden email]> wrote:

 

I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.

 

I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.

 

I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?

 

Beau Elliott

University of Alabama

Center for Advanced Public Safety

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

 


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

Vallee, Francois
In reply to this post by srcnick
From the output of Repast, you are creating an undirected network. Could you try to make your spreadsheet  a symmetrical matrix like this:


A
B
C
D
A
0
1835
0
0
B
1835
0
400
600
C
0
400
0
2400
D
0
600
2400
0

That's the kind of matrix I use and it loads well.

For your problem about moving agents, I have the same kind of model and I chose to make my nodes as contexts (extends SmallDefaultContext class) so I can move agents from one to another (by removing and adding them to nodes).

Francois

On 26/05/16 01:08, Nick Collier wrote:
That doesn’t look like the correct network, so something is going wrong in your loading. Is any other network creation code being run? 

You can get random objects (such as the network node agents) from the context with context.getRandomObjects.

So assuming you have a list of your Officers in officers. You could also get them from the context.

int i = 0;
int officerCount = officers.size();
for (X node : context.getRandomObjects(X.class, officerCount)) {
     Officer officer = officers.get(i);
    officer.setNode(node);
++i;
}

where X is the class of your network node. 

Nick

On May 24, 2016, at 4:45 PM, Elliott, Beau <[hidden email]> wrote:

 
 
            NetworkBuilder<Object> builder = new NetworkBuilder<Object>("Network",context, false);
            MyNodeCreator nodeCreator = new MyNodeCreator();
            try {
            builder.load("C:<a moz-do-not-send="true" href="smb://Users//Beau//workspace//GraphExample//data//test.xls" style="color: purple; text-decoration: underline;" class="">\\Users\\Beau\\workspace\\GraphExample\\data\\test.xls", NetworkFileFormat.EXCEL, nodeCreator);
            } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
            Network<Object> net = builder.buildNetwork();
 
The spreadsheet looks like this: 

A
B
C
D
A
0
1835
0
0
B
0
0
400
0
C
0
0
0
2400
D
0
600
0
0
 
 
When I look at the output file for the network, I see this:
0.00 1.00 0.00 0.00
1.00 0.00 1.00 1.00
0.00 1.00 0.00 1.00
0.00 1.00 1.00 0.00
 
It doesn’t have the weights that I need, but that’s probably ok for now. 

Here’s my next question:  My “agents” aren’t the nodes.   They are representing the road network.  My actual agents will be the officer class that I have built.  I would like to place the officers on random nodes throughout the network that I built above.  Is that possible?  Then for every tick that transpires, I want the officer to move to a different a neighbor node based off the distance (i.e. the weights of the edges). 
 
Thanks for helping me in this!

Beau
From: Nick Collier [[hidden email]] 
Sent: Tuesday, May 24, 2016 7:54 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email][hidden email]
Subject: Re: [Repast-interest] Getting started with a network
 
The JZombies model does contain a network. You can see the Network being created in lines 35-37 in JZombiesBuilder. 
 
NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(
                              "infection network", context, true);
               netBuilder.buildNetwork();
 
Any agent added to the context referenced above automatically becomes a node in the network. So,
 
for (int i = 0; i < zombieCount; i++) {
                       context.add(new Zombie(space, grid));
               }
 
 
adds Zombies as nodes in the network. The edges are created when a Zombie infects a Human in Zombie.infect(). 
 
Network<Object> net = (Network<Object>)context.getProjection("infection network");
                       net.addEdge(this, zombie);
 
Here we get by name the network that was created in JZombiesBuilder (above), and add an edge to it. “this” refers to the Zombie whose infect method is being run and “zombie” is the Human infected by this Zombie that is now a Zombie.
 
Nick
 
 
On May 12, 2016, at 2:43 PM, Elliott, Beau <[hidden email][hidden email]> wrote:
 
I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.
 
I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.
 
I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?
 
Beau Elliott
University of Alabama
Center for Advanced Public Safety
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest



------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j


_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting started with a network

srcnick
In reply to this post by Elliott, Beau
Yes, if the class parameter passed to getRandomObjects is the class of the network node “agent” then only random objects of that type will be selected. You could also do what Fracois suggests in the other rely.

Nick


On May 25, 2016, at 10:57 AM, Elliott, Beau <[hidden email]> wrote:

 
I apologize if I’m not understanding you on the placing officers on my network that I created below.  I want to create that network as the “roadway” for my agents to travel on.  I don’t really want the nodes of the network to do anything.  I just want them to have a name (i.e. node 18732) and a weight to it’s neighbors. 
 
So in the example you have below, my context.getRandomObjects will be my network that I created?   If that’s the case, then I can get the random node from that list and store that data in my Officer class as where that officer is placed in the network?
 
Is that accurate?
 
 
Beau
From: Nick Collier [[hidden email]] 
Sent: Wednesday, May 25, 2016 8:08 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email]
Subject: Re: [Repast-interest] Getting started with a network
 
That doesn’t look like the correct network, so something is going wrong in your loading. Is any other network creation code being run? 
 
You can get random objects (such as the network node agents) from the context with context.getRandomObjects.
 
So assuming you have a list of your Officers in officers. You could also get them from the context.
 
int i = 0;
int officerCount = officers.size();
for (X node : context.getRandomObjects(X.class, officerCount)) {
     Officer officer = officers.get(i);
    officer.setNode(node);
            ++i;
}
 
where X is the class of your network node. 
 
Nick
 
On May 24, 2016, at 4:45 PM, Elliott, Beau <[hidden email]> wrote:
 
I see that now.  I’m now able to create a small network using the code:
 
 
            NetworkBuilder<Object> builder = new NetworkBuilder<Object>("Network",context, false);
            MyNodeCreator nodeCreator = new MyNodeCreator();
            try {
            builder.load("C:<a href="smb://Users/Beau/workspace/GraphExample/data/test.xls" style="color: purple; text-decoration: underline;" class="">\\Users\\Beau\\workspace\\GraphExample\\data\\test.xls", NetworkFileFormat.EXCEL, nodeCreator);
            } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
            Network<Object> net = builder.buildNetwork();
 
The spreadsheet looks like this: 
A
B
C
D
A
0
1835
0
0
B
0
0
400
0
C
0
0
0
2400
D
0
600
0
0
 
 
When I look at the output file for the network, I see this:
0.00 1.00 0.00 0.00
1.00 0.00 1.00 1.00
0.00 1.00 0.00 1.00
0.00 1.00 1.00 0.00
 
It doesn’t have the weights that I need, but that’s probably ok for now. 

Here’s my next question:  My “agents” aren’t the nodes.   They are representing the road network.  My actual agents will be the officer class that I have built.  I would like to place the officers on random nodes throughout the network that I built above.  Is that possible?  Then for every tick that transpires, I want the officer to move to a different a neighbor node based off the distance (i.e. the weights of the edges). 
 
Thanks for helping me in this!

Beau
From: Nick Collier [[hidden email]] 
Sent: Tuesday, May 24, 2016 7:54 AM
To: Elliott, Beau <[hidden email]>
Cc: [hidden email]
Subject: Re: [Repast-interest] Getting started with a network
 
The JZombies model does contain a network. You can see the Network being created in lines 35-37 in JZombiesBuilder. 
 
NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(
                              "infection network", context, true);
               netBuilder.buildNetwork();
 
Any agent added to the context referenced above automatically becomes a node in the network. So,
 
for (int i = 0; i < zombieCount; i++) {
                       context.add(new Zombie(space, grid));
               }
 
 
adds Zombies as nodes in the network. The edges are created when a Zombie infects a Human in Zombie.infect(). 
 
Network<Object> net = (Network<Object>)context.getProjection("infection network");
                       net.addEdge(this, zombie);
 
Here we get by name the network that was created in JZombiesBuilder (above), and add an edge to it. “this” refers to the Zombie whose infect method is being run and “zombie” is the Human infected by this Zombie that is now a Zombie.
 
Nick
 
 
On May 12, 2016, at 2:43 PM, Elliott, Beau <[hidden email]> wrote:
 
I’m trying to build an agent based model of police cars covering a road network.  I have a list of nodes (i.e. intersections).  I know the distance between each node and I know the neighbors for each node.  This should be an undirected graph I would presume.
 
I’m trying to build a model to determine the number of police cars needed to “cover” all the nodes in the graph.  I have a general understanding of what I’m wanting to do, but I’m having a hard time putting this into something in Repast.  Specifically, I’m confused in how to build the context of system.  The only examples I’ve seen is the human/zombies example and it’s using a grid and not a network.  I feel once I have create my network in the system, I could code the actions of my agents in the network.
 
I would like to build my network using my node list that I have, and then randomly place police cars in the graph.  For every tick, I would like the police cars to traverse the graph.  Are there any examples that exist that would put me on the right track?
 
Beau Elliott
University of Alabama
Center for Advanced Public Safety
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...