                         KNAPSACK ALGORITHMS

The programs in this directory solve the 0/1 Knapsack Program.

DYNPRO is a dynamic programming, wavefront, version.  The BB* programs are
Branch and Bound versions, using an M-strucuture for the Global Lower
Bound. BBREC is a recursive solution, BBITI is an iterative solution using
I-structures for the task queues, BBITM is an iterative solution, which
takes out, at a certain level in the search tree, tasks with the same
capacity but lower profit, as in Dynpro. Kid.c (k) generates knapsack
problems in Id, bbiti.c and bbitm.c mimic bbiti.id and bbitm.id,
respectively.

                         KNAPSACK ALGORITHMS
                         ===================

We us three test problems :                  # I N S T R U C T I O N S
                                                [ #nodes visited ]
                                                 ( #instr/node )
 

                                          DYN PRO   BBREC   BBISTR  BBMSTR
Problem 1: size 10:                        13,837  27,640   26,489  25,538
% Problem Def                              [270]     [42]    [48]    [36]
n = 10; cap = 27;                           (51)    (658)    (551)   (709)
P = {1d_array (1,10) of 
35 25 24 30 41 25 33 37 40 25 };
W = {1d_array (1,10) of 
13 10 10 13 18 11 15 17 19 12 };
% end of Problem Def

                                          DYN PRO   BBREC   BBISTR  BBMSTR
                                                [ #nodes visited ]
                                                 ( #instr/node )

Problem 2: size 14:                       197,477 290,967  225,247 105,981
% Problem Def                              [4200]   [467]    [467]   [135]
n = 14; cap = 300;                           (47)   (623)    (482)   (785)
P = {1d_array (1,14) of 
83 83 73 73 89 72 72  78 78 73 81 85 88 73 };
W = {1d_array (1,14) of 
111 111 102 102 126 102 102 111 111 105 117 123 129 108 };
% end of Problem Def

                                          DYN PRO   BBREC   BBISTR  BBMSTR
                                                 ( #instr/node )
Problem 3: size 18:                         852K  445,952    421K  214,525
% Problem Def                             [18000]   [544]   [574]    [210]
n = 18; cap = 1000;                          (47)   (819)   (733)   (1021)
P = {1d_array (1,18) of 
83 83 73 73 89 72 72  78 78 73 81 85 88 73 65 60 55 50 };
W = {1d_array (1,18) of 
111 111 102 102 126 102 102 111 111 105 117 123 129 108 100 95 90 85 };
% end of Problem Def

DYNAMIC PROGRAMMING
===================

Version dp.id
Problem 1: size 10:
Id> kdp 10
Check...Setup...Run...Done!

_E2 = 270, 65

Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |   13,837    28.17%  
Second-Phase   |        5     0.01%  
Idles          |   35,274    71.82%  
-------------------------------------
Total          |   49,116  
Critical Path  |   49,116  

Problem 2: size 14:
Id> kdp 14
Check...Setup...Run...Done!

_E1 = 4200, 177
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |  197,477    27.37%  
Second-Phase   |        5     0.00%  
Idles          |  523,950    72.63%  
-------------------------------------
Total          |  721,432  
Critical Path  |  721,432  
Id> 

Problem 3: size 18:
Id> kdp 18
Check...Setup...Run...Done!

_E5 = 18000, 714
Id> @display-count
 (x 1000)      
Type           |  Count    Percent   
-------------------------------------
Instructions   |      852    27.31%  
Second-Phase   |        0     0.00%  
Idles          |    2,268    72.69%  
-------------------------------------
Total          |    3,121  
Critical Path  |    3,121  
Id> 


===================

We run three B&B codes: recursive, iterative, iterative with sieve

RECURSIVE
=========

Version bbrec: Recursive, relying on gready, breadth first evaluation of 
function calls

Problem 1: size 10:

Id> kbb 10
Check...Setup...Run...Done!

_E42 = 65, 65, 42
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |   27,640    86.67%  
Second-Phase   |      140     0.44%  
Idles          |    4,112    12.89%  
-------------------------------------
Total          |   31,892  
Critical Path  |   31,892  


Problem 2: size 14:

Id> kbb 14
Check...Setup...Run...Done!

_E1 = 177, 177, 467
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |  290,967    96.19%  
Second-Phase   |    2,385     0.79%  
Idles          |    9,133     3.02%  
-------------------------------------
Total          |  302,485  
Critical Path  |  302,485  
Id> 

Problem 3: size 18:
Id> kbb 18
Check...Setup...Run...Done!

_E4 = 714, 714, 544
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |  445,952    96.47%  
Second-Phase   |    2,317     0.50%  
Idles          |   13,986     3.03%  
-------------------------------------
Total          |  462,255  
Critical Path  |  462,255  
Id> 

=========================================================================
ITERATIVE I
===========

Version bbiti


Problem 1: size 10:

Id> kbb 10
Check...Setup...Run...Done!

_E44 = {1D_I_array (1,8) of 3 1 4 4 _ _ _ _},
       {1D_I_array (1,8) of 60 65 59 60 _ _ _ _},
       65,
       48
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |   26,489    43.59%  
Second-Phase   |      102     0.17%  
Idles          |   34,174    56.24%  
-------------------------------------
Total          |   60,765  
Critical Path  |   60,765  

Problem 2: size 14:

Id> kbb 14
Check...Setup...Run...Done!

_E2 = {1D_I_array (1,180) of ... },
      {1D_I_array (1,180) of ... },
      177,
      467
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |  225,247    43.81%  
Second-Phase   |      940     0.18%  
Idles          |  287,919    56.00%  
-------------------------------------
Total          |  514,106  
Critical Path  |  514,106  
Id> 


Problem 3: size 18:
Id> kbb 18
Check...Setup...Run...Done!

_E3 = {1D_I_array (1,14) of 1 7 1 7 _ _ _ _ _ _ _ _ _ _},
      {1D_I_array (1,14) of 714 710 714 710 _ _ _ _ _ _ _ _ _ _},
      714,
      574
Id> @display-count
 (x 1000)      
Type           |  Count    Percent   
-------------------------------------
Instructions   |      421    41.99%  
Second-Phase   |        1     0.12%  
Idles          |      580    57.89%  
-------------------------------------
Total          |    1,001  
Critical Path  |    1,001  
Id> 
=========================================================================
ITERATIVE M
===========

Version bbitm: Iterative, deleting doubles
This requires that the task queues (Caps and Profs) are M structures

Problem 1: size 10:
Id> kbb 10
Check...Setup...Run...Done!

_E40 = {1D_M_array (1,6) of 3 4 1 _ _ _},
       {1D_M_array (1,6) of 60 60 65 _ _ _},
       65,
       36
Id>  @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |   25,538    39.33%  
Second-Phase   |      272     0.42%  
Idles          |   39,125    60.25%  
-------------------------------------
Total          |   64,935  
Critical Path  |   64,935  


Problem 2: size 14:
Id> kbb 14
Check...Setup...Run...Done!

_E2 = {1D_M_array (1,46) of ... },
      {1D_M_array (1,46) of ... },
      177,
      135
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |  105,981    33.21%  
Second-Phase   |    1,903     0.60%  
Idles          |  211,238    66.19%  
-------------------------------------
Total          |  319,122  
Critical Path  |  319,122  
Id> 


Problem 3: size 18:

Id> kbb 18
Check...Setup...Run...Done!

_E4 = {1D_M_array (1,8) of 1 7 _ _ _ _ _ _},
      {1D_M_array (1,8) of 714 710 _ _ _ _ _ _},
      714,
      210
Id> @display-count
Type           |  Count    Percent   
-------------------------------------
Instructions   |  214,525    33.92%  
Second-Phase   |    3,139     0.50%  
Idles          |  414,845    65.59%  
-------------------------------------
Total          |  632,509  
Critical Path  |  632,509  
Id> 
