File: StatisticReader_PrimalBoundHistoryReader.py

package info (click to toggle)
scip 10.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,156 kB
  • sloc: ansic: 716,600; cpp: 41,095; awk: 9,195; sh: 4,918; makefile: 4,044; python: 2,076; perl: 731; xml: 660; java: 314; php: 24; lisp: 15
file content (179 lines) | stat: -rw-r--r-- 7,736 bytes parent folder | download
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
from StatisticReader import StatisticReader
import re

class PrimalBoundHistoryReader(StatisticReader):
   name = 'PrimalBoundHistoryReader'
   regular_exp =  ' time | node  | left  |LP iter|LP it/n| mem |mdpt |frac |vars |cons |cols |rows |cuts |confs|strbr|  dualbound   | primalbound  |  gap   '
   columnwidth = 20
   datakey = 'PrimalBoundHistory'
   columnheaderstr = 'PrimalBoundHistory'.rjust(columnwidth)
   inTable = False
   lastPrimalBound = '--'
   listOfPoints = []
   easyCPLEX= True
   totalnumberofsols = 0
       
   testnumberofsols = 0
   gurobiextralist = []

   def extractStatistic(self, line):
      if StatisticReader.solvertype == StatisticReader.SOLVERTYPE_SCIP:
         if self.regular_exp in line:
            self.inTable = True
         elif self.inTable and re.search("s\|", line):
   #         print line
            mylist = line.split()
   #         print mylist
            if len(mylist) == 0:
               return None
            if re.search('s\|', mylist[0]):
               rawtime = mylist[0].split('s|')[0]
            else:
               assert(re.search('s|', mylist[1]))
               rawtime = mylist[1].split('s|')[0]
                     
            rawtime = re.split('[a-zA-Z*]', rawtime)
                  
            pointInTime = rawtime[len(rawtime) - 1]
            if re.search("\|",mylist[len(mylist) - 1]):
               PrimalBound = mylist[len(mylist) - 2].strip("|")
            else:
               PrimalBound = mylist[len(mylist) - 3].strip("|")
   #         print pointInTime, PrimalBound
            if PrimalBound != self.lastPrimalBound:
               self.lastPrimalBound = PrimalBound
               try:
                   self.listOfPoints.append((float(pointInTime),float(PrimalBound)))
               except ValueError:
                   pass

         elif "SCIP Status" in line and self.inTable:
            self.inTable = False

      elif StatisticReader.solvertype == StatisticReader.SOLVERTYPE_GUROBI:
         if "Found heuristic solution" in line:
            self.gurobiextralist.append(line.split()[-1])
         if "Expl Unexpl |  Obj  Depth" in line:
            self.inTable = True
         elif self.inTable and line.endswith("s\n") and self.gurobiextralist != []:
#            print "+++++++++++++++++++++"
            pointInTime = line.split()[-1].strip("s")
            self.listOfPoints.append((float(pointInTime), float(self.gurobiextralist[-1])))
            self.gurobiextralist = []
         elif self.inTable and line.startswith("H") or line.startswith("*"):
            self.readBoundAndTime(line, -5, -1, timestripchars="s")
             
         elif "Cutting planes:" in line and self.inTable:
            self.inTable = False
         elif self.gurobiextralist != [] and "Explored " in line:
#            print "-------------------------"
            pointInTime = line.split()[-2]
            self.listOfPoints.append((float(pointInTime), float(self.gurobiextralist[-1])))
            self.gurobiextralist = []
          
         return None
            
      elif StatisticReader.solvertype == StatisticReader.SOLVERTYPE_CBC:
         if "Integer solution of " in line:
            self.readBoundAndTime(line, 4, -2, timestripchars="(")
             
         return None
          
      elif StatisticReader.solvertype == StatisticReader.SOLVERTYPE_XPRESS:
         if "BestSoln" in line:
            self.xpresscutidx = line.index("BestSoln") + len("BestSoln")
         elif line.startswith("+") or line.startswith("*"):
            self.readBoundAndTime(line, -1, -1, cutidx=self.xpresscutidx)
         elif line.startswith(" *** Heuristic solution found: "):
            self.readBoundAndTime(line, -4, -2)
             
      elif StatisticReader.solvertype == StatisticReader.SOLVERTYPE_CPLEX:
         if "Solution pool: " in line:
            self.testnumberofsols = int(line.split()[2])
            # assert len(self.listOfPoints) >= self.testnumberofsols
         if self.easyCPLEX and "Found incumbent of value" in line:
            splitline = line.split()
            self.readBoundAndTime(line, splitline.index("Found") + 4, splitline.index("Found") + 6)
         elif not self.easyCPLEX:
            if "Welcome to IBM(R) ILOG(R) CPLEX(R)" in line:
               self.lastelapsedtime = 0.0
               self.nnodessincelastelapsedtime = 0
               self.lastnnodes = 0
               self.cpxprimals = []
                
            if "   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap" in line:
               self.inTable = True

               self.cpxbestintegeridx = line.index("Best Integer") + 11
                
            elif self.inTable and ("cuts applied:" in line or "Root node processing" in line):
               self.inTable = False
            elif self.inTable and "Repeating presolve." in line:
               self.inTable = False
            elif self.inTable and "Covers:" in line:
               self.inTable = False
            elif self.inTable and len(line) > 0 and line.startswith(" ") or line.startswith("*"):
               if line=="\n":
                  return None
               nodeinlineidx = 7
               while line[nodeinlineidx] != " " and line[nodeinlineidx] != "+":
                  nodeinlineidx += 1
               nnodes = int(line[:nodeinlineidx].split()[-1].strip('*+')) + 1
               if line.startswith("*") or line.startswith("+"):
                  print line
                  primalbound = float(line.split()[-4])
                  print primalbound, nnodes
                  self.cpxprimals.append((nnodes, primalbound))
               self.lastnnodes = nnodes
            elif "Elapsed time = " in line:
               thetime = float(line.split()[3])
               self.processCpxprimals(thetime)
                
               self.nnodessincelastelapsedtime = self.lastnnodes
               self.lastelapsedtime = thetime

            elif "Solution time =" in line:
               thetime = float(line.split()[3])
               self.processCpxprimals(thetime)
       
      return None
       
   def readBoundAndTime(self, line, boundidx, timeidx, timestripchars="", cutidx=-1):
      splitline = line.split()
        
      primalbound = line[:cutidx].split()[boundidx]
        
      pointInTime = splitline[timeidx].strip(timestripchars)
             
#        print line 
#        print pointInTime, primalbound
        
        
      self.lastPrimalBound = primalbound
      self.listOfPoints.append((float(pointInTime), float(primalbound)))
       
   def processCpxprimals(self, currenttime):
      solvednodes = (self.lastnnodes - self.nnodessincelastelapsedtime)
      timespentonnode = (currenttime - self.lastelapsedtime)/max(1.0, float(solvednodes))
      assert currenttime >= self.lastelapsedtime
      for node, bound in self.cpxprimals:
         estimatedtime = self.lastelapsedtime + (node - self.nnodessincelastelapsedtime) * timespentonnode
                   
         if bound != self.lastPrimalBound:
            self.lastPrimalBound = bound
            if len(self.listOfPoints) > 0:
               othertime, otherbound = self.listOfPoints[-1]
               assert othertime <= estimatedtime
               self.listOfPoints.append((float(estimatedtime), float(bound)))
               
      self.cpxprimals = []

   def execEndOfProb(self):
      self.inTable = False
      self.testnumberofsols = 0
      theList = self.listOfPoints[:]
      self.listOfPoints = []
      self.lastPrimalBound = '--'
      PrimalBoundHistoryReader.totalnumberofsols += len(theList)
      #print " solutions added:", PrimalBoundHistoryReader.totalnumberofsols
      return theList