⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 observerswarm.java

📁 本源码应用于Java的JDK1.4.2版本+Swarm2.2 程序在Cygwin终端运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                             + e.getMessage ());
       }

    try{
      	    sel=new Selector(AgentList.getClass(),"getCount",false);
            populationGraph.createSequence$withFeedFrom$andSelector
                                                  ("population",AgentList,sel);
         }catch(Exception e){System.err.println("population"+e.getMessage()); }

       }


       //Create a  graph for various agent attributes
       attributeGraph = new EZGraphImpl(getZone(),
                                         "Agent attributes over time",
                                         "time",
                                         "attribute",
                                         "attributeGraph" );

        //Two data sequence here.Average vision for all the bugs
        try {
        attributeGraph.enableDestroyNotification$notificationMethod
          (this, new Selector (getClass (),
                               "_attributeGraphDeath_",
                               false));
      } catch (Exception e) {
        System.err.println ("Exception _attributeGraphDeath_: "
                            + e.getMessage ());
      }

     try{
     	    sel=new Selector(Class.forName ("SugarAgent"),"getVision",false);
            attributeGraph.createAverageSequence$withFeedFrom$andSelector
                                                ("vision",AgentList,sel);
            //And average metabolism
            sel=new Selector(Class.forName ("SugarAgent"),"getMetabolism",false);
            attributeGraph.createAverageSequence$withFeedFrom$andSelector
                                             ("metabolism",AgentList,sel);
        }catch(Exception e){System.err.println("Exception"+e.getMessage());}


//-----------------------------
     if(drawWealthHistogram==1)
      {
        //create a histogram of agent wealth distribution
        Zone aZone=getZone();
        wealthHistogram = new EZBinCImpl(new EZBinImpl ());
        wealthHistogram.createBegin(aZone);
        wealthHistogram.setBinCount(9);
        wealthHistogram.setLowerBound(0);
        wealthHistogram.setUpperBound(300);
        wealthHistogram.setCollection(_modelSwarm.getAgentList());
        wealthHistogram.setTitle("Agent wealth distribution");
        wealthHistogram.setAxisLabelsX$Y( "number of agents","wealth");
    try{
             sel=new Selector(SugarAgent.class,"getcurrentsugar",false);
              wealthHistogram.setProbedSelector(sel);

           // sel=new Selector(this.getClass(),"_wealthHistogramDeath_", false);
       //    wealthHistogram.enableDestroyNotification$notificationMethod(this, sel);
           }catch(Exception e)
           { e.printStackTrace (System.err);
          System.exit (1);  }
        wealthEZBin = (EZBin) wealthHistogram.createEnd ();
        return this;
      }
//-----------------------------------------------
        return this;
    }
/*public Object _wealthHistogramDeath_(Object caller)
{
    wealthEZBin.drop();
    wealthHistogram = null;
   return this;
}*/
public Object _worldRasterDeath_(Object caller)
{
   worldRaster.drop();
   worldRaster = null;
   return this;
}
public Object _attributeGraphDeath_(Object caller)
{
   attributeGraph.drop();
   attributeGraph=null;
   return this;
}
 public Object _populationGraphDeath_(Object caller)
{
   populationGraph.drop();
   populationGraph=null;
   return this;
}


public Object _updateDisplay_()
{
    if(worldRaster!=null)
    {
      worldRaster.fillRectangleX0$Y0$X1$Y1$Color
         (0,0,worldRaster.getWidth(),worldRaster.getHeight(),(byte)0);
        sugarDisplay.display();
        agentDisplay.display();
        worldRaster.drawSelf();
     }
  /*   if (attributeGraph != null)
    try{
        attributeGraph.step ();
        } catch (Exception e){
          System.err.println("Exception attributeGraph: "
                            + e.getMessage ())  ;
        }
   if (populationGraph != null)
    try{
        populationGraph.step ();
        } catch (Exception e){
          System.err.println("Exception populationGraph: "
                          + e.getMessage ())  ;
        }*/
   if(wealthHistogram!=null)
   {
      wealthEZBin.reset();
      wealthEZBin.update();
      wealthEZBin.output();
   }

     return this;
}
   public void drop () {
   if (populationGraph != null)
     populationGraph.disableDestroyNotification ();
    if(attributeGraph !=null)
        attributeGraph.disableDestroyNotification();
   if (worldRaster != null)
     worldRaster.disableDestroyNotification ();

   super.drop ();
 }

//the display schedule
public Object buildActions()
{
     super.buildActions();
     _modelSwarm.buildActions();
      Selector sel;

      displayActions= new ActionGroupImpl(getZone());

     try{
       sel= new Selector(this.getClass(), "_updateDisplay_",false);
       displayActions.createActionTo$message(this, sel);
     } catch (Exception e) {
       System.out.println ("Exception:updateDisplay " + e.getMessage ());}

   try{
       sel = new Selector(attributeGraph.getClass(), "step", true);
       displayActions.createActionTo$message(attributeGraph, sel);
     } catch (Exception e) {
       System.out.println ("Exception: step" + e.getMessage ());}

    try{
      if (drawPopulationGraph == 1) {
         sel = new Selector(populationGraph.getClass(), "step", true);
         displayActions.createActionTo$message(populationGraph, sel);}
      } catch (Exception e) {
       System.out.println ("Exception:step " + e.getMessage ());}
//--------------------------------------
 /*      if (drawWealthHistogram == 1) {
         sel = new Selector(this.getClass(), "_updateHistogram_", true);
         displayActions.createActionTo$message(this, sel);}*/
 //---------------------------------------
  try{
       sel = new Selector(Globals.env.probeDisplayManager.getClass(), "update", true);
       displayActions.createActionTo$message(Globals.env.probeDisplayManager, sel);
      } catch (Exception e) {
       System.out.println ("Exception:update " + e.getMessage ());}
  try{
        sel = new Selector(worldRaster.getClass(), "drawSelf ",true);
        displayActions.createActionTo$message(worldRaster, sel);
     } catch (Exception e) {
       System.out.println ("Exception:drawSelf " + e.getMessage ());}
    try{
       sel = new Selector(getActionCache().getClass(), "doTkEvents", true);
       displayActions.createActionTo$message(getActionCache(), sel);
     } catch (Exception e) {
       System.out.println ("Exception:doTKEvents " + e.getMessage ());}

      displaySchedule = new ScheduleImpl(getZone(),displayFrequency);
      displaySchedule.at$createAction(0, displayActions);
    //  displaySchedule.setRepeatInterval(displayFrequency);

      return this;
}
 //scheduling details :the modelswarm is activated here.

public Activity activateIn(Swarm swarmContext)
{
    super.activateIn(swarmContext);
    _modelSwarm.activateIn(this);
    displaySchedule.activateIn(this);
    return getActivity();
}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -