!******************************************
!******************************************
!演示一个特殊电路尽力寻找电路满足问题的解答
!******************************************
! SINOMACH
!
! 演示一个特殊电路尽力寻找电路满足问题的解答
!
! 周勇
! 20221128
!**************************************************
!c$$Run, Output:
!**************************************************
!**************************************************
Program main
!*********************************************************************72
!
!c MAIN is the main program for SATISFY.
!
Implicit None
Integer n
Parameter (n=26)
Integer bvec(n)
Integer circuit_value
Integer i
Integer ihi
Integer j
Integer solution_num
Integer value
Write (, '(a)') ' '
Call timestamp()
Write (, '(a)') ' '
Write (, '(a)') 'SATISFY'
Write (, '(a)') ' FORTRAN95,2013&18 version'
Write (, '(a)') ' We have a logical function of N logical arguments.'
Write (, '(a)') ' We do an exhaustive search of all 2^N possibilities,'
Write (*, '(a)') ' seeking those inputs that make the function TRUE.'
!
! Compute the number of binary vectors to check.
!
ihi = 2**n
Write (, '(a)') ' '
Write (, '(a,i8)') ' The number of logical variables is N = ', n
Write (, '(a,i9)') ' The number of input vectors to check is ', ihi
Write (, '(a)') ' '
Write (, '(a)') ' # Index ' //&
'---------Input Values------------------------'
Write (, '(a)') ' '
!
! Check every possible input vector.
!
solution_num = 0
Do i = 0, ihi - 1
Call i4_to_bvec(i, n, bvec)
value = circuit_value(n, bvec)
If (value==1) Then
solution_num = solution_num + 1
Write (*, '(2x,i3,2x,i10,3x,26i2)') solution_num, i, (bvec(j), j=1, n)
End If
End Do
!
! Report.
!
Write (, '(a)') ' '
Write (, '(a,i8)') ' Number of solutions found was ', solution_num
!
! Shut down.
!
Write (, '(a)') ' '
Write (, '(a)') 'SATISFY'
Write (, '(a)') ' Normal end of execution.'
Write (, '(a)') ' '
Call timestamp()
Stop
End Program main
Function circuit_value(n, bvec)
!*********************************************************************72
!
!c CIRCUIT_VALUE returns the value of a circuit for a given input set.
!
! Parameters:
!
! Input, integer N, the length of the input vector.
!
! Input, integer BVEC(N), the binary inputs.
!
! Output, integer CIRCUIT_VALUE, the output of the circuit.
!
Implicit None
Integer n
Integer bvec(n)
Integer circuit_value
Logical value
value = (bvec(1)==1 .Or. bvec(2)==1) .And. (bvec(2)==0 .Or. bvec(4)==0) &
.And. (bvec(3)==1 .Or. bvec(4)==1) .And. (bvec(4)==0 .Or. bvec(5)==0)&
.And. (bvec(5)==1 .Or. bvec(6)==0) .And. (bvec(6)==1 .Or. bvec(7)==0)&
.And. (bvec(6)==1 .Or. bvec(7)==1) .And. (bvec(7)==1 .Or. bvec(16)==0)&
.And. (bvec(8)==1 .Or. bvec(9)==0) .And. (bvec(8)==0 .Or. bvec(14)==0)&
.And. (bvec(9)==1 .Or. bvec(10)==1) .And. (bvec(9)==1 .Or. bvec(10)==0)&
.And. (bvec(10)==0 .Or. bvec(11)==0) .And. (bvec(10)==1 .Or. bvec(12)==1)&
.And. (bvec(11)==1 .Or. bvec(12)==1) .And. (bvec(13)==1 .Or. bvec(14)==1)&
.And. (bvec(14)==1 .Or. bvec(15)==0) .And. (bvec(15)==1 .Or. bvec(16)==1) &
.And. (bvec(15)==1 .Or. bvec(17)==1) .And. (bvec(18)==1 .Or. bvec(2)==1)&
.And. (bvec(19)==1 .Or. bvec(1)==0) .And. (bvec(20)==1 .Or. bvec(2)==1)&
.And. (bvec(20)==1 .Or. bvec(19)==0) .And. (bvec(20)==0 .Or. bvec(10)==0) &
.And. (bvec(1)==1 .Or. bvec(18)==1) .And. (bvec(2)==0 .Or. bvec(21)==1) &
.And. (bvec(22)==0 .Or. bvec(21)==1) .And. (bvec(23)==0 .Or.&
bvec(21)==1) .And. (bvec(22)==0 .Or. bvec(21)==0) .And.&
(bvec(23)==1 .Or. bvec(21)==0)
If (value) Then
circuit_value = 1
Else
circuit_value = 0
End If
Return
End Function circuit_value
Subroutine i4_to_bvec(i4, n, bvec)
!*********************************************************************72
!
!c I4_TO_BVEC converts an integer into a binary vector.
!
! Parameters:
!
! Input, integer I4, the integer.
!
! Input, integer N, the dimension of the vector.
!
! Output, integer BVEC(N), the vector of binary remainders.
!
Implicit None
Integer n
Integer bvec(n)
Integer i
Integer i4
Integer i4_copy
i4_copy = i4
Do i = n, 1, -1
bvec(i) = mod(i4_copy, 2)
i4_copy = i4_copy/2
End Do
Return
End Subroutine i4_to_bvec
Subroutine timestamp()
!*********************************************************************72
!
!c TIMESTAMP prints out the current YMDHMS date as a timestamp.
!
! Parameters:
!
! None
!
Implicit None
Character *(8) ampm
Integer d
Character *(8) date
Integer h
Integer m
Integer mm
Character *(9) month(12)
Integer n
Integer s
Character *(10) time
Integer y
Save month
Data month/'January ', 'February ', 'March ', 'April ', &
'May ', 'June ', 'July ', 'August ', 'September',&
'October ', 'November ', 'December '/
Call date_and_time(date, time)
Read (date, '(i4,i2,i2)') y, m, d
Read (time, '(i2,i2,i2,1x,i3)') h, n, s, mm
If (h<12) Then
ampm = 'AM'
Else If (h==12) Then
If (n==0 .And. s==0) Then
ampm = 'Noon'
Else
ampm = 'PM'
End If
Else
h = h - 12
If (h<12) Then
ampm = 'PM'
Else If (h==12) Then
If (n==0 .And. s==0) Then
ampm = 'Midnight'
Else
ampm = 'AM'
End If
End If
End If
Write (*, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)') d,&
month(m), y, h, ':', n, ':', s, '.', mm, ampm
Return
End Subroutine timestamp
!**************************************************
!c$$Run, Output:
!**************************************************
Compiled Successfully. memory: 2828 time: 11.09 exit code: 0
SATISFY
FORTRAN95,2013&18 version
We have a logical function of N logical arguments.
We do an exhaustive search of all 2^N possibilities,
seeking those inputs that make the function TRUE.
The number of logical variables is N = 26
The number of input vectors to check is 67108864
Index ---------Input Values------------------------
1 29255464 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 0 0
2 29255465 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 0 1
3 29255466 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 1 0
.........................................
118 62842861 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 1 0 1
119 62842862 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 0
120 62842863 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1
Number of solutions found was 120
SATISFY
Normal end of execution.
15 April 2022 6:27:12.886 AM
演示一个特殊电路尽力寻找电路满足问题的解答,
编译运行验证演示如上.
广州