Algorithm for reducing a series of actions?

It was a little time since my class of algorithms was at school, so forgive me if my terminology is not accurate.

I have a series of actions that, at startup, create some kind of desired state (this is basically a set of steps for reproducing the error, but it does not matter for this question).

My goal is to find the shortest series of steps that still create the desired state. Any given step may be unnecessary, so I try to remove them as efficiently as possible.

I want to keep the order of the steps (so I can delete the steps, but not reorder them).

The naive approach that I take is to take the entire series and try to delete each action. If I successfully delete one action (without changing the final state), I will start from the beginning of the series. It should be O (n ^ 2) in the worst case.

I am starting to play in order to make it more efficient, but I am sure that this is a problem. Unfortunately, I don’t know for sure that for Google the series is not really a β€œpath”, so I cannot use path reduction algorithms. Any help β€” even just giving me some search terms β€” would be helpful.

Update: several people have indicated that even my naive algorithm will not find the shortest solution. This is a good point, so let me reconsider my question a bit: any ideas on approximate algorithms for the same problem? I would prefer a short solution that would be closer to the shortest quick solution than take a very long time to guarantee an absolute shortest series. Thanks!

+4
source share
5 answers

Your naive approach n ^ 2 is not entirely correct; in the worst case, you may have to look at all the subsets (well, actually, the more accurate thing is that this problem can be NP-hard, which does not mean that "you may have to look at all the subsets", but anyway...)

For example, suppose you are currently running steps 12345, and you are trying to delete each one individually. Then you may find that you cannot delete 1, you can delete 2 (so you delete it), then you look at 1345 and you will find that each of them is necessary - not one can be deleted. But it may turn out that in fact, if you hold 2, then "125" is enough.

If your family of sets that produce this result is not monotonous (i.e., if it does not have the property that if a certain set of actions is valid, then any supernet), then you can prove that there is no way to find the shortest sequence without view all subsets.

+4
source

If you do not arbitrarily make any assumptions about the impact of each action and want to find the smallest subset, then you will need to try all possible sub-elements of the action to find the shortest seuence.

The specified binary search method will be sufficient if only one step caused your desired state.

For a more general state, even deleting one action at a time will not necessarily give you the shortest sequence. This is so if you are considering pathological examples where actions may not create problems together, but individually trigger your desired state.

Your problem seems to be reducible to a more general search problem, and the more assumptions you can create, the less your search space will become.

+2
source

Delta Debugging , a method to minimize the set of errors that caused input, can be very good.
I previously used Delta (minimizes "interesting" files based on an interesting test) to reduce the file size by 1000 lines 10 lines, for reporting an error.

+2
source

The most obvious thing that comes to mind is a recursive separation based on binary search into halves, where you alternately leave each half. If you leave half at any stage of the recursion, still reproduces the final state, then leave it; otherwise return it and write down both halves of this half, etc.

A recursion in both halves means that it is trying to eliminate large pieces before surrendering and trying smaller pieces of these pieces. The run time will be O (n log (n)) in the worst case, but if you have a large n with a high probability of many irrelevant steps, it should defeat O (n) every step one at a time (but not restart).

This algorithm will find only minimal paths, although it cannot find smaller paths that may exist due to combinatorial interstep effects (if the steps really have this character). However, the discovery of all these factors will lead to a combinatorial explosion, unless you have additional information about the steps that can be substantiated (for example, dependencies).

+1
source

Your problem domain can be compared with a directed graph, where you have states as nodes and steps as links, you want to find the shortest path in the graph, for this there are a number of well-known algorithms, for example Dijkstra's or A *

Updated:

Let's think about a simple case, if you have one step that leads from state A to state B, this can be done as 2 nodes connected by a link. Now you have another step that leads from A to C and from C you take a step, which leads to B. At the same time, you have a graph with 3 nodes and 3 links, the cost of achieving B from A it eather 2 (ACB) or 1 (AB). Thus, you can see that the cost function is very simple, you add 1 for every step you take to achieve the goal.

0
source

All Articles