31.05.2013 Views

think-cell technical report TC2003/01 A GUI-based Interaction ...

think-cell technical report TC2003/01 A GUI-based Interaction ...

think-cell technical report TC2003/01 A GUI-based Interaction ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.2 An Application of Dynamic Programming IMPLEMENTATION<br />

I suggest that to a large degree it is possible to foresee the user’s intention and<br />

place the pasted shapes where they are meant to be. Some key indicators that can<br />

help to understand the user’s intention are:<br />

• Spatial proximity of edges<br />

• Similarity of shapes in terms of type and formatting<br />

• Patterns that indicate a common case, such as a table row being inserted<br />

These hints can be encoded in a cost function that – given the environment of<br />

the source shapes and that of the destination slide – calculates the costs of some<br />

source gridline being placed before, on, or after some destination gridline. When<br />

every aspect perfectly fits, the costs will be zero; the more counter indication is<br />

detected for the placement in question, the bigger the costs will be. Given such a<br />

local cost function, the gridline matching problem can be seen as an optimization<br />

problem. The optimal solution is a list of source, dest and identify instructions<br />

that describes the order in which gridlines must be taken to create a matching with<br />

minimal cumulated costs.<br />

I do not present a detailed cost function here. It is plausible that a polynomial-<br />

time cost function is feasible; however, a lot of testing and fine-tuning will be<br />

required to achieve reasonable results. For the current implementation I chose a<br />

trivial cost function that takes the relative distance between a source gridline and a<br />

destination gridline as a measure for the cost, and defines the cost for “very close”<br />

to be zero. This algorithm implements a simple snapping behavior, but a much<br />

more sophisticated matching is desirable for a future version of the software.<br />

5.2.2 A Recursive Algorithm with Exponential Running Time<br />

The graph in figure 42 illustrates the interpretation of the gridline matching problem<br />

as a shortest path problem. A straight forward algorithm to find an optimal solution<br />

to this problem is presented in figure 43. The recursive MergeGridlines() function<br />

takes as input two lists of gridlines and returns the minimal costs along with the<br />

optimal path. The algorithm effectively does a complete enumeration of all possible<br />

paths from source s to target t. Assuming that the number of source gridlines n<br />

and the number of destination gridlines m are of the same order, this leads to an<br />

exponential asymptotic running time of Θ(3 n ): The algorithm does not have any<br />

loops and therefore only the recursive function calls contribute to the asymptotic<br />

running time. There are three recursive calls altogether, and for about half of all<br />

nodes in the shortest-path-graph, all three calls are carried out. I further assume<br />

that the cost function has some polynomial running time characteristics.<br />

The cost function in the recursive algorithm is called CostNext(). This is, be-<br />

cause given a certain state of the calculation, this function calculates the costs for<br />

making a source, dest or identify decision for the next gridlines (i. e., the heads<br />

of the listSource and listDest parameters).<br />

77

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!