configs.f 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. PROGRAM OUTLET
  2. IMPLICIT NONE
  3. INTEGER NMMAX,NMAX
  4. PARAMETER (NMMAX=50000,NMAX=100)
  5. DOUBLE PRECISION X(NMAX)
  6. INTEGER I, J, N, M, NM, IT
  7. INTEGER IPERM(NMAX)
  8. INTEGER L1(NMAX), L2(NMAX)
  9. INTEGER PATTERNS ( NMMAX, NMAX )
  10. INTEGER CONF(NMAX,6), FREQ(NMMAX), IPAT
  11. DOUBLE PRECISION DFREQ(NMMAX)
  12. INTEGER PERM ( NMAX, 6), P1(NMAX), P2(NMAX), P(NMAX)
  13. LOGICAL ISOMORPHICQ
  14. INTEGER NITER
  15. CHARACTER (LEN=10) STR
  16. CHARACTER (LEN=20) ARGV
  17. INTEGER NARG
  18. REAL TSTART, TEND
  19. CALL GETARG(1, ARGV)
  20. READ (ARGV,*) N
  21. CALL GETARG(2, ARGV)
  22. READ (ARGV,*) M
  23. CALL GETARG(3, ARGV)
  24. READ (ARGV,*) NITER
  25. C NITER = 1000
  26. C N = 4
  27. C M = 3
  28. NM = N * M
  29. C CALL PERMUTATIONS ( N, 100, PERM )
  30. C DO 12, I = 1, NM
  31. C12 PRINT * , ( PERM ( I , J ), J = 1 , N )
  32. C
  33. C
  34. C DO 10, J = 1, 100
  35. C CALL GENER ( N, M, P1 )
  36. C PRINT *, (P1(I), I=1,NM)
  37. C
  38. C CALL GENER ( N, M, P2 )
  39. C PRINT *, (P2(I), I=1,NM)
  40. C
  41. C PRINT*, ISOMORPHICQ ( N, M, P1, P2, PERM )
  42. C 10 CONTINUE
  43. DFREQ = 0.D0
  44. FREQ = 0
  45. CALL CPU_TIME(TSTART)
  46. CALL GRAPHS (N,M,PATTERNS,IPAT,FREQ,NITER)
  47. CALL CPU_TIME(TEND)
  48. C PRINT*, IPAT
  49. PRINT '("TIME = ",F10.3," SECONDS.")',TEND-TSTART
  50. PRINT*, N, M, IPAT
  51. DO 10, I = 1, IPAT
  52. DFREQ ( I ) = DBLE( FREQ(I) ) / DBLE(NITER) * 100.D0
  53. WRITE(STR,'(I5)') NM
  54. 10 WRITE(6, "(I5,F8.2," // ADJUSTL(STR) // "I5)" )
  55. & I, DFREQ( I ), (PATTERNS(I,J), J=1,NM)
  56. C PRINT '("TIME = ",F10.3," SECONDS.")',TEND-TSTART
  57. C IT = 1
  58. C CONF(IT, 1) = 1
  59. C CONF(IT, 2) = 1
  60. C CONF(IT, 3) = 2
  61. C CONF(IT, 4) = 2
  62. C CONF(IT, 5) = 3
  63. C CONF(IT, 6) = 3
  64. C CALL PATTERNS ( CONF, NMAX, N, IT, DIST )
  65. C PRINT *
  66. C L1(1) = 1
  67. C L1(2) = 1
  68. C L1(3) = 3
  69. C L1(4) = 2
  70. C L1(5) = 3
  71. C L1(6) = 2
  72. C L2(1) = 1
  73. C L2(2) = 1
  74. C L2(3) = 2
  75. C L2(4) = 3
  76. C L2(5) = 2
  77. C L2(6) = 3
  78. C PRINT *, (L1(I), I=1,NM)
  79. C PRINT *, (L2(I), I=1,NM)
  80. C PRINT*, ISOMORPHICQ ( N, M, L1, L2, PERM )
  81. C DO 1, I=1, N
  82. C 1 L1(I) = I
  83. C L1(1)=1
  84. C L1(2)=1
  85. C L1(3)=2
  86. C L1(4)=2
  87. C L1(5)=3
  88. C L1(6)=3
  89. C CALL PADLIST( L1, L2, N, 1)
  90. C DO 2, I = 1, N
  91. C2 PRINT '(2I5)', L1(I), L2(I)
  92. END
  93. SUBROUTINE GRAPHS ( N, M, PATTERNS, IPAT, FREQ, ITMAX )
  94. IMPLICIT NONE
  95. INTEGER NMMAX,NMAX
  96. PARAMETER (NMMAX=50000,NMAX=100)
  97. INTEGER N, M, NM, IPAT, ITMAX
  98. INTEGER PATTERNS ( NMMAX, NMAX )
  99. INTEGER FREQ (NMAX)
  100. INTEGER I, J, K, IT
  101. INTEGER PERM ( NMAX, 6), P1(NMAX), P2(NMAX), P(NMAX)
  102. LOGICAL ISOMORPHICQ
  103. LOGICAL Q
  104. NM = N * M
  105. CALL PERMUTATIONS ( N, 100, PERM )
  106. C DO 1, I = 1, NM
  107. C1 PRINT * , ( PERM ( I , J ), J = 1 , N )
  108. CALL GENER ( N, M, P1 )
  109. C PRINT *, (P1(I), I=1,NM)
  110. DO 2, J = 1, NM
  111. 2 PATTERNS(1,J) = P1(J)
  112. FREQ = 0
  113. IPAT = 1
  114. FREQ(1) = 1
  115. C MAIN LOOP
  116. IT = 1
  117. 10 CONTINUE
  118. Q = .FALSE.
  119. CALL GENER ( N, M, P2 )
  120. C Check isomorphy against all existing patterns
  121. K = 0
  122. 20 CONTINUE
  123. K = K + 1
  124. DO 12, J = 1, NM
  125. 12 P1(J) = PATTERNS(K,J)
  126. IF (ISOMORPHICQ(N,M,P1,P2,PERM)) THEN
  127. Q = .TRUE.
  128. FREQ ( K ) = FREQ ( K ) + 1
  129. IT = IT + 1
  130. C PRINT*, (P2(J), J=1,NM)
  131. IF (IT.LT.ITMAX) GOTO 10
  132. ELSE
  133. IF (K.LT.IPAT) GOTO 20
  134. ENDIF
  135. C If it doesn't match any existing pattern add it
  136. IF (.NOT. Q) THEN
  137. IPAT = IPAT + 1
  138. FREQ(IPAT) = 1
  139. DO 14, J=1, NM
  140. 14 PATTERNS(IPAT,J) = P2(J)
  141. C WRITE(*,'(1H+,A,I5,A)') 'PROGRESS: ', IPAT, '%'
  142. C PRINT*, (P2(J), J=1,NM)
  143. ENDIF
  144. IT = IT + 1
  145. C IF (ISOMORPHICQ(N,M,P1,P2,PERM)) THEN
  146. C FREQ(K) = FREQ(K)+1
  147. C IT = IT + 1
  148. C IF (IT.LT.ITMAX) GOTO 10
  149. C GOTO 60
  150. C ENDIF
  151. C50 CONTINUE
  152. IF (IT.LT.ITMAX) GOTO 10
  153. C55 CONTINUE
  154. C IF ( Q ) THEN
  155. C IPAT = IPAT + 1
  156. C FREQ(IPAT) = 1
  157. C DO 14, J=1, NM
  158. C14 PATTERNS(IPAT,J) = P2(J)
  159. C PRINT*, (P2(J), J=1,NM)
  160. C ELSE
  161. C IT = IT + 1
  162. C IF (IT.LT.ITMAX) GOTO 10
  163. C60 CONTINUE
  164. RETURN
  165. END
  166. FUNCTION ISOMORPHICQ (N, M, P1, P2, PERM)
  167. IMPLICIT NONE
  168. LOGICAL ISOMORPHICQ, Q
  169. INTEGER N, M
  170. INTEGER P1( N*M ), P2( N*M ), P3( N*M ), P4( N*M ), P11( N*M )
  171. INTEGER PERM ( 100, N * M )
  172. INTEGER I, J, K, NM, FACT, DIFF1, DIFF11
  173. Q = .FALSE.
  174. NM = N * M
  175. FACT = 1
  176. DO 1, I = 1, N
  177. 1 FACT = I * FACT
  178. P11 (1) = P1 (1)
  179. DO 10, I = 2, NM
  180. 10 P11(I) = P1(NM+2-I)
  181. DO 2, I = 1, FACT
  182. DO 3, J = 1, NM
  183. 3 P3 ( J ) = PERM ( I , P2 ( J ) )
  184. C PRINT *, "P3 -> " , (P3(K), K=1,NM)
  185. DO 2, J = 0, NM - 1
  186. CALL PADLIST ( P3, P4, NM, J )
  187. DIFF1 = 0
  188. DIFF11 = 0
  189. DO 4, K = 1, NM
  190. DIFF1 = DIFF1 + ABS ( P4 ( K ) - P1 ( K ) )
  191. 4 DIFF11 = DIFF11 + ABS ( P4 ( K ) - P11 ( K ) )
  192. C PRINT *, (P4(K), K=1,NM), DIFF
  193. IF ((DIFF1.EQ.0).OR.(DIFF11.EQ.0)) THEN
  194. Q = .TRUE.
  195. GOTO 100
  196. ENDIF
  197. 2 CONTINUE
  198. 100 CONTINUE
  199. ISOMORPHICQ = Q
  200. RETURN
  201. END
  202. SUBROUTINE GENER ( N, M, P )
  203. IMPLICIT NONE
  204. INTEGER NMAX
  205. PARAMETER (NMAX=100)
  206. INTEGER N, M, NM
  207. INTEGER P ( * )
  208. DOUBLE PRECISION X ( NMAX )
  209. INTEGER IPERM (NMAX) , IER
  210. INTEGER I
  211. NM = N * M
  212. DO 1, I=1, NM
  213. 1 X(I) = RAND()
  214. CALL DPSORT(X, NM, IPERM, 1, IER)
  215. DO 2, I = 1, NM
  216. 2 P ( I ) = ( IPERM ( I ) - 1 ) / M + 1
  217. RETURN
  218. END
  219. SUBROUTINE PERMUTATIONS ( M, MMAX, PERM )
  220. IMPLICIT NONE
  221. INTEGER M, MMAX, MFAC
  222. INTEGER PERM ( MMAX, M )
  223. INTEGER I, J, A ( M )
  224. LOGICAL NEXTP
  225. EXTERNAL NEXTP
  226. MFAC = 1
  227. DO 1, I = 1, M
  228. A ( I ) = I
  229. PERM ( 1, I ) = A ( I )
  230. MFAC = MFAC * I
  231. 1 CONTINUE
  232. DO 2, I = 2, MFAC
  233. IF(NEXTP(M, A)) THEN
  234. DO 3, J = 1, M
  235. 3 PERM ( I, J ) = A ( J )
  236. ENDIF
  237. 2 CONTINUE
  238. RETURN
  239. END
  240. C SUBROUTINE PATTERNS ( CONF, NMAX, N, M, IT, DIST )
  241. C IMPLICIT NONE
  242. C INTEGER NMAX, N, M, IT
  243. C INTEGER CONF ( NMAX, N ), DIST ( NMAX )
  244. C INTEGER A(M)
  245. C DOUBLE PRECISION X ( N )
  246. C INTEGER PERMUT ( NMAX, N )
  247. C INTEGER I, J
  248. C DO 1, I=1, M
  249. C A(I) = I
  250. C 1 CONTINUE
  251. C DO 2, I = 1, M
  252. C END
  253. SUBROUTINE PADLIST ( L1, L2, N, INC )
  254. IMPLICIT NONE
  255. INTEGER N, INC, I
  256. INTEGER L1 ( N ), L2 ( N )
  257. IF (INC.LE.-1) GOTO 50
  258. IF (ABS(INC).GE.N) THEN
  259. PRINT*, "Incorrect value of INC, try smaller value"
  260. GOTO 100
  261. ENDIF
  262. DO 10, I=1, N
  263. IF(I+INC.LE.N) THEN
  264. L2(I+INC) = L1(I)
  265. ELSE
  266. L2(I+INC-N) = L1(I)
  267. ENDIF
  268. 10 CONTINUE
  269. GOTO 100
  270. 50 CONTINUE
  271. DO 11, I=1, N
  272. IF(I+INC.GE.1) THEN
  273. L2(I+INC) = L1(I)
  274. ELSE
  275. L2(I+INC+N) = L1(I)
  276. ENDIF
  277. 11 CONTINUE
  278. 100 CONTINUE
  279. RETURN
  280. END
  281. FUNCTION NEXTP(N,A)
  282. INTEGER N,A,I,J,K,T
  283. LOGICAL NEXTP
  284. DIMENSION A(N)
  285. I=N-1
  286. 10 IF(A(I).LT.A(I+1)) GO TO 20
  287. I=I-1
  288. IF(I.EQ.0) GO TO 20
  289. GO TO 10
  290. 20 J=I+1
  291. K=N
  292. 30 T=A(J)
  293. A(J)=A(K)
  294. A(K)=T
  295. J=J+1
  296. K=K-1
  297. IF(J.LT.K) GO TO 30
  298. J=I
  299. IF(J.NE.0) GO TO 40
  300. NEXTP=.FALSE.
  301. RETURN
  302. 40 J=J+1
  303. IF(A(J).LT.A(I)) GO TO 40
  304. T=A(I)
  305. A(I)=A(J)
  306. A(J)=T
  307. NEXTP=.TRUE.
  308. END