-
Notifications
You must be signed in to change notification settings - Fork 0
/
const_matrix.f
147 lines (89 loc) · 2.96 KB
/
const_matrix.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
SUBROUTINE const_matrix()
C ------------------------------------------------------------------
C For more details, see the reference: O. N. Starovoytov and S. Yang
C
include "parameter.h"
include "variable.h"
include "common.h"
C ------------------------------------------------------------------
C Suffle A matrix according to the constraints
i = 0
do 220 j = 1, ATM
if (numj(j).ne.0) then
i = i + 1
k = numi(j)
l = numj(j)
m = abs(l - k)
if (m.eq.0) then
numi(i + ATM) = k
numj(i + ATM) = l
endif
if (k.lt.l) then
numi(i + ATM) = k
numj(i + ATM) = l
endif
if (k.gt.l) then
numi(i + ATM) = k
numj(i + ATM) = l
endif
endif
220 enddo
C ------------------------------------------------------------------
C Writing down the constraints
do 230 i = ATM + 1, ATM + NOC
k = numi(i)
l = numj(i)
if (k == l) then
A(k,i) = 1.0d0
A(i,k) = -1.0d0
endif
if (k < l) then
A(k,i) = 1.0d0
A(i,k) = 1.0d0
A(l,i) = -1.0d0
A(i,l) = -1.0d0
endif
if (k > l) then
A(k,i) = 1.0d0
A(i,k) = 1.0d0
A(l,i) = -1.0d0
A(i,l) = -1.0d0
endif
230 enddo
C ------------------------------------------------------------------
C Fixed charges for matrix A.CONSTR
i = 0
do 240 j = 1, ATM
if (fix(j)==1) then
i = i + 1
A( j, i + ATM + NOC ) = 1.0d0
A( i + ATM + NOC, j ) = 1.0d0
endif
240 enddo
C ------------------------------------------------------------------
C Fixed charges for matrix B.CONSTR
i = 0
do 260 j = 1, ATM
if (fix(j)==1) then
i = i + 1
k = fix(j)
fix( i + ATM + NOC ) = k
q( i + ATM + NOC ) = q(j)
endif
260 enddo
do 270 j = ATM + NOC + 1, ATM + NOC + NOF
B( j ) = q(j)
270 enddo
C ------------------------------------------------------------------
C Finilizing constraints for matrix A.CONSTR
do 280 i = 1, ATM + NOC + NOF
do 290 j = 1, ATM + NOC + NOF
if ( i == (ATM + NOC + NOF) ) A(i + 1, j - NOC - NOF) = 1.0d0
if ( j == (ATM + NOC + NOF) ) A(i - NOC - NOF, j + 1) = 1.0d0
if ( i == (ATM + NOC + NOF) .and. j == (ATM + NOC + NOF) ) then
A(i + 1, j + 1) = 0.0d0
endif
290 enddo
280 enddo
ATM = ATM + NOC + NOF
END