Skip to content

Commit

Permalink
Merge pull request #216 from gama-platform/fixes-209
Browse files Browse the repository at this point in the history
Fixes #209
  • Loading branch information
lesquoyb authored Jun 14, 2024
2 parents 6352522 + ee05285 commit 80997c9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions gama.core/src/gama/core/common/interfaces/IKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public interface IKeyword {
/** The current state. */
String CURRENT_STATE = "currentState";

/** The Constant CYCLE. */
String CYCLE = "cycle";

/** The cycle length. */
String CYCLE_LENGTH = "cycle_length";

Expand Down
20 changes: 19 additions & 1 deletion gama.core/src/gama/core/kernel/experiment/ExperimentAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
name = IKeyword.RNG,
type = IType.STRING,
doc = @doc (RandomUtils.DOC)),
@variable (
name = IKeyword.CYCLE,
type = IType.INT,
doc = @doc ("Returns the current cycle of the simulation")),
@variable (
name = SimulationAgent.USAGE,
type = IType.INT,
Expand Down Expand Up @@ -738,6 +742,20 @@ public GamaMap<String, Object> getParameters(final IScope scope) {
@getter (PROJECT_PATH)
public String getProjectPath() { return getModel().getProjectPath() + "/"; }


/**
* Gets the cycle.
*
* @param scope
* the scope
* @return the cycle
*/
@getter (IKeyword.CYCLE)
public Integer getCycle(final IScope scope) {
if (ownClock != null) return ownClock.getCycle();
return 0;
}

/**
* Update displays.
*
Expand Down Expand Up @@ -1197,7 +1215,7 @@ public Iterable<IOutputManager> getAllSimulationOutputs() {
if (pop != null)
return Iterables.filter(Iterables.concat(Iterables.transform(pop, SimulationAgent::getOutputManager),
Collections.singletonList(getOutputManager())), each -> each != null);
return Collections.EMPTY_LIST;
return Collections.emptyList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
value = "Represents the total time passed, in model time, since the beginning of the simulation",
comment = "Equal to cycle * step if the user does not arbitrarily initialize it.")),
@variable (
name = SimulationAgent.CYCLE,
name = IKeyword.CYCLE,
type = IType.INT,
doc = @doc ("Returns the current cycle of the simulation")),
@variable (
Expand Down Expand Up @@ -173,9 +173,6 @@ public class SimulationAgent extends GamlAgent implements ITopLevelAgent {
/** The Constant AVERAGE_DURATION. */
public static final String AVERAGE_DURATION = "average_duration";

/** The Constant CYCLE. */
public static final String CYCLE = "cycle";

/** The Constant TIME. */
public static final String TIME = "time";

Expand Down Expand Up @@ -534,7 +531,7 @@ public IPopulation<? extends IAgent> getPopulationFor(final String speciesName)
* the scope
* @return the cycle
*/
@getter (CYCLE)
@getter (IKeyword.CYCLE)
public Integer getCycle(final IScope scope) {
final SimulationClock clock = getClock();
if (clock != null) return clock.getCycle();
Expand Down Expand Up @@ -1010,7 +1007,7 @@ public void updateWith(final IScope scope, final ISerialisedAgent sa) {
setUsage(usageValue);

// Update Clock
final Object cycle = sa.getAttributeValue(CYCLE);
final Object cycle = sa.getAttributeValue(IKeyword.CYCLE);
ownClock.setCycleNoCheck((Integer) cycle);

final Map<String, ISerialisedPopulation> savedAgentInnerPop = sa.innerPopulations();
Expand Down
4 changes: 2 additions & 2 deletions gama.core/src/gama/core/metamodel/agent/SerialisedAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static Map<String, Object> filterAttributes(final IAgent agent, final boo
map.put(IKeyword.SEED, sim.getSeed());
map.put(IKeyword.RNG, sim.getRng());
map.put(SimulationAgent.USAGE, sim.getUsage());
map.put(SimulationAgent.CYCLE, sim.getClock().getCycle());
map.put(IKeyword.CYCLE, sim.getClock().getCycle());
}
if (!isGrid) { map.put(IKeyword.SHAPE, agent.getGeometry()); }
map.put(IKeyword.NAME, agent.getName());
Expand Down Expand Up @@ -232,7 +232,7 @@ public void restoreAs(final IScope scope, final IAgent agent) {
sim.setRandomGenerator(new RandomUtils(seedValue, rngValue));
sim.setUsage(usageValue);
// Update Clock
final Integer cycle = (Integer) sim.getAttribute(SimulationAgent.CYCLE);
final Integer cycle = (Integer) sim.getAttribute(IKeyword.CYCLE);
sim.getClock().setCycleNoCheck(cycle);

}
Expand Down

0 comments on commit 80997c9

Please sign in to comment.