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

📄 dumpspatialmodel.java

📁 linux下用于移动节点的移动活动生成工具
💻 JAVA
字号:
package de.uni_stuttgart.informatik.canu.spatialmodel.extensions;

import de.uni_stuttgart.informatik.canu.mobisim.core.*;
import de.uni_stuttgart.informatik.canu.spatialmodel.core.*;
import de.uni_stuttgart.informatik.canu.mobisim.extensions.Graph;
import de.uni_stuttgart.informatik.canu.senv.core.Edge;
import de.uni_stuttgart.informatik.canu.mobisim.notifications.*;

/**
 * <p>Title: Spatial Model</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002-2003</p>
 * <p>Company: University of Stuttgart</p>
 * @author Illya Stepanov
 * @version 1.1
 */

/**
 * This class is used to dump the Spatial Model
 * @author Illya Stepanov 
 */
public class DumpSpatialModel extends ExtensionModule
{
  /**
   * Spatial Model
   */
  protected SpatialModel spatialModel;

  /**
   * Output Stream
   */
  protected java.io.PrintStream o = System.err;

  /**
   * Constructor
   */
  public DumpSpatialModel()
  {
    super("DumpSpatialModel");
  }

  /**
   * Returns the module's description. <br>
   * <br>
   * @return extension module's description
   */
  public String getDescription()
  {
    return "Spatial Model dumping module";
  }

  /**
   * Performs the module initialization. <br>
   * <br>
   * The method is called after finishing the scenario file processing.
   */
  public void initialize()
  {
    java.util.Map elements = spatialModel.getElements();

    // Number of features belonging to a class
    java.util.Map n_features = new java.util.TreeMap();

    // Iterate the elements
    java.util.Iterator iter = elements.values().iterator();
    while (iter.hasNext())
    {
      SpatialModelElement element = (SpatialModelElement)iter.next();
      String code = element.getClassCode()+element.getSubClassCode();

      Integer i = (Integer)n_features.get(code);
      if (i==null)
        i = new Integer(1);
      else
        i = new Integer(i.intValue()+1);
      n_features.put(code, i);
    }

    // Display a number of features found
    o.println("! Summary of features found:");
    iter = n_features.keySet().iterator();
    while (iter.hasNext())
    {
      String code = (String)iter.next();
      int n = ((Integer)n_features.get(code)).intValue();
      o.println("! "+code+" "+n);
    }

    o.println("! Area dimensions: "+u.getDimensionX()+' '+u.getDimensionY());
    
    Graph graph = spatialModel.getGraph();
    o.println("! Movement area dimensions: "+(float)(graph.getRightmostCoordinate()-graph.getLeftmostCoordinate())+
        ' '+(float)(graph.getUppermostCoordinate()-graph.getLowermostCoordinate()));
    o.println("! Graph has "+graph.getVertices().size()+" vertices, "
        +graph.getEdges().size()+" edges ");

    o.println("! Movement area graph (in xgraph.exe format):");
    iter = graph.getInfrastructureGraph().getEdges().iterator();
    while (iter.hasNext())
    {
      Edge edge = (Edge)iter.next();

      o.println(edge.getV1().getX()+" "+edge.getV1().getY());
      o.println(edge.getV2().getX()+" "+edge.getV2().getY());

      o.println("next");
    }
  }

  /**
   * Execute the extension. <br>
   * <br>
   * The method is called on every simulation timestep.
   * @return 0 - the module should be executed on next timesteps,
   *        -1 - the module should not be executed on further timesteps and should be removed from the extensions' list
   */
  public int act()
  {
    return -1;
  }

  /**
   * Initializes simulation parameters from XML tag. <br>
   * <br>
   * @throws Exception Exception if parameters are invalid
   */
  public void load(org.w3c.dom.Element element) throws Exception
  {
    u.sendNotification(new LoaderNotification(this, u,
      "Loading DumpSpatialModel extension"));
    
    super.load(element);

    String outName = element.getAttribute("output");
    if (outName.length()>0)
      o = new java.io.PrintStream(new java.io.FileOutputStream(outName));    

    spatialModel = (SpatialModel)u.getExtension("SpatialModel");
    if (spatialModel==null)
      throw new Exception("SpatialModel instance does not exist!");
      
    u.sendNotification(new LoaderNotification(this, u,
      "Finished loading DumpSpatialModel extension"));
  }
}

⌨️ 快捷键说明

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