[i=s] 本帖最后由 zorsite 于 2015-10-9 20:49 编辑 [/i]
[b][url=http://flexsim.asia/redirect.php?goto=findpost&pid=18220&ptid=5505]9#[/url] [i]慧娴亚伦[/i] [/b]
总结的很有道理。
也很感谢各位非常有意义的讨论和回帖。
我之所以提出这样一个问题,是在做FMAT样题第一题的时候,[url=http://www.flexsim.asia/space.php?uid=29661][color=#0066cc]FFFrenk[/color][/url]版主提醒说有更简单的解决方案,就是系统自带的拉入策略“Pull Best Item”。[url=http://www.flexsim.asia/space.php?uid=1434][color=#0066cc]missman[/color][/url]也给出了自己的代码。见[url=http://www.flexsim.asia/viewthread.php?tid=5361&page=1&fromuid=610#pid17648]http://www.flexsim.asia/viewthread.php?tid=5361&page=1&fromuid=610#pid17648[/url]
于是我就去研究“Pull Best Item”策略,发现其设置了非常严格的端口检测条件,有兴趣的可以观摩观摩:[code]
int nrports = nrip(current);
int domax = 0;
if (!inputopen(current))
return PULL_REEVALUATE_ON_READY;
double bestval = domax?-10000000000:10000000000;
int bestportnr = 0;
treenode bestitem = NULL;
for (int i = 1; i <= nrports; i++) {
treenode object = inobject(current, i);
if (!outputopen(object))
continue;
int opnr = ipopno(current, i);
if (!opopen(object, opnr))
continue;
int startindex = 1; int endindex = content(object) + 1; int incr = 1;
if (getvarnum(object, "lifo")) {
startindex = content(object);
endindex = 0;
incr = -1;
}
for (int j = startindex; j != endindex; j+=incr) {
treenode item = rank(object, j);
if (evaluatepullcriteria(current, item, i)) {
double val = getitemtype(item);
int newbest = domax ? val > bestval : val < bestval;
if (newbest) {
bestval = val;
bestitem = item;
bestportnr = i;
}
}
}
}
if (bestitem)
pullitem(current, bestitem, bestportnr, BYPASS_ALL);
else return PULL_REEVALUATE_ON_READY;
return 0;
[/code]在这段代码中,前三个if都是判断端口状态的。
[color=red]if (!inputopen(current))[/color]
return PULL_REEVALUATE_ON_READY;
//如果处理器端口没打开,用return跳出此段代码
......
for (int i = 1; i <= nrports; i++) {
treenode object = inobject(current, i);
[color=red]if (!outputopen(object))[/color]
continue;
//如果上游输出端口没打开,用continue跳出此次for循环
int opnr = ipopno(current, i);
[color=red]if (!opopen(object, opnr))[/color]
continue;
[color=#444444]//如果上游输出端口打开了,继续判断上游实体与当前实体相连的那个输出端口是否打开,如果没打开,则用continue跳出此次for循环[/color]
我主要是对最后一次判断比较不理解,因为根据我在前面的分析,固定实体是不能单独打开或关闭某个端口的。 |