switch_model/utilities/gurobi_aug.py
def _save_warm_start(self, save_c_v_basis):
        """Create a pickle file containing the CBasis/VBasis information."""
        # Setup our data objects
        n_var = len(self._pyomo_var_to_solver_var_map)
        n_const = len(self._pyomo_con_to_solver_con_map)

        if save_c_v_basis is None:
            save_c_v_basis = True

        if save_c_v_basis:
            var_data = VBasis(n=n_var)
            const_data = CBasis(n=n_const)
            var_attr = self._gurobipy.GRB.Attr.VBasis
            const_attr = self._gurobipy.GRB.Attr.CBasis
        else:
            var_data = PicklableData(n=n_var, val_dtype=float)
            const_data = PicklableData(n=n_const, val_dtype=float)
            var_attr = self._gurobipy.GRB.Attr.X
            const_attr = self._gurobipy.GRB.Attr.Pi

        try:
            # Save the variable data
            for pyomo_var, gurobipy_var in self._pyomo_var_to_solver_var_map.items():
                var_data.save_component(pyomo_var, gurobipy_var.getAttr(var_attr))
        except AttributeError as e:
            if save_c_v_basis:
                # If we get an Attribute error and using c_v_basis it's probably cause
                # there was no crossover. In this case we retry without c_v_basis
                return self._save_warm_start(save_c_v_basis=False)
            raise e

        # Save the constraint data
        for pyomo_const, gurobipy_const in self._pyomo_con_to_solver_con_map.items():
            const_data.save_component(pyomo_const, gurobipy_const.getAttr(const_attr))

        # Dump the data to a pickle file
        with open(self._write_warm_start, "wb") as f:
            data = WarmStartData(var_data, const_data, save_c_v_basis)
            pickle.dump(data, f)
Create a pickle file containing the CBasis/VBasis information.
Create a pickle file containing the CBasis/VBasis information.
Create a pickle file containing the CBasis / VBasis information .
def _save_warm_start(self, save_c_v_basis):
        n_var = len(self._pyomo_var_to_solver_var_map)
        n_const = len(self._pyomo_con_to_solver_con_map)
        if save_c_v_basis is None:
            save_c_v_basis = True
        if save_c_v_basis:
            var_data = VBasis(n=n_var)
            const_data = CBasis(n=n_const)
            var_attr = self._gurobipy.GRB.Attr.VBasis
            const_attr = self._gurobipy.GRB.Attr.CBasis
        else:
            var_data = PicklableData(n=n_var, val_dtype=float)
            const_data = PicklableData(n=n_const, val_dtype=float)
            var_attr = self._gurobipy.GRB.Attr.X
            const_attr = self._gurobipy.GRB.Attr.Pi
        try:
            for pyomo_var, gurobipy_var in self._pyomo_var_to_solver_var_map.items():
                var_data.save_component(pyomo_var, gurobipy_var.getAttr(var_attr))
        except AttributeError as e:
            if save_c_v_basis:
                return self._save_warm_start(save_c_v_basis=False)
            raise e
        for pyomo_const, gurobipy_const in self._pyomo_con_to_solver_con_map.items():
            const_data.save_component(pyomo_const, gurobipy_const.getAttr(const_attr))
        with open(self._write_warm_start, "wb") as f:
            data = WarmStartData(var_data, const_data, save_c_v_basis)
            pickle.dump(data, f)
def _save_warm_start ( self , save_c_v_basis ) : n_var = len ( self . _pyomo_var_to_solver_var_map ) n_const = len ( self . _pyomo_con_to_solver_con_map ) if save_c_v_basis is None : save_c_v_basis = True if save_c_v_basis : var_data = VBasis ( n = n_var ) const_data = CBasis ( n = n_const ) var_attr = self . _gurobipy . GRB . Attr . VBasis const_attr = self . _gurobipy . GRB . Attr . CBasis else : var_data = PicklableData ( n = n_var , val_dtype = float ) const_data = PicklableData ( n = n_const , val_dtype = float ) var_attr = self . _gurobipy . GRB . Attr . X const_attr = self . _gurobipy . GRB . Attr . Pi try : for pyomo_var , gurobipy_var in self . _pyomo_var_to_solver_var_map . items ( ) : var_data . save_component ( pyomo_var , gurobipy_var . getAttr ( var_attr ) ) except AttributeError as e : if save_c_v_basis : return self . _save_warm_start ( save_c_v_basis = False ) raise e for pyomo_const , gurobipy_const in self . _pyomo_con_to_solver_con_map . items ( ) : const_data . save_component ( pyomo_const , gurobipy_const . getAttr ( const_attr ) ) with open ( self . _write_warm_start , "wb" ) as f : data = WarmStartData ( var_data , const_data , save_c_v_basis ) pickle . dump ( data , f )
Create a pickle file containing the CBasis/VBasis information.
Create a pickle file containing the CBasis / VBasis information .
"""Create a pickle file containing the CBasis/VBasis information.""" # Setup our data objects # Save the variable data # If we get an Attribute error and using c_v_basis it's probably cause # there was no crossover. In this case we retry without c_v_basis # Save the constraint data # Dump the data to a pickle file
self
save_c_v_basis