I am working on an agent-based simulation in AnyLogic where I need to adjust certain factors for each learner agent based on slider inputs. The top-level agent in my model is Main. I have a collection in my Simulation Agent called 'factorAdjustments'
. This collection stores adjustments made through 15 sliders, as seen in the attached screenshot.
The goal is to apply these adjustments to the Learner agents. However, I am encountering an issue where the Learner agent cannot access the factorAdjustments collection. The error message I receive is:
Description: factorAdjustments cannot be resolved to a variable.
Location: Learner_progression/Learner/enter - State
Here’s the code I’m using to apply the adjustments:
// Access the Main agent instance
Main main = (Main) get_Main();
// Ensure the learners population is not empty before accessing the first learner
if (!main.learners.isEmpty()) {
// Iterate over the factor adjustments
for (Map.Entry<String, Double> entry : factorAdjustments.entrySet()) {
String factorName = entry.getKey();
double percentageChange = entry.getValue();
// Retrieve the first Learner in the population
Learner sampleLearner = main.learners.get(0);
double minFactor = sampleLearner.min_fscore(factorName);
double maxFactor = sampleLearner.max_fscore(factorName);
// Iterate over all learners and apply changes
for (Learner learner : main.learners) {
learner.change_fscore(factorName, minFactor, maxFactor, percentageChange);
}
}
}
I have defined the factorAdjustments
collection in the Simulation agent, which should collect the slider adjustments. However, I am not sure how to properly access this collection from within the Learner agent.
The objective is to adjust the sliders, let these changes affect the variables of the Learner agents, and then run the simulation.
Could someone help me understand how to properly access the factorAdjustments
collection in the Simulation agent from the Learner agent?
Additional Context:
- The Simulation agent has the sliders and the
factorAdjustments
collection. - The Main agent holds the learners population.
- Attached is a screenshot of the simulation interface for reference.
Thank you for your help!
P.s. I tried all kinds of references to the Simulation Agent but I am obviously not understanding the construct of the three agents (Main, Simulation, Learner) and how they should communicate with each other.