If you have a list of cell tower ids and their respective start and end time (i.e. the time the phone was registered at that tower), is there an easy to cluster the ids and visualise the cells and their clusters in a diagram?
Thanks
Not without some knowledge of location. Minimally at start time and at end time. If you were travelling in a line for example you could estimate the distance of the tower from the midpoint of those. If you just have time data but no location data there is nothing you can map.
Edit: To simplify, if you have no location data, you can't map much of anything, you could simply index transitions - which towers are certainly adjacent. If you jumped from tower A to B to D to B to C to F to C to D to E to A, then you can map them in graph form:
A -- B -- C -- F
| | //
E -- D
This is only the connections that are definitely there, in the example F could be connected to D, or B could be connected to E, but you can only map the transitions you are sure of.
With location data for the mobile device, you could map the points of influence of the towers. From these points you could derive probable areas of influence (circular).
Conversely with location data for the towers, you could map probable transition spots. These could be connected into polygons of influence.
With no location data you can only make speculative graphs.
Related
I am trying to replicate the KOSKK model (Kumpula et al. 2007) in NetLogo but I am stuck.
The original algorithm is:
(I) Select a node i randomly, and
(a) select a friend’s friend k (by weighted search) and introduce
it to i with prob. p_1 (with initial tie strength w_0) if not already
acquainted. Increase tie strengths by "d" along the search path, as
well as on the link l_{ik} if it was already present.
(b) Additionally, with prob. p_r (or with prob. 1 if i has no connections), connect i to a random node j (with tie strength w_0).
(II) Select a random node and with prob. p_d remove all of its ties.
In particular, I am struggling to write correctly the initial step I-a. How can I tell the program to pick the friend k of a friend j (!= myself, i) in the highest weighted path (l_{ij},l_{jk})?
For an experiment I need to pseudo randomize a vector of 100 trials of stimulus categories, 80% of which are category A, 10% B, and 10% C. The B trials have at least two non-B trials between each other, and the C trials must come after two A trials and have two A trials following them.
At first I tried building a script that randomized a vector and sort of "popped" out the trials that were not where they should be, and put them in a space in the vector where there was a long series of A trials. I'm worried though that this is overcomplicated and will create an endless series of unforeseen errors that will need to be debugged, as well as it not being random enough.
After that I tried building a script which simply shuffles the vector until it reaches the criteria, which seems to require less code. However now that I have spent several hours on it, I am wondering if these criteria aren't too strict for this to make sense, meaning that it would take forever for the vector to shuffle before it actually met the criteria.
What do you think is the simplest way to handle this problem? Additionally, which would be the best shuffle function to use, since Shuffle in psychtoolbox seems to not be working correctly?
The scope of this question moves much beyond language-specific constructs, and involves a good understanding of probability and permutation/combinations.
An approach to solving this question is:
Create blocks of vectors, such that each block is independent to be placed anywhere.
Randomly allocate these blocks to get a final random vector satisfying all constraints.
Part 0: Category A
Since category A has no constraints imposed on it, we will go to the next category.
Part 1: Make category C independent
The only constraint on category C is that it must have two A's before and after. Hence, we first create random groups of 5 vectors, of the pattern A A C A A.
At this point, we have an array of A vectors (excluding blocks), blocks of A A C A A vectors, and B vectors.
Part 2: Resolving placement of B
The constraint on B is that two consecutive Bs must have at-least 2 non-B vectors between them.
Visualize as follows: Let's pool A and A A C A A in one array, X. Let's place all Bs in a row (suppose there are 3 Bs):
s0 B s1 B s2 B s3
Where s is the number of vectors between each B. Hence, we require that s1, s2 be at least 2, and overall s0 + s1 + s2 + s3 equal to number of vectors in X.
The task is then to choose random vectors from X and assign them to each s. At the end, we finally have a random vector with all categories shuffled, satisfying the constraints.
P.S. This can be mapped to the classic problem of finding a set of random numbers that add up to a certain sum, with constraints.
It is easier to reduce the constrained sum problem to one with no constraints. This can be done as:
s0 B s1 t1 B s2 t2 B s3
Where t1 and t2 are chosen from X just enough to satisfy constraints on B, and s0 + s1 + s2 + s3 equal to number of vectors in X not in t.
Implementation
Implementing the same in MATLAB could benefit from using cell arrays, and this algorithm for the random numbers of constant sum.
You would also need to maintain separate pools for each category, and keep building blocks and piece them together.
Really, this is not trivial but also not impossible. This is the approach you could try, if you want to step aside from brute-force search like you have tried before.
SAT BASED MOTION PLANNING ALGORITHM
A simple motion planning problem can be remodelled as a SAT solving problem. Can anyone explain how is this possible?
In this problem, we have to find a collision free path from start to end location.
The simplest example could look like this.
Let's introduce 2D grid of N rows and M columns, a moving agent A starts at a node (x,y). His target T has coordinates (x_i, y_j):
To reach a target the agent should perform several steps - move left, right, up or down consequently. We don't know how many steps it needs, so we have to limit this number ourselves. Let's say, we are searching for a plan that consists of K steps. In this case, we should add N*M*K boolean variables: N and M represent coordinates, K - time. If a variable is True then the agent currently at a node (x,y) at time k.
Next, we add various constraints:
The agent must change his position at each step (this is optional, actually)
If robot at step k is at a position (x,y), then at step k+1 it must be at one of four adjacent nodes
SAT formula is satisfied if and only if the agent at step k is at the target node
I'll not discuss a detailed implementation of the constraints here, it's not that difficult. The similar approach could be used for multiagent planning.
This example is just an illustration. People use satplan and STRIPS in real life.
EDIT1
In the case of a collision-free path you should add additional constraints:
If a node contains an obstacle, an agent can't visit it. E.g. corresponding boolean variables can't be True at any timestep e.g. it's always False
If we are talking about a multiagent system, then two boolean variables, corresponding to two agents being at same timestep at the same node, can't be True simultaneously:
AND (agent1_x_y_t, agent2_x_y_t) <=> False
EDIT2
How to build a formula that would be satisfied. Iterate over all nodes and all timestamps, e.g. over each Boolean variable. For each Boolean variable add constraints (I'll use Python-like pseudocode):
formula = []
for x in range(N):
for y in range(M):
for t in range (K):
current_var = all_vars[x][y][t]
# obstacle
if obstacle:
formula = AND (formula, NOT (current_var))
# an agent should change his location each step
prev_step = get_prev_step (x,y,t)
change = NOT (AND (current_var, prev_step))
formula = AND (formula, change)
adjacent_nodes = get_adj (x,y, k+1)
constr = AND (current_var, only_one_is_true (adjacent_nodes))
formula = AND (formula, constr)
satisfy (formula)
Is there a way to use Bing Maps Driving REST Service the same way we use Google Distance Matrix?
I want to be able to calculate the distance:
p1 -> p2
p1 -> p3
p1 -> p4
...
p1 -> p15
With Google Distance Matrix I am able to get the distance for the 15 routes with one request, but using Bing I don't find a way to do it (only with 15 requests for each distance calculation).
Bing Maps does not expose a distance Matrix API, however it is possible to generate the required data using the Bing Maps Routing Service. You could make a request for each distance but this would be slow and generate a lot of transactions. The Bing Maps Routing Service allows you to pass in up to 25 waypoints into a single request. As such you can use this to do a batch calculation. For example, lets say we have 3 locations. A matrix would be 3x3 = 9 cells, 3 of these would have a value of 0 (i.e. A -> A). This leaves 6 cells that need calculations. To further optimize would could assume the distance between two locations is the same regardless of the direction of travel (i.e. A -> B = B -> A). If we make this assumption we only need to calculate the values for 3 cells; A-> B, A-> C, B-> C. To further optimize the route calculation we could align the waypoints such that we minimize the number of extra calculations done; A -> B, B -> C, C -> A. By doing this we can then calculate a route from A -> B -> C -> A. This would be a route with only 4 waypoints. The route response will then contain an array of route legs, each having a defined distance and time value which you can use to generate your matrix.
In your case you are only calculating from one location to 15 others. This is a 2 x 15 matrix and a bit similar than the above method to accomplish. In this case you can calculate a multi-waypoint route back and forth from the start point and each waypoint. Lets say the start is S and the other points are A, B, C, we could calculate a route from S -> A -> S -> B -> S -> C. This response for the route would have an array of route legs. The odd indexed route legs in the array would have your distance/times from S -> (A,B,C). Using this method you could calculate the data you need from S to 11 other locations. If you have 15 locations you would need to make two route requests. Note that if you are doing this while displaying an interactive map you can generate a session key from the map and use that in the request o make the route calls non-billable.
I'm assuming you want to do this so that you can calculate an optimized route using a traveling salesmen algorithm. If this is the case you might find this code sample interesting: https://code.msdn.microsoft.com/windowsapps/Bing-Maps-trip-optimizer-c4e037f7
I want to compare two routes to check if they are same or not in my iPhone app.
There is a person X who wants to go to point A to point B and another person wants to go to point A1 to point B1.
I can get a route between A to B using this direction APIs of google.
http://maps.googleapis.com/maps/api/directions/xml?origin=Point a A address&destination=Point B address&sensor=false
same way I can get route of A1 to B1.
but the latitude and longitude I am getting in xmls are not matching (even a single point is not matching). So here is my question how can I match two routes I want to know is this same route or not.
If the optimal route A1B1 is actually a subset of the route AB I'd expect the start_location and end_locations for the matching steps to share similar longitudes and latitudes, but this isn't a requirement of the directions API. The best path from A to B might pass through A1 and B1, but that doesn't mean the best path from A1 to B1 will share the exact same steps.
What I think you want to do is look at the polyline points returned for the route segments and see if they would pass through A1 and B1 in the correct order. You can expand the encoded polyline strings into a list of latitude and longitudes using this algorithm.