Definition at line 14 of file ConfigWriter.java.
Static Public Member Functions | |
| static void | write (String config, String activity, String mobility, List< Edge > edges, List< String > wantedVehicle, Map< String, Double > vehicleFirstOcc, Map< String, Double > vehicleLastOcc, double begin, double penetration, boolean hasPenetration) |
| static void ns2::ConfigWriter::write | ( | String | config, | |
| String | activity, | |||
| String | mobility, | |||
| List< Edge > | edges, | |||
| List< String > | wantedVehicle, | |||
| Map< String, Double > | vehicleFirstOcc, | |||
| Map< String, Double > | vehicleLastOcc, | |||
| double | begin, | |||
| double | penetration, | |||
| boolean | hasPenetration | |||
| ) | [inline, static] |
working method
| config | name of ns2 config file | |
| activity | name of ns2 activity file | |
| mobility | name of ns2 mobility file | |
| edges | list of edges | |
| wantedVehicle | list of vehicles to be selected for ns2 | |
| vehicleFirstOcc | map: vehicle id -> first occurence of vehicle in sumo | |
| vehicleLastOcc | map: vehicle id -> last occurence of vehicle in sumo | |
| begin | sumo time at which ns2 should start to simulate |
Definition at line 26 of file ConfigWriter.java.
00036 { 00037 float xmin = 0, xmax = 0, ymin = 0, ymax = 0; 00038 float end = 0; 00039 00040 // extend of map 00041 boolean first = true; 00042 for (Edge edge: edges) { 00043 for (Lane lane: edge.lanes.values() ) { 00044 if (first) { 00045 first = false; 00046 xmin = Math.min(lane.xfrom, lane.xto); 00047 xmax = Math.max(lane.xfrom, lane.xto); 00048 ymin = Math.min(lane.yfrom, lane.yto); 00049 ymax = Math.max(lane.yfrom, lane.yto); 00050 } else { 00051 xmin = Math.min(Math.min(lane.xfrom, lane.xto), xmin); 00052 xmax = Math.max(Math.max(lane.xfrom, lane.xto), xmax); 00053 ymin = Math.min(Math.min(lane.yfrom, lane.yto), ymin); 00054 ymax = Math.max(Math.max(lane.yfrom, lane.yto), ymax); 00055 } 00056 } 00057 } 00058 xmin = (float) Math.floor(xmin); 00059 xmax = (float) Math.ceil(xmax); 00060 ymin = (float) Math.floor(ymin); 00061 ymax = (float) Math.ceil(ymax); 00062 00063 00064 // duration of simulation 00065 first = true; 00066 for (String id: wantedVehicle) { 00067 if (first) { 00068 first = false; 00069 end = vehicleLastOcc.get(id).floatValue(); 00070 } else { 00071 end = Math.max(vehicleLastOcc.get(id).floatValue(), end); 00072 } 00073 } 00074 00075 // write! 00076 try { 00077 PrintWriter out = new PrintWriter(config); 00078 00079 out.println("# set number of nodes"); 00080 if (hasPenetration) { 00081 out.println("set opt(nn) " + Math.floor(penetration*wantedVehicle.size())); 00082 } else { 00083 int N = wantedVehicle.size(); 00084 for (int i = 0; i <= N-1; i++) { 00085 out.print("if { $opt(penetration) > " + ((double) i/N) + " } { "); 00086 out.print("set opt(nn) " + (i+1)); 00087 out.println(" }"); 00088 } 00089 } 00090 out.println(); 00091 out.println("# set activity file"); 00092 out.println("set opt(af) $opt(config-path)"); 00093 out.println("append opt(af) /" + activity); 00094 out.println(); 00095 out.println("# set mobility file"); 00096 out.println("set opt(mf) $opt(config-path)"); 00097 out.println("append opt(mf) /" + mobility); 00098 out.println(); 00099 out.println("# set start/stop time"); 00100 out.println("set opt(start) 0.0"); 00101 out.println("set opt(stop) " + (end-begin)); 00102 out.println(); 00103 out.println("# set floor size"); 00104 out.println("set opt(x) " + (int) xmax); 00105 out.println("set opt(y) " + (int) ymax); 00106 out.println("set opt(min-x) " + (int) xmin); 00107 out.println("set opt(min-y) " + (int) ymin); 00108 00109 out.flush(); 00110 out.close(); 00111 } catch (FileNotFoundException ex) { 00112 System.err.println(ex); 00113 } 00114 }
1.5.6