ActivityWriter.java

Go to the documentation of this file.
00001 package ns2;
00002 
00003 import java.io.FileNotFoundException;
00004 import java.io.PrintWriter;
00005 import java.util.Map;
00006 import java.util.List;
00007 
00015 public class ActivityWriter {
00025     public static void write(
00026             String activity,
00027             List<String> wantedVehicle,
00028             List<String> vehicleNewId,
00029             Map<String, Double> vehicleFirstOcc, 
00030             Map<String, Double> vehicleLastOcc,
00031             double begin,
00032             double penetration,
00033             boolean hasPenetration) {
00034         try {
00035             PrintWriter out = new PrintWriter(activity);
00036             for (String id: wantedVehicle) {
00037                 String newId =  vehicleNewId.get(wantedVehicle.indexOf(id));
00038                 double minP =  Double.parseDouble(newId)/wantedVehicle.size();
00039                 if (hasPenetration) {
00040                     if (penetration > minP) {
00041                         out.println("$ns_ at " + (vehicleFirstOcc.get(id)-begin) + " \"$g(" + newId + ") start\"" + "\t;# SUMO-ID: " + id);
00042                         out.println("$ns_ at " + (vehicleLastOcc.get(id)-begin) + " \"$g(" + newId + ") stop\"" + "\t;# SUMO-ID: " + id);
00043                     }
00044                 } else {
00045                     out.println("if { $opt(penetration) > " + minP  + " } { ");
00046                     out.println("  $ns_ at " + (vehicleFirstOcc.get(id)-begin) + " \"$g(" + newId + ") start\"" + "\t;# SUMO-ID: " + id);
00047                     out.println("  $ns_ at " + (vehicleLastOcc.get(id)-begin) + " \"$g(" + newId + ") stop\"" + "\t;# SUMO-ID: " + id);
00048                     out.println("}");
00049                 }
00050             }
00051             out.flush();
00052             out.close();
00053         } catch (FileNotFoundException ex) {
00054             System.err.println(ex);
00055         }
00056     }
00057 }

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