简体   繁体   中英

how to set the memory parameter in a Gurobi model

I would like to allocate a large memory for a model created using Python API. When I try to set MemLimit parameter, I do receive an error.

import gurobipy as gp
from gurobipy import GRB

my_model = gp.Model('myModel')
my_model.setParam('MemLimit', 1e+11)
gurobipy.GurobiError: Unable to modify parameter MemLimit after environment started

Could soemone show how to create an empty enviroment, set the memory parameter and then connect that with the model please?

There are two default behaviors that prevent you from setting the MemLimit parameter in the the Gurobi Python API (gurobipy):

  1. gurobipy creates a default Gurobi environment
  2. You cannot set the MemLimit parameter once the environment has been created

There are two alternate ways to handle this:

  1. Use an environment file: Create a gurobi.env file in your working directory that contains the line:
MemLimit 1e11
  1. Use an explicit Gurobi Env object like this:
import gurobipy as gp
from gurobipy import GRB

e = gp.Env("gurobi.log", params={'MemLimit': 1e11})
my_model = gp.Model('myModel', env=e)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM