ansim::AnsimWriter Class Reference


Detailed Description

Class for writing ansim tracefiles
Author:
Thimor Bohn <bohn@itm.uni-luebeck.de>

Definition at line 13 of file AnsimWriter.java.


Static Public Member Functions

static void write (String outfile, String trace, List< Vehicle > vehicles, HashMap< String, Integer > vehicleIds, List< Edge > edges)

Member Function Documentation

static void ansim::AnsimWriter::write ( String  outfile,
String  trace,
List< Vehicle vehicles,
HashMap< String, Integer >  vehicleIds,
List< Edge edges 
) [inline, static]

method for writing ansim tracefile

Parameters:
out name of trace file
vehicles vehicles to be written
vehicleIds contains vehicle ids
edges net

Definition at line 21 of file AnsimWriter.java.

00021                                                                                                                                           {
00022         PrintWriter out = null;
00023         try {
00024             out = new PrintWriter(outfile);
00025         } catch (IOException e) {
00026             System.err.println(e);
00027             System.exit(1);
00028         }
00029         
00030         // find extend of net
00031         float xmin = 0;
00032         float ymin = 0;
00033         float xmax = 0;
00034         float ymax = 0;
00035         
00036         xmin = edges.get(0).xfrom;
00037         xmax = xmin;
00038         ymin = edges.get(0).yfrom;
00039         ymax = ymin;
00040         for (Edge edge: edges) {
00041             xmin = Math.min(xmin, edge.xfrom);
00042             xmin = Math.min(xmin, edge.xto);
00043             xmax = Math.max(xmax, edge.xfrom);
00044             xmax = Math.max(xmax, edge.xto);
00045             ymin = Math.min(ymin, edge.yfrom);
00046             ymin = Math.min(ymin, edge.yto);
00047             ymax = Math.max(ymax, edge.yfrom);
00048             ymax = Math.max(ymax, edge.yto);
00049         }
00050         
00051         // write extend to header
00052         out.println("<?xml version=\"1.0\" ?>");
00053         out.println("<simulation xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.i-u.de/schools/hellbrueck/ansim/xml/spmobtrace.xsd\">");
00054         
00055         out.println("<parameter>");
00056         out.println("  <field_shape>rectangle</field_shape>");
00057         out.println("  <xmin>" + xmin + "</xmin>");
00058         out.println("  <xmax>" + xmax + "</xmax>");
00059         out.println("  <ymin>" + ymin + "</ymin>");
00060         out.println("  <ymax>" + ymax + "</ymax>");
00061         out.println("  <numberOfNodes>" + vehicles.size() + "</numberOfNodes>");
00062         out.println("</parameter>");
00063         out.println("<node_settings>");
00064         
00065         // write initial vehicle positions to header 
00066         for (Vehicle vehicle: vehicles) {
00067             out.println("  <node>");
00068             out.println("    <node_id>" + vehicleIds.get(vehicle.id) + "</node_id>");
00069             out.println("    <name>" + vehicle.id + "</name>");
00070             out.println("    <position>");
00071             out.println("      <xpos>" + vehicle.x + "</xpos>");
00072             out.println("      <ypos>" + vehicle.y + "</ypos>");
00073             out.println("    </position>");
00074             out.println("  </node>");
00075         }
00076         out.println("</node_settings>");        
00077         
00078         System.out.println("start: read trace file - stage 2");
00079         TraceReader.readSecond(out, trace, vehicles, vehicleIds, edges);
00080         System.out.println("finished: read trace file - stage 2");
00081         out.println("</simulation>");
00082         out.println();
00083         out.close();
00084     }


The documentation for this class was generated from the following file:

Generated on Wed May 5 00:07:01 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6