Goal Optimizations


The user can explicitly turn any combination of these procedures on or off in achieving a certain goal.

Explicitly picking one procedure to do the sorting:

  
	   > L1 satisfy sort using quick-sort.

Explicitly picking more than one procedure to do the sorting:

  
	   > L1 satisfy sort using quick-sort broken-sort.	   

More realistically, we like to dynamically decide the mixture of procedures to use to accomplish the task at hand. JOHN allows optimization definitions for goal to achieve this.

The sort optimization control:

 
	   goal-optimization AList sort use swap-items if its items almost-sorted = yes.
	   goal-optimization AList sort use pop-min if its items almost-sorted = no.

Sample Run 1: for list L1 the optimizations choose "swap-items" procedure

	   > make AList L1 [ 3, 1, 4, 5 ] [].
	   ok.
	   > L1 satisfy sort by L1. 
	   looking 1 time unit ahead (1 possible worlds)
	   satisfied at time: 1
	   satisfied by: [ L1 swap-items  ]

Sample Run 2: for list L2 the optimizations choose 4 iteration of "pop-min" procedure as the best way to sort
	   > make AList L2 [ 4, 3, 5, 1 ] [].
	   > L2 satisfy sort by L2. 
	   looking 1 time unit ahead (1 possible worlds)
	   looking 2 time unit ahead (1 possible worlds)
	   looking 3 time unit ahead (1 possible worlds)
	   looking 4 time unit ahead (1 possible worlds)
	   satisfied at time: 4
	   satisfied by: [ L2 pop-min , L2 pop-min , L2 pop-min , L2 pop-min  ] 

It is also possible for optimizations to choose a mixture of procedures, as long as those procedures can be used collaboratively to get to a goal state. In the example below, we are trying to get the first 10 numbers in the Fibonacci sequence.

We like to use the nice mathematical formula Fib(n) = Fib(n-1) + Fib(n-2) , for all n > 1 as long as the numbers are small, but this is a rather expensive calculation and after a while (say after n>5) we like to use the iterative method to get the next fib number in the sequence, by simply adding the last two items in the sequence to get the next Fibonacci number. We call the two procedures slow-fib and fast-fib.

Optimizations, assuming "fib-sequence" goal for class "Calc" already defined:

 
   	   goal-optimization Calculator fibonacci-sequence use fast-fib if its answer size > 5.
   	   goal-optimization Calculator fibonacci-sequence use slow-fib if its answer size <= 5.

Sample Run: The object has used the slow-fib for the first 4 fib numbers, and then fast-fib for the rest

	   > Calc answer.
	   [ 1, 1 ]
	   > Calc satisfy fibonacci-sequence 10.
	   satisfied at time: 9
	   satisfied by: [ Calc slow-fib , Calc slow-fib , Calc slow-fib , Calc slow-fib , Calc fast-fib , Calc fast-fib , Calc fast-fib , Calc fast-fib , Calc fast-fib  ]
	   > Calc answer.
	   [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ]

 
Page last modified on September 22, 2008, at 07:45 PM

simplaPoweredBy

 

Warning: fopen(wiki.d/.flock) [function.fopen]: failed to open stream: Permission denied in /home/hesam/public_html/pmwiki/pmwiki.php on line 417

PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.