Re: [PHP] Seeking a scheduling algorithm

2012-07-15 Thread Tedd Sperling

_
t...@sperling.com
http://sperling.com

On Jul 14, 2012, at 6:32 PM, Bill Guion  wrote:

> On Jul 14, 2012, at 4:53 PM, php-general-digest-h...@lists.php.net wrote:
> 
>> From: Tedd Sperling 
>> Does anyone have a resource, or better yet code, to solve the scheduling 
>> problem described below?
>> -snip- 
>> The problem is, knowing what appointments (i.e., twice a week for 2 hours, 
>> three times a week for one hour, etc.) must be scheduled for the week, what 
>> is the most efficient way to schedule these appointments into that week?
> 
> 
> Tedd,
> 
> There is an old general rule that the most time efficient way to schedule is 
> to put the "big" time requests on the schedule first. In this case, that 
> would mean schedule all five times a week requests first, then the four times 
> a week, then the three times a week. The two hour requests should be 
> scheduled next: three times a week and twice a week can be scheduled at the 
> same time. Then fill in the rest with the one hour requests.
> 
> Hope that makes sense.
> 
> -= Bill =-

Bill:

Yes, that makes sense and that has been my first-blush approach to the solution 
to this problem. It's a bit like filling a paper bag at checkout, or filling a 
moving van -- you put in the biggest items first and then fill the empty spaces 
with smaller and smaller items.

I was just thinking the problem is not new and perhaps there is an algorithm 
laying around somewhere.

For example, an automated "solution" for the Tetris game might be a good match.

People have proposed the Bin Packing Problem and looks interesting. Likewise, 
the knapsack proposal is interesting, but it leaves stuff behind, which is not 
possible in the problem I'm trying to solve. If I have too many appointments, 
then I simply hire more people to solve the overbooking problem.

This problem is:

1. Fill all the open times efficiently with bookings.
2. If you run out of open times, then open a new week and fill it similarly.

Like I said, this is similar to filling a paper bag at checkout -- when the bag 
is filled (as efficiently as possible), then get another bag and repeat.

I claim if you know the size and number of items before-hand, then you should 
be able to optimize both: a) the filling of each bag; b) and minimize the 
number of bags you need.  Maybe that's a better way to describe this problem.

> A closed mouth gathers no feet.

LOL -- I should remember that.

Cheers,

tedd
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Seeking a scheduling algorithm

2012-07-15 Thread Matijn Woudt
On Sat, Jul 14, 2012 at 10:53 PM, Tedd Sperling  wrote:
> Hi gang:
>
> Does anyone have a resource, or better yet code, to solve the scheduling 
> problem described below?
>
> Let's say you have a week calendar that has openings between 8:00am to 5:00pm 
> for Monday through Friday (40 hours).
>
> Then you have an assortment of appointments that must be scheduled into the 
> week calendar. Some of the appointments are simply a one hour per week, while 
> others may be two, three, four, or five times per week and each appointment 
> for an hour or more (up to eight hours).
>
> The problem is, knowing what appointments (i.e., twice a week for 2 hours, 
> three times a week for one hour, etc.) must be scheduled for the week, what 
> is the most efficient way to schedule these appointments into that week?
>
> The most efficient way is defined as scheduling appointments with little, or 
> no, gaps in between appointments. For example, four one-hour appointments on 
> Monday between 8:00am to 12:00pm is better than four one-hour appointments 
> spread out between 8:00am to 5:00pm.
>
> Anyone have any solutions, ideas, resources, code?
>
> Thanks,
>
> tedd

Take a look at the knapsack problem, it could work for you too.

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PDO: extend or encapsulate?

2012-07-15 Thread tamouse mailing lists
On Sun, Jul 15, 2012 at 5:50 AM, shiplu  wrote:
> From OOP point of view.
>
> Use encapsulation:
> When a class has a "has-a" relation-ship with other class you should use
> encapsulation. For example, If MyDB is a class that "has-a" pdo driver in
> it, then PDO will be encapsulated inside MyDB class. This is also called
> containment. MyDB should contain PDO.
>
> Use inheritance:
> When a class has a "is-a" relation ship with other class use inheritance.
> For example,  Dog is an Animal. so Dog should extend Animal class. MyPHPDb
> is-a PHP Database Object (aka PDO). So it'll be inheritance. MyPHPDb should
> extend PDO.
>
> Think about the relation have. Then implement it.
>
>
> --
> Shiplu.Mokadd.im
> ImgSign.com | A dynamic signature machine
> Innovation distinguishes between follower and leader
>

Yes, good: "has-a" and "is-a". In some cases, the distinction seems
clear. The think in this case, the class I'm implementing "has-a" PDO
driver, rather than "is-a" PDO driver. In this case, I'm encapsulting
the PDO classes within my class to provide removal of details from the
main program for dealing with data, which isn't particularly
interested in how that data is manipulated or stored.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PDO: extend or encapsulate?

2012-07-15 Thread shiplu
>From OOP point of view.

Use encapsulation:
When a class has a "has-a" relation-ship with other class you should use
encapsulation. For example, If MyDB is a class that "has-a" pdo driver in
it, then PDO will be encapsulated inside MyDB class. This is also called
containment. MyDB should contain PDO.

Use inheritance:
When a class has a "is-a" relation ship with other class use inheritance.
For example,  Dog is an Animal. so Dog should extend Animal class. MyPHPDb
is-a PHP Database Object (aka PDO). So it'll be inheritance. MyPHPDb should
extend PDO.

Think about the relation have. Then implement it.


-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] database hell

2012-07-15 Thread Nick Edwards
On 7/12/12, Ashley Sheridan  wrote:
>
>
> "ma...@behnke.biz"  wrote:
>
>>
>>
>>
>>Nick Edwards  hat am 12. Juli 2012 um 14:00
>>geschrieben:
>>
>>> On 7/12/12, Gibbs  wrote:
>>>
>>> > mysql_query("DELETE from userprefs where clientr='$User'",
>>$connmy);
>>
>>
>>Sidenote: And don't forget to validate user input and make use of mysql
>>escape
>>and prepared statements ;)
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
> Another way if the access credentials are the same would be to specify the
> full 'path' to the table in the query:
>
> DELETE FROM database.table WHERE clause
>

Umm I wouldn't be doing that if using mysql replication, I only now (2
days later) discovered that broke it! but your suggestion was the only
one that allowed it to work without crashing out for unauthed access
to (wrong) database when using db1 and db2  (worked until it needed to
return to db1, strill tried to use db2 method, hrmm at least perl
knows to return to use the original, not php though)


thanks to all suggestions, looks like we just need to close db1 con
db2, close db2 and recon to db1  *sigh*

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php