home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math
- Path: sparky!uunet!caen!takriti
- From: takriti@engin.umich.edu (samer Takriti)
- Subject: Re: Combinatorial Problem
- Message-ID: <Skj-ga#@engin.umich.edu>
- Date: Thu, 27 Aug 92 16:16:53 EDT
- Organization: University of Michigan Engineering, Ann Arbor
- References: <1992Aug27.135518.8048@rhrk.uni-kl.de>
- Followup-To: I have a Problem, which I think is very easy
- Keywords: combinatorics
- Nntp-Posting-Host: maize.engin.umich.edu
- Lines: 30
-
- I will restate your problem first:
- Find the integers x(i), i=1, ..., m
- such that
- x(1) + x(2) + ... + x(m) = K
- l(i) <= x(i) <= u(i), i=1, ..., m
-
- I don't think that you can compute the exact number of feasible
- solutions. You may obtain some bounds on the number of possible
- solutions though.
- If you need to exhaust all the solutions you may want to do the
- following:
- Create m for loops as follows:
- for (x(1)=l(1); x(1)<=K && x(1)<=u(1); x(1)++)
- for (x(2)=l(2); x(2)<=K-x(1) && x(2)<=u(2); x(2)++)
- for (x(3)=l(3); x(3)<=K-x(1)-x(2) && x(3)<=u(3); x(3)++)
- ..........
- for (x(m-1)=l(m-1); x(m-1)<=K-x(1)-x(2)-...-x(m-2) && x(m-1)<=u(m-1); x(m-1)++)
- {
- x(m) = K - x(1) - x(2) - x(3) - ... - x(m-1)
- if x(m) <= u(m)
- printf ("%....", x(1), x(2), ..., x(m))
- }
- As you see, the previous code or algorithm gives an upper bound
- on the number of the possible solutions.
- If you want to implement this algorithm on a computer, there is
- no need for m-1 loops. You can use recursion.
-
- If you are interested in one solution only, you can use integer
- programming to do so.
- -Samer
-