Find an agent in a certain zone

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

Find an agent in a certain zone

cnietocoria
Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

srcnick
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

cnietocoria
Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

srcnick
OK. I think I misunderstood you. Where do you get the error. Is it when you iterate through the agents and call createNeighbourhood on each one? Can you post the code where you do that?

Nick

On Apr 14, 2016, at 10:00 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

cnietocoria
Hello Nick,

This is the complete code of the method.

@ScheduledMethod(start = 1, interval = 0, priority = 1)
    public void createNeighbourhood(){

        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
       
        //hexagon is the geometry
        Geometry hexagon = /*geography.getLayer(Hexagon.class);//*/geography.getGeometry(this);
       

        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
        //Assign the direction to the neighbors
        for(Hexagon neigh : neighbors){
            double calcLatitude = round(calculateDeltaCoor(this.centroidLatitude, neigh.centroidLatitude), precision);
            double calcLongitude = round(calculateDeltaCoor(this.centroidLongitude, neigh.centroidLongitude), precision);

            if(calcLatitude == nordLatitude && calcLongitude == nordLongitude){
                neighborDirections.put(neigh.ID, "Nord");
                neighboursDirections.put("N",neigh.ID);
            } else if(calcLatitude == nordEstLatitude && calcLongitude == nordEstLongitude){
                neighborDirections.put(neigh.ID, "NordEast");
                neighboursDirections.put("NE",neigh.ID);
            } else if(calcLatitude == nordWestLatitude && calcLongitude == nordWestLongitude){
                neighborDirections.put(neigh.ID, "NordWest");
                neighboursDirections.put("NW",neigh.ID);
            } else if(calcLatitude == southLatitude && calcLongitude == southLongitude){
                neighborDirections.put(neigh.ID, "South");
                neighboursDirections.put("S",neigh.ID);
            } else if(calcLatitude == southEstLatitude && calcLongitude == southEstLongitude){
                neighborDirections.put(neigh.ID, "SouthEast");
                neighboursDirections.put("SE",neigh.ID);
            } else if(calcLatitude == southWestLatitude && calcLongitude == southWestLongitude){
                neighborDirections.put(neigh.ID, "SouthWest");
                neighboursDirections.put("SW",neigh.ID);
            }else {
                System.out.println("ERROR: You should check your shapefile, it is having some features problems");

            }
        }


And this is the console output

FATAL [Thread-18] 12:36:17,746 repast.simphony.ui.GUIScheduleRunner - RunTimeException when running the schedule
Current tick (1.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
    at repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
    at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
    at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:206)
    at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
    at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
    at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at environment.Hexagon$$FastClassByCGLIB$$26fc4d25.invoke(<generated>)
    at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
    ... 7 more
Caused by: java.lang.ClassCastException: environment.Region cannot be cast to environment.Hexagon
    at environment.Hexagon.BoundaryCondition(Hexagon.java:207)
    ... 10 more

The 207 line is highlighted, because I think that there is where the compilator tries to perform the actions like an hexagon but the geometry is a region, and replies that it can be casted as a hexagon.




On Thu, Apr 14, 2016 at 6:18 PM, Nick Collier <[hidden email]> wrote:
OK. I think I misunderstood you. Where do you get the error. Is it when you iterate through the agents and call createNeighbourhood on each one? Can you post the code where you do that?

Nick

On Apr 14, 2016, at 10:00 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

srcnick
If you replace 

 for (Hexagon obj: within.query()){

with:

for (Hexagon obj : new FilteredIterator<T>(within.query().iterator(), new InstanceOfPredicate(Hexagon.class)) {

That should filter out all the objects returned from the query that are not Hexagons.

Nick

On Apr 15, 2016, at 6:43 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

This is the complete code of the method.

@ScheduledMethod(start = 1, interval = 0, priority = 1)
    public void createNeighbourhood(){

        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
       
        //hexagon is the geometry
        Geometry hexagon = /*geography.getLayer(Hexagon.class);//*/geography.getGeometry(this);
       

        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
        //Assign the direction to the neighbors
        for(Hexagon neigh : neighbors){
            double calcLatitude = round(calculateDeltaCoor(this.centroidLatitude, neigh.centroidLatitude), precision);
            double calcLongitude = round(calculateDeltaCoor(this.centroidLongitude, neigh.centroidLongitude), precision);

            if(calcLatitude == nordLatitude && calcLongitude == nordLongitude){
                neighborDirections.put(neigh.ID, "Nord");
                neighboursDirections.put("N",neigh.ID);
            } else if(calcLatitude == nordEstLatitude && calcLongitude == nordEstLongitude){
                neighborDirections.put(neigh.ID, "NordEast");
                neighboursDirections.put("NE",neigh.ID);
            } else if(calcLatitude == nordWestLatitude && calcLongitude == nordWestLongitude){
                neighborDirections.put(neigh.ID, "NordWest");
                neighboursDirections.put("NW",neigh.ID);
            } else if(calcLatitude == southLatitude && calcLongitude == southLongitude){
                neighborDirections.put(neigh.ID, "South");
                neighboursDirections.put("S",neigh.ID);
            } else if(calcLatitude == southEstLatitude && calcLongitude == southEstLongitude){
                neighborDirections.put(neigh.ID, "SouthEast");
                neighboursDirections.put("SE",neigh.ID);
            } else if(calcLatitude == southWestLatitude && calcLongitude == southWestLongitude){
                neighborDirections.put(neigh.ID, "SouthWest");
                neighboursDirections.put("SW",neigh.ID);
            }else {
                System.out.println("ERROR: You should check your shapefile, it is having some features problems");

            }
        }


And this is the console output

FATAL [Thread-18] 12:36:17,746 repast.simphony.ui.GUIScheduleRunner - RunTimeException when running the schedule
Current tick (1.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
    at repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
    at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
    at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:206)
    at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
    at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
    at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at environment.Hexagon$$FastClassByCGLIB$$26fc4d25.invoke(<generated>)
    at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
    ... 7 more
Caused by: java.lang.ClassCastException: environment.Region cannot be cast to environment.Hexagon
    at environment.Hexagon.BoundaryCondition(Hexagon.java:207)
    ... 10 more

The 207 line is highlighted, because I think that there is where the compilator tries to perform the actions like an hexagon but the geometry is a region, and replies that it can be casted as a hexagon.




On Thu, Apr 14, 2016 at 6:18 PM, Nick Collier <[hidden email]> wrote:
OK. I think I misunderstood you. Where do you get the error. Is it when you iterate through the agents and call createNeighbourhood on each one? Can you post the code where you do that?

Nick

On Apr 14, 2016, at 10:00 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

cnietocoria
Hi Nick, 

Thanks for your answer, I spent the weekend trying to fix it. Although I wasn't successful. 

I made different things, as you can observe in the attached picture, I changed the order of the FilteredIterator parameters because I saw in the repast doc that was in that way. Furthermore I tried also using the collections, in all the changes always was showing me the same message. What I made it wrong? 


Anyway, I'm using an old repast version (2.1). Do you think that it can be the problem? 

Regards, 

Cesar



On Fri, Apr 15, 2016 at 3:24 PM, Nick Collier <[hidden email]> wrote:
If you replace 

 for (Hexagon obj: within.query()){

with:

for (Hexagon obj : new FilteredIterator<T>(within.query().iterator(), new InstanceOfPredicate(Hexagon.class)) {

That should filter out all the objects returned from the query that are not Hexagons.

Nick

On Apr 15, 2016, at 6:43 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

This is the complete code of the method.

@ScheduledMethod(start = 1, interval = 0, priority = 1)
    public void createNeighbourhood(){

        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
       
        //hexagon is the geometry
        Geometry hexagon = /*geography.getLayer(Hexagon.class);//*/geography.getGeometry(this);
       

        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
        //Assign the direction to the neighbors
        for(Hexagon neigh : neighbors){
            double calcLatitude = round(calculateDeltaCoor(this.centroidLatitude, neigh.centroidLatitude), precision);
            double calcLongitude = round(calculateDeltaCoor(this.centroidLongitude, neigh.centroidLongitude), precision);

            if(calcLatitude == nordLatitude && calcLongitude == nordLongitude){
                neighborDirections.put(neigh.ID, "Nord");
                neighboursDirections.put("N",neigh.ID);
            } else if(calcLatitude == nordEstLatitude && calcLongitude == nordEstLongitude){
                neighborDirections.put(neigh.ID, "NordEast");
                neighboursDirections.put("NE",neigh.ID);
            } else if(calcLatitude == nordWestLatitude && calcLongitude == nordWestLongitude){
                neighborDirections.put(neigh.ID, "NordWest");
                neighboursDirections.put("NW",neigh.ID);
            } else if(calcLatitude == southLatitude && calcLongitude == southLongitude){
                neighborDirections.put(neigh.ID, "South");
                neighboursDirections.put("S",neigh.ID);
            } else if(calcLatitude == southEstLatitude && calcLongitude == southEstLongitude){
                neighborDirections.put(neigh.ID, "SouthEast");
                neighboursDirections.put("SE",neigh.ID);
            } else if(calcLatitude == southWestLatitude && calcLongitude == southWestLongitude){
                neighborDirections.put(neigh.ID, "SouthWest");
                neighboursDirections.put("SW",neigh.ID);
            }else {
                System.out.println("ERROR: You should check your shapefile, it is having some features problems");

            }
        }


And this is the console output

FATAL [Thread-18] 12:36:17,746 repast.simphony.ui.GUIScheduleRunner - RunTimeException when running the schedule
Current tick (1.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
    at repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
    at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
    at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:206)
    at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
    at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
    at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at environment.Hexagon$$FastClassByCGLIB$$26fc4d25.invoke(<generated>)
    at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
    ... 7 more
Caused by: java.lang.ClassCastException: environment.Region cannot be cast to environment.Hexagon
    at environment.Hexagon.BoundaryCondition(Hexagon.java:207)
    ... 10 more

The 207 line is highlighted, because I think that there is where the compilator tries to perform the actions like an hexagon but the geometry is a region, and replies that it can be casted as a hexagon.




On Thu, Apr 14, 2016 at 6:18 PM, Nick Collier <[hidden email]> wrote:
OK. I think I misunderstood you. Where do you get the error. Is it when you iterate through the agents and call createNeighbourhood on each one? Can you post the code where you do that?

Nick

On Apr 14, 2016, at 10:00 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest

screenshotRepast.JPG (30K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Find an agent in a certain zone

srcnick
The FilterIterator I was thinking of is the apache commons FilterIterator that comes with Repast, not repast's one. Sorry for the confusion. 


I'm not sure that was included with 2.1 but I think it was. As a last resort, you could iterate through the within query as before, but have it return Object. Then check if that Object is a Hexagon with if (obj instanceof Hexagon).

hope this helps,

Nick

On Mon, Apr 18, 2016 at 7:05 AM, Cesar Nieto Coria <[hidden email]> wrote:
Hi Nick, 

Thanks for your answer, I spent the weekend trying to fix it. Although I wasn't successful. 

I made different things, as you can observe in the attached picture, I changed the order of the FilteredIterator parameters because I saw in the repast doc that was in that way. Furthermore I tried also using the collections, in all the changes always was showing me the same message. What I made it wrong? 


Anyway, I'm using an old repast version (2.1). Do you think that it can be the problem? 

Regards, 

Cesar



On Fri, Apr 15, 2016 at 3:24 PM, Nick Collier <[hidden email]> wrote:
If you replace 

 for (Hexagon obj: within.query()){

with:

for (Hexagon obj : new FilteredIterator<T>(within.query().iterator(), new InstanceOfPredicate(Hexagon.class)) {

That should filter out all the objects returned from the query that are not Hexagons.

Nick

On Apr 15, 2016, at 6:43 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

This is the complete code of the method.

@ScheduledMethod(start = 1, interval = 0, priority = 1)
    public void createNeighbourhood(){

        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
       
        //hexagon is the geometry
        Geometry hexagon = /*geography.getLayer(Hexagon.class);//*/geography.getGeometry(this);
       

        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
        //Assign the direction to the neighbors
        for(Hexagon neigh : neighbors){
            double calcLatitude = round(calculateDeltaCoor(this.centroidLatitude, neigh.centroidLatitude), precision);
            double calcLongitude = round(calculateDeltaCoor(this.centroidLongitude, neigh.centroidLongitude), precision);

            if(calcLatitude == nordLatitude && calcLongitude == nordLongitude){
                neighborDirections.put(neigh.ID, "Nord");
                neighboursDirections.put("N",neigh.ID);
            } else if(calcLatitude == nordEstLatitude && calcLongitude == nordEstLongitude){
                neighborDirections.put(neigh.ID, "NordEast");
                neighboursDirections.put("NE",neigh.ID);
            } else if(calcLatitude == nordWestLatitude && calcLongitude == nordWestLongitude){
                neighborDirections.put(neigh.ID, "NordWest");
                neighboursDirections.put("NW",neigh.ID);
            } else if(calcLatitude == southLatitude && calcLongitude == southLongitude){
                neighborDirections.put(neigh.ID, "South");
                neighboursDirections.put("S",neigh.ID);
            } else if(calcLatitude == southEstLatitude && calcLongitude == southEstLongitude){
                neighborDirections.put(neigh.ID, "SouthEast");
                neighboursDirections.put("SE",neigh.ID);
            } else if(calcLatitude == southWestLatitude && calcLongitude == southWestLongitude){
                neighborDirections.put(neigh.ID, "SouthWest");
                neighboursDirections.put("SW",neigh.ID);
            }else {
                System.out.println("ERROR: You should check your shapefile, it is having some features problems");

            }
        }


And this is the console output

FATAL [Thread-18] 12:36:17,746 repast.simphony.ui.GUIScheduleRunner - RunTimeException when running the schedule
Current tick (1.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
    at repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
    at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
    at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:206)
    at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
    at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
    at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at environment.Hexagon$$FastClassByCGLIB$$26fc4d25.invoke(<generated>)
    at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
    ... 7 more
Caused by: java.lang.ClassCastException: environment.Region cannot be cast to environment.Hexagon
    at environment.Hexagon.BoundaryCondition(Hexagon.java:207)
    ... 10 more

The 207 line is highlighted, because I think that there is where the compilator tries to perform the actions like an hexagon but the geometry is a region, and replies that it can be casted as a hexagon.




On Thu, Apr 14, 2016 at 6:18 PM, Nick Collier <[hidden email]> wrote:
OK. I think I misunderstood you. Where do you get the error. Is it when you iterate through the agents and call createNeighbourhood on each one? Can you post the code where you do that?

Nick

On Apr 14, 2016, at 10:00 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
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: Find an agent in a certain zone

cnietocoria
Let me check it, then I'll write you again. 

Cesar

On Mon, Apr 18, 2016 at 3:14 PM, Nick Collier <[hidden email]> wrote:
The FilterIterator I was thinking of is the apache commons FilterIterator that comes with Repast, not repast's one. Sorry for the confusion. 


I'm not sure that was included with 2.1 but I think it was. As a last resort, you could iterate through the within query as before, but have it return Object. Then check if that Object is a Hexagon with if (obj instanceof Hexagon).

hope this helps,

Nick

On Mon, Apr 18, 2016 at 7:05 AM, Cesar Nieto Coria <[hidden email]> wrote:
Hi Nick, 

Thanks for your answer, I spent the weekend trying to fix it. Although I wasn't successful. 

I made different things, as you can observe in the attached picture, I changed the order of the FilteredIterator parameters because I saw in the repast doc that was in that way. Furthermore I tried also using the collections, in all the changes always was showing me the same message. What I made it wrong? 


Anyway, I'm using an old repast version (2.1). Do you think that it can be the problem? 

Regards, 

Cesar



On Fri, Apr 15, 2016 at 3:24 PM, Nick Collier <[hidden email]> wrote:
If you replace 

 for (Hexagon obj: within.query()){

with:

for (Hexagon obj : new FilteredIterator<T>(within.query().iterator(), new InstanceOfPredicate(Hexagon.class)) {

That should filter out all the objects returned from the query that are not Hexagons.

Nick

On Apr 15, 2016, at 6:43 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

This is the complete code of the method.

@ScheduledMethod(start = 1, interval = 0, priority = 1)
    public void createNeighbourhood(){

        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
       
        //hexagon is the geometry
        Geometry hexagon = /*geography.getLayer(Hexagon.class);//*/geography.getGeometry(this);
       

        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
        //Assign the direction to the neighbors
        for(Hexagon neigh : neighbors){
            double calcLatitude = round(calculateDeltaCoor(this.centroidLatitude, neigh.centroidLatitude), precision);
            double calcLongitude = round(calculateDeltaCoor(this.centroidLongitude, neigh.centroidLongitude), precision);

            if(calcLatitude == nordLatitude && calcLongitude == nordLongitude){
                neighborDirections.put(neigh.ID, "Nord");
                neighboursDirections.put("N",neigh.ID);
            } else if(calcLatitude == nordEstLatitude && calcLongitude == nordEstLongitude){
                neighborDirections.put(neigh.ID, "NordEast");
                neighboursDirections.put("NE",neigh.ID);
            } else if(calcLatitude == nordWestLatitude && calcLongitude == nordWestLongitude){
                neighborDirections.put(neigh.ID, "NordWest");
                neighboursDirections.put("NW",neigh.ID);
            } else if(calcLatitude == southLatitude && calcLongitude == southLongitude){
                neighborDirections.put(neigh.ID, "South");
                neighboursDirections.put("S",neigh.ID);
            } else if(calcLatitude == southEstLatitude && calcLongitude == southEstLongitude){
                neighborDirections.put(neigh.ID, "SouthEast");
                neighboursDirections.put("SE",neigh.ID);
            } else if(calcLatitude == southWestLatitude && calcLongitude == southWestLongitude){
                neighborDirections.put(neigh.ID, "SouthWest");
                neighboursDirections.put("SW",neigh.ID);
            }else {
                System.out.println("ERROR: You should check your shapefile, it is having some features problems");

            }
        }


And this is the console output

FATAL [Thread-18] 12:36:17,746 repast.simphony.ui.GUIScheduleRunner - RunTimeException when running the schedule
Current tick (1.0)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:72)
    at repast.simphony.engine.controller.ScheduledMethodControllerAction$ScheduleMethodAllAction.execute(ScheduledMethodControllerAction.java:333)
    at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
    at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:206)
    at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:231)
    at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
    at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at environment.Hexagon$$FastClassByCGLIB$$26fc4d25.invoke(<generated>)
    at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
    at repast.simphony.engine.schedule.DynamicTargetAction.execute(DynamicTargetAction.java:69)
    ... 7 more
Caused by: java.lang.ClassCastException: environment.Region cannot be cast to environment.Hexagon
    at environment.Hexagon.BoundaryCondition(Hexagon.java:207)
    ... 10 more

The 207 line is highlighted, because I think that there is where the compilator tries to perform the actions like an hexagon but the geometry is a region, and replies that it can be casted as a hexagon.




On Thu, Apr 14, 2016 at 6:18 PM, Nick Collier <[hidden email]> wrote:
OK. I think I misunderstood you. Where do you get the error. Is it when you iterate through the agents and call createNeighbourhood on each one? Can you post the code where you do that?

Nick

On Apr 14, 2016, at 10:00 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello Nick,

Sure, following I pasted the code how to get the neighbours. Note: before to add the regions it worked well.

public void createNeighbourhood(){
        Context context = ContextUtils.getContext(this);
        Geography<Hexagon> geography = (Geography)context.getProjection("Geography");
        //hexagon is the geometry
        Geometry hexagon = geography.getGeometry(this);
        GeographyWithin<Hexagon> within = new GeographyWithin<Hexagon>(geography, distance , this);
        if( within.query() != null ){

            for (Hexagon obj: within.query()){

                neighbors.add(obj);

                idList.add(obj.ID);
                double[] centroidsNeigh = new double[2];
                centroidsNeigh[0] = obj.centroidLatitude;
                centroidsNeigh[1] = obj.centroidLongitude;
                //map with ID--CentroidsCoordinates[]
                centroids.put(obj.ID, centroidsNeigh);

            }

        }else{
            System.out.println("ERROR: Hexagon "+this.ID+" has not neighbors! ");
        }
}

The method createNeighbourhood belongs to the Hexagon class.

Regards,

Cesar

On Thu, Apr 14, 2016 at 3:25 PM, Nick Collier <[hidden email]> wrote:
Can you say more how you are creating the neighborhood? It seems likes Geography.getLayer(Hexagon.class) might help in only getting the hexagons from the geography but its hard to say without knowing more.

Nick

On Apr 13, 2016, at 2:14 PM, Cesar Nieto Coria <[hidden email]> wrote:

Hello everyone,

Before to perform my question, I would like to introduce you with my problem. I am developing a model that uses a GIS display. I used a shapefile that contains a hexagonal grid. Each hexagon is an agent on my model. Hence, each agent hast it own parameters, as coordinates, bathymentry, etc. Also, the agents can communicate to each others, sharing some variables to their neighbours.

Then I would like to load different shapefiles, is like overlaying the shapefiles, why? You might ask. Is because I want, depending on the location of the agent I will to perform some actions. Furthermore, each agent depending on the location will change the color. Those shapefiles that will creates zones, are composed by multypoligons, however, I don't want to display them.

I can comment what I did so far, each hexagon is an agent and it has its own variables and methods. Then I created the region agents, loading each zone as an agent in the same geography that are the hexagons.

The problem comes when repast tries to creates the neighbourhood. Because I created a method in the Hexagon class itself, that calls the context and get all the agents on the Geography. As I mentioned above I did added my Region agents, to doing so I added them in the same Geography where the Hexagon agents were. Hence when the framework tries to creates the neighbourhood and it is a Region, it returns reflection error (java.lang.reflect.InvocationTargetException). 

Clearly I need to learn more about how the geography works. I was wondering if I create 2 geographies, one for the hexagons and the other for the regions. Then perform a spatial query to look if a hexagon is located inside of a a region. It is possible? Or Is the spatial query will return null because the hexagon is in a different geography?

I apologize for this very long email. I tried to be as clear as possible.

I am open to any thoughts or suggestion that you might have.  

Best Regards,

Cesar



--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria





--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...