ALGORITHM 595 An Enumerative Algorithm for Finding Hamiltonian

ALGORITHM 595
An Enumerative Algorithm for Finding
Hamiltonian Circuits in a Directed Graph
SILVANO MARTELLO
University of Bologna, Italy
Categories and Subject Descriptors: G.2.2 [Discrete Mathematics]: Graph theory--path and cwcult
problems; G.m [Mathematics of Computing]: Miscellaneous--FORTRAN
General Terms Algorithms
Additional Key Words and Phrases Hamfltoman circuit, depth-first search
DESCRIPTION
Problem
L e t G = (V, A ) be a directed graph (or digraph), w h e r e V - - {vl, v2 . . . . . v,} is
t h e set of the n vertices a n d A is t h e set o f t h e m arcs (v,, vj) in G. A Hamiltonian
circuit in G is a p e r m u t a t i o n (s,) o f t h e vertices s u c h t h a t (vs,, v,,+,) E A for
t = 1, . . . , n - 1 a n d (v~,,, v,,) ~ A.
T h e p r o b l e m o f finding one or m o r e H a m i l t o n i a n circuits in a given g r a p h (or
alternatively of d e t e r m i n i n g t h a t t h e g r a p h does n o t possess H a m i l t o n i a n circuits)
is k n o w n to b e l o n g to t h e class of t h e NP-complete problems, so e x a c t e n u m e r a t i v e
a l g o r i t h m s or heuristic t e c h n i q u e s are generally u s e d for its solution.
T h i s p a p e r p r e s e n t s a p r o g r a m for solving t h e following g e n e r a l p r o b l e m , e i t h e r
exactly or heuristically:
(P) G i v e n a d i g r a p h G = (V, A ) a n d a value h(1 _< h __ + w ) , find h distinct
H a m i l t o n i a n circuits in G or, if G does n o t possess h H a m i l t o n i a n circuits,
find all t h e H a m i l t o n i a n circuits in G.
T h e m o s t c o m m o n cases o f (P) are t h e e x t r e m e s i t u a t i o n s h = 1 (find a
H a m i l t o n i a n circuit in G, if any) a n d h = + oo (find all t h e H a m i l t o n i a n circuits in
G). T h e m o s t efficient m e t h o d for solving (P) is t h a t p r o p o s e d b y Christofides
[1] a n d S e l b y [3], described in [1], w h i c h is b a s e d on t h e e n u m e r a t i v e s c h e m e o f
Received 13 March 1981; revised 19 August 1982; accepted 7 October 1982.
This work was supported by Consiglio Nazionale delle Ricerche, Italy.
Author's address. Istituto di AutomaUca, Umverslty of Bologna, 1-40136 Bologna, Italy.
Permission to copy without fee all or part of this material is granted provided that the copies are not
made or distributed for direct commercial advantage, the ACM copyright notice and the title of the
pubhcatlon and its date appear, and notice is given that copymg is by permission of the Association
for Computing Machinery To copy otherwise, or to republish, requires a fee and/or specific
permission
© 1983 ACM 0098-3500/83/0300-0131 $00.75
ACMTransactionson Mathematmal Software,Vol.9, No. 1, March 1983,Pages 131-138.
132
Algorithms
Roberts and Flores [2]. T h e algorithm presented in this p a p e r improves on the
Christofides-Selby m e t h o d by incorporating some heuristic techniques (mainly
at steps 0 and 3) for determining the branches to follow in the decision tree.
It is assumed, with no loss of generality, t h a t (v,, v,) ~ AVv, ~ V.
Algorithm
T h e algorithm is described as an exact procedure for solving problem (P) above.
T h e following notation is used:
R, = {Jl (v,, vj) ~ A};
Q = {il (v,, vj) E A } .
T h e m e t h o d is based on a depth-first branching strategy which progressively
extends an e l e m e n t a r y p a t h S = {(v,,, vs..), (v,,, v , , ) , . . . , (v,,_,, v~)) (k denotes the
current level of the branch decision tree and is used to save information relative
to each active node of the tree) until either no further extension is possible or the
p a t h includes n - 1 arcs (possibly giving a Hamfltonian circuit if (v,k, v,,) E A).
In b o t h cases the algorithm performs a backtracking, consisting in removing the
last arc v , _ , v,~) from S, followed by a branching, consisting in adding to S a new
arc emanating from v , _ . At each branching, a reduction phase removes from A
all useless arcs (arcs t h a t will never be included in S) and inserts implied arcs
(arcs t h a t will sooner or later be included in S) in a s e t / .
At Step 0 a vertex Vr ( r o o t o f S ) is selected such t h a t [ Cr] --~"maxv,ev{] C, I} (ties
are broken by choosing vr with m i n i m u m ]Rr ]); this increases the probability
that, when S includes n - 1 arcs, a Hamiltonian circuit m a y be formed through
arc (v,,, v,, -- Vr). T h e initialization also involves setting I = 6 , k -- 1, sl = r.
Step 1 performs a search for implied arcs b y looking for nodes of in- or
outdegree equal to one. L e t (v,, v~) be any arc of A such t h a t R, = {j} or Cj = (i).
For any such arc the largest p a t h formed by (v,, vj) and previously implied arcs
is built. L e t / d e n o t e this path. If [/] < n - 1, (v,, vj) is added t o / , while all the
arcs emanating from v, or terminating at vj and the arc from the end to the
beginning vertex of f are r e m o v e d from A (if this removal causes any vertices Vq
to have R q = (~J o r Cq = 6 , a backtracking (step 5) is performed). If If] = n - 1,
then either a Hamiltonian circuit has been found (if the arc from the end to the
beginning vertex o f / e x i s t s ) or a backtracking must occur. Step 1 is iterated until
no further arc can be added to 1.
Step 2 determines w h e t h e r an implied arc e m a n a t e s from vs, (say (v,,, v~) E I).
If E ~- r and k < n, a backtracking is performed; otherwise, S is extended b y
setting k = k + 1, sk = g (if now k = n, either a Hamiltonian circuit has been
found or a backtracking must occur). Step 2 is iterated until no f u r t h e r implied
arc can be added to S.
Step 3 performs the branching phase. T h e next arc (v,,, v~) to be added to S is
selected from the arcs not previously tried so t h a t min(] R~[, [ C~I} is a m i n i m u m
(ties are broken by choosing (v~, v~) with m i n i m u m ]R~] + ]C~[); in this way the
most "critical" vertices are inserted first in S, increasing the probability t h a t a
Hamiltonian circuit can be obtained. If no feasible arc (v,~, v;) exists, a backtracking is performed. Otherwise, all the arcs emanating from v,~ or terminating at v;,
as well as arc (v;, Vr), are r e m o v e d from A, and S is extended by setting k = k +
ACM Transactions on Mathematmal Software, Vol 9, No 1, March 1983
Algorithms
•
133
1, sk = £ If the removal causes a vertex Vq to have Rq ~ I~) or Cq -~ ~ , a
backtracking is executed; if not, step 2 follows.
Step 4 is performed whenever a new Hamiltonian circuit is found. It only
determines whether the required number h of Hamiltonian circuits has been
completed: if so, the execution terminates; if not, a backtracking follows.
Step 5 performs the backtracking phase. Arc (v~_,, v~) is removed from S (if
k = 1, all possibilities have been exhausted, so execution terminates). If (v~_,, v~,)
I (i.e., if the arc was added to S at step 2), k is set to k - 1 and a new
backtracking occurs. Otherwise (i.e., if the arc was added to S at step 3), all the
arcs removed from A at level k are reinserted in A, all the arcs inserted in I at
level k are removed from I, k is set to k - 1, and a new branching (step 3) is
performed.
The heuristic version of the algorithm is obtained by imposing an upper bound
on the number of backtrackings allowed. Only backtrackings on arcs ~ I are
considered, since arcs E I require no computational effort.
Program
The algorithm of the previous section was implemented in American National
Standard FORTRAN as a main subroutine (HC) calling five subroutines (PATH,
FUPD, BUPD, IUPD, and RARC). The whole package is completely selfcontained and communication to it is achieved solely through the parameter list
of HC. Entrance to the package is achieved by using the statement:
CALL HC(N, PR, AR, KW, NC, NB, S, N + 1, PR(N + 1), PC, AC, VR, VC, P, SUBR,
RBUS, TOR).
Only the values of the first six parameters niust be defined by the user prior to
calling HC.
The input digraph G = (V, A) is stored as an adjacency list. Array A R contains
the elements of R~ in the first ] R~ [ locations, the elements of R2 in the following
I R2 [ locations, and so on. The n records of AR are pointed by the n + I elements
of array PR (PR(i) = ~j=~
'-~ [R~ I; PR(1) = 0), so that the elements of R, are stored
in locations PR(i) + 1 to PR(i + 1) of AR. It follows that the value m is stored
in PR(n + 1).
The other input parameters are
N
KW
number of vertices (n);
output unit number on which to write the permutations (s,) corresponding
to the Hamiltonian circuits found ( K W = - 1 if no writing is desired). The
permutations are written according to Format 2015.
Two input-output parameters are used:
NC (input)
NC (output)
NB (input)
NB (output)
upper bound on the number of Hamiltonian circuits to be found
(NC = - 1 if all are to be found);
number of Hamiltonian circuits found;
- 1 if exact execution is required; upper bound on the number of
backtrackings if heuristic execution is required;
number of backtrackings performed (for heuristic executions, if
NB(output) < NB(input), the result obtained is exact).
ACM Transactions on M a t h e m a t m a l Software, Vol 9, No. 1, M a r c h 1983.
<
~s
C~
A
~
L~- O0 ~'~ ~
,-~
[~
(/)
c~
E~
i
<
E~
<
<
Algorithms
•
135
The only output parameter is
S(i)
ith element of the permutation corresponding to the last Hamiltonian
circuit found (s,).
N + 1 and PR(N + 1) are used for adjustable dimensions. PC, AC, VR, VC, P,
SUBR, RBUS, and TOR are work arrays. In the calling program, the user must
dimension P R and PC at least at n + 1, AR and AC at least at m, and S, VR,
VCP, SUBR, RBUS, and TOR at least at n.
All the parameters are integer. After execution, the order of the elements
within the records of AR may be altered.
Computat,onal Results
The code was computationaUy tested on randomly generated digraphs with both
the indegree and the outdegree of each vertex lying in prefixed ranges. For each
range and for different values of the number of nodes, 10 graphs were generated
and solved on a CDC-6600.
Table I shows the results obtained by using the code for finding all the
Hamiltonian circuits in small-size digraphs. The case of vertex degrees in range
1-3 shows that the algorithm is very fast in solving problems where very few (or
no) Hamiltonian circuits exist. The case of vertex degrees in range 2-3 shows that
the ratio (average running time)/(average number of Hamiltonian circuits) grows
about linearly with n. The same growing rate is presented by the case of vertex
degrees in range 2-4; in this case, however, the running times tend to be
impractical because of the high number of Hamiltonian circuits.
Table II refers to use of the code for finding a single Hamiltonian circuit in
large-size digraphs. It is confirmed that the algorithm easily solves cases where
no Hamiltonian circuit exists (vertex degrees in range 1-3). The cases of vertex
degrees in ranges 2-3 and 2-4 show that the growing rate with n is much higher
for dense digraphs.
Used as a heuristic on the same problems as Table II, the code obviously gave
an exact solution for all the digraphs with vertex degrees in range 1-3, for any
prefixed upper bound NB on the number of backtrackings allowed. In the case of
vertex degrees in range 2-3, the problems solved exactly were 62 percent for NB
= 10, 78 percent for NB = 20, 85 percent for NB = 40; for range 2-4, such
percentages were 50, 58, and 72 percent, respectively.
ACKNOWLEDGMENT
I am grateful to Prof. P. Toth for his helpful comments.
REFERENCES
1 CHRISTOFIDES, N. Graph Theory--An Algorzthmtc Approach. Academic Press, New York,
1975.
2. ROBERTS, S.M., AND FLORES, B. Systematic generation of Hamiltonian circuits. Commun ACM
9, 9(Sept. 1966), 690-694.
3. SELBY, G.R. The use of topolog]cal methods m computer-aided circuit layout. Ph.D. dissertation,
London Univ., London, England, 1970.
ALGORITHM
[A part of the listing is printed here. The complete listing is available from the
ACM Algorithms Distribution Service (see page 141 for order form).]
ACM Transactions on Mathematical Software, Vol. 9, bIo. 1, March 1983.
136
•
Algorithms
C S A M P L E D R I V E R PROGRAM FOR HC.
C
C THIS P R O G R A M FINDS ONE OR MORE H A M I L T O N I A N C I R C U I T S IN A
C D I R E C T E D GRAPH OF
N VERTICES AND
M ARCS.
C
C C O M P L E T E D E T A I L S OF THE PARAMETERS MAY BE FOUND IN THE
C D O C U M E N T A T I O N OF S U B R O U T I N E HC.
C
C THE INPUT U N I T N U M B E R IS A S S U M E D TO BE
5 •
C THE O U T P U T U N I T N U M B E R IS A S S U M E D TO BE
6 •
C THE A R R A Y S ARE C U R R E N T L Y D I M E N S I O N E D TO A L L O W PROBLEMS F O R
C WHICH
N .LE. 250
AND
M .LE. 2000 .
C
C THE P R O G R A M MAY BE T E S T E D ON THE F O L L O W I N G D A T A
C
C N
=
6
C PR =
0
3
5
8
Ii
13
16
CAR=
3
5
6
6
3
6
1
4
5
1
C
2
2
3
4
2
5
C
INTEGER PR(251), PC(251), AR(2000), AC(2000), S(250), VR(250),
* VC(250), P(250), SUBR(250), RBUS(250), TOR(250)
NIN = 5
NOUT = 6
C INPUT D A T A
R E A D (NIN,99999) N
NPI = N + 1
READ (NIN,99999) (PR(J),J=I,NPI)
M = PR(NPI)
R E A D (NIN,99999) (AR(J),J=I,M)
W R I T E (NOUT,99998)
W R I T E (NOUT, 99997) N
W R I T E (NOUT,99996) (PR(J),J=I,NPI)
W R I T E (NOUT,99995) (AR(J),J=I,M)
W R I T E (NOUT, 99994)
C C A L L HC AS EXACT P R O C E D U R E TO F I N D (AND PRINT) A SINGLE
C H A M I L T O N I A N CIRCUIT, IF ONE EXISTS.
NC = 1
NB = -i
CALL HC(N, PR, AR, NOUT, NC, NB, S, N+I, PR(N+I), PC, AC, VR, VC,
* P, SUBR, RBUS, TOR)
W R I T E (NOUT,99993) NC, NB
C C A L L HC AS EXACT P R O C E D U R E TO FIND (AND PRINT) ALL THE
C H A M I L T O N I A N CIRCUITS.
NC = -i
NB = -i
CALL HC(N, PR, AR, NOUT, NC, NB, S, N+I, PR(N+I), PC, AC, VR, VC,
* P, SUBR, RBUS, TOR)
W R I T E (NOUT,99993) NC, NB
C C A L L HC AS H E U R I S T I C P R O C E D U R E TO F I N D (AND PRINT) A
C SINGLE H A M I L T O N I A N CIRCUIT, IF ONE EXISTS, W I T H O U T
C PERFORMING MORE THAN
2 BACKTRACKINGS.
NC = 1
NB = 2
CALL HC(N, PR, AR, NOUT, NC, NB, S, N+I, PR(N+I), PC, AC, VR, VC,
* P, SUBR, RBUS, TOR)
W R I T E (NOUT, 99993) NC, NB
C C A L L HC AS H E U R I S T I C P R O C E D U R E TO FIND (AND PRINT) A
C SINGLE H A M I L T O N I A N CIRCUIT, IF ONE EXISTS, W I T H O U T
C P E R F O R M I N G MORE T H A N
4 BACKTRACKINGS.
NC = 1
NB = 4
C A L L HC(N, PR, AR, NOUT, NC, NB, S, N+I, PR(N+I), PC, AC, VR, VC,
* P, SUBR, RBUS, TOR)
W R I T E (NOUT,99993) NC, NB
C CALL HC AS H E U R I S T I C P R O C E D U R E TO FIND (WITHOUT PRINTING)
C A T MOST
2 H A M I L T O N I A N CIRCUITS, W I T H O U T P E R F O R M I N G MORE
C THAN
5 BACKTRACKINGS.
NC = 2
NB = 5
C A L L HC(N, PR, AR, -i, NC, NB, S, N+I, PR(N+I), PC, AC, VR, VC,
* P, SUBR, RBUS, TOR)
W R I T E (NOUT,99993) NC, NB
IF (NC.EQ.0) STOP
C PRINT THE L A S T H A M I L T O N I A N C I R C U I T FOUND
W R I T E (NOUT,99992) (S(J),J=I,N)
ACMTransac~onsonMathemaUcM Software, Vol 9, No l, March1983
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
32@
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
Algorithms
99999
99998
99997
99996
99995
99994
99993
99992
STOP
F O R M A T (1015)
F O R M A T (IHI////////)
F O R M A T (6H N
= , I5)
F O R M A T (6H PR = , 2515)
F O R M A T (6H AR = , 2515)
F O R M A T (//////)
F O R M A T (/I5, 10H C I R C U I T S , I5, 14H B A C K T R A C K I N G S / / / )
F O R M A T (4X, 4HS = , 2515)
END
S U B R O U T I N E HC(N, PR, AR, KW, NC, NB, S, NPI, M, PC, AC, VR, VC,
* P, SUBR, RBUS, TOR)
C
C S U B R O U T I N E TO FIND ONE OR MORE H A M I L T O N I A N C I R C U I T S IN A
C D I R E C T E D G R A P H OF
N V E R T I C E S ( N .GT. 1 ) R E P R E S E N T E D
C BY THE INTEGERS
i, 2, ..., N A N D
M ARCS.
C
C HC IS B A S E D ON AN E N U M E R A T I V E A L G O R I T H M A N D CAN BE USED
C E I T H E R AS AN EXACT P R O C E D U R E OR AS A H E U R I S T I C P R O C E D U R E
C (BY L I M I T I N G THE N U M B E R OF B A C K T R A C K I N G S ALLOWED).
C
C E N T R A N C E TO HC IS A C H I E V E D BY USING THE S T A T E M E N T
C
CALL H C ( N , P R , A R , K W , N C , N B , S , N + I , P R ( N + I ) , P C , A C , V R , V C ,
C
*
P,SUBR,RBUS,TOR)
C
C THE V A L U E S OF THE FIRST SIX P A R A M E T E R S M U S T BE D E F I N E D
C BY THE USER P R I O R TO C A L L I N G HC. HC NEEDS
2 A R R A Y S ( PR
C AND
PC ) OF L E N G T H
N + 1 , 2 A R R A Y S ( AR
AND
AC )
C OF L E N G T H
M AND
7 A R R A Y S ( S , V R , VC , SUBR ,
C RBUS
AND
TOR ) OF L E N G T H
N . T H E S E A R R A Y S M U S T BE
C D I M E N S I O N E D BY THE U S E R IN THE C A L L I N G PROGRAM.
C
C HC CALLS
5 S U B R O U T I N E S : PATH, FUPD, BUPD, IUPD, RARC.
C THESE S U B R O U T I N E S ARE C O M P L E T E L Y LOCAL, I.E. THE INFORMAC TION THEY NEED IS P A S S E D T H R O U G H THE P A R A M E T E R LIST.
C THE W H O L E P A C K A G E IS C O M P L E T E L Y SELF C O N T A I N E D AND C O M M U C N I C A T I O N TO IT IS A C H I E V E D S O L E L Y T H R O U G H THE P A R A M E T E R
C LIST OF HC. NO M A C H I N E D E P E N D E N T C O N S T A N T S ARE USED.
C THE P A C K A G E IS W R I T T E N IN A M E R I C A N N A T I O N A L S T A N D A R D
C F O R T R A N AND IS A C C E P T E D BY THE
FTN(EL=A)
C O M P I L E R OF THE
C CDC C Y B E R 76 (OPTION
EL=A
C H E C K S P R O G R A M AND S U B R O U T I N E S
C FOR A D H E R E N C E TO ANSI) AS W E L L AS BY THE PFORT V E R I F I E R .
C THE P A C K A G E HAS B E E N T E S T E D ON A
CDC C Y B E R 76 , ON A
CDC
C 6600 , ON AN
IBM 370/158
A N D ON A
D I G I T A L V A X 11/780 .
C
C M E A N I N G OF THE INPUT PARAMETERS:
C N
= N U M B E R OF VERTICES.
C PR(I) = SUM OF THE O U T - D E G R E E S OF V E R T I C E S
1 . . . . , I-I
C
( P R ( 1 ) = 0 , PR(N+I) = M ).
CAR
= A D J A C E N C Y LIST. THE E L E M E N T S FROM
AR(PR(1)+I)
TO
C
AR(PR(I+I))
ARE A R E C O R D C O N T A I N I N G , I N A N Y ORDER,
C
ALL THE V E R T I C E S
J
SUCH T H A T ARC
(I,J)
EXISTS.
C
THE G R A P H S H O U L D NOT C O N T A I N A R C S STARTING A N D
C
E N D I N G AT THE SAME VERTEX.
C KW
= UNIT TAPE ON W H I C H TO W R I T E THE H A M I L T O N I A N CIRC
CUITS FOUND, A C C O R D I N G TO F O R M A T
2015 . KW = - 1
C
IF NO W R I T I N G IS DESIRED. THE C I R C U I T S ARE W R I T T E N
C
AS O R D E R E D S E Q U E N C E S OF
N VERTICES.
C
C M E A N I N G OF THE I N P U T - O U T P U T PARAMETERS:
C NC(INPUT)
= UPPER B O U N D ON THE N U M B E R OF H A M I L T O N I A N
C
C I R C U I T S TO BE FOUND ( NC = - I IF A L L THE
C
H A M I L T O N I A N C I R C U I T S A R E TO BE FOUND).
C NC(OUTPUT) = N U M B E R OF H A M I L T O N I A N C I R C U I T S FOUND.
C NB(INPUT)
= - I
IF HC M U S T BE E X E C U T E D AS AN E X A C T
C
PROCEDURE.
C
= UPPER B O U N D ON THE N U M B E R OF B A C K T R A C K I N G S IF
C
HC M U S T BE E X E C U T E D AS A H E U R I S T I C PROCEDURE.
C NB(OUTPUT) = N U M B E R OF B A C K T R A C K I N G S PERFORMED. W H E N HC
C
HAS B E E N E X E C U T E D AS A H E U R I S T I C PROCEDURE,
C
IF NB(OUTPUT) .LT. NB(INPUT)
T H E N THE
C
R E S U L T O B T A I N E D IS EXACT.
C
C M E A N I N G OF THE O U T P U T PARAMETER:
C S(I) = I-TH
V E R T E X IN THE L A S T H A M I L T O N I A N C I R C U I T FOUND.
C
•
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
MAN
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
NC
HC
HC
NC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
BC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
137
770
780
790
800
810
820
830
840
850
860
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
ACM Transactions on Mathematmal Software, Vol, 9, No. 1, March 1983
138
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
Algorithms
ON R E T U R N OF HC
N, PR A N D
KW ARE UNCHANGED, W H I L E IN
AR
THE O R D E R OF THE E L E M E N T S W I T H I N EACH R E C O R D MAY BE
ALTERED.
M E A N I N G OF THE W O R K ARRAYS:
PC(I)
= SUM OF THE I N - D E G R E E S OF V E R T I C E S
I, ..., I-i
( P C ( l ) = 0 ).
AC
= A D J A C E N C Y L I S T (BACKWARD). THE E L E M E N T S FROM
AC(PC(I)+I)
TO
AC(PC(I+I))
CONTAIN, IN A N Y
ORDER, A L L THE V E R T I C E S
J
SUCH T H A T A R C
(J,I)
EXISTS.
W H E N A N A R C IS R E M O V E D FROM THE G R A P H A T THE
K-TH
LEVEL
OF THE B R A N C H - D E C I S I O N TREE, THE C O R R E S P O N D I N G E L E M E N T S
AR(Q)
AND
AC(T)
ARE SET TO
- (K*(N+I) + AR(Q))
AND
TO
- (K*(N+I) + AC(T)) , R E S P E C T I V E L Y .
VR(I)
= C U R R E N T O U T - D E G R E E OF V E R T E X
I •
VC(I)
= C U R R E N T I N - D E G R E E OF V E R T E X
I .
SUBR(I) = - (K*(N+I) + J)
IF A R C
(I,J)
WAS IMPLIED AT
THE
K-TH
L E V E L OF THE B R A N C H - D E C I S I O N TREE.
= 0 OTHERWISE.
RBUS(I) = - J
IF ARC
(J,I)
IS C U R R E N T L Y IMPLIED.
= 0 OTHERWISE.
TOR(K)
= Q*(M+I) + T
IF THE ARC G O I N G F R O M
S(K)
TO THE
ROOT, C O R R E S P O N D I N G TO
AR(Q)
A N D TO
AC(T),
W A S R E M O V E D FROM THE G R A P H A T THE
K-TH
LEVEL
OF THE B R A N C H - D E C I S I O N TREE.
= 0 OTHERWISE.
P(I)
= P O I N T E R FOR THE F O R W A R D STEP. THE N E X T ARC
S T A R T I N G FROM
I TO BE C O N S I D E R E D IN THE
B R A N C H - D E C I S I O N TREE IS
(I,AR(PR(I)+P(I)).
M E A N I N G OF THE M A I N W O R K S I M P L E V A R I A B L E S :
JR
= ROOT. THE H A M I L T O N I A N C I R C U I T S A R E D E T E R M I N E D AS
PATHS S T A R T I N G A N D E N D I N G A T
JR •
K
= C U R R E N T L E V E L OF THE B R A N C H - D E C I S I O N TREE.
M
= N U M B E R OF ARCS.
MPI = M + i (USED F O R P A C K I N G
TOR ).
NPI = N + 1 (USED FOR P A C K I N G
A R , AC
AND
SUBR )
I N T E G E R PR(NPI), PC(NPI),
• SUBR(N), RBUS(N), TOR(N)
AR(M),
AC(M),
S(N), VR(N), VC(N),
ACM Transactions on Mathematical Software, Vol 9, No. 1, M a r c h 1983
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
HC
P(N), HC
HC
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070