當前位置: 首頁>>代碼示例>>Python>>正文


Python gurobipy.GurobiError方法代碼示例

本文整理匯總了Python中gurobipy.GurobiError方法的典型用法代碼示例。如果您正苦於以下問題:Python gurobipy.GurobiError方法的具體用法?Python gurobipy.GurobiError怎麽用?Python gurobipy.GurobiError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gurobipy的用法示例。


在下文中一共展示了gurobipy.GurobiError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: findSolutionValues

# 需要導入模塊: import gurobipy [as 別名]
# 或者: from gurobipy import GurobiError [as 別名]
def findSolutionValues(self):
            for var in self.varables.values():
                try:
                    var.varValue = var.solver_var.X
                except gurobipy.GurobiError:
                    pass
            GRB = gurobipy.GRB
            gurobiLPStatus = {
                GRB.OPTIMAL: LpStatusOptimal,
                GRB.INFEASIBLE: LpStatusInfeasible,
                GRB.INF_OR_UNBD: LpStatusInfeasible,
                GRB.UNBOUNDED: LpStatusUnbounded,
                GRB.ITERATION_LIMIT: LpStatusNotSolved,
                GRB.NODE_LIMIT: LpStatusNotSolved,
                GRB.TIME_LIMIT: LpStatusNotSolved,
                GRB.SOLUTION_LIMIT: LpStatusNotSolved,
                GRB.INTERRUPTED: LpStatusNotSolved,
                GRB.NUMERIC: LpStatusNotSolved,
            }
            self.status = gurobiLPStatus.get(self.gurobi_model.Status, LpStatusUndefined)
            return self.status 
開發者ID:QuantEcon,項目名稱:MatchingMarkets.py,代碼行數:23,代碼來源:solvers.py

示例2: _relax_customer_constraints_with_feasRelax

# 需要導入模塊: import gurobipy [as 別名]
# 或者: from gurobipy import GurobiError [as 別名]
def _relax_customer_constraints_with_feasRelax(m, customer_cover_constraints, active_ptls, relaxed_ptls):
    # relax the model and relax minimal number of customer serving constraints
    pens = [1.0]*len(customer_cover_constraints)
    m.feasRelax(2, True, None, None, None, customer_cover_constraints, pens)
    # TODO: not sure if feasRelax can change Status, test it someday
    if m.Status == GRB.INTERRUPTED: 
        raise KeyboardInterrupt()
    m.optimize()

    # restore SIGINT callback handler which is changed by gurobipy
    signal(SIGINT, default_int_handler)

    status = m.Status
    if __debug__:
        log(DEBUG-2, "Relaxed problem Gurobi runtime = %.2f"%m.Runtime)
        if m.Status == GRB.OPTIMAL:
            log(DEBUG-3, "Relaxed problem Gurobi objective = %.2f"%
                         m.getObjective().getValue())

    if status == GRB.OPTIMAL:
        return _decision_variables_to_petals(m.X, active_ptls, relaxed_ptls), False
    elif status == GRB.TIME_LIMIT:
        raise GurobiError(10023, "Gurobi timeout reached when attempting to solve relaxed SCPCVRP")
    elif m.Status == GRB.INTERRUPTED:
        raise KeyboardInterrupt()
    return None,False 
開發者ID:yorak,項目名稱:VeRyPy,代碼行數:28,代碼來源:petalvrp.py

示例3: copy_solver_configuration

# 需要導入模塊: import gurobipy [as 別名]
# 或者: from gurobipy import GurobiError [as 別名]
def copy_solver_configuration(source, target):
    """
    Copies the solver configuration from a source model to a target model
    :param source:
    :param target:
    :return:
    """

    # LP method
    try:
        target.solver.configuration.lp_method = source.solver.configuration.lp_method
    except AttributeError:
        pass

    # Presolve
    target.solver.configuration.presolve = source.solver.configuration.presolve

    # Timeout
    target.solver.configuration.timeout = source.solver.configuration.timeout

    # Tolerances
    for tol_name in dir(source.solver.configuration.tolerances):
        tol = getattr(source.solver.configuration.tolerances, tol_name)
        setattr(target.solver.configuration.tolerances, tol_name, tol)

    # Additionnal solver-specific settings
    try:
        # Gurobi
        if source.solver.interface.__name__ == 'optlang.gurobi_interface':
            from gurobipy import GurobiError
            for k in dir(source.solver.problem.Params):
                if not k.startswith('_'):
                    try:
                        v = getattr(source.solver.problem.Params, k)
                        setattr(target.solver.problem.Params, k, v)
                    except GurobiError:
                        pass
    except ModuleNotFoundError:
        pass

    # Verbosity
    target.solver.configuration.verbosity = source.solver.configuration.verbosity 
開發者ID:EPFL-LCSB,項目名稱:pytfa,代碼行數:44,代碼來源:utils.py

示例4: _mmp_solve

# 需要導入模塊: import gurobipy [as 別名]
# 或者: from gurobipy import GurobiError [as 別名]
def _mmp_solve(w1_ij, x_ij_keys, n, w2_ij = None):
    """A helper function that solves a weighted maximum matching problem.
    """
    
    m = Model("MBSA")
    
    if __debug__:
        log(DEBUG,"")
        log(DEBUG,"Solving a weighted maximum matching problem with "+
                  "%d savings weights." % len(w1_ij))

    # build model
    x_ij = m.addVars(x_ij_keys, obj=w1_ij, vtype=GRB.BINARY, name='x')    
    _mmp_add_cnts_sum(m, x_ij, x_ij_keys, w1_ij, n)
    m._vars = x_ij
    m.modelSense = GRB.MAXIMIZE
    m.update()

    # disable output
    m.setParam('OutputFlag', 0)    
    m.setParam('TimeLimit', MAX_MIP_SOLVER_RUNTIME)
    m.setParam('Threads', MIP_SOLVER_THREADS)
    #m.write("out.lp")
    m.optimize()

    # restore SIGINT callback handler which is changed by gurobipy
    signal(SIGINT, default_int_handler)

    if __debug__:
        log(DEBUG-1, "Gurobi runtime = %.2f"%m.Runtime)
    
    if m.Status == GRB.OPTIMAL:
        if w2_ij==None:
            max_wt, max_merge = max( (w1_ij[k], x_ij_keys[k])
                                      for k, v in enumerate(m.X) if v )
        else:
            max_wt, _, max_merge = max( (w1_ij[k], w2_ij[k], x_ij_keys[k])
                                      for k, v in enumerate(m.X) if v )
            
        return max_wt, max_merge[0], max_merge[1]
    elif m.Status == GRB.TIME_LIMIT:
        raise GurobiError(10023, "Gurobi timeout reached when attempting to solve GAP")
    elif m.Status == GRB.INTERRUPTED:
        raise KeyboardInterrupt()
    return None 
開發者ID:yorak,項目名稱:VeRyPy,代碼行數:47,代碼來源:matchingvrp.py

示例5: findSolutionValues

# 需要導入模塊: import gurobipy [as 別名]
# 或者: from gurobipy import GurobiError [as 別名]
def findSolutionValues(self, lp):
            """

            :param lp:
            :return:
            """
            model = lp.solverModel
            solutionStatus = model.Status
            GRB = gurobipy.GRB
            gurobiLpStatus = {GRB.OPTIMAL: LpStatusOptimal,
                              GRB.INFEASIBLE: LpStatusInfeasible,
                              GRB.INF_OR_UNBD: LpStatusInfeasible,
                              GRB.UNBOUNDED: LpStatusUnbounded,
                              GRB.ITERATION_LIMIT: LpStatusNotSolved,
                              GRB.NODE_LIMIT: LpStatusNotSolved,
                              GRB.TIME_LIMIT: LpStatusNotSolved,
                              GRB.SOLUTION_LIMIT: LpStatusNotSolved,
                              GRB.INTERRUPTED: LpStatusNotSolved,
                              GRB.NUMERIC: LpStatusNotSolved}

            # populate pulp solution values
            try:
                for var, value in zip(lp.variables(), model.getAttr(GRB.Attr.X, model.getVars())):
                    var.varValue = value
            except (gurobipy.GurobiError, AttributeError):
                pass

            try:
                for var, value in zip(lp.variables(), model.getAttr(GRB.Attr.RC, model.getVars())):
                    var.dj = value
            except (gurobipy.GurobiError, AttributeError):
                pass

            # put pi and slack variables against the constraints
            try:
                for constr, value in zip(lp.constraints.values(), model.getAttr(GRB.Pi, model.getConstrs())):
                    constr.pi = value
            except (gurobipy.GurobiError, AttributeError):
                pass

            try:
                for constr, value in zip(lp.constraints.values(), model.getAttr(GRB.Slack, model.getConstrs())):
                    constr.slack = value
            except (gurobipy.GurobiError, AttributeError):
                pass

            if self.msg:
                print("Gurobi status=", solutionStatus)
            lp.resolveOK = True
            for var in lp.variables():
                var.isModified = False
            lp.status = gurobiLpStatus.get(solutionStatus, LpStatusUndefined)
            return lp.status 
開發者ID:SanPen,項目名稱:GridCal,代碼行數:55,代碼來源:gurobi.py


注:本文中的gurobipy.GurobiError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。