We will be sunsetting Advisor during Jan, 2026 and will instead be providing information in Snyk Security DB.

You can begin to take advantage of Snyk Security DB today for a unified, package-centric experience.

How to use the docplex.mp.context.Context function in docplex

To help you get started, we’ve selected a few docplex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ekhoda / optimization-tutorial / optimization_model_docplex.py View on Github external
"""
        If CPLEX is installed locally, we can use that to solve the problem.
        Otherwise, we can use DOcplexcloud. For docloud solve, we need valid 'url' and 'key'.
        Note, that if 'url' and 'key' parameters are present,
        the solve will be started on DOcplexcloud even if CPLEX is available.
            e.g. this forces the solve on DOcplexcloud:
            model.solve(url='https://foo.com', key='bar')

        Using 'docplex.mp.context.Context', it is possible to control how to solve.
        """

        if model_params['write_lp']:
            logger.info('Writing the lp file!')
            self.model.export_as_lp('./{}.lp'.format(self.model.name))

        ctx = Context()
        ctx.solver.docloud.url = model_params['url']
        ctx.solver.docloud.key = model_params['api_key']
        agent = 'docloud' if model_params['cplex_cloud'] else 'local'

        # There are several ways to set the parameters. Here are two ways:
        # method 1:
        if model_params['mip_gap']:
            self.model.parameters.mip.tolerances.mipgap = model_params['mip_gap']
        if model_params['time_limit']:
            self.model.set_time_limit(model_params['time_limit'])

        # # method 2:
        # cplex_parameters = {'mip.tolerances.mipgap': model_params['mip_gap'],
        #                     'timelimit': model_params['time_limit']}
        # ctx.update(cplex_parameters, create_missing_nodes=True)

docplex

The IBM Decision Optimization CPLEX Modeling for Python

Apache-2.0
Latest version published 6 months ago

Package Health Score

65 / 100
Full package analysis