Hi Ramyaa,
I have submitted a patch for the latest code here :
https://issues.apache.org/jira/secure/attachment/12595758/crimingeoprofile.diff
The code for the function implementing random movement is given below:
function random_movement($start_lat, $start_long, $dest_lat, $dest_long,
$time){
$con = pg_connect("host=localhost port=5432 dbname=template_postgis_20
user=postgres password=a");
//finding nearest node to destination
$query = "SELECT * FROM node
ORDER BY geom <-> ST_GeometryFromText('POINT(".$dest_lat."
".$dest_long.")',4326)
LIMIT 1;";
$result = pg_query($con, $query);
$row = pg_fetch_row($result);
$dest_id = $row[0];
//find nearest road to given point
$query = "SELECT * FROM network
ORDER BY geom <-> ST_GeometryFromText('POINT(".$start_lat."
".$start_long.")',4326)
LIMIT 1;";
$result = pg_query($con, $query);
$row = pg_fetch_row($result);
$start_id = $row[13];
$end_id = $row[14];
$curr_road_id = $row[1];
$route = array();
$n=0;
//decide randomly whether to move up or down the road
$ran = rand(0,1);
$curr_node = 0;
if($ran == 0){
$curr_node = $start_id;
}
else{
$curr_node = $end_id;
}
while(1){
//stroing route
$route[$n++] = $curr_node;
//finding distance from intersection to destination
$query = "SELECT * FROM pgr_dijkstra('
SELECT gid AS id,
start_id::int4 AS source,
end_id::int4 AS target,
length::float8 AS cost
FROM network',
".$curr_node.",
".$dest_id.",
false,
false);";
$result = pg_query($con, $query);
$cost = 0;
while($row = pg_fetch_row($result)){
$cost+=$row[3];
}
//if time runs out break from loop
if(($time > $cost/30000*60) + ($curr_cost/30000*60) + 5) break;
//else get all roads at this intersection
$query = "SELECT osm_id FROM network
WHERE
network.start_id = ".$curr_node." OR network.end_id = ".$curr_node.";";
$result = pg_query($con, $query);
//stroing all roads from this intersection except the road thruogh which
the agent came
$way = array();
$num = 0;
while($row = pg_fetch_row($result)){
$tmp = $row[0];
if($tmp != $curr_road_id){
$way[$num++] = $tmp;
}
}
//choosing a new road randomly
$ran = rand(0,$num-1);
$curr_road_id = $way[$ran];
//finding the other end of the new road
$query = "SELECT start_id, end_id FROM network
WHERE
network.osm_id = ".$curr_node.";";
$result = pg_query($con, $query);
$row = pg_fetch_row($result);
$start_id = $row[0];
$end_id = $row[1];
if($curr_node == $start_id){
$curr_node == $end_id;
}
else if($curr_node == $end_id){
$curr_node == $start_id;
}
}
//moving to destination by the shortest path;
$query = "SELECT * FROM pgr_dijkstra('
SELECT gid AS id,
start_id::int4 AS source,
end_id::int4 AS target,
length::float8 AS cost
FROM network',
".$curr_node.",
".$dest_id.",
false,
false);";
$result = pg_query($con, $query);
while($row = pg_fetch_row($result)){
$route[$n++] = $row[1];
}
}
Thanks,
Nadeem
On Fri, Aug 2, 2013 at 3:04 AM, Ra myaa <[email protected]> wrote:
> Hi,
> I am travelling, so I can check the simulation only later today.
> regarding hybrid,
> I will recheck the algo with Dr Verma
> (one way to go is as we had discussed, like in your mail, to take
> short detours; another way is to go to a transit point and then roam around
> there - i will need to check this)
> either way, you are right in assuming that there are only minor changes to
> be done.
>
> reg random movement,
> i have a few clarifications in what you wrote (you may be doing the right
> this, i just wanted to be clear about it)
> what do you mean choose one randomly? - do u mean choose a road that is
> at this intersection randomly?
> - and when time runs out, go to destination.
>
> also, could you send me the code?
>
> thanks,
> -Ramyaa
>
>
>
> On Thu, Aug 1, 2013 at 4:49 AM, Adam Estrada <[email protected]>
> wrote:
>
> > Good job and thanks Nadeem!
> >
> > Adam
> >
>