Help! -Match problem

  • Thread starter Thread starter Chengfu
  • Start date Start date
C

Chengfu

Hi, group.

I need your help.

I have two tables, one is tblTutor with the names and their available
times, the other one is tblTutee with the names and the available times.
What I need to do is to match every tutee with one tutor. Of course, the
available times of the matched tutee should be a subset of the available
times of the tutors. So, my question is, How should I set the structure of
the tables and how can I get the matched list?

Thank you very much!

Joe
 
Hi,


Part of the solution is to run a maximum flow algorithm (Ford-Fulkerson,
or using the Simplex Method), part of the solution is to get the "graph"
(from which you can run the max flow algorithm). SQL can be use for that
second part.

I start with the following tables:

tutors tutor period
E alpha
E beta
E gamma
D alpha
D gamma
D delta
C alpha
C beta
C gamma
B alpha
B gamma
A beta
A gamma
A delta
B beta

tutees tutee period
a alpha
a beta
a gamma
b alpha
b gamma
b delta
c alpha
c beta
c gamma
d alpha
d gamma
e beta
e gamma



The SQL Statement (JET):
----------------------------------------
SELECT a.tutor, a.tutee
FROM (SELECT tutors.tutor, tutees.tutee, Count(*) AS Critical
FROM tutors INNER JOIN tutees
ON tutors.period = tutees.period
GROUP BY tutors.tutor, tutees.tutee) AS a
INNER JOIN (SELECT tutees.tutee, COUNT(*) as Required
FROM tutees
GROUP BY tutees.tutee) AS b
ON (a.tutee=b.tutee) AND (a.Critical=b.Required)
GROUP BY a.tutor, a.tutee;
-----------------------------------------

supplies us with the graph of tutors who can accept tutees:

Query41 tutor tutee
A e
B a
B c
B d
B e
C a
C c
C d
C e
D b
D d
E a
E c
E d
E e



based on the assumption that a tutor must be available for ALL the periods
required by a tutee to be able to be the tutor of the tutee.


The graph is just then a matter so define a SOURCE node, with links of
capacity of one toward each tutee-node, then define links from each
tutee-node toward each tutor-node, capacity of one, then, from each tutor
node to the SINK node, each link again with a capacity of 1 (or more, if a
tutor can get more than one tutee). A solution of the max flow FROM the
SOURCE to the SINK is then a possible assignment. If the max flow is less
than the number of tutee, a solution is impossible (for all tutee to get a
tutor). That is where the simplex method becomes more helpful, since it can
"easily" perform post-optimization analysis. I am not aware of a SQL
implementation of the Simplex method (even for very sparse "matrix" ).


To solve through the simplex method, well, I hope you already know the
method, if not, as fast search on Google give me the following site:
http://www-fp.mcs.anl.gov/otc/Guide/CaseStudies/simplex/explanation.html

To get the graph-to-simplex representation of the max flow problem, start
with Xi the flow in link i, Xi>=0 as usual non-negativity constraints on
variables for the Simplex, but also, Xi <= Ci, the capacity of the link, as
real constraints of the problem we try to solve. You try to maximize the sum
of the Xi getting out of the source. That's all. Since every pivot is
either -1, either +1, the Simplex will preserve integrality if you start
with an integral solution (ie, you won't get 0.5 student here, or there).

Note also that min{ z } is the same as - max{ -z }, it is just a matter
of sign.



Hoping it may help,
Vanderghast, Access MVP
 
Hi,


oops. There is a major constraint I forgot if you use the Simplex:

The sum of Xi entering in a node k must be equal to the sum of Xi
leaving the node k, except for the source node and for the sink node. That
creates one more additional constraint,per tutor and per tutee.



Vanderghast, Access MVP
 
Back
Top