Skip to content

Commit

Permalink
PY3: Use print function
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhelmus committed Oct 2, 2015
1 parent 347d8c0 commit 1b798eb
Show file tree
Hide file tree
Showing 24 changed files with 334 additions and 312 deletions.
13 changes: 7 additions & 6 deletions cylp/cy/CyClpPrimalColumnSteepest.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cython: embedsignature=True

from __future__ import print_function


#cimport cClpPrimalColumnSteepest
Expand All @@ -14,12 +15,12 @@ cdef class ClpPrimalColumnSteepest(ClpPrimalColumnPivot):


#cdef Rectangle r = Rectangle(1, 2, 3, 4)
#print r
#print "Original area:", r.getArea()
#print(r)
#print("Original area:", r.getArea())
#r.move(1,2)
#print r
#print "Area is invariante under rigid motions:", r.getArea()
#print(r)
#print("Area is invariante under rigid motions:", r.getArea())
#r += Rectangle(0,0,1,1)
#print r
#print "Now the aread is:", r.getArea()
#print(r)
#print("Now the aread is:", r.getArea())

11 changes: 6 additions & 5 deletions cylp/cy/CyClpSimplex.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# cython: profile=True
# cython: embedsignature=True

from __future__ import print_function

from exceptions import TypeError
import inspect
Expand Down Expand Up @@ -1481,7 +1482,7 @@ cdef class CyClpSimplex:
'''
name, ext = os.path.splitext(filename)
if ext not in ['.mps', '.qps']:
print 'unrecognised extension %s' % ext
print('unrecognised extension %s' % ext)
return -1

if ext == '.mps':
Expand Down Expand Up @@ -1750,7 +1751,7 @@ cdef class CyClpSimplex:
numberPasses, dropNames, doRowObjective)
s = CyClpSimplex()
if model == NULL:
print "Presolve says problem infeasible."
print("Presolve says problem infeasible.")
return s

s.setCppSelf(model)
Expand All @@ -1767,7 +1768,7 @@ cdef class CyClpSimplex:
feasibilityTolerance, keepIntegers,
numberPasses, dropNames, doRowObjective)
if ret == -2000:
print "Presolve says problem infeasible."
print("Presolve says problem infeasible.")
return -2000

return problemStatus[ret]
Expand All @@ -1779,7 +1780,7 @@ cdef class CyClpSimplex:
feasibilityTolerance, keepIntegers,
numberPasses, dropNames, doRowObjective)
if ret == -2000:
print "Presolve says problem infeasible."
print("Presolve says problem infeasible.")
return -2000

return problemStatus[ret]
Expand Down Expand Up @@ -2110,7 +2111,7 @@ cdef class CyClpSimplex:
# #When you create LP using CoinModel getComplementarityList
# #cannot return with the right size
# #cl = self.getComplementarityList()
# #print var1, var2, len(cl)
# #print(var1, var2, len(cl))
# #cl[var1], cl[var2] = var2, var1
# self.CppSelf.setComplement(var1, var2)

Expand Down
3 changes: 2 additions & 1 deletion cylp/cy/CyCoinIndexedVector.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cython: embedsignature=True

from __future__ import print_function

cdef class CyCoinIndexedVector:
'''
Expand Down Expand Up @@ -46,7 +47,7 @@ cdef class CyCoinIndexedVector:
#self.CppSelf.setItem(key, value)

#def __setslice__(self, rg, val):
#print rg, val
#print(rg, val)

def clear(self):
self.CppSelf.clear()
Expand Down
7 changes: 4 additions & 3 deletions cylp/cy/CyPEPivot.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cython: embedsignature=True

from __future__ import print_function

import numpy as np
cimport numpy as np
Expand Down Expand Up @@ -67,13 +68,13 @@ cdef class CyPEPivot(CyClpPrimalColumnPivotBase):
maxInd = ind

if maxCompInd != -1 and maxCompRc > 0.4 * maxRc:
print s.iteration, ' : comp selected', maxCompInd
print(s.iteration, ' : comp selected', maxCompInd)
return maxCompInd

print s.iteration, ' : incomp selected', maxInd
print(s.iteration, ' : incomp selected', maxInd)
self.updateP()
self.updateW()
#print 'updated'
#print('updated')
return maxInd

cdef CyClpPrimalColumnPivot* clone(self, bint copyData):
Expand Down
5 changes: 3 additions & 2 deletions cylp/cy/CySolve.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import print_function
import sys
from cylp.cy.CyTest import CySolve

if __name__ == '__main__':
if len(sys.argv) < 3:
print 'Arg error: Usage example: python CySolve.py lp.mps d'
print('Arg error: Usage example: python CySolve.py lp.mps d')
sys.exit(0)
method = sys.argv[2]
if method == 'p':
print 'Positive edge is not implemented in Cython yet. Quitting.'
print('Positive edge is not implemented in Cython yet. Quitting.')
sys.exit(1)
CySolve(sys.argv[1], sys.argv[2])
3 changes: 2 additions & 1 deletion cylp/cy/CyTest.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys
from time import clock
from cylp.cy.CyClpSimplex cimport CyClpSimplex
Expand All @@ -22,5 +23,5 @@ def CySolve(fileName, method):

start = clock()
s.primal()
print 'Exec time: ', clock() - start
print('Exec time: ', clock() - start)
return s.objectiveValue
3 changes: 2 additions & 1 deletion cylp/input/fileDownloader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import urllib
f = urllib.urlopen("http://www.netlib.org/lp/data/")
lines = f.read().splitlines()
Expand All @@ -8,7 +9,7 @@
line = line[(ind_start + 1):]
ind_end = line.index('<')
line = line[:ind_end]
print 'Downloading ', line, '...'
print('Downloading ', line, '...')
urllib.urlretrieve("http://www.netlib.org/lp/data/" + line, line)

f.close()
5 changes: 3 additions & 2 deletions cylp/input/netlib/fileDownloader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import urllib
import os

Expand All @@ -10,9 +11,9 @@
line = line[(ind_start+1):]
ind_end = line.index('<')
line = line[:ind_end]
print 'Downloading ', line, '...'
print('Downloading ', line, '...')
urllib.urlretrieve("http://www.netlib.org/lp/data/"+line, line)
print 'emps-ing ', line, '...'
print('emps-ing ', line, '...')
os.system('./emps ' + line + ' > ' + line + '.mps')

f.close()
11 changes: 6 additions & 5 deletions cylp/py/PySolve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys
from time import clock
import cProfile
Expand Down Expand Up @@ -27,7 +28,7 @@ def solve(filename, method):
elif method == 'p':
pivot = PositiveEdgePivot(s)
else:
print 'Unkown solution method.'
print('Unkown solution method.')
sys.exit(1)

s.setPivotMethod(pivot)
Expand All @@ -36,14 +37,14 @@ def solve(filename, method):

start = clock()
s.primal()
print 'Problem solved in %g seconds.' % (clock() - start)
print('Problem solved in %g seconds.' % (clock() - start))
return s.objectiveValue


# s.copyInIntegerInformation(np.array(s.nCols * [True], np.uint8))
# #s.setInteger(100)
#
# print "Solving relaxation"
# print("Solving relaxation")
# cbcModel = s.getCbcModel()
# from SimpleNodeCompare import SimpleNodeCompare
# from CyCgl import CyCglGomory, CyCglClique, CyCglKnapsackCover
Expand All @@ -63,11 +64,11 @@ def solve(filename, method):
#
#
# cbcModel.branchAndBound()
# print cbcModel.primalVariableSolution
# print(cbcModel.primalVariableSolution)

if __name__ == '__main__':
if len(sys.argv) < 3:
print 'Usage example (Dantzig pivot): PySolve file.mps d'
print('Usage example (Dantzig pivot): PySolve file.mps d')
sys.exit(1)
solve(sys.argv[1], sys.argv[2])
#cProfile.run('solve(sys.argv[1], sys.argv[2])')
29 changes: 15 additions & 14 deletions cylp/py/QP/GQP.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import QP
import numpy as np
import Constants
Expand Down Expand Up @@ -125,18 +126,18 @@ def checkInvars(self):
# Make sure that Q2 and J2 are alright
if (abs((self.L.T * self.J2).T * Q1) > 0.1).any() or \
(abs(Q1.T * (self.L.T * self.J2)) > 0.1).any():
#print "post1" , abs((self.L.T * self.J2).T * Q1)
#print abs(Q1.T * (self.L.T * self.J2))
#print "--"
#print("post1" , abs((self.L.T * self.J2).T * Q1))
#print(abs(Q1.T * (self.L.T * self.J2)))
#print("--")
ret = False

# Make sure that R is OK and N_star IS the pseudo-inverse of N
N_star_N = (R.I * self.J1.T) * (self.CT[[i for i in self.A], :].T)
iden = np.matrix(np.identity(self.q, float))

if (abs(N_star_N) - iden > 0.5).any():
#print "post2" , abs(N_star_N) - iden
#print "--"
#print("post2" , abs(N_star_N) - iden)
#print("--")
ret = False
return ret

Expand Down Expand Up @@ -247,12 +248,12 @@ def dual(self, verbose):
while True:
iteration += 1
if verbose:
print '-----------------------------------------'
print 'iteration = ', iteration
print('-----------------------------------------')
print('iteration = ', iteration)

#print "obj value=" , f
print "active set:"
print self.A
#print("obj value=" , f)
print("active set:")
print(self.A)
p = self.getMostViolatedConst(self.x)

if p == -1:
Expand Down Expand Up @@ -296,7 +297,7 @@ def dual(self, verbose):
return 'infeasible', -1, -1
elif t2 == -1:
if verbose:
print "taking a partial step_1"
print("taking a partial step_1")
uPlus += t * dual_dir
#we'll not use Q_tilde here. It is used in the PAS method.
uPlus, Q_tilde = self.removeConstraint(k, uPlus)
Expand All @@ -309,15 +310,15 @@ def dual(self, verbose):

if abs(t - t2) <= Constants.EPSILON:
if verbose:
print "taking a full step "
print 'blocking constriant : ', p
print("taking a full step ")
print('blocking constriant : ', p)
self.u = uPlus
self.addConstraint(p)
#We took the full step, going back to step 1
break
else:
if verbose:
print "taking a partial step_2"
print("taking a partial step_2")
#t == t1
uPlus, Q_tilde = self.removeConstraint(k, uPlus)
continue
Expand Down
Loading

0 comments on commit 1b798eb

Please sign in to comment.