Creating multiple networks

View: New views
3 Messages — Rating Filter:   Alert me  

Creating multiple networks

by Russell Lawrence :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello all,

I am trying to model a supply chain but am having difficulty trying to
create multiple information networks at the same time.

I have multiple base farmers trying to establish a network with all of
their elevators(distributors). What I would like to do is get a list of
all farmers and then have each one of them create a network to all of
the elevators. I have tried to emulate what was done in AE
SheepNetwork, however, instead of getRandomObjects(), I am using
getObjects() as I want all elevators to be in the network.

I am getting an error that says 'cannot cast 'Farmer 1' with class
'graingame2.Farmer' to class 'graingame2.Elevator'. Is there a way that
a network can be created between agents of different classes?

Here is the groovy code:

// Find all farmers in this context
        Context context = FindContext("Grain Game 2")
        Iterator list = context.getObjects(Farmer.class).iterator()

        // Loop over all of the elevators
        while (list.hasNext()) {

            // Every farmer establishes a link to every elevator
            IndexedIterable iter = GetObjects("Grain Game 2",
"graingame2.Elevator")
            Elevator elevator = list.next()
            CreateEdge("Grain Game 2/Network", this, neighbors.next(),
1.0)
            CreateEdge("Grain Game 2/Network", this, neighbors.next(),
1.0)

        }

Russell

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

Russell Lawrence
M.Sc. Candidate (Agricultural Economics)
College of Agriculture and Bioresources
Saskatoon, SK

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest

Re: Creating multiple networks

by Willem van Asperen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Russel,

What about:

Iterator farmerIter = context.getObjects(Farmer.class);
while (farmerIter.hasNext()) {
  Farmer farmer = (Farmer)farmerIter.next();
  Iterator elevatorIter = context.getObjects(Elevator.class);
  while (elevatorIter.hasNext()) {
    Elevator elevator = (Elevator)elevatorIter.next();
    CreateEdge("Grain Game 2/Network", farmer, elevator, 1.0);
  }
}

Willem

-----Original Message-----
From: Russell Lawrence [mailto:rjl864@...]
Sent: dinsdag 10 november 2009 5:06
To: repast-interest@...
Subject: [Repast-interest] Creating multiple networks

Hello all,

I am trying to model a supply chain but am having difficulty trying to
create multiple information networks at the same time.

I have multiple base farmers trying to establish a network with all of
their elevators(distributors). What I would like to do is get a list of
all farmers and then have each one of them create a network to all of
the elevators. I have tried to emulate what was done in AE
SheepNetwork, however, instead of getRandomObjects(), I am using
getObjects() as I want all elevators to be in the network.

I am getting an error that says 'cannot cast 'Farmer 1' with class
'graingame2.Farmer' to class 'graingame2.Elevator'. Is there a way that
a network can be created between agents of different classes?

Here is the groovy code:

// Find all farmers in this context
        Context context = FindContext("Grain Game 2")
        Iterator list = context.getObjects(Farmer.class).iterator()

        // Loop over all of the elevators
        while (list.hasNext()) {

            // Every farmer establishes a link to every elevator
            IndexedIterable iter = GetObjects("Grain Game 2",
"graingame2.Elevator")
            Elevator elevator = list.next()
            CreateEdge("Grain Game 2/Network", this, neighbors.next(),
1.0)
            CreateEdge("Grain Game 2/Network", this, neighbors.next(),
1.0)

        }

Russell

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

Russell Lawrence
M.Sc. Candidate (Agricultural Economics)
College of Agriculture and Bioresources
Saskatoon, SK

------------------------------------------------------------------------
------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008
30-Day
trial. Simplify your report design, integration and deployment - and
focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest

Re: Creating multiple networks

by David J. Barnes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It might be worth taking advantage of the fact that generic types in
Java have added additional type security, such that you can often avoid
explicit casting. Coupled with the for-each version of the for loop it
should be possible to write Willem's code slightly more succinctly as:

for(Farmer farmer : context.getObjects(Farmer.class)) {
   for(Elevator elevator : context.getObjects(Elevator.class)) {
     CreateEdge("Grain Game 2/Network", farmer, elevator, 1.0);
   }
}

David


Willem van Asperen wrote:

> Hi Russel,
>
> What about:
>
> Iterator farmerIter = context.getObjects(Farmer.class);
> while (farmerIter.hasNext()) {
>   Farmer farmer = (Farmer)farmerIter.next();
>   Iterator elevatorIter = context.getObjects(Elevator.class);
>   while (elevatorIter.hasNext()) {
>     Elevator elevator = (Elevator)elevatorIter.next();
>     CreateEdge("Grain Game 2/Network", farmer, elevator, 1.0);
>   }
> }
>
> Willem
>
> -----Original Message-----
> From: Russell Lawrence [mailto:rjl864@...]
> Sent: dinsdag 10 november 2009 5:06
> To: repast-interest@...
> Subject: [Repast-interest] Creating multiple networks
>
> Hello all,
>
> I am trying to model a supply chain but am having difficulty trying to
> create multiple information networks at the same time.
>
> I have multiple base farmers trying to establish a network with all of
> their elevators(distributors). What I would like to do is get a list of
> all farmers and then have each one of them create a network to all of
> the elevators. I have tried to emulate what was done in AE
> SheepNetwork, however, instead of getRandomObjects(), I am using
> getObjects() as I want all elevators to be in the network.
>
> I am getting an error that says 'cannot cast 'Farmer 1' with class
> 'graingame2.Farmer' to class 'graingame2.Elevator'. Is there a way that
> a network can be created between agents of different classes?
>
> Here is the groovy code:
>
> // Find all farmers in this context
>         Context context = FindContext("Grain Game 2")
>         Iterator list = context.getObjects(Farmer.class).iterator()
>
>         // Loop over all of the elevators
>         while (list.hasNext()) {
>
>             // Every farmer establishes a link to every elevator
>             IndexedIterable iter = GetObjects("Grain Game 2",
> "graingame2.Elevator")
>             Elevator elevator = list.next()
>             CreateEdge("Grain Game 2/Network", this, neighbors.next(),
> 1.0)
>             CreateEdge("Grain Game 2/Network", this, neighbors.next(),
> 1.0)
>
>         }
>
> Russell
>
> ----------------------------------------
>
> Russell Lawrence
> M.Sc. Candidate (Agricultural Economics)
> College of Agriculture and Bioresources
> Saskatoon, SK
>
> ------------------------------------------------------------------------
> ------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Repast-interest mailing list
> Repast-interest@...
> https://lists.sourceforge.net/lists/listinfo/repast-interest
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Repast-interest mailing list
> Repast-interest@...
> https://lists.sourceforge.net/lists/listinfo/repast-interest

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest