AnsimWriter.java
Go to the documentation of this file.00001 package ansim;
00002
00003 import java.io.IOException;
00004 import java.io.PrintWriter;
00005 import java.util.HashMap;
00006 import java.util.List;
00007
00013 public class AnsimWriter {
00021 public static void write(String outfile, String trace, List<Vehicle> vehicles, HashMap<String, Integer> vehicleIds, List<Edge> edges) {
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
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
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
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 }
00085 }