【问题标题】:AnyLogic - how to create a custom experimentAnyLogic - 如何创建自定义实验
【发布时间】:2017-07-06 19:15:05
【问题描述】:

我已经使用 AnyLogic 构建了我的第一个基于代理的模型,现在我需要对其进行校准。我尝试了可用的实验,但时间太长,我无法模拟超过 10.000 个代理。所以我想尝试自定义实验......但我不知道如何构建它!

我建立了一个非常简单的模型 其中参数是bernoulli(main.calib),然后我想最大化进入最终状态的代理数量。

我从帮助中提供的实验中复制了代码并做了一些小的调整

try {
// Create Engine, initialize random number generator:
Engine engine = createEngine();
// Set stop time:
engine.setStopTime( 2 );

// Create optimization variable 
final COptQuestContinuousVariable v = new COptQuestContinuousVariable();
v.SetLowerBound(0.0);
v.SetUpperBound(1.0);

// Create objective
final COptQuestObjective obj = new COptQuestUserControlledObjective();
obj.SetMaximize();

// 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.calib = 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.end );
            // 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.5);
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()); }

结果如下……

我不明白为什么目标总是为零...

感谢您的帮助!

【问题讨论】:

  • 我对自定义实验的使用并不多。主要是参数变化。但是你在哪里告诉实验最后阶段的代理数量?

标签: anylogic


【解决方案1】:

AnyLogic 的个人学习版对可以做某些事情的代理数量有一些限制,并且它也不允许自定义实验。也许 AnyLogic 正在默默地失败。只是在黑暗中拍摄,因为我不是普通的 AnyLogic 用户。

【讨论】:

    猜你喜欢
    • 2017-07-21
    • 2011-06-03
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    相关资源
    最近更新 更多