GAMS [ Home | Downloads | Documentation | Solvers | APIs | Tools | Model Libraries | Resources | Sales | Support | Contact Us | Search ]

GAMS Python API - Tutorial and Examples
clad.py File Reference

This example demonstrates how to implement a complex termination criterion for a difficult MIP using GAMS/Cplex. More...

Go to the source code of this file.

Variables

 clad.ws = GamsWorkspace(system_directory = sys.argv[1])
 
 clad.j1 = ws.add_job_from_file("clad")
 
 clad.f = open(os.path.join(ws.working_directory, "cplex.opt"), "w")
 
 clad.opt = ws.add_options()
 
 clad.mip
 
 clad.optfile
 
 clad.solvelink
 
 clad.sw = StringIO()
 
 clad.opt_thread = Thread(target=j1.run, args=(opt,), kwargs={"output":sw})
 
list clad.steps
 
float clad.prev_step = 0.0
 
 clad.log = sw.getvalue()
 

Detailed Description

This example demonstrates how to implement a complex termination criterion for a difficult MIP using GAMS/Cplex.

We would like to achieve a globally optimal solution (relative gap 0%) but if solution time becomes larger than n1 seconds, we can compromise for a 10% gap, and if this is not achieved after n2 seconds, we compromise for a 20% gap, and again if this is not accomplished in n3 seconds we take whatever the solver has done so far and terminate the solve. This is implemented by executing GamsJob.run in an independent thread and providing new tolerances for the relative gap in the main thread by supplying new GAMS/Cplex option files and triggers the processing of the new tolerance option by GAMS/Cplex through the GamsJob.interrupt method.

Definition in file clad.py.