switch_model/utilities/gurobi_aug.py
def _warm_start(self):
        """Override the default _warm_start function that only works for MIP."""
        if self._solver_model.IsMIP:
            return super(GurobiAugmented, self)._warm_start()

        time = StepTimer(msg="Loading warm start data...")
        if self._read_warm_start is None:
            raise Exception("Must specify warm_start_in= when running solve()")

        # For some reason this is required. Without it warnings get thrown.
        # It seems like to set VBasis/CBasis the variables needs to already be in
        # the Gurobi model (hence why we need to call update()).
        self._update()

        # Load the basis information from a previous pickle file
        with open(self._read_warm_start, "rb") as f:
            warm_start_data = pickle.load(f)

        # Keep track of any variables or constraints that weren't in the pickle file
        error = None
        error_count = 0
        # Specify which Gurobi Attributes we should set depending on whether we are using C/V Basis or P/D Start.
        if warm_start_data.use_c_v_basis:
            var_attr = self._gurobipy.GRB.Attr.VBasis
            const_attr = self._gurobipy.GRB.Attr.CBasis
            var_default = GurobiAugmented.VBASIS_DEFAULT
            const_default = GurobiAugmented.CBASIS_DEFAULT
        else:
            var_attr = self._gurobipy.GRB.Attr.PStart
            const_attr = self._gurobipy.GRB.Attr.DStart
            var_default = 0
            const_default = 0
        # Set the VBasis or PStart for each variable
        for pyomo_var, gurobi_var in self._pyomo_var_to_solver_var_map.items():
            try:
                val = warm_start_data.var_data.get_component(pyomo_var)
            except KeyError as e:
                val, error = var_default, e
                error_count += 1
            gurobi_var.setAttr(var_attr, val)

        # Set the CBasis or DStart for each constraint
        for pyomo_const, gurobi_const in self._pyomo_con_to_solver_con_map.items():
            try:
                val = warm_start_data.const_data.get_component(pyomo_const)
            except KeyError as e:
                val, error = const_default, e
                error_count += 1
            gurobi_const.setAttr(const_attr, val)

        if error is not None:
            warnings.warn(
                f"{error} and {error_count - 1} others were not found in warm start pickle file. "
                f"If many variables or constraints are not found it may be more efficient to not use --warm-start.")

        print(f"Time spent warm starting: {time.step_time_as_str()}")
Override the default _warm_start function that only works for MIP.
Override the default _warm_start function that only works for MIP.
Override the default _warm_start function that only works for MIP .
def _warm_start(self):
        if self._solver_model.IsMIP:
            return super(GurobiAugmented, self)._warm_start()
        time = StepTimer(msg="Loading warm start data...")
        if self._read_warm_start is None:
            raise Exception("Must specify warm_start_in= when running solve()")
        self._update()
        with open(self._read_warm_start, "rb") as f:
            warm_start_data = pickle.load(f)
        error = None
        error_count = 0
        if warm_start_data.use_c_v_basis:
            var_attr = self._gurobipy.GRB.Attr.VBasis
            const_attr = self._gurobipy.GRB.Attr.CBasis
            var_default = GurobiAugmented.VBASIS_DEFAULT
            const_default = GurobiAugmented.CBASIS_DEFAULT
        else:
            var_attr = self._gurobipy.GRB.Attr.PStart
            const_attr = self._gurobipy.GRB.Attr.DStart
            var_default = 0
            const_default = 0
        for pyomo_var, gurobi_var in self._pyomo_var_to_solver_var_map.items():
            try:
                val = warm_start_data.var_data.get_component(pyomo_var)
            except KeyError as e:
                val, error = var_default, e
                error_count += 1
            gurobi_var.setAttr(var_attr, val)
        for pyomo_const, gurobi_const in self._pyomo_con_to_solver_con_map.items():
            try:
                val = warm_start_data.const_data.get_component(pyomo_const)
            except KeyError as e:
                val, error = const_default, e
                error_count += 1
            gurobi_const.setAttr(const_attr, val)
        if error is not None:
            warnings.warn(
                f"{error} and {error_count - 1} others were not found in warm start pickle file. "
                f"If many variables or constraints are not found it may be more efficient to not use --warm-start.")
        print(f"Time spent warm starting: {time.step_time_as_str()}")
def _warm_start ( self ) : if self . _solver_model . IsMIP : return super ( GurobiAugmented , self ) . _warm_start ( ) time = StepTimer ( msg = "Loading warm start data..." ) if self . _read_warm_start is None : raise Exception ( "Must specify warm_start_in= when running solve()" ) self . _update ( ) with open ( self . _read_warm_start , "rb" ) as f : warm_start_data = pickle . load ( f ) error = None error_count = 0 if warm_start_data . use_c_v_basis : var_attr = self . _gurobipy . GRB . Attr . VBasis const_attr = self . _gurobipy . GRB . Attr . CBasis var_default = GurobiAugmented . VBASIS_DEFAULT const_default = GurobiAugmented . CBASIS_DEFAULT else : var_attr = self . _gurobipy . GRB . Attr . PStart const_attr = self . _gurobipy . GRB . Attr . DStart var_default = 0 const_default = 0 for pyomo_var , gurobi_var in self . _pyomo_var_to_solver_var_map . items ( ) : try : val = warm_start_data . var_data . get_component ( pyomo_var ) except KeyError as e : val , error = var_default , e error_count += 1 gurobi_var . setAttr ( var_attr , val ) for pyomo_const , gurobi_const in self . _pyomo_con_to_solver_con_map . items ( ) : try : val = warm_start_data . const_data . get_component ( pyomo_const ) except KeyError as e : val , error = const_default , e error_count += 1 gurobi_const . setAttr ( const_attr , val ) if error is not None : warnings . warn ( f"{error} and {error_count - 1} others were not found in warm start pickle file. " f"If many variables or constraints are not found it may be more efficient to not use --warm-start." ) print ( f"Time spent warm starting: {time.step_time_as_str()}" )
Override the default _warm_start function that only works for MIP.
Override the default _warm_start function that only works for MIP .
"""Override the default _warm_start function that only works for MIP.""" # For some reason this is required. Without it warnings get thrown. # It seems like to set VBasis/CBasis the variables needs to already be in # the Gurobi model (hence why we need to call update()). # Load the basis information from a previous pickle file # Keep track of any variables or constraints that weren't in the pickle file # Specify which Gurobi Attributes we should set depending on whether we are using C/V Basis or P/D Start. # Set the VBasis or PStart for each variable # Set the CBasis or DStart for each constraint
self