II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
160 c.A.R. HOARE<br />
already to be possible, but excluding any exams which have already been<br />
tried. We therefore introduce a variable:<br />
untried: powerset exam,<br />
and a procedure<br />
procedure gensupersets,<br />
which generates and records all possible supersets of trial by adding <strong>on</strong>e or<br />
more exams from untried to it. This procedure will be called from within<br />
"suitable".<br />
functi<strong>on</strong> suitable" sessi<strong>on</strong>;<br />
begin trial, bestsofar" sessi<strong>on</strong>; e'exam; untried'powerset exam ;<br />
end;<br />
e from remainder;<br />
trial: = bestsofar: = {e};<br />
untried'= remaining- trial- incompat (e);<br />
gensupersets;<br />
suitable: = bestsofar<br />
Note that the first value of the trial is the unitset of some exam chosen from<br />
the remainder according to some as yet undefined criteri<strong>on</strong>. The justificati<strong>on</strong><br />
for this is that the chosen exam must eventually feature in some sessi<strong>on</strong> of<br />
the timetable, and it might as well be this <strong>on</strong>e. If this prior choice were not<br />
made, gensupersets would keep <strong>on</strong> generating the same supersets <strong>on</strong> every<br />
cycle of the major loop of the timetabling program.<br />
As another significant optimisati<strong>on</strong>, we have removed from untried any<br />
exams which are incompatible with the exams in the trial, since there is no<br />
need to even c<strong>on</strong>sider the additi<strong>on</strong> of any of these exams to the trial.<br />
The generati<strong>on</strong> of supersets of a given trial may proceed by selecting<br />
each exam from untried, and adding it to trial. If the result is still valid, it<br />
should be recorded, and the new value of trial is then a suitable sessi<strong>on</strong> to<br />
act as a basis for further superset generati<strong>on</strong>. This suggests a recursive<br />
program structure. Of course, the exam added to trials should also be sub-<br />
tracted from untried, to avoid unnecessary repetiti<strong>on</strong>s; and it is very advan-<br />
tageous to remove from untried any exams which are incompatible with the<br />
exam just added to the trial, so that these do not have to be c<strong>on</strong>sidered again<br />
in future. Also, the values of trial and untried must be left unchanged<br />
by each call, so any change made to them must be recorded and restored in<br />
variables save 1 and save 2.