Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #209 #216

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Primitive Obsession
The ratio of primitive types in function arguments decreases from 41.30% to 40.43%, threshold = 30.0%

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
Loading