Quantcast

Re: How to reference Context builder from the Agent Class

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

Re: How to reference Context builder from the Agent Class

Olusola Faboya-2
Hi Nick,
Thanks for your assistance. I tried another method which seemed to work for what I wanted to do. I distributed each of the types into 80/20 % as they are added into the context.  The code segment used is given below.

Regards

Olusola

.
.
.
int abledBodiedCounts = 300;
                for (int i = 0; i < abledBodiedCounts; i++) {
                        Passenger passe = new Passenger(space, grid);
                        passe.passType = new AbleBodiedAdult();
                        passe.initialize();
                        if (i<= abledBodiedCounts*0.8 ){
                                passe.prefferedMode = new ModeCar();
                        }else passe.prefferedMode = new ModeTrain();
                        context.add(passe);
                }
       
                       
                 for (Object obj : context) {
                        NdPoint pt = space.getLocation(obj);
                        grid.moveTo(obj, (int) pt.getX(), (int) pt.getY());
                }
               
               
                return context;
        }
________________________________________
From: [hidden email] [[hidden email]]
Sent: 26 October 2016 14:58
To: [hidden email]
Subject: Repast-interest Digest, Vol 125, Issue 21

Send Repast-interest mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.sourceforge.net/lists/listinfo/repast-interest
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Repast-interest digest..."


Today's Topics:

   1. Re: How to reference Context builder from Agent   class
      (Nick Collier)


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

Message: 1
Date: Wed, 26 Oct 2016 09:57:05 -0400
From: Nick Collier <[hidden email]>
Subject: Re: [Repast-interest] How to reference Context builder from
        Agent   class
To: Olusola Faboya <[hidden email]>
Cc: "[hidden email]"
        <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="utf-8"

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
> e: [hidden email] <mailto:[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 <http://asp.net/> CLI. Get your free copy!
> http://sdm.link/telerik_______________________________________________ <http://sdm.link/telerik_______________________________________________>
> Repast-interest mailing list
> [hidden email] <mailto:[hidden email]>
> https://lists.sourceforge.net/lists/listinfo/repast-interest <https://lists.sourceforge.net/lists/listinfo/repast-interest>
-------------- next part --------------
An HTML attachment was scrubbed...

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

------------------------------------------------------------------------------
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


End of Repast-interest Digest, Vol 125, Issue 21
************************************************




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
Loading...