Changeset 4535
 Timestamp:
 08/01/11 15:53:40 (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

coopr.pyomo/trunk/coopr/pyomo/tests/io/test_writers.py
r4532 r4535 9 9 asl = coopr.plugins.mip.ASL(keepFiles=True, options={'solver':'cplexamp'}) 10 10 cplexamp_available = cplex_available and (not asl.executable() is None) and asl.available(False) 11 try: 12 import cplex 13 cplexpy_available = True 14 except pyutilib.common.ApplicationError: 15 cplexpy_available = False 11 16 except pyutilib.common.ApplicationError: 12 17 cplexamp_available=False … … 17 22 asl = coopr.plugins.mip.ASL(keepFiles=True, options={'solver':'gurobi_ampl'}) 18 23 gurobi_ampl_available = gurobi_available and (not asl.executable() is None) and asl.available(False) 24 try: 25 import gurobipy 26 gurobi_py_available = True 27 except pyutilib.common.ApplicationError: 28 gurobi_py_available = False 19 29 except pyutilib.common.ApplicationError: 20 30 gurobi_ampl_available=False … … 23 33 24 34 @unittest.skipIf(not (cplex_available and cplexamp_available),"The 'cplex' executable is not available") 25 def testCPLEX (self):35 def testCPLEXnl(self): 26 36 instancelp=model.create() 27 37 instancenl=model.create() 28 instancepy=model.create()29 38 30 39 optlp=SolverFactory("cplex",solver_io="lp") 31 40 optnl=SolverFactory("cplex",solver_io="nl") 32 optpy=SolverFactory("cplex",solver_io="python")33 41 34 42 resultslp=optlp.solve(instancelp) 35 43 resultsnl=optnl.solve(instancenl) 36 resultspy=optpy.solve(instancepy)37 44 38 45 instancelp.load(resultslp) 39 46 instancenl.load(resultsnl) 40 instancepy.load(resultspy)41 47 42 48 self.assertEqual(instancelp.obj(),instancenl.obj()) 43 49 for i in instancelp.variables(): 44 50 self.assertEqual(instancelp.variables()[i](),instancenl.variables()[i]()) 51 52 @unittest.skipIf(not (cplex_available and cplexpy_available),"The 'cplex' python interface is not available") 53 def testCPLEXpy(self): 54 instancelp=model.create() 55 instancepy=model.create() 56 57 optlp=SolverFactory("cplex",solver_io="lp") 58 optpy=SolverFactory("cplex",solver_io="python") 59 60 resultslp=optlp.solve(instancelp) 61 resultspy=optpy.solve(instancepy) 62 63 instancelp.load(resultslp) 64 instancepy.load(resultspy) 65 45 66 self.assertEqual(instancelp.obj(),instancepy.obj()) 46 67 for i in instancelp.variables(): … … 48 69 49 70 @unittest.skipIf(not (gurobi_available and gurobi_ampl_available),"The 'gurobi executable is not available") 50 def testGUROBI (self):71 def testGUROBInl(self): 51 72 instancelp=model.create() 52 73 instancenl=model.create() 53 instancepy=model.create()54 74 55 75 #Deactivate quadratic constraints  gurobi currently doesn't support those 56 76 instancelp.constr.active = False 57 77 instancelp.preprocess() 58 78 instancenl.constr.active = False 59 instancenl.preprocess() 60 instancepy.constr.active = False 61 instancepy.preprocess() 79 instancenl.preprocess() 62 80 63 81 optlp=SolverFactory("gurobi",solver_io="lp") 64 optnl=SolverFactory("gurobi",solver_io="nl") 65 optpy=SolverFactory("gurobi",solver_io="python") 82 optnl=SolverFactory("gurobi_ampl",solver_io="nl") 66 83 67 84 resultslp=optlp.solve(instancelp) 68 85 resultsnl=optnl.solve(instancenl) 69 resultspy=optpy.solve(instancepy)70 86 71 87 instancelp.load(resultslp) 72 88 instancenl.load(resultsnl) 73 instancepy.load(resultspy)74 89 75 90 self.assertEqual(instancelp.obj(),instancenl.obj()) 76 91 for i in instancelp.variables(): 77 92 self.assertEqual(instancelp.variables()[i](),instancenl.variables()[i]()) 93 94 @unittest.skipIf(not (gurobi_available and gurobi_py_available),"The 'gurobi python interface is not available") 95 def testGUROBIpy(self): 96 instancelp=model.create() 97 instancepy=model.create() 98 99 #Deactivate quadratic constraints  gurobi currently doesn't support those 100 instancelp.constr.active = False 101 instancelp.preprocess() 102 instancepy.constr.active = False 103 instancepy.preprocess() 104 105 optlp=SolverFactory("gurobi",solver_io="lp") 106 optpy=SolverFactory("gurobi",solver_io="python") 107 108 resultslp=optlp.solve(instancelp) 109 resultspy=optpy.solve(instancepy) 110 111 instancelp.load(resultslp) 112 instancepy.load(resultspy) 113 78 114 self.assertEqual(instancelp.obj(),instancepy.obj()) 79 115 for i in instancelp.variables():
Note: See TracChangeset
for help on using the changeset viewer.