001 import swarm.*; 002 import swarm.activity.*; 003 import swarm.defobj.*; 004 import swarm.objectbase.*; 005 006 public class ModelSwarm extends SwarmImpl{ 007 public int width,height; 008 PatternSpace patternSpace; 009 010 ActionGroup modelActions; 011 Schedule modelSchedule; 012 013 boolean stopFlag; 014 015 public ModelSwarm(Zone aZone){ 016 super(aZone); 017 018 width=50; 019 height=50; 020 021 stopFlag=false; 022 023 EmptyProbeMap probeMap; 024 probeMap=new EmptyProbeMapImpl(aZone,this.getClass()); 025 026 probeMap.addProbe(Globals.env.probeLibrary.getProbeForVariable$inClass 027 ("width",getClass())); 028 probeMap.addProbe(Globals.env.probeLibrary.getProbeForVariable$inClass 029 ("height",getClass())); 030 031 Globals.env.probeLibrary.setProbeMap$For(probeMap,this.getClass()); 032 033 } 034 035 public Object buildObjects(){ 036 patternSpace=new PatternSpace(this,width,height); 037 return this; 038 } 039 040 /** 041 * PatternSpaceのupdateをスケジュールに組み込む 042 */ 043 public Object buildActions(){ 044 modelActions=new ActionGroupImpl(this); 045 try{ 046 modelActions.createActionTo$message(patternSpace, 047 new Selector(Class.forName("PatternSpace"),"update",false)); 048 modelActions.createActionTo$message(this, 049 new Selector(getClass(),"checkToStop",false)); 050 } catch (Exception e) { 051 e.printStackTrace (System.err); 052 System.exit(1); 053 } 054 055 modelSchedule=new ScheduleImpl(this,1); 056 modelSchedule.at$createAction(0,modelActions); 057 return this; 058 } 059 060 public Activity activateIn(Swarm context){ 061 super.activateIn (context); 062 modelSchedule.activateIn(this); 063 return getActivity(); 064 } 065 066 /** 067 * 終了判定<BR> 068 * PatternSpaceに点の置かれていない格子がなくなったら、 069 * 最後のクラスタリング(trace)をして終了 070 */ 071 public void checkToStop(){ 072 if(!patternSpace.remainingQ()){ 073 patternSpace.trace(); 074 this.getActivity().terminate(); 075 stopFlag=true; 076 } 077 } 078 079 /** 080 * シミュレーションが終了したか 081 */ 082 public boolean stopQ(){ 083 return stopFlag; 084 } 085 086 public PatternSpace getPattern(){ 087 return patternSpace; 088 } 089 090 public int getWidth(){ 091 return width; 092 } 093 094 public int getHeight(){ 095 return height; 096 } 097 098 public void initializeSpace(){ 099 if(patternSpace!=null) 100 patternSpace.initializeSpace(); 101 } 102 }