1 | package vnsim.socialNet; |
---|
2 | |
---|
3 | |
---|
4 | import vnsim.socialNet.GlobalNetwork; |
---|
5 | import vnsim.gui.MapLoader; |
---|
6 | import vnsim.map.object.*; |
---|
7 | |
---|
8 | import java.util.ArrayList; |
---|
9 | |
---|
10 | import java.io.File; |
---|
11 | |
---|
12 | import javax.swing.JFileChooser; |
---|
13 | import javax.swing.JOptionPane; |
---|
14 | |
---|
15 | import vnsim.vehicular.generator.NewCarEvent; |
---|
16 | import vnsim.vehicular.routePlan.RouteComputingUtils; |
---|
17 | import vnsim.vehicular.scenarios.EntryExitScenario; |
---|
18 | import vnsim.vehicular.scenarios.EntryScenario; |
---|
19 | import vnsim.vehicular.scenarios.Route; |
---|
20 | import vnsim.vehicular.simulator.Location; |
---|
21 | import vnsim.vehicular.simulator.RouteSegment; |
---|
22 | import vnsim.vehicular.scenarios.Scenario; |
---|
23 | |
---|
24 | public class Main { |
---|
25 | |
---|
26 | public static Scenario getScenario(String map, ArrayList<Location> entries, ArrayList<Location> exits,ArrayList<String> driverTypes, ArrayList<Route> routes, String name){ |
---|
27 | Scenario s = new Scenario(map,entries,exits,driverTypes,routes,name); |
---|
28 | |
---|
29 | EntryScenario es; |
---|
30 | EntryExitScenario ees; |
---|
31 | int i, j; |
---|
32 | Route r; |
---|
33 | |
---|
34 | for (i = 0; i < entries.size(); i++) { |
---|
35 | es = new EntryScenario(entries.get(i)); |
---|
36 | es.flow = 400; |
---|
37 | es.percentsDriverTypes.add(new Integer(GlobalNetwork.CALM)); |
---|
38 | es.percentsDriverTypes.add(new Integer(GlobalNetwork.REGULAR)); |
---|
39 | es.percentsDriverTypes.add(new Integer(GlobalNetwork.AGGRESIVE)); |
---|
40 | |
---|
41 | ees = new EntryExitScenario(entries.get(i), exits.get(i)); |
---|
42 | ees.percentsEachRoute.add(new Integer(100)); |
---|
43 | r = new Route(); |
---|
44 | r.entry = entries.get(i); |
---|
45 | r.exit = exits.get(i); |
---|
46 | r.route = new ArrayList<RouteSegment>(); |
---|
47 | try { |
---|
48 | r = returnRoute(r.entry, r.exit); |
---|
49 | |
---|
50 | } catch (Exception e) { |
---|
51 | } |
---|
52 | |
---|
53 | ees.routes.add(r); |
---|
54 | es.entryExits.add(ees); |
---|
55 | s.allRoutes.add(r); |
---|
56 | |
---|
57 | for (j = 0; j < es.entryExits.size(); j++) { |
---|
58 | es.entryExits.get(j).percentOfFlow = (int) (100); |
---|
59 | } |
---|
60 | s.entryScenarios.add(es); |
---|
61 | } |
---|
62 | return s; |
---|
63 | } |
---|
64 | |
---|
65 | public static Route returnRoute(Location entrie, Location exit){ |
---|
66 | RouteComputingUtils rcu = new RouteComputingUtils(); |
---|
67 | //return rcu.bestRoute(entrie,exit); |
---|
68 | return rcu.shortestPathByTimeAproximation(entrie,exit); |
---|
69 | } |
---|
70 | |
---|
71 | public static ArrayList<Route> returnRoutes(ArrayList<Location> entries, ArrayList<Location> exits){ |
---|
72 | ArrayList<Route> route = new ArrayList<Route>(); |
---|
73 | for(int i=0;i<entries.size();i++){ |
---|
74 | Route raux = returnRoute(entries.get(i),exits.get(i)); |
---|
75 | route.add(raux); |
---|
76 | } |
---|
77 | return route; |
---|
78 | } |
---|
79 | |
---|
80 | public static Route returnSocialNetworkRoute(int i,Location entry, Location exit, Mobility mob, int cellX[], int cellY[]){ |
---|
81 | ArrayList<RouteSegment> rs = mob.getSocialAtractionRoute(i,cellX, cellY); |
---|
82 | Route route = new Route(); |
---|
83 | route.entry = entry; |
---|
84 | route.exit = exit; |
---|
85 | route.route = rs; |
---|
86 | return route; |
---|
87 | } |
---|
88 | |
---|
89 | public static ArrayList<Route> returnSocialNetworkRoutes(ArrayList<Location> entries, ArrayList<Location> exits,Mobility mob, int cellX[], int cellY[]){ |
---|
90 | ArrayList<Route> route = new ArrayList<Route>(); |
---|
91 | for(int i=0;i<entries.size();i++){ |
---|
92 | Route raux = returnSocialNetworkRoute(i,entries.get(i),exits.get(i),mob,cellX,cellY); |
---|
93 | route.add(raux); |
---|
94 | } |
---|
95 | return route; |
---|
96 | } |
---|
97 | |
---|
98 | public static Scenario recofigurare(){ |
---|
99 | |
---|
100 | Mobility mob = GlobalNetwork.socialMobility; |
---|
101 | ArrayList<Location> entries; |
---|
102 | ArrayList<Location> exits; |
---|
103 | mob.deleteAll(); |
---|
104 | mob.reconfigureEntrie(); |
---|
105 | mob.placeNodes(0); |
---|
106 | mob.initalPositions(); |
---|
107 | entries = mob.getLocations(); |
---|
108 | int cellX[] = new int[GlobalNetwork.nrHosts]; |
---|
109 | int cellY[] = new int[GlobalNetwork.nrHosts]; |
---|
110 | mob.getPositions(cellX,cellY); |
---|
111 | mob.deleteAll(); |
---|
112 | mob.reconfigureExit(); |
---|
113 | mob.placeNodes(1); |
---|
114 | mob.initalPositions(); |
---|
115 | exits = mob.getLocations(); |
---|
116 | ArrayList<Route> route; |
---|
117 | Scenario s; |
---|
118 | if(GlobalNetwork.numberOfReconfigurations%2==0){ |
---|
119 | route = returnRoutes(exits,entries); |
---|
120 | s = getScenario(GlobalNetwork.mapName,exits,entries,GlobalNetwork.driverType,route,GlobalNetwork.name); |
---|
121 | GlobalNetwork.entries = exits; |
---|
122 | GlobalNetwork.exits = entries; |
---|
123 | } |
---|
124 | else{ |
---|
125 | if(GlobalNetwork.routingType==0){ |
---|
126 | route = returnSocialNetworkRoutes(entries,exits,mob,cellX,cellY); |
---|
127 | } |
---|
128 | else{ |
---|
129 | route = returnRoutes(entries,exits); |
---|
130 | } |
---|
131 | //route = returnRoutes(entries,exits); |
---|
132 | s = getScenario(GlobalNetwork.mapName,entries,exits,GlobalNetwork.driverType,route,GlobalNetwork.name); |
---|
133 | GlobalNetwork.entries = entries; |
---|
134 | GlobalNetwork.exits = exits; |
---|
135 | } |
---|
136 | |
---|
137 | GlobalNetwork.numberOfReconfigurations=GlobalNetwork.numberOfReconfigurations+1; |
---|
138 | GlobalNetwork.nextReconfigurationTime=(GlobalNetwork.numberOfReconfigurations+1)*GlobalNetwork.CONFTIME; |
---|
139 | |
---|
140 | GlobalNetwork.socialMobility = mob; |
---|
141 | |
---|
142 | return s; |
---|
143 | } |
---|
144 | |
---|
145 | public static void addCarEvents(Scenario sc, int crtTime){ |
---|
146 | ArrayList<EntryScenario> entryScenarios=sc.entryScenarios; |
---|
147 | |
---|
148 | for(int i=0;i<entryScenarios.size();i++) { |
---|
149 | EntryScenario es=entryScenarios.get(i); |
---|
150 | vnsim.vehicular.generator.Mobility.entryScenarios.add(es); |
---|
151 | int period=(int)((double)3600*Globals.executionFPS / (double)es.flow); |
---|
152 | NewCarEvent nce=new NewCarEvent(crtTime+period,i, period); |
---|
153 | vnsim.vehicular.generator.Mobility.events.addEvent(nce); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | public static void main(String args[]) throws Exception{ |
---|
158 | System.out.println("In main - "+args[0]+" - "+GlobalNetwork.CALM+" "+GlobalNetwork.AGGRESIVE+" "+GlobalNetwork.REGULAR); |
---|
159 | System.out.println(GlobalNetwork.THESHOLD+" "+GlobalNetwork.REWIRE); |
---|
160 | System.out.println(GlobalNetwork.CONFTIME); |
---|
161 | System.out.println(GlobalNetwork.ROWS+" "+GlobalNetwork.COLUMNS+" "+GlobalNetwork.GROUPS); |
---|
162 | System.out.println("priority: "+GlobalNetwork.PRIORITY+" "+GlobalNetwork.priorityType); |
---|
163 | |
---|
164 | Globals.SOCIALNETWORK = 1; |
---|
165 | |
---|
166 | // MapLoader.loadSimulationParameters(); |
---|
167 | |
---|
168 | Util.getCellSize(args[0]); |
---|
169 | |
---|
170 | System.out.println("Map loaded..."); |
---|
171 | |
---|
172 | GlobalNetwork.numberOfReconfigurations=0; |
---|
173 | GlobalNetwork.nextReconfigurationTime=GlobalNetwork.CONFTIME; |
---|
174 | GlobalNetwork.nrHosts = GlobalNetwork.AGGRESIVE + GlobalNetwork.CALM + GlobalNetwork.REGULAR; |
---|
175 | |
---|
176 | GlobalNetwork.LENGTHX = GlobalNetwork.pointMax.getLongitude() - GlobalNetwork.pointMin.getLongitude(); |
---|
177 | GlobalNetwork.LENGTHY = GlobalNetwork.pointMax.getLatitude() - GlobalNetwork.pointMin.getLatitude(); |
---|
178 | |
---|
179 | if(GlobalNetwork.GROUPS > GlobalNetwork.nrHosts){ |
---|
180 | GlobalNetwork.GROUPS = GlobalNetwork.nrHosts; |
---|
181 | } |
---|
182 | |
---|
183 | vnsim.socialNet.Mobility mob = new vnsim.socialNet.Mobility(); |
---|
184 | |
---|
185 | if(GlobalNetwork.priorityType==0){ |
---|
186 | mob.setPriorityEntry(); |
---|
187 | mob.setPriorityExit(); |
---|
188 | } |
---|
189 | if(GlobalNetwork.priorityType==1){ |
---|
190 | mob.setPriorityEntryCenter(false); |
---|
191 | mob.setPriorityExitCenter(true); |
---|
192 | } |
---|
193 | if(GlobalNetwork.priorityType==2){ |
---|
194 | mob.setPriorityEntryCenter(false); |
---|
195 | mob.setPriorityExitCenter(false); |
---|
196 | } |
---|
197 | |
---|
198 | mob.reconfigureEntrie(); |
---|
199 | |
---|
200 | mob.placeNodes(0); |
---|
201 | |
---|
202 | mob.initalPositions(); |
---|
203 | |
---|
204 | ArrayList<Location> entries = mob.getLocations(); |
---|
205 | |
---|
206 | int cellX[] = new int[GlobalNetwork.nrHosts]; |
---|
207 | int cellY[] = new int[GlobalNetwork.nrHosts]; |
---|
208 | mob.getPositions(cellX,cellY); |
---|
209 | |
---|
210 | mob.deleteAll(); |
---|
211 | |
---|
212 | mob.reconfigureExit(); |
---|
213 | |
---|
214 | mob.placeNodes(1); |
---|
215 | |
---|
216 | mob.initalPositions(); |
---|
217 | |
---|
218 | ArrayList<Location> exits = mob.getLocations(); |
---|
219 | |
---|
220 | ArrayList<Route> route; |
---|
221 | if(GlobalNetwork.routingType==0){ |
---|
222 | route = returnSocialNetworkRoutes(entries,exits,mob,cellX,cellY); |
---|
223 | } |
---|
224 | else{ |
---|
225 | route = returnRoutes(entries,exits); |
---|
226 | } |
---|
227 | //ArrayList<Route> route = returnRoutes(entries,exits); |
---|
228 | //ArrayList<Route> route = returnSocialNetworkRoutes(entries,exits,mob,cellX,cellY); |
---|
229 | |
---|
230 | ArrayList<String> driverTypes = new ArrayList<String>(); |
---|
231 | driverTypes.add("very calm"); |
---|
232 | driverTypes.add("regular"); |
---|
233 | driverTypes.add("aggresive"); |
---|
234 | |
---|
235 | String name = new String("Scenario"+args[0]); |
---|
236 | |
---|
237 | int ret=JOptionPane.showConfirmDialog(null, "Do you want to specify a flow variations file?"); |
---|
238 | |
---|
239 | if(ret==JOptionPane.OK_OPTION) { |
---|
240 | JFileChooser fc=new JFileChooser(System.getProperty("user.home") + File.separatorChar + "maps" + |
---|
241 | File.separatorChar + "variations"); |
---|
242 | fc.setDialogTitle("Choose the file specifying the flow variations"); |
---|
243 | int retVal=fc.showOpenDialog(null); |
---|
244 | if(retVal==JFileChooser.APPROVE_OPTION) { |
---|
245 | vnsim.map.object.Globals.variationsFile=fc.getSelectedFile().getName(); |
---|
246 | } else { |
---|
247 | vnsim.map.object.Globals.variationsFile=null; |
---|
248 | } |
---|
249 | } else { |
---|
250 | vnsim.map.object.Globals.variationsFile=null; |
---|
251 | } |
---|
252 | //Scenario sc = getScenario(".//maps//map//"+args[0], entries, exits, driverTypes, route,name); |
---|
253 | Scenario sc = getScenario(System.getProperty("user.home") + File.separatorChar + "maps" + |
---|
254 | File.separatorChar + "map" + File.separatorChar + args[0], entries, exits, driverTypes, route,name); |
---|
255 | |
---|
256 | |
---|
257 | |
---|
258 | GlobalNetwork.driverType = driverTypes; |
---|
259 | GlobalNetwork.name = name; |
---|
260 | //GlobalNetwork.mapName = ".//maps//map//"+args[0]; |
---|
261 | GlobalNetwork.mapName = System.getProperty("user.home") + File.separatorChar + "maps" + |
---|
262 | File.separatorChar + "map" + File.separatorChar + args[0]; |
---|
263 | |
---|
264 | GlobalNetwork.entries = entries; |
---|
265 | GlobalNetwork.exits = exits; |
---|
266 | GlobalNetwork.socialMobility = mob; |
---|
267 | |
---|
268 | try |
---|
269 | { |
---|
270 | vnsim.vehicular.generator.Mobility.loadScenario(sc); |
---|
271 | } |
---|
272 | catch (Exception ex) |
---|
273 | { |
---|
274 | JOptionPane.showMessageDialog(null, "<html>ERROR! Map structure has been modified<br> Try rebuilding the map " + sc.mapFileName +"!</html>"); |
---|
275 | throw ex; |
---|
276 | } |
---|
277 | |
---|
278 | vnsim.gui.Main.startGui(); |
---|
279 | //vnsim.socialNet.startGraph.start(); |
---|
280 | } |
---|
281 | |
---|
282 | } |
---|