Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default generate all subsets (2^n array)

Hi there,

I'm wondering if anyone here can point me in the right direction. I'm
working on an exhaustive search for 0-1 knapsack problem.

I need to write some vba that will represent every possible combination of
items in the knapsack.

for example, if there are 3 items in the knapsack, I need to store the value
(v) of the items stored. Of course the knapsack capacity varies. In the
following example n= 3, i.e. there are 3 items to store, and 2^3 = 8
combinations of items.

000 = v1
010 = v2
001 = v3
011 = v4
111 = v5
101 = v6
110 = v7
111 = v8

I need to do this in vba as I'm unfamiliar with C, C++ or Java.

thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default generate all subsets (2^n array)

Additionally, I've only been able to find solution in C language. One of
them uses bitfields (and bitwise operations) to generate array ( as
represented in previous thread). Can one create something similar to the
following C pseudo code in VBA ?

We just generate all bitfields. And what could be easier than to just use an
"int" variable, declare the lower N bits as our bitfield, and then count
from 0 to 2N-1 with that variable? Again, here's some outline:
for( int B=0; B<(1<<N); ++B ){
clearSubset();
for( int i=0; i<N; ++i )
if( (B & (1<<i)) 0 )
addToSubset( element(i) );
useBuiltSubset();
}

"Robert Reid" wrote in message
...
Hi there,

I'm wondering if anyone here can point me in the right direction. I'm
working on an exhaustive search for 0-1 knapsack problem.

I need to write some vba that will represent every possible combination of
items in the knapsack.

for example, if there are 3 items in the knapsack, I need to store the
value (v) of the items stored. Of course the knapsack capacity varies.
In the following example n= 3, i.e. there are 3 items to store, and 2^3 =
8 combinations of items.

000 = v1
010 = v2
001 = v3
011 = v4
111 = v5
101 = v6
110 = v7
111 = v8

I need to do this in vba as I'm unfamiliar with C, C++ or Java.

thanks in advance.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating subsets beejay Excel Discussion (Misc queries) 1 September 30th 08 12:30 PM
Manipulating subsets of large datasets Astrofin Excel Worksheet Functions 4 March 7th 07 05:11 PM
How to generate formula from two dimensional array of data KROATA Excel Worksheet Functions 1 December 2nd 05 12:39 PM
Getting subsets of data Roy Kirkland Excel Programming 1 November 30th 04 02:53 PM
how do I generate an array of correlated values vishs Excel Worksheet Functions 1 November 20th 04 12:24 AM


All times are GMT +1. The time now is 12:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"