aidkvm.blogg.se

Dynamic programming prolog
Dynamic programming prolog





dynamic programming prolog

We didn't aim at a predicate that takes a Prolog closure term argument for the boolean condition, but instead only provide a predicate that enumerates the lazy list elements, and the user of the predicate can filter in the Prolog continuation. The last hurdle and second building block is to get a Haskell dropWhile in Prolog. So we readly arrive at a co-recursive predicate steps that does simulate all possible paths of the elevator: ?- take(5, steps(7,]), L). If we are at a level k, the elevator can go to a level k+2 or k-3, only provided the elevator stays inside the building. In case of the evaluator problem we will have a path and thus node expansion that will not always lead to two successors. Here is an example run: ?- take(5, tree, L). In the full binary tree paths and thus nodes are always expanded twice: % tree(+Paths, -Path, -LazyPaths) This can be done by a simple list append predicate call, so that the missing definition reads as follows. To archive breadth first enumeration we will append the new expanded paths and thus nodes at the end of the agenda.

dynamic programming prolog

We can then start with an agenda that only contains the root: % tree(-Path, -LazyPaths) We adopt the idea that the Prolog closure term should carry an agenda with the paths and thus nodes that should be expanded. One building block is a way to enumerate a search tree co-recursively in Prolog. Writef ( "Tower of hanoi size % in %p \n", N, D ).In this co-recursive Prolog solution we need two building blocks. ProfileSolve ( N ) :- T1 = time :: now ( ), _ = hanoi ( N, a, b, c ), T2 = time :: now ( ), D = duration :: new ( T1, T2 ) , Writef ( " % -> % \n", Source, Destination ) , WriteSolution (compound ( First, Source, Destination, Last ) ) :. Compound (solution SourceToTemp, pole Source, pole Destination, solution TempToDestination ).







Dynamic programming prolog