I am trying to solve this problem and unable to come up with a robust solution. Any idea, pseudo-code or a python implementation would be greatly appreciated. For sake of simplicity, consider a small matrix like in Figure 1. The rows in the matrix represent days and the columns represent minutes. We can assume that a bus travels between two points that takes 10 minutes and stops at a particular cell defined by a letter in that cell at each minute. Given the historical pattern (day 1 thru 5), we want to find the best sequence of letters. To do that we need to follow certain rules:
We are not looking for the shortest distance (most straight line, etc.)
Here are a couple examples: The sequence in Figure 1 satisfies all these rules. The highlighted sequence is just for visualization purpose. There are other ways of visualizing this sequence in Figure 1.
The sequence in Figure 2 is discontinuous. Hence the most frequent letters can't be stitched together. For that reason, we select the second most frequent letter in minute 3, one of the C, A, D instead of B. With that we can satisfy the rules. However, keep in mind, when 365 days used along with 100+ minutes, it gets complex. For instance, using the second most frequent letter may have resulted in rewiring the rest of the sequence.
Any guidance is highly appreciated.
This sounds like a relative straightforward dynamic programming task.
sum([0 if cell.most_frequent else 1 for cell in cells])
You might have to tweak the target function eg the last most frequent and the second most frequent letter are treated the same. Maybe you want to give a score based on how frequent they are.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.