You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sis.apache.org by Nadeem Anjum <na...@gmail.com> on 2013/08/01 07:38:45 UTC
[GSoC] Update
Hi All,
I have been able to convert the open street map data into a routable
network, and extract roads and intersections from that. This data will be
useful for simulating both the other two from of agent movements - random
and hybrid. For random movement, I have formulated queries to:
- find the the closest road to the start point
- find the next road intersection
- choosing one randomly at each intersection (if time permits)
- doing the above repeatedly.
So I now have the route data for random movement. I just have to have put
the queries together, and mark the route with poly-lines.
For hybrid movement, since we have the road and intersection data now, its
a matter of a few lines of code to have the simulation.
@Ramyaa - if there are any changes in the algo for hybrid movement from
what you had sent me earlier, please let me know. If not, I will proceed to
implement the algo below:
The agent moves along a chosen route, but takes short detours at random.
again, this is time bound
he picks 2 points along the route, and chooses a
diff, longer route between these two.
then if he has time, he repeats this again.
Thanks,
Nadeem
Re: [GSoC] Update
Posted by Nadeem Anjum <na...@gmail.com>.
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 <ra...@gmail.com> 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 <es...@gmail.com>
> wrote:
>
> > Good job and thanks Nadeem!
> >
> > Adam
> >
>
Re: [GSoC] Update
Posted by Ra myaa <ra...@gmail.com>.
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 <es...@gmail.com> wrote:
> Good job and thanks Nadeem!
>
> Adam
>
Re: [GSoC] Update
Posted by Adam Estrada <es...@gmail.com>.
Good job and thanks Nadeem!
Adam
Re: [GSoC] Update
Posted by Arvind Verma <av...@gmail.com>.
Nadeem
I am in India and my mobile number is 9810439903 in case you need to
discuss something with me.
Arvind Verma
On Thu, Aug 1, 2013 at 1:38 AM, Nadeem Anjum <na...@gmail.com>wrote:
> Hi All,
>
> I have been able to convert the open street map data into a routable
> network, and extract roads and intersections from that. This data will be
> useful for simulating both the other two from of agent movements - random
> and hybrid. For random movement, I have formulated queries to:
>
> - find the the closest road to the start point
> - find the next road intersection
> - choosing one randomly at each intersection (if time permits)
> - doing the above repeatedly.
>
> So I now have the route data for random movement. I just have to have put
> the queries together, and mark the route with poly-lines.
>
> For hybrid movement, since we have the road and intersection data now, its
> a matter of a few lines of code to have the simulation.
>
> @Ramyaa - if there are any changes in the algo for hybrid movement from
> what you had sent me earlier, please let me know. If not, I will proceed to
> implement the algo below:
>
> The agent moves along a chosen route, but takes short detours at random.
> again, this is time bound
> he picks 2 points along the route, and chooses a
> diff, longer route between these two.
> then if he has time, he repeats this again.
>
>
>
> Thanks,
> Nadeem
>