1

我是 java 新手,吃过饭。我正在尝试创建网格单元(网格单元)类型为网格单元(值层单元)的列表,但我不断收到错误“GridCell 类型不是通用的;它不能用参数参数化”

我该如何解决?

package tester;

import java.util.List;

import repast.simphony.context.Context;
import repast.simphony.engine.environment.RunEnvironment;
import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.parameter.Parameters;
//import repast.simphony.query.space.grid.GridCell;
import repast.simphony.query.space.grid.GridCellNgh;
import repast.simphony.space.grid.Grid;
import repast.simphony.space.grid.GridPoint;
import repast.simphony.valueLayer.AbstractGridFunction;
import repast.simphony.valueLayer.BufferedGridValueLayer;
import repast.simphony.valueLayer.BufferedGridValueLayer.Buffer;
import repast.simphony.valueLayer.GridCell;
import repast.simphony.valueLayer.MaxGridFunction;
import repast.simphony.valueLayer.MinGridFunction;

            private void Move() {
                // TODO Auto-generated method stub

                BufferedGridValueLayer heat = (BufferedGridValueLayer) context.getValueLayer("Heat Layer");
                Grid <Object> grid = (Grid <Object>) context.getProjection("Insulation Grid");

                //Get the Grid Location of this insulation unit.
                GridPoint pt = grid.getLocation(this);

                //Use the GridCellNgh to retrieve the list of of Gridcells (grid) contianing Gridcells (valueLayergrid). 
                GridCellNgh <GridCell> nghCreator = new GridCellNgh <GridCell> (grid, pt, GridCell.class, 1, 1);


                List <GridCell <GridCell>> gridCells = nghCreator.getNeighborhood(true);
            }  
4

1 回答 1

1

因为 Repast API 中有两个 GridCell 类,所以有些混乱。

GridCellNgh.getNeighborhood(true)返回类型repast.simphony.query.space.grid.GridCell<T>,它是位于特定网格位置的代理的容器。该类GridCellNgh用于根据代理类的类型检索这些类型的网格单元,并且不适用于 ValueLayerrepast.simphony.valueLayer.GridCell对象。

GridCellNgh可用于获取 GridPoints 的列表,您可以从中获取关联的GridCellvia GridCell.getPoint(),但是这假定所有周围的网格位置都填充有传递给GridCellNgh构造函数的代理类,这仅在网格完全充满代理时才实用。

我建议GridPoint pt = grid.getLocation(this)像您目前所做的那样简单地使用来获取中心点,然后只访问基于构成摩尔邻域的每个 x+/-1、y+/-1 的中心 x、y 的值层。

于 2016-12-02T20:52:42.367 回答