this is what i am trying to achieve

T

tony collier

ok . thanks everyone for your advice so far. this is what i am trying to
do and there is probably a much better way which this newbie hasn't read
or thought about yet.

i am getting prices from x number of suppliers who all quote me a
different individual price for each of y items. no one supplier is always
cheaper than the others.

no. of suppliers: x (preferably unlimited)

no. of items: y (again, preferably unlimited)

i then calculate all the different combination of items from mixed
suppliers. The formula to work out number of combinations =

no.of supplier ^ (to the power of) no. of items.

this requires creating an array of y dimensions with x elements per
dimension to store all combinations

as you will now understand , i have so far only been able to go up to x=
11, and y=7 before running into memory constraints.

items must be able to be added/deleted like in a cart until user
checksout, so no running calculation can take place to try and crunch
numbers as i go. this is why i can't see how array can be made any
smaller.

hope this all makes sense. any ideas to do this in a better way would be
greatly appreciated.


Incidentally, is there any way to initalize all elements in the array to
zero in one fell swoop rather than looping through them?



many thanks tc.
 
F

Frank Oquendo

tony said:
hope this all makes sense. any ideas to do this in a better way
would be greatly appreciated.

Is this a triplicate post or did you not like the advice you've received
thus far?

The better way you ask for is to use a DataSet containing a table for
items and suppliers. In addition, a third table will hold rows
indicating which items may be obtained from which suppliers and at what
price, lead time, etc.

This cuts the amount of information you're manipulating dramatically
since it does not operate on the assumption that all items may be
procured from all suppliers. It also removes a lot of unneeded
complexity since you can pull information using standard SQL.

This solution is simple, scalable and maintainable.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
J

james

Sounds like an interesting problem, is this a high school or college
assignment ?-)
 
T

tony collier

no - i is just a personal project to extend the functionality of a
website i have created.
 
V

Vijaye Raji

How did you come up with the formula x^y??

If there are max y items and max x suppliers, isn't the array size x*y???

Like Frank suggested, a DataSet should do the work for you pretty well. If
you insist on going with an array, do a multi-dimensional array -
array[x][y] where x is supplier and y is item index.

-vJ
 
T

tony collier

How did you come up with the formula x^y??
If there are max y items and max x suppliers, isn't the array size
x*y???

Like Frank suggested, a DataSet should do the work for you pretty
well. If you insist on going with an array, do a multi-dimensional
array - array[x][y] where x is supplier and y is item index.

-vJ
no , it is x^y. i can't proove it , i just tried a few trivial cases and
noticed a pattern. i am sure someone could post mathematical proof but
that isn't really the issue here - you'll just have to trust me or work
through a few examples yourself.

don't know much about [x][y] ( i thought this was for jagged arrays) or
DataSets. any good sites to read about these?
 
M

Michael Culley

tony collier said:
no , it is x^y. i can't proove it , i just tried a few trivial cases and
noticed a pattern. i am sure someone could post mathematical proof but
that isn't really the issue here - you'll just have to trust me or work
through a few examples yourself.

From the description you gave it should be x*y, either x^y is wrong or your description is wrong.
 
T

tony collier

From the description you gave it should be x*y, either x^y is wrong or
your description is wrong.

i want all combinations in all different orders eg. with 3 suppliers
a,b,c and 2 items I want:

| a | b | c
===================================
1 | | |
===================================
2 | | |


a,a
a,b
a,c
b,a
b,b
b,c
c,a
c,b
c,c

= 3^2 = 9 combinations in all possible orders.

hope this is now clear.
 
F

Frank Oquendo

tony said:
= 3^2 = 9 combinations in all possible orders.

hope this is now clear.

Nope. 2 items are each available from 3 suppliers. That's six
possibilities, not nine:

Item 1, Supplier 1
Item 1, Supplier 2
Item 1, Supplier 3
Item 2, Supplier 1
Item 2, Supplier 2
Item 2, Supplier 3

Take this as constructive criticism, not just ankle biting. It would
seem there's a great deal of confusion in your design. If you're having
a hard time nailing the requirements, the code is doomed to failure.

Forget about the implementation for now and concentrate solely upon the
use cases for your application. Once the use cases are laid out you can
design the application specs. Coding should be the next step in that
process, not the first.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
T

tony collier

Nope. 2 items are each available from 3 suppliers. That's six
possibilities, not nine:

Item 1, Supplier 1
Item 1, Supplier 2
Item 1, Supplier 3
Item 2, Supplier 1
Item 2, Supplier 2
Item 2, Supplier 3

Take this as constructive criticism, not just ankle biting. It would
seem there's a great deal of confusion in your design. If you're
having a hard time nailing the requirements, the code is doomed to
failure.

Forget about the implementation for now and concentrate solely upon
the use cases for your application. Once the use cases are laid out
you can design the application specs. Coding should be the next step
in that process, not the first.

Maybe i just haven't explained it very well so far. In your example
above you have understood me to want 1 item. This is not what i want. I
want both items. in my previous list when i wrote things like

a,a , this meant that i was pricing the cost of buying item 1 from
supplier a AND item 2 from supplier a. so

a,b means buying item 1 from supplier a and item 2 from supplier b.

b,a means buying item1 from supplier b and and item 2 from supplier a

and so on. ( therefore a,b doesn't equal b,a incidentally)
 
M

Michael Culley

I'm not sure why you need this, but don't store it, just calculate it as you need it, that way you need to store very little data.
 
F

Frank Oquendo

tony said:
a,a , this meant that i was pricing the cost of buying item 1 from
supplier a AND item 2 from supplier a. so

a,b means buying item 1 from supplier a and item 2 from supplier b.

b,a means buying item1 from supplier b and and item 2 from supplier a

and so on. ( therefore a,b doesn't equal b,a incidentally)

That's not a function of the data. Simply store the items, the suppliers
and relevant pricing. Let the user choose what he wants instead of
trying to preconceive every possible permutation.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
C

Champika Nirosh

X^Y - As far as the explaination is concern methematically what Tony said is
correct...

in the same time if a one supplier cannot same item again then it become

x!
_
(x-1)!

Nirosh.

Michael Culley said:
I'm not sure why you need this, but don't store it, just calculate it as
you need it, that way you need to store very little data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top