Good afternoon,
I am hoping someone in the community may be able to help me out with my problem.
I am using Matlab to generate combinations with constraints, as follows:
I have a fixed value, let's say 156, that I want to distribute amongst 20 slots in packages of 4. For each problem, I define the following constraints:
- the possible slots (out of the 20) amongst which these 156 may be distributed;
- the minimum amount of load on each slot
- the maximum amount of load on each slot
The problem is that I tried to generate all possible alternatives, then eliminate those that do not comply with the constraints. However, I get the OUT OF MEMORY error, so I really have to find a more efficient way of doing this.
Appreciate any kind of help!
Thanks,
JCF
|
|
0
|
|
|
|
Reply
|
Jose
|
9/21/2010 4:33:33 PM |
|
"Jose " <zeca_ferrao@hotmail.com> wrote in message <i7amot$s7$1@fred.mathworks.com>...
> Good afternoon,
>
> I am hoping someone in the community may be able to help me out with my problem.
> I am using Matlab to generate combinations with constraints, as follows:
>
> I have a fixed value, let's say 156, that I want to distribute amongst 20 slots in packages of 4. For each problem, I define the following constraints:
> - the possible slots (out of the 20) amongst which these 156 may be distributed;
> - the minimum amount of load on each slot
> - the maximum amount of load on each slot
>
> The problem is that I tried to generate all possible alternatives, then eliminate those that do not comply with the constraints. However, I get the OUT OF MEMORY error, so I really have to find a more efficient way of doing this.
>
> Appreciate any kind of help!
>
> Thanks,
>
> JCF
The query isn't clear to me. What is a package? What is load?
Might help to show a few acceptable and unacceptable combinations
Ross
|
|
0
|
|
|
|
Reply
|
Ross
|
9/21/2010 8:36:07 PM
|
|
>
> The query isn't clear to me. What is a package? What is load?
>
> Might help to show a few acceptable and unacceptable combinations
>
> Ross
Ok, I'll try to explain it better.
I have 20 slots on which to distribute a given total load of 156 kg;
I have discretised my total load in packages of 4kg each;
I want to obtain all the possible combinations of package distributions amongst the 20 slots, subject to the following constraints:
- some of the slots cannot be used (they are identified by numbers)
- some of the slots have a minimum value of load
- some of the slots have a maximum value of load;
Ill give a rough example: imagine 5 slots on which I want to distribute 10 kg in packages of 2; some possible combinations without constraints) would be:
[2 2 2 2 2]
[4 0 2 2 2]
[4 0 0 4 2]
But, if I define that slot nr 2 cannot receive load, then the option [2 2 2 2 2] would not be considered.
On the other hand, if I define that slot 4 cannot handle more than 2 kg, then option [4 0 0 4 2] would also be discarded.
I think that the problem is not too complex, but the number of combinations that arise when working with 20 slots and more than 100 kg of load in small packages makes it impossible to calculate all the combinations and then eliminate the ones that do not comply with the constraints.
I was hoping that there'd be a way of calculating just the combinations that satisfy the constraints.
Thanks a lot for your help!
JCF
|
|
0
|
|
|
|
Reply
|
Jose
|
9/21/2010 10:37:03 PM
|
|
"Jose " <zeca_ferrao@hotmail.com> wrote in message <i7bc2f$qer$1@fred.mathworks.com>...
>
> >
> > The query isn't clear to me. What is a package? What is load?
> >
> > Might help to show a few acceptable and unacceptable combinations
> >
> > Ross
>
> Ok, I'll try to explain it better.
>
> I have 20 slots on which to distribute a given total load of 156 kg;
> I have discretised my total load in packages of 4kg each;
> I want to obtain all the possible combinations of package distributions amongst the 20 slots, subject to the following constraints:
> - some of the slots cannot be used (they are identified by numbers)
> - some of the slots have a minimum value of load
> - some of the slots have a maximum value of load;
>
> Ill give a rough example: imagine 5 slots on which I want to distribute 10 kg in packages of 2; some possible combinations without constraints) would be:
> [2 2 2 2 2]
> [4 0 2 2 2]
> [4 0 0 4 2]
>
> But, if I define that slot nr 2 cannot receive load, then the option [2 2 2 2 2] would not be considered.
> On the other hand, if I define that slot 4 cannot handle more than 2 kg, then option [4 0 0 4 2] would also be discarded.
>
> I think that the problem is not too complex, but the number of combinations that arise when working with 20 slots and more than 100 kg of load in small packages makes it impossible to calculate all the combinations and then eliminate the ones that do not comply with the constraints.
>
> I was hoping that there'd be a way of calculating just the combinations that satisfy the constraints.
>
There are an infinite number of combinations that meet the constraints.
|
|
0
|
|
|
|
Reply
|
Sean
|
9/21/2010 10:56:19 PM
|
|
"Jose " <zeca_ferrao@hotmail.com> wrote in message <i7bc2f$qer$1@fred.mathworks.com>...
>
> >
> > The query isn't clear to me. What is a package? What is load?
> >
> > Might help to show a few acceptable and unacceptable combinations
> >
> > Ross
>
> Ok, I'll try to explain it better.
>
> I have 20 slots on which to distribute a given total load of 156 kg;
> I have discretised my total load in packages of 4kg each;
> I want to obtain all the possible combinations of package distributions amongst the 20 slots, subject to the following constraints:
> - some of the slots cannot be used (they are identified by numbers)
> - some of the slots have a minimum value of load
> - some of the slots have a maximum value of load;
>
> Ill give a rough example: imagine 5 slots on which I want to distribute 10 kg in packages of 2; some possible combinations without constraints) would be:
> [2 2 2 2 2]
> [4 0 2 2 2]
> [4 0 0 4 2]
>
> But, if I define that slot nr 2 cannot receive load, then the option [2 2 2 2 2] would not be considered.
> On the other hand, if I define that slot 4 cannot handle more than 2 kg, then option [4 0 0 4 2] would also be discarded.
>
> I think that the problem is not too complex, but the number of combinations that arise when working with 20 slots and more than 100 kg of load in small packages makes it impossible to calculate all the combinations and then eliminate the ones that do not comply with the constraints.
>
> I was hoping that there'd be a way of calculating just the combinations that satisfy the constraints.
>
You will quickly find that the number of combinations
is quite large. But it IS simply done recursively.
Look at the first slot. Assume that it can take any of
these loads.
0,2,4,6,8,10
Now, simply compute the possible combinations for the
other slots, given what remains to be distributed for
each of those possibilities. At some point, there is either
nothing left to be distributed, or more than the remaining
slots can carry. In either case, you are done with that
thread of the recursion.
Simple recursion.
John
|
|
0
|
|
|
|
Reply
|
John
|
9/21/2010 10:58:04 PM
|
|
>
> You will quickly find that the number of combinations
> is quite large. But it IS simply done recursively.
>
> Look at the first slot. Assume that it can take any of
> these loads.
>
> 0,2,4,6,8,10
>
> Now, simply compute the possible combinations for the
> other slots, given what remains to be distributed for
> each of those possibilities. At some point, there is either
> nothing left to be distributed, or more than the remaining
> slots can carry. In either case, you are done with that
> thread of the recursion.
>
> Simple recursion.
>
> John
Ok, I'll do it recursively, it should work.
Thanks a lot for your help, John.
JCF
|
|
0
|
|
|
|
Reply
|
Jose
|
9/21/2010 11:11:05 PM
|
|
"John D'Errico" <woodchips@rochester.rr.com> wrote in message <i7bd9s$eqv$1@fred.mathworks.com>...
> "Jose " <zeca_ferrao@hotmail.com> wrote in message <i7bc2f$qer$1@fred.mathworks.com>...
> >
> > >
> > > The query isn't clear to me. What is a package? What is load?
> > >
> > > Might help to show a few acceptable and unacceptable combinations
> > >
> > > Ross
> >
> > Ok, I'll try to explain it better.
> >
> > I have 20 slots on which to distribute a given total load of 156 kg;
> > I have discretised my total load in packages of 4kg each;
> > I want to obtain all the possible combinations of package distributions amongst the 20 slots, subject to the following constraints:
> > - some of the slots cannot be used (they are identified by numbers)
> > - some of the slots have a minimum value of load
> > - some of the slots have a maximum value of load;
> >
> > Ill give a rough example: imagine 5 slots on which I want to distribute 10 kg in packages of 2; some possible combinations without constraints) would be:
> > [2 2 2 2 2]
> > [4 0 2 2 2]
> > [4 0 0 4 2]
> >
> > But, if I define that slot nr 2 cannot receive load, then the option [2 2 2 2 2] would not be considered.
> > On the other hand, if I define that slot 4 cannot handle more than 2 kg, then option [4 0 0 4 2] would also be discarded.
> >
> > I think that the problem is not too complex, but the number of combinations that arise when working with 20 slots and more than 100 kg of load in small packages makes it impossible to calculate all the combinations and then eliminate the ones that do not comply with the constraints.
> >
> > I was hoping that there'd be a way of calculating just the combinations that satisfy the constraints.
> >
>
> You will quickly find that the number of combinations
> is quite large. But it IS simply done recursively.
>
> Look at the first slot. Assume that it can take any of
> these loads.
>
> 0,2,4,6,8,10
>
> Now, simply compute the possible combinations for the
> other slots, given what remains to be distributed for
> each of those possibilities. At some point, there is either
> nothing left to be distributed, or more than the remaining
> slots can carry. In either case, you are done with that
> thread of the recursion.
>
> Simple recursion.
>
> John
As I understand it, John's nice suggestion is related to an optimisation technique called dynamic programming, which the OP might like to read up on.
Dynamic programming could be used to search for an optimal assignment of packages to slots (e.g. most evenly balanced, or most profitable, or whatever objective function you want to use),
Ross
|
|
0
|
|
|
|
Reply
|
Ross
|
9/21/2010 11:16:08 PM
|
|
The function implemented here does something pretty close to what you asked
http://www.mathworks.com/matlabcentral/fileexchange/17818
You can use it as template to implement the recursive algorithm.
Bruno
|
|
0
|
|
|
|
Reply
|
Bruno
|
9/22/2010 12:41:25 AM
|
|
|
7 Replies
448 Views
(page loaded in 0.057 seconds)
Similiar Articles: How to generate discrete combinations with fixed sum? - comp.soft ...Good afternoon, I am hoping someone in the community may be able to help me out with my problem. I am using Matlab to generate combinations with c... Out of memory, close specific figure on GUI - comp.soft-sys.matlab ...How to generate discrete combinations with fixed sum? - comp.soft ... However, I get the OUT OF MEMORY error, so I really have to ... function implemented here does ... Find all possible pairs - comp.lang.prologHow to generate discrete combinations with fixed sum? - comp.soft ... Find all possible pairs - comp.lang.prolog... you want the unordered pairs (any two "distinct ... AR coefficients for complex numbers - comp.dspHow to generate discrete combinations with fixed sum? - comp.soft ... I think that the problem is not too complex, but the number of combinations that arise when working ... Most Quickly Readable Font? - comp.fontsHow to generate discrete combinations with fixed sum? - comp.soft ... > You will quickly find that the number of combinations is ... dynamic programming, which the OP ... Frequency Resolution of the DFT - comp.dsp... talking about multiplying a band of frequencies (spectrum analysis with a fixed ... The inverse transform is a discrete sum (taken at distinct frequencies) over a finite ... How to check whether malloc has allocated memory properly in case ...... employees =3D NULL; } There I both fixed the ... non-NULL, it > must return a value that is distinct ... to run your code simultaneously on multiple combinations ... How to count how many times ech row has been repeated? - comp.soft ...How to generate discrete combinations with fixed sum? - comp.soft ... How to count how many times ech row has been repeated? - comp.soft ..... go to the help menu many ... String based hashCode - comp.lang.java.programmerThere are algorithms that will generate a perfect hash for asmall fixed ... unique given that the string>combination used to generate ... knows how to keep your objects distinct ... Minimum Phase Impulse Response - comp.dsp... anyone know how to find the precise minimum phase discrete ... and z transform k=N/2 H(z) = sum ... View with a fixed-width font to see the figure. There ... How to generate discrete combinations with fixed sum? - comp.soft ...Good afternoon, I am hoping someone in the community may be able to help me out with my problem. I am using Matlab to generate combinations with c... How to Find the Sum of Which Number Combinations Equal a Specific ...Using a simple math equation, you can easily find the sum of a combination of two numbers that equal a specific number. To do this, you need to first start with a ... 7/25/2012 8:30:18 AM
|