Commit 7dccf356 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Make code compatible with python3.

parent 1410604e
...@@ -23,15 +23,15 @@ class Display(): ...@@ -23,15 +23,15 @@ class Display():
try: try:
self.viewer=gepetto.corbaserver.Client() self.viewer=gepetto.corbaserver.Client()
except: except:
print "Error while starting the viewer client. " print("Error while starting the viewer client. ")
print "Check whether Gepetto-viewer is properly started" print("Check whether Gepetto-viewer is properly started")
# Open a window for displaying your model. # Open a window for displaying your model.
try: try:
# If the window already exists, do not do anything. # If the window already exists, do not do anything.
windowID = self.viewer.gui.getWindowID (windowName) windowID = self.viewer.gui.getWindowID (windowName)
print "Warning: window '"+windowName+"' already created." print("Warning: window '"+windowName+"' already created.")
print "The previously created objects will not be destroyed and do not have to be created again." print("The previously created objects will not be destroyed and do not have to be created again.")
except: except:
# Otherwise, create the empty window. # Otherwise, create the empty window.
windowID = self.viewer.gui.createWindow (windowName) windowID = self.viewer.gui.createWindow (windowName)
......
...@@ -19,21 +19,21 @@ class CallbackLogger: ...@@ -19,21 +19,21 @@ class CallbackLogger:
def __init__(self): def __init__(self):
self.nfeval = 1 self.nfeval = 1
def __call__(self,x): def __call__(self,x):
print '===CBK=== {0:4d} {1: 3.6f} {2: 3.6f} {3: 3.6f}'.format(self.nfeval, x[0], x[1], cost(x)) print('===CBK=== {0:4d} {1: 3.6f} {2: 3.6f} {3: 3.6f}'.format(self.nfeval, x[0], x[1], cost(x)))
self.nfeval += 1 self.nfeval += 1
x0 = np.array([0.0,0.0]) x0 = np.array([0.0,0.0])
# Optimize cost without any constraints in BFGS, with traces. # Optimize cost without any constraints in BFGS, with traces.
xopt_bfgs = fmin_bfgs(cost, x0, callback=CallbackLogger()) xopt_bfgs = fmin_bfgs(cost, x0, callback=CallbackLogger())
print '\n *** Xopt in BFGS = ',xopt_bfgs,'\n\n\n\n' print('\n *** Xopt in BFGS = ',xopt_bfgs,'\n\n\n\n')
# Optimize cost without any constraints in CLSQ # Optimize cost without any constraints in CLSQ
xopt_lsq = fmin_slsqp(cost,[-1.0,1.0], iprint=2, full_output=1) xopt_lsq = fmin_slsqp(cost,[-1.0,1.0], iprint=2, full_output=1)
print '\n *** Xopt in LSQ = ',xopt_lsq,'\n\n\n\n' print('\n *** Xopt in LSQ = ',xopt_lsq,'\n\n\n\n')
# Optimize cost with equality and inequality constraints in CLSQ # Optimize cost with equality and inequality constraints in CLSQ
xopt_clsq = fmin_slsqp(cost,[-1.0,1.0], xopt_clsq = fmin_slsqp(cost,[-1.0,1.0],
f_eqcons=constraint_eq, f_ieqcons=constraint_ineq, f_eqcons=constraint_eq, f_ieqcons=constraint_ineq,
iprint=2, full_output=1) iprint=2, full_output=1)
print '\n *** Xopt in c-lsq = ',xopt_clsq,'\n\n\n\n' print('\n *** Xopt in c-lsq = ',xopt_clsq,'\n\n\n\n')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment