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 ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
5.2 An Application of Dynamic Programming IMPLEMENTATION<br />
Algorithm: MergeGridlines (recursive shortest path)<br />
Input: listSource, listDest : List of Gridline<br />
Output: minimalCost : Accumulated cost for the optimal path<br />
optimalPath : A list of source, dest, identify that describes<br />
the optimal path<br />
Variables: costSource, costDest, costIdentify, minimalCost : Cost<br />
pathSource, pathDest, pathIdentify, optimalPath : List of Choice<br />
Begin<br />
costSource ← 0, costDest ← 0, costIdentify ← 0<br />
If Not IsEmpty(listSource) Then<br />
(costSource, pathSource) ← MergeGridlines(Tail(listSource), listDest)<br />
// Tail((a, b, c)) ↦→ (b, c)<br />
costSource ← costSource + CostNext(source, . . .)<br />
End If<br />
If Not IsEmpty(listDest) Then<br />
(costDest, pathDest) ← MergeGridlines(listSource, Tail(listDest))<br />
costDest ← costDest + CostNext(dest, . . .)<br />
End If<br />
If Not (IsEmpty(listSource) Or IsEmpty(listDest)) Then<br />
(costIdentify, pathIdentify) ← MergeGridlines(Tail(listSource), Tail(listDest))<br />
costIdentify ← costIdentify + CostNext(identify, . . .)<br />
End If<br />
If costDest < costSource Then<br />
If costDest < costIdentify Then<br />
minimalCost ← costDest<br />
optimalP ath ← dest.pathDest // a.(b, c) ↦→ (a, b, c)<br />
Else<br />
minimalCost ← costIdentify<br />
optimalP ath ← identify.pathIdentify<br />
End If<br />
Else<br />
If costSource < costIdentify Then<br />
minimalCost ← costSource<br />
optimalP ath ← source.pathSource<br />
Else<br />
minimalCost ← costIdentify<br />
optimalP ath ← identify.pathIdentify<br />
End If<br />
End If<br />
Return (minimalCost, optimalP ath)<br />
End<br />
Figure 43: An exponential-time recursive algorithm for gridline matching<br />
79