-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslpmain.f
1475 lines (1268 loc) · 45.3 KB
/
slpmain.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
subroutine slp_main(n, m, maxa, ngrad, nspace, maxlws, iprint,
& ifail, rifail, maxf, rho, f, hc, x, xnew, c, cnew,
& drlo, drup, dclo, dcup, a, la,
& mrow, mcol, dels, dobj,
& d, ff, fc, lws, dspace,
& user, iuser, max_iter, istat, rstat, blo, bup, lam,
& ispace, sv_bs_r, sv_bs_c, s, sv_t_fi,
& se_mx_lp_it, wr_msg, status, result, oldbnd,
& do_rng)
implicit none
INCLUDE 'SLPCOMM.INC'
include 'msg.inc'
c dChange
c add this to have access to pointers into user/iuser (for maxCost)
include 'pusr.inc'
c end dChange
c ------------ declaration of passed parameters -----------------
integer n, m, maxa, ngrad, nspace, maxlws, iprint, ifail,
& max_iter, maxf, rifail
double precision rho, f, hc
c dChange
c new shape for phase one problem needs to be declared here
c
c change number of columns from n+m to n+2*m in
c sv_bs_c, dclo, dcup, dobj
c
c change number of rows from 2*m to m in
c sv_bs_r, drlo, drup
c
c change total row/col info from 2*ngrad+2*m to ngrad+2*m in
c mrow, mcol, dels
c
c (don't change result or status)
integer la(0:maxa+m+2), mrow(ngrad+2*m), mcol(ngrad + 2*m),
& lws(maxlws), istat(12), iuser(*),
& ispace(2*nspace), sv_bs_c(n+2*m), sv_bs_r(m),
& status(n+m)
double precision x(n), xnew(n), c(m), cnew(m), drlo(m),
& drup(m), dclo(n+2*m), dcup(n+2*m), a(maxa),
& dspace(nspace), user(*), dels(ngrad+2*m),
& rstat(3), blo(n+m), bup(n+m), lam(n+m), d(n),
& ff(maxf), fc(maxf), dobj(n+m), s(n+m),
& result(7, n+m), oldbnd(2*n+2*m)
c end dChange
logical sv_t_fi, se_mx_lp_it, wr_msg, do_rng
integer f_lp_it
c ------------- declaration of internal variables ---------------
integer i, j, k, flag, mxa, iter, sizef, rtcod, pjp, INFifail,
& maxprt, k_el, nr_lp, nr_rsv
integer n_two, n_xb
double precision q, hcnew, fnew, ratiof, ratioc, ratio, normd,
& penalty, mdl_f, mdl_hc, maxmu, kt_rsdu, mx_inf,
& oldrobjvalue
logical accept, f_prob, pr_to_fi, set_stat, fi_xst, f_lp_af_phI,
& scnd_try, rlx_bnds, f_rng_it
character ch
character*20 msg, ch_fnew
character*4 int2char
integer trim77
integer ems_time
character*32 bin32
double precision ems_drand
integer tt0, tt1, tt00
common /ttc/ tt0, tt1
integer bt30_32
parameter (bt30_32 = 2**31+2**30+2**29)
double precision stp_eps, csr_eps
common /tol/ stp_eps, csr_eps
integer drv_ct(3)
double precision infty, eps
common /NLP_eps_inf/ infty, eps
logical wr_msg_ag
common /wr_msg_ag_cn/ wr_msg_ag
integer seed, bigiter
common /summc/ seed, bigiter
c dChange
c extra variables needed for various things:
c maximal magnitude of objective coefficients and pointers into
c iuser/user needed to access this information on the problem
double precision maxCost
integer n_lt, n_nt, pcsi, p_ltd, p_ntd
c kt_tol is estimate of sensible threshold on kt_rsdu
c optimalityConditionMet is logical to say if converged
double precision kt_tol
logical optimalityConditionMet
double precision oldKTmeasure
c Storage for best point yet (with properties and optimal basis)
double precision Bf, Bhc, Bx(n)
integer Bsv_bs_c(n), Bsv_bs_r(m)
c end dChange
double precision sv_obj
include 'EMSOLI.INC'
include 'EMSOLN.INC'
include 'EMSOLR.INC'
c --------------------- subroutine body -------------------------
INTEGER NINF
DOUBLE PRECISION SUMPRIMALINF,SUMDUALINF,SUMRELATIVEINF
c dChange
c size of initial trust region set to typically much larger than 5
if (1==1) then
rho = 0
do i=1,n
if ( ((bup(i)-blo(i))/s(i)) .ge. rho) then
rho = (bup(i)-blo(i))/s(i)
end if
end do
c if too big just use 5
if (rho>1e8) then
if (iprint>=1) print*, 'initial rho set too big at', rho,
& 'reset to ', 5
rho=5
else
rho = ceiling(rho)
end if
end if
c end dChange
NINF=-1
rifail = 1
DO I=1,MIN(MIN_DSPACE,NSPACE) ! Inserted JCH 7/3/2000
DSPACE(I)=0D0 ! Inserted JCH 7/3/2000
END DO ! Inserted JCH 7/3/2000
iter = 0
tt0 = ems_time()
tt00 = tt0
do i=1,n+m
if (blo(i).gt.bup(i)) then
c write(nout,*) i, blo(i), bup(i)
fnew = 0.d0
WRITE(nout,*) 'Inconsistent bounds'
msg = ' incons bnds'
normd = 0.d0
hcnew = infty
ifail = 7
goto 15
end if
end do
do i=1,n
c if (x(i).gt.bup(i)+1d-7.or.x(i).lt.blo(i)-1d-7) then
c print *, i, blo(i), x(i), bup(i)
c end if
x(i) = min(x(i), bup(i))
x(i) = max(x(i), blo(i))
end do
c equivalence(ispace(1), dspace(1))
c WRITE(nout,*)'EMSOL workspace :',nspace
wr_msg_ag = .false.
f_lp_af_phI = .false.
scnd_try = .false.
rlx_bnds = .false.
f_rng_it = .false.
msg = '.'
maxprt = -1
if (wr_msg) maxprt = 256
ch = 'n' ! Corrected JCH 7/1/2000
pr_to_fi = .false.
if (ch.eq.'y') pr_to_fi = .true.
if (iprint.gt.0) then
WRITE(nout,*)
WRITE(nout,*)' start solving problem by SLP method (v3_0)'
WRITE(nout,*)' n = ',n
WRITE(nout,*)' m = ',m
c WRITE(nout,*)' ngrad = ',ngrad
end if
flag = 0
f_prob = .true.
set_stat = .false.
nr_rsv = 0
ifail = 0
fnew = infty
call ems_mset(rtcod, dspace, 1, 0, maxprt, 0, 0, 9999, 1)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_mset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('MSET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
CJCH if (.not.f_prob) then
call ems_init(rtcod, dspace)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_init: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('INIT',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
CJCH else
CJCH f_prob = .false.
CJCH end if
call ems_iget(rtcod, dspace, emsoli, emsoliln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_iget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('IGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
call ems_rget(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
call ems_rd_ct_vr(rtcod, emsoliln, emsolrln, emsoli, emsolr)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rd_ct_vr: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('rd_ct_vr',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
c dChange
c potential change to EMSOL before first LP solve
c so only calls ems_itru.f at start and when believed to be optimal
if (2==0) then
Iiterufreq = 999999
end if
c end dChange
call ems_iset(rtcod, dspace, emsoli, emsoliln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_iset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('ISET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
call ems_rset(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RSET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
c call ems_rd_ct_vr(rtcod, dspace, drv_ct)
c if (rtcod.ne.0) then
c WRITE(nout,*)'error in ems_rd_ct_vr: ',rtcod
C IF(RTCOD.GE.BAD_EMSERROR) THEN
C CALL GET_EMSERROR('rd_ct_vr',RTCOD,EMSOL_ERRORMESSAGE)
C END IF
c goto 99
c end if
call ems_rget(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
if (iprint.ge.3) WRITE(nout,*)'error in ems_rget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
c WRITE(nout,*)'emsol_tol = ',csr_eps
RTOLPINF = csr_eps *10.
call ems_rset(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RSET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
call ems_dsca(rtcod, dspace, nspace, 1)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_dsca: ',rtcod
C IF(RTCOD.GE.BAD_EMSERROR) THEN
C CALL GET_EMSERROR('DSCA',RTCOD,EMSOL_ERRORMESSAGE)
C END IF
c goto 99
end if
call objfun(x, n, f, user, iuser, flag)
call confun(x, n, m, c, a, la, user, iuser, flag)
sizef = 1
ff(sizef) = f
hc = 0.
do i=1,m
hc = hc +
& max(c(i)-bup(n+i),blo(n+i)-c(i),0.d0)/s(n+i)
c if (c(i).gt.bup(n+i)+1d-7.or.c(i).lt.blo(n+i)-1d-7) then
c print '(A,I5,3g17.11)', 'C',i, blo(n+i), c(i), bup(n+i)
c end if
end do
c stop
fc(sizef) = hc
c dChange
c initialisation of best point vectors
Bf = f
Bhc = hc
Bx = x
c end dChange
c dChange
c get maxCost (i.e. the maximal objective coefficient) for use later
c in KT test and in setting rpweight
c Calculated from problem data => for linear objectives this bound
c is valid through all iterations. For bilinear objectives the
c calulated bound assumes that all variables are below 1.
c .. get pointer into iuser to start of integer information about
c objective
pcsi = iuser(pi_cs_pi+n_cs+1)
c ... this slicing up explained in register.f:
c number of linear and bilinear terms
n_lt = iuser(pcsi)
n_nt = iuser(pcsi+1)
c pointer into user for real info on linear/bilinear terms
p_ltd = iuser(pcsi+4)
p_ntd = iuser(pcsi+5)
maxCost = 0
do i=1,n_lt
c ... user(p_ltd+i-1) are the objective coefficients
c (for linear terms)
if (abs(user(p_ltd+i-1))>maxCost) then
maxCost=abs(user(p_ltd+i-1))
end if
end do
do i=1,n_nt
c ... user(p_ltd+i-1) are the objective coefficients
c (for bilinear terms) (are there any?)
if (abs(user(p_ntd+i-1))>maxCost) then
maxCost=abs(user(p_ntd+i-1))
end if
end do
c end dChange
if (iprint.eq.1) then
WRITE(nout,*)
WRITE(nout,*) 'iter |d| rho f '//
& ' |c(x)| lp_iter st'
WRITE(nout,*)
& '------------------------------------------------'//
& '--------------------------'
end if
IF (msg_wrt_sumdat) THEN
write(22,*) 'iter |d| rho f '//
& ' |c(x)| lp_iter st'
write(22,*) '-----------------------------------------------'//
& '---------------------------'
END IF
c dChange
c print out 0th iteration giving initial objective and infeas
if (iprint.eq.1) then
WRITE(nout,'(I3,2G16.8,2G14.8,I5,A5)')
& iter, 0.0, 0.0, f, hc, 0, ' 00'
end if
CALL LOGOUT(2,dspace,bigiter,
& iter,0,0,fnew,hcnew,0,+01)
c end dChange
c do i=1,n
c WRITE(nout,*) i, x(i)
c end do
call gradient(n, m, mxa, x, a, la, maxa, user, iuser, flag)
5 continue
c ----------------- setup phase II LP ------------------------
do i=1,n
dclo(i) = max(-rho*s(i), blo(i)-x(i))
dcup(i) = min( rho*s(i), bup(i)-x(i))
c write(nout,*) i, blo(i), x(i), bup(i)
end do
do i=1,m
drlo(i) = blo(n+i)-c(i)
drup(i) = bup(n+i)-c(i)
c print *, i, c(i)
end do
do i=1,n
dobj(i) = a(i)
end do
k_el = 1
pjp = la(0)
do j=1,m
do i=la(pjp+j), la(pjp+j+1)-1
dels(k_el) = a(i)
mcol(k_el) = la(i)
mrow(k_el) = j
k_el = k_el + 1
end do
end do
c call pmdl(rtcod, dspace, 1, m, n, ngrad, dobj, drlo, drup,
c & dclo, dcup, mrow, mcol, dels)
call ems_lmdl(rtcod, dspace, 1, m, n, ngrad, dobj, drlo, drup,
& dclo, dcup, mrow, mcol, dels)
if (rtcod.ne.0) then
if (iprint.ge.3) WRITE(nout,*)'error in ems_lmdl: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('LMDL',RTCOD,EMSOL_ERRORMESSAGE)
END IF
msg = msg(1:trim77(msg))//' bad model detected: data error?'
goto 99
end if
c -------------------- set warmstart information ----------------
if (set_stat) then
call ems_nget(rtcod, dspace, emsoln, emsolnln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_nget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('NGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
do i=1,m
ispace(nrowstat+i-1) =
& iand(ispace(nrowstat+i-1),not(bt30_32)) + sv_bs_r(i)
if (.not.btest(sv_bs_r(i),31)) then
if (.not.btest(sv_bs_r(i),30))
& dspace(nrowacts+i-1) = dspace(nrowlower+i-1)
if (.not.btest(sv_bs_r(i),29))
& dspace(nrowacts+i-1) = dspace(nrowupper+i-1)
else
dspace(nrowacts+i-1) = dspace(nrowlower+i-1)
end if
end do
do i=1,n
c WRITE(nout,'(B33.32)') ispace(ncolstat+i-1)
ispace(ncolstat+i-1) =
& iand(ispace(ncolstat+i-1),not(bt30_32)) + sv_bs_c(i)
c WRITE(nout,'(2B33.32)') ispace(ncolstat+i-1), sv_bs_c(i)
if (.not.btest(sv_bs_c(i),31)) then
cc ... variable is active
if (.not.btest(sv_bs_c(i),30))
& dspace(ncolsol+i-1) = dclo(i)
if (.not.btest(sv_bs_c(i),29))
& dspace(ncolsol+i-1) = dcup(i)
else
if (f_lp_af_phI) then
dspace(ncolsol+i-1) = x(i)+d(i)
else
dspace(ncolsol+i-1) = dclo(i)
end if
end if
end do
end if
c ----- write model to file --------
if (sv_t_fi) then
c open(12,file='lastlp.mps')
open(12,file='lp'//int2char(iter+1)//'.mps')
write(nout, *) 'write model to file: lp'//
& int2char(iter+1)//'.mps'
call ems_bcdo(rtcod, dspace, 12, 1, 2)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_bcdo: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('BCDO',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
close(12)
c open(12,file='lastas.dat')
write(nout,*)
& 'write warmstart info to file: as'//int2char(iter+1)//
& '.dat ',set_stat
open(12,file='as'//int2char(iter+1)//'.dat')
write(12,*) set_stat
if (set_stat) then
do i=1,n
write(12,'(A)') bin32(sv_bs_c(i))
end do
do i=1,m
write(12,'(A)') bin32(sv_bs_r(i))
end do
end if
close(12)
end if
if (.not.set_stat) set_stat = .true.
c ----------------- solve phase II LP -----------------------
c call ems_mset(rtcod, dspace, 1, 0, 256, 0, 0, 9999, 1)
c if (rtcod.ne.0) then
c WRITE(nout,*)'error in ems_mset: ',rtcod
C IF(RTCOD.GE.BAD_EMSERROR) THEN
C CALL GET_EMSERROR('MSET',RTCOD,EMSOL_ERRORMESSAGE)
C END IF
c goto 99
c end if
call ems_scal(rtcod, dspace)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_scal: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('SCAL',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
c call ems_mset(rtcod, dspace, 1, 0, -1, 0, 0, 9999, 1)
c if (rtcod.ne.0) then
c WRITE(nout,*)'error in ems_mset: ',rtcod
C IF(RTCOD.GE.BAD_EMSERROR) THEN
C CALL GET_EMSERROR('MSET',RTCOD,EMSOL_ERRORMESSAGE)
C END IF
c goto 99
c end if
call ems_sslv(rtcod, dspace, 1, 0)
if (rtcod.ne.0) then
if (iprint.ge.3) WRITE(nout,*)'error in ems_sslv: ',rtcod
C IF(RTCOD.GE.BAD_EMSERROR) THEN
C CALL GET_EMSERROR('SSLV',RTCOD,EMSOL_ERRORMESSAGE)
C END IF
c goto 99
end if
tt1 = ems_time()
c WRITE(nout,*)tt1-tt0
tt0=tt1
CALL EMS_CA_G_N_SU_MX_PR_IFS(NINF,
& SUMPRIMALINF,
& SUMDUALINF,
& SUMRELATIVEINF,
& DSPACE,ISPACE)
call ems_nget(rtcod, dspace, emsoln, emsolnln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_nget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('NGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
c ---------------- get warmstart information --------------------
c do i=0,n+m-1
c if (i.le.2*m-1) then
c WRITE(nout,'(I,G20.10, F10.5, 3G20.10,F10.5,3G20.10)') i+1,
c & dspace(nobjective+i), dspace(ncolaux+i), dspace(ncollower+i),
c & dspace(ncolsol+i), dspace(ncolupper+i),
c & dspace(nrowaux+i), dspace(nrowlower+i), dspace(nrowacts+i),
c & dspace(nrowupper+i)
c else
c WRITE(nout,'(I,G20.10,F10.5,3G20.10)') i,
c & dspace(nobjective+i), dspace(ncolaux+i), dspace(ncollower+i),
c & dspace(ncolsol+i), dspace(ncolupper+i)
c end if
c end do
do i=1,n
sv_bs_c(i) = iand(ispace(ncolstat+i-1), bt30_32)
c WRITE(nout,'(2b33.32)') sv_bs_c(i), ispace(ncolstat+i-1)
end do
do i=1,m
sv_bs_r(i) = iand(ispace(nrowstat+i-1), bt30_32)
end do
c do i=1,n+m
c if (i.gt.2*m) then
c WRITE(nout,'(I5,4G20.10)') i, dspace(nobjective+i-1),
c & dspace(ncollower+i-1), dspace(ncolupper+i-1),
c & dspace(ncolaux+i-1)
c else
c WRITE(nout,'(I5,7G20.10)') i, dspace(nobjective+i-1),
c & dspace(ncollower+i-1), dspace(ncolupper+i-1),
c & dspace(ncolaux+i-1),
c & dspace(nrowlower+i-1), dspace(nrowupper+i-1),
c & dspace(nrowaux+i-1)
c end if
c end do
c open(11,file='lpas'//int2char(iter)//'.dat')
c do i=1,n
c write(11,'(b33.32)') sv_bs_c(i)
c end do
c do i=1,m
c write(11,'(b33.32)') sv_bs_r(i)
c end do
c close(11)
c -------------- END get warmstart information ------------------
call ems_iget(rtcod, dspace, emsoli, emsoliln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_iget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('IGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
call ems_rget(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
if (iprint.ge.2) WRITE(nout,*) 'LP exit code: ',iprobstat
nr_lp = Iiternum
if (iprobstat.eq.1) then
if (iprint.ge.2)
& WRITE(nout,*)' Infeasible LP detected => PHASE I'
mx_inf = 0.d0
do i=1,n
mx_inf = max(mx_inf, max(
& (dspace(ncolsol+i-1)-dcup(i))*dspace(ncolscales+i-1),
& (dclo(i)-dspace(ncolsol+i-1))*dspace(ncolscales+i-1)))
c WRITE(nout,*)i, dspace(ncolscales+i-1)
end do
do i=1,m
mx_inf = max(mx_inf, max(
& (dspace(nrowacts+i-1)-drup(i))*dspace(nrowscales+i-1),
& (drlo(i)-dspace(nrowacts+i-1))*dspace(nrowscales+i-1)))
c WRITE(nout,*) i, dspace(nrowscales+i-1)
end do
c WRITE(nout,*)'max c/s violation: ',mx_inf
if (f_lp_af_phI) then
if (scnd_try) then
msg = msg(1:trim77(msg))//' failed feas'
ch_fnew = ' '
hcnew = hc
ifail = 3
RTOLPINF = csr_eps*10.
goto 17
end if
WRITE(nout,*)'First Lp after phase I not feasible'
WRITE(nout,*)'Relax tolerance to ',mx_inf*1.1
RTOLPINF = mx_inf*1.1
call ems_rset(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RSET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
do i=1,n
sv_bs_c(i) = iand(ispace(ncolstat+i-1), bt30_32)
d(i) = dspace(ncolsol+i-1)
end do
do i=1,m
sv_bs_r(i) = iand(ispace(nrowstat+i-1), bt30_32)
end do
scnd_try = .true.
goto 5
end if
c dChange
c do five things after p2 solve point before entering p1
c
c get info on the point
c see if best point yet
c increment iteration counter
c print out iteration with 01 code
c check if SLP iteration limit reached
if (1==1) then
c get info on the point
normd = 0.d0
do i = 1,n
d(i) = dspace(ncolsol+i-1)
lam(i) = dspace(ncolrcosts+i-1)
xnew(i) = min(max(blo(i), x(i) + d(i)), bup(i))
normd = max(normd,abs(d(i)/s(i)))
end do
do i = 1,m
lam(n+i) = dspace(nrowduals+i-1)
end do
call objfun(xnew, n, fnew, user, iuser, flag)
call confun(xnew, n, m, cnew, a, la, user, iuser, flag)
hcnew = 0.
do i = 1,m
hcnew = hcnew +
. max(cnew(i)-bup(n+i),blo(n+i)-cnew(i),0.d0)/s(n+i)
end do
c see if best point yet
call checkBestPoint(n,m, csr_eps, fnew, hcnew, xnew,
& ispace(ncolstat:ncolstat+n-1),ispace(nrowstat:nrowstat+m-1)
& ,Bf,Bhc,Bx,sv_bs_c,Bsv_bs_r)
c increment iteration counter
iter = iter+1
c print out iteration with 01 code
if (iprint.ge.1) then
WRITE(nout,'(I3,2G16.8,2G14.8,I5,A5)')
& iter, normd, rho, fnew, hcnew,nr_lp, ' 01'
end if
CALL LOGOUT(2,dspace,bigiter,
& iter,normd,rho,fnew,hcnew,nr_lp,+01)
c check if SLP iteration limit reached
if (iter>=max_iter) then
if (iprint>=2)
& write(nout,*) ' maximal number of iterations'
msg = msg(1:trim77(msg))//' max iter'
ifail = 2
goto 15
end if
end if
c end dChange
c dChange
c also send Bf, Bhc, Bx, Bsv_bs_c, Bsv_bs_r to phaseI
c for keeping track of best point
call phaseI(n, m, maxa, ngrad, maxlws, iprint,
& ifail, maxf, rho, f, x, xnew, c, cnew,
& drlo, drup, dclo, dcup, a, la, mrow, mcol, dels,
& dobj, d, ff, fc, lws, user, iuser,
& istat, rstat, blo, bup, lam,dspace, ispace,
& pr_to_fi, nspace, iter, s,
& sv_bs_c, sv_bs_r, msg, max_iter, hc, sv_t_fi,
& se_mx_lp_it, normd, Bf, Bhc, Bx, Bsv_bs_c, Bsv_bs_r)
c end dChange
if (ifail.ne.0) then
c ... phaseI returns in f the best obtained constraint violation
c and in hc the scaled constraint violation
msg = msg(1:trim77(msg))//' infeasible'
ch_fnew = ''
c ... remember best found c/s violation (unscaled) for reporting
hc = f
hcnew = hc
chc ... Do ranging even if infeasible
call ranging(dspace, ispace, nspace, n, m, status, dcup,
& drup, dclo, drlo, dobj, result, rifail)
goto 17
end if
c dChange
c add multiplier to LP phase one for SLP phase two
c size of multiplier is 0.01 scaled by maxCost
if (1==1) then
rpweight = 0.01/maxCost
call ems_rset(rtcod, dspace, emsolr, emsolrln)
if (iprint>=2) print*, 'setting rpweight', rpweight
end if
c end dChange
f_lp_af_phI = .true.
scnd_try = .false.
n_two = 0
c ... set status vector for phase II hotstart:
c dChange
c with new phase one have a different warm start procedure
c for reentering phase two from phase one
c basically dont need to do anything:
c If a constraint is active (by necessity with zero slacks) in
c Phase I it is also active in the corresponding phase II problem.
do i=1,m
sv_bs_r(i) = ibset(sv_bs_r(i),31)
end do
c end dChange
set_stat = .true.
sizef = 1
ff(sizef) = f
fc(sizef) = hc
goto 5
elseif (iprobstat.eq.3) then
WRITE(nout,*)' Maximal LP iterations reached'
WRITE(nout,*)
& ' Number of primal/dual infeasibilities and values:'
WRITE(nout,*)' primal:',inumpinf, rsumpinf
WRITE(nout,*)' dual :',inumdinf, rsumdinf
c dChange
c if we have ems_itru.f (but we dont here)
c it is possible we have the message that max LP iterations are
c reached as we have reached a close to optimal point and ems_itru
c has caused an exit with iprobstat=3
c if that is the case then we continue problem just as before.
c In that case we are likely more likely to reach here
c end dChange
if ((inumpinf.eq.0).or.(rsumpinf.le.50.*rtolpinf)) then
c ... boldly go...
goto 10
end if
msg = ' max lp iter'
ifail = 4
goto 15
elseif (iprobstat.eq.6) then
WRITE(nout,*)' Not enough workspace'
msg = ' out of memory'
ifail = 6
goto 15
elseif (iprobstat.ne.0) then
WRITE(nout,*) ' Unexpected ifail from LP: ',iprobstat
WRITE(nout,*)
& ' Number of primal/dual infeasibilities and values:'
WRITE(nout,*)' primal:',inumpinf, rsumpinf
WRITE(nout,*)' dual :',inumdinf, rsumdinf
if ((inumpinf.eq.0).or.(rsumpinf.le.50.*rtolpinf)) then
if ((rsumdinf.le.50.*rtoldinf).or.(nr_rsv.eq.2)) then
c ... boldly go...
goto 10
end if
end if
if (nr_rsv.eq.0) then
WRITE(nout,*) '1. resolve - coldstart'
nr_rsv = 1
set_stat = .false.
goto 5
end if
if (nr_rsv.eq.1) then
WRITE(nout,*)' 2. resolve - disturbing point'
nr_rsv = 2
set_stat = .false.
do i=1,n
x(i) = x(i) + 1.d-10*ems_drand(0)
end do
goto 5
end if
WRITE(nout,*) ' Maximal number of unsuccesful resolves!'
WRITE(nout,*) ' STOP!'
goto 99
end if
c ... LP solved succesfully (sort of)
10 continue
f_lp_af_phI = .false.
if (scnd_try) then
c ... reset tolerance to original value
WRITE(nout,*)'reset tolerance to ',10.*csr_eps
RTOLPINF = csr_eps*10.
call ems_rset(rtcod, dspace, emsolr, emsolrln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_rset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('RSET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
scnd_try = .false.
end if
if (se_mx_lp_it) then
call ems_iget(rtcod, dspace, emsoli, emsoliln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_iget: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('IGET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
IMAXITER = 2*IITERNUM
se_mx_lp_it = .false.
call ems_iset(rtcod, dspace, emsoli, emsoliln)
if (rtcod.ne.0) then
WRITE(nout,*)'error in ems_iset: ',rtcod
IF(RTCOD.GE.BAD_EMSERROR) THEN
CALL GET_EMSERROR('ISET',RTCOD,EMSOL_ERRORMESSAGE)
END IF
goto 99
end if
end if
nr_rsv = 0
normd = 0.d0
do i=1,n
d(i) = dspace(ncolsol+i-1)
if (abs(d(i))-s(i)*rho.gt.1e-5) then
WRITE(nout,*) i, dclo(i), d(i), dcup(i)
end if
lam(i) = dspace(ncolrcosts+i-1)
xnew(i) = min(max(blo(i), x(i) + d(i)), bup(i))
normd = max(normd,abs(d(i)/s(i)))
end do
do i=1,m
lam(n+i) = dspace(nrowduals+i-1)
end do
q = robjvalue
oldrobjvalue = robjvalue
iter = iter + 1
c do i=1,n
c write(6,*) i, dspace(ncollower+i-1), d(i),
c & dspace(ncolupper+i-1)
c end do
c write(6,*) robjvalue
maxmu = 0.
do i=1,n
if (lam(i).le.0) then
if (abs(dcup(i)-s(i)*rho).le.1.e-12)
& maxmu = max(maxmu, abs(lam(i)))
else
if (abs(dclo(i)+s(i)*rho).le.1.e-12)
& maxmu = max(maxmu, abs(lam(i)))
end if
end do
if (iprint.ge.3)
& WRITE(nout,*) 'maximal multiplier on trust region: ',maxmu
c ---------------- calculate KT residual ----------------------
c pjp = la(0)
c d = a(1:n)
c do j=1,m
c do i=la(pjp+j),la(pjp+j+1)-1
c d(la(i)) = d(la(i)) - a(i)*lam(n+j)
c end do
c end do
c kt_rsdu = 0.d0
c do i=1,n
c d(i) = d(i) - lam(i)
c kt_rsdu = max(kt_rsdu,abs(d(i)))
c end do
c WRITE(nout,*)'LP KT res = ',kt_rsdu
if (pr_to_fi) then
open(26,file='lastiter.dat')