Skip to content

Commit

Permalink
Fixes genstar compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
lesquoyb committed Feb 22, 2024
1 parent 0dad3f6 commit 6779ee1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import espacedev.gaml.extensions.genstar.utils.GenStarGamaUtils;
import msi.gama.common.interfaces.IKeyword;
import msi.gama.kernel.experiment.ExperimentAgent;
import msi.gama.kernel.experiment.ExperimentPlan;
import msi.gama.kernel.experiment.ExperimentPlan.ExperimentPopulation;
import msi.gama.kernel.simulation.SimulationPopulation;
import msi.gama.metamodel.agent.IAgent;
import msi.gama.metamodel.agent.IMacroAgent;
import msi.gama.metamodel.population.IPopulation;
import msi.gama.precompiler.GamlAnnotations.doc;
import msi.gama.precompiler.GamlAnnotations.example;
Expand Down Expand Up @@ -58,8 +61,6 @@
import msi.gaml.species.ISpecies;
import msi.gaml.statements.AbstractStatementSequence;
import msi.gaml.statements.Arguments;
import msi.gaml.statements.Facets;
import msi.gaml.statements.Facets.Facet;
import msi.gaml.statements.IStatement;
import msi.gaml.statements.RemoteSequence;
import msi.gaml.types.IType;
Expand Down Expand Up @@ -243,26 +244,36 @@ public void fillWithUserInit(final IScope scope, final Map values) {
// ------------------------------------------------------------------------------------------------ //
// ------------------------------------------------------------------------------------------------ //


/**
* Find population.
*
* @param scope
* the scope
* @return the i population
*/
@SuppressWarnings ("rawtypes")
private IPopulation findPopulation(final IScope scope) {
IPopulation findPopulation(final IScope scope) {
final IAgent executor = scope.getAgent();
if (species == null) return executor.getPopulationFor(description.getSpeciesContext().getName());
ISpecies s = Cast.asSpecies(scope, species.value(scope));
if (s == null) {// A last attempt in order to fix #2466
final String potentialSpeciesName = species.getDenotedType().getSpeciesName();
if (potentialSpeciesName != null) { s = scope.getModel().getSpecies(potentialSpeciesName); }
}
if (s == null) throw GamaRuntimeException.error(
"No population of " + species.serialize(false) + " is accessible in the context of " + executor + ".",
scope);
return executor.getPopulationFor(s);
if (s == null) throw GamaRuntimeException.error("No population of " + species.serializeToGaml(false)
+ " is accessible in the context of " + executor + ".", scope);
IPopulation pop = executor.getPopulationFor(s);
// hqnghi population of micro-model's experiment is not exist, we
// must create the new one
if (pop == null && s instanceof ExperimentPlan ep && executor instanceof IMacroAgent) {
pop = ep.new ExperimentPopulation(s);
final IScope sc = ep.getExperimentScope();
pop.initializeFor(sc);
((IMacroAgent) executor).addExternMicroPopulation(
s.getDescription().getModelDescription().getAlias() + "." + s.getName(), pop);
}
// end-hqnghi
return pop;
}

/**
Expand Down Expand Up @@ -369,15 +380,14 @@ public void validate(final StatementDescription description) {
}
}

final Facets facets = description.getPassedArgs();
for (final Facet att : facets.getFacets()) {
if (!sd.isExperiment() && !sd.hasAttribute(att.key)) {
description.error("Attribute " + att + " is not defined in species " + species.getName(),
UNKNOWN_VAR);
return;
final Arguments facets = description.getPassedArgs();
facets.forEachFacet((s, e) -> {
boolean error = !sd.isExperiment() && !sd.hasAttribute(s);
if (error) {
description.error("Attribute " + s + " is not defined in species " + species.getName(), UNKNOWN_VAR);
}
}

return !error;
});
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package espacedev.gaml.extensions.genstar.type;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -36,18 +35,13 @@
import msi.gama.precompiler.GamlAnnotations.variable;
import msi.gama.precompiler.GamlAnnotations.vars;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaListFactory;
import msi.gama.util.IContainer;
import msi.gama.util.IList;
import msi.gaml.operators.Strings;
import msi.gama.util.file.json.Json;
import msi.gama.util.file.json.JsonValue;
import msi.gaml.types.IType;
import msi.gaml.types.Types;
import spll.localizer.constraint.ISpatialConstraint;
import spll.localizer.constraint.SpatialConstraintMaxDensity;
import spll.localizer.constraint.SpatialConstraintMaxNumber;
import spll.localizer.distribution.ISpatialDistribution;
import spll.localizer.distribution.SpatialDistributionFactory;

/**
* The Class GamaPopGenerator.
Expand Down Expand Up @@ -242,10 +236,6 @@ public GamaPopGenerator() {

// IValue constract

@Override
public String serialize(final boolean includingBuiltIn) {
return null;
}

@Override
public String stringValue(final IScope scope) {
Expand Down Expand Up @@ -778,4 +768,10 @@ public IAgent getAgent(final ADemoEntity e) {
*/
public Collection<IAgent> getAgents() { return mapEntitiesAgent.values(); }

@Override
public JsonValue serializeToJson(Json json) {
// TODO Auto-generated method stub
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import msi.gama.precompiler.GamlAnnotations.variable;
import msi.gama.precompiler.GamlAnnotations.vars;
import msi.gama.runtime.IScope;
import msi.gama.util.file.json.Json;
import msi.gama.util.file.json.JsonValue;
import msi.gaml.types.IType;

/**
Expand Down Expand Up @@ -69,7 +71,6 @@ public GamaRange(final Number min, final Number max) {
@getter ("max_value")
public Number getMax() { return max.doubleValue(); }

@Override
public String serialize(final boolean includingBuiltIn) {
return min + "->" + max;
}
Expand Down Expand Up @@ -127,4 +128,9 @@ private double floatValue() {
private int intValue() {
return (int) floatValue();
}

@Override
public JsonValue serializeToJson(Json json) {
return json.valueOf(min + "->" + max);
}
}

0 comments on commit 6779ee1

Please sign in to comment.