Skip to content

Commit

Permalink
first try for comodeling when using different gis in micromodel
Browse files Browse the repository at this point in the history
  • Loading branch information
hqnghi88 committed Oct 19, 2020
1 parent 6a21084 commit 6c97bc5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
Expand Up @@ -277,11 +277,6 @@ public ExperimentAgent getAgent(final IScope scope, final ILocation value) {
return agent;
}

@Override
public IMacroAgent getHost() {
return null;
}

@Override
public void computeTopology(final IScope scope) throws GamaRuntimeException {
topology = new AmorphousTopology();
Expand Down
Expand Up @@ -367,7 +367,7 @@ public void dispose() {

}

private boolean isMicroSimulation() {
public boolean isMicroSimulation() {
return getSpecies().getDescription().belongsToAMicroModel();
}

Expand Down
Expand Up @@ -596,6 +596,11 @@ protected static ITopology buildGridTopology(final IScope scope, final ISpecies
public IMacroAgent getHost() {
return host;
}

@Override
public void setHost(IMacroAgent agt) {
host=agt;
}
//
// @Override
// public Iterator<T> iterator() {
Expand Down
Expand Up @@ -143,6 +143,13 @@ T createAgentAt(final IScope s, int index, Map<String, Object> initialValues, bo
* @return
*/
IMacroAgent getHost();

/**
* Set the macro-agent hosting this population.
*
* @return
*/
void setHost(IMacroAgent agt);

/**
* @throws GamaRuntimeException
Expand Down
17 changes: 13 additions & 4 deletions msi.gama.core/src/msi/gama/util/file/GamaGisFile.java
Expand Up @@ -23,6 +23,7 @@
import msi.gama.common.geometry.Envelope3D;
import msi.gama.common.geometry.GeometryUtils;
import msi.gama.common.geometry.ICoordinates;
import msi.gama.kernel.experiment.IExperimentAgent;
import msi.gama.metamodel.shape.GamaPoint;
import msi.gama.metamodel.shape.IShape;
import msi.gama.metamodel.topology.projection.IProjection;
Expand Down Expand Up @@ -90,10 +91,16 @@ protected CoordinateReferenceSystem getExistingCRS(final IScope scope) {
protected abstract CoordinateReferenceSystem getOwnCRS(IScope scope);

protected void computeProjection(final IScope scope, final Envelope3D env) {
if (scope == null) { return; }
if (scope == null) {
return;
}
final CoordinateReferenceSystem crs = getExistingCRS(scope);
final ProjectionFactory pf =
scope.getSimulation() == null ? new ProjectionFactory() : scope.getSimulation().getProjectionFactory();
final ProjectionFactory pf;
if (scope.getSimulation().isMicroSimulation()) {
pf=((IExperimentAgent)scope.getExperiment().getPopulation().getHost()).getSimulation().getProjectionFactory();
} else {
pf = scope.getSimulation() == null ? new ProjectionFactory() : scope.getSimulation().getProjectionFactory();
}
gis = pf.fromCRS(scope, crs, env);
}

Expand Down Expand Up @@ -123,7 +130,9 @@ protected Geometry multiPolygonManagement(final Geometry geom) {

protected static boolean hasNullElements(final Object[] array) {
for (final Object element : array) {
if (element == null) { return true; }
if (element == null) {
return true;
}
}
return false;
}
Expand Down
1 change: 1 addition & 0 deletions msi.gama.core/src/msi/gaml/statements/CreateStatement.java
Expand Up @@ -504,6 +504,7 @@ private IList<? extends IAgent> createAgents(final IScope scope, final IPopulati
// hqnghi in case of creating experiment of micro-models, we must
// implicitely initialize it and its simulation output
if (population instanceof ExperimentPopulation) {
population.setHost(scope.getExperiment());
for (final IAgent a : population) {
((ExperimentAgent) a)._init_(scope);
final SimulationAgent sim = ((ExperimentAgent) a).getSimulation();
Expand Down

0 comments on commit 6c97bc5

Please sign in to comment.