iso.f 7.1 KB

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