Roy Gourgi said:
Believe it or not, in most combinatorial problems there is some
*unavoidable
redundancy* as most combinatorial covering designs are not perfect (i.e.
they contain some unavoidable redundancy). There are instances of perfect
combinatorial designs such as this design C(22,6,3)=77 and when they are
perfect they are call t-designs. But most designs do not fall under this
perfect category and they are thus much harder to find than their
counterparts.
If you are interested I can shed some more light, but it gets more
complex.
Let's see how much progress we make elsewhere first... I can't remember
much of the combinatorics I did from university, unfortunately. (I
can't even remember how much we did.)
No, I am not counting the instances of a particular combination such as
2,3,4 because if you look at the code carefully, any combination is never
checked more than once in any of the 6 columns in the gaSeconds. That is
why
as I mentioned in my other posts, the way the search is conducted is of
the
essence. If 3 points such as 2,3,4 appear in any one of 6 numbers, it
would
be better if they appear in the first 3 of the 6 because that would speed
up
the search. Do you follow?
That may well be the intention, but it's not what actually happens, as
far as I can tell. If you make the program dump out any times when it's
checking {2,3,4} just with the lp1/lp2/lp3, lp2/lp3/lp4 combinations,
you'll see it does it several times.
However, it looks like the code doesn't actually do what I thought it
did - a brute force search for all x/y/z such that 0 < x < y < z < 50
and gaSumWorkDays[gaSeconds[x,1]+gaSeconds[y,2]+gaSeconds[z,3]]<=0
finds plenty.
So, one more time: what is this actually trying to do? Without
understanding the code in depth (which is tricky, due to the way it's
written) it's very hard to do anything other the kind of refactoring
which Markus performed.
First of all, I don't think that C++ supports jagged arrays (correct me
if I
am wrong).
I wouldn't like to say for sure, to be honest. I'm not sure what you
*do* get in C++ - it's been a while. I *suspect* that C++ doesn't
actually support *rectangular* arrays directly - you have to create a
one-dimensional array with a size of the product of the individual rank
lengths.
Furthermore, as I reiterated a few times, my knowledge in
programming is not as extensive as yours and I thought jagged arrays are
to
be used only when the arrays are not rectangular and in my case they
always
are.
No - rectangular arrays are definitely more memory efficient, but
slower in .NET.
I was not aware that jagged arrays would speed up the search process
(one of the new things that I learnt).
But when I told you that originally, you said that you *couldn't* use
jagged arrays. Is that actually the case (and in which case, why?) or
not?
In my original program I use 3 one
dimensional arrays (i.e. gaSeconds1,gaSeconds2,gaSeconds3) which I guess
is
analogous to a jagged array.
Yes, pretty much.
I think it may even be faster than a jagged
array as you are only accessing a one dimension array at a time (correct
me
if I am wrong) but I was too lazy to try to see which one is faster.
Also,
to me it seems more natural and intuitive to have several one dimensional
arrays, but this might just be a matter of preference. BTW do you know
which
would be faster a jagged array, or multiple one dimensional arrays?
I don't know which would be faster, to be honest - you'd need to
benchmark it. Of course, doing that is *much* easier if you refactor
the test bit into a separate method, which is almost certain to be
inlined anyway. Just an example of why it's important to code in a
maintainable way rather than assuming that anything which is
understandable won't perform.