2

假设我有这个单元

unit agent {
    init_all_regs() @clock is {…};
};

我有一个代理列表,代理的数量各不相同。我想调用所有代理的方法 init_all_regs() ,以便所有代理并行运行。

是否存在“所有”和“每个”语法的某种组合?

4

2 回答 2

4

没有“all of for each”语法,但使用现有语法很容易实现。例如,您可以使用反对。定义一个 objection_kind,并使用它进行同步。

例如:

extend objection_kind :[AGNETS_CHECK_REGS];

unit agent {
    init_all_regs()@clk is {
        raise_objection(AGNETS_CHECK_REGS);
        //...
        drop_objection(AGNETS_CHECK_REGS);   
    };
};
extend env {
   my_method() @clock is {
        for each in agents {
        start it.init_all_regs();
        };

        wait cycle;
        while get_objection_total(AGNETS_CHECK_REGS) > 0 {
            wait cycle;
        };
   };
};
于 2017-05-19T05:44:26.907 回答
1

另一种选择是使用一个计数器,用静态成员实现。一个缺点是它需要更多的行。

像这样的东西-

unit agent {
    static active_counter : int = 0;
    static increase_active_counter() is {
        active_counter += 1;
    };
    ////....
    init_all_regs()@clk is {
        increase_active_counter();
        //....

        decrease_active_counter();
    };
};

extend env {
    scenario() @any is {

        agent::init_active_counter();

        for each in agents {
            start it.init_all_regs();
        };

        wait cycle;
        while agent::get_active_counter() > 0 {
            wait cycle;
        };
    };
  };
于 2017-05-19T05:48:45.620 回答