I'm trying to build a custom experiment...but it gives the following error
I don't get what is going wrong!
It is because in the Main I defined the following?
At the very beginning I want one agent to receive a message, why the custom experiment gives me trouble while the normal simulation experiment doesn't?
The code for the custom experiment I took it from the example models
try {
// Create Engine, initialize random number generator:
Engine engine = createEngine();
// Set stop time:
engine.setStopTime( 3287 );
// Create optimization variable
final COptQuestContinuousVariable v = new COptQuestContinuousVariable();
v.SetLowerBound(0.0);
v.SetUpperBound(0.03);
// Create objective
final COptQuestObjective obj = new COptQuestUserControlledObjective();
obj.SetMinimize();
// Create optimization engine
final COptQuestOptimization opt = ExperimentOptimization.createOptimization(engine, new OptimizationCallback() {
@Override
public void evaluate(COptQuestOptimization optimization,
COptQuestSolution solution, Engine engine) {
try {
// Create new root object:
Main root = new Main( engine, null, null );
// Setup parameters of root object here
root.susc_s = solution.GetVariableValue(v);
// Prepare Engine for simulation:
engine.start( root );
// Start simulation in fast mode:
engine.runFast();
// Process results of simulation here
solution.SetObjectiveValue( obj, root.objective );
// Destroy the model:
engine.stop();
} catch (COptQuestException e) {
traceln(e.Description());
}
}
// Trace each iteration (optional!)
@Override
public void monitorStatus(COptQuestOptimization optimization,
COptQuestSolution solution, Engine engine) {
try {
traceln(String.format(" %3d : %6.2f : %8.2f -- %8.2f",
solution.GetIteration(), solution.GetVariableValue(v),
solution.GetObjectiveValue(),
optimization.GetBestSolution() != null ?
optimization.GetBestSolution().GetObjectiveValue(obj) : Double.NaN));
} catch (COptQuestException e) {
traceln(e.Description());
}
}
});
// Setup optimization engine
opt.AddVariable(v);
opt.AddObjective(obj);
// Set the number of iterations to run
opt.SetMaximumIterations(30);
// Add suggested solution (initial solution)
COptQuestSolution suggestedSolution = opt.CreateSolution();
suggestedSolution.SetVariableValue(v, 0.014);
opt.AddSuggestedSolution(suggestedSolution);
traceln(" Iter : Param : Objective -- Best obj.");
traceln("-------------------------------------------");
// Perform optimization
opt.Optimize();
traceln("-------------------------------------------");
// Output results
COptQuestSolution bestSolution = opt.GetBestSolution();
traceln("Best objective: " + format(bestSolution.GetObjectiveValue(obj)));
traceln(" is feasible: " + format(bestSolution.IsFeasible()));
traceln("Best parameter: " + format(bestSolution.GetVariableValue(v)));
traceln("Best iteration: " + bestSolution.GetIteration()); } catch (COptQuestException e) {
traceln(e.Description()); }