Quantcast

How to reference Context builder from Agent class

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

How to reference Context builder from Agent class

Olusola Faboya-2

Hello all,

 

Can somebody give me an idea of how to go about this problem please. I’m simulating private and public transport users’ model using repast symphony.

I have different types of agents (travellers) of varying numbers added from the context builder. (as shown in the codes below).

I want 80% of the whole agents (travellers) to be car users while the other 20% be train users as initiated by the builder.

I have written a code in the (Object obj:context) section of the builder to do this.

My questions are:

1.  I’m not sure if I have done the distribution in the right place and if I still need to add ”context.add(passe)” statement again in the (Object obj:context).

2.  I want to be sure this distribution actually works, so I tried to add a method “getprefferedMode()” in my agent class which will give me the actual mode of a given agent. But I’m finding it difficult to reference the contextbuilder from the agent class so that an agent mode can be known.

 

public class passengMatProjectBuilder implements ContextBuilder<Object> {

       @Override

       public Context build(Context<Object> context) {

             context.setId("passengMatProject");

                          

             ……..

             }

                         

             int youthCounts = 200;

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

                    Passenger passe = new Passenger(space, grid);

                    passe.passType = new Youth();

                    passe.initialize();

                    context.add(passe);

             }

             int abledBodiedCounts = 300;

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

                    Passenger passe = new Passenger(space, grid);

                    passe.passType = new AbleBodiedAdult();

                    passe.initialize();

                    context.add(passe);

             }

            

             (Object obj: context) {

                    int trainUsers =0;

                    int carUsers=0;

                   

                    ArrayList<Passenger>  passeList = new ArrayList<Passenger>();

                           for (Object passenger : passeList){

                           passeList.add((Passenger) passenger);

                           }

                   

                    if(passeList.size()>0){                       

                           trainUsers = (int) (passeList.size()*0.2);

                           carUsers = (int) (passeList.size()*0.8);

                    }

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

                           Passenger passe = new Passenger(space, grid);

                           passe.mode= new ModeTrain();

                           }

                          

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

                           Passenger passe = new Passenger(space, grid);

                           passe.mode=new ModeCar();

                           }

                    NdPoint pt = space.getLocation(obj);

                    grid.moveTo(obj, (int) pt.getX(), (int) pt.getY());

             }

            

            

             return context;}}

 

Olusola

 

 

Olusola Theophilus, FABOYA

Intelligent Modelling & Analysis (IMA) group

Room B36, School of Computer Science,

University of Nottingham,UK.

NG8 1BB

t: +44(0)1158467282

e: [hidden email]

 



This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive.
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
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: How to reference Context builder from Agent class

srcnick
I’m not sure what you are trying to do with the passeList, because as the code is written it will always be empty. Are the passengers added at the beginning with passType of Youth and AbleBodiedAdult, the car and train users? Or, are the car and train users a new set of passengers. If its the former, you could set car / train mode when they are created. In that case, if i < numberOfYouthCarUsers or numberofAdultCarUser then its a carUser  otherwise its a train user. 

Nick

On Oct 26, 2016, at 5:37 AM, Olusola Faboya <[hidden email]> wrote:

Hello all,
 
Can somebody give me an idea of how to go about this problem please. I’m simulating private and public transport users’ model using repast symphony.
I have different types of agents (travellers) of varying numbers added from the context builder. (as shown in the codes below).
I want 80% of the whole agents (travellers) to be car users while the other 20% be train users as initiated by the builder.
I have written a code in the (Object obj:context) section of the builder to do this.
My questions are:
1.  I’m not sure if I have done the distribution in the right place and if I still need to add ”context.add(passe)” statement again in the (Object obj:context).
2.  I want to be sure this distribution actually works, so I tried to add a method “getprefferedMode()” in my agent class which will give me the actual mode of a given agent. But I’m finding it difficult to reference the contextbuilder from the agent class so that an agent mode can be known.
 
public class passengMatProjectBuilder implements ContextBuilder<Object> {
       @Override
       public Context build(Context<Object> context) {
             context.setId("passengMatProject");
                          
             ……..
             }
                         
             int youthCounts = 200;
             for (int i = 0; i < youthCounts; i++) {
                    Passenger passe = new Passenger(space, grid);
                    passe.passType = new Youth();
                    passe.initialize();
                    context.add(passe);
             }
             int abledBodiedCounts = 300;
             for (int i = 0; i < abledBodiedCounts; i++) {
                    Passenger passe = new Passenger(space, grid);
                    passe.passType = new AbleBodiedAdult();
                    passe.initialize();
                    context.add(passe);
             }
            
             (Object obj: context) {
                    int trainUsers =0;
                    int carUsers=0;
                   
                    ArrayList<Passenger>  passeList = new ArrayList<Passenger>();
                           for (Object passenger : passeList){
                           passeList.add((Passenger) passenger);
                           }
                   
                    if(passeList.size()>0){                       
                           trainUsers = (int) (passeList.size()*0.2);
                           carUsers = (int) (passeList.size()*0.8);
                    }
                           for (int i = 0; i<= trainUsers; i++){
                           Passenger passe = new Passenger(space, grid);
                           passe.mode= new ModeTrain();
                           }
                          
                           for (int i = 0; i<= carUsers; i++){
                           Passenger passe = new Passenger(space, grid);
                           passe.mode=new ModeCar();
                           }
                    NdPoint pt = space.getLocation(obj);
                    grid.moveTo(obj, (int) pt.getX(), (int) pt.getY());
             }
            
            
             return context;}}
 
Olusola 
 
 
Olusola Theophilus, FABOYA
Intelligent Modelling & Analysis (IMA) group
Room B36, School of Computer Science,
University of Nottingham,UK.
NG8 1BB
t: +44(0)1158467282
 
This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.
------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive.
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...