gpt4 book ai didi

java - GridCell 类型不是通用的;它不能使用参数 进行参数化。创建列表时

转载 作者:行者123 更新时间:2023-11-30 07:10:32 26 4
gpt4 key购买 nike

我是java和吃饭的新手。我正在尝试创建 gridcells(值层单元格)类型的网格单元格(网格单元格)列表,但我不断收到错误“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);
}

最佳答案

由于 Repast API 中有两个 GridCell 类,因此存在一些困惑。

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

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

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

关于java - GridCell 类型不是通用的;它不能使用参数 <GridCell> 进行参数化。创建列表时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39306908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com