source: proiecte/ptvs/src/vnsim/vehicular/routePlan/selfRouted/QueryGeneration.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 2.3 KB
Line 
1/************************************************************************************
2 * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
3 * All rights reserved.
4 * Refer to LICENSE for terms and conditions of use.
5 ***********************************************************************************/
6package vnsim.vehicular.routePlan.selfRouted;
7
8
9import java.util.Date;
10
11import vnsim.applications.trafficview.SimulatedCarInfo;
12import vnsim.applications.vitp.CarRunningVITP;
13import vnsim.applications.vitp.utils.VITPRequest;
14import vnsim.map.object.Globals;
15import vnsim.vehicular.simulator.CarInstance;
16import vnsim.vehicular.simulator.RouteSegment;
17
18
19
20
21public class QueryGeneration{
22       
23        public static void generateQueryForCar(CarInstance car){
24               
25
26                if ((car.routingType % 2 == 1)
27                                && (car.queryTime == Globals.engine.crtTime % 3000)) {
28                        //System.out.println("Car "+car.ID+"gen query");
29                       
30                                SimulatedCarInfo myCar = Globals.engine.getCarIdx(car.ID);
31                                if (myCar != null) {
32                                        RouteSegment nextHop = null;
33                                        int ah,pt1,pt2;
34                                        for (ah = 0; ah < Globals.routePlanConstants.HOW_FAR_AHEAD; ah++) {
35                                                //
36                                                nextHop = getNextSegmentFromRoute(car,(ah + 1));
37                                               
38                                                if (nextHop != null) {
39                                                        pt1 = nextHop.pt1;
40                                                        pt2 = nextHop.pt2;
41                                                        if (pt1 < pt2) {
42                                                                if (pt2 - 4 > pt1) {
43                                                                        pt1 = pt2 - 4;
44                                                                }
45                                                        } else {
46                                                                if (pt2 + 4 < pt1) {
47                                                                        pt1 = pt2 + 4;
48                                                                }
49                                                        }
50
51                                                        VITPRequest req = new VITPRequest(
52                                                                        (short) nextHop.roadIndex,
53                                                                        (short) pt1, (short) pt2,
54                                                                        (short) -1, (short) -1, (short) -1,
55                                                                        new Date(), new Date(), "none", -1,
56                                                                        "RI ", "GET",
57                                                                        "/Route/Time?[cnt=3&tout=30000msec]");
58                                                        try {
59                                                                ((CarRunningVITP) myCar).p
60                                                                                .postMessageFromAbove(req);
61                                                                car.sentMsgCount++;
62                                                        } catch (Exception e) {
63                                                                e.printStackTrace();
64                                                        }
65//                                             
66                                                } 
67                                        }
68                                }
69                       
70                       
71
72                }
73               
74               
75        }
76       
77        public static RouteSegment getNextSegmentFromRoute(CarInstance car, int far) {
78                RouteSegment rez = null;
79                if (car.routeIndex + far < car.route.length) {
80                        try {
81                                rez = car.route[car.routeIndex + far];
82                        } catch (Exception e) {
83                                // no more streets
84
85                        }
86                }
87                return rez;
88        }
89
90       
91       
92}
Note: See TracBrowser for help on using the repository browser.