设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9022|回复: 7

[交流] 科学网于同奎先生的源程序

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
1 a( J3 e1 {. dsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行5 V# K, ~. \. t2 _) t8 b/ d
6 J+ u9 r; r$ F, H' l: @9 O: E# k
似乎缺少了一个SwarmUtils的类,不知道怎么回事
/ d5 k0 B8 T4 l7 @$ t8 Y: R
) G" r9 E9 M- t; b. z7 b朋友们给个反馈??

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1仿真币 +12 +1 收起 理由
苘苘 + 12 + 1

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  W( x" F" h. d
/ Y+ J, {, O- N$ m: P; S2 r! s
public class SwarmUtils {8 r3 t) F& _, d& I
  public static Selector getSelector(String name, String method) {9 ^6 j0 ^3 n" g2 g6 `: d0 U  J$ t4 T
    Selector sel;
- Q/ r5 h! ?3 G    try {
5 l7 _5 Q: d. F' R" E4 r8 T& Z      sel = new Selector(Class.forName(name), method, false);& m# x" w5 A) @0 N  r7 t
    } catch (Exception e) {
7 u! ?: e1 c# G( F( o2 o6 n      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
7 S& Y% b8 X7 y/ ~$ W3 T$ e      System.err.println(name + "." + method + " returns " + e.getMessage());
3 @# A( o6 A; u# B/ ]; T! }      System.err.println("The process will be terminated.");' I/ _$ |& t: ~# f0 ~/ F
      System.exit(1);0 u2 Z6 ]1 B( w- N4 M/ S1 J- ?( w5 g
      return null;& T* F" X* f1 S% u
    }- b8 {2 w8 P8 T% Y. b3 \  T
    return sel;/ Z. g9 S# x: N. f: U5 A( A; A8 c
  }
/ K7 R( Y7 q/ Z" T1 H! A9 S, \7 y1 X0 F+ I: d# |
  public static Selector getSelector(Object obj, String method) {- t3 T# @7 {# U) s6 l+ S
    Selector sel;6 }9 u+ C; x" p9 N* L/ p' K) W
    try {& ^& E) ^2 w, N4 w, S( E9 }0 f
      sel = new Selector(obj.getClass(), method, false);( f- U% b% X+ o
    } catch (Exception e) {
( |0 X6 Z+ v& B3 D8 L+ |* ?      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ K1 D, i7 Q+ ?6 F1 Q9 F3 H          + (obj.getClass()).getName() + ".");
6 d' O/ X5 Q3 f* |; q      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 x5 Q* ?4 E( i. I      System.err.println("The process will be terminated.");* G6 p8 y* {+ ?; D/ P) t9 F
      System.exit(1);
7 X  U. W' Q$ r$ I* t! M      return null;5 t' L6 ^$ U# Y7 [5 b0 U8 v
    }
, W) E/ c+ \/ b. H* Z8 z    return sel;
* S% n7 g- Y" j$ ?) p5 Y4 J  }. j; y" {0 l6 s; z# ^6 @
}

评分

参与人数 1仿真币 +21 +1 收起 理由
苘苘 + 21 + 1 我很赞同

查看全部评分

发表于 2008-11-20 19:49:58 | 显示全部楼层
very good.
发表于 2008-11-28 11:12:43 | 显示全部楼层
这个……在SimpleBug的代码中自带了一个SwarmUtils的类……答案如2楼所示……
发表于 2009-3-12 14:52:51 | 显示全部楼层

谢谢

学习学习
发表于 2009-12-2 20:20:58 | 显示全部楼层
请问一下代码是添加在哪里的啊?
发表于 2012-5-22 10:31:21 | 显示全部楼层
是单独建立一个新的JAVA文件,文件名为SwarmUtils.java,然后把上述代码复制进去就可以了
发表于 2013-1-25 12:27:29 | 显示全部楼层
学习。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-3-1 03:38 , Processed in 0.023389 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表