php-general Digest 3 Oct 2013 12:47:41 -0000 Issue 8386

Topics (messages 322235 through 322240):

Re: Algorithm Help
        322235 by: Stuart Dallas
        322236 by: Serge Fonville
        322237 by: Floyd Resler
        322238 by: Marc Guay
        322239 by: Tamara Temple
        322240 by: Floyd Resler

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 1 Oct 2013, at 19:51, Floyd Resler <fres...@adex-intl.com> wrote:

> Here's my task: A group of kids is going to be staying with different host 
> families throughout the next 8 months.  The number of kids staying with a 
> host family can range from 2 to 10.  When deciding which kids should stay 
> together at a host family, the idea is for the system to put together kids 
> who have stayed with each other the least on past weekends.  So, if a host 
> family can keep 5 kids, then the group of 5 kids who have stayed together the 
> least will be chosen.
> 
> I can't think of an easy, quick way to accomplish this.  I've tried various 
> approaches that have resulted in a lot of coding and being very slow.  My 
> idea was to give each group of kids a score and the lowest score is the group 
> that is selected.  However, this approach wound of iterating through several 
> arrays several times which was really slow.  Does anyone have any ideas on 
> this puzzle?

Sounds like a job for a directed graph data structure. I wish I had time to 
knock up a solution but I don't right now. This article should help you get 
started: 
http://www.codediesel.com/algorithms/building-a-graph-data-structure-in-php/

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
It also depends on the amount of kids, families and stays.

If the numbers are low, by hand may be a lot easier and faster

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl


2013/10/2 Tamara Temple <tamouse.li...@gmail.com>

>
> On Oct 1, 2013, at 1:51 PM, Floyd Resler <fres...@adex-intl.com> wrote:
>
> > Here's my task: A group of kids is going to be staying with different
> host families throughout the next 8 months.  The number of kids staying
> with a host family can range from 2 to 10.  When deciding which kids should
> stay together at a host family, the idea is for the system to put together
> kids who have stayed with each other the least on past weekends.  So, if a
> host family can keep 5 kids, then the group of 5 kids who have stayed
> together the least will be chosen.
> >
> > I can't think of an easy, quick way to accomplish this.  I've tried
> various approaches that have resulted in a lot of coding and being very
> slow.  My idea was to give each group of kids a score and the lowest score
> is the group that is selected.  However, this approach wound of iterating
> through several arrays several times which was really slow.  Does anyone
> have any ideas on this puzzle?
> >
> > Thanks!
> > Floyd
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> While definitely a tempting coding exercise, I just want to say that if
> this is urgent in any way, shuffling cards with the kids' names on them by
> hand might just be faster and less frustrating :)
>
> OTOH, if this is something you're going to have to figure out week after
> week, then a software solution might be handy.
>
> This is also not an *easy* problem to solve; there isn't a simple approach
> to optimizing this sort of thing because you're building a net between all
> the various kids based on past stays, in addition to the constraints of
> host family  capacity. Thus your previous code attempts might in fact be
> the end result.
>
> Obviously, structuring the data is the key here.
>
> I'm thinking of 3 primary models: Kids, Hosts, and Stays.
>
> Kids and Hosts seem pretty obvious. Stays is the interesing model, and
> needs to have joining tables with Kids and Hosts.
>
> A Stay will have one Host, and have many Kids and a date.
>
> The algorithm then needs to make the graph where it can pull out the
> number of times any particular kid has stayed with another, looking
> something like this:
>
> Amy:
>    Ben: 10
>    Jill: 3
>    Carlos: 7
>    Chen: 2
> Ben:
>    Amy: 10
>    Jill: 5
>    Carlos: 8
>    Chen: 3
> Jill:
>    … and so on
>
> Then you be able to pull through that graph and find the smallest number
> of stays for each kid.
>
> Not simple, but I hope this helps.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---

On Oct 2, 2013, at 9:51 AM, Tamara Temple <tamouse.li...@gmail.com> wrote:

> 
> On Oct 1, 2013, at 1:51 PM, Floyd Resler <fres...@adex-intl.com> wrote:
> 
>> Here's my task: A group of kids is going to be staying with different host 
>> families throughout the next 8 months.  The number of kids staying with a 
>> host family can range from 2 to 10.  When deciding which kids should stay 
>> together at a host family, the idea is for the system to put together kids 
>> who have stayed with each other the least on past weekends.  So, if a host 
>> family can keep 5 kids, then the group of 5 kids who have stayed together 
>> the least will be chosen.
>> 
>> I can't think of an easy, quick way to accomplish this.  I've tried various 
>> approaches that have resulted in a lot of coding and being very slow.  My 
>> idea was to give each group of kids a score and the lowest score is the 
>> group that is selected.  However, this approach wound of iterating through 
>> several arrays several times which was really slow.  Does anyone have any 
>> ideas on this puzzle?
>> 
>> Thanks!
>> Floyd
>> 
>> 
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
> 
> While definitely a tempting coding exercise, I just want to say that if this 
> is urgent in any way, shuffling cards with the kids' names on them by hand 
> might just be faster and less frustrating :)
> 
> OTOH, if this is something you're going to have to figure out week after 
> week, then a software solution might be handy.
> 
> This is also not an *easy* problem to solve; there isn't a simple approach to 
> optimizing this sort of thing because you're building a net between all the 
> various kids based on past stays, in addition to the constraints of host 
> family  capacity. Thus your previous code attempts might in fact be the end 
> result.
> 
> Obviously, structuring the data is the key here.
> 
> I'm thinking of 3 primary models: Kids, Hosts, and Stays.
> 
> Kids and Hosts seem pretty obvious. Stays is the interesing model, and needs 
> to have joining tables with Kids and Hosts.
> 
> A Stay will have one Host, and have many Kids and a date.
> 
> The algorithm then needs to make the graph where it can pull out the number 
> of times any particular kid has stayed with another, looking something like 
> this:
> 
> Amy:
>   Ben: 10
>   Jill: 3
>   Carlos: 7
>   Chen: 2
> Ben:
>   Amy: 10
>   Jill: 5
>   Carlos: 8
>   Chen: 3
> Jill:
>   … and so on
> 
> Then you be able to pull through that graph and find the smallest number of 
> stays for each kid.
> 
> Not simple, but I hope this helps.
> 
> 

That's the only approach I could think of.  I may have to tell the director it 
may be a bit slow but at least she won't have to do it by hand!

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
If you have the technology handy, it could also just be easier to wipe
the children's memories after each stay.

Marc

--- End Message ---
--- Begin Message ---
On Oct 2, 2013, at 9:05 AM, Marc Guay <marc.g...@gmail.com> wrote:

> If you have the technology handy, it could also just be easier to wipe
> the children's memories after each stay.
> 
> Marc
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Well played! (.. eying the black suit…. "What's that funny stick you're hol….")


--- End Message ---
--- Begin Message ---

On Oct 2, 2013, at 6:23 PM, Tamara Temple <tamouse.li...@gmail.com> wrote:

> 
> On Oct 2, 2013, at 9:05 AM, Marc Guay <marc.g...@gmail.com> wrote:
> 
>> If you have the technology handy, it could also just be easier to wipe
>> the children's memories after each stay.
>> 
>> Marc
>> 
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
> 
> Well played! (.. eying the black suit…. "What's that funny stick you're 
> hol….")
> 
> 
> 

I love it! Our director loved it too!  Too funny!

Thanks!
Floyd



--- End Message ---

Reply via email to