Among the four stations shown, which of stations C , D should be closer to A, and why? - wireless

The figure below shows an example of the operation of the 802.11 MAC
sublayer protocol for wireless LANs. Among the four stations shown,
which of stations C , D should be closer to A, and why?
http://www.4shared.com/download/Z5pAEx_d/pics.jpg?tsid=20130328-034821-6bef16d4
My anwer: I believe that station D need to be closer to A, becuase the NAV of station D occur after the CTS. Is this correct?

I would say that C is closer. Assuming that the NAV in the picture relates to setting of NAV for the relevant station, it can be seen that for station C the NAV is set upon RTS transmission (A -> B) and for station D only upon CTS (B -> A) transmission. This implies that D didn't receive the RTS since it's too far away from A. It did receive the CTS because it's close enough to B in order to hear its transmissions.

D is not in the transmission range of A, this is why it's NAV is not updated by A's RTS.
C is in the transmission range of A, this is why it's NAV in updated by A's RTS.
So, simply C is closer to A than D.
Furthermore, D is in the transmission range of B (D's NAV is updated by B's CTS).

Related

Efficient Product of 3 Sparse Matrices that creates a dense intermediate

I have 3 matrices that are all sparse, A, B, and C.
I need to take the matrix product of AB, which results in a dense matrix.
After that, I need the element wise product of AB (element wise *) C.
C is sparse, and therefore the element wise multiplication will zero out most of the dense product AB, resulting in a sparse matrix again.
Knowing that, I am trying to figure out a strategy for not materializing all of the dense components of AB.
If C_{i,J} is 0, then I should not materialize AB_{i, j}. This means I can skip the dot product of A_{row i} and B_{col j}. But it seems very inefficient to write a for loop over rows of A to pick out the rows I want to materialize.
Could there be another way to intelligently do this multiplication?
Here is an example data generator in R, although the real product AB that I have is more dense than this generator. FWIW help from any programming language would be useful, not necessarily R. (Eigen would be great though!)
require(Matrix)
n = 10000
p = 100
A = rsparsematrix(n, p, .1)
B = rsparsematrix(p, p, .1)
C = rsparsematrix(n, p, .1)
This is pretty closely related to triangle counting. If A, B, and C were all binary matrices, then you could interpret them as the adjacency matrices for a tripartite graph and count for each edge in C how many triangles it belongs to.
Perhaps there's a triangle-counting community detection in R that could be adapted to your use case.
Underneath such a library is likely the following trick (that I should have a cite for, but don't offhand). It involves sorting the nodes of the graph by degree and directing all of the outgoing edges from low-degree to high. Then for each node, you test each pair of outgoing edges (wedge) for the edge that would complete it.

Maze Solving From All Start Points

Recently I came across a problem that stated;
Assume a maze having characters *,.,C .* represents walls and ./C are allowed. There is only one point which is marked C. Now given a bot stands on any of the allowed points, there exists a series of commands (for example LDDRU or LLLRRDU,etc.) such that if the bot starts from any allowed point, it passes through C at least once.
Eg:
******
*.C..*
**.***
*....*
******
Command: RLLURUU
Now I know how to solve a maze using DFS/BFS(for shortest path). But can anyone provide a hint on how I shall proceed problems like this?
EDIT: if the next move is into walls / outside maze, it is ignored. And as usual L IS LEFT R IS RIGHT U IS UP D IS DOWN.
This problem is related to the concept of synchronizing words or reset sequences for finite automata. You can imagine building an automaton where
each open space, plus C, is a state;
each state other than C transitions to itself for every move that hits a wall;
each state other than C transitions to a neighboring open state in the indicated direction if there's an open spot in that direction; and
the C state transitions to itself on all moves.
Given this automaton, you're now looking for a sequence that takes every state to the C state, hence the connection to synchronizing words. There are a number of algorithms for finding synchronizing words, and any of them could be adapted to solve this particular problem. One option would be to build the power automaton from the original automaton and to look for a path from the start state to the C state, which (I believe) ends up being a theoretically optimal version of the comment talking about collapsing virtual robots together (in that it will always find the optimal path.)

The Classic Farmer,Wolf,Goat,Cabbage Production System Construction

Im trying to learn the producttion system for the FWGC Artificial Intelligence problem.More details https://www.cs.unm.edu/~luger/ai-final2/CH4_Depth-.%20Breadth-,%20and%20Best-first%20Search.pdf
I have a problem in understanding how the graph is constructed.I understand upto this figure and how the state is represented based on the location.
How is this graph constructed? Can someone explain?
According to the document, describing the diagram:
The "graph" is a state transition diagram showing you what possible states you can go to from any other given state, starting at state(w,w,w,w) as the initial state. How a transition is determined is by considering the logic of the described problem. Such a graph could be automatically generated in Prolog if you have all the correct Prolog rules set up for the problem, or it could be generated manually as an aid to figure out how you wish to write the rules. The document doesn't say exactly how they generated it, but they only say that it's a partial description of the possible state transitions, and without regard to whether any given state is "safe", which means that the diagram contains some states which you would want your Prolog solution to rule out. Given it's place in the document and the context, I believe it's manually generated as an aid to coming up with a reasonable data representation and design for the Prolog program.
To take an example, the initial state is that all 4 things (farmer, wolf, goat, cabbage) are on the West bank. That's state state(w,w,w,w) representing location of F,W,G,C, respectively. The possible states that a single move can take you from there are, since the farmer can only take at most one item at a time across the river:
West East State
---- ---- -----
G, C F, W state(e, e, w, w)
W, C F, G state(e, w, e, w)
W, G F, C state(e, w, w, e)
W, G, C F state(e, w, w, w)
This is figured out by thinking about the rules and the possible choices. In each of the above new states, the farmer either took one item across the river, or went across themselves with nothing else. That's 4 possible moves. The arrows in the diagram indicate which states you can transition to. So the diagram indicates that the state transitions are reflexive (that is, if you go from state A to state B, you can also go from B to A).
As another example, when at state(e, e, w, w):
West East State
---- ---- -----
G, C F, W state(e, e, w, w)
From here, there are only two possible moves: the farmer takes the wolf back across the river (goes back to state(w, w, w, w), or the farmer goes back across the river on their own, which would be state(w, e, w, w) and is what's shown in the state transition diagram.

Using graph to translate differing representations

I have a data translation problem, and would like guidance on how I can crack it:
I have an inbound list of items that represent train cars assigned to segments along a journey. Each item has an index, a car reference, an origin and a destination.
E.g.
Index Car Origin Destination
1 C1 L1 L2
2 C2 L1 L2
3 C3 L1 L2
4 C1 L2 L3
5 C2 L2 L3
6 C4 L2 L3
The example above show four cars (C1, C2, C3, C4). Cars C1-C2 travels from L1 to L3. C3 travels from L1 to L2. C4 travels from L2 to L3. The index maintains the order of the cars within each 'leg', but it is relative: For the second leg (L2-L3), the first index in use is 4.
I need to translate this into a different model that provides a distinct list of cars, while maintaining the order of the cars within the train.
E.g.
Index Car Origin Destination
1 C1 L1 L3
2 C2 L1 L3
3 C3 L1 L2
4 C4 L2 L3
The second model doesn't allow for a complete re-ordering of the train cars mid journey. I.e. I can't allow cars A, B, C, D to change order to A, C, B, D. I would have to apply some heuristic to obtain the resulting car order, and it would not reflect reality. I'm happy to accept this drawback.
Also, although the target model index specifies car order within the train, it doesn't matter whether I index from the front or the back of the train. It would be nice to use lower indeces for car assignments earlier in the Journey.
So, for the solution: I think I need to employ graphs to make this translation but I'm unsure where to start. I think I should be modeling a car as a vertex, and a coupling of a two cars in the same leg as an edge. But I'm not sure where I go from there.
I'd be very grateful for any pointers on how to approach the problem: Modelling tips, merging algorithms...
Edit
One more complication: On some legs the order of cars in a train may completely reverse. This is used to indicate the train changed direction. I don't need to capture that reversal, but I do need to retain the inter-connected order of the cars.
In essence, and leaving aside the question of reversed segments, this problem reduces to a topological sort for which a number of simple and efficient algorithms exist (see the Wikipedia link for examples). To construct the graph, we use the cars as vertices and insert an edge from Ci to Cj if Ci immediately precedes Cj in some leg. (This minimizes the number of edges, which reduces the cost of an O(V+E) topological sort.)
But that won't work with "reversed" legs; these will cause the topological sort to fail. So the other part of the problem is to detect reversed legs. Here I'm assuming that there is no definite list of reversed legs; if there were, the solution would be obvious.
I think the following will work reasonably efficiently, but it may well not be optimal.
Let's say that two legs are forward compatible if they share at least two cars and the order of the shared cars is identical in the two legs. Similarly, two legs are reverse compatible if they share at least two cars and the order of the shared cars in one is the exact reverse of the order of the shared cars in the other. Finally, two legs are bidirectionally compatible if they share at most one car. (It's possible that two legs don't fit into any of these three categories, in which case they are incompatible and the problem has no solution.)
It's easy to categorize the relationship between two legs. With the right datastructure (a hashtable, for example) finding the list of shared cars between two legs is O(min(m,n)) where m and n are the sizes of the legs (in number of cars), as is checking if the shared cars appear in the same or reversed order in the two lists. So constructing the entire array of relationships between all possible pairs of legs should be O(L·N) where L is the number of legs and N the number of cars. (I don't have a proof of this assertion, so it could be wrong. But it seems reasonable.)
With the graph of compatibilities, we need to assign a direction to each leg. We do this using a traverse of the graph, using the following recursive procedures:
# Direction is either Forward or Reverse. We assume a function reverse(D) which
# returns Reverse if D is Forward, and Forward if D is Reverse
setDirection(Leg, Direction):
+ If the Direction of Leg is Direction, return.
+ If the Direction of Leg is set and not the same as Direction, fail.
+ Otherwise:
+ Set the Direction of Leg to Direction.
+ For each L such that Leg is forward compatible with L:
+ Call SetDirection(L, Direction)
+ For each L such that Leg is reverse compatible with L:
+ Call SetDirection(L, reverse(Direction))
setAllDirections():
+ while some Leg L does not have its direction set:
+ SetDirection(L, Forward)
Now, we can reverse the order of the cars in the legs which are marked as reversed, and apply the topological sort.
Note that it is possible for the above procedure to a consistent set of leg directions which does not correspond to "reality", because the decision to set the initial direction of a new Leg in the last line is totally arbitrary. But I think it is the best that we can do.

General Design Question

I have a general design question:
There is a junction, with four roads connecting to it. Each road has 2 lanes.
What would be the best way to design a program to handle such junction. It should allow 2 cars 2 go through the junction if they don't interfere each other. and 1 car came in before the other, and they both should use the same part of the junction, the 1st car should get priority. Also, 2 cars may arrive the junction at the exact same time.
What would be the best design for this problem? what exactly should you lock, in order to allow best use of the junction?
Thanks!
Each car should lock parts of the lane it's going to pass trough. If one of the parts is locked then car should wait until it will be released.
What do you think about having 4 different queues for each part of the junction. each car that comes in enters the relevant queue (should enter to more than one queue?), and only after the car leaves all queue it can go through the junction..
Still not sure what is the best implementation for it though.
Create a circle buffer with two entries for each road (one for inbound, one for outbound) meeting at the intersection.
For each car that you have to route put it's name into the circle buffer for its source (inbound) and its destination (outbound). Then iterate through the circle buffer, if you get two instances of the same car together then that car may travel. After that pick at random from the other cars.
I have a feeling that's pretty unclear so consider an intersection with 4 roads that we'll call N, E, S and W. To that we'll have 3 cars, A coming from the East turning South, B from the South travelling North and C from the West travelling East.
Circle buffer can be built as such (i=inbound, o=outbound:
Ni No Ei Eo Si So Wi Wo
B - C A A B - C
As we iterate through from left to right we realise that the two A's are adjacent so they can go but the B's and C's are not adjacent so these cars are block each other. Pick one at random for this light cycle and let the other go in the next light cycle. So either A and B can go or A and C can go.
Note1: testing adjacent ignores blanks so in the case of
Ni No Ei Eo Si So Wi Wo
D E - - E D - -
which models a car travelling North and another travelling South both E's and D's are adjacent.
Note2: I've mapped this out for driving on the left because that's what I do. You'll have to mirror it for driving on the right.
Note3: You can't overwrite a position in the buffer, if two cars want the same destination they're automatically blocking and you should just leave the first one in there and consider the other one next time.

Resources