Skip to main content
Jump to: navigation, search

AMP/UserGuide/AMF/ExampleRepastCode

< AMP‎ | UserGuide‎ | AMF
Revision as of 22:27, 14 October 2009 by Milesparker.gmail.com (Talk | contribs) (New page: <source lang="java"> @repast.simphony.engine.schedule.ScheduledMethod(start = 1, interval = 1, priority = -0) public void findPartner() { final repast.simphony.context.Cont...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
    @repast.simphony.engine.schedule.ScheduledMethod(start = 1, interval = 1, priority = -0)
    public void findPartner() {
        final repast.simphony.context.Context context = repast.simphony.util.ContextUtils.getContext(this);
        final repast.simphony.space.grid.Grid city = (repast.simphony.space.grid.Grid) context.getProjection("City");
        {
            repast.simphony.query.Query<Object> partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_QueryCondition = new repast.simphony.query.Query<Object>() {
                public java.lang.Iterable<Object> query() {
 
                    return new repast.simphony.util.collections.FilteredIterator<Object>(context.iterator(),
                            new org.apache.commons.collections15.Predicate() {
                        public boolean evaluate(Object object) {
 
                            if (object instanceof Individual) {
                                Individual partner = (Individual) object;
                                return partner.getAge() == partner.getAge();
                            } else {
                                return false;
                            }
 
                        }
                    });
                }
 
                public java.lang.Iterable<Object> query(java.lang.Iterable<Object> other) {
                    return new repast.simphony.util.collections.FilteredIterator<Object>(query().iterator(),
                            repast.simphony.query.QueryUtils.createContains(other));
                }
            };
            repast.simphony.query.Query<Object> partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Query = null;
            partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Query = new repast.simphony.query.space.grid.GridWithin(
                                                                                                                      city, this, partner.getVision());
            partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Query = new repast.simphony.query.AndQuery<Object>(
                    partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Query,
                    partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_QueryCondition);
            java.util.Iterator partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Iter = partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Query
            .query().iterator();
            if (partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Iter.hasNext()) {
                java.util.List partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_List = org.apache.commons.collections15.IteratorUtils
                .toList(partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_Iter);
                final Individual partner = (Individual) partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_List
                .get(repast.simphony.random.RandomHelper.nextIntFromTo(0,
                                                                       partner_AgeIdenticalAgeQueryOrWithin_Vision_Query_List
                                                                       .size() - 1));
                {
                    repast.simphony.query.Query<Object> partnerNeighbor_AvailableQueryOrNeighborQuery_Query = null;
                    partnerNeighbor_AvailableQueryOrNeighborQuery_Query = new repast.simphony.query.space.grid.GridWithin(
                                                                                                                          city, this, 1);
                    repast.simphony.query.Query<Object> partnerNeighbor_AvailableQueryOrNeighborQuery_QueryAvailable = new repast.simphony.query.Query<Object>() {
                        public java.lang.Iterable<Object> query() {
 
                            return new repast.simphony.util.collections.FilteredIterator<Object>(context.iterator(),
                                    new org.apache.commons.collections15.Predicate() {
                                public boolean evaluate(Object object) {
 
                                    repast.simphony.space.grid.GridPoint location = city.getLocation(object);
                                    if (location != null) {
                                        java.util.Iterator locIter = city.getObjectsAt(location.toIntArray(null))
                                        .iterator();
                                        if (locIter.hasNext()) {
                                            locIter.next();
                                            if (!locIter.hasNext()) {
                                                return true;
                                            }
                                        }
                                    }
                                    return false;
 
                                }
                            });
 
                        }
 
                        public java.lang.Iterable<Object> query(java.lang.Iterable<Object> other) {
                            return new repast.simphony.util.collections.FilteredIterator<Object>(query().iterator(),
                                    repast.simphony.query.QueryUtils.createContains(other));
                        }
                    };
                    partnerNeighbor_AvailableQueryOrNeighborQuery_Query = new repast.simphony.query.AndQuery<Object>(
                            partnerNeighbor_AvailableQueryOrNeighborQuery_Query,
                            partnerNeighbor_AvailableQueryOrNeighborQuery_QueryAvailable);
                    java.util.Iterator partnerNeighbor_AvailableQueryOrNeighborQuery_Iter = partnerNeighbor_AvailableQueryOrNeighborQuery_Query
                    .query().iterator();
                    if (partnerNeighbor_AvailableQueryOrNeighborQuery_Iter.hasNext()) {
                        java.util.List partnerNeighbor_AvailableQueryOrNeighborQuery_List = org.apache.commons.collections15.IteratorUtils
                        .toList(partnerNeighbor_AvailableQueryOrNeighborQuery_Iter);
                        final Block partnerNeighbor = (Block) partnerNeighbor_AvailableQueryOrNeighborQuery_List
                        .get(repast.simphony.random.RandomHelper.nextIntFromTo(0,
                                                                               partnerNeighbor_AvailableQueryOrNeighborQuery_List
                                                                               .size() - 1));
                        int[] moveIndividualLoc = city.getLocation(partnerNeighbor).toIntArray(null);
                        city.moveTo(this, moveIndividualLoc);
                    }
                }
            }
        }
    }

Back to the top